diff options
Diffstat (limited to 'www/js/musicpools.js')
-rw-r--r-- | www/js/musicpools.js | 87 |
1 files changed, 37 insertions, 50 deletions
diff --git a/www/js/musicpools.js b/www/js/musicpools.js index abb6679..ce8e81a 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -35,7 +35,7 @@ function musicpools_init() { importer = new Rivendell.Importer(); var musicpools = new Rivendell.GroupList(rivendell); - musicpoolsView = new MusicpoolsView(musicpools); + musicpoolsView = new Rivendell.MusicpoolsView(musicpools); } function musicpools_cleanup() { @@ -44,41 +44,49 @@ function musicpools_cleanup() { rivendell = null; } -var MusicpoolsView = function(model) { +Rivendell.MusicpoolsView = function(model) { this.model = model; + this.musicpoolViews = []; this.currentPoolId = sessionStorage.getItem('currentPoolId'); var self = this; this.model.fetch('musicpool', function() { + $(self.model.groups).each(function(index, musicpool) { + var musicpoolView = new Rivendell.MusicpoolView(musicpool); + self.musicpoolViews.push(musicpoolView); + }); self.updateSelector(); }); }; -MusicpoolsView.prototype.setCurrentPoolId = function(currentPoolId) { +Rivendell.MusicpoolsView.prototype.setCurrentPoolId = function(currentPoolId) { this.currentPoolId = currentPoolId; sessionStorage.setItem('currentPoolId', this.currentPoolId); }; -MusicpoolsView.prototype.getCurrentPool = function() { +Rivendell.MusicpoolsView.prototype.getCurrentPoolView = function() { if (this.model.groups.length === 0) { return null; } + if (this.musicpoolViews.length === 0) { + return null; + } if (this.currentPoolId === null) { this.setCurrentPoolId(this.model.groups[0].clock); } var self = this; - var musicpoolFound = null; - $(this.model.groups).each(function(index, musicpool) { - if (musicpool.clock === self.currentPoolId) { - musicpoolFound = musicpool; + var musicpoolViewFound = null; + $(this.musicpoolViews).each(function(index, musicpoolView) { + if (musicpoolView.model.clock === self.currentPoolId) { + musicpoolViewFound = musicpoolView; return true; } }); - return musicpoolFound; + return musicpoolViewFound; }; -MusicpoolsView.prototype.updateSelector = function() { +Rivendell.MusicpoolsView.prototype.updateSelector = function() { var self = this; var $musicpoolSelector = $('#musicpool-selector'); @@ -97,69 +105,61 @@ MusicpoolsView.prototype.updateSelector = function() { $musicpoolSelector.on('change', function() { self.setCurrentPoolId($('option:selected', $musicpoolSelector).attr('value')); - self.getCurrentPool().render(); + self.getCurrentPoolView().render(); }); - this.getCurrentPool().render(); + this.getCurrentPoolView().render(); }; // this and jinglegroup are basicly the same thing -var Musicpool = function(groupName, description, lowcart, highcart, normlevel, trimlevel, title, clock) { +Rivendell.Musicpool = function(groupName, description, lowcart, highcart, normlevel, trimlevel, title, clock) { if (arguments.length === 1) { Rivendell.Group.call(this, groupName); - this.title = $('musicpool-title', this.groupXml).text(); - this.clock = $('musicpool-clock', this.groupXml).text(); + this.title = $('musicpool-title', this.xml).text(); + this.clock = $('musicpool-clock', this.xml).text(); } else { Rivendell.Group.call(this, groupName, description, lowcart, highcart, normlevel, trimlevel); this.title = title; this.clock = clock; } +}; +Rivendell.Musicpool.prototype = Object.create(Rivendell.Group.prototype); +Rivendell.Musicpool.prototype.constructor = Rivendell.Musicpool; - this.carts = []; +Rivendell.MusicpoolView = function(model) { + this.model = model; this.$el = null; }; -Musicpool.prototype = Object.create(Rivendell.Group.prototype); -Musicpool.prototype.constructor = Musicpool; -Musicpool.prototype.render = function() { +Rivendell.MusicpoolView.prototype.render = function() { var self = this; - this.fetchCarts(function() { + this.model.fetchCarts(function() { self.$el = $('#hiddenTemplates .musicpoolTemplate').clone().removeClass('musicpoolTemplate'); $('#app-musicpools .musicpoolContainer').html(self.$el); - $('h2', self.$el).html(self.title); + $('h2', self.$el).html(self.model.title); $('table tbody tr', self.$el).remove(); // todo /*$('.uploadButton', self.$el).on('click', function() { - importer.showUploadModal(self); + importer.showUploadModal(self.model); });*/ }); }; -Musicpool.prototype.fetchCarts = function(success) { +Rivendell.Musicpool.prototype.fetchCarts = function(success) { 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 cart = new Rivendell.Cart(cartXml, self); var cuts = $('cutList', cartXml).children(); - cart.cut = new MusicpoolCut( - cart, - cart.number, - $('cutName', cuts[0]).find().text(), - $('description', cuts[0]).find().text() - ); + cart.cuts.push(new Rivendell.Cut(cuts[0], cart)); self.carts.push(cart); }); @@ -168,21 +168,8 @@ Musicpool.prototype.fetchCarts = function(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; +Rivendell.MusicpoolCutView = function(model) { + this.model = model; this.$el = null; }; |