diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/jingles.js | 118 |
1 files changed, 47 insertions, 71 deletions
diff --git a/www/js/jingles.js b/www/js/jingles.js index b737a1b..814053a 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -44,11 +44,6 @@ function jingles_cleanup() { var JingleGroupList = function() { this.groups = []; - - var self = this; - $(this).on('add update', function () { - self.render(); - }); }; JingleGroupList.prototype.fetch = function() { @@ -72,14 +67,6 @@ JingleGroupList.prototype.fetch = function() { $('autotrim-level', groupXml).text() ); - $(jingleGroup).on('update', function() { - $(self).trigger('update'); - }); - - $(jingleGroup).on('add', function() { - self.fetch(); - }); - self.groups.push(jingleGroup); }); }); @@ -110,6 +97,7 @@ var JingleGroup = function(title, groupName, description, lowcart, highcart, nor this.$el = null; + this.render(); this.fetchCarts(); }; @@ -123,19 +111,7 @@ JingleGroup.prototype.fetchCarts = function() { self.deactivateCart = self.createCartFromXml(cartXml, false); }) ).then(function() { - $(self.mainCart).on('add', function() { - $(self).trigger('add'); - }); - - $(self.deactivateCart).on('add', function() { - $(self).trigger('add'); - }); - - /*self.mainCart.on('remove', function() { - self.trigger('remove'); - });*/ - - $(self).trigger('update'); + self.renderCarts(); }); }; @@ -143,7 +119,8 @@ JingleGroup.prototype.createCartFromXml = function(cartXml, active) { var cart = new JingleCart( $(cartXml).find('number').text(), $(cartXml).find('title').text(), - $(cartXml).find('groupName').text() + $(cartXml).find('groupName').text(), + this ); var self = this; @@ -157,10 +134,6 @@ JingleGroup.prototype.createCartFromXml = function(cartXml, active) { active ); - $(cut).on('add', function() { - $(self).trigger('add'); - }); - cart.addCut(cut); }); @@ -180,6 +153,13 @@ JingleGroup.prototype.render = function() { importer.showUploadModal(self); }); + this.renderCarts(); +}; + +JingleGroup.prototype.renderCarts = function() { + $('table > tbody', this.$el).html(''); + + var self = this; if (this.mainCart) { $.each(this.mainCart.cuts, function(index, cut) { $('table > tbody', self.$el).append(cut.render()); @@ -192,32 +172,18 @@ JingleGroup.prototype.render = function() { } }; -JingleGroup.prototype.uploading = function() { - console.log('uploading!'); - $('table > tfoot .progressBar', this.$el).removeClass('hidden'); +JingleGroup.prototype.addUpload = function() { + var $tfoot = $('table > tfoot', this.$el); + var $progressBar = $('.progressBarTemplate').clone().removeClass('progressBarTemplate'); + $progressBar.appendTo($tfoot); + return $progressBar; }; -JingleGroup.prototype.uploadProgress = function(file) { - console.log('uploadProgress!'); - - var stats = $('table > tfoot .progressBar', this.$el); - - 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"; - stats.find('.file-bytes').text(bytes_str); - stats.find('.progress .bar').css("width", file.upload.progress + "%"); - } else { - stats.find('.file-bytes').text('importiere...'); - stats.find('.progress .bar').css('width', '100%'); - stats.find('.progress').addClass('progress-striped').addClass('active'); - } -}; - -var JingleCart = function(number, title, groupName) { +var JingleCart = function(number, title, groupName, group) { this.number = number; this.title = title; this.groupName = groupName; + this.group = group; this.cuts = []; }; @@ -253,11 +219,11 @@ JingleCut.prototype.move = function() { $(jinglesGroupList.groups).each(function(index, group) { if (self.active) { if (self.cartNumber !== group.mainCart.number) { - destinationCart = group.mainCart.number; + destinationCart = group.mainCart; } } else { if (self.cartNumber !== group.deactivateCart.number) { - destinationCart = group.deactivateCart.number; + destinationCart = group.deactivateCart; } } }); @@ -267,8 +233,9 @@ JingleCut.prototype.move = function() { // todo: fix - rivendell.moveCut(this.cartNumber, this.number, destinationCart, function() { - $(self).trigger('add'); + rivendell.moveCut(this.cartNumber, this.number, destinationCart.number, function() { + self.cart.group.fetchCarts(); + destinationCart.group.fetchCarts(); }); }; @@ -281,7 +248,7 @@ JingleCut.prototype.toggleActive = function() { } var self = this; rivendell.moveCut(this.cartNumber, this.number, destinationCart, function() { - $(self).trigger('add'); + self.cart.group.fetchCarts(); }); }; @@ -407,7 +374,7 @@ Importer.prototype.importFileSelectError = function(dropzone, file, msg) { Importer.prototype.importCartConfirm = function(dz) { $('#uploadModal').modal('hide'); - this.currentGroup.uploading(); + var progressBar = this.currentGroup.addUpload(); @@ -422,22 +389,37 @@ Importer.prototype.importCartConfirm = function(dz) { //importing_row.find('.file-name').text(files[0].name); //jingles_importUpdateProgress(files[0], importing_row); var self = this; - dz.on("uploadprogress", function(file) { self.currentGroup.uploadProgress(file); }); - dz.on("success", function(file) { - self.importFileUploadSuccess(dz, file); + dz.on('uploadprogress', function(file) { self.uploadProgress(file, progressBar); }); + dz.on('success', function(file) { + self.importFileUploadSuccess(dz, file, progressBar); }); - dz.on("error", function(file, msg, xhr) { + dz.on('error', function(file, msg, xhr) { self.importFileUploadError(this, file, msg, xhr); }); this.importAddCut(dz, files[0]) }; -Importer.prototype.importFileUploadSuccess = function(dz, file) { +Importer.prototype.uploadProgress = function(file, progressBar) { + 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 + "%"); + } else { + progressBar.find('.file-bytes').text('importiere...'); + progressBar.find('.progress .bar').css('width', '100%'); + progressBar.find('.progress').addClass('progress-striped').addClass('active'); + } +}; + +Importer.prototype.importFileUploadSuccess = function(dz, file, progressBar) { //var command = { LOGIN_NAME: auth_username, PASSWORD: auth_token, DESCRIPTION: file. }; //jingles_updateGroupCartInfo(cart); dz.disable(); - $(this.currentGroup.mainCart).trigger('add'); + progressBar.remove(); + this.currentGroup.fetchCarts(); + //$(this.currentGroup.mainCart).trigger('add'); }; Importer.prototype.importFileUploadError = function(dz, file, msg, xhr) { @@ -452,7 +434,7 @@ Importer.prototype.importFileUploadError = function(dz, file, msg, xhr) { Importer.prototype.importAddCut = function(dz, file) { var cart = this.currentGroup.mainCart; - rivendell.addCut(cart.number, file.name, function(cutXml) { + rivendell.addAndEditCut(cart.number, {DESCRIPTION: file.name}, function(cutXml) { var cutNumber = $(cutXml).find('cutNumber').text(); dz.on('sending', function(file, xhr, formData) { formData.append('COMMAND', 2); @@ -470,9 +452,3 @@ Importer.prototype.importAddCut = function(dz, file) { self.importFileUploadError(cart, dz, file, err, xhr); }); }; - -Importer.prototype.importCartCancel = function(cart, dz) { - this.deleteCart(cart); - dz.off("error"); - dz.disable(); -}; |