summaryrefslogtreecommitdiff
path: root/www/js/musicpools.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/musicpools.js')
-rw-r--r--www/js/musicpools.js45
1 files changed, 36 insertions, 9 deletions
diff --git a/www/js/musicpools.js b/www/js/musicpools.js
index f164d13..58359ad 100644
--- a/www/js/musicpools.js
+++ b/www/js/musicpools.js
@@ -23,25 +23,29 @@
'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() {
- rivendell = null;
musicpoolsView = null;
+ importer = null;
+ rivendell = null;
}
var MusicpoolsView = function(model) {
this.model = model;
- this.currentPoolId = sessionStorage.getItem("currentPoolId");
+ this.currentPoolId = sessionStorage.getItem('currentPoolId');
var self = this;
this.model.fetch(function() {
@@ -49,17 +53,27 @@ var MusicpoolsView = function(model) {
});
};
+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.currentPoolId = 0;
- }
- if (this.currentPoolId > this.model.groups.length) {
- this.currentPoolId = 0;
+ this.setCurrentPoolId(this.model.groups[0].clock);
}
- return this.model.groups[this.currentPoolId];
+ 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() {
@@ -68,13 +82,18 @@ MusicpoolsView.prototype.updateSelector = function() {
$('option', $musicpoolSelector).remove();
- // todo: add from list
$(this.model.groups).each(function(index, musicpool) {
var name = musicpool.title + ' (' + musicpool.clock + ')';
- $musicpoolSelector.append($('<option>').attr('value', musicpool.title).text(name));
+ $musicpoolSelector.append($('<option>').attr('value', musicpool.clock).text(name));
});
+ if (this.currentPoolId === null) {
+ this.setCurrentPoolId(this.model.groups[0].clock);
+ }
+ $('option[value="' + this.currentPoolId + '"]', $musicpoolSelector).attr('selected', 'selected');
+
$musicpoolSelector.on('change', function() {
+ self.setCurrentPoolId($('option:selected', $musicpoolSelector).attr('value'));
self.getCurrentPool().render();
});
@@ -106,6 +125,14 @@ Musicpool.prototype.render = function() {
self.$el = $('#hiddenTemplates .musicpoolTemplate').clone().removeClass('musicpoolTemplate');
$('#app-musicpools .musicpoolContainer').html(self.$el);
+ $('h2', self.$el).html(self.title);
+ $('table tbody tr', self.$el).remove();
+
+ // todo
+ /*$('.uploadButton', self.$el).on('click', function() {
+ importer.showUploadModal(self);
+ });*/
+
});
};