diff options
author | Christian Pointner <equinox@helsinki.at> | 2014-10-07 13:44:33 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2014-10-07 13:44:33 (GMT) |
commit | ee0dc07f5e2c10f9f8c4340724fda4379e84654f (patch) | |
tree | 368652e16c915564c504eabdc2bb77adfb50612f | |
parent | 30d6af7727e2ead6b011663c7ee36b45c47ebe2c (diff) |
starting upload works now
-rw-r--r-- | js/shows.js | 43 |
1 files changed, 36 insertions, 7 deletions
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 = '<div class="progress progress-striped"><div class="bar" style="width: 60%;"></div></div>'; + var progress_bar = '<div class="progress progress-striped"><div class="bar" style="width: 0%;"></div></div>'; var cancel_button = '<button class="btn btn-danger btn-mini">' + '<i class="icon-remove icon-white"></i> Abbrechen</button>'; - return $('<tr>').append($('<td>').text('filename.flac')) - .append($('<td>').text('xx of XX Bytes')) + return $('<tr>').append($('<td>').addClass('file-name').text('-')) + .append($('<td>').addClass('file-bytes').text('??.? von ??.? MB')) .append($('<td colspan=3>').append(progress_bar)) .append($('<td>').append(cancel_button)); } |