Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / grid / enhanced / plugins / IndirectSelection.js

History | View | Annotate | Download (10.1 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.enhanced.plugins.IndirectSelection"]){
9
dojo._hasResource["dojox.grid.enhanced.plugins.IndirectSelection"]=true;
10
dojo.provide("dojox.grid.enhanced.plugins.IndirectSelection");
11
dojo.require("dojox.grid.cells.dijit");
12
dojo.require("dojox.grid.cells._base");
13
dojo.declare("dojox.grid.enhanced.plugins.IndirectSelection",null,{constructor:function(_1){
14
this.grid=_1;
15
dojo.connect(_1.layout,"setStructure",dojo.hitch(_1.layout,this.addRowSelectCell));
16
},addRowSelectCell:function(){
17
if(!this.grid.indirectSelection||this.grid.selectionMode=="none"){
18
return;
19
}
20
var _2=false,_3=["get","formatter","field","fields"],_4={type:dojox.grid.cells.DijitMultipleRowSelector,name:"",editable:true,width:"30px",styles:"text-align: center;"};
21
dojo.forEach(this.structure,dojo.hitch(this,function(_5){
22
var _6=_5.cells;
23
if(_6&&_6.length>0&&!_2){
24
var _7=_6[0];
25
if(_7[0]&&_7[0]["isRowSelector"]){
26
_2=true;
27
return;
28
}
29
var _8,_9=this.grid.selectionMode=="single"?dojox.grid.cells.DijitSingleRowSelector:dojox.grid.cells.DijitMultipleRowSelector;
30
if(!dojo.isObject(this.grid.indirectSelection)){
31
_8=dojo.mixin(_4,{type:_9});
32
}else{
33
_8=dojo.mixin(_4,this.grid.indirectSelection,{type:_9,editable:true});
34
dojo.forEach(_3,function(_a){
35
if(_a in _8){
36
delete _8[_a];
37
}
38
});
39
}
40
_6.length>1&&(_8["rowSpan"]=_6.length);
41
dojo.forEach(this.cells,function(_b,i){
42
if(_b.index>=0){
43
_b.index+=1;
44
}else{
45
}
46
});
47
var _c=this.addCellDef(0,0,_8);
48
_c.index=0;
49
_7.unshift(_c);
50
this.cells.unshift(_c);
51
this.grid.rowSelectCell=_c;
52
_2=true;
53
}
54
}));
55
this.cellCount=this.cells.length;
56
}});
57
dojo.declare("dojox.grid.cells._SingleRowSelectorMixin",null,{alwaysEditing:true,widgetMap:{},widget:null,isRowSelector:true,defaultValue:false,formatEditing:function(_d,_e){
58
this.needFormatNode(_d,_e);
59
},_formatNode:function(_f,_10){
60
this.formatNode(_f,_10);
61
},setValue:function(_11,_12){
62
return;
63
},get:function(_13){
64
var _14=this.widgetMap[this.view.id]?this.widgetMap[this.view.id][_13]:null;
65
var _15=_14?_14.attr("checked"):"";
66
return _15;
67
},_fireSelectionChanged:function(){
68
dojo.publish(this.grid.rowSelectionChangedTopic,[this]);
69
},_selectionChanged:function(obj){
70
if(obj==this||obj.grid&&obj.grid!=this.grid){
71
return;
72
}
73
for(var i in this.widgetMap[this.view.id]){
74
var idx=new Number(i);
75
var _16=this.widgetMap[this.view.id][idx];
76
var _17=!!this.grid.selection.selected[idx];
77
_16.attr("checked",_17);
78
}
79
this.defaultValue=false;
80
this.grid.edit.isEditing()&&this.grid.edit.apply();
81
},_toggleSingleRow:function(idx,_18){
82
var _19;
83
dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype[_18?"addToSelection":"deselect"])(idx);
84
if(this.widgetMap[this.view.id]&&(_19=this.widgetMap[this.view.id][idx])){
85
_19.attr("checked",_18);
86
}
87
this._fireSelectionChanged();
88
},inIndirectSelectionMode:function(){
89
},toggleAllSelection:function(){
90
}});
91
dojo.declare("dojox.grid.cells._MultipleRowSelectorMixin",null,{swipeStartRowIndex:-1,swipeMinRowIndex:-1,swipeMaxRowIndex:-1,toSelect:false,lastClickRowIdx:-1,toggleAllTrigerred:false,_inDndSelection:false,domousedown:function(e){
92
if(e.target.tagName=="INPUT"){
93
this._startSelection(e.rowIndex);
94
}
95
dojo.stopEvent(e);
96
},domousemove:function(e){
97
this._updateSelection(e,0);
98
},onRowMouseOver:function(e){
99
this._updateSelection(e,0);
100
if(this.grid.dnd){
101
this._inDndSelection=this.grid.select.isInSelectingMode("row");
102
}
103
},domouseup:function(e){
104
dojo.isIE&&this.view.content.decorateEvent(e);
105
var _1a=e.cellIndex>=0&&(this.inIndirectSelectionMode()||this._inDndSelection)&&!this.grid.edit.isEditRow(e.rowIndex);
106
_1a&&this._focusEndingCell(e.rowIndex,e.cellIndex);
107
this._finisheSelect();
108
},dokeyup:function(e){
109
if(!e.shiftKey){
110
this._finisheSelect();
111
}
112
},_startSelection:function(_1b){
113
this.swipeStartRowIndex=this.swipeMinRowIndex=this.swipeMaxRowIndex=_1b;
114
this.toSelect=!this.widgetMap[this.view.id][_1b].attr("checked");
115
},_updateSelection:function(e,_1c){
116
if(this.swipeStartRowIndex<0){
117
return;
118
}
119
var _1d=_1c!=0;
120
var _1e=e.rowIndex-this.swipeStartRowIndex+_1c;
121
_1e>0&&(this.swipeMaxRowIndex<e.rowIndex+_1c)&&(this.swipeMaxRowIndex=e.rowIndex+_1c);
122
_1e<0&&(this.swipeMinRowIndex>e.rowIndex+_1c)&&(this.swipeMinRowIndex=e.rowIndex+_1c);
123
if(this.swipeMinRowIndex!=this.swipeMaxRowIndex){
124
for(var i in this.widgetMap[this.view.id]){
125
var idx=new Number(i);
126
var _1f=(idx>=(_1e>0?this.swipeStartRowIndex:e.rowIndex+_1c)&&idx<=(_1e>0?e.rowIndex+_1c:this.swipeStartRowIndex));
127
var _20=(idx>=this.swipeMinRowIndex&&idx<=this.swipeMaxRowIndex);
128
if(_1f&&!(_1e==0&&!this.toSelect)){
129
(this.widgetMap[this.view.id][idx]).attr("checked",this.toSelect);
130
dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype[this.toSelect?"addToSelection":"deselect"])(idx);
131
}else{
132
if(_20&&!_1d){
133
(this.widgetMap[this.view.id][idx]).attr("checked",!this.toSelect);
134
dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype[!this.toSelect?"addToSelection":"deselect"])(idx);
135
}
136
}
137
}
138
}
139
this._fireSelectionChanged();
140
},swipeSelectionByKey:function(e,_21){
141
if(this.swipeStartRowIndex<0){
142
this.swipeStartRowIndex=e.rowIndex;
143
if(_21>0){
144
this.swipeMaxRowIndex=e.rowIndex+_21;
145
this.swipeMinRowIndex=e.rowIndex;
146
}else{
147
this.swipeMinRowIndex=e.rowIndex+_21;
148
this.swipeMaxRowIndex=e.rowIndex;
149
}
150
this.toSelect=this.widgetMap[this.view.id][e.rowIndex].attr("checked");
151
}
152
this._updateSelection(e,_21);
153
},_finisheSelect:function(){
154
this.swipeStartRowIndex=-1;
155
this.swipeMinRowIndex=-1;
156
this.swipeMaxRowIndex=-1;
157
this.toSelect=false;
158
},inIndirectSelectionMode:function(){
159
return this.swipeStartRowIndex>=0;
160
},toggleAllSelection:function(_22){
161
for(var i in this.widgetMap[this.view.id]){
162
var idx=new Number(i);
163
var _23=this.widgetMap[this.view.id][idx];
164
_23.attr("checked",_22);
165
dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype[_22?"addToSelection":"deselect"])(idx);
166
}
167
!_22&&this.grid.selection.deselectAll();
168
this.defaultValue=_22;
169
this.toggleAllTrigerred=true;
170
this._fireSelectionChanged();
171
}});
172
dojo.declare("dojox.grid.cells.DijitSingleRowSelector",[dojox.grid.cells._Widget,dojox.grid.cells._SingleRowSelectorMixin],{widgetClass:dijit.form.RadioButton,constructor:function(){
173
dojo.subscribe(this.grid.rowSelectionChangedTopic,this,this._selectionChanged);
174
dojo.subscribe(this.grid.sortRowSelectionChangedTopic,this,this._selectionChanged);
175
this.grid.indirectSelector=this;
176
},formatNode:function(_24,_25){
177
if(!this.widgetClass){
178
return _24;
179
}
180
!this.widgetMap[this.view.id]&&(this.widgetMap[this.view.id]={});
181
var _26=this.widgetMap[this.view.id][_25];
182
var _27=this.getNode(_25);
183
if(!_27){
184
return;
185
}
186
var _28=!_27.firstChild||(_26&&_26.domNode!=_27.firstChild);
187
var _29=_28&&!_27.firstChild?_27.appendChild(dojo.create("div")):_27.firstChild;
188
if(!_26||dojo.isIE){
189
!this.widgetProps&&(this.widgetProps={});
190
this.widgetProps.name="select_"+this.view.id;
191
var _2a=this.getDefaultValue(_26,_25);
192
this.widget=_26=this.createWidget(_29,_24,_25);
193
this.widgetMap[this.view.id][_25]=_26;
194
this.widget.attr("checked",_2a);
195
dojo.connect(_26,"_onClick",dojo.hitch(this,function(e){
196
this._selectRow(e,_25);
197
}));
198
dojo.connect(_26.domNode,"onkeyup",dojo.hitch(this,function(e){
199
e.keyCode==dojo.keys.SPACE&&this._selectRow(e,_25,true);
200
}));
201
dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype[_2a?"addToSelection":"deselect"])(_25);
202
}else{
203
this.widget=_26;
204
dojo.addClass(this.widget.domNode,"dojoxGridWidgetHidden");
205
_28&&this.attachWidget(_29,_24,_25);
206
}
207
this.grid.rowHeightChanged(_25);
208
dojo.removeClass(this.widget.domNode,"dojoxGridWidgetHidden");
209
(_25==this.grid.lastRenderingRowIdx)&&dojo.removeClass(this.grid.domNode,"dojoxGridSortInProgress");
210
},getDefaultValue:function(_2b,_2c){
211
var _2d=_2b?_2b.attr("checked"):this.defaultValue;
212
if(!_2b){
213
if(this.grid.nestedSorting){
214
_2d=_2d||this.grid.getStoreSelectedValue(_2c);
215
}
216
_2d=this.grid.selection.isSelected(_2c)?true:_2d;
217
}
218
return _2d;
219
},focus:function(_2e){
220
var _2f=this.widgetMap[this.view.id][_2e];
221
if(_2f){
222
setTimeout(dojo.hitch(_2f,function(){
223
dojox.grid.util.fire(this,"focus");
224
}),0);
225
}
226
},_focusEndingCell:function(_30,_31){
227
var _32=this.grid.getCell(_31);
228
this.grid.focus.setFocusCell(_32,_30);
229
this.grid.isDndSelectEnable&&this.grid.focus._blurRowBar();
230
},_selectRow:function(e,_33,_34){
231
if(dojo.isMoz&&_34){
232
return;
233
}
234
dojo.stopEvent(e);
235
this._focusEndingCell(_33,0);
236
var _35=!this.grid.selection.selected[_33];
237
this.grid.selection.deselectAll();
238
this.grid.selection.addToSelection(_33);
239
if(!dojo.isMoz){
240
var _36=this.widgetMap[this.view.id][_33];
241
_36.attr("checked",true);
242
}
243
this._fireSelectionChanged();
244
},toggleRow:function(idx,_37){
245
var _38=dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype.getFirstSelected)();
246
if(idx!=_38&&!_37||idx==_38&&_37){
247
return;
248
}
249
var _39;
250
if(idx!=_38&&_37&&this.widgetMap[this.view.id]&&(_39=this.widgetMap[this.view.id][_38])){
251
_39.attr("checked",false);
252
}
253
this.grid.selection.deselectAll();
254
this._toggleSingleRow(idx,_37);
255
},setDisabled:function(idx,_3a){
256
if(this.widgetMap[this.view.id]){
257
var _3b=this.widgetMap[this.view.id][idx];
258
_3b&&_3b.attr("disabled",_3a);
259
}
260
}});
261
dojo.declare("dojox.grid.cells.DijitMultipleRowSelector",[dojox.grid.cells.DijitSingleRowSelector,dojox.grid.cells._MultipleRowSelectorMixin],{widgetClass:dijit.form.CheckBox,constructor:function(){
262
dojo.connect(dojo.doc,"onmouseup",this,"domouseup");
263
this.grid.indirectSelector=this;
264
},_selectRow:function(e,_3c,_3d){
265
dojo.stopEvent(e);
266
this._focusEndingCell(_3c,0);
267
var _3e=_3c-this.lastClickRowIdx;
268
if(this.lastClickRowIdx>=0&&!e.ctrlKey&&!e.altKey&&e.shiftKey){
269
var _3f=this.widgetMap[this.view.id][_3c].attr("checked");
270
_3f=_3d?!_3f:_3f;
271
for(var i in this.widgetMap[this.view.id]){
272
var idx=new Number(i);
273
var _40=(idx>=(_3e>0?this.lastClickRowIdx:_3c)&&idx<=(_3e>0?_3c:this.lastClickRowIdx));
274
if(_40){
275
var _41=this.widgetMap[this.view.id][idx];
276
_41.attr("checked",_3f);
277
dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype[_3f?"addToSelection":"deselect"])(idx);
278
}
279
}
280
}else{
281
var _42=!this.grid.selection.selected[_3c];
282
var _41=this.widgetMap[this.view.id][_3c];
283
_41.attr("checked",_42);
284
dojo.hitch(this.grid.selection,dojox.grid.Selection.prototype[_42?"addToSelection":"deselect"])(_3c);
285
}
286
this.lastClickRowIdx=_3c;
287
this._fireSelectionChanged();
288
},toggleRow:function(idx,_43){
289
this._toggleSingleRow(idx,_43);
290
}});
291
}