summaryrefslogtreecommitdiff
path: root/www/js/musicgrid.js
diff options
context:
space:
mode:
authorPeterTheOne <petertheone@gmail.com>2016-01-29 00:09:17 (GMT)
committerPeterTheOne <petertheone@gmail.com>2016-01-29 00:09:17 (GMT)
commite0ad0c1481387e73b1d2b00c0c35d7ef85db2dff (patch)
tree2eadd8af2046166e42caf7bee97459da3dd97a90 /www/js/musicgrid.js
parent1ef5a5a1aac0e562c0b3b81c0cb7eb5997b02bd5 (diff)
jingles: use Rivendell.Cart and Cut classes with Views, etc.
validate html, move rivendell.js init to apps.js, cleanup importer, add update event to fetch functions instead of success callback.
Diffstat (limited to 'www/js/musicgrid.js')
-rw-r--r--www/js/musicgrid.js40
1 files changed, 24 insertions, 16 deletions
diff --git a/www/js/musicgrid.js b/www/js/musicgrid.js
index 221f489..d95fb1e 100644
--- a/www/js/musicgrid.js
+++ b/www/js/musicgrid.js
@@ -24,15 +24,10 @@
var Rivendell = Rivendell || {};
-var rivendell = null;
var musicgridView = null;
var musicpoolModal = null;
function musicgrid_init() {
- rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi');
- rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi');
- rivendell.setMusicgridEndpoint('/rh-bin/musicgrid.cgi');
-
var musicgrid = new Rivendell.Musicgrid();
musicgridView = new Rivendell.MusicgridView(musicgrid);
@@ -42,24 +37,37 @@ function musicgrid_init() {
function musicgrid_cleanup() {
musicpoolModal = null;
+
+ musicgridView.clean();
musicgridView = null;
- rivendell = null;
}
Rivendell.MusicgridView = function(model) {
this.model = model;
+ this.$el = $('#app-musicgrid table');
+
var self = this;
- this.model.fetch(function() {
- self.updateTable();
+ $(this.model).on('update', function() {
+ self.update();
});
+ this.model.fetch();
};
-Rivendell.MusicgridView.prototype.updateTable = function() {
- var $table = $('#app-musicgrid table');
- $('tr td', $table).html('').removeClass('clock').css('background-color', '').css('color', '').attr('title', null);
+Rivendell.MusicgridView.prototype.clean = function() {
+ $('tr td', this.$el)
+ .html('')
+ .removeClass('clock')
+ .css('background-color', '')
+ .css('color', '')
+ .attr('title', null);
+};
+
+Rivendell.MusicgridView.prototype.update = function() {
+ this.clean();
+
$(this.model.clocks).each(function(index, clock) {
- var $td = $('tr[data-dow="' + clock.dow + '"] td[data-hour="' + clock.hour +'"]', $table);
+ var $td = $('tr[data-dow="' + clock.dow + '"] td[data-hour="' + clock.hour +'"]', this.$el);
$td.addClass('clock');
$td.html(clock.name);
$td.attr('title', clock.title);
@@ -76,10 +84,9 @@ Rivendell.MusicgridView.prototype.updateTable = function() {
});
});
- $('tr td:not(.clock)', $table).off().on('click', function() {
+ $('tr td:not(.clock)', this.$el).off().on('click', function() {
musicpoolModal.selectClock($(this).parent().data('dow'), $(this).data('hour'), null);
});
-
};
Rivendell.MusicpoolModal = function(model) {
@@ -97,7 +104,7 @@ Rivendell.MusicpoolModal.prototype.selectClock = function(dow, hour, clockName)
$('tbody', $modalBody).html('');
var self = this;
- this.model.fetch('musicpool', function() {
+ $(this.model).on('update', function() {
$(self.model.groups).each(function(index, musicpool) {
var $button = null;
if (clockName === musicpool.clock) {
@@ -109,7 +116,7 @@ Rivendell.MusicpoolModal.prototype.selectClock = function(dow, hour, clockName)
$button.on('click', function() {
rivendell.setMusicgrid(dow, hour, musicpool.clock, function() {
$('#musicpoolModal').modal('hide');
- musicgrid.fetch();
+ musicgridView.modal.fetch();
});
});
@@ -121,4 +128,5 @@ Rivendell.MusicpoolModal.prototype.selectClock = function(dow, hour, clockName)
$('tbody', $modalBody).append($tr);
});
});
+ this.model.fetch('musicpool');
};