From 8ce69bbc3ef2974ab1bc4b02b5320827a1ae9935 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Wed, 10 Feb 2016 06:00:16 +0100 Subject: shows rewrite (import still missing) diff --git a/www/index.html b/www/index.html index 7b63a38..d6599f8 100644 --- a/www/index.html +++ b/www/index.html @@ -137,7 +137,7 @@    - diff --git a/www/js/musicpools.js b/www/js/musicpools.js index e77c23c..28fcabb 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -187,8 +187,6 @@ Rivendell.MusicpoolCartView = function(model) { }; Rivendell.MusicpoolCartView.prototype.render = function() { - var number = this.model.number; - var length = '-'; var imported = '-'; var playcnt = '-'; @@ -218,7 +216,7 @@ Rivendell.MusicpoolCartView.prototype.render = function() { this.$el = $('') .attr('id', 'musicpool-' + this.model.number) - .append($('').text(number)) + .append($('').text(this.model.number)) .append($('').text(this.model.title)) .append($('').text(this.model.artist)) .append($('').text(this.model.album)) diff --git a/www/js/rdxport.js b/www/js/rdxport.js index 91944ac..35c1b7d 100644 --- a/www/js/rdxport.js +++ b/www/js/rdxport.js @@ -359,6 +359,8 @@ Rivendell.GroupList = function(rivendell) { Rivendell.Group = function(groupName, description, lowcart, highcart, normlevel, trimlevel) { this.xml = null; + // looks strange but child somehow can't do use $(this) otherwise. + this.$this = $(this); if (arguments.length === 1) { this.xml = arguments[0]; @@ -378,10 +380,16 @@ Rivendell.Group = function(groupName, description, lowcart, highcart, normlevel, } this.carts = []; + this.cartsByNumber = {}; +}; + +Rivendell.Group.prototype.getCartByNumber = function(number) { + return this.cartsByNumber[number] ? this.cartsByNumber[number] : null; }; Rivendell.Group.prototype.addCart = function(cart) { this.carts.push(cart); + this.cartsByNumber[cart.number] = cart; }; Rivendell.Group.prototype.removeCart = function(cart) { @@ -391,12 +399,14 @@ Rivendell.Group.prototype.removeCart = function(cart) { self.carts.splice(index, 1); } }); + delete this.cartsByNumber[cart.number]; }; Rivendell.Group.prototype.fetchCarts = function() { var self = this; rivendell.listCarts(this.groupName, 1, function(cartsXml, status, req) { self.carts = []; + self.cartsByNumber = {}; var dbs = $('cartList', cartsXml).children(); dbs.each(function(index, cartXml) { @@ -407,12 +417,58 @@ Rivendell.Group.prototype.fetchCarts = function() { cart.cuts.push(new Rivendell.Cut(cut, cart)); }); - self.carts.push(cart); + self.addCart(cart); }); $(self).trigger('update'); }); }; +Rivendell.Log = function(line, id, type, cartType, cartNumber, cutNumber, groupName, groupColor, title, group) { + /*this.xml = null; + + if (arguments.length === 2) { + this.xml = arguments[0]; + this.line = $('line', this.xml).text(); + this.id = $('id', this.xml).text(); + this.type = $('type', this.xml).text(); + this.cartType = $('cartType', this.xml).text(); + this.cartNumber = $('cartNumber', this.xml).text(); + this.cutNumber = $('cutNumber', this.xml).text(); + this.groupName = $('groupName', this.xml).text(); + this.groupColor = $('groupColor', this.xml).text(); + this.title = $('title', this.xml).text(); + this.group = arguments[1]; + } else {*/ + this.line = line; + this.id = id; + this.type = type; + this.cartType = cartType; + this.cartNumber = cartNumber; + this.cutNumber = cutNumber; + this.groupName = groupName; + this.groupColor = groupColor; + this.title = title; + this.group = group; + //} +}; + +Rivendell.Log.newFromXml = function(xml, group) { + var log = new Rivendell.Log( + $('line', xml).text(), + $('id', xml).text(), + $('type', xml).text(), + $('cartType', xml).text(), + $('cartNumber', xml).text(), + $('cutNumber', xml).text(), + $('groupName', xml).text(), + $('groupColor', xml).text(), + $('title', xml).text(), + group + ); + log.xml = xml; + return log; +}; + Rivendell.Cart = function(number, title, groupName, group) { this.xml = null; diff --git a/www/js/rdxport.rh.js b/www/js/rdxport.rh.js index a80e6de..3c1bdfe 100644 --- a/www/js/rdxport.rh.js +++ b/www/js/rdxport.rh.js @@ -92,9 +92,9 @@ Rivendell.GroupList.prototype.fetch = function(type) { dbs.each(function(index, groupXml) { var group = null; switch ($('type', groupXml).text()) { - /*case 'show': - // todo - break;*/ + case 'show': + group = new Rivendell.Show(groupXml); + break; case 'jingle': group = new Rivendell.JingleGroup(groupXml); break; diff --git a/www/js/shows.js b/www/js/shows.js index 84d49a5..91c4bc0 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -24,12 +24,266 @@ var Rivendell = Rivendell || {}; -var shows_currentid = null; +/*var shows_currentid = null; var shows_list = []; var shows_current; var shows_group_carts = {}; -var shows_log_carts = []; -var shows_clock; +var shows_log_carts = [];*/ + +var showListView = null; + +function shows_init() { + /*shows_currentid = sessionStorage.getItem("shows_currentid"); + shows_list = []; + rivendell.listDropboxes('show', shows_updateList);*/ + + var showList = new Rivendell.GroupList(rivendell); + showListView = new Rivendell.ShowListView(showList); + + drawClock('Do, 1.1.1970', '00:00:00', 0); + clock_add_callback(drawClock); +} + +function shows_cleanup() { + $('#show-carts tbody').find('tr').remove(); + /*sessionStorage.removeItem("shows_currentid"); + shows_currentid = null; + shows_list = []; + shows_group_carts = {}; + shows_log_carts = [];*/ +} + +Rivendell.ShowListView = function(model) { + this.model = model; + + this.showViews = []; + this.currentShowId = sessionStorage.getItem('currentShowId'); + + var self = this; + $(this.model).on('update', function() { + $(self.model.groups).each(function(index, show) { + var showView = new Rivendell.ShowView(show); + self.showViews.push(showView); + }); + self.updateSelector(); + }); + this.model.fetch('show'); +}; + +Rivendell.ShowListView.prototype.setCurrentShowId = function(currentShowId) { + this.currentShowId = currentShowId; + sessionStorage.setItem('currentShowId', this.currentShowId); +}; + +Rivendell.ShowListView.prototype.getCurrentShowView = function() { + if (this.model.groups.length === 0) { + return null; + } + if (this.showViews.length === 0) { + return null; + } + if (this.currentShowId === null) { + this.setCurrentShowId(this.model.groups[0].id); + } + var self = this; + var showViewFound = null; + $(this.showViews).each(function(index, showView) { + if (showView.model.id === self.currentShowId) { + showViewFound = showView; + return true; + } + }); + return showViewFound; +}; + +Rivendell.ShowListView.prototype.updateSelector = function() { + var self = this; + var $showSelector = $('#show-selector'); + + $showSelector.off(); + $('option', $showSelector).remove(); + + $(this.model.groups).each(function(index, show) { + var name = show.title + ' (' + show.rhythm + ', ' + weekday[show.dayofweek] + ', ' + show.starttime + ', ' + show.length + ' Min.)'; + $showSelector.append($('