Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

tabbedpage.js 5.2 KiB

13 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. if(hide_autosuggest)
  53. hide_autosuggest();
  54. }
  55. tab.set_selected = function() {
  56. if(me.cur_tab) me.cur_tab.collapse();
  57. this.className = 'box_tab_selected';
  58. $(this).css('opacity', 1);
  59. me.cur_tab = this;
  60. }
  61. tab.expand = function(arg) {
  62. this.set_selected();
  63. if(this.tab_body) $ds(this.tab_body);
  64. if(this.onshow)this.onshow(arg);
  65. }
  66. tab.onmouseover = function() {
  67. if(me.cur_tab!=this) this.className = 'box_tab_mouseover';
  68. }
  69. tab.onmouseout = function() {
  70. if(me.cur_tab!=this) this.className = ''
  71. }
  72. tab.hide = function() {
  73. this.collapse();
  74. $dh(this);
  75. }
  76. tab.show = function() {
  77. $ds(this);
  78. }
  79. tab.onclick = function() { this.expand(); }
  80. this.tabs[n] = tab;
  81. return tab;
  82. }
  83. // =================================================================================
  84. function TrayPage(parent, height, width, width_body) {
  85. var me = this;
  86. if(!width) width=(100/8)+'%';
  87. this.body_style = {margin: '4px 8px'}
  88. this.cur_item = null;
  89. this.items = {};
  90. this.tabs = this.items // for tabs
  91. this.tab = make_table($a(parent, 'div'), 1, 2, '100%', [width, width_body]);
  92. // tray style
  93. $y($td(this.tab, 0, 0),{
  94. backgroundColor: this.tray_bg
  95. //,borderRight:'1px solid ' + this.tray_fg
  96. ,width: width
  97. });
  98. // body style
  99. this.body = $a($td(this.tab, 0, 1), 'div');
  100. if(height) {
  101. $y(this.body, {height: height, overflow: 'auto'});
  102. }
  103. this.add_item = function(label, onclick, no_body, with_heading) {
  104. this.items[label] = new TrayItem(me, label, onclick, no_body, with_heading);
  105. return this.items[label];
  106. }
  107. }
  108. function TrayItem(tray, label, onclick, no_body, with_heading) {
  109. this.label = label;
  110. this.onclick = onclick;
  111. var me = this;
  112. this.ldiv = $a($td(tray.tab, 0, 0), 'div');
  113. $item_normal(this.ldiv);
  114. if(!no_body) {
  115. this.wrapper = $a(tray.body, 'div', '', tray.body_style);
  116. if(with_heading) {
  117. this.header = $a(this.wrapper, 'div', 'sectionHeading', {marginBottom:'16px', paddingBottom:'0px'});
  118. this.header.innerHTML = label;
  119. }
  120. this.body = $a(this.wrapper, 'div');
  121. this.tab_body = this.body; // for sync with tabs
  122. $dh(this.wrapper);
  123. }
  124. $(this.ldiv).html(label)
  125. .hover(
  126. function() { if(tray.cur_item.label != this.label) $item_active(this); },
  127. function() { if(tray.cur_item.label != this.label) $item_normal(this); }
  128. )
  129. .click(
  130. function() { me.expand(); }
  131. )
  132. this.ldiv.label = label;
  133. this.ldiv.setAttribute('title',label);
  134. this.ldiv.onmousedown = function() { $item_pressed(this); }
  135. this.ldiv.onmouseup = function() { $item_selected(this); }
  136. this.expand = function() {
  137. if(tray.cur_item) tray.cur_item.collapse();
  138. if(me.wrapper) $ds(me.wrapper);
  139. if(me.onclick) me.onclick(me.label);
  140. me.show_as_expanded();
  141. }
  142. this.show_as_expanded = function() {
  143. $item_selected(me.ldiv);
  144. tray.cur_item = me;
  145. }
  146. this.collapse = function() {
  147. if(me.wrapper)$dh(me.wrapper);
  148. $item_normal(me.ldiv);
  149. }
  150. this.hide = function() {
  151. me.collapse();
  152. $dh(me.ldiv);
  153. }
  154. this.show = function() {
  155. $ds(me.ldiv);
  156. }
  157. }