diff options
author | Peter Grassberger <petertheone@gmail.com> | 2016-04-01 15:30:45 (GMT) |
---|---|---|
committer | Peter Grassberger <petertheone@gmail.com> | 2016-04-01 15:30:45 (GMT) |
commit | 8db94592d6222fbd0153cf05c83724d7ac518634 (patch) | |
tree | fe89e9ed21ce849f3f5fcbfecff335d1cc90f409 /www/js | |
parent | 3c584d7ee53ecfb35f32a2182971dfbc30009590 (diff) | |
parent | 4a79af6bf48f7543a407d86fc73ce70f39fc6d94 (diff) |
Merge branch 'master' into rdxportjs-refactor
Conflicts:
www/js/importer.js
www/js/jingles.js
www/js/musicpools.js
www/js/shows.js
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/apps.js | 1 | ||||
-rw-r--r-- | www/js/importer.js | 30 | ||||
-rw-r--r-- | www/js/jingles.js | 35 | ||||
-rw-r--r-- | www/js/musicpools.js | 35 | ||||
-rw-r--r-- | www/js/shows.js | 36 | ||||
-rw-r--r-- | www/js/utils.js | 13 |
6 files changed, 116 insertions, 34 deletions
diff --git a/www/js/apps.js b/www/js/apps.js index 478fadd..dd5b337 100644 --- a/www/js/apps.js +++ b/www/js/apps.js @@ -136,7 +136,6 @@ function apps_init() { window.onbeforeunload = function(e) { if (importer && importer.isUploading()) { return 'Achtung: Es laufen noch imports.'; - return; } }; } diff --git a/www/js/importer.js b/www/js/importer.js index 86f7947..13e7aff 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -113,6 +113,30 @@ Rdxport.Importer.prototype.removeUpload = function(upload) { }); }; +Rdxport.Importer.prototype.getUploadByCartNumber = function (cartNumber) { + var upload = null; + $.each(this.uploads, function(index, currentUpload){ + if (currentUpload.cart !== null && + currentUpload.cart.number === cartNumber ) { + upload = currentUpload; + } + }); + return upload; +}; + +Rdxport.Importer.prototype.getUploadByCartAndCutNumber = function (cartNumber, cutNumber) { + var upload = null; + $.each(this.uploads, function(index, currentUpload) { + if (currentUpload.cart !== null && + currentUpload.cart.number === cartNumber && + currentUpload.cut !== null && + currentUpload.cut.number === cutNumber) { + upload = currentUpload; + } + }); + return upload; +}; + Rdxport.Upload = function(group, groupView, createCart, newCartNumber, useMetadata, dropzone) { this.group = group; this.groupView = groupView; @@ -121,6 +145,11 @@ Rdxport.Upload = function(group, groupView, createCart, newCartNumber, useMetada this.useMetadata = useMetadata; this.dropzone = dropzone; + this.uploadprogress = { + progress: 0, + total: 0, + bytesSent: 0 + }; this.cart = null; this.cut = null; @@ -158,6 +187,7 @@ Rdxport.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/jingles.js b/www/js/jingles.js index 72522c4..02070ae 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -135,16 +135,7 @@ Rdxport.JingleGroupView.prototype.uploadProgress = function(upload, file) { $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 .progress-bar').css("width", file.upload.progress + "%"); - } else { - $cut.find('.file-bytes').text('importiere...'); - $cut.find('.progress .progress-bar').css('width', '100%'); - $cut.find('.progress .progress-bar').addClass('progress-bar-striped').addClass('active'); - } + updateProgressBar($cut, upload); }; Rdxport.JingleGroupView.prototype.uploadError = function(upload, file, msg, xhr, acknowledge) { @@ -208,7 +199,12 @@ Rdxport.JingleCutView = function(model) { this.$spinner = null; this.$el = null; - this.render(); + var upload = null; + if ((upload = importer.getUploadByCartAndCutNumber(this.model.cartNumber, this.model.number)) !== null) { + this.renderUploading(upload); + } else { + this.render(); + } }; Rdxport.JingleCutView.prototype.render = function() { @@ -259,6 +255,23 @@ Rdxport.JingleCutView.prototype.render = function() { ); }; +Rdxport.JingleCutView.prototype.renderUploading = function(upload) { + var $progressBar = $('.progressBarTemplate.jingles').clone().removeClass('progressBarTemplate'); + $('.file-name', $progressBar).text(this.model.name); + $('.cart-number', $progressBar).text(this.model.number); + + this.$el = $('<tr>') + .attr('id', 'jingle-' + this.model.cartNumber + '-' + this.model.number) + .html($progressBar.html()) + .addClass('uploading'); + + $('button', this.$el).on('click', function() { + upload.cancel(); + }); + + updateProgressBar(this.$el, upload); +}; + Rdxport.JingleCutView.prototype.move = function() { this.$el.find('td:first').html(this.$spinner); var self = this; diff --git a/www/js/musicpools.js b/www/js/musicpools.js index 4449865..400c0bd 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -170,16 +170,7 @@ Rdxport.MusicpoolView.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"; - $cart.find('.file-bytes').text(bytes_str); - $cart.find('.progress .progress-bar').css("width", file.upload.progress + "%"); - } else { - $cart.find('.file-bytes').text('importiere...'); - $cart.find('.progress .progress-bar').css('width', '100%'); - $cart.find('.progress .progress-bar').addClass('progress-bar-striped').addClass('active'); - } + updateProgressBar($cart, upload); }; Rdxport.MusicpoolView.prototype.uploadError = function(upload, file, msg, xhr, acknowledge) { @@ -219,7 +210,12 @@ Rdxport.MusicpoolCartView = function(model) { this.$spinner = null; this.$el = null; - this.render(); + var upload = null; + if ((upload = importer.getUploadByCartNumber(this.model.number)) !== null) { + this.renderUploading(upload); + } else { + this.render(); + } }; Rdxport.MusicpoolCartView.prototype.render = function() { @@ -263,6 +259,23 @@ Rdxport.MusicpoolCartView.prototype.render = function() { .append($('<td>').addClass('text-center').append(deleteButton)); }; +Rdxport.MusicpoolCartView.prototype.renderUploading = function(upload) { + var $progressBar = $('.progressBarTemplate.musicpools').clone().removeClass('progressBarTemplate'); + $('.file-name', $progressBar).text(this.model.title); + $('.cart-number', $progressBar).text(this.model.number); + + this.$el = $('<tr>') + .attr('id', 'musicpool-' + this.model.number) + .html($progressBar.html()) + .addClass('uploading'); + + $('button', this.$el).on('click', function() { + upload.cancel(); + }); + + updateProgressBar(this.$el, upload); +}; + Rdxport.MusicpoolCartView.prototype.delete = function() { this.$el.find('td:last').html(this.$spinner); diff --git a/www/js/shows.js b/www/js/shows.js index 0379951..8fcba8b 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -203,7 +203,12 @@ Rdxport.ShowView.prototype.render = function() { if (cart) { var cartView = new Rdxport.ShowCartView(cart, self); self.cartViews.push(cartView); - cartView.render(); + var upload = null; + if ((upload = importer.getUploadByCartNumber(log.cartNumber)) !== null) { + cartView.renderUploading(upload); + } else { + cartView.render(); + } $('#app-shows table > tbody').append(cartView.$el); } else { @@ -230,16 +235,7 @@ Rdxport.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"; - $cart.find('.file-bytes').text(bytes_str); - $cart.find('.progress .progress-bar').css("width", file.upload.progress + "%"); - } else { - $cart.find('.file-bytes').text('importiere...'); - $cart.find('.progress .progress-bar').css('width', '100%'); - $cart.find('.progress .progress-bar').addClass('progress-bar-striped').addClass('active'); - } + updateProgressBar($cart, upload); }; Rdxport.ShowView.prototype.uploadError = function(upload, file, msg, xhr, acknowledge) { @@ -313,6 +309,24 @@ Rdxport.ShowCartView.prototype.render = function() { .append($('<td>').css('text-align', 'center').append($deleteButton)); }; +Rdxport.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() + .attr('id', 'show-cart-' + this.model.number) + .html($progressBar.html()) + .attr('id', 'show-cart-' + this.model.number) + .addClass('uploading'); + + $('button', this.$el).on('click', function() { + upload.cancel(); + }); + + updateProgressBar(this.$el, upload); +}; + Rdxport.ShowCartView.renderEmpty = function(group, groupView, cartNumber) { var $uploadButton = $('<button class="uploadButton btn btn-primary btn-xs"><span class="glyphicon glyphicon-upload"></span> Importieren</button>'); diff --git a/www/js/utils.js b/www/js/utils.js index 81501e9..26b0822 100644 --- a/www/js/utils.js +++ b/www/js/utils.js @@ -140,3 +140,16 @@ jQuery.fn.brightness = function() { if (this.parent().length) return this.parent().brightness(); } }; + +function updateProgressBar($el, upload) { + 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"; + $el.find('.file-bytes').text(bytes_str); + $el.find('.progress .progress-bar').css("width", upload.uploadprogress.progress + "%"); + } else { + $el.find('.file-bytes').text('importiere...'); + $el.find('.progress .progress-bar').css('width', '100%'); + $el.find('.progress .progress-bar').addClass('progress-bar-striped').addClass('active'); + } +} |