Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / form / FilePickerTextBox.js @ 10

History | View | Annotate | Download (7.16 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

    
8
if(!dojo._hasResource["dojox.form.FilePickerTextBox"]){
9
dojo._hasResource["dojox.form.FilePickerTextBox"]=true;
10
dojo.provide("dojox.form.FilePickerTextBox");
11
dojo.require("dojo.window");
12
dojo.require("dijit.form.ValidationTextBox");
13
dojo.require("dijit._HasDropDown");
14
dojo.require("dojox.widget.FilePicker");
15
dojo.declare("dojox.form.FilePickerTextBox",[dijit.form.ValidationTextBox,dijit._HasDropDown],{baseClass:"dojoxFilePickerTextBox",templateString:dojo.cache("dojox.form","resources/FilePickerTextBox.html","<div class=\"dijit dijitReset dijitInlineTable dijitLeft\"\n\tid=\"widget_${id}\"\n\twaiRole=\"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\" waiRole=\"presentation\"\n\t\t\t><div class=\"dijitArrowButtonInner\">&thinsp;</div\n\t\t\t><div class=\"dijitArrowButtonChar\">&#9660;</div\n\t\t></div\n\t\t><div class=\"dijitReset dijitValidationIcon\"><br></div\n\t\t><div class=\"dijitReset dijitValidationIconText\">&Chi;</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' waiRole=\"textbox\" waiState=\"haspopup-true,autocomplete-list\"\n\t\t/></div\n\t></div\n></div>\n"),searchDelay:500,valueItem:null,numPanes:2.25,postMixInProperties:function(){
16
this.inherited(arguments);
17
this.dropDown=new dojox.widget.FilePicker(this.constraints);
18
},postCreate:function(){
19
this.inherited(arguments);
20
this.connect(this.dropDown,"onChange",this._onWidgetChange);
21
this.connect(this.focusNode,"onblur","_focusBlur");
22
this.connect(this.focusNode,"onfocus","_focusFocus");
23
this.connect(this.focusNode,"ondblclick",function(){
24
dijit.selectInputText(this.focusNode);
25
});
26
},_setValueAttr:function(_1,_2,_3){
27
if(!this._searchInProgress){
28
this.inherited(arguments);
29
_1=_1||"";
30
var _4=this.dropDown.attr("pathValue")||"";
31
if(_1!==_4){
32
this._skip=true;
33
var fx=dojo.hitch(this,"_setBlurValue");
34
this.dropDown._setPathValueAttr(_1,!_3,this._settingBlurValue?fx:null);
35
}
36
}
37
},_onWidgetChange:function(_5){
38
if(!_5&&this.focusNode.value){
39
this._hasValidPath=false;
40
this.focusNode.value="";
41
}else{
42
this.valueItem=_5;
43
var _6=this.dropDown._getPathValueAttr(_5);
44
if(_6){
45
this._hasValidPath=true;
46
}
47
if(!this._skip){
48
this._setValueAttr(_6,undefined,true);
49
}
50
delete this._skip;
51
}
52
this.validate();
53
},startup:function(){
54
if(!this.dropDown._started){
55
this.dropDown.startup();
56
}
57
this.inherited(arguments);
58
},openDropDown:function(){
59
this.dropDown.domNode.style.width="0px";
60
if(!("minPaneWidth" in (this.constraints||{}))){
61
this.dropDown.attr("minPaneWidth",(this.domNode.offsetWidth/this.numPanes));
62
}
63
this.inherited(arguments);
64
},toggleDropDown:function(){
65
this.inherited(arguments);
66
if(this._opened){
67
this.dropDown.attr("pathValue",this.get("value"));
68
}
69
},_focusBlur:function(e){
70
if(e.explicitOriginalTarget==this.focusNode&&!this._allowBlur){
71
window.setTimeout(dojo.hitch(this,function(){
72
if(!this._allowBlur){
73
this.focus();
74
}
75
}),1);
76
}else{
77
if(this._menuFocus){
78
this.dropDown._updateClass(this._menuFocus,"Item",{"Hover":false});
79
delete this._menuFocus;
80
}
81
}
82
},_focusFocus:function(e){
83
if(this._menuFocus){
84
this.dropDown._updateClass(this._menuFocus,"Item",{"Hover":false});
85
}
86
delete this._menuFocus;
87
var _7=dijit.getFocus(this);
88
if(_7&&_7.node){
89
_7=dijit.byNode(_7.node);
90
if(_7){
91
this._menuFocus=_7.domNode;
92
}
93
}
94
if(this._menuFocus){
95
this.dropDown._updateClass(this._menuFocus,"Item",{"Hover":true});
96
}
97
delete this._allowBlur;
98
},_onBlur:function(){
99
this._allowBlur=true;
100
delete this.dropDown._savedFocus;
101
this.inherited(arguments);
102
},_setBlurValue:function(){
103
if(this.dropDown&&!this._settingBlurValue){
104
this._settingBlurValue=true;
105
this.set("value",this.focusNode.value);
106
}else{
107
delete this._settingBlurValue;
108
this.inherited(arguments);
109
}
110
},parse:function(_8,_9){
111
if(this._hasValidPath||this._hasSelection){
112
return _8;
113
}
114
var dd=this.dropDown,_a=dd.topDir,_b=dd.pathSeparator;
115
var _c=dd.attr("pathValue");
116
var _d=function(v){
117
if(_a.length&&v.indexOf(_a)===0){
118
v=v.substring(_a.length);
119
}
120
if(_b&&v[v.length-1]==_b){
121
v=v.substring(0,v.length-1);
122
}
123
return v;
124
};
125
_c=_d(_c);
126
var _e=_d(_8);
127
if(_e==_c){
128
return _8;
129
}
130
return undefined;
131
},_startSearchFromInput:function(){
132
var dd=this.dropDown,fn=this.focusNode;
133
var _f=fn.value,_10=_f,_11=dd.topDir;
134
if(this._hasSelection){
135
dijit.selectInputText(fn,_10.length);
136
}
137
this._hasSelection=false;
138
if(_11.length&&_f.indexOf(_11)===0){
139
_f=_f.substring(_11.length);
140
}
141
var _12=_f.split(dd.pathSeparator);
142
var _13=dojo.hitch(this,function(idx){
143
var dir=_12[idx];
144
var _14=dd.getChildren()[idx];
145
var _15;
146
this._searchInProgress=true;
147
var _16=dojo.hitch(this,function(){
148
delete this._searchInProgress;
149
});
150
if((dir||_14)&&!this._opened){
151
this.toggleDropDown();
152
}
153
if(dir&&_14){
154
var fx=dojo.hitch(this,function(){
155
if(_15){
156
this.disconnect(_15);
157
}
158
delete _15;
159
var _17=_14._menu.getChildren();
160
var _18=dojo.filter(_17,function(i){
161
return i.label==dir;
162
})[0];
163
var _19=dojo.filter(_17,function(i){
164
return (i.label.indexOf(dir)===0);
165
})[0];
166
if(_18&&((_12.length>idx+1&&_18.children)||(!_18.children))){
167
idx++;
168
_14._menu.onItemClick(_18,{type:"internal",stopPropagation:function(){
169
},preventDefault:function(){
170
}});
171
if(_12[idx]){
172
_13(idx);
173
}else{
174
_16();
175
}
176
}else{
177
_14._setSelected(null);
178
if(_19&&_12.length===idx+1){
179
dd._setInProgress=true;
180
dd._removeAfter(_14);
181
delete dd._setInProgress;
182
var _1a=_19.label;
183
if(_19.children){
184
_1a+=dd.pathSeparator;
185
}
186
_1a=_1a.substring(dir.length);
187
window.setTimeout(function(){
188
dojo.window.scrollIntoView(_19.domNode);
189
},1);
190
fn.value=_10+_1a;
191
dijit.selectInputText(fn,_10.length);
192
this._hasSelection=true;
193
try{
194
_19.focusNode.focus();
195
}
196
catch(e){
197
}
198
}else{
199
if(this._menuFocus){
200
this.dropDown._updateClass(this._menuFocus,"Item",{"Hover":false,"Focus":false});
201
}
202
delete this._menuFocus;
203
}
204
_16();
205
}
206
});
207
if(!_14.isLoaded){
208
_15=this.connect(_14,"onLoad",fx);
209
}else{
210
fx();
211
}
212
}else{
213
if(_14){
214
_14._setSelected(null);
215
dd._setInProgress=true;
216
dd._removeAfter(_14);
217
delete dd._setInProgress;
218
}
219
_16();
220
}
221
});
222
_13(0);
223
},_onKey:function(e){
224
if(this.disabled||this.readOnly){
225
return;
226
}
227
var dk=dojo.keys;
228
var c=e.charOrCode;
229
if(c==dk.DOWN_ARROW){
230
this._allowBlur=true;
231
}
232
if(c==dk.ENTER&&this._opened){
233
this.dropDown.onExecute();
234
dijit.selectInputText(this.focusNode,this.focusNode.value.length);
235
this._hasSelection=false;
236
dojo.stopEvent(e);
237
return;
238
}
239
if((c==dk.RIGHT_ARROW||c==dk.LEFT_ARROW||c==dk.TAB)&&this._hasSelection){
240
this._startSearchFromInput();
241
dojo.stopEvent(e);
242
return;
243
}
244
this.inherited(arguments);
245
var _1b=false;
246
if((c==dk.BACKSPACE||c==dk.DELETE)&&this._hasSelection){
247
this._hasSelection=false;
248
}else{
249
if(c==dk.BACKSPACE||c==dk.DELETE||c==" "){
250
_1b=true;
251
}else{
252
_1b=e.keyChar!=="";
253
}
254
}
255
if(this._searchTimer){
256
window.clearTimeout(this._searchTimer);
257
}
258
delete this._searchTimer;
259
if(_1b){
260
this._hasValidPath=false;
261
this._hasSelection=false;
262
this._searchTimer=window.setTimeout(dojo.hitch(this,"_startSearchFromInput"),this.searchDelay+1);
263
}
264
}});
265
}