Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

183 linhas
5.1 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. // Tabbed Page
  23. function TabbedPage(parent, only_labels) {
  24. this.tabs = {};
  25. this.items = this.tabs // bc
  26. this.cur_tab = null;
  27. this.label_wrapper = $a(parent, 'div','box_label_wrapper', {marginTop:'16px'}); // for border
  28. this.label_body = $a(this.label_wrapper, 'div', 'box_label_body'); // for height
  29. this.label_area = $a(this.label_body, 'ul', 'box_tabs');
  30. if(!only_labels)this.body_area = $a(parent, 'div', '', {backgroundColor:'#FFF'});
  31. else this.body_area = null;
  32. this.add_item = function(label, onclick, no_body, with_heading) {
  33. this.add_tab(label, onclick, no_body, with_heading);
  34. return this.items[label];
  35. }
  36. }
  37. TabbedPage.prototype.add_tab = function(n, onshow, no_body, with_heading) {
  38. var tab = $a(this.label_area, 'li');
  39. tab.label = $a(tab,'a');
  40. tab.label.innerHTML = n;
  41. if(this.body_area && !no_body){
  42. tab.tab_body = $a(this.body_area, 'div');
  43. $dh(tab.tab_body);
  44. tab.body = tab.tab_body; // bc
  45. } else {
  46. tab.tab_body = null;
  47. }
  48. tab.onshow = onshow;
  49. var me = this;
  50. tab.collapse = function() {
  51. if(this.tab_body)$dh(this.tab_body); this.className = '';
  52. }
  53. tab.set_selected = function() {
  54. if(me.cur_tab) me.cur_tab.collapse();
  55. this.className = 'box_tab_selected';
  56. $(this).css('opacity', 1);
  57. me.cur_tab = this;
  58. }
  59. tab.expand = function(arg) {
  60. this.set_selected();
  61. if(this.tab_body) $ds(this.tab_body);
  62. if(this.onshow)this.onshow(arg);
  63. }
  64. tab.onmouseover = function() {
  65. if(me.cur_tab!=this) this.className = 'box_tab_mouseover';
  66. }
  67. tab.onmouseout = function() {
  68. if(me.cur_tab!=this) this.className = ''
  69. }
  70. tab.hide = function() {
  71. this.collapse();
  72. $dh(this);
  73. }
  74. tab.show = function() {
  75. $ds(this);
  76. }
  77. tab.onclick = function() { this.expand(); }
  78. this.tabs[n] = tab;
  79. return tab;
  80. }
  81. // =================================================================================
  82. function TrayPage(parent, height, width, width_body) {
  83. var me = this;
  84. if(!width) width=(100/8)+'%';
  85. this.body_style = {margin: '4px 8px'}
  86. this.cur_item = null;
  87. this.items = {};
  88. this.tabs = this.items // for tabs
  89. this.tab = make_table($a(parent, 'div'), 1, 2, '100%', [width, width_body]);
  90. // tray style
  91. $y($td(this.tab, 0, 0),{
  92. backgroundColor: this.tray_bg
  93. //,borderRight:'1px solid ' + this.tray_fg
  94. ,width: width
  95. });
  96. // body style
  97. this.body = $a($td(this.tab, 0, 1), 'div');
  98. if(height) {
  99. $y(this.body, {height: height, overflow: 'auto'});
  100. }
  101. this.add_item = function(label, onclick, no_body, with_heading) {
  102. this.items[label] = new TrayItem(me, label, onclick, no_body, with_heading);
  103. return this.items[label];
  104. }
  105. }
  106. function TrayItem(tray, label, onclick, no_body, with_heading) {
  107. this.label = label;
  108. this.onclick = onclick;
  109. var me = this;
  110. this.ldiv = $a($td(tray.tab, 0, 0), 'div');
  111. $item_normal(this.ldiv);
  112. if(!no_body) {
  113. this.wrapper = $a(tray.body, 'div', '', tray.body_style);
  114. if(with_heading) {
  115. this.header = $a(this.wrapper, 'div', 'sectionHeading', {marginBottom:'16px', paddingBottom:'0px'});
  116. this.header.innerHTML = label;
  117. }
  118. this.body = $a(this.wrapper, 'div');
  119. this.tab_body = this.body; // for sync with tabs
  120. $dh(this.wrapper);
  121. }
  122. $(this.ldiv).html(label)
  123. .hover(
  124. function() { if(tray.cur_item.label != this.label) $item_active(this); },
  125. function() { if(tray.cur_item.label != this.label) $item_normal(this); }
  126. )
  127. .click(
  128. function() { me.expand(); }
  129. )
  130. this.ldiv.label = label;
  131. this.ldiv.setAttribute('title',label);
  132. this.ldiv.onmousedown = function() { $item_pressed(this); }
  133. this.ldiv.onmouseup = function() { $item_selected(this); }
  134. this.expand = function() {
  135. if(tray.cur_item) tray.cur_item.collapse();
  136. if(me.wrapper) $ds(me.wrapper);
  137. if(me.onclick) me.onclick(me.label);
  138. me.show_as_expanded();
  139. }
  140. this.show_as_expanded = function() {
  141. $item_selected(me.ldiv);
  142. tray.cur_item = me;
  143. }
  144. this.collapse = function() {
  145. if(me.wrapper)$dh(me.wrapper);
  146. $item_normal(me.ldiv);
  147. }
  148. this.hide = function() {
  149. me.collapse();
  150. $dh(me.ldiv);
  151. }
  152. this.show = function() {
  153. $ds(me.ldiv);
  154. }
  155. }