forked from Public/pics
Implement upload throttling: one file at a time.
This commit is contained in:
@@ -697,6 +697,11 @@ a#previous_photo:hover, a#next_photo:hover {
|
||||
#upload_preview_area .progress .error {
|
||||
background: #b22;
|
||||
}
|
||||
#photo_submit:disabled {
|
||||
background: #ccc;
|
||||
color: #777;
|
||||
border-color: #aaa;
|
||||
}
|
||||
|
||||
/* Spinner animation
|
||||
----------------------*/
|
||||
|
||||
@@ -15,6 +15,7 @@ UploadQueue.prototype.addEvents = function() {
|
||||
for (var i = 0; i < that.queue.files.length; i++) {
|
||||
var callback = (i !== that.queue.files.length - 1) ? null : function() {
|
||||
that.hideSpinner();
|
||||
that.submit.disabled = false;
|
||||
};
|
||||
that.addPreviewForFile(that.queue.files[i], i, callback);
|
||||
};
|
||||
@@ -23,10 +24,13 @@ UploadQueue.prototype.addEvents = function() {
|
||||
e.preventDefault();
|
||||
that.process();
|
||||
});
|
||||
this.submit.disabled = true;
|
||||
};
|
||||
|
||||
UploadQueue.prototype.clearPreviews = function() {
|
||||
this.preview_area.innerHTML = '';
|
||||
this.submit.disabled = true;
|
||||
this.current_upload_index = -1;
|
||||
}
|
||||
|
||||
UploadQueue.prototype.addPreviewForFile = function(file, index, callback) {
|
||||
@@ -67,16 +71,24 @@ UploadQueue.prototype.addPreviewForFile = function(file, index, callback) {
|
||||
|
||||
UploadQueue.prototype.process = function() {
|
||||
this.showSpinner(this.submit, "Preparing to upload files...");
|
||||
var files = this.queue.files;
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
this.setSpinnerLabel("Uploading file " + (i + 1) + " out of " + files.length);
|
||||
var callback = (i !== files.length - 1) ? null : function() {
|
||||
this.hideSpinner();
|
||||
};
|
||||
this.sendFile(files[i], i, callback);
|
||||
};
|
||||
if (this.queue.files.length > 0) {
|
||||
this.submit.disabled = true;
|
||||
this.nextFile();
|
||||
}
|
||||
};
|
||||
|
||||
UploadQueue.prototype.nextFile = function() {
|
||||
var files = this.queue.files;
|
||||
var i = ++this.current_upload_index;
|
||||
if (i === files.length) {
|
||||
this.hideSpinner();
|
||||
} else {
|
||||
this.setSpinnerLabel("Uploading file " + (i + 1) + " out of " + files.length);
|
||||
this.sendFile(files[i], i, function() {
|
||||
this.nextFile();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
UploadQueue.prototype.sendFile = function(file, index, callback) {
|
||||
// Prepare the request.
|
||||
|
||||
Reference in New Issue
Block a user