Debian Codegraph @

dojox/grid/_Events.js

raw symbols SCIP
1 define([
2 "dojo/keys",
3 "dojo/dom-class",
4 "dojo/_base/declare",
5 "dojo/_base/event",
6 "dojo/_base/sniff"
7 ], function(keys, domClass, declare, event, has){
8
9 return declare("dojox.grid._Events", null, {
10 // summary:
11 // _Grid mixin that provides default implementations for grid events.
12 // description:
13 // Default synthetic events dispatched for _Grid. dojo.connect to events to
14 // retain default implementation or override them for custom handling.
15
16 // cellOverClass: String
17 // css class to apply to grid cells over which the cursor is placed.
18 cellOverClass: "dojoxGridCellOver",
19
20 onKeyEvent: function(e){
21 // summary:
22 // top level handler for Key Events
23 this.dispatchKeyEvent(e);
24 },
25
26 onContentEvent: function(e){
27 // summary:
28 // Top level handler for Content events
29 this.dispatchContentEvent(e);
30 },
31
32 onHeaderEvent: function(e){
33 // summary:
34 // Top level handler for header events
35 this.dispatchHeaderEvent(e);
36 },
37
38 onStyleRow: function(inRow){
39 // summary:
40 // Perform row styling on a given row. Called whenever row styling is updated.
41 // inRow: Object
42 // Object containing row state information: selected, true if the row is selcted; over:
43 // true of the mouse is over the row; odd: true if the row is odd. Use customClasses and
44 // customStyles to control row css classes and styles; both properties are strings.
45 // example:
46 // | onStyleRow({ selected: true, over:true, odd:false })
47 var i = inRow;
48 i.customClasses += (i.odd?" dojoxGridRowOdd":"") + (i.selected?" dojoxGridRowSelected":"") + (i.over?" dojoxGridRowOver":"");
49 this.focus.styleRow(inRow);
50 this.edit.styleRow(inRow);
51 },
52
53 onKeyDown: function(e){
54 // summary:
55 // Grid key event handler. By default enter begins editing and applies edits, escape cancels an edit,
56 // tab, shift-tab, and arrow keys move grid cell focus.
57 if(e.altKey || e.metaKey){
58 return;
59 }
60 var colIdx;
61 switch(e.keyCode){
62 case keys.ESCAPE:
63 this.edit.cancel();
64 break;
65 case keys.ENTER:
66 if(!this.edit.isEditing()){
67 colIdx = this.focus.getHeaderIndex();
68 if(colIdx >= 0) {
69 this.setSortIndex(colIdx);
70 break;
71 }else {
72 this.selection.clickSelect(this.focus.rowIndex, dojo.isCopyKey(e), e.shiftKey);
73 }
74 event.stop(e);
75 }
76 if(!e.shiftKey){
77 var isEditing = this.edit.isEditing();
78 this.edit.apply();
79 if(!isEditing){
80 this.edit.setEditCell(this.focus.cell, this.focus.rowIndex);
81 }
82 }
83 if (!this.edit.isEditing()){
84 var curView = this.focus.focusView || this.views.views[0]; //if no focusView than only one view
85 curView.content.decorateEvent(e);
86 this.onRowClick(e);
87 event.stop(e);
88 }
89 break;
90 case keys.SPACE:
91 if(!this.edit.isEditing()){
92 colIdx = this.focus.getHeaderIndex();
93 if(colIdx >= 0) {
94 this.setSortIndex(colIdx);
95 break;
96 }else {
97 this.selection.clickSelect(this.focus.rowIndex, dojo.isCopyKey(e), e.shiftKey);
98 // Set focus back on the cell they were on for keyboard accessibility
99 this.focus._focusifyCellNode(true);
100 this.focus.setFocusCell(this.focus.cell, this.focus.rowIndex); }
101 event.stop(e);
102 }
103 break;
104 case keys.TAB:
105 this.focus[e.shiftKey ? 'previousKey' : 'nextKey'](e);
106 break;
107 case keys.LEFT_ARROW:
108 case keys.RIGHT_ARROW:
109 if(!this.edit.isEditing()){
110 var keyCode = e.keyCode; // IE seems to lose after stopEvent when modifier keys
111 event.stop(e);
112 colIdx = this.focus.getHeaderIndex();
113 if (colIdx >= 0 && (e.shiftKey && e.ctrlKey)){
114 this.focus.colSizeAdjust(e, colIdx, (keyCode == keys.LEFT_ARROW ? -1 : 1)*5);
115 }
116 else{
117 var offset = (keyCode == keys.LEFT_ARROW) ? 1 : -1;
118 if(this.isLeftToRight()){ offset *= -1; }
119 this.focus.move(0, offset);
120 }
121 }
122 break;
123 case keys.UP_ARROW:
124 if(!this.edit.isEditing() && this.focus.rowIndex !== 0){
125 event.stop(e);
126 this.focus.move(-1, 0);
127 }
128 break;
129 case keys.DOWN_ARROW:
130 if(!this.edit.isEditing() && this.focus.rowIndex+1 != this.rowCount){
131 event.stop(e);
132 this.focus.move(1, 0);
133 }
134 break;
135 case keys.PAGE_UP:
136 if(!this.edit.isEditing() && this.focus.rowIndex !== 0){
137 event.stop(e);
138 if(this.focus.rowIndex != this.scroller.firstVisibleRow+1){
139 this.focus.move(this.scroller.firstVisibleRow-this.focus.rowIndex, 0);
140 }else{
141 this.setScrollTop(this.scroller.findScrollTop(this.focus.rowIndex-1));
142 this.focus.move(this.scroller.firstVisibleRow-this.scroller.lastVisibleRow+1, 0);
143 }
144 }
145 break;
146 case keys.PAGE_DOWN:
147 if(!this.edit.isEditing() && this.focus.rowIndex+1 != this.rowCount){
148 event.stop(e);
149 if(this.focus.rowIndex != this.scroller.lastVisibleRow-1){
150 this.focus.move(this.scroller.lastVisibleRow-this.focus.rowIndex-1, 0);
151 }else{
152 this.setScrollTop(this.scroller.findScrollTop(this.focus.rowIndex+1));
153 this.focus.move(this.scroller.lastVisibleRow-this.scroller.firstVisibleRow-1, 0);
154 }
155 }
156 break;
157 default:
158 break;
159 }
160 },
161
162 onMouseOver: function(e){
163 // summary:
164 // Event fired when mouse is over the grid.
165 // e: Event
166 // Decorated event object contains reference to grid, cell, and rowIndex
167 e.rowIndex == -1 ? this.onHeaderCellMouseOver(e) : this.onCellMouseOver(e);
168 },
169
170 onMouseOut: function(e){
171 // summary:
172 // Event fired when mouse moves out of the grid.
173 // e: Event
174 // Decorated event object that contains reference to grid, cell, and rowIndex
175 e.rowIndex == -1 ? this.onHeaderCellMouseOut(e) : this.onCellMouseOut(e);
176 },
177
178 onMouseDown: function(e){
179 // summary:
180 // Event fired when mouse is down inside grid.
181 // e: Event
182 // Decorated event object that contains reference to grid, cell, and rowIndex
183 e.rowIndex == -1 ? this.onHeaderCellMouseDown(e) : this.onCellMouseDown(e);
184 },
185
186 onMouseOverRow: function(e){
187 // summary:
188 // Event fired when mouse is over any row (data or header).
189 // e: Event
190 // Decorated event object contains reference to grid, cell, and rowIndex
191 if(!this.rows.isOver(e.rowIndex)){
192 this.rows.setOverRow(e.rowIndex);
193 e.rowIndex == -1 ? this.onHeaderMouseOver(e) : this.onRowMouseOver(e);
194 }
195 },
196 onMouseOutRow: function(e){
197 // summary:
198 // Event fired when mouse moves out of any row (data or header).
199 // e: Event
200 // Decorated event object contains reference to grid, cell, and rowIndex
201 if(this.rows.isOver(-1)){
202 this.onHeaderMouseOut(e);
203 }else if(!this.rows.isOver(-2)){
204 this.rows.setOverRow(-2);
205 this.onRowMouseOut(e);
206 }
207 },
208
209 onMouseDownRow: function(e){
210 // summary:
211 // Event fired when mouse is down inside grid row
212 // e: Event
213 // Decorated event object that contains reference to grid, cell, and rowIndex
214 if(e.rowIndex != -1)
215 this.onRowMouseDown(e);
216 },
217
218 // cell events
219 onCellMouseOver: function(e){
220 // summary:
221 // Event fired when mouse is over a cell.
222 // e: Event
223 // Decorated event object contains reference to grid, cell, and rowIndex
224 if(e.cellNode){
225 domClass.add(e.cellNode, this.cellOverClass);
226 }
227 },
228
229 onCellMouseOut: function(e){
230 // summary:
231 // Event fired when mouse moves out of a cell.
232 // e: Event
233 // Decorated event object which contains reference to grid, cell, and rowIndex
234 if(e.cellNode){
235 domClass.remove(e.cellNode, this.cellOverClass);
236 }
237 },
238
239 onCellMouseDown: function(e){
240 // summary:
241 // Event fired when mouse is down in a header cell.
242 // e: Event
243 // Decorated event object which contains reference to grid, cell, and rowIndex
244 },
245
246 onCellClick: function(e){
247 // summary:
248 // Event fired when a cell is clicked.
249 // e: Event
250 // Decorated event object which contains reference to grid, cell, and rowIndex
251 this._click[0] = this._click[1];
252 this._click[1] = e;
253 if(!this.edit.isEditCell(e.rowIndex, e.cellIndex)){
254 this.focus.setFocusCell(e.cell, e.rowIndex);
255 }
256 // in some cases click[0] is null which causes false doubeClicks. Fixes #100703
257 if(this._click.length > 1 && this._click[0] == null){
258 this._click.shift();
259 }
260 this.onRowClick(e);
261 },
262
263 onCellDblClick: function(e){
264 // summary:
265 // Event fired when a cell is double-clicked.
266 // e: Event
267 // Decorated event object contains reference to grid, cell, and rowIndex
268 var event;
269 if(this._click.length > 1 && has('ie')){
270 event = this._click[1];
271 }else if(this._click.length > 1 && this._click[0].rowIndex != this._click[1].rowIndex){
272 event = this._click[0];
273 }else{
274 event = e;
275 }
276 this.focus.setFocusCell(event.cell, event.rowIndex);
277 this.edit.setEditCell(event.cell, event.rowIndex);
278 this.onRowDblClick(e);
279 },
280
281 onCellContextMenu: function(e){
282 // summary:
283 // Event fired when a cell context menu is accessed via mouse right click.
284 // e: Event
285 // Decorated event object which contains reference to grid, cell, and rowIndex
286 this.onRowContextMenu(e);
287 },
288
289 onCellFocus: function(inCell, inRowIndex){
290 // summary:
291 // Event fired when a cell receives focus.
292 // inCell: Object
293 // Cell object containing properties of the grid column.
294 // inRowIndex: Integer
295 // Index of the grid row
296 this.edit.cellFocus(inCell, inRowIndex);
297 },
298
299 // row events
300 onRowClick: function(e){
301 // summary:
302 // Event fired when a row is clicked.
303 // e: Event
304 // Decorated event object which contains reference to grid, cell, and rowIndex
305 this.edit.rowClick(e);
306 this.selection.clickSelectEvent(e);
307 },
308
309 onRowDblClick: function(e){
310 // summary:
311 // Event fired when a row is double clicked.
312 // e: Event
313 // decorated event object which contains reference to grid, cell, and rowIndex
314 },
315
316 onRowMouseOver: function(e){
317 // summary:
318 // Event fired when mouse moves over a data row.
319 // e: Event
320 // Decorated event object which contains reference to grid, cell, and rowIndex
321 },
322
323 onRowMouseOut: function(e){
324 // summary:
325 // Event fired when mouse moves out of a data row.
326 // e: Event
327 // Decorated event object contains reference to grid, cell, and rowIndex
328 },
329
330 onRowMouseDown: function(e){
331 // summary:
332 // Event fired when mouse is down in a row.
333 // e: Event
334 // Decorated event object which contains reference to grid, cell, and rowIndex
335 },
336
337 onRowContextMenu: function(e){
338 // summary:
339 // Event fired when a row context menu is accessed via mouse right click.
340 // e: Event
341 // Decorated event object which contains reference to grid, cell, and rowIndex
342 event.stop(e);
343 },
344
345 // header events
346 onHeaderMouseOver: function(e){
347 // summary:
348 // Event fired when mouse moves over the grid header.
349 // e: Event
350 // Decorated event object contains reference to grid, cell, and rowIndex
351 },
352
353 onHeaderMouseOut: function(e){
354 // summary:
355 // Event fired when mouse moves out of the grid header.
356 // e: Event
357 // Decorated event object which contains reference to grid, cell, and rowIndex
358 },
359
360 onHeaderCellMouseOver: function(e){
361 // summary:
362 // Event fired when mouse moves over a header cell.
363 // e: Event
364 // Decorated event object which contains reference to grid, cell, and rowIndex
365 if(e.cellNode){
366 domClass.add(e.cellNode, this.cellOverClass);
367 }
368 },
369
370 onHeaderCellMouseOut: function(e){
371 // summary:
372 // Event fired when mouse moves out of a header cell.
373 // e: Event
374 // Decorated event object which contains reference to grid, cell, and rowIndex
375 if(e.cellNode){
376 domClass.remove(e.cellNode, this.cellOverClass);
377 }
378 },
379
380 onHeaderCellMouseDown: function(e) {
381 // summary:
382 // Event fired when mouse is down in a header cell.
383 // e: Event
384 // Decorated event object which contains reference to grid, cell, and rowIndex
385 },
386
387 onHeaderClick: function(e){
388 // summary:
389 // Event fired when the grid header is clicked.
390 // e: Event
391 // Decorated event object which contains reference to grid, cell, and rowIndex
392 },
393
394 onHeaderCellClick: function(e){
395 // summary:
396 // Event fired when a header cell is clicked.
397 // e: Event
398 // Decorated event object which contains reference to grid, cell, and rowIndex
399 this.setSortIndex(e.cell.index);
400 this.onHeaderClick(e);
401 },
402
403 onHeaderDblClick: function(e){
404 // summary:
405 // Event fired when the grid header is double clicked.
406 // e: Event
407 // Decorated event object which contains reference to grid, cell, and rowIndex
408 },
409
410 onHeaderCellDblClick: function(e){
411 // summary:
412 // Event fired when a header cell is double clicked.
413 // e: Event
414 // Decorated event object which contains reference to grid, cell, and rowIndex
415 this.onHeaderDblClick(e);
416 },
417
418 onHeaderCellContextMenu: function(e){
419 // summary:
420 // Event fired when a header cell context menu is accessed via mouse right click.
421 // e: Event
422 // Decorated event object which contains reference to grid, cell, and rowIndex
423 this.onHeaderContextMenu(e);
424 },
425
426 onHeaderContextMenu: function(e){
427 // summary:
428 // Event fired when the grid header context menu is accessed via mouse right click.
429 // e: Event
430 // Decorated event object which contains reference to grid, cell, and rowIndex
431 if(!this.headerMenu){
432 event.stop(e);
433 }
434 },
435
436 // editing
437 onStartEdit: function(inCell, inRowIndex){
438 // summary:
439 // Event fired when editing is started for a given grid cell
440 // inCell: Object
441 // Cell object containing properties of the grid column.
442 // inRowIndex: Integer
443 // Index of the grid row
444 },
445
446 onApplyCellEdit: function(inValue, inRowIndex, inFieldIndex){
447 // summary:
448 // Event fired when editing is applied for a given grid cell
449 // inValue: String
450 // Value from cell editor
451 // inRowIndex: Integer
452 // Index of the grid row
453 // inFieldIndex: Integer
454 // Index in the grid's data store
455 },
456
457 onCancelEdit: function(inRowIndex){
458 // summary:
459 // Event fired when editing is cancelled for a given grid cell
460 // inRowIndex: Integer
461 // Index of the grid row
462 },
463
464 onApplyEdit: function(inRowIndex){
465 // summary:
466 // Event fired when editing is applied for a given grid row
467 // inRowIndex: Integer
468 // Index of the grid row
469 },
470
471 onCanSelect: function(inRowIndex){
472 // summary:
473 // Event to determine if a grid row may be selected
474 // inRowIndex: Integer
475 // Index of the grid row
476 // returns: Boolean
477 // true if the row can be selected
478 return true;
479 },
480
481 onCanDeselect: function(inRowIndex){
482 // summary:
483 // Event to determine if a grid row may be deselected
484 // inRowIndex: Integer
485 // Index of the grid row
486 // returns: Boolean
487 // true if the row can be deselected
488 return true;
489 },
490
491 onSelected: function(inRowIndex){
492 // summary:
493 // Event fired when a grid row is selected
494 // inRowIndex: Integer
495 // Index of the grid row
496 this.updateRowStyles(inRowIndex);
497 },
498
499 onDeselected: function(inRowIndex){
500 // summary:
501 // Event fired when a grid row is deselected
502 // inRowIndex: Integer
503 // Index of the grid row
504 this.updateRowStyles(inRowIndex);
505 },
506
507 onSelectionChanged: function(){
508 }
509 });
510 });