Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / grid / enhanced / dnd / _DndSelectingManager.js

History | View | Annotate | Download (10.7 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.grid.enhanced.dnd._DndSelectingManager"]){
9
dojo._hasResource["dojox.grid.enhanced.dnd._DndSelectingManager"]=true;
10
dojo.provide("dojox.grid.enhanced.dnd._DndSelectingManager");
11
dojo.require("dojox.grid.util");
12
dojo.require("dojox.grid._Builder");
13
dojo.require("dojox.grid.enhanced.dnd._DndGrid");
14
dojo.require("dojox.grid.enhanced.dnd._DndBuilder");
15
dojo.require("dojox.grid.enhanced.dnd._DndRowSelector");
16
dojo.require("dojox.grid.enhanced.dnd._DndFocusManager");
17
dojo.declare("dojox.grid.enhanced.dnd._DndSelectingManager",null,{typeSelectingMode:[],selectingDisabledTypes:[],drugSelectionStart:null,drugCurrentPoint:null,drugMode:null,keepState:false,extendSelect:false,headerNodes:null,selectedCells:null,selectedColumns:[],selectedClass:"dojoxGridRowSelected",autoScrollRate:1000,constructor:function(_1){
18
this.grid=_1;
19
this.typeSelectingMode=[];
20
this.selectingDisabledTypes=[];
21
this.selectedColumns=[];
22
this.drugSelectionStart=new Object();
23
this.drugCurrentPoint=new Object();
24
this.resetStartPoint();
25
this.extendGridForDnd(_1);
26
this.selectedCells=[];
27
dojo.connect(this.grid,"_onFetchComplete",dojo.hitch(this,"refreshColumnSelection"));
28
dojo.connect(this.grid.scroller,"scroll",dojo.hitch(this,"refreshColumnSelection"));
29
dojo.subscribe(this.grid.rowSelectionChangedTopic,dojo.hitch(this,function(_2){
30
try{
31
if(_2.grid==this.grid&&_2!=this){
32
this.cleanCellSelection();
33
}
34
}
35
catch(e){
36
}
37
}));
38
},extendGridForDnd:function(_3){
39
var _4=_3.constructor;
40
_3.mixin(_3,dojo.hitch(new dojox.grid.enhanced.dnd._DndGrid(this)));
41
_3.constructor=_4;
42
_3.mixin(_3.focus,new dojox.grid.enhanced.dnd._DndFocusManager());
43
_3.mixin(_3.selection,{clickSelect:function(){
44
}});
45
dojo.forEach(_3.views.views,function(_5){
46
_3.mixin(_5.content,new dojox.grid.enhanced.dnd._DndBuilder());
47
_3.mixin(_5.header,new dojox.grid.enhanced.dnd._DndHeaderBuilder());
48
if(_5.declaredClass=="dojox.grid._RowSelector"){
49
_3.mixin(_5,new dojox.grid.enhanced.dnd._DndRowSelector());
50
}
51
dojox.grid.util.funnelEvents(_5.contentNode,_5,"doContentEvent",["mouseup"]);
52
dojox.grid.util.funnelEvents(_5.headerNode,_5,"doHeaderEvent",["mouseup"]);
53
});
54
dojo.forEach(this.grid.dndDisabledTypes,function(_6){
55
this.disableSelecting(_6);
56
},this);
57
this.disableFeatures();
58
},disableFeatures:function(){
59
if(this.selectingDisabledTypes["cell"]){
60
this.cellClick=function(){
61
};
62
this.drugSelectCell=function(){
63
};
64
}
65
if(this.selectingDisabledTypes["row"]){
66
this.drugSelectRow=function(){
67
};
68
}
69
if(this.selectingDisabledTypes["col"]){
70
this.selectColumn=function(){
71
};
72
this.drugSelectColumn=function(){
73
};
74
}
75
},disableSelecting:function(_7){
76
this.selectingDisabledTypes[_7]=true;
77
},isInSelectingMode:function(_8){
78
return !!this.typeSelectingMode[_8];
79
},setInSelectingMode:function(_9,_a){
80
this.typeSelectingMode[_9]=_a;
81
},getSelectedRegionInfo:function(){
82
var _b=[],_c="";
83
if(this.selectedColumns.length>0){
84
_c="col";
85
dojo.forEach(this.selectedColumns,function(_d,_e){
86
!!_d&&_b.push(_e);
87
});
88
}else{
89
if(this.grid.selection.getSelectedCount()>0){
90
_c="row";
91
_b=dojox.grid.Selection.prototype.getSelected.call(this.grid.selection);
92
}
93
}
94
return {"selectionType":_c,"selectedIdx":_b};
95
},clearInSelectingMode:function(){
96
this.typeSelectingMode=[];
97
},getHeaderNodes:function(){
98
return this.headerNodes==null?dojo.query("[role*='columnheader']",this.grid.viewsHeaderNode):this.headerNode;
99
},_range:function(_f,_10,_11){
100
var s=(_f>=0?_f:_10),e=_10;
101
if(s>e){
102
e=s;
103
s=_10;
104
}
105
for(var i=s;i<=e;i++){
106
_11(i);
107
}
108
},cellClick:function(_12,_13){
109
if(_12>this.exceptColumnsTo){
110
this.grid.selection.clear();
111
this.publishRowChange();
112
var _14=this.getCellNode(_12,_13);
113
this.cleanAll();
114
this.addCellToSelection(_14);
115
}
116
},setDrugStartPoint:function(_15,_16){
117
this.drugSelectionStart.colIndex=_15;
118
this.drugSelectionStart.rowIndex=_16;
119
this.drugCurrentPoint.colIndex=_15;
120
this.firstOut=true;
121
var _17=dojo.connect(dojo.doc,"onmousemove",dojo.hitch(this,function(e){
122
this.outRangeValue=e.clientY-dojo.coords(this.grid.domNode).y-this.grid.domNode.offsetHeight;
123
if(this.outRangeValue>0){
124
if(this.drugSelectionStart.colIndex==-1){
125
if(!this.outRangeY){
126
this.autoRowScrollDrug(e);
127
}
128
}else{
129
if(this.drugSelectionStart.rowIndex==-1){
130
}else{
131
this.autoCellScrollDrug(e);
132
}
133
}
134
}else{
135
this.firstOut=true;
136
this.outRangeY=false;
137
}
138
}));
139
var _18=dojo.connect(dojo.doc,"onmouseup",dojo.hitch(this,function(e){
140
this.outRangeY=false;
141
dojo.disconnect(_18);
142
dojo.disconnect(_17);
143
this.grid.onMouseUp(e);
144
}));
145
},autoRowScrollDrug:function(e){
146
this.outRangeY=true;
147
this.autoSelectNextRow();
148
},autoSelectNextRow:function(){
149
if(this.grid.select.outRangeY){
150
this.grid.scrollToRow(this.grid.scroller.firstVisibleRow+1);
151
this.drugSelectRow(this.drugCurrentPoint.rowIndex+1);
152
setTimeout(dojo.hitch(this,"autoSelectNextRow",this.drugCurrentPoint.rowIndex+1),this.getAutoScrollRate());
153
}
154
},autoCellScrollDrug:function(e){
155
var _19=null;
156
dojo.forEach(this.getHeaderNodes(),function(_1a){
157
var _1b=dojo.coords(_1a);
158
if(e.clientX>=_1b.x&&e.clientX<=_1b.x+_1b.w){
159
_19=Number(_1a.attributes.getNamedItem("idx").value);
160
}
161
});
162
if(_19!=this.drugCurrentPoint.colIndex||this.firstOut){
163
if(!this.firstOut){
164
this.colChanged=true;
165
this.drugCurrentPoint.colIndex=_19;
166
}
167
this.firstOut=false;
168
this.outRangeY=true;
169
dojo.hitch(this,"autoSelectCellInNextRow")();
170
}
171
},autoSelectCellInNextRow:function(){
172
if(this.grid.select.outRangeY){
173
this.grid.scrollToRow(this.grid.scroller.firstVisibleRow+1);
174
this.drugSelectCell(this.drugCurrentPoint.colIndex,this.drugCurrentPoint.rowIndex+1);
175
if(this.grid.select.colChanged){
176
this.grid.select.colChanged=false;
177
}else{
178
setTimeout(dojo.hitch(this,"autoSelectCellInNextRow",this.drugCurrentPoint.rowIndex+1),this.getAutoScrollRate());
179
}
180
}
181
},getAutoScrollRate:function(){
182
return this.autoScrollRate;
183
},resetStartPoint:function(){
184
if(this.drugSelectionStart.colIndex==-1&&this.drugSelectionStart.rowIndex==-1){
185
return;
186
}
187
this.lastDrugSelectionStart=dojo.clone(this.drugSelectionStart);
188
this.drugSelectionStart.colIndex=-1;
189
this.drugSelectionStart.rowIndex=-1;
190
},restorLastDragPoint:function(){
191
this.drugSelectionStart=dojo.clone(this.lastDrugSelectionStart);
192
},drugSelectCell:function(_1c,_1d){
193
this.cleanAll();
194
this.drugCurrentPoint.columnIndex=_1c;
195
this.drugCurrentPoint.rowIndex=_1d;
196
var _1e,_1f,_20,_21;
197
if(_1d<this.drugSelectionStart.rowIndex){
198
_1e=_1d;
199
_1f=this.drugSelectionStart.rowIndex;
200
}else{
201
_1e=this.drugSelectionStart.rowIndex;
202
_1f=_1d;
203
}
204
if(_1c<this.drugSelectionStart.colIndex){
205
_20=_1c;
206
_21=this.drugSelectionStart.colIndex;
207
}else{
208
_20=this.drugSelectionStart.colIndex;
209
_21=_1c;
210
}
211
for(var i=_20;i<=_21;i++){
212
this.addColumnRangeToSelection(i,_1e,_1f);
213
}
214
},selectColumn:function(_22){
215
this.addColumnToSelection(_22);
216
},drugSelectColumn:function(_23){
217
this.selectColumnRange(this.drugSelectionStart.colIndex,_23);
218
},drugSelectColumnToMax:function(dir){
219
if(dir=="left"){
220
this.selectColumnRange(this.drugSelectionStart.colIndex,0);
221
}else{
222
this.selectColumnRange(this.drugSelectionStart.colIndex,this.getHeaderNodes().length-1);
223
}
224
},selectColumnRange:function(_24,_25){
225
if(!this.keepState){
226
this.cleanAll();
227
}
228
this._range(_24,_25,dojo.hitch(this,"addColumnToSelection"));
229
},addColumnToSelection:function(_26){
230
this.selectedColumns[_26]=true;
231
dojo.toggleClass(this.getHeaderNodes()[_26],"dojoxGridHeaderSelected",true);
232
this._rangCellsInColumn(_26,-1,Number.POSITIVE_INFINITY,this.addCellToSelection);
233
},addColumnRangeToSelection:function(_27,_28,to){
234
var _29=this.grid.views;
235
var _2a=[];
236
var _2b=this;
237
dojo.forEach(_29.views,function(_2c){
238
dojo.forEach(this.getViewRowNodes(_2c.rowNodes),function(_2d,_2e){
239
if(!_2d){
240
return;
241
}
242
if(_2e>=_28&&_2e<=to){
243
dojo.forEach(_2d.firstChild.rows[0].cells,function(_2f){
244
if(_2f&&_2f.attributes&&(idx=_2f.attributes.getNamedItem("idx"))&&Number(idx.value)==_27){
245
_2b.addCellToSelection(_2f);
246
}
247
});
248
}
249
},this);
250
},this);
251
},_rangCellsInColumn:function(_30,_31,to,_32){
252
var _33=this.grid.views;
253
var _34=[];
254
var _35=this;
255
dojo.forEach(_33.views,function(_36){
256
dojo.forEach(this.getViewRowNodes(_36.rowNodes),function(_37,_38){
257
if(!_37){
258
return;
259
}
260
if(_38>=_31&&_38<=to){
261
dojo.forEach(_37.firstChild.rows[0].cells,function(_39){
262
if(_39&&_39.attributes&&(idx=_39.attributes.getNamedItem("idx"))&&Number(idx.value)==_30){
263
_32(_39,_35);
264
}
265
});
266
}
267
},this);
268
},this);
269
},drugSelectRow:function(_3a){
270
this.drugCurrentPoint.rowIndex=_3a;
271
this.cleanCellSelection();
272
this.clearDrugDivs();
273
var _3b=this.grid.selection;
274
_3b._beginUpdate();
275
if(!this.keepState){
276
_3b.deselectAll();
277
}
278
_3b.selectRange(this.drugSelectionStart.rowIndex,_3a);
279
_3b._endUpdate();
280
this.publishRowChange();
281
},drugSelectRowToMax:function(dir){
282
if(dir=="up"){
283
this.drugSelectRow(0);
284
}else{
285
this.drugSelectRow(this.grid.rowCount);
286
}
287
},getCellNode:function(_3c,_3d){
288
var _3e=[],_3f=null;
289
var _40=this.grid.views;
290
for(var i=0,v,n;(v=_40.views[i])&&(n=v.getRowNode(_3d));i++){
291
_3e.push(n);
292
}
293
dojo.forEach(_3e,dojo.hitch(function(_41,_42){
294
if(_3f){
295
return;
296
}
297
var _43=dojo.query("[idx='"+_3c+"']",_41);
298
if(_43&&_43[0]){
299
_3f=_43[0];
300
}
301
}));
302
return _3f;
303
},addCellToSelection:function(_44,_45){
304
if(!_45){
305
_45=this;
306
}
307
_45.selectedCells[_45.selectedCells.length]=_44;
308
dojo.toggleClass(_44,_45.selectedClass,true);
309
},isColSelected:function(_46){
310
return this.selectedColumns[_46];
311
},isRowSelected:function(_47){
312
return this.grid.selection.selected[_47];
313
},isContinuousSelection:function(_48){
314
var _49=-1;
315
for(var i=0;i<_48.length;i++){
316
if(!_48[i]){
317
continue;
318
}
319
if(_49<0||i-_49==1){
320
_49=i;
321
}else{
322
if(i-_49>=2){
323
return false;
324
}
325
}
326
}
327
return _49>=0?true:false;
328
},cleanCellSelection:function(){
329
dojo.forEach(this.selectedCells,dojo.hitch(this,"removeCellSelectedState"));
330
this.selectedCells=[];
331
dojo.forEach(this.selectedColumns,function(_4a,_4b){
332
if(_4a){
333
dojo.toggleClass(this.getHeaderNodes()[_4b],"dojoxGridHeaderSelected",false);
334
}
335
},this);
336
this.selectedColumns=[];
337
this.grid.edit.isEditing()&&this.grid.edit.apply();
338
},removeCellSelectedState:function(_4c){
339
dojo.toggleClass(_4c,this.selectedClass,false);
340
},cleanAll:function(){
341
this.cleanCellSelection();
342
this.grid.selection.clear();
343
this.publishRowChange();
344
},refreshColumnSelection:function(){
345
dojo.forEach(this.selectedColumns,dojo.hitch(this,function(_4d,_4e){
346
if(_4d){
347
this.grid.select.addColumnToSelection(_4e);
348
}
349
}));
350
},inSelectedArea:function(_4f,_50){
351
return this.selectedColumns[_4f]||this.gird.selection.selecteded[_50];
352
},publishRowChange:function(){
353
dojo.publish(this.grid.rowSelectionChangedTopic,[this]);
354
},getViewRowNodes:function(_51){
355
var _52=[];
356
for(i in _51){
357
_52.push(_51[i]);
358
}
359
return _52;
360
},getFirstSelected:function(){
361
return dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype.getFirstSelected)();
362
},getLastSelected:function(){
363
var _53=this.grid.selection.selected;
364
for(var i=_53.length-1;i>=0;i--){
365
if(_53[i]){
366
return i;
367
}
368
}
369
return -1;
370
}});
371
}