diff --git a/server/djrandom/frontend/static/js/djr/djr.js b/server/djrandom/frontend/static/js/djr/djr.js index ff7a9c5e95b7513512a537bb7c0a0fde0036d335..d10dbf38531050e0ffbc6fea611cacd0fbc0d326 100644 --- a/server/djrandom/frontend/static/js/djr/djr.js +++ b/server/djrandom/frontend/static/js/djr/djr.js @@ -85,6 +85,7 @@ djr.init = function (userid) { var pltitle = $('#savetext').val(); if (pltitle != '') { djr.state.player.savePlaylistWithTitle(pltitle); + djr.updatePlaylists(); } $('#saveForm').hide(); }); @@ -131,21 +132,8 @@ djr.init = function (userid) { }); $('#pllistbtn').click(function () { if ($('#pllist').is(':visible') == false) { + djr.updatePlaylists(); $('#pllist').show('slow'); - djr.state.backend.getPlList(djr.state.userid, function(results) { - var pllist = results; - if (pllist.length == 0) { - djr.debug('No results found.'); - return; - } - var output = "<ul>"; - for (var i; i < pllist.length; i++) { - output += "<li><a onclick='djm.player.loadPlaylist(\"" + pllist[i].uuid + "\")' >" + pllist[i].title + "</a></li>"; - - } - output += "</ul>"; - $('#pllist').html(output); - }); } else { $('#pllist').hide('slow') } @@ -158,6 +146,8 @@ djr.init = function (userid) { }); djr.debug('initialization done.'); + + djr.updatePlaylists(); }; // Export the player for quick onclick access @@ -165,6 +155,24 @@ djr.player = function() { return djr.state.player; }; +// Update the list of playlists. +djr.updatePlaylists = function() { + djr.state.backend.getPlList(djr.state.userid, function(results) { + if (results.length == 0) { + djr.debug('No playlists found.'); + return; + } + var output = '<ul>'; + $.each(results, function(idx, x) { + if (x.title) { + output += "<li><a onclick='djm.player.loadPlaylist(\"" + x.uuid + "\")' >" + x.title + "</a></li>"; + } + }); + output += '</ul>'; + $('#pllist').html(output); + }); +}; + // Show/hide the 'loader' animated GIF. // Keep a counter so we can nest calls. djr.loading = function(active) {