From c6feaeb048417f7131ed98a48b6ce201e164b2f1 Mon Sep 17 00:00:00 2001 From: Nick Steel Date: Mon, 9 Nov 2015 21:18:11 +0000 Subject: [PATCH] Use a more generic maybePlay throughout playBrowsedTracks. --- .../static/js/controls.js | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/mopidy_musicbox_webclient/static/js/controls.js b/mopidy_musicbox_webclient/static/js/controls.js index a55cfac..46054fe 100644 --- a/mopidy_musicbox_webclient/static/js/controls.js +++ b/mopidy_musicbox_webclient/static/js/controls.js @@ -8,9 +8,6 @@ function playBrowsedTracks(action, trackIndex) { if (typeof trackIndex === 'undefined') { trackIndex = $('#popupBrowse').data("tlid"); } - if (action == PLAY_ALL) { - mopidy.tracklist.clear(); - } var trackUris = []; switch (action) { case PLAY_NOW: @@ -18,13 +15,21 @@ function playBrowsedTracks(action, trackIndex) { case ADD_THIS_BOTTOM: trackUris.push(browseTracks[trackIndex].uri); break; - case ADD_ALL_BOTTOM: case PLAY_ALL: + mopidy.tracklist.clear(); + // Don't break, fall through. + case ADD_ALL_BOTTOM: trackUris = getUris(browseTracks); break; default: break; } + var maybePlay = function(tlTracks) { + if (action === PLAY_NOW || action === PLAY_ALL) { + var playIndex = (action === PLAY_ALL) ? 0 trackIndex : 0; + mopidy.playback.play(tlTracks[playIndex]); + } + }; // For radio streams we just add the selected URI. // TODO: Why? @@ -36,24 +41,14 @@ function playBrowsedTracks(action, trackIndex) { switch (action) { case PLAY_NOW: case PLAY_NEXT: - var maybePlay = function(tlTracks) { - if (action === PLAY_NOW) { - mopidy.playback.play(tlTracks[0]); - } - }; - mopidy.tracklist.index().then(function (currentTrack) { - mopidy.tracklist.add(null, currentTrack + 1, null, trackUris).then(maybePlay); + mopidy.tracklist.index().then(function (currentIndex) { + mopidy.tracklist.add(null, currentIndex + 1, null, trackUris).then(maybePlay); }); break; case ADD_THIS_BOTTOM: case ADD_ALL_BOTTOM: case PLAY_ALL: - var addFunc = mopidy.tracklist.add(null, null, null, trackUris); - if (action == PLAY_ALL) { - addFunc.then(function(tlTracks) { - mopidy.playback.play(tlTracks[trackIndex]); - }); - } + mopidy.tracklist.add(null, null, null, trackUris).then(maybePlay); break; default: break;