Skip to content

Commit

Permalink
AjaxFileUpload correctly handles server erros (CodePlex item 27327)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailTymchukDX committed Oct 15, 2015
1 parent 731e87a commit ffb00d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion AjaxControlToolkit/Scripts/AjaxFileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {
}
};

this.resetUI = function () {
$common.setVisible(elements.progressBarContainer, false);
$common.setVisible(control._elements.uploadOrCancelButton, false);

var fileItem = control.getNextFile();
fileItem._isUploaded = true;
fileItem._isUploading = false;
},

this.upload = function(fileItem) {
if(!control._isUploading)
return;
Expand Down Expand Up @@ -1092,6 +1101,7 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
self.raise_uploadStart(Sys.Serialization.JavaScriptSerializer.deserialize(xhr.responseText));
} else {
self.raise_uploadError(xhr);
self.setFileStatus(fileItem, 'error', Sys.Extended.UI.Resources.AjaxFileUpload_error);
throw "Failed to starting upload.";
}
}
Expand Down Expand Up @@ -1158,6 +1168,7 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
self.raise_uploadCompleteAll(Sys.Serialization.JavaScriptSerializer.deserialize(xhr.responseText));
} else {
self.raise_uploadError(xhr);
self.setFileStatus(fileItem, 'error', Sys.Extended.UI.Resources.AjaxFileUpload_error);
throw "Failed to completing upload.";
}
}
Expand Down Expand Up @@ -1295,7 +1306,7 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
xhr.open("POST", "?contextKey=" + this.get_id() + "&done=1&guid=" + fileItem._id, true);
xhr.onreadystatechange = function(e) {
if(xhr.readyState == 4) {
if(xhr.status == 200) {
if (xhr.status == 200 && xhr.responseText != "") {

// Mark as done and invoke event handler
self.raise_uploadComplete(Sys.Serialization.JavaScriptSerializer.deserialize(xhr.responseText));
Expand Down Expand Up @@ -1570,8 +1581,11 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
eh(this, e);
}

this._processor.resetUI();

this._canceled = false;
this._isUploading = false;
this._isUploaded = true;
this.enableControls(true);
},

Expand Down
Loading

0 comments on commit ffb00d3

Please sign in to comment.