/* * 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 = null; var importer = null; var musicpoolsView = null; function musicpools_init() { rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi'); rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi'); importer = new Rivendell.Importer(); var musicpools = new Rivendell.GroupList(rivendell, 'musicpool'); musicpoolsView = new MusicpoolsView(musicpools); } function musicpools_cleanup() { musicpoolsView = null; importer = null; rivendell = null; } var MusicpoolsView = function(model) { this.model = model; this.currentPoolId = sessionStorage.getItem('currentPoolId'); var self = this; this.model.fetch(function() { self.updateSelector(); }); }; MusicpoolsView.prototype.setCurrentPoolId = function(currentPoolId) { this.currentPoolId = currentPoolId; sessionStorage.setItem('currentPoolId', this.currentPoolId); }; MusicpoolsView.prototype.getCurrentPool = function() { if (this.model.groups.length === 0) { return null; } if (this.currentPoolId === null) { this.setCurrentPoolId(this.model.groups[0].clock); } var self = this; var musicpoolFound = null; $(this.model.groups).each(function(index, musicpool) { if (musicpool.clock === self.currentPoolId) { musicpoolFound = musicpool; return true; } }); return musicpoolFound; }; 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($('