summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/jingles.js53
-rw-r--r--www/js/musicpools.js64
-rw-r--r--www/js/rivendell.js42
-rw-r--r--www/js/rivendell.rh.js67
4 files changed, 120 insertions, 106 deletions
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($('<option>').attr('value', musicpool.title).text(name));
+ $musicpoolSelector.append($('<option>').attr('value', musicpool.title).text(name));
});
- var self = this;
- $('#musicpool-selector').on('change', function() {
+ $musicpoolSelector.on('change', function() {
self.getCurrentPool().render();
});
diff --git a/www/js/rivendell.js b/www/js/rivendell.js
index 8331093..ffa138a 100644
--- a/www/js/rivendell.js
+++ b/www/js/rivendell.js
@@ -63,6 +63,15 @@ Rivendell.Rivendell.prototype.listServices = function(success) {
return $.post(this.rdxportEndpoint, command, success, "xml");
};
+Rivendell.Rivendell.prototype.listGroups = function(success) {
+ var command = {
+ COMMAND: 4,
+ LOGIN_NAME: this.username,
+ PASSWORD: this.token
+ };
+ return $.post(this.rdxportEndpoint, command, success, "xml");
+};
+
Rivendell.Rivendell.prototype.listGroup = function(groupName, success) {
var command = {
COMMAND: 5,
@@ -73,11 +82,13 @@ Rivendell.Rivendell.prototype.listGroup = function(groupName, success) {
return $.post(this.rdxportEndpoint, command, success, "xml");
};
-Rivendell.Rivendell.prototype.listGroups = function(success) {
+Rivendell.Rivendell.prototype.listCarts = function(groupName, includeCuts, success) {
var command = {
- COMMAND: 4,
+ COMMAND: 6,
LOGIN_NAME: this.username,
- PASSWORD: this.token
+ PASSWORD: this.token,
+ GROUP_NAME: groupName,
+ INCLUDE_CUTS: includeCuts
};
return $.post(this.rdxportEndpoint, command, success, "xml");
};
@@ -93,17 +104,6 @@ Rivendell.Rivendell.prototype.listCart = function(cartNumber, includeCuts, succe
return $.post(this.rdxportEndpoint, command, success);
};
-Rivendell.Rivendell.prototype.listCarts = function(groupName, includeCuts, success) {
- var command = {
- COMMAND: 6,
- LOGIN_NAME: this.username,
- PASSWORD: this.token,
- GROUP_NAME: groupName,
- INCLUDE_CUTS: includeCuts
- };
- return $.post(this.rdxportEndpoint, command, success, "xml");
-};
-
Rivendell.Rivendell.prototype.addCart = function(groupName, type, cartNumber, success) {
var command = {
COMMAND: 12,
@@ -134,23 +134,23 @@ Rivendell.Rivendell.prototype.removeCart = function(cartNumber, success) {
return $.post(this.rdxportEndpoint, command, success, "xml");
};
-Rivendell.Rivendell.prototype.listCut = function(cartNumber, cutNumber, success) {
+Rivendell.Rivendell.prototype.listCuts = function(cartNumber, success) {
var command = {
- COMMAND: 8,
+ COMMAND: 9,
LOGIN_NAME: this.username,
PASSWORD: this.token,
- CART_NUMBER: cartNumber,
- CUT_NUMBER: cutNumber
+ CART_NUMBER: cartNumber
};
return $.post(this.rdxportEndpoint, command, success, 'xml');
};
-Rivendell.Rivendell.prototype.listCuts = function(cartNumber, success) {
+Rivendell.Rivendell.prototype.listCut = function(cartNumber, cutNumber, success) {
var command = {
- COMMAND: 9,
+ COMMAND: 8,
LOGIN_NAME: this.username,
PASSWORD: this.token,
- CART_NUMBER: cartNumber
+ CART_NUMBER: cartNumber,
+ CUT_NUMBER: cutNumber
};
return $.post(this.rdxportEndpoint, command, success, 'xml');
};
diff --git a/www/js/rivendell.rh.js b/www/js/rivendell.rh.js
index dfcadcd..fdacd85 100644
--- a/www/js/rivendell.rh.js
+++ b/www/js/rivendell.rh.js
@@ -22,6 +22,8 @@
'use strict';
+var Rivendell = Rivendell || {};
+
Rivendell.Rivendell.prototype.setListDropboxesEndpoint = function(listDropboxesEndpoint) {
this.listDropboxesEndpoint = listDropboxesEndpoint;
};
@@ -32,9 +34,11 @@ Rivendell.Rivendell.prototype.setMusicgridEndpoint = function(musicgridEndpoint)
Rivendell.Rivendell.prototype.listDropboxes = function(type, success) {
var command = {
LOGIN_NAME: this.username,
- PASSWORD: this.token,
- TYPE: type
+ PASSWORD: this.token
};
+ if (type !== null) {
+ command.TYPE = type;
+ }
return $.post(this.listDropboxesEndpoint, command, success, 'xml');
};
@@ -67,3 +71,62 @@ Rivendell.Rivendell.prototype.setMusicgrid = function(dow, hour, name, success)
};
return $.post(this.musicgridEndpoint, command, success, "xml");
};
+
+Rivendell.GroupList = function(rivendell, type) {
+ this.rivendell = rivendell;
+
+ this.type = type;
+
+ this.groups = [];
+};
+
+Rivendell.GroupList.prototype.fetch = function(success) {
+ this.groups = [];
+
+ var self = this;
+ this.rivendell.listDropboxes(this.type, function(groupsXml, status, req) {
+ var dbs = $('dropboxList', groupsXml).children();
+ dbs.each(function(index, groupXml) {
+ switch ($('type', groupXml).text()) {
+ case 'show':
+ // todo
+ break;
+ case 'jingle':
+ var group = 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()
+ );
+ break;
+ case 'musicpool':
+ var group = 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()
+ );
+ break;
+ }
+
+ self.groups.push(group);
+ });
+
+ if (success) {
+ success();
+ }
+ });
+};
+
+Rivendell.GroupList.prototype.destroy = function() {
+ $(this.groups).each(function(index, group) {
+ group.destroy();
+ });
+};