Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

143 lignes
3.5 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. /*
  4. + Layout
  5. + wrapper
  6. + LayoutRow
  7. + main_head
  8. + main_body
  9. + header
  10. + body
  11. ..
  12. ..
  13. + subrows
  14. */
  15. function Layout(parent, width) {
  16. if(parent&&parent.substr) { parent = $i(parent); }
  17. this.wrapper = $a(parent, 'div', '', {display:'none'});
  18. if(width) {
  19. this.width = this.wrapper.style.width;
  20. }
  21. this.myrows = [];
  22. }
  23. Layout.prototype.addrow = function() {
  24. this.cur_row = new LayoutRow(this, this.wrapper);
  25. this.myrows[this.myrows.length] = this.cur_row;
  26. return this.cur_row
  27. }
  28. Layout.prototype.addsubrow = function() {
  29. this.cur_row = new LayoutRow(this, this.cur_row.main_body);
  30. this.myrows[this.myrows.length] = this.cur_row;
  31. return this.cur_row
  32. }
  33. Layout.prototype.addcell = function(width) {
  34. return this.cur_row.addCell(width);
  35. }
  36. Layout.prototype.setcolour = function(col) { $bg(cc,col); }
  37. Layout.prototype.show = function() { $ds(this.wrapper); }
  38. Layout.prototype.hide = function() { $dh(this.wrapper); }
  39. Layout.prototype.close_borders = function() {
  40. if(this.with_border) {
  41. this.myrows[this.myrows.length-1].wrapper.style.borderBottom = '1px solid #000';
  42. }
  43. }
  44. function LayoutRow(layout, parent) {
  45. this.layout = layout;
  46. this.wrapper = $a(parent,'div','form-layout-row');
  47. // main head
  48. this.main_head = $a(this.wrapper, 'div');
  49. // main head
  50. this.main_body = $a(this.wrapper, 'div');
  51. if(layout.with_border) {
  52. this.wrapper.style.border = '1px solid #000';
  53. this.wrapper.style.borderBottom = '0px';
  54. }
  55. this.header = $a(this.main_body, 'div','',{padding:(layout.with_border ? '0px 8px' : '0px')});
  56. this.body = $a(this.main_body,'div');
  57. this.table = $a(this.body, 'table', '', {width:'100%', borderCollapse: 'collapse', tableLayout:'fixed'});
  58. this.row = this.table.insertRow(0);
  59. this.mycells = [];
  60. }
  61. LayoutRow.prototype.hide = function() { $dh(this.wrapper); }
  62. LayoutRow.prototype.show = function() { $ds(this.wrapper); }
  63. LayoutRow.prototype.addCell = function(wid) {
  64. var lc = new LayoutCell(this.layout, this, wid);
  65. this.mycells[this.mycells.length] = lc;
  66. return lc;
  67. }
  68. function LayoutCell(layout, layoutRow, width) {
  69. if(width) { // add '%' if user has forgotten
  70. var w = width + '';
  71. if(w.substr(w.length-2, 2) != 'px') {
  72. if(w.substr(w.length-1, 1) != "%") {width = width + '%'};
  73. }
  74. }
  75. this.width = width;
  76. this.layout = layout;
  77. var cidx = layoutRow.row.cells.length;
  78. this.cell = layoutRow.row.insertCell(cidx);
  79. this.cell.style.verticalAlign = 'top';
  80. this.set_width(layoutRow.row, width);
  81. var h = $a(this.cell, 'div','',{padding:(layout.with_border ? '0px 8px' : '0px')});
  82. this.wrapper = $a(this.cell, 'div','',{padding:(layout.with_border ? '8px' : '0px')});
  83. layout.cur_cell = this.wrapper;
  84. layout.cur_cell.header = h;
  85. }
  86. // evenly distribute columns
  87. LayoutCell.prototype.set_width = function(row, width) {
  88. var w = 100;
  89. var n_cells = row.cells.length;
  90. var cells_with_no_width = n_cells;
  91. // current cell
  92. if(width) {
  93. $y(row.cells[n_cells-1], {width: cint(width) + '%'})
  94. } else {
  95. row.cells[n_cells-1].estimated_width = 1;
  96. }
  97. // get user specified width
  98. for(var i=0; i<n_cells; i++) {
  99. if(!row.cells[i].estimated_width) {
  100. w = w - cint(row.cells[i].style.width);
  101. cells_with_no_width--;
  102. }
  103. }
  104. // evenly distribute all
  105. for(var i=0; i<n_cells; i++) {
  106. if(row.cells[i].estimated_width)
  107. $y(row.cells[i], {width:cint(w/cells_with_no_width) + '%'})
  108. }
  109. }
  110. LayoutCell.prototype.show = function() { $ds(this.wrapper); }
  111. LayoutCell.prototype.hide = function() { $dh(this.wrapper); }