From e7071e58293c926553e9fbfcad5cc261a189aa6a Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Fri, 15 Jul 2016 21:22:55 +0200 Subject: add multiple files upload diff --git a/www/js/importer.js b/www/js/importer.js index fc2e462..4c6ddb9 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -129,13 +129,19 @@ Rdxport.Importer.prototype.resetModal = function() { $('.modal-body .drop form input[type="file"]', this.$el).val(''); $('.modal-body #sourceUri', this.$el).val(''); $('#uploadModal-confirm', this.$el).attr('disabled','disabled').off('click'); + $('form input[type="file"]', this.$el).removeAttr('multiple'); }; -Rdxport.Importer.prototype.openModal = function(group, groupView, cartNumber, useMetadata) { +Rdxport.Importer.prototype.openModal = function(group, groupView, cartNumber, useMetadata, multifiles) { this.resetModal(); var $drop = $('.modal-body .drop', this.$el); var $form = $('form', $drop); var $fileInput = $('input[type="file"]', $form); + if (multifiles) { + $fileInput.attr('multiple', 'multiple'); + } else { + $fileInput.removeAttr('multiple'); + } $drop.off('click').on('click', function(event) { $fileInput.get(0).click(); @@ -159,8 +165,6 @@ Rdxport.Importer.prototype.openModal = function(group, groupView, cartNumber, us var self = this; function handleFiles(files) { - var file = files[0]; - /*if (!Dropzone.isValidFile(file, dropzone.options.acceptedFiles)) { $('div.modal-header h4', self.$el).text('Nicht unterstützter Dateityp.'); $('.modal-body .drop', this.$el).css("background-image", "url('/img/dz-backdrop.png')"); @@ -168,13 +172,25 @@ Rdxport.Importer.prototype.openModal = function(group, groupView, cartNumber, us return; }*/ - $('div.modal-header h4', self.$el).text(file.name); + if (multifiles && files.length > 1) { + $('div.modal-header h4', self.$el).text(files.length + ' files.'); + } else { + $('div.modal-header h4', self.$el).text(files[0].name); + } $('div.modal-body .drop', self.$el).css("background-image", "url('/img/audio_file.png')"); $('.modal-body #sourceUri', self.$el).val(''); $('#uploadModal-confirm', self.$el).off('click').on('click', function() { - var upload = new Rdxport.Upload(file, group, groupView, cartNumber, useMetadata); - upload.import(); - self.uploads.push(upload); + if (!multifiles) { + var upload = new Rdxport.Upload(files[0], group, groupView, cartNumber, useMetadata); + upload.import(); + self.uploads.push(upload); + } else { + $.each(files, function(index, file) { + var upload = new Rdxport.Upload(file, group, groupView, cartNumber, useMetadata); + upload.import(); + self.uploads.push(upload); + }); + } self.$el.off('hide.bs.modal'); self.$el.modal('hide'); @@ -194,7 +210,7 @@ Rdxport.Importer.prototype.openModal = function(group, groupView, cartNumber, us return; } $('.modal-body .drop', self.$el).css("background-image", "url('/img/dz-backdrop.png')"); - $('.modal-body .drop form input[type="file"]', this.$el).val(''); + $('.modal-body .drop form input[type="file"]', self.$el).val(''); $form.off('submit').on('submit', function(event) { event.preventDefault(); handleSource(); diff --git a/www/js/jingles.js b/www/js/jingles.js index 6457b5a..6f0d10c 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -108,7 +108,7 @@ Rdxport.JingleGroupView.prototype.render = function() { $('table tbody tr', this.$el).remove(); $('.uploadButton', this.$el).on('click', function() { - importer.openModal(self.model, self, self.model.carts[0].number, false); + importer.openModal(self.model, self, self.model.carts[0].number, false, true); }); }; diff --git a/www/js/musicpools.js b/www/js/musicpools.js index c56ab78..3bd905a 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -186,7 +186,7 @@ Rdxport.MusicpoolView.prototype.render = function() { $('.uploadButton', this.$el).on('click', function() { - importer.openModal(self.model, self, null, true); + importer.openModal(self.model, self, null, true, true); }); }; diff --git a/www/js/shows.js b/www/js/shows.js index ccea2e5..8f837ba 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -385,7 +385,7 @@ Rdxport.ShowCartView.renderEmpty = function(group, groupView, cartNumber) { var $uploadButton = $(''); $uploadButton.off('click').on('click', function() { - importer.openModal(group, groupView, cartNumber, true); + importer.openModal(group, groupView, cartNumber, true, false); }); return $('') -- cgit v0.10.2