summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
authorPeter Grassberger <petertheone@gmail.com>2015-09-04 18:34:54 (GMT)
committerPeter Grassberger <petertheone@gmail.com>2015-09-04 18:34:54 (GMT)
commit2b1a99121c7f040705ee19e6978a16fdde4e9f3a (patch)
treee9f9f307f3599235132c5c4585ef02ad91a1fecb /www/js
parent77376357c285265546107e66b4c6949a8fe6f09e (diff)
restructure jingle events
Diffstat (limited to 'www/js')
-rw-r--r--www/js/jingles.js209
-rw-r--r--www/js/rivendell.js25
2 files changed, 133 insertions, 101 deletions
diff --git a/www/js/jingles.js b/www/js/jingles.js
index 00de8d5..7e3fb01 100644
--- a/www/js/jingles.js
+++ b/www/js/jingles.js
@@ -22,40 +22,75 @@
"use strict";
+var jinglesGroupList = null;
+
+function jingles_init() {
+ jinglesGroupList = new JingleGroupList();
+ jinglesGroupList.fetch();
+}
+
+function jingles_cleanup() {
+ jinglesGroupList.destroy();
+ jinglesGroupList = null;
+}
+
var JingleGroupList = function() {
this.groups = [];
- this.fetchGroups();
+ var self = this;
+ $(this).on('add remove update', function () {
+ self.render();
+ });
};
-JingleGroupList.prototype.fetchGroups = function() {
- console.log('fetchGroups JingleGroupList');
+JingleGroupList.prototype.fetch = function() {
+ console.log('JingleGroupList.prototype.fetchGroups');
+ this.groups = [];
var self = this;
var command = { LOGIN_NAME: auth_username, PASSWORD: auth_token };
$.post("/rh-bin/listdropboxes.cgi", command, function(groupsXml, status, req) {
var dbs = $(groupsXml).find("dropboxList").children();
dbs.each(function(index, groupXml) {
- var type = $(groupXml).find('type').text();
- if (type == 'jingle') {
- var jingleGroup = new JingleGroup(
- $(groupXml).find('jingle-title').text(),
- $(groupXml).find('group').text(),
- $(groupXml).find('group-description').text(),
- $(groupXml).find('group-low-cart').text(),
- $(groupXml).find('group-high-cart').text(),
- $(groupXml).find('normalization-level').text(),
- $(groupXml).find('autotrim-level').text()
- );
- $(jingleGroup).on('change', function() {
- $(self).trigger('change');
- });
- self.groups.push(jingleGroup);
+ if ($('type', groupXml).text() !== 'jingle') {
+ return true; // continue
}
+
+ var jingleGroup = new JingleGroup(
+ $('jingle-title', groupXml).text(),
+ $('group', groupXml).text(),
+ $('group-description', groupXml).text(),
+ $('group-low-cart', groupXml).text(),
+ $('group-high-cart', groupXml).text(),
+ $('normalization-level', groupXml).text(),
+ $('autotrim-level', groupXml).text()
+ );
+
+ $(jingleGroup).on('update', function() {
+ $(self).trigger('update');
+ });
+
+ $(jingleGroup).on('add', function() {
+ self.fetch();
+ });
+
+ $(jingleGroup).on('remove', function() {
+ self.fetch();
+ });
+
+ self.groups.push(jingleGroup);
});
}, "xml");
};
+JingleGroupList.prototype.render = function() {
+ console.log('JingleGroupList.prototype.render');
+ $('#app-jingles').html('');
+ $(this.groups).each(function(index, group) {
+ group.render();
+ });
+};
+
var JingleGroup = function(title, groupName, description, lowcart, highcart, normlevel, trimlevel) {
this.title = title;
this.groupName = groupName;
@@ -70,48 +105,11 @@ var JingleGroup = function(title, groupName, description, lowcart, highcart, nor
this.$el = null;
- var self = this;
- $(this).on('change', function() {
- console.log('JingleGroup change!');
- console.log(self.mainCart);
- console.log(self.deactivateCart);
- self.render();
- });
-
this.fetchCarts();
};
-JingleGroup.prototype.render = function() {
- console.log('render JingleGroup');
-
- // todo: copy some kind of template and render..
- if (!this.$el) {
- this.$el = $('.jingleGroupTemplate').clone().removeClass('jingleGroupTemplate');
- this.$el.removeClass('hidden').appendTo('#app-jingles');
- }
-
- $('h2', this.$el).html(this.title);
- $('table tbody tr', this.$el).remove();
-
- var cuts = [];
- if (this.mainCart && this.deactivateCart) {
- cuts = $.merge(this.mainCart.cuts, this.deactivateCart.cuts);
- }
- cuts = cuts.sort(function(a, b) {
- if (a.title && b.title) {
- return a.title.toLowerCase() < b.title.toLowerCase();
- }
- return a.title < b.title;
- });
-
- var self = this;
- $.each(cuts, function(index, cut) {
- $('table > tbody', self.$el).append(cut.render());
- });
-};
-
JingleGroup.prototype.fetchCarts = function() {
- console.log('fetchGroups JingleGroup');
+ console.log('JingleGroup.prototype.fetchCarts');
var self = this;
var command1 = { COMMAND: 7, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: this.lowcart, INCLUDE_CUTS: 1 };
var command2 = { COMMAND: 7, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: this.highcart, INCLUDE_CUTS: 1 };
@@ -123,7 +121,7 @@ JingleGroup.prototype.fetchCarts = function() {
self.deactivateCart = self.createCartFromXml(cartXml, false);
}, "xml")
).then(function() {
- $(self).trigger('change');
+ $(self).trigger('update');
});
};
@@ -144,18 +142,55 @@ JingleGroup.prototype.createCartFromXml = function(cartXml, active) {
$(cutXml).find('description').text(),
active
);
- $(cut).on('change', function(event, silent) {
- console.log('JingleCut change!');
- if (!silent) {
- $(self).trigger('change');
- }
+
+ $(cut).on('remove', function() {
+ $(self).trigger('remove');
});
+
cart.addCut(cut);
});
return cart;
};
+JingleGroup.prototype.render = function() {
+ console.log('JingleGroup.prototype.render');
+ //if (!this.$el) {
+ this.$el = $('.jingleGroupTemplate').clone().removeClass('jingleGroupTemplate');
+ this.$el.removeClass('hidden').appendTo('#app-jingles');
+ //}
+
+ $('h2', this.$el).html(this.title);
+ $('table tbody tr', this.$el).remove();
+
+ // todo: fix
+ /*var cuts = [];
+ if (this.mainCart && this.deactivateCart) {
+ cuts = $.merge(this.mainCart.cuts, this.deactivateCart.cuts);
+ } else if (this.mainCart) {
+ cuts = this.mainCart.cuts;
+ } else if (this.deactivateCart) {
+ cuts = this.deactivateCart.cuts;
+ }
+ console.log(cuts);
+ cuts = cuts.sort(function(a, b) {
+ if (a.title && b.title) {
+ return a.title.toLowerCase() < b.title.toLowerCase();
+ }
+ return a.title < b.title;
+ });
+
+ var self = this;
+ $.each(cuts, function(index, cut) {
+ $('table > tbody', self.$el).append(cut.render());
+ });*/
+ if (this.deactivateCart) {
+ var self = this;
+ $.each(this.deactivateCart.cuts, function(index, cut) {
+ $('table > tbody', self.$el).append(cut.render());
+ });
+ }
+};
var JingleCart = function(number, title, groupName) {
this.number = number;
@@ -169,13 +204,6 @@ JingleCart.prototype.addCut = function(cut) {
this.cuts.push(cut);
};
-JingleCart.prototype.removeCut = function(cut) {
- var index = this.cuts.indexOf(cut);
- if (index > -1) {
- this.cuts.splice(index, 1);
- }
-};
-
var JingleCut = function(cart, cartNumber, name, description, active) {
this.cart = cart;
this.cartNumber = cartNumber;
@@ -187,14 +215,14 @@ var JingleCut = function(cart, cartNumber, name, description, active) {
};
JingleCut.prototype.move = function() {
- console.log('move');
+ console.log('JingleCut.prototype.move');
// move to other group, if active stay in mainCart, if deactivated stay in deactiveCart
// check if there is an empty cut at destination
// todo: remove hardcoded cartNumbers
var destinationCart = ((parseInt(this.cartNumber) - 2000 + 2) % 4) + 2000;
- console.log(parseInt(this.cartNumber));
- console.log(destinationCart);
+ //console.log(parseInt(this.cartNumber));
+ //console.log(destinationCart);
var self = this;
var command = { COMMAND: 9, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: destinationCart };
@@ -212,10 +240,10 @@ JingleCut.prototype.move = function() {
// use command 18 copy audio from one cart to another
// then delete old cart
- self.delete();
+ //self.delete();
// auto update
- //$(this).trigger('change');
+ $(self).trigger('remove');
}, "xml");
}
}, "xml");
@@ -223,36 +251,24 @@ JingleCut.prototype.move = function() {
};
JingleCut.prototype.toggleActivate = function() {
- console.log('toggleActivate');
+ console.log('JingleCut.prototype.toggleActivate');
// move to other cart, from mainCart to deactiveCart or the other way around
- //$(this).trigger('change');
+
};
JingleCut.prototype.delete = function() {
- console.log('delete');
- // remove cut, command 11
-
- console.log(this.cartNumber);
- console.log(this.number);
+ console.log('JingleCut.prototype.delete');
var self = this;
var command = { COMMAND: 11, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: this.cartNumber, CUT_NUMBER: this.number};
$.post("/rd-bin/rdxport.cgi", command, function() {
- self.cart.removeCut(this);
-
- self.$el.remove();
- self.$el = null;
-
- $(self).trigger('change', true);
- $(self).off();
+ $(self).trigger('remove');
});
};
JingleCut.prototype.render = function() {
- if (this.$el) {
- return this.$el;
- }
+ console.log('JingleCut.prototype.render');
var moveButton = $('<button class="btn btn-info btn-mini"><i class="icon-arrow-right icon-white"></i> Verschieben</button>');
var activateButton;
@@ -265,6 +281,7 @@ JingleCut.prototype.render = function() {
var self = this;
moveButton.on('click', function() {
+ console.log('m0ve!');
self.move();
});
activateButton.on('click', function() {
@@ -285,13 +302,3 @@ JingleCut.prototype.render = function() {
return this.$el;
};
-
-var jinglesGroupList = null;
-
-function jingles_init() {
- jinglesGroupList = new JingleGroupList();
-}
-
-function jingles_cleanup() {
- jinglesGroupList = null;
-}
diff --git a/www/js/rivendell.js b/www/js/rivendell.js
new file mode 100644
index 0000000..eb3d99f
--- /dev/null
+++ b/www/js/rivendell.js
@@ -0,0 +1,25 @@
+/*
+ * rhwebimport
+ *
+ * Copyright (C) 2014-2015 Christian Pointner <equinox@helsinki.at>
+ * Copyright (C) 2015 Peter Grassberger <petertheone@gmail.at>
+ *
+ * This file is part of rhwebimport.
+ *
+ * rhwebimport is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * rhwebimport is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with rhwebimport. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+var Rivendell = Rivendell || {};