root / trunk / web / dojo / dojox / grid / TreeSelection.js @ 12
History | View | Annotate | Download (3.9 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.grid.TreeSelection"]){ |
||
9 | dojo._hasResource["dojox.grid.TreeSelection"]=true; |
||
10 | dojo.provide("dojox.grid.TreeSelection");
|
||
11 | dojo.require("dojox.grid.DataSelection");
|
||
12 | dojo.declare("dojox.grid.TreeSelection",dojox.grid.DataSelection,{setMode:function(_1){ |
||
13 | this.selected={};
|
||
14 | this.sorted_sel=[];
|
||
15 | this.sorted_ltos={};
|
||
16 | this.sorted_stol={};
|
||
17 | dojox.grid.DataSelection.prototype.setMode.call(this,_1);
|
||
18 | },addToSelection:function(_2){ |
||
19 | if(this.mode=="none"){ |
||
20 | return;
|
||
21 | } |
||
22 | var _3=null; |
||
23 | if(typeof _2=="number"||typeof _2=="string"){ |
||
24 | _3=_2; |
||
25 | }else{
|
||
26 | _3=this.grid.getItemIndex(_2);
|
||
27 | } |
||
28 | if(this.selected[_3]){ |
||
29 | this.selectedIndex=_3;
|
||
30 | }else{
|
||
31 | if(this.onCanSelect(_3)!==false){ |
||
32 | this.selectedIndex=_3;
|
||
33 | var _4=dojo.query("tr[dojoxTreeGridPath='"+_3+"']",this.grid.domNode); |
||
34 | if(_4.length){
|
||
35 | dojo.attr(_4[0],"aria-selected","true"); |
||
36 | } |
||
37 | this._beginUpdate();
|
||
38 | this.selected[_3]=true; |
||
39 | this._insertSortedSelection(_3);
|
||
40 | this.onSelected(_3);
|
||
41 | this._endUpdate();
|
||
42 | } |
||
43 | } |
||
44 | },deselect:function(_5){ |
||
45 | if(this.mode=="none"){ |
||
46 | return;
|
||
47 | } |
||
48 | var _6=null; |
||
49 | if(typeof _5=="number"||typeof _5=="string"){ |
||
50 | _6=_5; |
||
51 | }else{
|
||
52 | _6=this.grid.getItemIndex(_5);
|
||
53 | } |
||
54 | if(this.selectedIndex==_6){ |
||
55 | this.selectedIndex=-1; |
||
56 | } |
||
57 | if(this.selected[_6]){ |
||
58 | if(this.onCanDeselect(_6)===false){ |
||
59 | return;
|
||
60 | } |
||
61 | var _7=dojo.query("tr[dojoxTreeGridPath='"+_6+"']",this.grid.domNode); |
||
62 | if(_7.length){
|
||
63 | dojo.attr(_7[0],"aria-selected","false"); |
||
64 | } |
||
65 | this._beginUpdate();
|
||
66 | delete this.selected[_6]; |
||
67 | this._removeSortedSelection(_6);
|
||
68 | this.onDeselected(_6);
|
||
69 | this._endUpdate();
|
||
70 | } |
||
71 | },getSelected:function(){ |
||
72 | var _8=[];
|
||
73 | for(var i in this.selected){ |
||
74 | if(this.selected[i]){ |
||
75 | _8.push(this.grid.getItem(i));
|
||
76 | } |
||
77 | } |
||
78 | return _8;
|
||
79 | },getSelectedCount:function(){ |
||
80 | var c=0; |
||
81 | for(var i in this.selected){ |
||
82 | if(this.selected[i]){ |
||
83 | c++; |
||
84 | } |
||
85 | } |
||
86 | return c;
|
||
87 | },_bsearch:function(v){ |
||
88 | var o=this.sorted_sel; |
||
89 | var h=o.length-1,l=0,m; |
||
90 | while(l<=h){
|
||
91 | var _9=this._comparePaths(o[m=(l+h)>>1],v); |
||
92 | if(_9<0){ |
||
93 | l=m+1;
|
||
94 | continue;
|
||
95 | } |
||
96 | if(_9>0){ |
||
97 | h=m-1;
|
||
98 | continue;
|
||
99 | } |
||
100 | return m;
|
||
101 | } |
||
102 | return _9<0?m-_9:m; |
||
103 | },_comparePaths:function(a,b){ |
||
104 | for(var i=0,l=(a.length<b.length?a.length:b.length);i<l;i++){ |
||
105 | if(a[i]<b[i]){
|
||
106 | return -1; |
||
107 | } |
||
108 | if(a[i]>b[i]){
|
||
109 | return 1; |
||
110 | } |
||
111 | } |
||
112 | if(a.length<b.length){
|
||
113 | return -1; |
||
114 | } |
||
115 | if(a.length>b.length){
|
||
116 | return 1; |
||
117 | } |
||
118 | return 0; |
||
119 | },_insertSortedSelection:function(_a){ |
||
120 | _a=String(_a); |
||
121 | var s=this.sorted_sel; |
||
122 | var sl=this.sorted_ltos; |
||
123 | var ss=this.sorted_stol; |
||
124 | var _b=_a.split("/"); |
||
125 | _b=dojo.map(_b,function(_c){
|
||
126 | return parseInt(_c,10); |
||
127 | }); |
||
128 | sl[_b]=_a; |
||
129 | ss[_a]=_b; |
||
130 | if(s.length===0){ |
||
131 | s.push(_b); |
||
132 | return;
|
||
133 | } |
||
134 | if(s.length==1){ |
||
135 | var _d=this._comparePaths(s[0],_b); |
||
136 | if(_d==1){ |
||
137 | s.unshift(_b); |
||
138 | }else{
|
||
139 | s.push(_b); |
||
140 | } |
||
141 | return;
|
||
142 | } |
||
143 | var _e=this._bsearch(_b); |
||
144 | this.sorted_sel.splice(_e,0,_b); |
||
145 | },_removeSortedSelection:function(_f){ |
||
146 | _f=String(_f); |
||
147 | var s=this.sorted_sel; |
||
148 | var sl=this.sorted_ltos; |
||
149 | var ss=this.sorted_stol; |
||
150 | if(s.length===0){ |
||
151 | return;
|
||
152 | } |
||
153 | var _10=ss[_f];
|
||
154 | if(!_10){
|
||
155 | return;
|
||
156 | } |
||
157 | var idx=this._bsearch(_10); |
||
158 | if(idx>-1){ |
||
159 | delete sl[_10];
|
||
160 | delete ss[_f];
|
||
161 | s.splice(idx,1);
|
||
162 | } |
||
163 | },getFirstSelected:function(){ |
||
164 | if(!this.sorted_sel.length||this.mode=="none"){ |
||
165 | return -1; |
||
166 | } |
||
167 | var _11=this.sorted_sel[0]; |
||
168 | if(!_11){
|
||
169 | return -1; |
||
170 | } |
||
171 | _11=this.sorted_ltos[_11];
|
||
172 | if(!_11){
|
||
173 | return -1; |
||
174 | } |
||
175 | return _11;
|
||
176 | },getNextSelected:function(_12){ |
||
177 | if(!this.sorted_sel.length||this.mode=="none"){ |
||
178 | return -1; |
||
179 | } |
||
180 | _12=String(_12); |
||
181 | var _13=this.sorted_stol[_12]; |
||
182 | if(!_13){
|
||
183 | return -1; |
||
184 | } |
||
185 | var idx=this._bsearch(_13); |
||
186 | var _14=this.sorted_sel[idx+1]; |
||
187 | if(!_14){
|
||
188 | return -1; |
||
189 | } |
||
190 | return this.sorted_ltos[_14]; |
||
191 | },_range:function(_15,_16,_17){ |
||
192 | if(!dojo.isString(_15)&&_15<0){ |
||
193 | _15=_16; |
||
194 | } |
||
195 | var _18=this.grid.layout.cells,_19=this.grid.store,_1a=this.grid; |
||
196 | _15=new dojox.grid.TreePath(String(_15),_1a);
|
||
197 | _16=new dojox.grid.TreePath(String(_16),_1a);
|
||
198 | if(_15.compare(_16)>0){ |
||
199 | var tmp=_15;
|
||
200 | _15=_16; |
||
201 | _16=tmp; |
||
202 | } |
||
203 | var _1b=_15._str,_1c=_16._str;
|
||
204 | _17(_1b); |
||
205 | var p=_15;
|
||
206 | while((p=p.next())){
|
||
207 | if(p._str==_1c){
|
||
208 | break;
|
||
209 | } |
||
210 | _17(p._str); |
||
211 | } |
||
212 | _17(_1c); |
||
213 | }}); |
||
214 | } |