From c84b446a7ace4f672e6cd0b4679df3e614bd2f70 Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Thu, 28 Jan 2016 18:15:10 +0100 Subject: combine JingleGroupList and Musicpools to GroupList class diff --git a/www/js/jingles.js b/www/js/jingles.js index e13f218..c633339 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -23,59 +23,28 @@ 'use strict'; var rivendell = null; -var jinglesGroupList = null; +var groupList = null; var importer = null; function jingles_init() { rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi'); rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi'); importer = new Importer(); - jinglesGroupList = new JingleGroupList(); - jinglesGroupList.fetch(); + + groupList = new Rivendell.GroupList(rivendell, 'jingle'); + // todo: move this elsewhere? + $('#app-jingles .groups').html(''); + groupList.fetch(); } function jingles_cleanup() { - if (jinglesGroupList) { - jinglesGroupList.destroy(); - jinglesGroupList = null; + if (groupList) { + groupList.destroy(); + groupList = null; } rivendell = null; } -var JingleGroupList = function() { - this.groups = []; -}; - -JingleGroupList.prototype.fetch = function() { - this.groups = []; - $('#app-jingles .groups').html(''); - - var self = this; - rivendell.listDropboxes('jingle', function(groupsXml, status, req) { - var dbs = $(groupsXml).find("dropboxList").children(); - dbs.each(function(index, groupXml) { - var jingleGroup = new JingleGroup( - $('jingle-title', groupXml).text(), - $('group', groupXml).text(), - $('group-description', groupXml).text(), - $('group-low-cart', groupXml).text(), - $('group-high-cart', groupXml).text(), - $('normalization-level', groupXml).text(), - $('autotrim-level', groupXml).text() - ); - - self.groups.push(jingleGroup); - }); - }); -}; - -JingleGroupList.prototype.destroy = function() { - // todo: implement - $(this.groups).each(function(index, group) { - group.destroy(); - }); -}; - var JingleGroup = function(title, groupName, description, lowcart, highcart, normlevel, trimlevel) { this.title = title; this.groupName = groupName; @@ -212,8 +181,8 @@ JingleCut.prototype.move = function() { var self = this; var destinationCart = this.cartNumber; // todo: make this work for multiple groups - if (jinglesGroupList.groups.length === 2) { - $(jinglesGroupList.groups).each(function(index, group) { + if (groupList.groups.length === 2) { + $(groupList.groups).each(function(index, group) { if (self.active) { if (self.cartNumber !== group.mainCart.number) { destinationCart = group.mainCart; diff --git a/www/js/musicpools.js b/www/js/musicpools.js index 93d4824..f164d13 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -23,76 +23,58 @@ 'use strict'; var rivendell = null; -var musicpools = 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'); - musicpools = new Musicpools(); + + var musicpools = new Rivendell.GroupList(rivendell, 'musicpool'); + musicpoolsView = new MusicpoolsView(musicpools); } function musicpools_cleanup() { rivendell = null; + musicpoolsView = null; } -// this and jinglegroups are basicly the same -var Musicpools = function() { - // todo: get current Pool Id from session like shows? +var MusicpoolsView = function(model) { + this.model = model; + this.currentPoolId = sessionStorage.getItem("currentPoolId"); - this.musicpools = []; - this.fetch(); + + var self = this; + this.model.fetch(function() { + self.updateSelector(); + }); }; -Musicpools.prototype.getCurrentPool = function() { - if (this.musicpools.length === 0) { +MusicpoolsView.prototype.getCurrentPool = function() { + if (this.model.groups.length === 0) { return null; } if (this.currentPoolId === null) { this.currentPoolId = 0; } - if (this.currentPoolId > this.musicpools.length) { + if (this.currentPoolId > this.model.groups.length) { this.currentPoolId = 0; } - return this.musicpools[this.currentPoolId]; + return this.model.groups[this.currentPoolId]; }; -Musicpools.prototype.fetch = function() { +MusicpoolsView.prototype.updateSelector = function() { var self = this; + var $musicpoolSelector = $('#musicpool-selector'); - rivendell.listDropboxes('musicpool', function(groupsXml, status, req) { - self.musicpools = []; - - var dbs = $(groupsXml).find("dropboxList").children(); - dbs.each(function(index, groupXml) { - var musicpool = new Musicpool( - $('musicpool-title', groupXml).text(), - $('musicpool-clock', groupXml).text(), - $('group', groupXml).text(), - $('group-description', groupXml).text(), - $('group-low-cart', groupXml).text(), - $('group-high-cart', groupXml).text(), - $('normalization-level', groupXml).text(), - $('autotrim-level', groupXml).text() - ); - - self.musicpools.push(musicpool); - }); - - self.updateSelector(); - }); -}; - -Musicpools.prototype.updateSelector = function() { - $('#musicpool-selector').find('option').remove(); + $('option', $musicpoolSelector).remove(); // todo: add from list - $(this.musicpools).each(function(index, musicpool) { + $(this.model.groups).each(function(index, musicpool) { var name = musicpool.title + ' (' + musicpool.clock + ')'; - $('#musicpool-selector').append($('