1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
//>>built
define("dojox/form/BusyButton", [
"dojo/_base/lang",
"dojo/dom-attr",
"dojo/dom-class",
"dijit/form/Button",
"dijit/form/DropDownButton",
"dijit/form/ComboButton",
"dojo/i18n",
"dojo/i18n!dijit/nls/loading",
"dojo/_base/declare"
], function(lang, domAttr, domClass, Button, DropDownButton, ComboButton, i18n, nlsLoading, declare){
/*=====
Button = dijit.form.Button;
DropDownButton = dijit.form.DropDownButton;
ComboButton = dijit.form.ComboButton;
=====*/
var _BusyButtonMixin = declare("dojox.form._BusyButtonMixin", null, {
isBusy: false,
busyLabel: "", // text while button is busy
timeout: null, // timeout, should be controlled by xhr call
useIcon: true, // use a busy icon
postMixInProperties: function(){
this.inherited(arguments);
if(!this.busyLabel){
this.busyLabel = i18n.getLocalization("dijit", "loading", this.lang).loadingState;
}
},
postCreate: function(){
// summary:
// stores initial label and timeout for reference
this.inherited(arguments);
this._label = this.containerNode.innerHTML;
this._initTimeout = this.timeout;
// for initial busy buttons
if(this.isBusy){
this.makeBusy();
}
},
makeBusy: function(){
// summary:
// sets state from idle to busy
this.isBusy = true;
this.set("disabled", true);
this.setLabel(this.busyLabel, this.timeout);
},
cancel: function(){
// summary:
// if no timeout is set or for other reason the user can put the button back
// to being idle
this.set("disabled", false);
this.isBusy = false;
this.setLabel(this._label);
if(this._timeout){ clearTimeout(this._timeout); }
this.timeout = this._initTimeout;
},
resetTimeout: function(/*Int*/ timeout){
// summary:
// to reset existing timeout and setting a new timeout
if(this._timeout){
clearTimeout(this._timeout);
}
// new timeout
if(timeout){
this._timeout = setTimeout(lang.hitch(this, function(){
this.cancel();
}), timeout);
}else if(timeout == undefined || timeout === 0){
this.cancel();
}
},
setLabel: function(/*String*/ content, /*Int*/ timeout){
// summary:
// setting a label and optional timeout of the labels state
// this.inherited(arguments); FIXME: throws an Unknown runtime error
// Begin IE hack
// summary: reset the label (text) of the button; takes an HTML string
this.label = content;
// remove children
while(this.containerNode.firstChild){
this.containerNode.removeChild(this.containerNode.firstChild);
}
this.containerNode.innerHTML = this.label;
if(this.showLabel == false && !domAttr.get(this.domNode, "title")){
this.titleNode.title=lang.trim(this.containerNode.innerText || this.containerNode.textContent || '');
}
// End IE hack
// setting timeout
if(timeout){
this.resetTimeout(timeout);
}else{
this.timeout = null;
}
// create optional busy image
if(this.useIcon && this.isBusy){
var node = new Image();
node.src = this._blankGif;
domAttr.set(node, "id", this.id+"_icon");
domClass.add(node, "dojoxBusyButtonIcon");
this.containerNode.appendChild(node);
}
},
_onClick: function(e){
// summary:
// on button click the button state gets changed
// only do something if button is not busy
if(!this.isBusy){
this.inherited(arguments); // calls onClick()
this.makeBusy();
}
}
});
var BusyButton = declare("dojox.form.BusyButton", [Button, _BusyButtonMixin], {});
declare("dojox.form.BusyComboButton", [ComboButton, _BusyButtonMixin], {});
declare("dojox.form.BusyDropDownButton", [DropDownButton, _BusyButtonMixin], {});
return BusyButton;
});
|