| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/event", |
| 5 |
"dojo/_base/lang", |
| 6 |
"dojo/_base/html", |
| 7 |
"dojo/_base/window", |
| 8 |
"dojo/_base/connect", |
| 9 |
"dojo/_base/sniff", |
| 10 |
"dojo/query", |
| 11 |
"dojo/keys", |
| 12 |
"dojo/string", |
| 13 |
"../_Plugin", |
| 14 |
"../../EnhancedGrid", |
| 15 |
"../../cells/dijit" |
| 16 |
], function(declare, array, evt, lang, html, win, connect, has, query, keys, string, _Plugin, EnhancedGrid){ |
| 17 |
|
| 18 |
var gridCells = lang.getObject("dojox.grid.cells"); |
| 19 |
|
| 20 |
var RowSelector = declare("dojox.grid.cells.RowSelector", gridCells._Widget, { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
inputType: "", |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
map: null, |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
disabledMap: null, |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
isRowSelector: true, |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
_connects: null, |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
_subscribes: null, |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
checkedText: '✓', |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
unCheckedText: 'O', |
| 55 |
|
| 56 |
constructor: function(){ |
| 57 |
this.map = {}; this.disabledMap = {}; this.disabledCount= 0; |
| 58 |
this._connects = []; this._subscribes = []; |
| 59 |
this.inA11YMode = html.hasClass(win.body(), "dijit_a11y"); |
| 60 |
|
| 61 |
this.baseClass = "dojoxGridRowSelector dijitReset dijitInline dijit" + this.inputType; |
| 62 |
this.checkedClass = " dijit" + this.inputType + "Checked"; |
| 63 |
this.disabledClass = " dijit" + this.inputType + "Disabled"; |
| 64 |
this.checkedDisabledClass = " dijit" + this.inputType + "CheckedDisabled"; |
| 65 |
this.statusTextClass = " dojoxGridRowSelectorStatusText"; |
| 66 |
|
| 67 |
this._connects.push(connect.connect(this.grid, 'dokeyup', this, '_dokeyup')); |
| 68 |
this._connects.push(connect.connect(this.grid.selection, 'onSelected', this, '_onSelected')); |
| 69 |
this._connects.push(connect.connect(this.grid.selection, 'onDeselected', this, '_onDeselected')); |
| 70 |
this._connects.push(connect.connect(this.grid.scroller, 'invalidatePageNode', this, '_pageDestroyed')); |
| 71 |
this._connects.push(connect.connect(this.grid, 'onCellClick', this, '_onClick')); |
| 72 |
this._connects.push(connect.connect(this.grid, 'updateRow', this, '_onUpdateRow')); |
| 73 |
}, |
| 74 |
formatter: function(data, rowIndex, scope){ |
| 75 |
|
| 76 |
|
| 77 |
var _this = scope; |
| 78 |
var clazz = _this.baseClass; |
| 79 |
var checked = !!_this.getValue(rowIndex); |
| 80 |
var disabled = !!_this.disabledMap[rowIndex]; |
| 81 |
|
| 82 |
if(checked){ |
| 83 |
clazz += _this.checkedClass; |
| 84 |
if(disabled){ clazz += _this.checkedDisabledClass; } |
| 85 |
}else if(disabled){ |
| 86 |
clazz += _this.disabledClass; |
| 87 |
} |
| 88 |
return ["<div tabindex = -1 ", |
| 89 |
"id = '" + _this.grid.id + "_rowSelector_" + rowIndex + "' ", |
| 90 |
"name = '" + _this.grid.id + "_rowSelector' class = '" + clazz + "' ", |
| 91 |
"role = " + _this.inputType.toLowerCase() + " aria-checked = '" + checked + "' aria-disabled = '" + disabled + |
| 92 |
"' aria-label = '" + string.substitute(_this.grid._nls["indirectSelection" + _this.inputType], [rowIndex + 1]) + "'>", |
| 93 |
"<span class = '" + _this.statusTextClass + "'>" + (checked ? _this.checkedText : _this.unCheckedText) + "</span>", |
| 94 |
"</div>"].join(""); |
| 95 |
}, |
| 96 |
setValue: function(rowIndex, inValue){ |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
}, |
| 101 |
getValue: function(rowIndex){ |
| 102 |
|
| 103 |
|
| 104 |
return this.grid.selection.isSelected(rowIndex); |
| 105 |
}, |
| 106 |
toggleRow: function(index, value){ |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
this._nativeSelect(index, value); |
| 114 |
}, |
| 115 |
setDisabled: function(index, disabled){ |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
if(index < 0){ return; } |
| 123 |
this._toggleDisabledStyle(index, disabled); |
| 124 |
}, |
| 125 |
disabled: function(index){ |
| 126 |
|
| 127 |
|
| 128 |
return !!this.disabledMap[index]; |
| 129 |
}, |
| 130 |
_onClick: function(e){ |
| 131 |
|
| 132 |
|
| 133 |
if(e.cell === this){ |
| 134 |
this._selectRow(e); |
| 135 |
} |
| 136 |
}, |
| 137 |
_dokeyup: function(e){ |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
if(e.cellIndex == this.index && e.rowIndex >= 0 && e.keyCode == keys.SPACE){ |
| 144 |
this._selectRow(e); |
| 145 |
} |
| 146 |
}, |
| 147 |
focus: function(rowIndex){ |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
var selector = this.map[rowIndex]; |
| 153 |
if(selector){ selector.focus(); } |
| 154 |
}, |
| 155 |
_focusEndingCell: function(rowIndex, cellIndex){ |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
var cell = this.grid.getCell(cellIndex); |
| 163 |
this.grid.focus.setFocusCell(cell, rowIndex); |
| 164 |
}, |
| 165 |
_nativeSelect: function(index, value){ |
| 166 |
|
| 167 |
|
| 168 |
this.grid.selection[value ? 'select' : 'deselect'](index); |
| 169 |
}, |
| 170 |
_onSelected: function(index){ |
| 171 |
|
| 172 |
|
| 173 |
this._toggleCheckedStyle(index, true); |
| 174 |
}, |
| 175 |
_onDeselected: function(index){ |
| 176 |
|
| 177 |
|
| 178 |
this._toggleCheckedStyle(index, false); |
| 179 |
}, |
| 180 |
_onUpdateRow: function(index){ |
| 181 |
|
| 182 |
|
| 183 |
delete this.map[index]; |
| 184 |
}, |
| 185 |
_toggleCheckedStyle: function(index, value){ |
| 186 |
|
| 187 |
|
| 188 |
var selector = this._getSelector(index); |
| 189 |
if(selector){ |
| 190 |
html.toggleClass(selector, this.checkedClass, value); |
| 191 |
if(this.disabledMap[index]){ |
| 192 |
html.toggleClass(selector, this.checkedDisabledClass, value); |
| 193 |
} |
| 194 |
selector.setAttribute("aria-checked", value); |
| 195 |
if(this.inA11YMode){ |
| 196 |
selector.firstChild.innerHTML = (value ? this.checkedText : this.unCheckedText); |
| 197 |
} |
| 198 |
} |
| 199 |
}, |
| 200 |
_toggleDisabledStyle: function(index, disabled){ |
| 201 |
|
| 202 |
|
| 203 |
var selector = this._getSelector(index); |
| 204 |
if(selector){ |
| 205 |
html.toggleClass(selector, this.disabledClass, disabled); |
| 206 |
if(this.getValue(index)){ |
| 207 |
html.toggleClass(selector, this.checkedDisabledClass, disabled); |
| 208 |
} |
| 209 |
selector.setAttribute("aria-disabled", disabled); |
| 210 |
} |
| 211 |
this.disabledMap[index] = disabled; |
| 212 |
if(index >= 0){ |
| 213 |
this.disabledCount += disabled ? 1 : -1; |
| 214 |
} |
| 215 |
}, |
| 216 |
_getSelector: function(index){ |
| 217 |
|
| 218 |
|
| 219 |
var selector = this.map[index]; |
| 220 |
if(!selector){ |
| 221 |
var rowNode = this.view.rowNodes[index]; |
| 222 |
if(rowNode){ |
| 223 |
selector = query('.dojoxGridRowSelector', rowNode)[0]; |
| 224 |
if(selector){ this.map[index] = selector; } |
| 225 |
} |
| 226 |
} |
| 227 |
return selector; |
| 228 |
}, |
| 229 |
_pageDestroyed: function(pageIndex){ |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
var rowsPerPage = this.grid.scroller.rowsPerPage; |
| 236 |
var start = pageIndex * rowsPerPage, end = start + rowsPerPage - 1; |
| 237 |
for(var i = start; i <= end; i++){ |
| 238 |
if(!this.map[i]){continue;} |
| 239 |
html.destroy(this.map[i]); |
| 240 |
delete this.map[i]; |
| 241 |
} |
| 242 |
|
| 243 |
}, |
| 244 |
destroy: function(){ |
| 245 |
for(var i in this.map){ |
| 246 |
html.destroy(this.map[i]); |
| 247 |
delete this.map[i]; |
| 248 |
} |
| 249 |
for(i in this.disabledMap){ delete this.disabledMap[i]; } |
| 250 |
array.forEach(this._connects, connect.disconnect); |
| 251 |
array.forEach(this._subscribes, connect.unsubscribe); |
| 252 |
delete this._connects; |
| 253 |
delete this._subscribes; |
| 254 |
|
| 255 |
} |
| 256 |
}); |
| 257 |
|
| 258 |
var SingleRowSelector = declare("dojox.grid.cells.SingleRowSelector", RowSelector, { |
| 259 |
|
| 260 |
|
| 261 |
inputType: "Radio", |
| 262 |
|
| 263 |
_selectRow: function(e){ |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
var index = e.rowIndex; |
| 269 |
if(this.disabledMap[index]){ return; } |
| 270 |
this._focusEndingCell(index, e.cellIndex); |
| 271 |
this._nativeSelect(index, !this.grid.selection.selected[index]); |
| 272 |
} |
| 273 |
}); |
| 274 |
|
| 275 |
var MultipleRowSelector = declare("dojox.grid.cells.MultipleRowSelector", RowSelector, { |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
inputType: "CheckBox", |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
swipeStartRowIndex: -1, |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
swipeMinRowIndex: -1, |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
swipeMaxRowIndex: -1, |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
toSelect: false, |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
lastClickRowIdx: -1, |
| 301 |
|
| 302 |
unCheckedText: '□', |
| 303 |
|
| 304 |
constructor: function(){ |
| 305 |
this._connects.push(connect.connect(win.doc, 'onmouseup', this, '_domouseup')); |
| 306 |
this._connects.push(connect.connect(this.grid, 'onRowMouseOver', this, '_onRowMouseOver')); |
| 307 |
this._connects.push(connect.connect(this.grid.focus, 'move', this, '_swipeByKey')); |
| 308 |
this._connects.push(connect.connect(this.grid, 'onCellMouseDown', this, '_onMouseDown')); |
| 309 |
if(this.headerSelector){ |
| 310 |
this._connects.push(connect.connect(this.grid.views, 'render', this, '_addHeaderSelector')); |
| 311 |
this._connects.push(connect.connect(this.grid, '_onFetchComplete', this, '_addHeaderSelector')); |
| 312 |
this._connects.push(connect.connect(this.grid, 'onSelectionChanged', this, '_onSelectionChanged')); |
| 313 |
this._connects.push(connect.connect(this.grid, 'onKeyDown', this, function(e){ |
| 314 |
if(e.rowIndex == -1 && e.cellIndex == this.index && e.keyCode == keys.SPACE){ |
| 315 |
this._toggletHeader(); |
| 316 |
} |
| 317 |
})); |
| 318 |
} |
| 319 |
}, |
| 320 |
toggleAllSelection:function(checked){ |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
var grid = this.grid, selection = grid.selection; |
| 326 |
if(checked){ |
| 327 |
selection.selectRange(0, grid.rowCount-1); |
| 328 |
}else{ |
| 329 |
selection.deselectAll(); |
| 330 |
} |
| 331 |
}, |
| 332 |
_onMouseDown: function(e){ |
| 333 |
if(e.cell == this){ |
| 334 |
this._startSelection(e.rowIndex); |
| 335 |
evt.stop(e); |
| 336 |
} |
| 337 |
}, |
| 338 |
_onRowMouseOver: function(e){ |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
this._updateSelection(e, 0); |
| 345 |
}, |
| 346 |
_domouseup: function(e){ |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
if(has('ie')){ |
| 352 |
this.view.content.decorateEvent(e); |
| 353 |
} |
| 354 |
var inSwipeSelection = e.cellIndex >= 0 && this.inSwipeSelection() && !this.grid.edit.isEditRow(e.rowIndex); |
| 355 |
if(inSwipeSelection){ |
| 356 |
this._focusEndingCell(e.rowIndex, e.cellIndex); |
| 357 |
} |
| 358 |
this._finishSelect(); |
| 359 |
}, |
| 360 |
_dokeyup: function(e){ |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
this.inherited(arguments); |
| 367 |
if(!e.shiftKey){ |
| 368 |
this._finishSelect(); |
| 369 |
} |
| 370 |
}, |
| 371 |
_startSelection: function(rowIndex){ |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
this.swipeStartRowIndex = this.swipeMinRowIndex = this.swipeMaxRowIndex = rowIndex; |
| 377 |
this.toSelect = !this.getValue(rowIndex); |
| 378 |
}, |
| 379 |
_updateSelection: function(e, delta){ |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
if(!this.inSwipeSelection()){ return; } |
| 388 |
|
| 389 |
var byKey = delta !== 0; |
| 390 |
var currRow = e.rowIndex, deltaRow = currRow - this.swipeStartRowIndex + delta; |
| 391 |
if(deltaRow > 0 && this.swipeMaxRowIndex < currRow + delta){ |
| 392 |
this.swipeMaxRowIndex = currRow + delta; |
| 393 |
} |
| 394 |
if(deltaRow < 0 && this.swipeMinRowIndex > currRow + delta){ |
| 395 |
this.swipeMinRowIndex = currRow + delta; |
| 396 |
} |
| 397 |
|
| 398 |
var min = deltaRow > 0 ? this.swipeStartRowIndex : currRow + delta; |
| 399 |
var max = deltaRow > 0 ? currRow + delta : this.swipeStartRowIndex; |
| 400 |
for(var i = this.swipeMinRowIndex; i <= this.swipeMaxRowIndex; i++){ |
| 401 |
if(this.disabledMap[i] || i < 0){ continue; } |
| 402 |
if(i >= min && i <= max){ |
| 403 |
this._nativeSelect(i, this.toSelect); |
| 404 |
}else if(!byKey){ |
| 405 |
this._nativeSelect(i, !this.toSelect); |
| 406 |
} |
| 407 |
} |
| 408 |
}, |
| 409 |
_swipeByKey: function(rowOffset, colOffset, e){ |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
if(!e || rowOffset === 0 || !e.shiftKey || e.cellIndex != this.index || |
| 419 |
this.grid.focus.rowIndex < 0){ |
| 420 |
return; |
| 421 |
} |
| 422 |
var rowIndex = e.rowIndex; |
| 423 |
if(this.swipeStartRowIndex < 0){ |
| 424 |
|
| 425 |
this.swipeStartRowIndex = rowIndex; |
| 426 |
if(rowOffset > 0){ |
| 427 |
this.swipeMaxRowIndex = rowIndex + rowOffset; |
| 428 |
this.swipeMinRowIndex = rowIndex; |
| 429 |
}else{ |
| 430 |
this.swipeMinRowIndex = rowIndex + rowOffset; |
| 431 |
this.swipeMaxRowIndex = rowIndex; |
| 432 |
} |
| 433 |
this.toSelect = this.getValue(rowIndex); |
| 434 |
} |
| 435 |
this._updateSelection(e, rowOffset); |
| 436 |
}, |
| 437 |
_finishSelect: function(){ |
| 438 |
|
| 439 |
|
| 440 |
this.swipeStartRowIndex = -1; |
| 441 |
this.swipeMinRowIndex = -1; |
| 442 |
this.swipeMaxRowIndex = -1; |
| 443 |
this.toSelect = false; |
| 444 |
}, |
| 445 |
inSwipeSelection: function(){ |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
return this.swipeStartRowIndex >= 0; |
| 451 |
}, |
| 452 |
_nativeSelect: function(index, value){ |
| 453 |
|
| 454 |
|
| 455 |
this.grid.selection[value ? 'addToSelection' : 'deselect'](index); |
| 456 |
}, |
| 457 |
_selectRow: function(e){ |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
var rowIndex = e.rowIndex; |
| 463 |
if(this.disabledMap[rowIndex]){ return; } |
| 464 |
evt.stop(e); |
| 465 |
this._focusEndingCell(rowIndex, e.cellIndex); |
| 466 |
|
| 467 |
var delta = rowIndex - this.lastClickRowIdx; |
| 468 |
var newValue = !this.grid.selection.selected[rowIndex]; |
| 469 |
if(this.lastClickRowIdx >= 0 && !e.ctrlKey && !e.altKey && e.shiftKey){ |
| 470 |
var min = delta > 0 ? this.lastClickRowIdx : rowIndex; |
| 471 |
var max = delta > 0 ? rowIndex : this.lastClickRowIdx; |
| 472 |
for(var i = min; i >= 0 && i <= max; i++){ |
| 473 |
this._nativeSelect(i, newValue); |
| 474 |
} |
| 475 |
}else{ |
| 476 |
this._nativeSelect(rowIndex, newValue); |
| 477 |
} |
| 478 |
this.lastClickRowIdx = rowIndex; |
| 479 |
}, |
| 480 |
getValue: function(rowIndex){ |
| 481 |
|
| 482 |
|
| 483 |
if(rowIndex == -1){ |
| 484 |
var g = this.grid; |
| 485 |
return g.rowCount > 0 && g.rowCount <= g.selection.getSelectedCount(); |
| 486 |
} |
| 487 |
return this.inherited(arguments); |
| 488 |
}, |
| 489 |
_addHeaderSelector: function(){ |
| 490 |
|
| 491 |
|
| 492 |
var headerCellNode = this.view.getHeaderCellNode(this.index); |
| 493 |
if(!headerCellNode){ return; } |
| 494 |
html.empty(headerCellNode); |
| 495 |
var g = this.grid; |
| 496 |
var selector = headerCellNode.appendChild(html.create("div", { |
| 497 |
'aria-label': g._nls["selectAll"], |
| 498 |
"tabindex": -1, "id": g.id + "_rowSelector_-1", "class": this.baseClass, "role": "checkbox", |
| 499 |
"innerHTML": "<span class = '" + this.statusTextClass + |
| 500 |
"'></span><span style='height: 0; width: 0; overflow: hidden; display: block;'>" + |
| 501 |
g._nls["selectAll"] + "</span>" |
| 502 |
})); |
| 503 |
this.map[-1] = selector; |
| 504 |
var idx = this._headerSelectorConnectIdx; |
| 505 |
if(idx !== undefined){ |
| 506 |
connect.disconnect(this._connects[idx]); |
| 507 |
this._connects.splice(idx, 1); |
| 508 |
} |
| 509 |
this._headerSelectorConnectIdx = this._connects.length; |
| 510 |
this._connects.push(connect.connect(selector, 'onclick', this, '_toggletHeader')); |
| 511 |
this._onSelectionChanged(); |
| 512 |
}, |
| 513 |
_toggletHeader: function(){ |
| 514 |
|
| 515 |
|
| 516 |
if(!!this.disabledMap[-1]){ return; } |
| 517 |
this.grid._selectingRange = true; |
| 518 |
this.toggleAllSelection(!this.getValue(-1)); |
| 519 |
this._onSelectionChanged(); |
| 520 |
this.grid._selectingRange = false; |
| 521 |
}, |
| 522 |
_onSelectionChanged: function(){ |
| 523 |
|
| 524 |
|
| 525 |
var g = this.grid; |
| 526 |
if(!this.map[-1] || g._selectingRange){ return; } |
| 527 |
g.allItemsSelected = this.getValue(-1); |
| 528 |
this._toggleCheckedStyle(-1, g.allItemsSelected); |
| 529 |
}, |
| 530 |
_toggleDisabledStyle: function(index, disabled){ |
| 531 |
|
| 532 |
|
| 533 |
this.inherited(arguments); |
| 534 |
if(this.headerSelector){ |
| 535 |
var allDisabled = (this.grid.rowCount == this.disabledCount); |
| 536 |
if(allDisabled != !!this.disabledMap[-1]){ |
| 537 |
arguments[0] = -1; |
| 538 |
arguments[1] = allDisabled; |
| 539 |
this.inherited(arguments); |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
}); |
| 544 |
|
| 545 |
var IndirectSelection = declare("dojox.grid.enhanced.plugins.IndirectSelection", _Plugin, { |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
name: "indirectSelection", |
| 560 |
|
| 561 |
constructor: function(){ |
| 562 |
|
| 563 |
var layout = this.grid.layout; |
| 564 |
this.connect(layout, 'setStructure', lang.hitch(layout, this.addRowSelectCell, this.option)); |
| 565 |
}, |
| 566 |
addRowSelectCell: function(option){ |
| 567 |
|
| 568 |
|
| 569 |
if(!this.grid.indirectSelection || this.grid.selectionMode == 'none'){ |
| 570 |
return; |
| 571 |
} |
| 572 |
var rowSelectCellAdded = false, inValidFields = ['get', 'formatter', 'field', 'fields'], |
| 573 |
defaultCellDef = {type: MultipleRowSelector, name: '', width:'30px', styles:'text-align: center;'}; |
| 574 |
if(option.headerSelector){ option.name = ''; } |
| 575 |
|
| 576 |
if(this.grid.rowSelectCell){ |
| 577 |
this.grid.rowSelectCell.destroy(); |
| 578 |
} |
| 579 |
|
| 580 |
array.forEach(this.structure, function(view){ |
| 581 |
var cells = view.cells; |
| 582 |
if(cells && cells.length > 0 && !rowSelectCellAdded){ |
| 583 |
var firstRow = cells[0]; |
| 584 |
if(firstRow[0] && firstRow[0].isRowSelector){ |
| 585 |
console.debug('addRowSelectCell() - row selector cells already added, return.'); |
| 586 |
rowSelectCellAdded = true; |
| 587 |
return; |
| 588 |
} |
| 589 |
var selectDef, cellType = this.grid.selectionMode == 'single' ? SingleRowSelector : MultipleRowSelector; |
| 590 |
selectDef = lang.mixin(defaultCellDef, option, {type: cellType, editable: false, notselectable: true, filterable: false, navigatable: true, nosort: true}); |
| 591 |
array.forEach(inValidFields, function(field){ |
| 592 |
if(field in selectDef){ delete selectDef[field]; } |
| 593 |
}); |
| 594 |
if(cells.length > 1){ selectDef.rowSpan = cells.length; } |
| 595 |
array.forEach(this.cells, function(cell, i){ |
| 596 |
if(cell.index >= 0){ |
| 597 |
cell.index += 1; |
| 598 |
|
| 599 |
}else{ |
| 600 |
console.warn('Error:IndirectSelection.addRowSelectCell()- cell ' + i + ' has no index!'); |
| 601 |
} |
| 602 |
}); |
| 603 |
var rowSelectCell = this.addCellDef(0, 0, selectDef); |
| 604 |
rowSelectCell.index = 0; |
| 605 |
firstRow.unshift(rowSelectCell); |
| 606 |
this.cells.unshift(rowSelectCell); |
| 607 |
this.grid.rowSelectCell = rowSelectCell; |
| 608 |
rowSelectCellAdded = true; |
| 609 |
} |
| 610 |
}, this); |
| 611 |
this.cellCount = this.cells.length; |
| 612 |
}, |
| 613 |
destroy: function(){ |
| 614 |
this.grid.rowSelectCell.destroy(); |
| 615 |
delete this.grid.rowSelectCell; |
| 616 |
this.inherited(arguments); |
| 617 |
} |
| 618 |
}); |
| 619 |
|
| 620 |
EnhancedGrid.registerPlugin(IndirectSelection, {"preInit": true}); |
| 621 |
|
| 622 |
return IndirectSelection; |
| 623 |
}); |