Collection={ artists:[], loaded:false, loading:false, loadedListeners:[], load:function(ready){ if(ready){ Collection.loadedListeners.push(ready); } if(!Collection.loading){ Collection.loading=true; $.ajax({ url: OC.linkTo('media','ajax/api.php')+'?action=get_collection', dataType: 'json', success: function(collection){ Collection.artists=collection; //set the album and artist fieds for the songs for(var i=0;i1){ var expander=$('>'); expander.data('expanded',true); expander.click(function(event){ var tr=$(this).parent().parent(); if(expander.data('expanded')){ Collection.hideArtist(tr.data('artist')); }else{ Collection.showArtist(tr.data('artist')); } }); tr.children('td.artist').append(expander); } } if(album.album_name!=lastAlbum){ tr.find('td.album a').click(function(event){ event.preventDefault(); PlayList.add(album,true); PlayList.play(0); Collection.parent.find('tr').removeClass('active'); $('tr[data-album="'+album.album_name+'"]').addClass('active'); }); tr.find('td.album a').text(album.album_name); if(album.songs.length>1){ var expander=$('>'); expander.data('expanded',true); expander.click(function(event){ var tr=$(this).parent().parent(); if(expander.data('expanded')){ Collection.hideAlbum(tr.data('album')); }else{ Collection.showAlbum(tr.data('album')); } }); tr.children('td.album').append(expander); } } tr.attr('data-artist',artist.artist_name); tr.attr('data-album',album.album_name); lastArtist=artist.artist_name; lastAlbum=album.album_name; Collection.parent.find('tbody').append(tr); }); Collection.hideAlbum(artist.artist_name,album.album_name); }); Collection.hideArtist(artist.artist_name); }); } } }, showArtist:function(artist){ Collection.parent.find('tr[data-artist="'+artist+'"]').show(); Collection.parent.find('tr[data-artist="'+artist+'"]').first().removeClass('collapsed'); Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').data('expanded',true); Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').addClass('expanded'); Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').text('v'); }, hideArtist:function(artist){ if(Collection.parent.find('tr[data-artist="'+artist+'"]').length>1){ Collection.parent.find('tr[data-artist="'+artist+'"]').hide(); Collection.parent.find('tr[data-artist="'+artist+'"]').first().show(); Collection.parent.find('tr[data-artist="'+artist+'"]').first().addClass('collapsed'); Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').data('expanded',false); Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').removeClass('expanded'); Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').text('>'); } }, showAlbum:function(artist,album){ Collection.parent.find('tr[data-artist="'+artist+'"][data-album="'+album+'"]').show(); }, hideAlbum:function(artist,album){ 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(){ if(Collection.parent){ Collection.parent.hide(); } }, registerPlay:function(item){ if(item){ var song=Collection.findSong(item.artist,item.album,item.name); song.song_playcount++; } }, addButtons:function(parent){ parent.children('button.add').click(function(){ var type=$(this).parent().data('type'); PlayList.add($(this).parent().data(type)); }); 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); }); }, find:function(artistName,albumName,songName){ if(songName){ return Collection.findSong(artistName,albumName,songName); }else if(albumName){ return Collection.findAlbum(artistName,albumName); }else{ return Collection.findArtist(artistName); } }, findArtist:function(name){ for(var i=0;i