Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

162 rindas
4.6 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. /*
  23. + Layout
  24. + wrapper
  25. + LayoutRow
  26. + main_head
  27. + main_body
  28. + header
  29. + body
  30. ..
  31. ..
  32. + subrows
  33. */
  34. function Layout(parent, width) {
  35. if(parent&&parent.substr) { parent = $i(parent); }
  36. this.wrapper = $a(parent, 'div', '', {display:'none'});
  37. if(width) {
  38. this.width = this.wrapper.style.width;
  39. }
  40. this.myrows = [];
  41. }
  42. Layout.prototype.addrow = function() {
  43. this.cur_row = new LayoutRow(this, this.wrapper);
  44. this.myrows[this.myrows.length] = this.cur_row;
  45. return this.cur_row
  46. }
  47. Layout.prototype.addsubrow = function() {
  48. this.cur_row = new LayoutRow(this, this.cur_row.main_body);
  49. this.myrows[this.myrows.length] = this.cur_row;
  50. return this.cur_row
  51. }
  52. Layout.prototype.addcell = function(width) {
  53. return this.cur_row.addCell(width);
  54. }
  55. Layout.prototype.setcolour = function(col) { $bg(cc,col); }
  56. Layout.prototype.show = function() { $ds(this.wrapper); }
  57. Layout.prototype.hide = function() { $dh(this.wrapper); }
  58. Layout.prototype.close_borders = function() {
  59. if(this.with_border) {
  60. this.myrows[this.myrows.length-1].wrapper.style.borderBottom = '1px solid #000';
  61. }
  62. }
  63. function LayoutRow(layout, parent) {
  64. this.layout = layout;
  65. this.wrapper = $a(parent,'div','form-layout-row');
  66. // main head
  67. this.main_head = $a(this.wrapper, 'div');
  68. // main head
  69. this.main_body = $a(this.wrapper, 'div');
  70. if(layout.with_border) {
  71. this.wrapper.style.border = '1px solid #000';
  72. this.wrapper.style.borderBottom = '0px';
  73. }
  74. this.header = $a(this.main_body, 'div','',{padding:(layout.with_border ? '0px 8px' : '0px')});
  75. this.body = $a(this.main_body,'div');
  76. this.table = $a(this.body, 'table', '', {width:'100%', borderCollapse: 'collapse', tableLayout:'fixed'});
  77. this.row = this.table.insertRow(0);
  78. this.mycells = [];
  79. }
  80. LayoutRow.prototype.hide = function() { $dh(this.wrapper); }
  81. LayoutRow.prototype.show = function() { $ds(this.wrapper); }
  82. LayoutRow.prototype.addCell = function(wid) {
  83. var lc = new LayoutCell(this.layout, this, wid);
  84. this.mycells[this.mycells.length] = lc;
  85. return lc;
  86. }
  87. function LayoutCell(layout, layoutRow, width) {
  88. if(width) { // add '%' if user has forgotten
  89. var w = width + '';
  90. if(w.substr(w.length-2, 2) != 'px') {
  91. if(w.substr(w.length-1, 1) != "%") {width = width + '%'};
  92. }
  93. }
  94. this.width = width;
  95. this.layout = layout;
  96. var cidx = layoutRow.row.cells.length;
  97. this.cell = layoutRow.row.insertCell(cidx);
  98. this.cell.style.verticalAlign = 'top';
  99. this.set_width(layoutRow.row, width);
  100. var h = $a(this.cell, 'div','',{padding:(layout.with_border ? '0px 8px' : '0px')});
  101. this.wrapper = $a(this.cell, 'div','',{padding:(layout.with_border ? '8px' : '0px')});
  102. layout.cur_cell = this.wrapper;
  103. layout.cur_cell.header = h;
  104. }
  105. // evenly distribute columns
  106. LayoutCell.prototype.set_width = function(row, width) {
  107. var w = 100;
  108. var n_cells = row.cells.length;
  109. var cells_with_no_width = n_cells;
  110. // current cell
  111. if(width) {
  112. $y(row.cells[n_cells-1], {width: cint(width) + '%'})
  113. } else {
  114. row.cells[n_cells-1].estimated_width = 1;
  115. }
  116. // get user specified width
  117. for(var i=0; i<n_cells; i++) {
  118. if(!row.cells[i].estimated_width) {
  119. w = w - cint(row.cells[i].style.width);
  120. cells_with_no_width--;
  121. }
  122. }
  123. // evenly distribute all
  124. for(var i=0; i<n_cells; i++) {
  125. if(row.cells[i].estimated_width)
  126. $y(row.cells[i], {width:cint(w/cells_with_no_width) + '%'})
  127. }
  128. }
  129. LayoutCell.prototype.show = function() { $ds(this.wrapper); }
  130. LayoutCell.prototype.hide = function() { $dh(this.wrapper); }