You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
8.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.ux.GroupTab = Ext.extend(Ext.Container, {
  16. mainItem: 0,
  17. expanded: true,
  18. deferredRender: true,
  19. activeTab: null,
  20. idDelimiter: '__',
  21. headerAsText: false,
  22. frame: false,
  23. hideBorders: true,
  24. initComponent: function(config){
  25. Ext.apply(this, config);
  26. this.frame = false;
  27. Ext.ux.GroupTab.superclass.initComponent.call(this);
  28. this.addEvents('activate', 'deactivate', 'changemainitem', 'beforetabchange', 'tabchange');
  29. this.setLayout(new Ext.layout.CardLayout({
  30. deferredRender: this.deferredRender
  31. }));
  32. if (!this.stack) {
  33. this.stack = Ext.TabPanel.AccessStack();
  34. }
  35. this.initItems();
  36. this.on('beforerender', function(){
  37. this.groupEl = this.ownerCt.getGroupEl(this);
  38. }, this);
  39. this.on('add', this.onAdd, this, {
  40. target: this
  41. });
  42. this.on('remove', this.onRemove, this, {
  43. target: this
  44. });
  45. if (this.mainItem !== undefined) {
  46. var item = (typeof this.mainItem == 'object') ? this.mainItem : this.items.get(this.mainItem);
  47. delete this.mainItem;
  48. this.setMainItem(item);
  49. }
  50. },
  51. /**
  52. * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
  53. * can return false to cancel the tab change.
  54. * @param {String/Panel} tab The id or tab Panel to activate
  55. */
  56. setActiveTab : function(item){
  57. item = this.getComponent(item);
  58. if(!item){
  59. return false;
  60. }
  61. if(!this.rendered){
  62. this.activeTab = item;
  63. return true;
  64. }
  65. if(this.activeTab != item && this.fireEvent('beforetabchange', this, item, this.activeTab) !== false){
  66. if(this.activeTab && this.activeTab != this.mainItem){
  67. var oldEl = this.getTabEl(this.activeTab);
  68. if(oldEl){
  69. Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
  70. }
  71. }
  72. var el = this.getTabEl(item);
  73. Ext.fly(el).addClass('x-grouptabs-strip-active');
  74. this.activeTab = item;
  75. this.stack.add(item);
  76. this.layout.setActiveItem(item);
  77. if(this.layoutOnTabChange && item.doLayout){
  78. item.doLayout();
  79. }
  80. if(this.scrolling){
  81. this.scrollToTab(item, this.animScroll);
  82. }
  83. this.fireEvent('tabchange', this, item);
  84. return true;
  85. }
  86. return false;
  87. },
  88. getTabEl: function(item){
  89. if (item == this.mainItem) {
  90. return this.groupEl;
  91. }
  92. return Ext.TabPanel.prototype.getTabEl.call(this, item);
  93. },
  94. onRender: function(ct, position){
  95. Ext.ux.GroupTab.superclass.onRender.call(this, ct, position);
  96. this.strip = Ext.fly(this.groupEl).createChild({
  97. tag: 'ul',
  98. cls: 'x-grouptabs-sub'
  99. });
  100. this.tooltip = new Ext.ToolTip({
  101. target: this.groupEl,
  102. delegate: 'a.x-grouptabs-text',
  103. trackMouse: true,
  104. renderTo: document.body,
  105. listeners: {
  106. beforeshow: function(tip) {
  107. var item = (tip.triggerElement.parentNode === this.mainItem.tabEl)
  108. ? this.mainItem
  109. : this.findById(tip.triggerElement.parentNode.id.split(this.idDelimiter)[1]);
  110. if(!item.tabTip) {
  111. return false;
  112. }
  113. tip.body.dom.innerHTML = item.tabTip;
  114. },
  115. scope: this
  116. }
  117. });
  118. if (!this.itemTpl) {
  119. var tt = new Ext.Template('<li class="{cls}" id="{id}">', '<a onclick="return false;" class="x-grouptabs-text {iconCls}">{text}</a>', '</li>');
  120. tt.disableFormats = true;
  121. tt.compile();
  122. Ext.ux.GroupTab.prototype.itemTpl = tt;
  123. }
  124. this.items.each(this.initTab, this);
  125. },
  126. afterRender: function(){
  127. Ext.ux.GroupTab.superclass.afterRender.call(this);
  128. if (this.activeTab !== undefined) {
  129. var item = (typeof this.activeTab == 'object') ? this.activeTab : this.items.get(this.activeTab);
  130. delete this.activeTab;
  131. this.setActiveTab(item);
  132. }
  133. },
  134. // private
  135. initTab: function(item, index){
  136. var before = this.strip.dom.childNodes[index];
  137. var p = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
  138. if (item === this.mainItem) {
  139. item.tabEl = this.groupEl;
  140. p.cls += ' x-grouptabs-main-item';
  141. }
  142. var el = before ? this.itemTpl.insertBefore(before, p) : this.itemTpl.append(this.strip, p);
  143. item.tabEl = item.tabEl || el;
  144. item.on('disable', this.onItemDisabled, this);
  145. item.on('enable', this.onItemEnabled, this);
  146. item.on('titlechange', this.onItemTitleChanged, this);
  147. item.on('iconchange', this.onItemIconChanged, this);
  148. item.on('beforeshow', this.onBeforeShowItem, this);
  149. },
  150. setMainItem: function(item){
  151. item = this.getComponent(item);
  152. if (!item || this.fireEvent('changemainitem', this, item, this.mainItem) === false) {
  153. return;
  154. }
  155. this.mainItem = item;
  156. },
  157. getMainItem: function(){
  158. return this.mainItem || null;
  159. },
  160. // private
  161. onBeforeShowItem: function(item){
  162. if (item != this.activeTab) {
  163. this.setActiveTab(item);
  164. return false;
  165. }
  166. },
  167. // private
  168. onAdd: function(gt, item, index){
  169. if (this.rendered) {
  170. this.initTab.call(this, item, index);
  171. }
  172. },
  173. // private
  174. onRemove: function(tp, item){
  175. Ext.destroy(Ext.get(this.getTabEl(item)));
  176. this.stack.remove(item);
  177. item.un('disable', this.onItemDisabled, this);
  178. item.un('enable', this.onItemEnabled, this);
  179. item.un('titlechange', this.onItemTitleChanged, this);
  180. item.un('iconchange', this.onItemIconChanged, this);
  181. item.un('beforeshow', this.onBeforeShowItem, this);
  182. if (item == this.activeTab) {
  183. var next = this.stack.next();
  184. if (next) {
  185. this.setActiveTab(next);
  186. }
  187. else if (this.items.getCount() > 0) {
  188. this.setActiveTab(0);
  189. }
  190. else {
  191. this.activeTab = null;
  192. }
  193. }
  194. },
  195. // private
  196. onBeforeAdd: function(item){
  197. var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
  198. if (existing) {
  199. this.setActiveTab(item);
  200. return false;
  201. }
  202. Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
  203. var es = item.elements;
  204. item.elements = es ? es.replace(',header', '') : es;
  205. item.border = (item.border === true);
  206. },
  207. // private
  208. onItemDisabled: Ext.TabPanel.prototype.onItemDisabled,
  209. onItemEnabled: Ext.TabPanel.prototype.onItemEnabled,
  210. // private
  211. onItemTitleChanged: function(item){
  212. var el = this.getTabEl(item);
  213. if (el) {
  214. Ext.fly(el).child('a.x-grouptabs-text', true).innerHTML = item.title;
  215. }
  216. },
  217. //private
  218. onItemIconChanged: function(item, iconCls, oldCls){
  219. var el = this.getTabEl(item);
  220. if (el) {
  221. Ext.fly(el).child('a.x-grouptabs-text').replaceClass(oldCls, iconCls);
  222. }
  223. },
  224. beforeDestroy: function(){
  225. Ext.TabPanel.prototype.beforeDestroy.call(this);
  226. this.tooltip.destroy();
  227. }
  228. });
  229. Ext.reg('grouptab', Ext.ux.GroupTab);