diff --git a/app/frontend/scripts/behaviors.js.coffee b/app/frontend/scripts/behaviors.js.coffee index 9291bb4a..16bffbb6 100644 --- a/app/frontend/scripts/behaviors.js.coffee +++ b/app/frontend/scripts/behaviors.js.coffee @@ -43,7 +43,7 @@ $(document).ready () -> # # data-artist - The Data attribute set on the link whose value is the # artist name for this song. - $('.artist').live 'click', () -> + $(document).on 'click', '.artist', () -> element = $(@) artist = escape(element.data('artist')) updateSongs("/artist/"+artist, "GET") @@ -53,7 +53,7 @@ $(document).ready () -> # # data-artist - The Data attribute set on the link whose value is the # artist name for this song. - $('.album').live 'click', () -> + $(document).on 'click', '.album', () -> element = $(@) artist = escape(element.data('artist')) album = escape(element.data('album')) @@ -118,7 +118,8 @@ $(document).ready () -> # # data-song-id - The Data attribute set on the link whose value is the # persistent ID of the song. - $('.add-to-queue').live 'click', () -> + $(document).on 'click', '.add-to-queue', () -> + play.spin(true) element = $(@) id = element.data('song-id') $.ajax @@ -127,14 +128,16 @@ $(document).ready () -> data: id: id success: (response) -> - alert 'added!' + element.replaceWith(queue(id, true)) + play.spin(false) false # Removes this song from the queue. # # data-song-id - The Data attribute set on the link whose value is the # persistent ID of the song. - $('.remove-from-queue').live 'click', () -> + $(document).on 'click', '.remove-from-queue', () -> + play.spin(true) element = $(@) id = element.data('song-id') $.ajax @@ -143,5 +146,6 @@ $(document).ready () -> data: id: id success: (response) -> - alert 'removed!' + element.replaceWith(queue(id, false)) + play.spin(false) false \ No newline at end of file diff --git a/app/frontend/scripts/helpers.js.coffee b/app/frontend/scripts/helpers.js.coffee index b4fabf3e..e9c199e4 100644 --- a/app/frontend/scripts/helpers.js.coffee +++ b/app/frontend/scripts/helpers.js.coffee @@ -62,6 +62,19 @@ play.renderStar = (id, starred) -> }) Mustache.to_html(templates.star,song,templates) +# Queue or unqueue a song +# +# id - The ID of the song +# queued - The Boolean value of whether this song should be queued or not. +# 'true' means Add to Queue, 'false' means Remove from Queue +# +play.queue = (id, queued) -> + song = new Song({ + id: id + queued: queued + }) + Mustache.to_html(templates.queuing,song,templates) + # Takes a JSON response and parses it for our common Song attributes. # # json - The common JSON endpoint we return.