From 34b6494b49c81ceed32b98403bf2597f8fef8124 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Mon, 7 Dec 2015 02:51:53 +0100 Subject: jingle: draw progress bar directly on new cut.. diff --git a/www/js/jingles.js b/www/js/jingles.js index e5749d2..b988592 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -172,12 +172,12 @@ JingleGroup.prototype.renderCarts = function() { } }; -JingleGroup.prototype.addUpload = function() { +/*JingleGroup.prototype.addUpload = function() { var $tfoot = $('table > tfoot', this.$el); var $progressBar = $('.progressBarTemplate').clone().removeClass('progressBarTemplate'); $progressBar.appendTo($tfoot); return $progressBar; -}; +};*/ var JingleCart = function(number, title, groupName, group) { this.number = number; @@ -281,7 +281,9 @@ JingleCut.prototype.render = function() { self.removeSelf(); }); - this.$el = $('').append($('').text(this.name)) + this.$el = $('') + .attr('id', 'jingle-' + this.cartNumber + '-' + this.number) + .append($('').text(this.name)) .append($('').text(this.description)) .append( $('') @@ -371,7 +373,7 @@ Importer.prototype.importFileSelectError = function(dropzone, file, msg) { Importer.prototype.importCartConfirm = function(dz, group) { $('#uploadModal').modal('hide'); - var progressBar = group.addUpload(); + //var progressBar = group.addUpload(); @@ -386,9 +388,9 @@ Importer.prototype.importCartConfirm = function(dz, group) { //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, progressBar); }); + dz.on('uploadprogress', function(file) { self.uploadProgress(file); }); dz.on('success', function(file) { - self.importFileUploadSuccess(dz, file, group, progressBar); + self.importFileUploadSuccess(dz, file, group); }); dz.on('error', function(file, msg, xhr) { self.importFileUploadError(this, file, msg, xhr); @@ -396,25 +398,35 @@ Importer.prototype.importCartConfirm = function(dz, group) { this.importAddCut(dz, group, files[0]) }; -Importer.prototype.uploadProgress = function(file, progressBar) { +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"; - progressBar.find('.file-bytes').text(bytes_str); - progressBar.find('.progress .bar').css("width", file.upload.progress + "%"); + $cut.find('.file-bytes').text(bytes_str); + $cut.find('.progress .bar').css("width", file.upload.progress + "%"); } else { - progressBar.find('.file-bytes').text('importiere...'); - progressBar.find('.progress .bar').css('width', '100%'); - progressBar.find('.progress').addClass('progress-striped').addClass('active'); + $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, progressBar) { +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(); + //progressBar.remove(); group.fetchCarts(); //$(this.currentGroup.mainCart).trigger('add'); }; @@ -432,8 +444,19 @@ Importer.prototype.importFileUploadError = function(dz, file, msg, xhr) { Importer.prototype.importAddCut = function(dz, group, file) { var cart = group.mainCart; rivendell.addAndEditCut(cart.number, {DESCRIPTION: file.name}, function(cutXml) { - var cutNumber = $(cutXml).find('cutNumber').text(); + 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); -- cgit v0.10.2