Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / grid / enhanced / _Events.js

History | View | Annotate | Download (11 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._Events"]){
9
dojo._hasResource["dojox.grid.enhanced._Events"]=true;
10
dojo.provide("dojox.grid.enhanced._Events");
11
dojo.declare("dojox.grid.enhanced._Events",null,{_events:null,headerCellActiveClass:"dojoxGridHeaderActive",cellActiveClass:"dojoxGridCellActive",rowActiveClass:"dojoxGridRowActive",selectRegionHoverClass:"dojoxGridSelectRegionHover",constructor:function(_1){
12
this._events=new dojox.grid._Events();
13
for(p in this._events){
14
if(!this[p]){
15
this.p=this._events.p;
16
}
17
}
18
_1.mixin(_1,this);
19
},onStyleRow:function(_2){
20
var i=_2;
21
i.customClasses+=(i.odd?" dojoxGridRowOdd":"")+(i.selected?" dojoxGridRowSelected":"")+(i.over?" dojoxGridRowOver":"");
22
this.focus.styleRow(_2);
23
this.edit.styleRow(_2);
24
},dokeyup:function(e){
25
this.indirectSelection&&!this.pluginMgr.inSingleSelection()&&this.indirectSelector.dokeyup(e);
26
},onKeyDown:function(e){
27
if(e.altKey||e.metaKey){
28
return;
29
}
30
if(e.ctrlKey&&!e.shiftKey){
31
dojo.publish("CTRL_KEY_DOWN",[this,e]);
32
}
33
var _3=false;
34
if(this.isDndSelectEnable&&!e.ctrlKey){
35
this.select.keepState=false;
36
}
37
if(this.isDndSelectEnable&&!e.shiftKey){
38
this.select.extendSelect=false;
39
}
40
var dk=dojo.keys;
41
switch(e.keyCode){
42
case dk.ENTER:
43
_3=true;
44
if(!this.edit.isEditing()){
45
var _4=this.focus.getHeaderIndex();
46
if(_4>=0){
47
this.nestedSorting&&this.focus.focusView.header.decorateEvent(e);
48
var _5=e.cell&&this.pluginMgr.isFixedCell(e.cell);
49
!e.selectChoice&&!_5&&this.setSortIndex(_4,null,e);
50
break;
51
}else{
52
!this.indirectSelection&&this.selection.clickSelect(this.focus.rowIndex,dojo.isCopyKey(e),e.shiftKey);
53
}
54
dojo.stopEvent(e);
55
}
56
if(!e.shiftKey){
57
var _6=this.edit.isEditing();
58
this.edit.apply();
59
if(!_6&&!this.pluginMgr.isFixedCell(this.focus.cell)){
60
this.edit.setEditCell(this.focus.cell,this.focus.rowIndex);
61
}
62
}
63
if(!this.edit.isEditing()){
64
var _7=this.focus.focusView||this.views.views[0];
65
_7.content.decorateEvent(e);
66
this.onRowClick(e);
67
}
68
break;
69
case dk.SPACE:
70
_3=true;
71
if(!this.edit.isEditing()){
72
var _4=this.focus.getHeaderIndex();
73
if(_4>=0){
74
this.focus.focusView.header.decorateEvent(e);
75
if(this.indirectSelection&&e.cell&&e.cell.isRowSelector){
76
return;
77
}
78
if(this.isDndSelectEnable&&(!this.nestedSorting&&!this.canSort()||this.nestedSorting&&e.selectChoice)){
79
this.inDNDKeySelectingColumnMode=true;
80
this.select.keepState=e.ctrlKey;
81
this.select.extendSelect=e.shiftKey;
82
if(!this.select.extendSelect){
83
this.select.drugSelectionStart.colIndex=_4;
84
}
85
this.select.drugSelectColumn(_4);
86
}else{
87
var _5=e.cell&&this.pluginMgr.isFixedCell(e.cell);
88
!_5&&e.rowIndex==-1&&e.cell&&this.setSortIndex(_4,null,e);
89
}
90
break;
91
}else{
92
if(this.isDndSelectEnable&&this.focus.isRowBar()){
93
this.inDNDKeySelectingRowMode=true;
94
this.select.keepState=e.ctrlKey;
95
this.select.extendSelect=e.shiftKey;
96
if(!this.select.extendSelect||this.pluginMgr.inSingleSelection()){
97
this.select.drugSelectionStart.rowIndex=this.focus.getFocusedRowIndex();
98
}
99
this.select.drugSelectRow(this.focus.getFocusedRowIndex());
100
}else{
101
!this.indirectSelection&&this.selection.clickSelect(this.focus.rowIndex,dojo.isCopyKey(e),e.shiftKey);
102
}
103
}
104
dojo.stopEvent(e);
105
}
106
break;
107
case dk.LEFT_ARROW:
108
case dk.RIGHT_ARROW:
109
_3=true;
110
this.nestedSorting&&this.focus.focusView.header.decorateEvent(e);
111
var _8=this.isDndSelectEnable&&e.shiftKey;
112
var _5=e.cell&&this.pluginMgr.isFixedCell(e.cell);
113
if(this.nestedSorting&&this.focus.isNavHeader()&&!_8&&!_5){
114
this.focus.navHeader(e);
115
return;
116
}
117
if(!this.edit.isEditing()){
118
var _9=e.keyCode;
119
dojo.stopEvent(e);
120
var _a=this.focus.getHeaderIndex();
121
if(_a>=0&&(e.shiftKey&&e.ctrlKey)){
122
this.focus.colSizeAdjust(e,_a,(_9==dk.LEFT_ARROW?-1:1)*5);
123
return;
124
}
125
var _b=(_9==dk.LEFT_ARROW)?1:-1;
126
if(dojo._isBodyLtr()){
127
_b*=-1;
128
}
129
if(this.nestedSorting&&this.focus.isNavHeader()&&(_8||_5)){
130
this.focus.navHeaderNode(_b,true);
131
}else{
132
if(!(this.isDndSelectEnable&&this.focus.isRowBar())){
133
this.focus.move(0,_b);
134
}
135
}
136
if(_8){
137
var _4=this.focus.getHeaderIndex();
138
if(!this.select.isColSelected(_a)){
139
this.inDNDKeySelectingColumnMode=true;
140
this.select.drugSelectionStart.colIndex=_a;
141
}else{
142
if(this.select.drugSelectionStart.colIndex==-1){
143
this.select.restorLastDragPoint();
144
}
145
}
146
if(e.ctrlKey){
147
this.select.drugSelectColumnToMax(e.keyCode==dk.LEFT_ARROW?"left":"right");
148
}else{
149
this.select.drugSelectColumn(_4);
150
}
151
}
152
}
153
break;
154
case dk.UP_ARROW:
155
case dk.DOWN_ARROW:
156
_3=true;
157
if(this.nestedSorting&&this.focus.isNavHeader()){
158
return;
159
}
160
var _c=e.keyCode==dk.UP_ARROW?-1:1;
161
if(this.isDndSelectEnable){
162
var _d=this.focus.getFocusedRowIndex();
163
}
164
if(this.isDndSelectEnable&&this.focus.isRowBar()){
165
this.focus[e.keyCode==dk.UP_ARROW?"focusPrevRowBar":"focusNextRowBar"]();
166
dojo.stopEvent(e);
167
}else{
168
if(!this.edit.isEditing()&&this.store&&0<=(this.focus.rowIndex+_c)&&(this.focus.rowIndex+_c)<this.rowCount){
169
dojo.stopEvent(e);
170
this.focus.move(_c,0);
171
this.indirectSelection&&this.focus.cell&&this.focus.cell.focus(this.focus.rowIndex);
172
!this.indirectSelection&&this.selection.clickSelect(this.focus.rowIndex,dojo.isCopyKey(e),e.shiftKey);
173
}
174
}
175
if(this.isDndSelectEnable&&this.focus.isRowBar()&&e.shiftKey&&!this.pluginMgr.inSingleSelection()){
176
if(!this.select.isRowSelected(_d)){
177
this.inDNDKeySelectingRowMode=true;
178
this.select.drugSelectionStart.rowIndex=_d;
179
}else{
180
if(this.select.drugSelectionStart.rowIndex==-1){
181
this.select.restorLastDragPoint();
182
}
183
}
184
if(e.ctrlKey){
185
this.select.drugSelectRowToMax(e.keyCode==dk.UP_ARROW?"up":"down");
186
}else{
187
var _e=this.focus.getFocusedRowIndex();
188
this.select.drugSelectRow(_e);
189
}
190
}else{
191
if(this.indirectSelection&&e.shiftKey&&!this.pluginMgr.inSingleSelection()&&this.focus.rowIndex>=0){
192
this.focus.focusView.content.decorateEvent(e);
193
if(e.cellIndex!=0||e.rowIndex==0&&_c==-1){
194
return;
195
}
196
this.indirectSelector.swipeSelectionByKey(e,_c);
197
}
198
}
199
break;
200
case dk.ESCAPE:
201
try{
202
this.select.cancelDND();
203
}
204
catch(e){
205
}
206
break;
207
}
208
!_3&&(dojo.hitch(this,this._events.onKeyDown)(e));
209
},onMouseDown:function(e){
210
dojo.hitch(this,this._events.onMouseDown)(e);
211
if(this.isDndSelectEnable&&!e.shiftKey){
212
this.select.setDrugStartPoint(e.cellIndex,e.rowIndex);
213
}
214
},onMouseUp:function(e){
215
e.rowIndex==-1?this.onHeaderCellMouseUp(e):this.onCellMouseUp(e);
216
},onMouseOutRow:function(e){
217
if(this.isDndSelectEnable){
218
return;
219
}
220
dojo.hitch(this,this._events.onMouseOutRow)(e);
221
},onMouseDownRow:function(e){
222
if(this.isDndSelectEnable){
223
return;
224
}
225
dojo.hitch(this,this._events.onMouseDownRow)(e);
226
},onCellMouseOver:function(e){
227
dojo.hitch(this,this._events.onCellMouseOver)(e);
228
var _f=this.pluginMgr.isFixedCell(e.cell)||this.rowSelectCell&&this.rowSelectCell.inIndirectSelectionMode();
229
if(this.isDndSelectEnable&&!_f){
230
if(this.select.isInSelectingMode("col")){
231
this.select.drugSelectColumn(e.cell.index);
232
}else{
233
if(this.select.isInSelectingMode("cell")){
234
this.select.drugSelectCell(e.cellIndex,e.rowIndex);
235
}else{
236
this.select.setDrugCoverDivs(e.cellIndex,e.rowIndex);
237
}
238
}
239
}
240
},onCellMouseOut:function(e){
241
dojo.hitch(this,this._events.onCellMouseOut)(e);
242
this.doubleAffordance&&e.cellNode&&dojo.removeClass(e.cellNode,this.cellActiveClass);
243
},onCellMouseDown:function(e){
244
dojo.addClass(e.cellNode,this.cellActiveClass);
245
dojo.addClass(e.rowNode,this.rowActiveClass);
246
if(this.isDndSelectEnable){
247
this.focus._blurRowBar();
248
if(e.cellIndex>this.select.exceptColumnsTo){
249
this.select.setInSelectingMode("cell",true);
250
}
251
}
252
},onCellMouseUp:function(e){
253
dojo.removeClass(e.cellNode,this.cellActiveClass);
254
dojo.removeClass(e.rowNode,this.rowActiveClass);
255
},onCellClick:function(e){
256
if(this.isDndSelectEnable){
257
this.focus._blurRowBar();
258
this._click[0]=this._click[1];
259
this._click[1]=e;
260
this.select.cellClick(e.cellIndex,e.rowIndex);
261
!this.edit.isEditCell(e.rowIndex,e.cellIndex)&&!this.edit.isEditing()&&this.select.cleanAll();
262
this.focus.setFocusCell(e.cell,e.rowIndex);
263
}else{
264
dojo.hitch(this,this._events.onCellClick)(e);
265
}
266
},onCellDblClick:function(e){
267
if(this.pluginMgr.isFixedCell(e.cell)){
268
return;
269
}
270
this._click.length>1&&(!this._click[0]||!this._click[1])&&(this._click[0]=this._click[1]=e);
271
dojo.hitch(this,this._events.onCellDblClick)(e);
272
},onRowClick:function(e){
273
this.edit.rowClick(e);
274
!this.indirectSelection&&this.selection.clickSelectEvent(e);
275
},onRowMouseOver:function(e){
276
if(this.isDndSelectEnable&&!this.pluginMgr.inSingleSelection()){
277
if(this.select.isInSelectingMode("row")){
278
this.select.drugSelectRow(e.rowIndex);
279
}else{
280
}
281
}
282
if(!e.cell&&e.cellIndex<0||e.cell&&(e.cell!=this.rowSelectCell)&&this.indirectSelection){
283
var _10=this.rowSelectCell;
284
_10&&_10.onRowMouseOver&&_10.onRowMouseOver(e);
285
}
286
},onRowMouseOut:function(e){
287
if(this.isDndSelectEnable){
288
if(this.select.isInSelectingMode("row")){
289
this.select.drugSelectRow(e.rowIndex);
290
}
291
}
292
},onRowContextMenu:function(e){
293
!this.edit.isEditing()&&this.menus&&this.showRowCellMenu(e);
294
},onSelectedRegionContextMenu:function(e){
295
if(this.selectedRegionMenu){
296
this.selectedRegionMenu._openMyself({target:e.target,coords:"pageX" in e?{x:e.pageX,y:e.pageY}:null});
297
dojo.stopEvent(e);
298
}
299
},onHeaderCellMouseOver:function(e){
300
if(e.cellNode){
301
dojo.addClass(e.cellNode,this.cellOverClass);
302
if(this.nestedSorting&&!this._inResize(e.sourceView)&&!this.pluginMgr.isFixedCell(e.cell)&&!(this.isDndSelectEnable&&this.select.isInSelectingMode("col"))){
303
this.addHoverSortTip(e);
304
}
305
if(this.isDndSelectEnable){
306
if(this.select.isInSelectingMode("col")){
307
this.select.drugSelectColumn(e.cell.index);
308
}else{
309
this.select.clearDrugDivs();
310
}
311
}
312
}
313
},onHeaderCellMouseOut:function(e){
314
if(e.cellNode){
315
dojo.removeClass(e.cellNode,this.cellOverClass);
316
dojo.removeClass(e.cellNode,this.headerCellActiveClass);
317
if(this.nestedSorting&&!this.pluginMgr.isFixedCell(e.cell)){
318
if(this.focus.headerCellInFocus(e.cellIndex)){
319
this._toggleHighlight(e.sourceView,e,true);
320
}else{
321
this.removeHoverSortTip(e);
322
}
323
}
324
}
325
},onHeaderCellMouseDown:function(e){
326
var _11=!this.nestedSorting?e.cellNode:this._getChoiceRegion(e.cellNode,e);
327
_11&&dojo.addClass(_11,this.headerCellActiveClass);
328
if(this.nestedSorting&&!e.selectChoice){
329
return;
330
}
331
if(this.isDndSelectEnable){
332
this.focus._blurRowBar();
333
try{
334
this.focus.focusHeaderNode(e.cellIndex,false,true);
335
}
336
catch(e){
337
}
338
if(e.button==2){
339
return;
340
}
341
if(e.cellNode){
342
this.select.setInSelectingMode("col",true);
343
this.select.keepState=e.ctrlKey;
344
this.select.extendSelect=e.shiftKey;
345
if(this.select.extendSelect){
346
this.select.restorLastDragPoint();
347
}else{
348
this.select.drugSelectionStart.colIndex=e.cellIndex;
349
}
350
this.select.drugSelectColumn(e.cellIndex);
351
}
352
}
353
},onHeaderCellMouseUp:function(e){
354
var _12=!this.nestedSorting?e.cellNode:this._getChoiceRegion(e.cellNode,e);
355
if(_12){
356
dojo.removeClass(_12,this.headerCellActiveClass);
357
e.selectChoice&&dojo.addClass(_12,this.selectRegionHoverClass);
358
}
359
},onHeaderCellClick:function(e){
360
if(this.nestedSorting){
361
if((e.unarySortChoice||e.nestedSortChoice)&&!this._inResize(e.sourceView)){
362
this.setSortIndex(e.cell.index,null,e);
363
}
364
}else{
365
if(!(this.indirectSelection&&e.cell&&e.cell.isRowSelector)){
366
this.setSortIndex(e.cell.index);
367
}
368
}
369
dojo.hitch(this,this._events.onHeaderClick)(e);
370
},onHeaderContextMenu:function(e){
371
if(this.nestedSorting&&this.headerMenu){
372
this._toggleHighlight(e.sourceView,e,true);
373
}
374
dojo.hitch(this,this._events.onHeaderContextMenu)(e);
375
}});
376
}