]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_FormSelectWidget.js
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
8 if(!dojo
._hasResource
["dijit.form._FormSelectWidget"]){
9 dojo
._hasResource
["dijit.form._FormSelectWidget"]=true;
10 dojo
.provide("dijit.form._FormSelectWidget");
11 dojo
.require("dijit.form._FormWidget");
12 dojo
.require("dojo.data.util.sorter");
13 dojo
.declare("dijit.form._FormSelectWidget",dijit
.form
._FormValueWidget
,{multiple
:false,options
:null,store
:null,query
:null,queryOptions
:null,onFetch
:null,sortByLabel
:true,loadChildrenOnOpen
:false,getOptions:function(_1
){
14 var _2
=_1
,_3
=this.options
||[],l
=_3
.length
;
19 return dojo
.map(_2
,"return this.getOptions(item);",this);
21 if(dojo
.isObject(_1
)){
22 if(!dojo
.some(this.options
,function(o
,_4
){
23 if(o
===_2
||(o
.value
&&o
.value
===_2
.value
)){
32 if(typeof _2
=="string"){
40 if(typeof _2
=="number"&&_2
>=0&&_2
<l
){
41 return this.options
[_2
];
44 },addOption:function(_5
){
45 if(!dojo
.isArray(_5
)){
48 dojo
.forEach(_5
,function(i
){
49 if(i
&&dojo
.isObject(i
)){
54 },removeOption:function(_6
){
55 if(!dojo
.isArray(_6
)){
58 var _7
=this.getOptions(_6
);
59 dojo
.forEach(_7
,function(i
){
61 this.options
=dojo
.filter(this.options
,function(_8
,_9
){
62 return (_8
.value
!==i
.value
);
64 this._removeOptionItem(i
);
68 },updateOption:function(_a
){
69 if(!dojo
.isArray(_a
)){
72 dojo
.forEach(_a
,function(i
){
73 var _b
=this.getOptions(i
),k
;
81 },setStore:function(_c
,_d
,_e
){
85 dojo
.forEach(this._notifyConnections
||[],dojo
.disconnect
);
86 delete this._notifyConnections
;
87 if(_c
&&_c
.getFeatures()["dojo.data.api.Notification"]){
88 this._notifyConnections
=[dojo
.connect(_c
,"onNew",this,"_onNewItem"),dojo
.connect(_c
,"onDelete",this,"_onDeleteItem"),dojo
.connect(_c
,"onSet",this,"_onSetItem")];
92 this._onChangeActive
=false;
93 if(this.options
&&this.options
.length
){
94 this.removeOption(this.options
);
98 if(this.sortByLabel
&&!_e
.sort
&&_10
.length
){
99 _10
.sort(dojo
.data
.util
.sorter
.createSortFunction([{attribute
:_c
.getLabelAttributes(_10
[0])[0]}],_c
));
104 dojo
.forEach(_10
,function(i
){
105 this._addOptionForItem(i
);
107 this._loadingStore
=false;
108 this.set("value",(("_pendingValue" in this)?this._pendingValue
:_d
));
109 delete this._pendingValue
;
110 if(!this.loadChildrenOnOpen
){
111 this._loadChildren();
113 this._pseudoLoadChildren(_10
);
115 this._fetchedWith
=_11
;
116 this._lastValueReported
=this.multiple
?[]:null;
117 this._onChangeActive
=true;
119 this._handleOnChange(this.value
);
121 var _11
=dojo
.mixin({onComplete
:cb
,scope
:this},_e
);
122 this._loadingStore
=true;
125 delete this._fetchedWith
;
128 },_setValueAttr:function(_12
,_13
){
129 if(this._loadingStore
){
130 this._pendingValue
=_12
;
133 var _14
=this.getOptions()||[];
134 if(!dojo
.isArray(_12
)){
137 dojo
.forEach(_12
,function(i
,idx
){
138 if(!dojo
.isObject(i
)){
141 if(typeof i
==="string"){
142 _12
[idx
]=dojo
.filter(_14
,function(_15
){
143 return _15
.value
===i
;
144 })[0]||{value
:"",label
:""};
147 _12
=dojo
.filter(_12
,function(i
){
150 if(!this.multiple
&&(!_12
[0]||!_12
[0].value
)&&_14
.length
){
153 dojo
.forEach(_14
,function(i
){
154 i
.selected
=dojo
.some(_12
,function(v
){
155 return v
.value
===i
.value
;
158 var val
=dojo
.map(_12
,function(i
){
160 }),_16
=dojo
.map(_12
,function(i
){
163 this.value
=this.multiple
?val
:val
[0];
164 this._setDisplay(this.multiple
?_16
:_16
[0]);
165 this._updateSelection();
166 this._handleOnChange(this.value
,_13
);
167 },_getDisplayedValueAttr:function(){
168 var val
=this.get("value");
169 if(!dojo
.isArray(val
)){
172 var ret
=dojo
.map(this.getOptions(val
),function(v
){
182 return this.multiple
?ret
:ret
[0];
183 },_getValueDeprecated
:false,getValue:function(){
184 return this._lastValue
;
186 this._setValueAttr(this._lastValueReported
,false);
187 },_loadChildren:function(){
188 if(this._loadingStore
){
191 dojo
.forEach(this._getChildren(),function(_17
){
192 _17
.destroyRecursive();
194 dojo
.forEach(this.options
,this._addOptionItem
,this);
195 this._updateSelection();
196 },_updateSelection:function(){
197 this.value
=this._getValueFromOpts();
199 if(!dojo
.isArray(val
)){
203 dojo
.forEach(this._getChildren(),function(_18
){
204 var _19
=dojo
.some(val
,function(v
){
205 return _18
.option
&&(v
===_18
.option
.value
);
207 dojo
.toggleClass(_18
.domNode
,this.baseClass
+"SelectedOption",_19
);
208 dijit
.setWaiState(_18
.domNode
,"selected",_19
);
211 this._handleOnChange(this.value
);
212 },_getValueFromOpts:function(){
213 var _1a
=this.getOptions()||[];
214 if(!this.multiple
&&_1a
.length
){
215 var opt
=dojo
.filter(_1a
,function(i
){
221 _1a
[0].selected
=true;
226 return dojo
.map(dojo
.filter(_1a
,function(i
){
234 },_onNewItem:function(_1b
,_1c
){
235 if(!_1c
||!_1c
.parent
){
236 this._addOptionForItem(_1b
);
238 },_onDeleteItem:function(_1d
){
240 this.removeOption(_1e
.getIdentity(_1d
));
241 },_onSetItem:function(_1f
){
242 this.updateOption(this._getOptionObjForItem(_1f
));
243 },_getOptionObjForItem:function(_20
){
244 var _21
=this.store
,_22
=_21
.getLabel(_20
),_23
=(_22
?_21
.getIdentity(_20
):null);
245 return {value
:_23
,label
:_22
,item
:_20
};
246 },_addOptionForItem:function(_24
){
248 if(!_25
.isItemLoaded(_24
)){
249 _25
.loadItem({item
:_24
,onComplete:function(i
){
250 this._addOptionForItem(_24
);
254 var _26
=this._getOptionObjForItem(_24
);
256 },constructor:function(_27
){
257 this._oValue
=(_27
||{}).value
||null;
258 },_fillContent:function(){
259 var _28
=this.options
;
261 _28
=this.options
=this.srcNodeRef
?dojo
.query(">",this.srcNodeRef
).map(function(_29
){
262 if(_29
.getAttribute("type")==="separator"){
263 return {value
:"",label
:"",selected
:false,disabled
:false};
265 return {value
:_29
.getAttribute("value"),label
:String(_29
.innerHTML
),selected
:_29
.getAttribute("selected")||false,disabled
:_29
.getAttribute("disabled")||false};
269 this.value
=this._getValueFromOpts();
271 if(this.multiple
&&typeof this.value
=="string"){
272 this.value
=this.value
.split(",");
275 },postCreate:function(){
276 dojo
.setSelectable(this.focusNode
,false);
277 this.inherited(arguments
);
278 this.connect(this,"onChange","_updateSelection");
279 this.connect(this,"startup","_loadChildren");
280 this._setValueAttr(this.value
,null);
281 },startup:function(){
282 this.inherited(arguments
);
283 var _2a
=this.store
,_2b
={};
284 dojo
.forEach(["query","queryOptions","onFetch"],function(i
){
290 if(_2a
&&_2a
.getFeatures()["dojo.data.api.Identity"]){
292 this.setStore(_2a
,this._oValue
,_2b
);
294 },destroy:function(){
295 dojo
.forEach(this._notifyConnections
||[],dojo
.disconnect
);
296 this.inherited(arguments
);
297 },_addOptionItem:function(_2c
){
298 },_removeOptionItem:function(_2d
){
299 },_setDisplay:function(_2e
){
300 },_getChildren:function(){
302 },_getSelectedOptionsAttr:function(){
303 return this.getOptions(this.get("value"));
304 },_pseudoLoadChildren:function(_2f
){
305 },onSetStore:function(){