/* * rhwebimport * * Copyright (C) 2014-2016 Christian Pointner * Copyright (C) 2015-2016 Peter Grassberger * * This file is part of rhwebimport. * * rhwebimport is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * rhwebimport is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with rhwebimport. If not, see . */ 'use strict'; var Rivendell = Rivendell || {}; var musicgridView = null; var musicpoolModal = null; function musicgrid_init() { var musicgrid = new Rivendell.Musicgrid(); musicgridView = new Rivendell.MusicgridView(musicgrid); var musicpools = new Rivendell.GroupList(rivendell); musicpoolModal = new Rivendell.MusicpoolModal(musicpools); } function musicgrid_cleanup() { musicpoolModal = null; musicgridView.clean(); musicgridView = null; } Rivendell.MusicgridView = function(model) { this.model = model; this.$el = $('#app-musicgrid table'); var self = this; $(this.model).on('update', function() { self.update(); }); this.model.fetch(); }; 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 +'"]', this.$el); $td.addClass('clock'); $td.html(clock.name); $td.attr('title', clock.title); $td.css('background-color', clock.color); if($td.isBackgroundDark()) { $td.css('color', '#ffffff'); } // todo: move this css to stylesheet $td.css('text-align', 'center'); $td.off().on('click', function() { musicpoolModal.selectClock(clock.dow, clock.hour, clock.name); }); }); $('tr td:not(.clock)', this.$el).off().on('click', function() { musicpoolModal.selectClock($(this).parent().data('dow'), $(this).data('hour'), null); }); }; Rivendell.MusicpoolModal = function(model) { this.model = model; }; Rivendell.MusicpoolModal.prototype.selectClock = function(dow, hour, clockName) { $('#musicpoolModal').modal({keyboard: true}); var $modalHeader = $('#musicpoolModal .modal-header'); var $modalBody = $('#musicpoolModal .modal-body'); $('h3', $modalHeader).html('Musikpool auswählen für Tag: ' + dow + ' Stunde: ' + hour + '.'); $('tbody', $modalBody).html(''); var self = this; $(this.model).on('update', function() { $(self.model.groups).each(function(index, musicpool) { var $button = null; if (clockName === musicpool.clock) { $button = $(''); } else { $button = $(''); } $button.on('click', function() { rivendell.setMusicgrid(dow, hour, musicpool.clock, function() { $('#musicpoolModal').modal('hide'); musicgridView.modal.fetch(); }); }); var $tr = $(''); $tr.append($('').html(musicpool.clock)); $tr.append($('').html(musicpool.title)); $tr.append($('').html($button)); $('tbody', $modalBody).append($tr); }); }); this.model.fetch('musicpool'); };