From b3f50be6ff9c72ed877f42e896c532b994cc49d1 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 13 Mar 2012 23:22:17 +0100 Subject: Implemented playlist item deletion. --- static/playlist.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'static/playlist.js') diff --git a/static/playlist.js b/static/playlist.js index 373098c..18403c4 100644 --- a/static/playlist.js +++ b/static/playlist.js @@ -9,26 +9,31 @@ $(function(){ }); window.items = new Playlist; PlaylistItemView = Backbone.View.extend({ - tagName: 'li', - template: Handlebars.compile('{{trackname}}'), + tagName: 'tr', + template: Handlebars.compile('{{trackname}}Delete'), render: function() { var model = this.model; var item = model.toJSON(); var el = $(this.el); el.html(this.template(item)); el.attr('id', 'cid-' + model.cid); - $(this.el, 'a').click(function() { + $('a.play', this.el).click(function() { while(model.collection.indexOf(model) > 0) { model.collection.remove(model.collection.at(0)); } playsound(model); return false; }); + $('a.delete', this.el).click(function() { + //var model = items.getByCid(model.cid); + items.remove(model); + return false; + }); return this; } }); PlaylistView = Backbone.View.extend({ - el: $('#playlist'), + el: $('#playlist tbody'), initialize: function() { items.bind('add', this.addOne, this); items.bind('remove', this.removeOne, this); @@ -53,6 +58,11 @@ $(function(){ removeOne: function(item) { $('#playlist #cid-' + item.cid).remove(); item.destroy(); + items.each(this.refreshOrder); + }, + refreshOrder: function(item) { + item.attributes.order_id = items.indexOf(item)+1; + item.save(); }, addAll: function() { items.each(this.addOne); -- cgit v1.2.3