summaryrefslogtreecommitdiffstats
path: root/apps/media/js
diff options
context:
space:
mode:
authorCôme BERNIGAUD <come.bernigaud@laposte.net>2011-08-25 20:57:17 +0200
committerCôme BERNIGAUD <come.bernigaud@laposte.net>2011-08-25 20:57:17 +0200
commit56399d1d7929a33af5c3d543f8281d4e6d0fe89d (patch)
tree575d33684d82f2df8a7b9f946aa19ad1471a57c4 /apps/media/js
parentce1d13c9b6adf351818637649ca90a757c67df96 (diff)
downloadnextcloud-server-56399d1d7929a33af5c3d543f8281d4e6d0fe89d.tar.gz
nextcloud-server-56399d1d7929a33af5c3d543f8281d4e6d0fe89d.zip
Play and add buttons in the collection.
Diffstat (limited to 'apps/media/js')
-rw-r--r--apps/media/js/collection.js124
1 files changed, 58 insertions, 66 deletions
diff --git a/apps/media/js/collection.js b/apps/media/js/collection.js
index 5c04313d143..4b772b1756f 100644
--- a/apps/media/js/collection.js
+++ b/apps/media/js/collection.js
@@ -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){