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.

318 lines
9.4 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.ns('Ext.ux');
  16. Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
  17. tabPosition: 'left',
  18. alternateColor: false,
  19. alternateCls: 'x-grouptabs-panel-alt',
  20. defaultType: 'grouptab',
  21. deferredRender: false,
  22. activeGroup : null,
  23. initComponent: function(){
  24. Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
  25. this.addEvents(
  26. 'beforegroupchange',
  27. 'groupchange'
  28. );
  29. this.elements = 'body,header';
  30. this.stripTarget = 'header';
  31. this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
  32. this.addClass('x-grouptabs-panel');
  33. if (this.tabStyle && this.tabStyle != '') {
  34. this.addClass('x-grouptabs-panel-' + this.tabStyle);
  35. }
  36. if (this.alternateColor) {
  37. this.addClass(this.alternateCls);
  38. }
  39. this.on('beforeadd', function(gtp, item, index){
  40. this.initGroup(item, index);
  41. });
  42. this.items.each(function(item){
  43. item.on('tabchange',function(item){
  44. this.fireEvent('tabchange', this, item.activeTab);
  45. }, this);
  46. },this);
  47. },
  48. initEvents : function() {
  49. this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
  50. },
  51. onRender: function(ct, position){
  52. Ext.TabPanel.superclass.onRender.call(this, ct, position);
  53. if(this.plain){
  54. var pos = this.tabPosition == 'top' ? 'header' : 'footer';
  55. this[pos].addClass('x-tab-panel-'+pos+'-plain');
  56. }
  57. var st = this[this.stripTarget];
  58. this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
  59. tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
  60. var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
  61. this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
  62. this.header.addClass('x-grouptabs-panel-header');
  63. this.bwrap.addClass('x-grouptabs-bwrap');
  64. this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
  65. if (!this.groupTpl) {
  66. var tt = new Ext.Template(
  67. '<li class="{cls}" id="{id}">',
  68. '<a class="x-grouptabs-expand" onclick="return false;"></a>',
  69. '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
  70. '<span>{text}</span></a>',
  71. '</li>'
  72. );
  73. tt.disableFormats = true;
  74. tt.compile();
  75. Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
  76. }
  77. this.items.each(this.initGroup, this);
  78. },
  79. afterRender: function(){
  80. Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
  81. this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
  82. cls: 'x-tab-joint'
  83. });
  84. this.addClass('x-tab-panel-' + this.tabPosition);
  85. this.header.setWidth(this.tabWidth);
  86. if (this.activeGroup !== undefined) {
  87. var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
  88. delete this.activeGroup;
  89. this.setActiveGroup(group);
  90. group.setActiveTab(group.getMainItem());
  91. }
  92. },
  93. getGroupEl : Ext.TabPanel.prototype.getTabEl,
  94. // private
  95. findTargets: function(e){
  96. var item = null,
  97. itemEl = e.getTarget('li', this.strip);
  98. if (itemEl) {
  99. item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
  100. if (item.disabled) {
  101. return {
  102. expand: null,
  103. item: null,
  104. el: null
  105. };
  106. }
  107. }
  108. return {
  109. expand: e.getTarget('.x-grouptabs-expand', this.strip),
  110. isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
  111. item: item,
  112. el: itemEl
  113. };
  114. },
  115. // private
  116. onStripMouseDown: function(e){
  117. if (e.button != 0) {
  118. return;
  119. }
  120. e.preventDefault();
  121. var t = this.findTargets(e);
  122. if (t.expand) {
  123. this.toggleGroup(t.el);
  124. }
  125. else if (t.item) {
  126. if(t.isGroup) {
  127. t.item.setActiveTab(t.item.getMainItem());
  128. }
  129. else {
  130. t.item.ownerCt.setActiveTab(t.item);
  131. }
  132. }
  133. },
  134. expandGroup: function(groupEl){
  135. if(groupEl.isXType) {
  136. groupEl = this.getGroupEl(groupEl);
  137. }
  138. Ext.fly(groupEl).addClass('x-grouptabs-expanded');
  139. this.syncTabJoint();
  140. },
  141. toggleGroup: function(groupEl){
  142. if(groupEl.isXType) {
  143. groupEl = this.getGroupEl(groupEl);
  144. }
  145. Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
  146. this.syncTabJoint();
  147. },
  148. collapseGroup: function(groupEl){
  149. if(groupEl.isXType) {
  150. groupEl = this.getGroupEl(groupEl);
  151. }
  152. Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
  153. this.syncTabJoint();
  154. },
  155. syncTabJoint: function(groupEl){
  156. if (!this.tabJoint) {
  157. return;
  158. }
  159. groupEl = groupEl || this.getGroupEl(this.activeGroup);
  160. if(groupEl) {
  161. this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
  162. var y = Ext.isGecko2 ? 0 : 1;
  163. if (this.tabPosition == 'left'){
  164. this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
  165. }
  166. else {
  167. this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
  168. }
  169. }
  170. else {
  171. this.tabJoint.hide();
  172. }
  173. },
  174. getActiveTab : function() {
  175. if(!this.activeGroup) return null;
  176. return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
  177. },
  178. onResize: function(){
  179. Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
  180. this.syncTabJoint();
  181. },
  182. createCorner: function(el, pos){
  183. return Ext.fly(el).createChild({
  184. cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
  185. });
  186. },
  187. initGroup: function(group, index){
  188. var before = this.strip.dom.childNodes[index],
  189. p = this.getTemplateArgs(group);
  190. if (index === 0) {
  191. p.cls += ' x-tab-first';
  192. }
  193. p.cls += ' x-grouptabs-main';
  194. p.text = group.getMainItem().title;
  195. var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
  196. tl = this.createCorner(el, 'top-' + this.tabPosition),
  197. bl = this.createCorner(el, 'bottom-' + this.tabPosition);
  198. group.tabEl = el;
  199. if (group.expanded) {
  200. this.expandGroup(el);
  201. }
  202. if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
  203. bl.setLeft('-10px');
  204. bl.setBottom('-5px');
  205. tl.setLeft('-10px');
  206. tl.setTop('-5px');
  207. }
  208. this.mon(group, {
  209. scope: this,
  210. changemainitem: this.onGroupChangeMainItem,
  211. beforetabchange: this.onGroupBeforeTabChange
  212. });
  213. },
  214. setActiveGroup : function(group) {
  215. group = this.getComponent(group);
  216. if(!group){
  217. return false;
  218. }
  219. if(!this.rendered){
  220. this.activeGroup = group;
  221. return true;
  222. }
  223. if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
  224. if(this.activeGroup){
  225. this.activeGroup.activeTab = null;
  226. var oldEl = this.getGroupEl(this.activeGroup);
  227. if(oldEl){
  228. Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
  229. }
  230. }
  231. var groupEl = this.getGroupEl(group);
  232. Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
  233. this.activeGroup = group;
  234. this.stack.add(group);
  235. this.layout.setActiveItem(group);
  236. this.syncTabJoint(groupEl);
  237. this.fireEvent('groupchange', this, group);
  238. return true;
  239. }
  240. return false;
  241. },
  242. onGroupBeforeTabChange: function(group, newTab, oldTab){
  243. if(group !== this.activeGroup || newTab !== oldTab) {
  244. this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
  245. }
  246. this.expandGroup(this.getGroupEl(group));
  247. if(group !== this.activeGroup) {
  248. return this.setActiveGroup(group);
  249. }
  250. },
  251. getFrameHeight: function(){
  252. var h = this.el.getFrameWidth('tb');
  253. h += (this.tbar ? this.tbar.getHeight() : 0) +
  254. (this.bbar ? this.bbar.getHeight() : 0);
  255. return h;
  256. },
  257. adjustBodyWidth: function(w){
  258. return w - this.tabWidth;
  259. }
  260. });
  261. Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);