| 1 |
define([ |
| 2 |
"dojo/_base/lang", |
| 3 |
"dojo/dom-attr", |
| 4 |
"dojo/dom-class", |
| 5 |
"dojo/dom-construct", |
| 6 |
"dijit/form/Button", |
| 7 |
"dijit/form/DropDownButton", |
| 8 |
"dijit/form/ComboButton", |
| 9 |
"dojo/i18n", |
| 10 |
"dojo/i18n!dijit/nls/loading", |
| 11 |
"dojo/_base/declare" |
| 12 |
], function(lang, domAttr, domClass, domConstruct, Button, DropDownButton, ComboButton, i18n, nlsLoading, declare){ |
| 13 |
return declare("dojox.form._BusyButtonMixin", null, { |
| 14 |
|
| 15 |
|
| 16 |
isBusy: false, |
| 17 |
|
| 18 |
|
| 19 |
isCancelled: false, |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
busyLabel: "", |
| 24 |
|
| 25 |
timeout: null, |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
useIcon: true, |
| 30 |
|
| 31 |
postMixInProperties: function(){ |
| 32 |
this.inherited(arguments); |
| 33 |
if(!this.busyLabel){ |
| 34 |
this.busyLabel = i18n.getLocalization("dijit", "loading", this.lang).loadingState; |
| 35 |
} |
| 36 |
}, |
| 37 |
|
| 38 |
postCreate: function(){ |
| 39 |
|
| 40 |
|
| 41 |
this.inherited(arguments); |
| 42 |
this._label = this.containerNode.innerHTML; |
| 43 |
this._initTimeout = this.timeout; |
| 44 |
|
| 45 |
|
| 46 |
if(this.isBusy){ |
| 47 |
this.makeBusy(); |
| 48 |
} |
| 49 |
}, |
| 50 |
|
| 51 |
makeBusy: function(){ |
| 52 |
|
| 53 |
|
| 54 |
this.isBusy = true; |
| 55 |
this.isCancelled = false; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
if(this._disableHandle) { |
| 60 |
this._disableHandle.remove(); |
| 61 |
} |
| 62 |
this._disableHandle = this.defer(function() { |
| 63 |
this.set("disabled", true); |
| 64 |
}); |
| 65 |
|
| 66 |
this.setLabel(this.busyLabel, this.timeout); |
| 67 |
}, |
| 68 |
|
| 69 |
cancel: function(){ |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
this.isCancelled = true; |
| 74 |
if(this._disableHandle) { |
| 75 |
this._disableHandle.remove(); |
| 76 |
} |
| 77 |
this.set("disabled", false); |
| 78 |
this.isBusy = false; |
| 79 |
this.setLabel(this._label); |
| 80 |
if(this._timeout){ clearTimeout(this._timeout); } |
| 81 |
this.timeout = this._initTimeout; |
| 82 |
}, |
| 83 |
|
| 84 |
resetTimeout: function( timeout){ |
| 85 |
|
| 86 |
|
| 87 |
if(this._timeout){ |
| 88 |
clearTimeout(this._timeout); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
if(timeout){ |
| 93 |
this._timeout = setTimeout(lang.hitch(this, function(){ |
| 94 |
this.cancel(); |
| 95 |
}), timeout); |
| 96 |
}else if(timeout == undefined || timeout === 0){ |
| 97 |
this.cancel(); |
| 98 |
} |
| 99 |
}, |
| 100 |
|
| 101 |
setLabel: function( content, timeout){ |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
this.label = content; |
| 109 |
|
| 110 |
while(this.containerNode.firstChild){ |
| 111 |
this.containerNode.removeChild(this.containerNode.firstChild); |
| 112 |
} |
| 113 |
this.containerNode.appendChild(domConstruct.toDom(this.label)); |
| 114 |
|
| 115 |
if(this.showLabel == false && !domAttr.get(this.domNode, "title")){ |
| 116 |
this.titleNode.title=lang.trim(this.containerNode.innerText || this.containerNode.textContent || ''); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
if(timeout){ |
| 122 |
this.resetTimeout(timeout); |
| 123 |
}else{ |
| 124 |
this.timeout = null; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
if(this.useIcon && this.isBusy){ |
| 129 |
var node = new Image(); |
| 130 |
node.src = this._blankGif; |
| 131 |
domAttr.set(node, "id", this.id+"_icon"); |
| 132 |
domClass.add(node, "dojoxBusyButtonIcon"); |
| 133 |
this.containerNode.appendChild(node); |
| 134 |
} |
| 135 |
}, |
| 136 |
|
| 137 |
_onClick: function(e){ |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
if(!this.isBusy){ |
| 143 |
this.inherited(arguments); |
| 144 |
|
| 145 |
if (!this.isCancelled) { |
| 146 |
this.makeBusy(); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
}); |
| 151 |
}); |