Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / form / _SelectStackMixin.js

History | View | Annotate | Download (3.83 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._SelectStackMixin"]){
9
dojo._hasResource["dojox.form._SelectStackMixin"]=true;
10
dojo.provide("dojox.form._SelectStackMixin");
11
dojo.declare("dojox.form._SelectStackMixin",null,{stackId:"",stackPrefix:"",_paneIdFromOption:function(_1){
12
return (this.stackPrefix||"")+_1;
13
},_optionValFromPane:function(id){
14
var sp=this.stackPrefix;
15
if(sp&&id.indexOf(sp)===0){
16
return id.substring(sp.length);
17
}
18
return id;
19
},_togglePane:function(_2,_3){
20
if(_2._shown!=undefined&&_2._shown==_3){
21
return;
22
}
23
var _4=dojo.filter(_2.getDescendants(),"return item.name;");
24
if(!_3){
25
_5={};
26
dojo.forEach(_4,function(w){
27
_5[w.id]=w.disabled;
28
w.attr("disabled",true);
29
});
30
_2._savedStates=_5;
31
}else{
32
var _5=_2._savedStates||{};
33
dojo.forEach(_4,function(w){
34
var _6=_5[w.id];
35
if(_6==undefined){
36
_6=false;
37
}
38
w.attr("disabled",_6);
39
});
40
delete _2._savedStates;
41
}
42
_2._shown=_3;
43
},_connectTitle:function(_7,_8){
44
var fx=dojo.hitch(this,function(_9){
45
this.updateOption({value:_8,label:_9});
46
});
47
if(_7._setTitleAttr){
48
this.connect(_7,"_setTitleAttr",fx);
49
}else{
50
this.connect(_7,"attr",function(_a,_b){
51
if(_a=="title"&&arguments.length>1){
52
fx(_b);
53
}
54
});
55
}
56
},onAddChild:function(_c,_d){
57
if(!this._panes[_c.id]){
58
this._panes[_c.id]=_c;
59
var v=this._optionValFromPane(_c.id);
60
this.addOption({value:v,label:_c.title});
61
this._connectTitle(_c,v);
62
}
63
if(!_c.onShow||!_c.onHide||_c._shown==undefined){
64
_c.onShow=dojo.hitch(this,"_togglePane",_c,true);
65
_c.onHide=dojo.hitch(this,"_togglePane",_c,false);
66
_c.onHide();
67
}
68
},_setValueAttr:function(v){
69
if("_savedValue" in this){
70
return;
71
}
72
this.inherited(arguments);
73
},attr:function(_e,_f){
74
if(_e=="value"&&arguments.length==2&&"_savedValue" in this){
75
this._savedValue=_f;
76
}
77
return this.inherited(arguments);
78
},onRemoveChild:function(_10){
79
if(this._panes[_10.id]){
80
delete this._panes[_10.id];
81
this.removeOption(this._optionValFromPane(_10.id));
82
}
83
},onSelectChild:function(_11){
84
this._setValueAttr(this._optionValFromPane(_11.id));
85
},onStartup:function(_12){
86
var _13=_12.selected;
87
this.addOption(dojo.filter(dojo.map(_12.children,function(c){
88
var v=this._optionValFromPane(c.id);
89
this._connectTitle(c,v);
90
var _14=null;
91
if(!this._panes[c.id]){
92
this._panes[c.id]=c;
93
_14={value:v,label:c.title};
94
}
95
if(!c.onShow||!c.onHide||c._shown==undefined){
96
c.onShow=dojo.hitch(this,"_togglePane",c,true);
97
c.onHide=dojo.hitch(this,"_togglePane",c,false);
98
c.onHide();
99
}
100
if("_savedValue" in this&&v===this._savedValue){
101
_13=c;
102
}
103
return _14;
104
},this),function(i){
105
return i;
106
}));
107
var _15=this;
108
var fx=function(){
109
delete _15._savedValue;
110
_15.onSelectChild(_13);
111
if(!_13._shown){
112
_15._togglePane(_13,true);
113
}
114
};
115
if(_13!==_12.selected){
116
var _16=dijit.byId(this.stackId);
117
var c=this.connect(_16,"_showChild",function(sel){
118
this.disconnect(c);
119
fx();
120
});
121
}else{
122
fx();
123
}
124
},postMixInProperties:function(){
125
this._savedValue=this.value;
126
this.inherited(arguments);
127
this.connect(this,"onChange","_handleSelfOnChange");
128
},postCreate:function(){
129
this.inherited(arguments);
130
this._panes={};
131
this._subscriptions=[dojo.subscribe(this.stackId+"-startup",this,"onStartup"),dojo.subscribe(this.stackId+"-addChild",this,"onAddChild"),dojo.subscribe(this.stackId+"-removeChild",this,"onRemoveChild"),dojo.subscribe(this.stackId+"-selectChild",this,"onSelectChild")];
132
var _17=dijit.byId(this.stackId);
133
if(_17&&_17._started){
134
this.onStartup({children:_17.getChildren(),selected:_17.selectedChildWidget});
135
}
136
},destroy:function(){
137
dojo.forEach(this._subscriptions,dojo.unsubscribe);
138
delete this._panes;
139
this.inherited("destroy",arguments);
140
},_handleSelfOnChange:function(val){
141
var _18=this._panes[this._paneIdFromOption(val)];
142
if(_18){
143
var s=dijit.byId(this.stackId);
144
if(_18==s.selectedChildWidget){
145
s._transition(_18);
146
}else{
147
s.selectChild(_18);
148
}
149
}
150
}});
151
}