From 2396977fd57fee58eec84ce0ac6fc91b1b0d1dc9 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Thu, 24 Mar 2016 17:00:07 +0100 Subject: shows: fix renderUploading diff --git a/www/js/importer.js b/www/js/importer.js index 5f7db6f..cba7d23 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -113,6 +113,26 @@ Rivendell.Importer.prototype.removeUpload = function(upload) { }); }; +Rivendell.Importer.prototype.getUploadByCartId = function (cartNumber) { + var upload = null; + $.each(this.uploads, function(index, currentUpload){ + if (currentUpload.newCartNumber === cartNumber) { + upload = currentUpload; + } + }); + return upload; +}; + +Rivendell.Importer.prototype.hasUploadByCartId = function (cartNumber) { + var found = false; + $.each(this.uploads, function(index, currentUpload){ + if (currentUpload.newCartNumber === cartNumber) { + found = true; + } + }); + return found; +}; + Rivendell.Upload = function(group, groupView, createCart, newCartNumber, useMetadata, dropzone) { this.group = group; this.groupView = groupView; @@ -121,6 +141,11 @@ Rivendell.Upload = function(group, groupView, createCart, newCartNumber, useMeta this.useMetadata = useMetadata; this.dropzone = dropzone; + this.uploadprogress = { + progress: 0, + total: 0, + bytesSent: 0 + }; this.cart = null; this.cut = null; @@ -158,6 +183,7 @@ Rivendell.Upload.prototype.import = function() { var self = this; this.dropzone.off('uploadprogress').on('uploadprogress', function(file) { + self.uploadprogress = file.upload; self.groupView.uploadProgress(self, file); }); this.dropzone.off(Dropzone.SUCCESS).on(Dropzone.SUCCESS, function(file) { diff --git a/www/js/shows.js b/www/js/shows.js index 1ba86b9..b910bdb 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -203,7 +203,12 @@ Rivendell.ShowView.prototype.render = function() { if (cart) { var cartView = new Rivendell.ShowCartView(cart, self); self.cartViews.push(cartView); - cartView.render(); + var upload = null; + if ((upload = importer.getUploadByCartId(log.cartNumber)) !== null) { + cartView.renderUploading(upload); + } else { + cartView.render(); + } $('#app-shows table > tbody').append(cartView.$el); } else { @@ -230,11 +235,11 @@ Rivendell.ShowView.prototype.uploadProgress = function(upload, file) { $cart.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"; + if(upload.uploadprogress.progress < 99) { + var bytes_str = Number((upload.uploadprogress.bytesSent/1024)/1024).toFixed(1) + " von " + + Number((upload.uploadprogress.total/1024)/1024).toFixed(1) + " MB"; $cart.find('.file-bytes').text(bytes_str); - $cart.find('.progress .progress-bar').css("width", file.upload.progress + "%"); + $cart.find('.progress .progress-bar').css("width", upload.uploadprogress.progress + "%"); } else { $cart.find('.file-bytes').text('importiere...'); $cart.find('.progress .progress-bar').css('width', '100%'); @@ -313,6 +318,32 @@ Rivendell.ShowCartView.prototype.render = function() { .append($('').css('text-align', 'center').append($deleteButton)); }; +Rivendell.ShowCartView.prototype.renderUploading = function(upload) { + var $progressBar = $('.progressBarTemplate.shows').clone().removeClass('progressBarTemplate'); + $('.file-name', $progressBar).text(this.model.title); + $('.cart-number', $progressBar).text(this.model.number); + + this.$el.empty() + .html($progressBar.html()) + .attr('id', 'show-cart-' + this.model.number) + .addClass('uploading'); + + $('button', this.$el).on('click', function() { + upload.cancel(); + }); + + if(upload.uploadprogress.progress < 99) { + var bytes_str = Number((upload.uploadprogress.bytesSent/1024)/1024).toFixed(1) + " von " + + Number((upload.uploadprogress.total/1024)/1024).toFixed(1) + " MB"; + this.$el.find('.file-bytes').text(bytes_str); + this.$el.find('.progress .progress-bar').css("width", upload.uploadprogress.progress + "%"); + } else { + this.$el.find('.file-bytes').text('importiere...'); + this.$el.find('.progress .progress-bar').css('width', '100%'); + this.$el.find('.progress .progress-bar').addClass('progress-bar-striped').addClass('active'); + } +}; + Rivendell.ShowCartView.renderEmpty = function(group, groupView, cartNumber) { var $uploadButton = $(''); -- cgit v0.10.2