From 9dbcf12861ed501b91260fdbb064808832674375 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 23 Dec 2012 11:41:33 +0100 Subject: Added artist view and links. Plus a number of other minor fixes. --- static/init.js | 48 ++++++++++++++++++++++++++++++++++++++++++++---- static/playlist.js | 8 ++++++++ static/style.css | 3 ++- static/templates.js | 8 +++++--- 4 files changed, 59 insertions(+), 8 deletions(-) (limited to 'static') diff --git a/static/init.js b/static/init.js index c4f6c2c..2c63ac8 100644 --- a/static/init.js +++ b/static/init.js @@ -60,7 +60,15 @@ function load_directory(dir_id, dir_item) { $('#directory-add').prop('disabled', track_list.find('.ui-selected').length == 0); return false; }); - $(el, 'a.album').click(function() { + el.find('a.artist').click(function() { + var artist = { + id: item.metadata.artist_id, + name: item.metadata.artist + }; + show_artist(artist); + return false; + }); + el.find('a.album').click(function() { var album = { id: item.metadata.album_id, name: item.metadata.album @@ -108,6 +116,14 @@ function set_tracks(container, select, click) { select.prop('disabled', container.find('.ui-selected').length == 0); return false; }); + el.find('a.artist').click(function(event) { + var artist = { + id: track.metadata.artist_id, + name: track.metadata.artist + }; + show_artist(artist); + return false; + }); el.find('a.album').click(function(event) { var album = { id: track.metadata.album_id, @@ -130,6 +146,30 @@ function set_tracks(container, select, click) { }); } +function show_artist(artist) { + var tabs = $('#tabs'); + var tabid = '#artist-tab-' + artist.id; + var tab = $(tabid); + if(tab.length > 0) { + tabs.tabs('select', tab.index()-1); + return; + } + var tabli = $(templates.artist_tabli({tabid: tabid, artist: artist})); + tabs.find('.ui-tabs-nav').append(tabli); + var tab = $(templates.artist_tab(artist)); + tabs.append(tab).tabs('refresh'); + $.get('/json/artist/' + artist.id, function(data) { + var albums = []; + $.each(data.albums, function(i, album) { + album.artist = {id: data.id, name: data.name}; + albums.push(album); + }); + tab.empty(); + add_albums(tabid, albums); + }, 'json'); + tabs.tabs('select', tab.index()-1); +} + function show_album(album) { var tabs = $('#tabs'); var tabid = '#album-tab-' + album.id; @@ -155,8 +195,8 @@ function show_album(album) { tabs.tabs('select', tab.index()-1); } -function add_albums(data) { - var div = $('#albums-list'); +function add_albums(selector, data) { + var div = $(selector); $.each(data, function(i, album) { var el = $(templates.albums_item(album)); el.find('a').click(function() { @@ -190,7 +230,7 @@ function load_albums(initiate_scrolling) { albums_loading = true; $.get('/json/albums/' + page, function(data) { if(data.length > 0) - add_albums(data); + add_albums('#albums-list', data); else albums_end = true; if(initiate_scrolling == true) diff --git a/static/playlist.js b/static/playlist.js index 90167ce..07953ce 100644 --- a/static/playlist.js +++ b/static/playlist.js @@ -24,6 +24,14 @@ $(function(){ playsound(model); return false; }); + $('a.artist', this.el).click(function() { + var artist = { + id: model.attributes.metadata.artist_id, + name: model.attributes.metadata.artist + }; + show_artist(artist); + return false; + }); $('a.album', this.el).click(function() { var album = { id: model.attributes.metadata.album_id, diff --git a/static/style.css b/static/style.css index 058a3d8..8b2f1e8 100644 --- a/static/style.css +++ b/static/style.css @@ -17,8 +17,9 @@ html, body, #content { height: 100%; } .track-table tr.ui-selected td { background-color: #fea; } .track-table tr:hover td { background-color: #fbb; } -.track-table a { color: inherit; text-decoration: inherit; background-repeat: no-repeat; padding-left: 20px; display: block; } +.track-table a { color: inherit; text-decoration: inherit; display: block; } .track-table a:hover { text-decoration: underline; } +.track-table a.track, .track-table a.dir { background-repeat: no-repeat; padding-left: 20px; } .track-table .dir { background-image: url('/static/icons/folder.png'); } .track-table .track { background-image: url('/static/icons/music.png'); } .track-table .track.nocache { background-image: url('/static/icons/music_nocache.png'); } diff --git a/static/templates.js b/static/templates.js index fa2a240..71b77e8 100644 --- a/static/templates.js +++ b/static/templates.js @@ -10,10 +10,12 @@ Handlebars.registerHelper('trackname', function() { }); var templates = new (function Templates() { - this.track_item = Handlebars.compile('{{trackname}}{{metadata.artist}}{{metadata.album}}'); + this.track_item = Handlebars.compile('{{trackname}}{{metadata.artist}}{{metadata.album}}'); // The playlist automatically adds a tr tag. - this.playlist_item = Handlebars.compile('{{trackname}}{{metadata.artist}}{{metadata.album}}Delete'); + this.playlist_item = Handlebars.compile('{{trackname}}{{metadata.artist}}{{metadata.album}}Delete'); this.albums_item = Handlebars.compile('
{{name}} by {{artist.name}}
{{name}}
'); - this.album_tab = Handlebars.compile('
Loading...
'); + this.album_tab = Handlebars.compile('
Loading... Loading...
'); this.album_tabli = Handlebars.compile('
  • Album: {{album.name}} Remove tab
  • '); + this.artist_tab = Handlebars.compile('
    Loading... Loading...
    '); + this.artist_tabli = Handlebars.compile('
  • Artist: {{artist.name}} Remove tab
  • '); })(); -- cgit v1.2.3