Added song selection change when changing albums

This commit is contained in:
gballan1 2016-11-28 23:24:18 -05:00
parent 8b42f39aa1
commit df72cf3a58
2 changed files with 47 additions and 1 deletions

View File

@ -16,4 +16,23 @@ $app->get('/apiv1/music/album-info/:albumid', function($albumid) use($app) {
$app->notFound(); $app->notFound();
} }
})->name('apiv1.music.get-album'); })->name('apiv1.music.album-info');
// retrieve an album's songs
$app->('/apiv1/music/album-songs/:albumid', function($albumid) use($app) {
if (!ctype_digit($albumid)) {
echo 'Don\'t do that';
return;
}
$album = $app->album->where('id', $albumid)->first();
if ($album) {
$json = [songs => $album->songs()];
echo json_encode($json);
} else {
$app->notFound();
}
})->name('apiv1.music.album-songs')

View File

@ -45,6 +45,33 @@ function getAlbumInfo(albumElem) {
}); });
} }
function getAlbumSongs(albumElem) {
albumElem = $(albumElem);
$.get('/apiv1/music/album-songs/' + albumElem.data('albumid'), function(data) {
var json = $.parseJSON(data);
var playlist = $('#now-playing-list');
playlist.empty();
for (var i = 0; i < json.songs.length; i++) {
var song = json.songs[i];
var classString = '';
if (i === 0) {
classString = 'music-track selected';
} else {
classString = 'music-track';
}
var songElem = '<li class="' + classString + '" data-trackid="' + song.id + '" data-title="' + song.title + '" data-album="' + song.album_id + '" data-order="' + song.track_order + '" data-path="' + song.audio_file + '">' +
'<span>' + song.track_order + '. ' + song.title + '</span>' +
'</li>';
playlist.append(song);
}
});
}
function changeSelectedTrack(trackElem) { function changeSelectedTrack(trackElem) {
var oldSelected = $('.now-playing-list .music-track.selected'); var oldSelected = $('.now-playing-list .music-track.selected');
var newSelected = $(trackElem); var newSelected = $(trackElem);