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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
//>>built
require({cache:{
'url:dojox/form/resources/FilePickerTextBox.html':"<div class=\"dijit dijitReset dijitInlineTable dijitLeft\"\n\tid=\"widget_${id}\"\n\trole=\"combobox\" tabIndex=\"-1\"\n\t><div style=\"overflow:hidden;\"\n\t\t><div class='dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton'\n\t\t\tdojoAttachPoint=\"downArrowNode,_buttonNode,_popupStateNode\" role=\"presentation\"\n\t\t\t><div class=\"dijitArrowButtonInner\"> </div\n\t\t\t><div class=\"dijitArrowButtonChar\">▼</div\n\t\t></div\n\t\t><div class=\"dijitReset dijitValidationIcon\"><br></div\n\t\t><div class=\"dijitReset dijitValidationIconText\">Χ</div\n\t\t><div class=\"dijitReset dijitInputField\"\n\t\t\t><input type=\"text\" autocomplete=\"off\" ${!nameAttrSetting} class='dijitReset'\n\t\t\t\tdojoAttachEvent='onkeypress:_onKey' \n\t\t\t\tdojoAttachPoint='textbox,focusNode' role=\"textbox\" aria-haspopup=\"true\" aria-autocomplete=\"list\"\n\t\t/></div\n\t></div\n></div>\n"}});
define("dojox/form/FilePickerTextBox", [
"dojo/_base/lang",
"dojo/_base/array",
"dojo/_base/event",
"dojo/window",
"dijit/focus",
"dijit/registry",
"dijit/form/_TextBoxMixin",
"dijit/form/ValidationTextBox",
"dijit/_HasDropDown",
"dojox/widget/FilePicker",
"dojo/text!./resources/FilePickerTextBox.html",
"dojo/_base/declare",
"dojo/keys" // keys
], function(lang, array, event, windowUtils, focus, registry, _TextBoxMixin, ValidationTextBox, _HasDropDown, FilePicker, template, declare, keys){
/*=====
ValidationTextBox = dijit.form.ValidationTextBox;
_HasDropDown = dijit._HasDropDown;
=====*/
return declare( "dojox.form.FilePickerTextBox", [ValidationTextBox, _HasDropDown],
{
// summary:
// A validating text box tied to a file picker popup
baseClass: "dojoxFilePickerTextBox",
templateString: template,
// searchDelay: Integer
// Delay in milliseconds between when user types something and we start
// searching based on that value
searchDelay: 500,
// valueItem: item
// The item, in our store, of the directory relating to our value
valueItem: null,
// numPanes: number
// The number of panes to display in our box (if we don't have any
// minPaneWidth specified by our constraints)
numPanes: 2.25,
postMixInProperties: function(){
this.inherited(arguments);
this.dropDown = new FilePicker(this.constraints);
},
postCreate: function(){
this.inherited(arguments);
// Make our connections we want
this.connect(this.dropDown, "onChange", this._onWidgetChange);
this.connect(this.focusNode, "onblur", "_focusBlur");
this.connect(this.focusNode, "onfocus", "_focusFocus");
this.connect(this.focusNode, "ondblclick", function(){
_TextBoxMixin.selectInputText(this.focusNode);
});
},
_setValueAttr: function(/*string*/value, priorityChange, fromWidget){
// summary: sets the value of this widget
if(!this._searchInProgress){
this.inherited(arguments);
value = value || "";
var tVal = this.dropDown.get("pathValue") || "";
if(value !== tVal){
this._skip = true;
var fx = lang.hitch(this, "_setBlurValue");
this.dropDown._setPathValueAttr(value, !fromWidget,
this._settingBlurValue ? fx : null);
}
}
},
_onWidgetChange: function(/*item*/item){
// summary: called when the path gets changed in the dropdown
if(!item && this.focusNode.value){
this._hasValidPath = false;
this.focusNode.value = "";
}else{
this.valueItem = item;
var value = this.dropDown._getPathValueAttr(item);
if(value){
this._hasValidPath = true;
}
if(!this._skip){
this._setValueAttr(value, undefined, true);
}
delete this._skip;
}
this.validate();
},
startup: function(){
if(!this.dropDown._started){
this.dropDown.startup();
}
this.inherited(arguments);
},
openDropDown: function(){
// set width to 0 so that it will resize automatically
this.dropDown.domNode.style.width="0px";
if(!("minPaneWidth" in (this.constraints||{}))){
this.dropDown.set("minPaneWidth", (this.domNode.offsetWidth / this.numPanes));
}
this.inherited(arguments);
},
toggleDropDown: function(){
this.inherited(arguments);
// Make sure our display is up-to-date with our value
if(this._opened){
this.dropDown.set("pathValue", this.get("value"));
}
},
_focusBlur: function(/*Event*/ e){
// summary: called when the focus node gets blurred
if(e.explicitOriginalTarget == this.focusNode && !this._allowBlur){
window.setTimeout(lang.hitch(this, function(){
if(!this._allowBlur){
this.focus();
}
}), 1);
}else if(this._menuFocus){
this.dropDown._updateClass(this._menuFocus, "Item", {"Hover": false});
delete this._menuFocus;
}
},
_focusFocus: function(/*Event*/ e){
// summary: called when the focus node gets focus
if(this._menuFocus){
this.dropDown._updateClass(this._menuFocus, "Item", {"Hover": false});
}
delete this._menuFocus;
var focusNode = focus.curNode;
if(focusNode){
focusNode = registry.byNode(focusNode);
if(focusNode){
this._menuFocus = focusNode.domNode;
}
}
if(this._menuFocus){
this.dropDown._updateClass(this._menuFocus, "Item", {"Hover": true});
}
delete this._allowBlur;
},
_onBlur: function(){
// summary: called when focus is shifted away from this widget
this._allowBlur = true;
delete this.dropDown._savedFocus;
this.inherited(arguments);
},
_setBlurValue: function(){
// summary: sets the value of the widget once focus has left
if(this.dropDown && !this._settingBlurValue){
this._settingBlurValue = true;
this.set("value", this.focusNode.value);
}else{
delete this._settingBlurValue;
this.inherited(arguments);
}
},
parse: function(/* String */ value, /* Object */ constraints){
// summary:
// Function to convert a formatted string to a value - we use
// it to verify that it *really* is a valid value
if(this._hasValidPath || this._hasSelection){
return value;
}
var dd = this.dropDown, topDir = dd.topDir, sep = dd.pathSeparator;
var ddVal = dd.get("pathValue");
var norm = function(v){
if(topDir.length && v.indexOf(topDir) === 0){
v = v.substring(topDir.length);
}
if(sep && v[v.length - 1] == sep){
v = v.substring(0, v.length - 1);
}
return v;
};
ddVal = norm(ddVal);
var val = norm(value);
if(val == ddVal){
return value;
}
return undefined;
},
_startSearchFromInput: function(){
// summary: kicks off a search based off the current text value of the widget
var dd = this.dropDown, fn = this.focusNode;
var val = fn.value, oVal = val, topDir = dd.topDir;
if(this._hasSelection){
_TextBoxMixin.selectInputText(fn, oVal.length);
}
this._hasSelection = false;
if(topDir.length && val.indexOf(topDir) === 0){
val = val.substring(topDir.length);
}
var dirs = val.split(dd.pathSeparator);
var setFromChain = lang.hitch(this, function(idx){
var dir = dirs[idx];
var child = dd.getChildren()[idx];
var conn;
this._searchInProgress = true;
var _cleanup = lang.hitch(this, function(){
delete this._searchInProgress;
});
if((dir || child) && !this._opened){
this.toggleDropDown();
}
if(dir && child){
var fx = lang.hitch(this, function(){
if(conn){
this.disconnect(conn);
}
delete conn;
var children = child._menu.getChildren();
var exact = array.filter(children, function(i){
return i.label == dir;
})[0];
var first = array.filter(children, function(i){
return (i.label.indexOf(dir) === 0);
})[0];
if(exact &&
((dirs.length > idx + 1 && exact.children) ||
(!exact.children))){
idx++;
child._menu.onItemClick(exact, {type: "internal",
stopPropagation: function(){},
preventDefault: function(){}});
if(dirs[idx]){
setFromChain(idx);
}else{
_cleanup();
}
}else{
child._setSelected(null);
if(first && dirs.length === idx + 1){
dd._setInProgress = true;
dd._removeAfter(child);
delete dd._setInProgress;
var targetString = first.label;
if(first.children){
targetString += dd.pathSeparator;
}
targetString = targetString.substring(dir.length);
window.setTimeout(function(){
windowUtils.scrollIntoView(first.domNode);
}, 1);
fn.value = oVal + targetString;
_TextBoxMixin.selectInputText(fn, oVal.length);
this._hasSelection = true;
try{first.focusNode.focus();}catch(e){}
}else{
if(this._menuFocus){
this.dropDown._updateClass(this._menuFocus, "Item", {"Hover": false, "Focus": false});
}
delete this._menuFocus;
}
_cleanup();
}
});
if(!child.isLoaded){
conn = this.connect(child, "onLoad", fx);
}else{
fx();
}
}else{
if(child){
child._setSelected(null);
dd._setInProgress = true;
dd._removeAfter(child);
delete dd._setInProgress;
}
_cleanup();
}
});
setFromChain(0);
},
_onKey: function(/*Event*/ e){
// summary: callback when the user presses a key on menu popup node
if(this.disabled || this.readOnly){ return; }
var c = e.charOrCode;
if(c==keys.DOWN_ARROW){
this._allowBlur = true;
}
if(c==keys.ENTER && this._opened){
this.dropDown.onExecute();
_TextBoxMixin.selectInputText(this.focusNode, this.focusNode.value.length);
this._hasSelection = false;
event.stop(e);
return;
}
if((c==keys.RIGHT_ARROW || c==keys.LEFT_ARROW || c==keys.TAB) && this._hasSelection){
this._startSearchFromInput();
event.stop(e);
return;
}
this.inherited(arguments);
var doSearch = false;
if((c==keys.BACKSPACE || c==keys.DELETE) && this._hasSelection){
this._hasSelection = false;
}else if(c==keys.BACKSPACE || c==keys.DELETE || c==" "){
doSearch = true;
}else{
doSearch = e.keyChar !== "";
}
if(this._searchTimer){
window.clearTimeout(this._searchTimer);
}
delete this._searchTimer;
if(doSearch){
this._hasValidPath = false;
this._hasSelection = false;
this._searchTimer = window.setTimeout(lang.hitch(this, "_startSearchFromInput"), this.searchDelay + 1);
}
}
}
);
});
|