/* * 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 musicpoolsView = null; function musicpools_init() { var musicpools = new Rivendell.GroupList(rivendell); musicpoolsView = new Rivendell.MusicpoolsView(musicpools); } function musicpools_cleanup() { musicpoolsView = null; rivendell = null; } Rivendell.MusicpoolsView = function(model) { this.model = model; this.musicpoolViews = []; this.currentPoolId = sessionStorage.getItem('currentPoolId'); var self = this; $(this.model).on('update', function() { $(self.model.groups).each(function(index, musicpool) { var musicpoolView = new Rivendell.MusicpoolView(musicpool); self.musicpoolViews.push(musicpoolView); }); self.updateSelector(); }); this.model.fetch('musicpool'); }; Rivendell.MusicpoolsView.prototype.setCurrentPoolId = function(currentPoolId) { this.currentPoolId = currentPoolId; sessionStorage.setItem('currentPoolId', this.currentPoolId); }; 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 musicpoolViewFound = null; $(this.musicpoolViews).each(function(index, musicpoolView) { if (musicpoolView.model.clock === self.currentPoolId) { musicpoolViewFound = musicpoolView; return true; } }); return musicpoolViewFound; }; Rivendell.MusicpoolsView.prototype.updateSelector = function() { var self = this; var $musicpoolSelector = $('#musicpool-selector'); $musicpoolSelector.off(); $('option', $musicpoolSelector).remove(); $(this.model.groups).each(function(index, musicpool) { var name = musicpool.title + ' (' + musicpool.clock + ')'; $musicpoolSelector.append($('