| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
cellOverClass: "dojoxGridCellOver", |
| 19 |
|
| 20 |
onKeyEvent: function(e){ |
| 21 |
|
| 22 |
|
| 23 |
this.dispatchKeyEvent(e); |
| 24 |
}, |
| 25 |
|
| 26 |
onContentEvent: function(e){ |
| 27 |
|
| 28 |
|
| 29 |
this.dispatchContentEvent(e); |
| 30 |
}, |
| 31 |
|
| 32 |
onHeaderEvent: function(e){ |
| 33 |
|
| 34 |
|
| 35 |
this.dispatchHeaderEvent(e); |
| 36 |
}, |
| 37 |
|
| 38 |
onStyleRow: function(inRow){ |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 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 |
|
| 55 |
|
| 56 |
|
| 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]; |
| 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 |
|
| 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; |
| 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 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
e.rowIndex == -1 ? this.onHeaderCellMouseOver(e) : this.onCellMouseOver(e); |
| 168 |
}, |
| 169 |
|
| 170 |
onMouseOut: function(e){ |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
e.rowIndex == -1 ? this.onHeaderCellMouseOut(e) : this.onCellMouseOut(e); |
| 176 |
}, |
| 177 |
|
| 178 |
onMouseDown: function(e){ |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
e.rowIndex == -1 ? this.onHeaderCellMouseDown(e) : this.onCellMouseDown(e); |
| 184 |
}, |
| 185 |
|
| 186 |
onMouseOverRow: function(e){ |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 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 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 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 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
if(e.rowIndex != -1) |
| 215 |
this.onRowMouseDown(e); |
| 216 |
}, |
| 217 |
|
| 218 |
|
| 219 |
onCellMouseOver: function(e){ |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
if(e.cellNode){ |
| 225 |
domClass.add(e.cellNode, this.cellOverClass); |
| 226 |
} |
| 227 |
}, |
| 228 |
|
| 229 |
onCellMouseOut: function(e){ |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
if(e.cellNode){ |
| 235 |
domClass.remove(e.cellNode, this.cellOverClass); |
| 236 |
} |
| 237 |
}, |
| 238 |
|
| 239 |
onCellMouseDown: function(e){ |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
}, |
| 245 |
|
| 246 |
onCellClick: function(e){ |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 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 |
|
| 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 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 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 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
this.onRowContextMenu(e); |
| 287 |
}, |
| 288 |
|
| 289 |
onCellFocus: function(inCell, inRowIndex){ |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
this.edit.cellFocus(inCell, inRowIndex); |
| 297 |
}, |
| 298 |
|
| 299 |
|
| 300 |
onRowClick: function(e){ |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
this.edit.rowClick(e); |
| 306 |
this.selection.clickSelectEvent(e); |
| 307 |
}, |
| 308 |
|
| 309 |
onRowDblClick: function(e){ |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
}, |
| 315 |
|
| 316 |
onRowMouseOver: function(e){ |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
}, |
| 322 |
|
| 323 |
onRowMouseOut: function(e){ |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
}, |
| 329 |
|
| 330 |
onRowMouseDown: function(e){ |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
}, |
| 336 |
|
| 337 |
onRowContextMenu: function(e){ |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
event.stop(e); |
| 343 |
}, |
| 344 |
|
| 345 |
|
| 346 |
onHeaderMouseOver: function(e){ |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
}, |
| 352 |
|
| 353 |
onHeaderMouseOut: function(e){ |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
}, |
| 359 |
|
| 360 |
onHeaderCellMouseOver: function(e){ |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
if(e.cellNode){ |
| 366 |
domClass.add(e.cellNode, this.cellOverClass); |
| 367 |
} |
| 368 |
}, |
| 369 |
|
| 370 |
onHeaderCellMouseOut: function(e){ |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if(e.cellNode){ |
| 376 |
domClass.remove(e.cellNode, this.cellOverClass); |
| 377 |
} |
| 378 |
}, |
| 379 |
|
| 380 |
onHeaderCellMouseDown: function(e) { |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
}, |
| 386 |
|
| 387 |
onHeaderClick: function(e){ |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
}, |
| 393 |
|
| 394 |
onHeaderCellClick: function(e){ |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
this.setSortIndex(e.cell.index); |
| 400 |
this.onHeaderClick(e); |
| 401 |
}, |
| 402 |
|
| 403 |
onHeaderDblClick: function(e){ |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
}, |
| 409 |
|
| 410 |
onHeaderCellDblClick: function(e){ |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
this.onHeaderDblClick(e); |
| 416 |
}, |
| 417 |
|
| 418 |
onHeaderCellContextMenu: function(e){ |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
this.onHeaderContextMenu(e); |
| 424 |
}, |
| 425 |
|
| 426 |
onHeaderContextMenu: function(e){ |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
if(!this.headerMenu){ |
| 432 |
event.stop(e); |
| 433 |
} |
| 434 |
}, |
| 435 |
|
| 436 |
|
| 437 |
onStartEdit: function(inCell, inRowIndex){ |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
}, |
| 445 |
|
| 446 |
onApplyCellEdit: function(inValue, inRowIndex, inFieldIndex){ |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
}, |
| 456 |
|
| 457 |
onCancelEdit: function(inRowIndex){ |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
}, |
| 463 |
|
| 464 |
onApplyEdit: function(inRowIndex){ |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
}, |
| 470 |
|
| 471 |
onCanSelect: function(inRowIndex){ |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
return true; |
| 479 |
}, |
| 480 |
|
| 481 |
onCanDeselect: function(inRowIndex){ |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
return true; |
| 489 |
}, |
| 490 |
|
| 491 |
onSelected: function(inRowIndex){ |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
this.updateRowStyles(inRowIndex); |
| 497 |
}, |
| 498 |
|
| 499 |
onDeselected: function(inRowIndex){ |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
this.updateRowStyles(inRowIndex); |
| 505 |
}, |
| 506 |
|
| 507 |
onSelectionChanged: function(){ |
| 508 |
} |
| 509 |
}); |
| 510 |
}); |