source: [view]
dojo.provide("dojox.form.FilePickerTextBox");
dojo.require("dojo.window");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit._HasDropDown");
dojo.require("dojox.widget.FilePicker");
dojo.declare(
"dojox.form.FilePickerTextBox",
[dijit.form.ValidationTextBox, dijit._HasDropDown],
{
// summary:
// A validating text box tied to a file picker popup
baseClass: "dojoxFilePickerTextBox",
templateString: dojo.cache("dojox.form", "resources/FilePickerTextBox.html"),
// 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 dojox.widget.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(){
dijit.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 = dojo.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);