76890346d05cb3506a7231a9ae1f9454f5b947d3.svn-base 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. if (!dojo._hasResource["dojox.grid._grid.layout"]) { // _hasResource checks
  2. // added by build. Do
  3. // not use _hasResource
  4. // directly in your
  5. // code.
  6. dojo._hasResource["dojox.grid._grid.layout"] = true;
  7. dojo.provide("dojox.grid._grid.layout");
  8. dojo.require("dojox.grid._grid.cell");
  9. dojo.declare("dojox.grid.layout", null, {
  10. // summary:
  11. // Controls grid cell layout. Owned by grid and used internally.
  12. constructor : function(inGrid) {
  13. this.grid = inGrid;
  14. },
  15. // flat array of grid cells
  16. cells : null,
  17. // structured array of grid cells
  18. structure : null,
  19. // default cell width
  20. defaultWidth : '6em',
  21. // methods
  22. setStructure : function(inStructure) {
  23. this.fieldIndex = 0;
  24. this.cells = [];
  25. var s = this.structure = [];
  26. for (var i = 0, viewDef, rows; (viewDef = inStructure[i]); i++) {
  27. s.push(this.addViewDef(viewDef));
  28. }
  29. this.cellCount = this.cells.length;
  30. },
  31. addViewDef : function(inDef) {
  32. this._defaultCellProps = inDef.defaultCell || {};
  33. return dojo.mixin({}, inDef, {
  34. rows : this.addRowsDef(inDef.rows
  35. || inDef.cells)
  36. });
  37. },
  38. addRowsDef : function(inDef) {
  39. var result = [];
  40. for (var i = 0, row; inDef && (row = inDef[i]); i++) {
  41. result.push(this.addRowDef(i, row));
  42. }
  43. return result;
  44. },
  45. addRowDef : function(inRowIndex, inDef) {
  46. var result = [];
  47. for (var i = 0, def, cell; (def = inDef[i]); i++) {
  48. cell = this.addCellDef(inRowIndex, i, def);
  49. result.push(cell);
  50. this.cells.push(cell);
  51. }
  52. return result;
  53. },
  54. addCellDef : function(inRowIndex, inCellIndex, inDef) {
  55. var w = 0;
  56. if (inDef.colSpan > 1) {
  57. w = 0;
  58. } else if (!isNaN(inDef.width)) {
  59. w = inDef.width + "em";
  60. } else {
  61. w = inDef.width || this.defaultWidth;
  62. }
  63. // fieldIndex progresses linearly from the last indexed
  64. // field
  65. // FIXME: support generating fieldIndex based a text field
  66. // name (probably in Grid)
  67. var fieldIndex = inDef.field != undefined
  68. ? inDef.field
  69. : (inDef.get ? -1 : this.fieldIndex);
  70. if ((inDef.field != undefined) || !inDef.get) {
  71. this.fieldIndex = (inDef.field > -1
  72. ? inDef.field
  73. : this.fieldIndex)
  74. + 1;
  75. }
  76. return new dojox.grid.cell(dojo.mixin({},
  77. this._defaultCellProps, inDef, {
  78. grid : this.grid,
  79. subrow : inRowIndex,
  80. layoutIndex : inCellIndex,
  81. index : this.cells.length,
  82. fieldIndex : fieldIndex,
  83. unitWidth : w
  84. }));
  85. }
  86. });
  87. }