summaryrefslogtreecommitdiff
path: root/www/js/shows.js
diff options
context:
space:
mode:
authorPeter Grassberger <petertheone@gmail.com>2016-02-10 05:00:16 (GMT)
committerPeter Grassberger <petertheone@gmail.com>2016-02-10 05:00:16 (GMT)
commit8ce69bbc3ef2974ab1bc4b02b5320827a1ae9935 (patch)
tree7824611556568eb191228ab7f4a6b154eef123f1 /www/js/shows.js
parent6f2d7a5dd61746a114488151cda132e032b10bb1 (diff)
shows rewrite (import still missing)
Diffstat (limited to 'www/js/shows.js')
-rw-r--r--www/js/shows.js281
1 files changed, 259 insertions, 22 deletions
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($('<option>').attr('value', show.id).text(name));
+ });
+
+ if (this.currentShowId === null) {
+ this.setCurrentShowId(this.model.groups[0].id);
+ }
+ $('option[value="' + this.currentShowId + '"]', $showSelector).attr('selected', 'selected');
+
+ $showSelector.on('change', function() {
+ self.setCurrentShowId($('option:selected', $showSelector).attr('value'));
+ self.getCurrentShowView().model.fetchCartsAndLogs();
+ });
+
+ this.getCurrentShowView().model.fetchCartsAndLogs();
+};
+
+Rivendell.Show = function(groupName, description, lowcart, highcart, normlevel, trimlevel,
+ id, title, log, rhythm, dayofweek, starttime, length) {
+ if (arguments.length = 1) {
+ Rivendell.Group.call(this, groupName);
+ this.id = $('show-id', this.xml).text();
+ this.title = $('show-title', this.xml).text();
+ this.log = $('show-log', this.xml).text();
+ this.rhythm = $('show-rhythm', this.xml).text();
+ this.dayofweek = $('show-dayofweek', this.xml).text();
+ this.starttime = $('show-starttime', this.xml).text();
+ this.length = $('show-length', this.xml).text();
+ } else {
+ Rivendell.Group.call(this, groupName, description, lowcart, highcart, normlevel, trimlevel);
+ this.id = id;
+ this.title = title;
+ this.log = log;
+ this.rhythm = rhythm;
+ this.dayofweek = dayofweek;
+ this.starttime = starttime;
+ this.length = length;
+ }
+
+ this.logs = [];
+};
+Rivendell.Show.prototype = Object.create(Rivendell.Group.prototype);
+Rivendell.Show.prototype.constructor = Rivendell.Show;
+
+Rivendell.Show.prototype.fetchCartsAndLogs = function() {
+ var self = this;
+
+ var lcd = rivendell.listLog(this.log, function(logsXml, status, req) {
+ self.logs = [];
+
+ var loglines = $('logList', logsXml).children();
+ loglines.each(function(index, logXml) {
+ var log = Rivendell.Log.newFromXml(logXml, self);
+ if(log.cartNumber >= self.lowcart &&
+ log.cartNumber <= self.highcart) {
+ self.logs.push(log);
+ }
+ });
+ });
+
+ var gcd = rivendell.listCarts(this.groupName, 1, function(cartsXml, status, req) {
+ self.carts = [];
+
+ var dbs = $('cartList', cartsXml).children();
+ dbs.each(function(index, cartXml) {
+ var cart = new Rivendell.Cart(cartXml, self);
+
+ var cuts = $('cutList', cartXml).children();
+ cuts.each(function(index, cut) {
+ cart.cuts.push(new Rivendell.Cut(cut, cart));
+ });
+
+ self.addCart(cart);
+ });
+ });
+
+ $.when(lcd, gcd).done(function(lcres, gcres) {
+ if(lcres[1] == 'success' && gcres[1] == 'success') {
+ self.$this.trigger('update');
+ }
+ });
+};
+
+Rivendell.ShowView = function(model) {
+ this.model = model;
+ this.cartViews = [];
+
+ this.$el = null;
+
+ var self = this;
+ this.model.$this.on('update', function() {
+ self.render();
+ });
+};
+
+Rivendell.ShowView.prototype.render = function() {
+ $('#show-title').text(this.model.title);
+ $('#show-dow').text(weekday[this.model.dayofweek]);
+ $('#show-rhythm').text(this.model.rhythm);
+ $('#show-starttime').text(this.model.starttime);
+ $('#show-length').text(this.model.length + ' Min.');
+
+ var $tableBody = $('#app-shows table tbody');
+ $('tr', $tableBody).remove();
+
+ var self = this;
+ this.cartViews = [];
+ $(this.model.logs).each(function(index, log) {
+ var cart = self.model.getCartByNumber(log.cartNumber);
+ if (cart) {
+ var cartView = new Rivendell.ShowCartView(cart);
+ self.cartViews.push(cartView);
+ cartView.render();
+
+ $('#app-shows table > tbody').append(cartView.$el);
+ } else {
+ var cart = new Rivendell.Cart(log.cartNumber, '-', '-', null);
+ var cartView = new Rivendell.ShowCartView(cart);
+ cartView.renderEmpty();
+ $('#app-shows table > tbody').append(cartView.$el);
+ }
+ });
+};
+
+Rivendell.ShowCartView = function(model) {
+ this.model = model;
+
+ this.$spinner = null;
+ this.$el = $('<tr>');
+};
+
+Rivendell.ShowCartView.prototype.render = function() {
+ var $deleteButton = $('<button class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span>&nbsp;&nbsp;Löschen</button>');
+
+ var self = this;
+ $deleteButton.on('click', function() {
+ self.delete();
+ });
+
+ this.$spinner = $('#hiddenTemplates .spinnerTemplate').clone().removeClass('spinnerTemplate');
+
+ var cut = this.model.cuts[0];
+ this.$el = this.$el.empty()
+ .attr('id', 'show-cart-' + this.model.number)
+ .append($('<td>').text(this.model.number))
+ .append($('<td>').text(this.model.title))
+ .append($('<td>').text(msToTimeString(Number(cut.length))))
+ .append($('<td>').text(format_datetime(new Date(cut.originDatetime))))
+ .append($('<td>').text(cut.playCounter))
+ .append($('<td>').text(format_datetime(new Date(cut.lastPlayDatetime))))
+ .append($('<td>').css('text-align', 'center').append($deleteButton));
+};
+
+Rivendell.ShowCartView.prototype.renderEmpty = function() {
+ var buttons = '<button class="btn btn-primary btn-xs">' +
+ '<span class="glyphicon glyphicon-upload"></span>&nbsp;&nbsp;Importieren</button>';
+
+ this.$el = this.$el.empty()
+ .attr('id', 'show-cart-' + this.model.number)
+ .append($('<td>').text(this.model.number))
+ .append($('<td>').text('-'))
+ .append($('<td>').text('-'))
+ .append($('<td>').text('-'))
+ .append($('<td>').text('-'))
+ .append($('<td>').text('-'))
+ .append($('<td>').css('text-align', 'center').append(buttons));
+};
+
+Rivendell.ShowCartView.prototype.delete = function() {
+ $('td:last', this.$el).html(this.$spinner);
+
+ var self = this;
+ rivendell.removeCart(this.model.number, function() {
+ self.model.group.removeCart(self.model);
+ self.renderEmpty();
+ });
+};
+
+
+
function shows_deleteCart(cart) {
rivendell.removeCart(cart, function() {
@@ -226,7 +480,7 @@ function shows_redrawCartEntry(cart) {
$('#show-cart-' + cart).replaceWith(shows_newCartEntry(cart));
}
-function shows_updateCartListing() {
+/*function shows_updateCartListing() {
$('#show-carts tbody').find('tr').remove();
shows_log_carts.forEach(function(elem) {
$('#show-carts > tbody:last').append(shows_newCartEntry(elem));
@@ -323,21 +577,4 @@ function shows_updateList(data, status, req) {
});
$('#show-selector').val(shows_currentid);
shows_showSelected();
-}
-
-function shows_init() {
- shows_currentid = sessionStorage.getItem("shows_currentid");
- shows_list = [];
- rivendell.listDropboxes('show', shows_updateList);
- 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 = [];
-}
+}*/