3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
9 Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
12 alternateColor: false,
14 alternateCls: 'x-grouptabs-panel-alt',
16 defaultType: 'grouptab',
18 deferredRender: false,
22 initComponent: function(){
23 Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
29 this.elements = 'body,header';
30 this.stripTarget = 'header';
32 this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
34 this.addClass('x-grouptabs-panel');
36 if (this.tabStyle && this.tabStyle != '') {
37 this.addClass('x-grouptabs-panel-' + this.tabStyle);
40 if (this.alternateColor) {
41 this.addClass(this.alternateCls);
44 this.on('beforeadd', function(gtp, item, index){
45 this.initGroup(item, index);
49 initEvents : function() {
50 this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
53 onRender: function(ct, position){
54 Ext.TabPanel.superclass.onRender.call(this, ct, position);
56 var pos = this.tabPosition == 'top' ? 'header' : 'footer';
57 this[pos].addClass('x-tab-panel-'+pos+'-plain');
60 var st = this[this.stripTarget];
62 this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
63 tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
65 var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
66 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
68 this.header.addClass('x-grouptabs-panel-header');
69 this.bwrap.addClass('x-grouptabs-bwrap');
70 this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
73 var tt = new Ext.Template(
74 '<li class="{cls}" id="{id}">',
75 '<a class="x-grouptabs-expand" onclick="return false;"></a>',
76 '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
77 '<span>{text}</span></a>',
80 tt.disableFormats = true;
82 Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
84 this.items.each(this.initGroup, this);
87 afterRender: function(){
88 Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
90 this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
94 this.addClass('x-tab-panel-' + this.tabPosition);
95 this.header.setWidth(this.tabWidth);
97 if (this.activeGroup !== undefined) {
98 var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
99 delete this.activeGroup;
100 this.setActiveGroup(group);
101 group.setActiveTab(group.getMainItem());
105 getGroupEl : Ext.TabPanel.prototype.getTabEl,
108 findTargets: function(e){
110 itemEl = e.getTarget('li', this.strip);
112 item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
122 expand: e.getTarget('.x-grouptabs-expand', this.strip),
123 isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
130 onStripMouseDown: function(e){
135 var t = this.findTargets(e);
137 this.toggleGroup(t.el);
141 t.item.setActiveTab(t.item.getMainItem());
144 t.item.ownerCt.setActiveTab(t.item);
149 expandGroup: function(groupEl){
150 if(groupEl.isXType) {
151 groupEl = this.getGroupEl(groupEl);
153 Ext.fly(groupEl).addClass('x-grouptabs-expanded');
157 toggleGroup: function(groupEl){
158 if(groupEl.isXType) {
159 groupEl = this.getGroupEl(groupEl);
161 Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
165 collapseGroup: function(groupEl){
166 if(groupEl.isXType) {
167 groupEl = this.getGroupEl(groupEl);
169 Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
173 syncTabJoint: function(groupEl){
174 if (!this.tabJoint) {
178 groupEl = groupEl || this.getGroupEl(this.activeGroup);
180 this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
182 var y = Ext.isGecko2 ? 0 : 1;
183 if (this.tabPosition == 'left'){
184 this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
187 this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
191 this.tabJoint.hide();
195 getActiveTab : function() {
196 if(!this.activeGroup) return null;
197 return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
200 onResize: function(){
201 Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
205 createCorner: function(el, pos){
206 return Ext.fly(el).createChild({
207 cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
211 initGroup: function(group, index){
212 var before = this.strip.dom.childNodes[index],
213 p = this.getTemplateArgs(group);
215 p.cls += ' x-tab-first';
217 p.cls += ' x-grouptabs-main';
218 p.text = group.getMainItem().title;
220 var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
221 tl = this.createCorner(el, 'top-' + this.tabPosition),
222 bl = this.createCorner(el, 'bottom-' + this.tabPosition);
225 if (group.expanded) {
226 this.expandGroup(el);
229 if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
231 bl.setBottom('-5px');
238 changemainitem: this.onGroupChangeMainItem,
239 beforetabchange: this.onGroupBeforeTabChange
243 setActiveGroup : function(group) {
244 group = this.getComponent(group);
249 this.activeGroup = group;
252 if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
253 if(this.activeGroup){
254 this.activeGroup.activeTab = null;
255 var oldEl = this.getGroupEl(this.activeGroup);
257 Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
261 var groupEl = this.getGroupEl(group);
262 Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
264 this.activeGroup = group;
265 this.stack.add(group);
267 this.layout.setActiveItem(group);
268 this.syncTabJoint(groupEl);
270 this.fireEvent('groupchange', this, group);
276 onGroupBeforeTabChange: function(group, newTab, oldTab){
277 if(group !== this.activeGroup || newTab !== oldTab) {
278 this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
280 this.expandGroup(this.getGroupEl(group));
281 if(group !== this.activeGroup) {
282 return this.setActiveGroup(group);
286 getFrameHeight: function(){
287 var h = this.el.getFrameWidth('tb');
288 h += (this.tbar ? this.tbar.getHeight() : 0) +
289 (this.bbar ? this.bbar.getHeight() : 0);
294 adjustBodyWidth: function(w){
295 return w - this.tabWidth;
299 Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);