summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
authorPeterTheOne <petertheone@gmail.com>2016-01-28 17:56:10 (GMT)
committerPeterTheOne <petertheone@gmail.com>2016-01-28 17:56:10 (GMT)
commit2eb10afbc4bcc36f4206c79df8ae6c1bcb841ad3 (patch)
treed77dd1ec70b505a26abcc8bbf994dea3239d372d /www
parentc84b446a7ace4f672e6cd0b4679df3e614bd2f70 (diff)
move importer to own file, fix musicpool selector
Diffstat (limited to 'www')
-rw-r--r--www/index.html1
-rw-r--r--www/js/importer.js181
-rw-r--r--www/js/jingles.js187
-rw-r--r--www/js/musicgrid.js1
-rw-r--r--www/js/musicpools.js45
5 files changed, 223 insertions, 192 deletions
diff --git a/www/index.html b/www/index.html
index 110849f..77bf69b 100644
--- a/www/index.html
+++ b/www/index.html
@@ -25,6 +25,7 @@
<script src="/js/rivendell.rh.js"></script>
<script src="/js/utils.js"></script>
<script src="/js/clock.js"></script>
+ <script src="/js/importer.js"></script>
<script src="/js/auth.js"></script>
<script src="/js/apps.js"></script>
<script src="/js/shows.js"></script>
diff --git a/www/js/importer.js b/www/js/importer.js
new file mode 100644
index 0000000..5261f6d
--- /dev/null
+++ b/www/js/importer.js
@@ -0,0 +1,181 @@
+/*
+ * rhwebimport
+ *
+ * Copyright (C) 2014-2016 Christian Pointner <equinox@helsinki.at>
+ * Copyright (C) 2015-2016 Peter Grassberger <petertheone@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+'use strict';
+
+var Rivendell = Rivendell || {};
+
+Rivendell.Importer = function() {
+ this.$el = $('#uploadModal');
+};
+
+Rivendell.Importer.prototype.showUploadModal = function(group) {
+ $('div.modal-header h3', this.$el).text("Datei auswählen...");
+ var form = $('<form>');
+ $('.modal-body', uploadModal).empty().append(form).css("background-image", "url('/img/dz-backdrop.png')");
+ var self = this;
+ var dropzone = form.dropzone({
+ url: '/rd-bin/rdxport.cgi',
+ parallelUploads: 1,
+ maxFilesize: 2048,
+ paramName: 'FILENAME',
+ uploadMultiple: false, // todo: maybe enable this?
+ clickable: true,
+ createImageThumbnails: false,
+ acceptedFiles: '.flac,.wav,.ogg,.mp3',
+ autoProcessQueue: false,
+ init: function() {
+ this.on("addedfile", function(file) {
+ self.importFileAdded(this, file, group);
+ });
+ this.on("error", function(file, msg) {
+ self.importFileSelectError(this, file, msg);
+ });
+ }
+ });
+
+ this.$el.modal({keyboard: true});
+};
+
+Rivendell.Importer.prototype.importFileAdded = function(dropzone, file, group) {
+ $(dropzone.getAcceptedFiles()).each(function(idx, elem) { dropzone.removeFile(elem); });
+
+ $('div.modal-body', this.$el).css("background-image", "url('/img/audio_file.png')");
+ $('div.modal-header h3', this.$el).text(file.name);
+ var self = this;
+ $('#uploadModal-confirm', this.$el).unbind('click').click(function() {
+ self.importCartConfirm(dropzone, group);
+ }).removeAttr('disabled');
+};
+
+Rivendell.Importer.prototype.importFileSelectError = function(dropzone, file, msg) {
+ $('div.modal-header h3', this.$el).text("Datei auswählen...");
+ $('div.modal-body', this.$el).css("background-image", "url('/img/dz-backdrop.png')");
+ $('#uploadModal-confirm', this.$el).attr('disabled','disabled').unbind('click');
+ dropzone.removeFile(file);
+};
+
+Rivendell.Importer.prototype.importCartConfirm = function(dz, group) {
+ this.$el.modal('hide');
+
+ //var progressBar = group.addUpload();
+
+
+
+ //var cart_row = $('#show-cart-' + cart);
+ //cart_row.find('.btn').attr('disabled','disabled');
+ //var importing_row = jingles_newImportingEntry(cart);
+ //importing_row.find('button').unbind('click').click(function() { jingles_importCartCancel(cart, dz); });
+ //cart_row.replaceWith(importing_row);
+
+ dz.off("error");
+ var files = dz.getAcceptedFiles();
+ //importing_row.find('.file-name').text(files[0].name);
+ //jingles_importUpdateProgress(files[0], importing_row);
+ var self = this;
+ dz.on('uploadprogress', function(file) { self.uploadProgress(file); });
+ dz.on('success', function(file) {
+ self.importFileUploadSuccess(dz, file, group);
+ });
+ dz.on('error', function(file, msg, xhr) {
+ self.importFileUploadError(this, file, msg, xhr);
+ });
+ /*$(files).each(function(index, file) {
+ self.importAddCut(dz, group, file);
+ });*/
+ self.importAddCut(dz, group, files[0]);
+};
+
+Rivendell.Importer.prototype.uploadProgress = function(file) {
+ if (!file.cartNumber || !file.cutNumber) {
+ return;
+ }
+ var $cut = $('#jingle-' + file.cartNumber + '-' + file.cutNumber).first();
+ if (!$cut.hasClass('uploading')) {
+ var $progressBar = $('.progressBarTemplate').clone().removeClass('progressBarTemplate');
+ $cut.html($progressBar.html());
+ $cut.addClass('uploading');
+ }
+
+ if(file.upload.progress < 99) {
+ var bytes_str = Number((file.upload.bytesSent/1024)/1024).toFixed(1) + " von " +
+ Number((file.upload.total/1024)/1024).toFixed(1) + " MB";
+ $cut.find('.file-bytes').text(bytes_str);
+ $cut.find('.progress .bar').css("width", file.upload.progress + "%");
+ } else {
+ $cut.find('.file-bytes').text('importiere...');
+ $cut.find('.progress .bar').css('width', '100%');
+ $cut.find('.progress').addClass('progress-striped').addClass('active');
+ }
+};
+
+Rivendell.Importer.prototype.importFileUploadSuccess = function(dz, file, group) {
+ //var command = { LOGIN_NAME: auth_username, PASSWORD: auth_token, DESCRIPTION: file. };
+
+ //jingles_updateGroupCartInfo(cart);
+ dz.disable();
+ //progressBar.remove();
+ group.fetchCarts();
+ //$(this.currentGroup.mainCart).trigger('add');
+};
+
+Rivendell.Importer.prototype.importFileUploadError = function(dz, file, msg, xhr) {
+ //var error_row = jingles_newImportErrorEntry(cart, msg);
+ //error_row.find('button').unbind('click').click(function() {
+ //jingles_deleteCart(cart);
+ //});
+ //$('#show-cart-' + cart).replaceWith(error_row);
+ //error_row.find('.file-name').text(file.name);
+ dz.disable();
+};
+
+Rivendell.Importer.prototype.importAddCut = function(dz, group, file) {
+ var cart = group.mainCart;
+ rivendell.addAndEditCut(cart.number, {DESCRIPTION: file.name}, function(cutXml) {
+ group.fetchCarts();
+ dz.on('sending', function(file, xhr, formData) {
+ var cutNumber = $(cutXml).find('cutNumber').text();
+ var cutNumberLeading = cutNumber;
+ switch (cutNumber.toString().length) {
+ case 0: cutNumberLeading = '000' + cutNumber; break;
+ case 1: cutNumberLeading = '00' + cutNumber; break;
+ case 2: cutNumberLeading = '0' + cutNumber; break;
+ case 3: default: cutNumberLeading = cutNumber; break;
+ }
+ file.cartNumber = cart.number;
+ file.cutNumber = cutNumberLeading;
+
+ formData.append('COMMAND', 2);
+ formData.append('LOGIN_NAME', auth_username);
+ formData.append('PASSWORD', auth_token);
+ formData.append('CART_NUMBER', cart.number);
+ formData.append('CUT_NUMBER', cutNumber);
+ formData.append('CHANNELS', 2);
+ formData.append('NORMALIZATION_LEVEL', cart.normlevel);
+ formData.append('AUTOTRIM_LEVEL', cart.trimlevel);
+ formData.append('USE_METADATA', 0); // don't set USE_METADATA 1 for jingles
+ });
+ dz.processQueue();
+ }).fail(function(xhr, status, err) {
+ self.importFileUploadError(cart, dz, file, err, xhr);
+ });
+};
diff --git a/www/js/jingles.js b/www/js/jingles.js
index c633339..a8bec1e 100644
--- a/www/js/jingles.js
+++ b/www/js/jingles.js
@@ -23,13 +23,14 @@
'use strict';
var rivendell = null;
-var groupList = null;
var importer = null;
+var groupList = 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();
+
+ importer = new Rivendell.Importer();
groupList = new Rivendell.GroupList(rivendell, 'jingle');
// todo: move this elsewhere?
@@ -42,6 +43,7 @@ function jingles_cleanup() {
groupList.destroy();
groupList = null;
}
+ importer = null;
rivendell = null;
}
@@ -260,184 +262,3 @@ JingleCut.prototype.render = function() {
return this.$el;
};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-var Importer = function() {
- this.$el = $('#uploadModal');
-};
-
-Importer.prototype.showUploadModal = function(group) {
- var uploadModal = $('#uploadModal');
- $('div.modal-header h3', uploadModal).text("Datei auswählen...");
- var form = $('<form>');
- $('.modal-body', uploadModal).empty().append(form).css("background-image", "url('/img/dz-backdrop.png')");
- var self = this;
- var dropzone = form.dropzone({
- url: '/rd-bin/rdxport.cgi',
- parallelUploads: 1,
- maxFilesize: 2048,
- paramName: 'FILENAME',
- uploadMultiple: false, // todo: maybe enable this?
- clickable: true,
- createImageThumbnails: false,
- acceptedFiles: '.flac,.wav,.ogg,.mp3',
- autoProcessQueue: false,
- init: function() {
- this.on("addedfile", function(file) {
- self.importFileAdded(this, file, group);
- });
- this.on("error", function(file, msg) {
- self.importFileSelectError(this, file, msg);
- });
- }
- });
-
- $('#uploadModal').modal({keyboard: true});
-};
-
-Importer.prototype.importFileAdded = function(dropzone, file, group) {
- $(dropzone.getAcceptedFiles()).each(function(idx, elem) { dropzone.removeFile(elem); });
-
- var uploadModal = $('#uploadModal');
- $('div.modal-body', uploadModal).css("background-image", "url('/img/audio_file.png')");
- $('div.modal-header h3', uploadModal).text(file.name);
- var self = this;
- $('#uploadModal-confirm', uploadModal).unbind('click').click(function() {
- self.importCartConfirm(dropzone, group);
- }).removeAttr('disabled');
-};
-
-Importer.prototype.importFileSelectError = function(dropzone, file, msg) {
- var uploadModal = $('#uploadModal');
- $('div.modal-header h3', uploadModal).text("Datei auswählen...");
- $('div.modal-body', uploadModal).css("background-image", "url('/img/dz-backdrop.png')");
- $('#uploadModal-confirm', uploadModal).attr('disabled','disabled').unbind('click');
- dropzone.removeFile(file);
-};
-
-Importer.prototype.importCartConfirm = function(dz, group) {
- $('#uploadModal').modal('hide');
-
- //var progressBar = group.addUpload();
-
-
-
- //var cart_row = $('#show-cart-' + cart);
- //cart_row.find('.btn').attr('disabled','disabled');
- //var importing_row = jingles_newImportingEntry(cart);
- //importing_row.find('button').unbind('click').click(function() { jingles_importCartCancel(cart, dz); });
- //cart_row.replaceWith(importing_row);
-
- dz.off("error");
- var files = dz.getAcceptedFiles();
- //importing_row.find('.file-name').text(files[0].name);
- //jingles_importUpdateProgress(files[0], importing_row);
- var self = this;
- dz.on('uploadprogress', function(file) { self.uploadProgress(file); });
- dz.on('success', function(file) {
- self.importFileUploadSuccess(dz, file, group);
- });
- dz.on('error', function(file, msg, xhr) {
- self.importFileUploadError(this, file, msg, xhr);
- });
- /*$(files).each(function(index, file) {
- self.importAddCut(dz, group, file);
- });*/
- self.importAddCut(dz, group, files[0]);
-};
-
-Importer.prototype.uploadProgress = function(file) {
- if (!file.cartNumber || !file.cutNumber) {
- return;
- }
- var $cut = $('#jingle-' + file.cartNumber + '-' + file.cutNumber).first();
- if (!$cut.hasClass('uploading')) {
- var $progressBar = $('.progressBarTemplate').clone().removeClass('progressBarTemplate');
- $cut.html($progressBar.html());
- $cut.addClass('uploading');
- }
-
- if(file.upload.progress < 99) {
- var bytes_str = Number((file.upload.bytesSent/1024)/1024).toFixed(1) + " von " +
- Number((file.upload.total/1024)/1024).toFixed(1) + " MB";
- $cut.find('.file-bytes').text(bytes_str);
- $cut.find('.progress .bar').css("width", file.upload.progress + "%");
- } else {
- $cut.find('.file-bytes').text('importiere...');
- $cut.find('.progress .bar').css('width', '100%');
- $cut.find('.progress').addClass('progress-striped').addClass('active');
- }
-};
-
-Importer.prototype.importFileUploadSuccess = function(dz, file, group) {
- //var command = { LOGIN_NAME: auth_username, PASSWORD: auth_token, DESCRIPTION: file. };
-
- //jingles_updateGroupCartInfo(cart);
- dz.disable();
- //progressBar.remove();
- group.fetchCarts();
- //$(this.currentGroup.mainCart).trigger('add');
-};
-
-Importer.prototype.importFileUploadError = function(dz, file, msg, xhr) {
- //var error_row = jingles_newImportErrorEntry(cart, msg);
- //error_row.find('button').unbind('click').click(function() {
- //jingles_deleteCart(cart);
- //});
- //$('#show-cart-' + cart).replaceWith(error_row);
- //error_row.find('.file-name').text(file.name);
- dz.disable();
-};
-
-Importer.prototype.importAddCut = function(dz, group, file) {
- var cart = group.mainCart;
- rivendell.addAndEditCut(cart.number, {DESCRIPTION: file.name}, function(cutXml) {
- group.fetchCarts();
- dz.on('sending', function(file, xhr, formData) {
- var cutNumber = $(cutXml).find('cutNumber').text();
- var cutNumberLeading = cutNumber;
- switch (cutNumber.toString().length) {
- case 0: cutNumberLeading = '000' + cutNumber; break;
- case 1: cutNumberLeading = '00' + cutNumber; break;
- case 2: cutNumberLeading = '0' + cutNumber; break;
- case 3: default: cutNumberLeading = cutNumber; break;
- }
- file.cartNumber = cart.number;
- file.cutNumber = cutNumberLeading;
-
- formData.append('COMMAND', 2);
- formData.append('LOGIN_NAME', auth_username);
- formData.append('PASSWORD', auth_token);
- formData.append('CART_NUMBER', cart.number);
- formData.append('CUT_NUMBER', cutNumber);
- formData.append('CHANNELS', 2);
- formData.append('NORMALIZATION_LEVEL', cart.normlevel);
- formData.append('AUTOTRIM_LEVEL', cart.trimlevel);
- formData.append('USE_METADATA', 0); // don't set USE_METADATA 1 for jingles
- });
- dz.processQueue();
- }).fail(function(xhr, status, err) {
- self.importFileUploadError(cart, dz, file, err, xhr);
- });
-};
diff --git a/www/js/musicgrid.js b/www/js/musicgrid.js
index ceadb0d..29e639e 100644
--- a/www/js/musicgrid.js
+++ b/www/js/musicgrid.js
@@ -34,6 +34,7 @@ function musicgrid_init() {
}
function musicgrid_cleanup() {
+ musicgrid = null
rivendell = null;
}
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);
+ });*/
+
});
};