| 1 |
define([ |
| 2 |
"../main", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/_base/window", |
| 6 |
"dojo/_base/event", |
| 7 |
"dojo/_base/sniff", |
| 8 |
"dojo/_base/connect", |
| 9 |
"dojo/dnd/Moveable", |
| 10 |
"dojox/html/metrics", |
| 11 |
"./util", |
| 12 |
"dojo/_base/html", |
| 13 |
"dojo/dom-geometry" |
| 14 |
], function(dojox, array, lang, win, event, has, connect, Moveable, metrics, util, html, domGeometry){ |
| 15 |
|
| 16 |
var dg = dojox.grid; |
| 17 |
|
| 18 |
var getTdIndex = function(td){ |
| 19 |
return td.cellIndex >=0 ? td.cellIndex : array.indexOf(td.parentNode.cells, td); |
| 20 |
}; |
| 21 |
|
| 22 |
var getTrIndex = function(tr){ |
| 23 |
return tr.rowIndex >=0 ? tr.rowIndex : array.indexOf(tr.parentNode.childNodes, tr); |
| 24 |
}; |
| 25 |
|
| 26 |
var getTr = function(rowOwner, index){ |
| 27 |
return rowOwner && ((rowOwner.rows||0)[index] || rowOwner.childNodes[index]); |
| 28 |
}; |
| 29 |
|
| 30 |
var findTable = function(node){ |
| 31 |
for(var n=node; n && n.tagName!='TABLE'; n=n.parentNode){} |
| 32 |
return n; |
| 33 |
}; |
| 34 |
|
| 35 |
var ascendDom = function(inNode, inWhile){ |
| 36 |
for(var n=inNode; n && inWhile(n); n=n.parentNode){} |
| 37 |
return n; |
| 38 |
}; |
| 39 |
|
| 40 |
var makeNotTagName = function(inTagName){ |
| 41 |
var name = inTagName.toUpperCase(); |
| 42 |
return function(node){ return node.tagName != name; }; |
| 43 |
}; |
| 44 |
|
| 45 |
var rowIndexTag = util.rowIndexTag; |
| 46 |
var gridViewTag = util.gridViewTag; |
| 47 |
|
| 48 |
|
| 49 |
var _Builder = dg._Builder = lang.extend(function(view){ |
| 50 |
if(view){ |
| 51 |
this.view = view; |
| 52 |
this.grid = view.grid; |
| 53 |
} |
| 54 |
},{ |
| 55 |
view: null, |
| 56 |
|
| 57 |
_table: '<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation"', |
| 58 |
|
| 59 |
|
| 60 |
getTableArray: function(){ |
| 61 |
var html = [this._table]; |
| 62 |
if(this.view.viewWidth){ |
| 63 |
html.push([' style="width:', this.view.viewWidth, ';"'].join('')); |
| 64 |
} |
| 65 |
html.push('>'); |
| 66 |
return html; |
| 67 |
}, |
| 68 |
|
| 69 |
|
| 70 |
generateCellMarkup: function(inCell, inMoreStyles, inMoreClasses, isHeader){ |
| 71 |
var result = [], html; |
| 72 |
if(isHeader){ |
| 73 |
var sortInfo = inCell.index != inCell.grid.getSortIndex() ? "" : inCell.grid.sortInfo > 0 ? 'aria-sort="ascending"' : 'aria-sort="descending"'; |
| 74 |
if (!inCell.id){ |
| 75 |
inCell.id = this.grid.id + "Hdr" + inCell.index; |
| 76 |
} |
| 77 |
|
| 78 |
html = ['<th tabIndex="-1" aria-readonly="true" role="columnheader"', sortInfo, ' id="', inCell.id, '"']; |
| 79 |
}else{ |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
var editInfo = this.grid.editable && !inCell.editable ? 'aria-readonly="true"' : ""; |
| 84 |
html = ['<td tabIndex="-1" role="gridcell"', editInfo]; |
| 85 |
} |
| 86 |
if(inCell.colSpan){ |
| 87 |
html.push(' colspan="', inCell.colSpan, '"'); |
| 88 |
} |
| 89 |
if(inCell.rowSpan){ |
| 90 |
html.push(' rowspan="', inCell.rowSpan, '"'); |
| 91 |
} |
| 92 |
html.push(' class="dojoxGridCell '); |
| 93 |
if(inCell.classes){ |
| 94 |
html.push(inCell.classes, ' '); |
| 95 |
} |
| 96 |
if(inMoreClasses){ |
| 97 |
html.push(inMoreClasses, ' '); |
| 98 |
} |
| 99 |
|
| 100 |
result.push(html.join('')); |
| 101 |
|
| 102 |
result.push(''); |
| 103 |
html = ['" idx="', inCell.index, '" style="']; |
| 104 |
if(inMoreStyles && inMoreStyles[inMoreStyles.length-1] != ';'){ |
| 105 |
inMoreStyles += ';'; |
| 106 |
} |
| 107 |
html.push(inCell.styles, inMoreStyles||'', inCell.hidden?'display:none;':''); |
| 108 |
if(inCell.unitWidth){ |
| 109 |
html.push('width:', inCell.unitWidth, ';'); |
| 110 |
} |
| 111 |
|
| 112 |
result.push(html.join('')); |
| 113 |
|
| 114 |
result.push(''); |
| 115 |
html = [ '"' ]; |
| 116 |
if(inCell.attrs){ |
| 117 |
html.push(" ", inCell.attrs); |
| 118 |
} |
| 119 |
html.push('>'); |
| 120 |
|
| 121 |
result.push(html.join('')); |
| 122 |
|
| 123 |
result.push(''); |
| 124 |
|
| 125 |
result.push(isHeader?'</th>':'</td>'); |
| 126 |
return result; |
| 127 |
}, |
| 128 |
|
| 129 |
|
| 130 |
isCellNode: function(inNode){ |
| 131 |
return Boolean(inNode && inNode!=win.doc && html.attr(inNode, "idx")); |
| 132 |
}, |
| 133 |
|
| 134 |
getCellNodeIndex: function(inCellNode){ |
| 135 |
return inCellNode ? Number(html.attr(inCellNode, "idx")) : -1; |
| 136 |
}, |
| 137 |
|
| 138 |
getCellNode: function(inRowNode, inCellIndex){ |
| 139 |
for(var i=0, row; ((row = getTr(inRowNode.firstChild, i)) && row.cells); i++){ |
| 140 |
for(var j=0, cell; (cell = row.cells[j]); j++){ |
| 141 |
if(this.getCellNodeIndex(cell) == inCellIndex){ |
| 142 |
return cell; |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
return null; |
| 147 |
}, |
| 148 |
|
| 149 |
findCellTarget: function(inSourceNode, inTopNode){ |
| 150 |
var n = inSourceNode; |
| 151 |
while(n && (!this.isCellNode(n) || (n.offsetParent && gridViewTag in n.offsetParent.parentNode && n.offsetParent.parentNode[gridViewTag] != this.view.id)) && (n!=inTopNode)){ |
| 152 |
n = n.parentNode; |
| 153 |
} |
| 154 |
return n!=inTopNode ? n : null; |
| 155 |
}, |
| 156 |
|
| 157 |
|
| 158 |
baseDecorateEvent: function(e){ |
| 159 |
e.dispatch = 'do' + e.type; |
| 160 |
e.grid = this.grid; |
| 161 |
e.sourceView = this.view; |
| 162 |
e.cellNode = this.findCellTarget(e.target, e.rowNode); |
| 163 |
e.cellIndex = this.getCellNodeIndex(e.cellNode); |
| 164 |
e.cell = (e.cellIndex >= 0 ? this.grid.getCell(e.cellIndex) : null); |
| 165 |
}, |
| 166 |
|
| 167 |
|
| 168 |
findTarget: function(inSource, inTag){ |
| 169 |
var n = inSource; |
| 170 |
while(n && (n!=this.domNode) && (!(inTag in n) || (gridViewTag in n && n[gridViewTag] != this.view.id))){ |
| 171 |
n = n.parentNode; |
| 172 |
} |
| 173 |
return (n != this.domNode) ? n : null; |
| 174 |
}, |
| 175 |
|
| 176 |
findRowTarget: function(inSource){ |
| 177 |
return this.findTarget(inSource, rowIndexTag); |
| 178 |
}, |
| 179 |
|
| 180 |
isIntraNodeEvent: function(e){ |
| 181 |
try{ |
| 182 |
return (e.cellNode && e.relatedTarget && html.isDescendant(e.relatedTarget, e.cellNode)); |
| 183 |
}catch(x){ |
| 184 |
|
| 185 |
return false; |
| 186 |
} |
| 187 |
}, |
| 188 |
|
| 189 |
isIntraRowEvent: function(e){ |
| 190 |
try{ |
| 191 |
var row = e.relatedTarget && this.findRowTarget(e.relatedTarget); |
| 192 |
return !row && (e.rowIndex==-1) || row && (e.rowIndex==row.gridRowIndex); |
| 193 |
}catch(x){ |
| 194 |
|
| 195 |
return false; |
| 196 |
} |
| 197 |
}, |
| 198 |
|
| 199 |
dispatchEvent: function(e){ |
| 200 |
if(e.dispatch in this){ |
| 201 |
return this[e.dispatch](e); |
| 202 |
} |
| 203 |
return false; |
| 204 |
}, |
| 205 |
|
| 206 |
|
| 207 |
domouseover: function(e){ |
| 208 |
if(e.cellNode && (e.cellNode!=this.lastOverCellNode)){ |
| 209 |
this.lastOverCellNode = e.cellNode; |
| 210 |
this.grid.onMouseOver(e); |
| 211 |
} |
| 212 |
this.grid.onMouseOverRow(e); |
| 213 |
}, |
| 214 |
|
| 215 |
domouseout: function(e){ |
| 216 |
if(e.cellNode && (e.cellNode==this.lastOverCellNode) && !this.isIntraNodeEvent(e, this.lastOverCellNode)){ |
| 217 |
this.lastOverCellNode = null; |
| 218 |
this.grid.onMouseOut(e); |
| 219 |
if(!this.isIntraRowEvent(e)){ |
| 220 |
this.grid.onMouseOutRow(e); |
| 221 |
} |
| 222 |
} |
| 223 |
}, |
| 224 |
|
| 225 |
domousedown: function(e){ |
| 226 |
if (e.cellNode) |
| 227 |
this.grid.onMouseDown(e); |
| 228 |
this.grid.onMouseDownRow(e); |
| 229 |
}, |
| 230 |
|
| 231 |
_getTextDirStyle: function(textDir, inCell, inRowIndex){ |
| 232 |
|
| 233 |
|
| 234 |
return ""; |
| 235 |
} |
| 236 |
}); |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
var _ContentBuilder = dg._ContentBuilder = lang.extend(function(view){ |
| 241 |
_Builder.call(this, view); |
| 242 |
},_Builder.prototype,{ |
| 243 |
update: function(){ |
| 244 |
this.prepareHtml(); |
| 245 |
}, |
| 246 |
|
| 247 |
|
| 248 |
prepareHtml: function(){ |
| 249 |
var defaultGet=this.grid.get, cells=this.view.structure.cells; |
| 250 |
for(var j=0, row; (row=cells[j]); j++){ |
| 251 |
for(var i=0, cell; (cell=row[i]); i++){ |
| 252 |
cell.get = cell.get || (cell.value == undefined) && defaultGet; |
| 253 |
cell.markup = this.generateCellMarkup(cell, cell.cellStyles, cell.cellClasses, false); |
| 254 |
if (!this.grid.editable && cell.editable){ |
| 255 |
this.grid.editable = true; |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
}, |
| 260 |
|
| 261 |
|
| 262 |
generateHtml: function(inDataIndex, inRowIndex){ |
| 263 |
var html = this.getTableArray(); |
| 264 |
var v = this.view; |
| 265 |
var cells = v.structure.cells; |
| 266 |
var item = this.grid.getItem(inRowIndex); |
| 267 |
var dir; |
| 268 |
|
| 269 |
util.fire(this.view, "onBeforeRow", [inRowIndex, cells]); |
| 270 |
for(var j=0, row; (row = cells[j]); j++){ |
| 271 |
if(row.hidden || row.header){ |
| 272 |
continue; |
| 273 |
} |
| 274 |
html.push(!row.invisible ? '<tr>' : '<tr class="dojoxGridInvisible">'); |
| 275 |
for(var i=0, cell, m, cc, cs; (cell=row[i]); i++){ |
| 276 |
m = cell.markup; |
| 277 |
cc = cell.customClasses = []; |
| 278 |
cs = cell.customStyles = []; |
| 279 |
|
| 280 |
|
| 281 |
m[5] = cell.format(inRowIndex, item); |
| 282 |
|
| 283 |
m[1] = cc.join(' '); |
| 284 |
|
| 285 |
m[3] = cs.join(';'); |
| 286 |
dir = cell.textDir || this.grid.textDir; |
| 287 |
if (dir) { |
| 288 |
m[3] += this._getTextDirStyle(dir, cell, inRowIndex); |
| 289 |
} |
| 290 |
|
| 291 |
html.push.apply(html, m); |
| 292 |
} |
| 293 |
html.push('</tr>'); |
| 294 |
} |
| 295 |
html.push('</table>'); |
| 296 |
return html.join(''); |
| 297 |
}, |
| 298 |
|
| 299 |
decorateEvent: function(e){ |
| 300 |
e.rowNode = this.findRowTarget(e.target); |
| 301 |
if(!e.rowNode){return false;} |
| 302 |
e.rowIndex = e.rowNode[rowIndexTag]; |
| 303 |
this.baseDecorateEvent(e); |
| 304 |
e.cell = this.grid.getCell(e.cellIndex); |
| 305 |
return true; |
| 306 |
} |
| 307 |
}); |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
var _HeaderBuilder = dg._HeaderBuilder = lang.extend(function(view){ |
| 312 |
this.moveable = null; |
| 313 |
_Builder.call(this, view); |
| 314 |
},_Builder.prototype,{ |
| 315 |
_skipBogusClicks: false, |
| 316 |
overResizeWidth: 4, |
| 317 |
minColWidth: 1, |
| 318 |
|
| 319 |
update: function(){ |
| 320 |
if(this.tableMap){ |
| 321 |
this.tableMap.mapRows(this.view.structure.cells); |
| 322 |
}else{ |
| 323 |
this.tableMap = new dg._TableMap(this.view.structure.cells); |
| 324 |
} |
| 325 |
}, |
| 326 |
|
| 327 |
generateHtml: function(inGetValue, inValue){ |
| 328 |
var dir, html = this.getTableArray(), cells = this.view.structure.cells; |
| 329 |
|
| 330 |
util.fire(this.view, "onBeforeRow", [-1, cells]); |
| 331 |
for(var j=0, row; (row=cells[j]); j++){ |
| 332 |
if(row.hidden){ |
| 333 |
continue; |
| 334 |
} |
| 335 |
html.push(!row.invisible ? '<tr>' : '<tr class="dojoxGridInvisible">'); |
| 336 |
for(var i=0, cell, markup; (cell=row[i]); i++){ |
| 337 |
cell.customClasses = []; |
| 338 |
cell.customStyles = []; |
| 339 |
if(this.view.simpleStructure){ |
| 340 |
if(cell.draggable){ |
| 341 |
if(cell.headerClasses){ |
| 342 |
if(cell.headerClasses.indexOf('dojoDndItem') == -1){ |
| 343 |
cell.headerClasses += ' dojoDndItem'; |
| 344 |
} |
| 345 |
}else{ |
| 346 |
cell.headerClasses = 'dojoDndItem'; |
| 347 |
} |
| 348 |
} |
| 349 |
if(cell.attrs){ |
| 350 |
if(cell.attrs.indexOf("dndType='gridColumn_") == -1){ |
| 351 |
cell.attrs += " dndType='gridColumn_" + this.grid.id + "'"; |
| 352 |
} |
| 353 |
}else{ |
| 354 |
cell.attrs = "dndType='gridColumn_" + this.grid.id + "'"; |
| 355 |
} |
| 356 |
} |
| 357 |
markup = this.generateCellMarkup(cell, cell.headerStyles, cell.headerClasses, true); |
| 358 |
|
| 359 |
markup[5] = (inValue != undefined ? inValue : inGetValue(cell)); |
| 360 |
|
| 361 |
markup[3] = cell.customStyles.join(';'); |
| 362 |
dir = cell.textDir || this.grid.textDir; |
| 363 |
if(dir){ |
| 364 |
markup[3] += this._getTextDirStyle(dir, cell, inValue); |
| 365 |
} |
| 366 |
|
| 367 |
markup[1] = cell.customClasses.join(' '); |
| 368 |
html.push(markup.join('')); |
| 369 |
} |
| 370 |
html.push('</tr>'); |
| 371 |
} |
| 372 |
html.push('</table>'); |
| 373 |
return html.join(''); |
| 374 |
}, |
| 375 |
|
| 376 |
|
| 377 |
getCellX: function(e){ |
| 378 |
var n, x, pos; |
| 379 |
|
| 380 |
n = ascendDom(e.target, makeNotTagName("th")); |
| 381 |
if(n){ |
| 382 |
|
| 383 |
pos = domGeometry.position(n); |
| 384 |
x = e.clientX - pos.x; |
| 385 |
}else{ |
| 386 |
|
| 387 |
x = e.layerX; |
| 388 |
} |
| 389 |
return x; |
| 390 |
}, |
| 391 |
|
| 392 |
|
| 393 |
decorateEvent: function(e){ |
| 394 |
this.baseDecorateEvent(e); |
| 395 |
e.rowIndex = -1; |
| 396 |
e.cellX = this.getCellX(e); |
| 397 |
return true; |
| 398 |
}, |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
prepareResize: function(e, mod){ |
| 403 |
do{ |
| 404 |
var i = e.cellIndex; |
| 405 |
e.cellNode = (i ? e.cellNode.parentNode.cells[i+mod] : null); |
| 406 |
e.cellIndex = (e.cellNode ? this.getCellNodeIndex(e.cellNode) : -1); |
| 407 |
}while(e.cellNode && e.cellNode.style.display == "none"); |
| 408 |
return Boolean(e.cellNode); |
| 409 |
}, |
| 410 |
|
| 411 |
canResize: function(e){ |
| 412 |
if(!e.cellNode || e.cellNode.colSpan > 1){ |
| 413 |
return false; |
| 414 |
} |
| 415 |
var cell = this.grid.getCell(e.cellIndex); |
| 416 |
return !cell.noresize && cell.canResize(); |
| 417 |
}, |
| 418 |
|
| 419 |
overLeftResizeArea: function(e){ |
| 420 |
|
| 421 |
if(html.hasClass(win.body(), "dojoDndMove")){ |
| 422 |
return false; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
if(has('ie')){ |
| 429 |
var tN = e.target; |
| 430 |
if(html.hasClass(tN, "dojoxGridArrowButtonNode") || |
| 431 |
html.hasClass(tN, "dojoxGridArrowButtonChar") || |
| 432 |
html.hasClass(tN, "dojoxGridColCaption")){ |
| 433 |
return false; |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
if(this.grid.isLeftToRight()){ |
| 438 |
return (e.cellIndex>0) && (e.cellX > 0 && e.cellX < this.overResizeWidth) && this.prepareResize(e, -1); |
| 439 |
} |
| 440 |
var t = e.cellNode && (e.cellX > 0 && e.cellX < this.overResizeWidth); |
| 441 |
return t; |
| 442 |
}, |
| 443 |
|
| 444 |
overRightResizeArea: function(e){ |
| 445 |
|
| 446 |
if(html.hasClass(win.body(), "dojoDndMove")){ |
| 447 |
return false; |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
if(has('ie')){ |
| 454 |
var tN = e.target; |
| 455 |
if(html.hasClass(tN, "dojoxGridArrowButtonNode") || |
| 456 |
html.hasClass(tN, "dojoxGridArrowButtonChar") || |
| 457 |
html.hasClass(tN, "dojoxGridColCaption")){ |
| 458 |
return false; |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
if(this.grid.isLeftToRight()){ |
| 463 |
return e.cellNode && (e.cellX >= e.cellNode.offsetWidth - this.overResizeWidth); |
| 464 |
} |
| 465 |
return (e.cellIndex>0) && (e.cellX >= e.cellNode.offsetWidth - this.overResizeWidth) && this.prepareResize(e, -1); |
| 466 |
}, |
| 467 |
|
| 468 |
domousemove: function(e){ |
| 469 |
|
| 470 |
if(!this.moveable){ |
| 471 |
var c = (this.overRightResizeArea(e) ? 'dojoxGridColResize' : (this.overLeftResizeArea(e) ? 'dojoxGridColResize' : '')); |
| 472 |
if(c && !this.canResize(e)){ |
| 473 |
c = 'dojoxGridColNoResize'; |
| 474 |
} |
| 475 |
html.toggleClass(e.sourceView.headerNode, "dojoxGridColNoResize", (c == "dojoxGridColNoResize")); |
| 476 |
html.toggleClass(e.sourceView.headerNode, "dojoxGridColResize", (c == "dojoxGridColResize")); |
| 477 |
if(c){ |
| 478 |
event.stop(e); |
| 479 |
} |
| 480 |
} |
| 481 |
}, |
| 482 |
|
| 483 |
domousedown: function(e){ |
| 484 |
if(!this.moveable){ |
| 485 |
if((this.overRightResizeArea(e) || this.overLeftResizeArea(e)) && this.canResize(e)){ |
| 486 |
this.beginColumnResize(e); |
| 487 |
}else{ |
| 488 |
this.grid.onMouseDown(e); |
| 489 |
this.grid.onMouseOverRow(e); |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
} |
| 495 |
}, |
| 496 |
|
| 497 |
doclick: function(e) { |
| 498 |
if(this._skipBogusClicks){ |
| 499 |
event.stop(e); |
| 500 |
return true; |
| 501 |
} |
| 502 |
return false; |
| 503 |
}, |
| 504 |
|
| 505 |
|
| 506 |
colResizeSetup: function(e, isMouse ){ |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
var headContentBox = html.contentBox(e.sourceView.headerNode); |
| 511 |
|
| 512 |
if(isMouse){ |
| 513 |
this.lineDiv = document.createElement('div'); |
| 514 |
|
| 515 |
var vw = html.position(e.sourceView.headerNode, true); |
| 516 |
var bodyContentBox = html.contentBox(e.sourceView.domNode); |
| 517 |
|
| 518 |
var l = e.pageX; |
| 519 |
if(!this.grid.isLeftToRight() && has('ie') < 8){ |
| 520 |
l -= metrics.getScrollbar().w; |
| 521 |
} |
| 522 |
html.style(this.lineDiv, { |
| 523 |
top: vw.y + "px", |
| 524 |
left: l + "px", |
| 525 |
height: (bodyContentBox.h + headContentBox.h) + "px" |
| 526 |
}); |
| 527 |
html.addClass(this.lineDiv, "dojoxGridResizeColLine"); |
| 528 |
this.lineDiv._origLeft = l; |
| 529 |
win.body().appendChild(this.lineDiv); |
| 530 |
} |
| 531 |
var spanners = [], nodes = this.tableMap.findOverlappingNodes(e.cellNode); |
| 532 |
for(var i=0, cell; (cell=nodes[i]); i++){ |
| 533 |
spanners.push({ node: cell, index: this.getCellNodeIndex(cell), width: cell.offsetWidth }); |
| 534 |
|
| 535 |
} |
| 536 |
|
| 537 |
var view = e.sourceView; |
| 538 |
var adj = this.grid.isLeftToRight() ? 1 : -1; |
| 539 |
var views = e.grid.views.views; |
| 540 |
var followers = []; |
| 541 |
for(var j=view.idx+adj, cView; (cView=views[j]); j=j+adj){ |
| 542 |
followers.push({ node: cView.headerNode, left: window.parseInt(cView.headerNode.style.left) }); |
| 543 |
} |
| 544 |
var table = view.headerContentNode.firstChild; |
| 545 |
var drag = { |
| 546 |
scrollLeft: e.sourceView.headerNode.scrollLeft, |
| 547 |
view: view, |
| 548 |
node: e.cellNode, |
| 549 |
index: e.cellIndex, |
| 550 |
w: html.contentBox(e.cellNode).w, |
| 551 |
vw: headContentBox.w, |
| 552 |
table: table, |
| 553 |
tw: html.contentBox(table).w, |
| 554 |
spanners: spanners, |
| 555 |
followers: followers |
| 556 |
}; |
| 557 |
return drag; |
| 558 |
}, |
| 559 |
beginColumnResize: function(e){ |
| 560 |
this.moverDiv = document.createElement("div"); |
| 561 |
html.style(this.moverDiv,{position: "absolute", left:0}); |
| 562 |
win.body().appendChild(this.moverDiv); |
| 563 |
html.addClass(this.grid.domNode, "dojoxGridColumnResizing"); |
| 564 |
var m = (this.moveable = new Moveable(this.moverDiv)); |
| 565 |
|
| 566 |
var drag = this.colResizeSetup(e,true); |
| 567 |
|
| 568 |
m.onMove = lang.hitch(this, "doResizeColumn", drag); |
| 569 |
|
| 570 |
connect.connect(m, "onMoveStop", lang.hitch(this, function(){ |
| 571 |
this.endResizeColumn(drag); |
| 572 |
if(drag.node.releaseCapture){ |
| 573 |
drag.node.releaseCapture(); |
| 574 |
} |
| 575 |
this.moveable.destroy(); |
| 576 |
delete this.moveable; |
| 577 |
this.moveable = null; |
| 578 |
html.removeClass(this.grid.domNode, "dojoxGridColumnResizing"); |
| 579 |
})); |
| 580 |
|
| 581 |
if(e.cellNode.setCapture){ |
| 582 |
e.cellNode.setCapture(); |
| 583 |
} |
| 584 |
m.onMouseDown(e); |
| 585 |
}, |
| 586 |
|
| 587 |
doResizeColumn: function(inDrag, mover, leftTop){ |
| 588 |
var changeX = leftTop.l; |
| 589 |
var data = { |
| 590 |
deltaX: changeX, |
| 591 |
w: inDrag.w + (this.grid.isLeftToRight() ? changeX : -changeX), |
| 592 |
vw: inDrag.vw + changeX, |
| 593 |
tw: inDrag.tw + changeX |
| 594 |
}; |
| 595 |
|
| 596 |
this.dragRecord = {inDrag: inDrag, mover: mover, leftTop:leftTop}; |
| 597 |
|
| 598 |
if(data.w >= this.minColWidth){ |
| 599 |
if (!mover) { |
| 600 |
this.doResizeNow(inDrag, data); |
| 601 |
} |
| 602 |
else{ |
| 603 |
html.style(this.lineDiv, "left", (this.lineDiv._origLeft + data.deltaX) + "px"); |
| 604 |
} |
| 605 |
} |
| 606 |
}, |
| 607 |
|
| 608 |
endResizeColumn: function(inDrag){ |
| 609 |
if(this.dragRecord){ |
| 610 |
var leftTop = this.dragRecord.leftTop; |
| 611 |
var changeX = this.grid.isLeftToRight() ? leftTop.l : -leftTop.l; |
| 612 |
|
| 613 |
|
| 614 |
changeX += Math.max(inDrag.w + changeX, this.minColWidth) - (inDrag.w + changeX); |
| 615 |
if(has('webkit') && inDrag.spanners.length){ |
| 616 |
|
| 617 |
changeX += html._getPadBorderExtents(inDrag.spanners[0].node).w; |
| 618 |
} |
| 619 |
var data = { |
| 620 |
deltaX: changeX, |
| 621 |
w: inDrag.w + changeX, |
| 622 |
vw: inDrag.vw + changeX, |
| 623 |
tw: inDrag.tw + changeX |
| 624 |
}; |
| 625 |
|
| 626 |
this.doResizeNow(inDrag, data); |
| 627 |
delete this.dragRecord; |
| 628 |
} |
| 629 |
|
| 630 |
html.destroy(this.lineDiv); |
| 631 |
html.destroy(this.moverDiv); |
| 632 |
html.destroy(this.moverDiv); |
| 633 |
delete this.moverDiv; |
| 634 |
this._skipBogusClicks = true; |
| 635 |
inDrag.view.update(); |
| 636 |
this._skipBogusClicks = false; |
| 637 |
this.grid.onResizeColumn(inDrag.index); |
| 638 |
}, |
| 639 |
doResizeNow: function(inDrag, data){ |
| 640 |
inDrag.view.convertColPctToFixed(); |
| 641 |
if(inDrag.view.flexCells && !inDrag.view.testFlexCells()){ |
| 642 |
var t = findTable(inDrag.node); |
| 643 |
if(t){ |
| 644 |
(t.style.width = ''); |
| 645 |
} |
| 646 |
} |
| 647 |
var i, s, sw, f, fl; |
| 648 |
for(i=0; (s=inDrag.spanners[i]); i++){ |
| 649 |
sw = s.width + data.deltaX; |
| 650 |
if(sw > 0){ |
| 651 |
s.node.style.width = sw + 'px'; |
| 652 |
inDrag.view.setColWidth(s.index, sw); |
| 653 |
} |
| 654 |
} |
| 655 |
if(this.grid.isLeftToRight() || !has('ie')){ |
| 656 |
for(i=0; (f=inDrag.followers[i]); i++){ |
| 657 |
fl = f.left + data.deltaX; |
| 658 |
f.node.style.left = fl + 'px'; |
| 659 |
} |
| 660 |
} |
| 661 |
inDrag.node.style.width = data.w + 'px'; |
| 662 |
inDrag.view.setColWidth(inDrag.index, data.w); |
| 663 |
inDrag.view.headerNode.style.width = data.vw + 'px'; |
| 664 |
inDrag.view.setColumnsWidth(data.tw); |
| 665 |
if(!this.grid.isLeftToRight()){ |
| 666 |
inDrag.view.headerNode.scrollLeft = inDrag.scrollLeft + data.deltaX; |
| 667 |
} |
| 668 |
} |
| 669 |
}); |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
dg._TableMap = lang.extend(function(rows){ |
| 674 |
this.mapRows(rows); |
| 675 |
},{ |
| 676 |
map: null, |
| 677 |
|
| 678 |
mapRows: function(inRows){ |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
var rowCount = inRows.length; |
| 685 |
if(!rowCount){ |
| 686 |
return; |
| 687 |
} |
| 688 |
|
| 689 |
this.map = []; |
| 690 |
var row; |
| 691 |
for(var k=0; (row=inRows[k]); k++){ |
| 692 |
this.map[k] = []; |
| 693 |
} |
| 694 |
for(var j=0; (row=inRows[j]); j++){ |
| 695 |
for(var i=0, x=0, cell, colSpan, rowSpan; (cell=row[i]); i++){ |
| 696 |
while(this.map[j][x]){x++;} |
| 697 |
this.map[j][x] = { c: i, r: j }; |
| 698 |
rowSpan = cell.rowSpan || 1; |
| 699 |
colSpan = cell.colSpan || 1; |
| 700 |
for(var y=0; y<rowSpan; y++){ |
| 701 |
for(var s=0; s<colSpan; s++){ |
| 702 |
this.map[j+y][x+s] = this.map[j][x]; |
| 703 |
} |
| 704 |
} |
| 705 |
x += colSpan; |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
}, |
| 710 |
|
| 711 |
dumpMap: function(){ |
| 712 |
for(var j=0, row, h=''; (row=this.map[j]); j++,h=''){ |
| 713 |
for(var i=0, cell; (cell=row[i]); i++){ |
| 714 |
h += cell.r + ',' + cell.c + ' '; |
| 715 |
} |
| 716 |
} |
| 717 |
}, |
| 718 |
|
| 719 |
getMapCoords: function(inRow, inCol){ |
| 720 |
|
| 721 |
|
| 722 |
for(var j=0, row; (row=this.map[j]); j++){ |
| 723 |
for(var i=0, cell; (cell=row[i]); i++){ |
| 724 |
if(cell.c==inCol && cell.r == inRow){ |
| 725 |
return { j: j, i: i }; |
| 726 |
} |
| 727 |
|
| 728 |
} |
| 729 |
} |
| 730 |
return { j: -1, i: -1 }; |
| 731 |
}, |
| 732 |
|
| 733 |
getNode: function(inTable, inRow, inCol){ |
| 734 |
|
| 735 |
|
| 736 |
var row = inTable && inTable.rows[inRow]; |
| 737 |
return row && row.cells[inCol]; |
| 738 |
}, |
| 739 |
|
| 740 |
_findOverlappingNodes: function(inTable, inRow, inCol){ |
| 741 |
var nodes = []; |
| 742 |
var m = this.getMapCoords(inRow, inCol); |
| 743 |
|
| 744 |
for(var j=0, row; (row=this.map[j]); j++){ |
| 745 |
if(j == m.j){ continue; } |
| 746 |
var rw = row[m.i]; |
| 747 |
|
| 748 |
var n = (rw?this.getNode(inTable, rw.r, rw.c):null); |
| 749 |
if(n){ nodes.push(n); } |
| 750 |
} |
| 751 |
|
| 752 |
return nodes; |
| 753 |
}, |
| 754 |
|
| 755 |
findOverlappingNodes: function(inNode){ |
| 756 |
return this._findOverlappingNodes(findTable(inNode), getTrIndex(inNode.parentNode), getTdIndex(inNode)); |
| 757 |
} |
| 758 |
}); |
| 759 |
|
| 760 |
return { |
| 761 |
_Builder: _Builder, |
| 762 |
_HeaderBuilder: _HeaderBuilder, |
| 763 |
_ContentBuilder: _ContentBuilder |
| 764 |
}; |
| 765 |
}); |