1
0
mirror of https://github.com/danbee/mpd-client synced 2025-03-04 08:39:09 +00:00
mpd-client/assets/js/components/panel.js
2014-01-10 17:01:34 +00:00

54 lines
1.2 KiB
JavaScript

can.Component.extend({
tag: 'mpd-panel',
template: can.view('views/panel.mustache'),
scope: {
show: '@',
depth: '@',
artist: '@',
album: '@',
title: function() {
if (this.show == 'root') return 'Library';
},
fetchItems: {
root: [
{ label: 'Artists', show: 'artists' },
{ label: 'Albums', show: 'albums' },
{ label: 'Songs', show: 'songs' }
],
artists: function() { return Artist.findAll({}) },
albums: function() { Album.findAll({ artist: this.artist }) },
songs: function() { Song.findAll({ artist: this.artist, album: this.album }) }
}
},
helpers: {
renderItems: function() {
return can.view.render('views/library/' + this.show, {
items: this.fetchItems.root
});
},
rootLink: function(item) {
console.log(item);
return can.route.link(item.label, {
type: 'library',
show: item.show,
depth: +this.depth + 1
});
},
artistLink: function(item) {
return can.route.link(item.attr('name'), {
page: 'library',
show: 'albums',
depth: console.log(this),
artist: item.attr('name')
})
}
}
});