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 all commits
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 @@ -139,6 +139,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
42 changes: 39 additions & 3 deletions AjaxControlToolkit/Scripts/AjaxFileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {
e.stopPropagation();
e.preventDefault();
this.addFilesToQueue(e.dataTransfer.files);

if (control.get_autoStartUpload()) {
control.startUpload();
}

};

this.onFileDragOverHandler = function(e) {
Expand All @@ -594,6 +599,10 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {
this.onFileSelectedHandler = function(e) {
this.addFilesToQueue(e.target.files);
this.createInputFileElement();

if (control.get_autoStartUpload()) {
control.startUpload();
}
};

this.createInputFileElement = function() {
Expand Down Expand Up @@ -633,10 +642,10 @@ 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++) {
// Validate and generate file item from HTML5 files.
for (var i = 0; i < files.length; i++) {

var blob = files[i],
slices = 0;
Expand Down Expand Up @@ -953,6 +962,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 @@ -1182,6 +1199,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 @@ -1530,6 +1559,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
Loading