From ada31015e989d062ac68d58c94701e2df253b21e Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Mon, 1 Feb 2016 16:55:49 +0100 Subject: musicpools: add delete button to carts diff --git a/www/js/jingles.js b/www/js/jingles.js index 8d6ae38..960dd25 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -166,7 +166,7 @@ Rivendell.JingleCutView.prototype.render = function() { self.toggleActive(); }); deleteButton.on('click', function() { - self.removeSelf(); + self.delete(); }); this.$el = $('') @@ -222,10 +222,10 @@ Rivendell.JingleCutView.prototype.toggleActive = function() { }); }; -Rivendell.JingleCutView.prototype.removeSelf = function() { +Rivendell.JingleCutView.prototype.delete = function() { var self = this; rivendell.removeCut(this.model.cartNumber, this.model.number, function() { - self.model.cart.removeCut(this); + self.model.cart.removeCut(self.model); self.$el.remove(); }); }; diff --git a/www/js/musicpools.js b/www/js/musicpools.js index b9f9107..27de48e 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -185,8 +185,13 @@ Rivendell.MusicpoolCartView.prototype.render = function() { lastplayed = format_datetime(new Date(cut.lastPlayDatetime)); } - //todo - var actions = ''; + var deleteButton = $(''); + + var self = this; + deleteButton.on('click', function() { + self.delete(); + }); + this.$el = $('') .append($('').text(number)) @@ -195,6 +200,13 @@ Rivendell.MusicpoolCartView.prototype.render = function() { .append($('').text(imported)) .append($('').text(playcnt)) .append($('').text(lastplayed)) - .append($('').text(actions)); + .append($('').append(deleteButton)); }; +Rivendell.MusicpoolCartView.prototype.delete = function() { + var self = this; + rivendell.removeCart(this.model.number, function() { + self.model.group.removeCart(self.model); + self.$el.remove(); + }); +}; diff --git a/www/js/rivendell.js b/www/js/rivendell.js index 1a00f07..0f4bcda 100644 --- a/www/js/rivendell.js +++ b/www/js/rivendell.js @@ -380,6 +380,19 @@ Rivendell.Group = function(groupName, description, lowcart, highcart, normlevel, this.carts = []; }; +Rivendell.Group.prototype.addCart = function(cart) { + this.carts.push(cart); +}; + +Rivendell.Group.prototype.removeCart = function(cart) { + var self = this; + $.each(this.carts, function(index, currentCart){ + if(currentCart === cart) { + self.carts.splice(index, 1); + } + }); +}; + Rivendell.Group.prototype.fetchCarts = function() { var self = this; rivendell.listCarts(this.groupName, 1, function(cartsXml, status, req) { -- cgit v0.10.2