[483] | 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 | // base class for generating markup for the views |
---|
| 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 | // boilerplate HTML |
---|
| 57 | _table: '<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation"', |
---|
| 58 | |
---|
| 59 | // Returns the table variable as an array - and with the view width, if specified |
---|
| 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 | // generate starting tags for a cell |
---|
| 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 | // column headers are not editable, mark as aria-readonly=true |
---|
| 78 | html = ['<th tabIndex="-1" aria-readonly="true" role="columnheader"', sortInfo, ' id="', inCell.id, '"']; |
---|
| 79 | }else{ |
---|
| 80 | // cells inherit grid aria-readonly property; default value for aria-readonly is false(grid is editable) |
---|
| 81 | // if grid is editable (had any editable cells), mark non editable cells as aria-readonly=true |
---|
| 82 | // if no editable cells, grid's aria-readonly value will have been set to true and cells will inherit |
---|
| 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 | // result[0] => td opener, style |
---|
| 100 | result.push(html.join('')); |
---|
| 101 | // SLOT: result[1] => td classes |
---|
| 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 | // result[2] => markup |
---|
| 112 | result.push(html.join('')); |
---|
| 113 | // SLOT: result[3] => td style |
---|
| 114 | result.push(''); |
---|
| 115 | html = [ '"' ]; |
---|
| 116 | if(inCell.attrs){ |
---|
| 117 | html.push(" ", inCell.attrs); |
---|
| 118 | } |
---|
| 119 | html.push('>'); |
---|
| 120 | // result[4] => td postfix |
---|
| 121 | result.push(html.join('')); |
---|
| 122 | // SLOT: result[5] => content |
---|
| 123 | result.push(''); |
---|
| 124 | // result[6] => td closes |
---|
| 125 | result.push(isHeader?'</th>':'</td>'); |
---|
| 126 | return result; // Array |
---|
| 127 | }, |
---|
| 128 | |
---|
| 129 | // cell finding |
---|
| 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 | // event decoration |
---|
| 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 | // event dispatch |
---|
| 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 | // e.relatedTarget has permission problem in FF if it's an input: https://bugzilla.mozilla.org/show_bug.cgi?id=208427 |
---|
| 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 | // e.relatedTarget on INPUT has permission problem in FF: https://bugzilla.mozilla.org/show_bug.cgi?id=208427 |
---|
| 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 | // dispatched event handlers |
---|
| 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 | // summary: |
---|
| 233 | // Get BiDi text dir, just a placeholder, defined in dojox/grid/bidi/_BidiMixin |
---|
| 234 | return ""; |
---|
| 235 | } |
---|
| 236 | }); |
---|
| 237 | |
---|
| 238 | // Produces html for grid data content. Owned by grid and used internally |
---|
| 239 | // for rendering data. Override to implement custom rendering. |
---|
| 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 | // cache html for rendering data rows |
---|
| 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 | // time critical: generate html using cache and data source |
---|
| 262 | generateHtml: function(inDataIndex, inRowIndex){ |
---|
| 263 | var |
---|
| 264 | html = this.getTableArray(), |
---|
| 265 | v = this.view, dir, |
---|
| 266 | cells = v.structure.cells, |
---|
| 267 | item = this.grid.getItem(inRowIndex); |
---|
| 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; cc = cell.customClasses = []; cs = cell.customStyles = []; |
---|
| 277 | // content (format can fill in cc and cs as side-effects) |
---|
| 278 | m[5] = cell.format(inRowIndex, item); |
---|
| 279 | // classes |
---|
| 280 | m[1] = cc.join(' '); |
---|
| 281 | // styles |
---|
| 282 | m[3] = cs.join(';'); |
---|
| 283 | dir = cell.textDir || this.grid.textDir; |
---|
| 284 | if(dir){ |
---|
| 285 | m[3] += this._getTextDirStyle(dir, cell, inRowIndex); |
---|
| 286 | } |
---|
| 287 | // in-place concat |
---|
| 288 | html.push.apply(html, m); |
---|
| 289 | } |
---|
| 290 | html.push('</tr>'); |
---|
| 291 | } |
---|
| 292 | html.push('</table>'); |
---|
| 293 | return html.join(''); // String |
---|
| 294 | }, |
---|
| 295 | |
---|
| 296 | decorateEvent: function(e){ |
---|
| 297 | e.rowNode = this.findRowTarget(e.target); |
---|
| 298 | if(!e.rowNode){return false;} |
---|
| 299 | e.rowIndex = e.rowNode[rowIndexTag]; |
---|
| 300 | this.baseDecorateEvent(e); |
---|
| 301 | e.cell = this.grid.getCell(e.cellIndex); |
---|
| 302 | return true; // Boolean |
---|
| 303 | } |
---|
| 304 | }); |
---|
| 305 | |
---|
| 306 | // Produces html for grid header content. Owned by grid and used internally |
---|
| 307 | // for rendering data. Override to implement custom rendering. |
---|
| 308 | var _HeaderBuilder = dg._HeaderBuilder = lang.extend(function(view){ |
---|
| 309 | this.moveable = null; |
---|
| 310 | _Builder.call(this, view); |
---|
| 311 | },_Builder.prototype,{ |
---|
| 312 | _skipBogusClicks: false, |
---|
| 313 | overResizeWidth: 4, |
---|
| 314 | minColWidth: 1, |
---|
| 315 | |
---|
| 316 | update: function(){ |
---|
| 317 | if(this.tableMap){ |
---|
| 318 | this.tableMap.mapRows(this.view.structure.cells); |
---|
| 319 | }else{ |
---|
| 320 | this.tableMap = new dg._TableMap(this.view.structure.cells); |
---|
| 321 | } |
---|
| 322 | }, |
---|
| 323 | |
---|
| 324 | generateHtml: function(inGetValue, inValue){ |
---|
| 325 | var dir, html = this.getTableArray(), cells = this.view.structure.cells; |
---|
| 326 | |
---|
| 327 | util.fire(this.view, "onBeforeRow", [-1, cells]); |
---|
| 328 | for(var j=0, row; (row=cells[j]); j++){ |
---|
| 329 | if(row.hidden){ |
---|
| 330 | continue; |
---|
| 331 | } |
---|
| 332 | html.push(!row.invisible ? '<tr>' : '<tr class="dojoxGridInvisible">'); |
---|
| 333 | for(var i=0, cell, markup; (cell=row[i]); i++){ |
---|
| 334 | cell.customClasses = []; |
---|
| 335 | cell.customStyles = []; |
---|
| 336 | if(this.view.simpleStructure){ |
---|
| 337 | if(cell.draggable){ |
---|
| 338 | if(cell.headerClasses){ |
---|
| 339 | if(cell.headerClasses.indexOf('dojoDndItem') == -1){ |
---|
| 340 | cell.headerClasses += ' dojoDndItem'; |
---|
| 341 | } |
---|
| 342 | }else{ |
---|
| 343 | cell.headerClasses = 'dojoDndItem'; |
---|
| 344 | } |
---|
| 345 | } |
---|
| 346 | if(cell.attrs){ |
---|
| 347 | if(cell.attrs.indexOf("dndType='gridColumn_") == -1){ |
---|
| 348 | cell.attrs += " dndType='gridColumn_" + this.grid.id + "'"; |
---|
| 349 | } |
---|
| 350 | }else{ |
---|
| 351 | cell.attrs = "dndType='gridColumn_" + this.grid.id + "'"; |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | markup = this.generateCellMarkup(cell, cell.headerStyles, cell.headerClasses, true); |
---|
| 355 | // content |
---|
| 356 | markup[5] = (inValue != undefined ? inValue : inGetValue(cell)); |
---|
| 357 | // styles |
---|
| 358 | markup[3] = cell.customStyles.join(';'); |
---|
| 359 | dir = cell.textDir || this.grid.textDir; |
---|
| 360 | if(dir){ |
---|
| 361 | markup[3] += this._getTextDirStyle(dir, cell, inValue); |
---|
| 362 | } |
---|
| 363 | // classes |
---|
| 364 | markup[1] = cell.customClasses.join(' '); //(cell.customClasses ? ' ' + cell.customClasses : ''); |
---|
| 365 | html.push(markup.join('')); |
---|
| 366 | } |
---|
| 367 | html.push('</tr>'); |
---|
| 368 | } |
---|
| 369 | html.push('</table>'); |
---|
| 370 | return html.join(''); |
---|
| 371 | }, |
---|
| 372 | |
---|
| 373 | // event helpers |
---|
| 374 | getCellX: function(e){ |
---|
| 375 | var n, x, pos; |
---|
| 376 | // Calculate starting x position |
---|
| 377 | n = ascendDom(e.target, makeNotTagName("th")); |
---|
| 378 | if(n){ |
---|
| 379 | // We have a proper parent node, use that for position |
---|
| 380 | pos = domGeometry.position(n); |
---|
| 381 | x = e.clientX - pos.x; |
---|
| 382 | }else{ |
---|
| 383 | // Fall back to layerX |
---|
| 384 | x = e.layerX; |
---|
| 385 | } |
---|
| 386 | return x; |
---|
| 387 | }, |
---|
| 388 | |
---|
| 389 | // event decoration |
---|
| 390 | decorateEvent: function(e){ |
---|
| 391 | this.baseDecorateEvent(e); |
---|
| 392 | e.rowIndex = -1; |
---|
| 393 | e.cellX = this.getCellX(e); |
---|
| 394 | return true; |
---|
| 395 | }, |
---|
| 396 | |
---|
| 397 | // event handlers |
---|
| 398 | // resizing |
---|
| 399 | prepareResize: function(e, mod){ |
---|
| 400 | do{ |
---|
| 401 | var i = e.cellIndex; |
---|
| 402 | e.cellNode = (i ? e.cellNode.parentNode.cells[i+mod] : null); |
---|
| 403 | e.cellIndex = (e.cellNode ? this.getCellNodeIndex(e.cellNode) : -1); |
---|
| 404 | }while(e.cellNode && e.cellNode.style.display == "none"); |
---|
| 405 | return Boolean(e.cellNode); |
---|
| 406 | }, |
---|
| 407 | |
---|
| 408 | canResize: function(e){ |
---|
| 409 | if(!e.cellNode || e.cellNode.colSpan > 1){ |
---|
| 410 | return false; |
---|
| 411 | } |
---|
| 412 | var cell = this.grid.getCell(e.cellIndex); |
---|
| 413 | return !cell.noresize && cell.canResize(); |
---|
| 414 | }, |
---|
| 415 | |
---|
| 416 | overLeftResizeArea: function(e){ |
---|
| 417 | // We are never over a resize area if we are in the process of moving |
---|
| 418 | if(html.hasClass(win.body(), "dojoDndMove")){ |
---|
| 419 | return false; |
---|
| 420 | } |
---|
| 421 | //Bugfix for crazy IE problem (#8807). IE returns position information for the icon and text arrow divs |
---|
| 422 | //as if they were still on the left instead of returning the position they were 'float: right' to. |
---|
| 423 | //So, the resize check ends up checking the wrong adjacent cell. This checks to see if the hover was over |
---|
| 424 | //the image or text nodes, then just ignored them/treat them not in scale range. |
---|
| 425 | if(has('ie')){ |
---|
| 426 | var tN = e.target; |
---|
| 427 | if(html.hasClass(tN, "dojoxGridArrowButtonNode") || |
---|
| 428 | html.hasClass(tN, "dojoxGridArrowButtonChar") || |
---|
| 429 | html.hasClass(tN, "dojoxGridColCaption")){ |
---|
| 430 | return false; |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | if(this.grid.isLeftToRight()){ |
---|
| 435 | return (e.cellIndex>0) && (e.cellX > 0 && e.cellX < this.overResizeWidth) && this.prepareResize(e, -1); |
---|
| 436 | } |
---|
| 437 | var t = e.cellNode && (e.cellX > 0 && e.cellX < this.overResizeWidth); |
---|
| 438 | return t; |
---|
| 439 | }, |
---|
| 440 | |
---|
| 441 | overRightResizeArea: function(e){ |
---|
| 442 | // We are never over a resize area if we are in the process of moving |
---|
| 443 | if(html.hasClass(win.body(), "dojoDndMove")){ |
---|
| 444 | return false; |
---|
| 445 | } |
---|
| 446 | //Bugfix for crazy IE problem (#8807). IE returns position information for the icon and text arrow divs |
---|
| 447 | //as if they were still on the left instead of returning the position they were 'float: right' to. |
---|
| 448 | //So, the resize check ends up checking the wrong adjacent cell. This checks to see if the hover was over |
---|
| 449 | //the image or text nodes, then just ignored them/treat them not in scale range. |
---|
| 450 | if(has('ie')){ |
---|
| 451 | var tN = e.target; |
---|
| 452 | if(html.hasClass(tN, "dojoxGridArrowButtonNode") || |
---|
| 453 | html.hasClass(tN, "dojoxGridArrowButtonChar") || |
---|
| 454 | html.hasClass(tN, "dojoxGridColCaption")){ |
---|
| 455 | return false; |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | if(this.grid.isLeftToRight()){ |
---|
| 460 | return e.cellNode && (e.cellX >= e.cellNode.offsetWidth - this.overResizeWidth); |
---|
| 461 | } |
---|
| 462 | return (e.cellIndex>0) && (e.cellX >= e.cellNode.offsetWidth - this.overResizeWidth) && this.prepareResize(e, -1); |
---|
| 463 | }, |
---|
| 464 | |
---|
| 465 | domousemove: function(e){ |
---|
| 466 | //console.log(e.cellIndex, e.cellX, e.cellNode.offsetWidth); |
---|
| 467 | if(!this.moveable){ |
---|
| 468 | var c = (this.overRightResizeArea(e) ? 'dojoxGridColResize' : (this.overLeftResizeArea(e) ? 'dojoxGridColResize' : '')); |
---|
| 469 | if(c && !this.canResize(e)){ |
---|
| 470 | c = 'dojoxGridColNoResize'; |
---|
| 471 | } |
---|
| 472 | html.toggleClass(e.sourceView.headerNode, "dojoxGridColNoResize", (c == "dojoxGridColNoResize")); |
---|
| 473 | html.toggleClass(e.sourceView.headerNode, "dojoxGridColResize", (c == "dojoxGridColResize")); |
---|
| 474 | if(c){ |
---|
| 475 | event.stop(e); |
---|
| 476 | } |
---|
| 477 | } |
---|
| 478 | }, |
---|
| 479 | |
---|
| 480 | domousedown: function(e){ |
---|
| 481 | if(!this.moveable){ |
---|
| 482 | if((this.overRightResizeArea(e) || this.overLeftResizeArea(e)) && this.canResize(e)){ |
---|
| 483 | this.beginColumnResize(e); |
---|
| 484 | }else{ |
---|
| 485 | this.grid.onMouseDown(e); |
---|
| 486 | this.grid.onMouseOverRow(e); |
---|
| 487 | } |
---|
| 488 | //else{ |
---|
| 489 | // this.beginMoveColumn(e); |
---|
| 490 | //} |
---|
| 491 | } |
---|
| 492 | }, |
---|
| 493 | |
---|
| 494 | doclick: function(e) { |
---|
| 495 | if(this._skipBogusClicks){ |
---|
| 496 | event.stop(e); |
---|
| 497 | return true; |
---|
| 498 | } |
---|
| 499 | return false; |
---|
| 500 | }, |
---|
| 501 | |
---|
| 502 | // column resizing |
---|
| 503 | colResizeSetup: function(/*Event Object*/e, /*boolean*/ isMouse ){ |
---|
| 504 | //Set up the drag object for column resizing |
---|
| 505 | // Called with mouse event in case of drag and drop, |
---|
| 506 | // Also called from keyboard shift-arrow event when focus is on a header |
---|
| 507 | var headContentBox = html.contentBox(e.sourceView.headerNode); |
---|
| 508 | |
---|
| 509 | if(isMouse){ //IE draws line even with no mouse down so separate from keyboard |
---|
| 510 | this.lineDiv = document.createElement('div'); |
---|
| 511 | |
---|
| 512 | var vw = html.position(e.sourceView.headerNode, true); |
---|
| 513 | var bodyContentBox = html.contentBox(e.sourceView.domNode); |
---|
| 514 | //fix #11340 |
---|
| 515 | var l = e.pageX; |
---|
| 516 | if(!this.grid.isLeftToRight() && has('ie') < 8){ |
---|
| 517 | l -= metrics.getScrollbar().w; |
---|
| 518 | } |
---|
| 519 | html.style(this.lineDiv, { |
---|
| 520 | top: vw.y + "px", |
---|
| 521 | left: l + "px", |
---|
| 522 | height: (bodyContentBox.h + headContentBox.h) + "px" |
---|
| 523 | }); |
---|
| 524 | html.addClass(this.lineDiv, "dojoxGridResizeColLine"); |
---|
| 525 | this.lineDiv._origLeft = l; |
---|
| 526 | win.body().appendChild(this.lineDiv); |
---|
| 527 | } |
---|
| 528 | var spanners = [], nodes = this.tableMap.findOverlappingNodes(e.cellNode); |
---|
| 529 | for(var i=0, cell; (cell=nodes[i]); i++){ |
---|
| 530 | spanners.push({ node: cell, index: this.getCellNodeIndex(cell), width: cell.offsetWidth }); |
---|
| 531 | //console.log("spanner: " + this.getCellNodeIndex(cell)); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | var view = e.sourceView; |
---|
| 535 | var adj = this.grid.isLeftToRight() ? 1 : -1; |
---|
| 536 | var views = e.grid.views.views; |
---|
| 537 | var followers = []; |
---|
| 538 | for(var j=view.idx+adj, cView; (cView=views[j]); j=j+adj){ |
---|
| 539 | followers.push({ node: cView.headerNode, left: window.parseInt(cView.headerNode.style.left) }); |
---|
| 540 | } |
---|
| 541 | var table = view.headerContentNode.firstChild; |
---|
| 542 | var drag = { |
---|
| 543 | scrollLeft: e.sourceView.headerNode.scrollLeft, |
---|
| 544 | view: view, |
---|
| 545 | node: e.cellNode, |
---|
| 546 | index: e.cellIndex, |
---|
| 547 | w: html.contentBox(e.cellNode).w, |
---|
| 548 | vw: headContentBox.w, |
---|
| 549 | table: table, |
---|
| 550 | tw: html.contentBox(table).w, |
---|
| 551 | spanners: spanners, |
---|
| 552 | followers: followers |
---|
| 553 | }; |
---|
| 554 | return drag; |
---|
| 555 | }, |
---|
| 556 | beginColumnResize: function(e){ |
---|
| 557 | this.moverDiv = document.createElement("div"); |
---|
| 558 | html.style(this.moverDiv,{position: "absolute", left:0}); // to make DnD work with dir=rtl |
---|
| 559 | win.body().appendChild(this.moverDiv); |
---|
| 560 | html.addClass(this.grid.domNode, "dojoxGridColumnResizing"); |
---|
| 561 | var m = (this.moveable = new Moveable(this.moverDiv)); |
---|
| 562 | |
---|
| 563 | var drag = this.colResizeSetup(e,true); |
---|
| 564 | |
---|
| 565 | m.onMove = lang.hitch(this, "doResizeColumn", drag); |
---|
| 566 | |
---|
| 567 | connect.connect(m, "onMoveStop", lang.hitch(this, function(){ |
---|
| 568 | this.endResizeColumn(drag); |
---|
| 569 | if(drag.node.releaseCapture){ |
---|
| 570 | drag.node.releaseCapture(); |
---|
| 571 | } |
---|
| 572 | this.moveable.destroy(); |
---|
| 573 | delete this.moveable; |
---|
| 574 | this.moveable = null; |
---|
| 575 | html.removeClass(this.grid.domNode, "dojoxGridColumnResizing"); |
---|
| 576 | })); |
---|
| 577 | |
---|
| 578 | if(e.cellNode.setCapture){ |
---|
| 579 | e.cellNode.setCapture(); |
---|
| 580 | } |
---|
| 581 | m.onMouseDown(e); |
---|
| 582 | }, |
---|
| 583 | |
---|
| 584 | doResizeColumn: function(inDrag, mover, leftTop){ |
---|
| 585 | var changeX = leftTop.l; |
---|
| 586 | var data = { |
---|
| 587 | deltaX: changeX, |
---|
| 588 | w: inDrag.w + (this.grid.isLeftToRight() ? changeX : -changeX),//fix #11341 |
---|
| 589 | vw: inDrag.vw + changeX, |
---|
| 590 | tw: inDrag.tw + changeX |
---|
| 591 | }; |
---|
| 592 | |
---|
| 593 | this.dragRecord = {inDrag: inDrag, mover: mover, leftTop:leftTop}; |
---|
| 594 | |
---|
| 595 | if(data.w >= this.minColWidth){ |
---|
| 596 | if (!mover) { // we are using keyboard do immediate resize |
---|
| 597 | this.doResizeNow(inDrag, data); |
---|
| 598 | } |
---|
| 599 | else{ |
---|
| 600 | html.style(this.lineDiv, "left", (this.lineDiv._origLeft + data.deltaX) + "px"); |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | }, |
---|
| 604 | |
---|
| 605 | endResizeColumn: function(inDrag){ |
---|
| 606 | if(this.dragRecord){ |
---|
| 607 | var leftTop = this.dragRecord.leftTop; |
---|
| 608 | var changeX = this.grid.isLeftToRight() ? leftTop.l : -leftTop.l; |
---|
| 609 | // Make sure we are not under our minimum |
---|
| 610 | // http://bugs.dojotoolkit.org/ticket/9390 |
---|
| 611 | changeX += Math.max(inDrag.w + changeX, this.minColWidth) - (inDrag.w + changeX); |
---|
| 612 | if(has('webkit') && inDrag.spanners.length){ |
---|
| 613 | // Webkit needs the pad border extents back in |
---|
| 614 | changeX += html._getPadBorderExtents(inDrag.spanners[0].node).w; |
---|
| 615 | } |
---|
| 616 | var data = { |
---|
| 617 | deltaX: changeX, |
---|
| 618 | w: inDrag.w + changeX, |
---|
| 619 | vw: inDrag.vw + changeX, |
---|
| 620 | tw: inDrag.tw + changeX |
---|
| 621 | }; |
---|
| 622 | // Only resize the columns when the drag has finished |
---|
| 623 | this.doResizeNow(inDrag, data); |
---|
| 624 | delete this.dragRecord; |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | html.destroy(this.lineDiv); |
---|
| 628 | html.destroy(this.moverDiv); |
---|
| 629 | html.destroy(this.moverDiv); |
---|
| 630 | delete this.moverDiv; |
---|
| 631 | this._skipBogusClicks = true; |
---|
| 632 | inDrag.view.update(); |
---|
| 633 | this._skipBogusClicks = false; |
---|
| 634 | this.grid.onResizeColumn(inDrag.index); |
---|
| 635 | }, |
---|
| 636 | doResizeNow: function(inDrag, data){ |
---|
| 637 | inDrag.view.convertColPctToFixed(); |
---|
| 638 | if(inDrag.view.flexCells && !inDrag.view.testFlexCells()){ |
---|
| 639 | var t = findTable(inDrag.node); |
---|
| 640 | if(t){ |
---|
| 641 | (t.style.width = ''); |
---|
| 642 | } |
---|
| 643 | } |
---|
| 644 | var i, s, sw, f, fl; |
---|
| 645 | for(i=0; (s=inDrag.spanners[i]); i++){ |
---|
| 646 | sw = s.width + data.deltaX; |
---|
| 647 | if(sw > 0){ |
---|
| 648 | s.node.style.width = sw + 'px'; |
---|
| 649 | inDrag.view.setColWidth(s.index, sw); |
---|
| 650 | } |
---|
| 651 | } |
---|
| 652 | if(this.grid.isLeftToRight() || !has('ie')){//fix #11339 |
---|
| 653 | for(i=0; (f=inDrag.followers[i]); i++){ |
---|
| 654 | fl = f.left + data.deltaX; |
---|
| 655 | f.node.style.left = fl + 'px'; |
---|
| 656 | } |
---|
| 657 | } |
---|
| 658 | inDrag.node.style.width = data.w + 'px'; |
---|
| 659 | inDrag.view.setColWidth(inDrag.index, data.w); |
---|
| 660 | inDrag.view.headerNode.style.width = data.vw + 'px'; |
---|
| 661 | inDrag.view.setColumnsWidth(data.tw); |
---|
| 662 | if(!this.grid.isLeftToRight()){ |
---|
| 663 | inDrag.view.headerNode.scrollLeft = inDrag.scrollLeft + data.deltaX; |
---|
| 664 | } |
---|
| 665 | } |
---|
| 666 | }); |
---|
| 667 | |
---|
| 668 | // Maps an html table into a structure parsable for information about cell row and col spanning. |
---|
| 669 | // Used by HeaderBuilder. |
---|
| 670 | dg._TableMap = lang.extend(function(rows){ |
---|
| 671 | this.mapRows(rows); |
---|
| 672 | },{ |
---|
| 673 | map: null, |
---|
| 674 | |
---|
| 675 | mapRows: function(inRows){ |
---|
| 676 | // summary: |
---|
| 677 | // Map table topography |
---|
| 678 | |
---|
| 679 | //console.log('mapRows'); |
---|
| 680 | // # of rows |
---|
| 681 | var rowCount = inRows.length; |
---|
| 682 | if(!rowCount){ |
---|
| 683 | return; |
---|
| 684 | } |
---|
| 685 | // map which columns and rows fill which cells |
---|
| 686 | this.map = []; |
---|
| 687 | var row; |
---|
| 688 | for(var k=0; (row=inRows[k]); k++){ |
---|
| 689 | this.map[k] = []; |
---|
| 690 | } |
---|
| 691 | for(var j=0; (row=inRows[j]); j++){ |
---|
| 692 | for(var i=0, x=0, cell, colSpan, rowSpan; (cell=row[i]); i++){ |
---|
| 693 | while(this.map[j][x]){x++;} |
---|
| 694 | this.map[j][x] = { c: i, r: j }; |
---|
| 695 | rowSpan = cell.rowSpan || 1; |
---|
| 696 | colSpan = cell.colSpan || 1; |
---|
| 697 | for(var y=0; y<rowSpan; y++){ |
---|
| 698 | for(var s=0; s<colSpan; s++){ |
---|
| 699 | this.map[j+y][x+s] = this.map[j][x]; |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | x += colSpan; |
---|
| 703 | } |
---|
| 704 | } |
---|
| 705 | //this.dumMap(); |
---|
| 706 | }, |
---|
| 707 | |
---|
| 708 | dumpMap: function(){ |
---|
| 709 | for(var j=0, row, h=''; (row=this.map[j]); j++,h=''){ |
---|
| 710 | for(var i=0, cell; (cell=row[i]); i++){ |
---|
| 711 | h += cell.r + ',' + cell.c + ' '; |
---|
| 712 | } |
---|
| 713 | } |
---|
| 714 | }, |
---|
| 715 | |
---|
| 716 | getMapCoords: function(inRow, inCol){ |
---|
| 717 | // summary: |
---|
| 718 | // Find node's map coords by it's structure coords |
---|
| 719 | for(var j=0, row; (row=this.map[j]); j++){ |
---|
| 720 | for(var i=0, cell; (cell=row[i]); i++){ |
---|
| 721 | if(cell.c==inCol && cell.r == inRow){ |
---|
| 722 | return { j: j, i: i }; |
---|
| 723 | } |
---|
| 724 | //else{console.log(inRow, inCol, ' : ', i, j, " : ", cell.r, cell.c); }; |
---|
| 725 | } |
---|
| 726 | } |
---|
| 727 | return { j: -1, i: -1 }; |
---|
| 728 | }, |
---|
| 729 | |
---|
| 730 | getNode: function(inTable, inRow, inCol){ |
---|
| 731 | // summary: |
---|
| 732 | // Find a node in inNode's table with the given structure coords |
---|
| 733 | var row = inTable && inTable.rows[inRow]; |
---|
| 734 | return row && row.cells[inCol]; |
---|
| 735 | }, |
---|
| 736 | |
---|
| 737 | _findOverlappingNodes: function(inTable, inRow, inCol){ |
---|
| 738 | var nodes = []; |
---|
| 739 | var m = this.getMapCoords(inRow, inCol); |
---|
| 740 | //console.log("node j: %d, i: %d", m.j, m.i); |
---|
| 741 | for(var j=0, row; (row=this.map[j]); j++){ |
---|
| 742 | if(j == m.j){ continue; } |
---|
| 743 | var rw = row[m.i]; |
---|
| 744 | //console.log("overlaps: r: %d, c: %d", rw.r, rw.c); |
---|
| 745 | var n = (rw?this.getNode(inTable, rw.r, rw.c):null); |
---|
| 746 | if(n){ nodes.push(n); } |
---|
| 747 | } |
---|
| 748 | //console.log(nodes); |
---|
| 749 | return nodes; |
---|
| 750 | }, |
---|
| 751 | |
---|
| 752 | findOverlappingNodes: function(inNode){ |
---|
| 753 | return this._findOverlappingNodes(findTable(inNode), getTrIndex(inNode.parentNode), getTdIndex(inNode)); |
---|
| 754 | } |
---|
| 755 | }); |
---|
| 756 | |
---|
| 757 | return { |
---|
| 758 | _Builder: _Builder, |
---|
| 759 | _HeaderBuilder: _HeaderBuilder, |
---|
| 760 | _ContentBuilder: _ContentBuilder |
---|
| 761 | }; |
---|
| 762 | }); |
---|