From 212c8cfbdaa51855ce8ec4f41f0b6bcf34373387 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Mon, 22 Feb 2016 17:03:27 +0100 Subject: importer: handle import errors diff --git a/www/js/importer.js b/www/js/importer.js index 7f8a0d8..bac23f6 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -57,6 +57,13 @@ Rivendell.Importer.prototype.openModal = function(group, groupView, createCart, var self = this; dropzone.on('addedfile', function(file) { + if (!Dropzone.isValidFile(file, dropzone.options.acceptedFiles)) { + $('div.modal-header h4', self.$el).text('Nicht unterstützter Dateityp.'); + $('.modal-body', this.$el).css("background-image", "url('/img/dz-backdrop.png')"); + $('#uploadModal-confirm', this.$el).attr('disabled','disabled').off('click'); + return; + } + $('div.modal-header h4', self.$el).text(file.name); $('div.modal-body', self.$el).css("background-image", "url('/img/audio_file.png')"); @@ -143,20 +150,21 @@ Rivendell.Upload.prototype.import = function() { Rivendell.Upload.prototype.addCart = function(success) { var files = this.dropzone.getAcceptedFiles(); + var file = files[files.length - 1]; var self = this; if (this.createCart) { rdxport.addCart(this.group.groupName, 'audio', this.newCartNumber, function(cartXML) { self.cart = new Rivendell.Cart(cartXML, self.group); - success(files[0]); + success(file); }).fail(function() { //self.importFileUploadError(files[0], 'Failed to add Cart.'); }); } else { this.cart = this.group.carts[0]; - success(files[0]); + success(file); } -}; +} Rivendell.Upload.prototype.importFileUploadSuccess = function() { this.dropzone.off(Dropzone.ERROR); @@ -169,8 +177,10 @@ Rivendell.Upload.prototype.importFileUploadSuccess = function() { }; Rivendell.Upload.prototype.importFileUploadError = function(file, msg, xhr) { - this.groupView.uploadError(self, file, msg); - this.cancel(); + var self = this; + this.groupView.uploadError(this, file, msg, xhr, function() { + self.cancel(); + }); }; Rivendell.Upload.prototype.addCut = function(file) { diff --git a/www/js/jingles.js b/www/js/jingles.js index c60d7fe..0bb586c 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -147,8 +147,11 @@ Rivendell.JingleGroupView.prototype.uploadProgress = function(upload, file) { } }; -Rivendell.JingleGroupView.prototype.uploadError = function(upload, file, msg) { +Rivendell.JingleGroupView.prototype.uploadError = function(upload, file, msg, xhr, acknowledge) { // todo + + // to this on ok click. + acknowledge(); }; Rivendell.JingleCartView = function(model, groupView, active) { diff --git a/www/js/musicpools.js b/www/js/musicpools.js index a5cd323..3a694b9 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -182,8 +182,11 @@ Rivendell.MusicpoolView.prototype.uploadProgress = function(upload, file) { } }; -Rivendell.MusicpoolView.prototype.uploadError = function(upload, file, msg) { +Rivendell.MusicpoolView.prototype.uploadError = function(upload, file, msg, xhr, acknowledge) { // todo + + // to this on ok click. + acknowledge(); }; Rivendell.MusicpoolCartView = function(model) { diff --git a/www/js/shows.js b/www/js/shows.js index 43149c3..1897352 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -258,18 +258,21 @@ Rivendell.ShowView.prototype.uploadProgress = function(upload, file) { } }; -Rivendell.ShowView.prototype.uploadError = function(upload, file, msg) { +Rivendell.ShowView.prototype.uploadError = function(upload, file, msg, xhr, acknowledge) { if (!file.cartNumber) { return; } - var dismiss_button = ''; + var responseCode = xhr.status; + var errorString = xhr.statusText; + + //var xmlDoc = $.parseXML(msg); + //var msg = $(xmlDoc); + //var responseCode = msg.find('ResponseCode').text(); + //var errorString = msg.find('ErrorString').text(); + var reason = $('').addClass('label').addClass('label-danger').text(responseCode).after($('').html(' ' + errorString)); - var xmlDoc = $.parseXML(msg); - var msg = $(xmlDoc); - var resp_code = msg.find('ResponseCode').text(); - var err_string = msg.find('ErrorString').text(); - var reason = $('').addClass('label').addClass('label-danger').text(resp_code).after($('').html(' ' + err_string)); + var dismiss_button = ''; var $errorRow = $('') .attr("id", "show-cart-" + file.cartNumber) @@ -283,6 +286,7 @@ Rivendell.ShowView.prototype.uploadError = function(upload, file, msg) { $('button', $errorRow).on('click', function() { var $emptyRow = Rivendell.ShowCartView.renderEmpty(self.model, self, file.cartNumber); $('#show-cart-' + file.cartNumber).replaceWith($emptyRow); + acknowledge(); }); $('#show-cart-' + file.cartNumber).replaceWith($errorRow); -- cgit v0.10.2