Play and add buttons in the collection.

This commit is contained in:
Côme BERNIGAUD 2011-08-25 20:57:17 +02:00
parent ce1d13c9b6
commit 56399d1d79
1 changed files with 58 additions and 66 deletions

View File

@ -79,19 +79,18 @@ Collection={
$.each(Collection.artists,function(i,artist){
if(artist.name && artist.songs.length>0){
var tr=template.clone().removeClass('template');
tr.addClass('artist');
tr.find('td.title a').text(artist.songs.length+' '+t('media','songs'));
tr.find('td.album a').text(artist.albums.length+' '+t('media','albums'));
tr.find('td.artist a').text(artist.name);
tr.data('artistData',artist);
tr.find('td.artist a').click(function(event){
event.preventDefault();
PlayList.add(artist,true);
PlayList.add(artist);
PlayList.play(0);
Collection.parent.find('tr').removeClass('active');
$('tr[data-artist="'+artist.name+'"]').addClass('active');
});
var expander=$('<a class="expander">&gt; </a>');
var expander=$('<a class="expander">&gt;</a>');
expander.data('expanded',false);
expander.click(function(event){
var tr=$(this).parent().parent();
@ -101,7 +100,9 @@ Collection={
Collection.showArtist(tr.data('artist'));
}
});
tr.find('td.album a').before(expander);
tr.find('td.artist').addClass('buttons');
Collection.addButtons(tr,artist);
tr.children('td.artist').append(expander);
tr.attr('data-artist',artist.name);
Collection.parent.find('tbody').append(tr);
}
@ -113,60 +114,49 @@ Collection={
var tr=Collection.parent.find('tr[data-artist="'+artist+'"]');
var nextRow=tr.next();
var artist=tr.data('artistData');
var first=true;
$.each(artist.albums,function(foo,album){
var newRow=tr.clone();
newRow.removeClass('artist');
newRow.addClass('album');
newRow.find('.expander').remove();
var expander=$('<a class="expander">v </a>');
expander.data('expanded',true);
expander.click(function(event){
var tr=$(this).parent().parent();
if(expander.data('expanded')) {
Collection.hideAlbum(tr.data('artist'),tr.data('album'));
} else {
Collection.showAlbum(tr.data('artist'),tr.data('album'));
}
});
newRow.find('td.title').text('');
newRow.find('td.artist a').text(album.name);
newRow.find('td.album a').text(album.songs.length+" songs");
newRow.find('td.artist a').click(function(event){
event.preventDefault();
PlayList.add(album,true);
PlayList.play(0);
Collection.parent.find('tr').removeClass('active');
$('tr[data-album="'+album.name+'"]').addClass('active');
});
newRow.find('td.album a').before(expander);
newRow.attr('data-artist',artist.name);
newRow.attr('data-album',album.name);
nextRow.before(newRow);
$.each(album.songs,function(i,song){
var newRow=tr.clone();
newRow.removeClass('artist');
newRow.addClass('song');
newRow.find('.expander').remove();
newRow.find('td.title a').text('');
newRow.find('td.album a').text('');
newRow.find('td.artist a').text(song.name);
newRow.find('td.artist a').click(function(event) {
if(first){
newRow=tr;
}else{
var newRow=tr.clone();
}
if(i==0){
newRow.find('td.album a').text(album.name);
newRow.find('td.album a').click(function(event){
event.preventDefault();
PlayList.add(album);
PlayList.play(0);
Collection.parent.find('tr').removeClass('active');
$('tr[data-album="'+album.name+'"]').addClass('active');
});
}else{
newRow.find('.expander').remove();
newRow.find('td.album a').text('');
}
newRow.find('td.title a').text(song.name);
Collection.addButtons(newRow,song);
newRow.find('td.title a').click(function(event){
event.preventDefault();
PlayList.add(song,true);
PlayList.add(song);
PlayList.play(0);
Collection.parent.find('tr').removeClass('active');
$('tr[data-title="'+song.name+'"]').addClass('active');
});
newRow.attr('data-artist',artist.name);
newRow.attr('data-album',album.name);
newRow.attr('data-title',song.name);
nextRow.before(newRow);
newRow.attr('data-artist',artist.name);
if(!first){
nextRow.before(newRow);
}
first=false;
});
});
tr.removeClass('collapsed');
tr.find('a.expander').data('expanded',true);
tr.find('a.expander').addClass('expanded');
tr.find('a.expander').text('v ');
tr.find('a.expander').text('v');
},
hideArtist:function(artist){
var tr=Collection.parent.find('tr[data-artist="'+artist+'"]');
@ -174,7 +164,7 @@ Collection={
var artist=tr.first().data('artistData');
tr.first().find('td.album a').text(artist.albums.length+' '+t('media','albums'));
tr.first().find('td.title a').text(artist.songs.length+' '+t('media','songs'));
tr.first().find('td.album a').last().unbind('click');
tr.first().find('td.album a').unbind('click');
tr.first().find('td.title a').unbind('click');
tr.each(function(i,row){
if(i>0){
@ -183,23 +173,15 @@ Collection={
});
tr.find('a.expander').data('expanded',false);
tr.find('a.expander').removeClass('expanded');
tr.find('a.expander').text('> ');
tr.find('a.expander').text('>');
}
},
showAlbum:function(artist,album){
var tr = Collection.parent.find('tr[data-artist="'+artist+'"][data-album="'+album+'"]');
tr.find('a.expander').data('expanded',true);
tr.find('a.expander').addClass('expanded');
tr.find('a.expander').text('v ');
tr.show();
Collection.parent.find('tr[data-artist="'+artist+'"][data-album="'+album+'"]').show();
},
hideAlbum:function(artist,album){
var tr = Collection.parent.find('tr[data-artist="'+artist+'"][data-album="'+album+'"]');
tr.find('a.expander').data('expanded',false);
tr.find('a.expander').removeClass('expanded');
tr.find('a.expander').text('> ');
tr.hide();
tr.first().show();
Collection.parent.find('tr[data-artist="'+artist+'"][data-album="'+album+'"]').hide();
Collection.parent.find('tr[data-artist="'+artist+'"][data-album="'+album+'"]').last().show();
},
parent:null,
hide:function(){
@ -213,16 +195,26 @@ Collection={
song.song_playcount++;
}
},
addButtons:function(parent){
parent.children('button.add').click(function(){
var type=$(this).parent().data('type');
PlayList.add($(this).parent().data(type));
addButtons:function(parent,data){
buttons = parent.find('.buttons');
if(buttons.find('.add').length<=0) {
buttons.append('<img class="add" src="'+OC.imagePath('core','actions/play-add')+'"/>');
}
if(buttons.find('.play').length<=0) {
buttons.append('<img class="play" src="'+OC.imagePath('core','actions/play')+'"/>');
}
buttons.find('.add').unbind('click');
buttons.find('.add').click(function(event){
event.preventDefault();
PlayList.add(data,true);
PlayList.render();
});
parent.children('button.play').click(function(){
var type=$(this).parent().data('type');
var oldSize=PlayList.items.length;
PlayList.add($(this).parent().data(type));
PlayList.play(oldSize);
buttons.find('.play').unbind('click');
buttons.find('.play').click(function(event){
event.preventDefault();
PlayList.add(data);
PlayList.play(0,0);
PlayList.render();
});
},
find:function(artistName,albumName,songName){