Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto upload feature #19

Merged
merged 5 commits into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ public AjaxFileUpload()
set { ViewState["Mode"] = value.ToString(); }
}

/// <summary>
/// Whether or not automatically start upload files after drag/drop or select in file dialog. The default is false
/// </summary>
[ExtenderControlProperty]
[DefaultValue(false)]
[ClientPropertyName("autoStartUpload")]
public bool AutoStartUpload
{
get { return bool.Parse((string)ViewState["AutoStartUpload"] ?? "false"); }
set { ViewState["AutoStartUpload"] = value.ToString(); }
}

/// <summary>
/// An event raised when the file upload starts.
/// </summary>
Expand Down
45 changes: 41 additions & 4 deletions AjaxControlToolkit/Scripts/AjaxFileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,13 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {

// #endregion

this.addFilesToQueue = function(files) {
// Validate and generate file item from HTML5 files.
this.addFilesToQueue = function (files) {

for(var i = 0; i < files.length; i++) {
var startUpload = true;
var fileCount = files.length; // store original value for later purposes (under WebKit/Blink the collection lenght is modified )

// Validate and generate file item from HTML5 files.
for (var i = 0; i < files.length; i++) {

var blob = files[i],
slices = 0;
Expand All @@ -636,15 +639,22 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {

// validate it, add it if it's OK
if(control.fileTypeIsValid(fileItem.type)) {
if(!control.addFileToQueue(fileItem))
if (!control.addFileToQueue(fileItem)) {
startUpload = false;
break;
}
} else {
startUpload = false;
control.confirmFileIsInvalid(fileItem);
}
}

// reset input file value so 'change' event can be fired again with same file name.
elements.inputFile.value = null;

if (fileCount > 0 && startUpload && control.get_autoStartUpload()) {
control.startUpload();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this check and control.startUpload() outside the method (see comment below).

}
};

this.cancelUpload = function() {
Expand Down Expand Up @@ -917,6 +927,14 @@ Sys.Extended.UI.AjaxFileUpload.Control = function(element) {
/// <member name="cP:AjaxControlToolkit.AjaxFileUpload.mode" />
this._mode = 0;

/// <summary>
/// Whether or not automatically start upload files after drag/drop or select in file dialog. The default is false
/// </summary>
/// <getter>get_autoStartUpload</getter>
/// <setter>set_autoStartUpload</setter>
/// <member name="cP:AjaxControlToolkit.AjaxFileUpload.autoStartUpload" />
this._autoStartUpload = false;

/// <summary>
/// Whether or not AjaxFileUpload supports server polling.
/// </summary>
Expand Down Expand Up @@ -1135,6 +1153,18 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
}
},

/// <summary>
/// Manually starts upload process
/// </summary>
startUpload: function () {
if (this._isUploading || !this._filesInQueue.length) {
return;
}

this._onUploadOrCancelButtonClickedHandler();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling _onUploadOrCancelButtonClickedHandler() directly starts upload process before createInputFileElement() call in onFileSelectedHandler:

this.onFileSelectedHandler = function(e) {
    this.addFilesToQueue(e.target.files);
    this.createInputFileElement();
};

Change onFileDroppedHandler() and onFileDroppedHandler() so that startUpload() is called at the end of the methods.

},


/// <summary>
/// If set to true, it will set the control state to enabled (ready to upload),
/// otherwise the control will be disabled and the button state turns to the Cancel button.
Expand Down Expand Up @@ -1450,6 +1480,13 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
this._mode = value;
},

get_autoStartUpload: function () {
return this._autoStartUpload;
},
set_autoStartUpload: function (value) {
this._autoStartUpload = value;
},

get_serverPollingSupport: function() {
return this._serverPollingSupport;
},
Expand Down