root / trunk / web / dojo / dijit / form / Select.js @ 9
History | View | Annotate | Download (5.46 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["dijit.form.Select"]){ |
| 9 |
dojo._hasResource["dijit.form.Select"]=true; |
| 10 |
dojo.provide("dijit.form.Select");
|
| 11 |
dojo.require("dijit.form._FormSelectWidget");
|
| 12 |
dojo.require("dijit._HasDropDown");
|
| 13 |
dojo.require("dijit.Menu");
|
| 14 |
dojo.require("dijit.Tooltip");
|
| 15 |
dojo.requireLocalization("dijit.form","validate",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw"); |
| 16 |
dojo.declare("dijit.form._SelectMenu",dijit.Menu,{buildRendering:function(){ |
| 17 |
this.inherited(arguments); |
| 18 |
var o=(this.menuTableNode=this.domNode); |
| 19 |
var n=(this.domNode=dojo.create("div",{style:{overflowX:"hidden",overflowY:"scroll"}})); |
| 20 |
if(o.parentNode){
|
| 21 |
o.parentNode.replaceChild(n,o); |
| 22 |
} |
| 23 |
dojo.removeClass(o,"dijitMenuTable");
|
| 24 |
n.className=o.className+" dijitSelectMenu";
|
| 25 |
o.className="dijitReset dijitMenuTable";
|
| 26 |
dijit.setWaiRole(o,"listbox");
|
| 27 |
dijit.setWaiRole(n,"presentation");
|
| 28 |
n.appendChild(o); |
| 29 |
},resize:function(mb){ |
| 30 |
if(mb){
|
| 31 |
dojo.marginBox(this.domNode,mb);
|
| 32 |
if("w" in mb){ |
| 33 |
this.menuTableNode.style.width="100%"; |
| 34 |
} |
| 35 |
} |
| 36 |
}}); |
| 37 |
dojo.declare("dijit.form.Select",[dijit.form._FormSelectWidget,dijit._HasDropDown],{baseClass:"dijitSelect",templateString:dojo.cache("dijit.form","templates/Select.html","<table class=\"dijit dijitReset dijitInline dijitLeft\"\n\tdojoAttachPoint=\"_buttonNode,tableNode,focusNode\" cellspacing='0' cellpadding='0'\n\twaiRole=\"combobox\" waiState=\"haspopup-true\"\n\t><tbody waiRole=\"presentation\"><tr waiRole=\"presentation\"\n\t\t><td class=\"dijitReset dijitStretch dijitButtonContents dijitButtonNode\" waiRole=\"presentation\"\n\t\t\t><span class=\"dijitReset dijitInline dijitButtonText\" dojoAttachPoint=\"containerNode,_popupStateNode\"></span\n\t\t\t><input type=\"hidden\" ${!nameAttrSetting} dojoAttachPoint=\"valueNode\" value=\"${value}\" waiState=\"hidden-true\"\n\t\t/></td><td class=\"dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton\"\n\t\t\t\tdojoAttachPoint=\"titleNode\" waiRole=\"presentation\"\n\t\t\t><div class=\"dijitReset dijitArrowButtonInner\" waiRole=\"presentation\"></div\n\t\t\t><div class=\"dijitReset dijitArrowButtonChar\" waiRole=\"presentation\">▼</div\n\t\t></td\n\t></tr></tbody\n></table>\n"),attributeMap:dojo.mixin(dojo.clone(dijit.form._FormSelectWidget.prototype.attributeMap),{style:"tableNode"}),required:false,state:"",tooltipPosition:[],emptyLabel:"",_isLoaded:false,_childrenLoaded:false,_fillContent:function(){ |
| 38 |
this.inherited(arguments); |
| 39 |
if(this.options.length&&!this.value&&this.srcNodeRef){ |
| 40 |
var si=this.srcNodeRef.selectedIndex; |
| 41 |
this.value=this.options[si!=-1?si:0].value; |
| 42 |
} |
| 43 |
this.dropDown=new dijit.form._SelectMenu({id:this.id+"_menu"}); |
| 44 |
dojo.addClass(this.dropDown.domNode,this.baseClass+"Menu"); |
| 45 |
},_getMenuItemForOption:function(_1){ |
| 46 |
if(!_1.value){
|
| 47 |
return new dijit.MenuSeparator(); |
| 48 |
}else{
|
| 49 |
var _2=dojo.hitch(this,"_setValueAttr",_1); |
| 50 |
var _3=new dijit.MenuItem({option:_1,label:_1.label,onClick:_2,disabled:_1.disabled||false}); |
| 51 |
dijit.setWaiRole(_3.focusNode,"listitem");
|
| 52 |
return _3;
|
| 53 |
} |
| 54 |
},_addOptionItem:function(_4){ |
| 55 |
if(this.dropDown){ |
| 56 |
this.dropDown.addChild(this._getMenuItemForOption(_4)); |
| 57 |
} |
| 58 |
},_getChildren:function(){ |
| 59 |
if(!this.dropDown){ |
| 60 |
return [];
|
| 61 |
} |
| 62 |
return this.dropDown.getChildren(); |
| 63 |
},_loadChildren:function(_5){ |
| 64 |
if(_5===true){ |
| 65 |
if(this.dropDown){ |
| 66 |
delete this.dropDown.focusedChild; |
| 67 |
} |
| 68 |
if(this.options.length){ |
| 69 |
this.inherited(arguments); |
| 70 |
}else{
|
| 71 |
dojo.forEach(this._getChildren(),function(_6){ |
| 72 |
_6.destroyRecursive(); |
| 73 |
}); |
| 74 |
var _7=new dijit.MenuItem({label:" "}); |
| 75 |
this.dropDown.addChild(_7);
|
| 76 |
} |
| 77 |
}else{
|
| 78 |
this._updateSelection();
|
| 79 |
} |
| 80 |
var _8=this.options.length; |
| 81 |
this._isLoaded=false; |
| 82 |
this._childrenLoaded=true; |
| 83 |
if(!this._loadingStore){ |
| 84 |
this._setValueAttr(this.value); |
| 85 |
} |
| 86 |
},_setValueAttr:function(_9){ |
| 87 |
this.inherited(arguments); |
| 88 |
dojo.attr(this.valueNode,"value",this.get("value")); |
| 89 |
},_setDisplay:function(_a){ |
| 90 |
this.containerNode.innerHTML="<span class=\"dijitReset dijitInline "+this.baseClass+"Label\">"+(_a||this.emptyLabel||" ")+"</span>"; |
| 91 |
dijit.setWaiState(this.focusNode,"valuetext",(_a||this.emptyLabel||" ")); |
| 92 |
},validate:function(_b){ |
| 93 |
var _c=this.isValid(_b); |
| 94 |
this.state=_c?"":"Error"; |
| 95 |
this._setStateClass();
|
| 96 |
dijit.setWaiState(this.focusNode,"invalid",_c?"false":"true"); |
| 97 |
var _d=_c?"":this._missingMsg; |
| 98 |
if(this._message!==_d){ |
| 99 |
this._message=_d;
|
| 100 |
dijit.hideTooltip(this.domNode);
|
| 101 |
if(_d){
|
| 102 |
dijit.showTooltip(_d,this.domNode,this.tooltipPosition,!this.isLeftToRight()); |
| 103 |
} |
| 104 |
} |
| 105 |
return _c;
|
| 106 |
},isValid:function(_e){ |
| 107 |
return (!this.required||!(/^\s*$/.test(this.value))); |
| 108 |
},reset:function(){ |
| 109 |
this.inherited(arguments); |
| 110 |
dijit.hideTooltip(this.domNode);
|
| 111 |
this.state=""; |
| 112 |
this._setStateClass();
|
| 113 |
delete this._message; |
| 114 |
},postMixInProperties:function(){ |
| 115 |
this.inherited(arguments); |
| 116 |
this._missingMsg=dojo.i18n.getLocalization("dijit.form","validate",this.lang).missingMessage; |
| 117 |
},postCreate:function(){ |
| 118 |
this.inherited(arguments); |
| 119 |
if(this.tableNode.style.width){ |
| 120 |
dojo.addClass(this.domNode,this.baseClass+"FixedWidth"); |
| 121 |
} |
| 122 |
},isLoaded:function(){ |
| 123 |
return this._isLoaded; |
| 124 |
},loadDropDown:function(_f){ |
| 125 |
this._loadChildren(true); |
| 126 |
this._isLoaded=true; |
| 127 |
_f(); |
| 128 |
},closeDropDown:function(){ |
| 129 |
this.inherited(arguments); |
| 130 |
if(this.dropDown&&this.dropDown.menuTableNode){ |
| 131 |
this.dropDown.menuTableNode.style.width=""; |
| 132 |
} |
| 133 |
},uninitialize:function(_10){ |
| 134 |
if(this.dropDown&&!this.dropDown._destroyed){ |
| 135 |
this.dropDown.destroyRecursive(_10);
|
| 136 |
delete this.dropDown; |
| 137 |
} |
| 138 |
this.inherited(arguments); |
| 139 |
}}); |
| 140 |
} |