Skip to content

Commit

Permalink
disable drop zone if control is disabled (DevExpress#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailTymchukDX authored Aug 4, 2016
1 parent 64dc812 commit bf7e57a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
15 changes: 15 additions & 0 deletions AjaxControlToolkit.Jasmine/Suites/AjaxFileUploadTests.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@

<act:AjaxFileUpload runat="server" ID="TestAjaxFileUpload2" />

<act:AjaxFileUpload runat="server" ID="DisabledAjaxFileUpload" Enabled="false" />

<script>
describe("AjaxFileUpload", function() {
var AJAX_FILE_UPLOAD_CLIENT_ID = "<%= TestAjaxFileUpload.ClientID %>";
var AJAX_FILE_UPLOAD2_CLIENT_ID = "<%= TestAjaxFileUpload2.ClientID %>";
var DISABLED_AJAX_FILE_UPLOAD_CLIENT_ID = "<%= DisabledAjaxFileUpload.ClientID %>";
beforeEach(function() {
this.ajaxFileUploadExtender = $find(AJAX_FILE_UPLOAD_CLIENT_ID);
this.ajaxFileUploadExtender2 = $find(AJAX_FILE_UPLOAD2_CLIENT_ID);
this.disabledAjaxFileUploadExtender = $find(DISABLED_AJAX_FILE_UPLOAD_CLIENT_ID);
});
it("hides upload button inside tabs", function() {
Expand Down Expand Up @@ -73,6 +77,17 @@
expect(this.ajaxFileUploadExtender.get_uploadHandlerPath()).toBe("/AjaxFileUploadHandler.axd");
});
it("reads Enabled property from server", function () {
expect(this.disabledAjaxFileUploadExtender.get_enabled()).toBe(false);
});
it("does not allow to drop files if disabled", function () {
spyOn(this.disabledAjaxFileUploadExtender._processor, "addFilesToQueue");
var fakeEvent = { stopPropagation: function () { }, preventDefault: function () { } };
this.disabledAjaxFileUploadExtender._processor.onFileDroppedHandler(fakeEvent);
expect(this.disabledAjaxFileUploadExtender._processor.addFilesToQueue).not.toHaveBeenCalled();
});
});
</script>
</asp:Content>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ protected override void DescribeComponent(ScriptComponentDescriptor descriptor)
descriptor.AddProperty("contextKey", ContextKey);
descriptor.AddProperty("postBackUrl", Page.Request.RawUrl);
descriptor.AddProperty("serverPollingSupport", ServerPollingSupport);
descriptor.AddProperty("enabled", Enabled);

if(ThrobberID != String.Empty) {
Control control = FindControl(ThrobberID);
Expand Down
17 changes: 17 additions & 0 deletions AjaxControlToolkit/Scripts/AjaxFileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {
this.onFileDroppedHandler = function(e) {
e.stopPropagation();
e.preventDefault();

if(!control.get_enabled())
return;

this.addFilesToQueue(e.dataTransfer.files);

if (control.get_autoStartUpload()) {
Expand Down Expand Up @@ -1040,6 +1044,13 @@ Sys.Extended.UI.AjaxFileUpload.Control = function(element) {
/// <setter>set_uploadHandlerPath</setter>
/// <member name="cP:AjaxControlToolkit.AjaxFileUpload.uploadHandlerPath" />
this._uploadHandlerPath = '/AjaxFileUploadHandler.axd';
/// <summary>
/// Whether the control is enabled.
/// </summary>
/// <getter>get_enabled</getter>
/// <setter>set_enabled</setter>
/// <member name="cP:AjaxControlToolkit.AjaxFileUpload.enabled" />
this._enabled = true;
this._useHtml5Support = false;
this._elements = null;
this._processor = null;
Expand Down Expand Up @@ -1650,6 +1661,12 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
set_uploadHandlerPath: function (value) {
this._uploadHandlerPath = value;
},
get_enabled: function () {
return this.enabled;
},
set_enabled: function (value) {
this.enabled = value;
},

/// <summary>
/// Occurs when the file upload starts
Expand Down
2 changes: 1 addition & 1 deletion AjaxControlToolkit/Scripts/AjaxFileUpload.min.js

Large diffs are not rendered by default.

0 comments on commit bf7e57a

Please sign in to comment.