From e881261ce10a8993602632d0ad39ed2c15a584eb Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sat, 7 Dec 2013 16:58:03 +0000 Subject: [PATCH] Fix some bugs around setting of playing status. --- assets/js/constructs/events.js | 5 +++-- assets/js/models/queueSong.js | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/assets/js/constructs/events.js b/assets/js/constructs/events.js index f40f0c3..cc203e4 100644 --- a/assets/js/constructs/events.js +++ b/assets/js/constructs/events.js @@ -7,9 +7,10 @@ var Events = can.Construct.extend({ this.events.onmessage = function(e) { response = JSON.parse(e.data); + console.log(response.data); switch (response.type) { case 'status': - status.attr(response.data); + status.attr(response.data, true); break; case 'queue': queue.replace(response.data); @@ -19,7 +20,7 @@ var Events = can.Construct.extend({ status.bind('change', function(event, attr, how, newVal, oldVal) { if (attr == 'song') { - queue.updatePlaying(oldVal, newVal); + queue.updatePlaying(how, newVal, oldVal); } }); }, diff --git a/assets/js/models/queueSong.js b/assets/js/models/queueSong.js index 2e662d9..cdd8021 100644 --- a/assets/js/models/queueSong.js +++ b/assets/js/models/queueSong.js @@ -6,9 +6,13 @@ var QueueSong = can.Model.extend({ QueueSong.List = can.List.extend({ - updatePlaying: function(oldVal, newVal) { - this.attr(oldVal).attr('playing', false); - this.attr(newVal).attr('playing', true); + updatePlaying: function(how, newVal, oldVal) { + if ((how == 'remove' || how == 'set') && this.attr(oldVal) != undefined) { + this.attr(oldVal).attr('playing', false); + } + if (how == 'add' || how == 'set') { + this.attr(newVal).attr('playing', true); + } } });