From 9d04aa9f631b088113d933690266dacd0df38c97 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Thu, 3 Dec 2015 13:06:10 +0100 Subject: jingles: removecut without refetching all groups, carts and cuts. diff --git a/www/js/jingles.js b/www/js/jingles.js index 3af1e63..b737a1b 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -46,7 +46,7 @@ var JingleGroupList = function() { this.groups = []; var self = this; - $(this).on('add remove update', function () { + $(this).on('add update', function () { self.render(); }); }; @@ -80,10 +80,6 @@ JingleGroupList.prototype.fetch = function() { self.fetch(); }); - $(jingleGroup).on('remove', function() { - self.fetch(); - }); - self.groups.push(jingleGroup); }); }); @@ -161,10 +157,6 @@ JingleGroup.prototype.createCartFromXml = function(cartXml, active) { active ); - $(cut).on('remove', function() { - $(self).trigger('remove'); - }); - $(cut).on('add', function() { $(self).trigger('add'); }); @@ -234,6 +226,15 @@ JingleCart.prototype.addCut = function(cut) { this.cuts.push(cut); }; +JingleCart.prototype.removeCut = function(cut) { + var self = this; + $.each(this.cuts, function(index, currentCut){ + if(currentCut === cut) { + self.cuts.splice(index, 1); + } + }); +}; + var JingleCut = function(cart, cartNumber, name, description, active) { this.cart = cart; this.cartNumber = cartNumber; @@ -284,15 +285,15 @@ JingleCut.prototype.toggleActive = function() { }); }; -JingleCut.prototype.delete = function() { +JingleCut.prototype.removeSelf = function() { var self = this; rivendell.removeCut(this.cartNumber, this.number, function() { - $(self).trigger('remove'); + self.cart.removeCut(this); + self.$el.remove(); }); }; JingleCut.prototype.render = function() { - var moveButton = $(''); var activateButton; if (this.active) { @@ -310,7 +311,7 @@ JingleCut.prototype.render = function() { self.toggleActive(); }); deleteButton.on('click', function() { - self.delete(); + self.removeSelf(); }); this.$el = $('').append($('').text(this.name)) -- cgit v0.10.2