summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--www/js/musicpools.js77
1 files changed, 76 insertions, 1 deletions
diff --git a/www/js/musicpools.js b/www/js/musicpools.js
index 6b46981..30e9d70 100644
--- a/www/js/musicpools.js
+++ b/www/js/musicpools.js
@@ -39,11 +39,23 @@ function musicpools_cleanup() {
var Musicpools = function() {
// todo: get current Pool Id from session like shows?
this.currentPoolId = sessionStorage.getItem("currentPoolId");
- this.currentPoolId = this.currentPoolId === null ? 0 : this.currentPoolId;
this.musicpools = [];
this.fetch();
};
+Musicpools.prototype.getCurrentPool = function() {
+ if (this.musicpools.length === 0) {
+ return null;
+ }
+ if (this.currentPoolId === null) {
+ this.currentPoolId = 0;
+ }
+ if (this.currentPoolId > this.musicpools.length) {
+ this.currentPoolId = 0;
+ }
+ return this.musicpools[this.currentPoolId];
+};
+
Musicpools.prototype.fetch = function() {
var self = this;
@@ -79,6 +91,12 @@ Musicpools.prototype.updateSelector = function() {
$('#musicpool-selector').append($('<option>').attr('value', musicpool.title).text(name));
});
+ var self = this;
+ $('#musicpool-selector').on('change', function() {
+ self.getCurrentPool().render();
+ });
+
+ this.getCurrentPool().render();
};
// this and jinglegroup are basicly the same thing
@@ -92,4 +110,61 @@ var Musicpool = function(title, clock, groupName, description, lowcart, highcart
this.highcart = highcart;
this.normlevel = normlevel;
this.trimlevel = trimlevel;
+
+ this.carts = [];
+};
+
+Musicpool.prototype.render = function() {
+ this.fetchCarts(function() {
+ console.log('render!');
+ });
+};
+
+Musicpool.prototype.fetchCarts = function(success) {
+ console.log('fetchCarts!');
+ var self = this;
+ rivendell.listCarts(this.groupName, 1, function(cartsXml, status, req) {
+ self.carts = [];
+
+ var dbs = $('cartList', cartsXml).children();
+ dbs.each(function(index, cartXml) {
+ var cart = new MusicpoolCart(
+ $('number', cartXml).text(),
+ $('title', cartXml).text(),
+ $('groupName', cartXml).text(),
+ self
+ );
+
+ var cuts = $('cutList', cartXml).children();
+ cart.cut = new MusicpoolCut(
+ cart,
+ cart.number,
+ $('cutName', cuts[0]).find().text(),
+ $('description', cuts[0]).find().text()
+ );
+
+ self.carts.push(cart);
+ });
+
+ success();
+ });
+};
+
+var MusicpoolCart = function(number, title, groupName, group) {
+ this.number = number;
+ this.title = title;
+ this.groupName = groupName;
+ this.group = group;
+
+ this.cut = null;
+};
+
+var MusicpoolCut = function(cart, cartNumber, name, description) {
+ this.cart = cart;
+ this.cartNumber = cartNumber;
+ this.number = name.substr(-3);
+ this.name = name;
+ this.description = description;
+
+ this.$el = null;
};