From ee0dc07f5e2c10f9f8c4340724fda4379e84654f Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 7 Oct 2014 13:44:33 +0000 Subject: starting upload works now diff --git a/js/shows.js b/js/shows.js index 8de5411..c705405 100644 --- a/js/shows.js +++ b/js/shows.js @@ -15,8 +15,28 @@ function shows_importCartCancel(cart, dz) { cart_row.next().remove(); cart_row.find('.btn').removeAttr('disabled'); cart_row.after(shows_getDzStat(true)); + dz.off("error"); + dz.disable(); +} + +function shows_importFileUploadError(cart, dz, file, msg, xhr) { + alert("import file upload error: " + msg); +} + +function shows_importFileUploadSuccess(cart, dz, file) { + alert("import file upload success for cart " + cart); +} - // TODO: cancel upload +function shows_importFileUploadComplete(cart, dz, file) { + alert("import file upload success/error for cart " + cart); +} + +function shows_updateProgress(file, stats) +{ + 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 + "%"); } function shows_importCartConfirm(cart, dz) { @@ -28,7 +48,16 @@ function shows_importCartConfirm(cart, dz) { dz_stat.find('button').unbind('click').click(function() { shows_importCartCancel(cart, dz); }); cart_row.after(dz_stat); - // call dz.processQueue() + dz.off("error"); + dz.on("error", function(file, msg, xhr) { shows_importFileUploadError(cart, this, file, msg, xhr); }); + files = dz.getAcceptedFiles(); + + dz_stat.find('.file-name').text(files[0].name); + shows_updateProgress(files[0], dz_stat); + dz.on("uploadprogress", function(file) { shows_updateProgress(file, dz_stat); }); + dz.on("success", function(file) { shows_updateProgress(cart, dz, file); }); + dz.on("complete", function(file) { shows_updateProgress(cart, dz, file); }); + dz.processQueue(); } function shows_createImportForm(cart) { @@ -51,7 +80,7 @@ function shows_importFileAdded(dz, file, cart) { $('#shows-upload-confirm').removeAttr('disabled').unbind('click').click(function() { shows_importCartConfirm(cart, dz); }); } -function shows_importFileError(dz, file, msg) { +function shows_importFileSelectError(dz, file, msg) { $('#shows-upload div.modal-header h3').text("Datei auswählen...") $('#shows-upload div.modal-body').css("background-image", "url('/img/dz-backdrop.png')"); $('#shows-upload-confirm').attr('disabled','disabled').unbind('click'); @@ -67,7 +96,7 @@ function shows_importCart(cart) { uploadMultiple: false, clickable: true, createImageThumbnails: false, acceptedFiles: ".flac,.wav,.ogg,.mp3", autoProcessQueue: false, init: function() { this.on("addedfile", function(file) { shows_importFileAdded(this, file, cart); }); - this.on("error", function(file, msg) { shows_importFileError(this, file, msg); }); + this.on("error", function(file, msg) { shows_importFileSelectError(this, file, msg); }); }}); $('#shows-upload').modal({ keyboard: true }); @@ -92,12 +121,12 @@ function shows_getDzStat(empty) .css("margin", 0) .css("padding", 0)); } else { - var progress_bar = '
'; + var progress_bar = '
'; var cancel_button = ''; - return $('').append($('').text('filename.flac')) - .append($('').text('xx of XX Bytes')) + return $('').append($('').addClass('file-name').text('-')) + .append($('').addClass('file-bytes').text('??.? von ??.? MB')) .append($('').append(progress_bar)) .append($('').append(cancel_button)); } -- cgit v0.10.2