2 * @author Nicolas Ferrero
3 * @class Ext.ux.GroupTabPanel
4 * @extends Ext.Container
5 * A TabPanel with grouping support.
7 Ext.define('Ext.ux.GroupTabPanel', {
8 extend: 'Ext.Container',
10 alias: 'widget.grouptabpanel',
18 baseCls : Ext.baseCSSPrefix + 'grouptabpanel',
20 initComponent: function(config) {
24 Ext.apply(me, config);
26 me.store = me.createItemsStore();
36 me.items = Ext.each(me.items, function(item) {
37 items.push(item.items);
42 cls: 'x-tree-panel x-grouptabbar',
58 renderer: function (value, cell, node, idx1, idx2, store, tree) {
61 if (!node.data.activeGroup) {
62 cls += ' x-inactive-group';
63 } else if (node.parentNode && node.parentNode.parentNode === null) {
64 cls += ' x-grouptab-first';
65 if (node.previousSibling) {
66 cls += ' x-grouptab-prev';
68 } else if (node.nextSibling === null) {
69 cls += ' x-grouptab-last';
71 cls += ' x-grouptab-center';
73 if (node.data.activeTab) {
74 cls += ' x-active-tab';
76 cell.tdCls= 'x-grouptab'+ cls;
85 activeItem: me.mainItem,
86 baseCls: Ext.baseCSSPrefix + 'grouptabcontainer',
92 * @event beforetabchange
93 * Fires before a tab change (activated by {@link #setActiveTab}). Return false in any listener to cancel
95 * @param {Ext.ux.GroupTabPanel} grouptabPanel The GroupTabPanel
96 * @param {Ext.Component} newCard The card that is about to be activated
97 * @param {Ext.Component} oldCard The card that is currently active
103 * Fires when a new tab has been activated (activated by {@link #setActiveTab}).
104 * @param {Ext.ux.GroupTabPanel} grouptabPanel The GroupTabPanel
105 * @param {Ext.Component} newCard The newly activated item
106 * @param {Ext.Component} oldCard The previously active item
111 * @event beforegroupchange
112 * Fires before a group change (activated by {@link #setActiveGroup}). Return false in any listener to cancel
114 * @param {Ext.ux.GroupTabPanel} grouptabPanel The GroupTabPanel
115 * @param {Ext.Component} newGroup The root group card that is about to be activated
116 * @param {Ext.Component} oldGroup The root group card that is currently active
122 * Fires when a new group has been activated (activated by {@link #setActiveGroup}).
123 * @param {Ext.ux.GroupTabPanel} grouptabPanel The GroupTabPanel
124 * @param {Ext.Component} newGroup The newly activated root group item
125 * @param {Ext.Component} oldGroup The previously active root group item
130 me.callParent(arguments);
131 me.setActiveTab(me.activeTab);
132 me.setActiveGroup(me.activeGroup);
133 me.mon(me.down('treepanel').getSelectionModel(), 'select', me.onNodeSelect, me);
138 * Node selection listener.
140 onNodeSelect: function (selModel, node) {
142 currentNode = me.store.getRootNode(),
145 if (node.parentNode && node.parentNode.parentNode === null) {
148 parent = node.parentNode;
151 if (me.setActiveGroup(parent.get('id')) === false || me.setActiveTab(node.get('id')) === false) {
156 currentNode.set('activeTab', false);
157 currentNode.set('activeGroup', false);
158 currentNode = currentNode.firstChild || currentNode.nextSibling || currentNode.parentNode.nextSibling;
161 parent.set('activeGroup', true);
163 parent.eachChild(function(child) {
165 child.set('activeGroup', true);
167 node.set('activeTab', true);
168 selModel.view.refresh();
172 * Makes the given component active (makes it the visible card in the GroupTabPanel's CardLayout)
173 * @param {Ext.Component} cmp The component to make active
175 setActiveTab: function(cmp) {
180 if(Ext.isString(cmp)) {
181 newTab = Ext.getCmp(newTab);
184 if (newTab === me.activeTab) {
188 oldTab = me.activeTab;
189 if (me.fireEvent('beforetabchange', me, newTab, oldTab) !== false) {
190 me.activeTab = newTab;
192 me.down('container[baseCls=' + Ext.baseCSSPrefix + 'grouptabcontainer' + ']').getLayout().setActiveItem(newTab);
194 me.fireEvent('tabchange', me, newTab, oldTab);
200 * Makes the given group active
201 * @param {Ext.Component} cmp The root component to make active.
203 setActiveGroup: function(cmp) {
208 if(Ext.isString(cmp)) {
209 newGroup = Ext.getCmp(newGroup);
212 if (newGroup === me.activeGroup) {
216 oldGroup = me.activeGroup;
217 if (me.fireEvent('beforegroupchange', me, newGroup, oldGroup) !== false) {
218 me.activeGroup = newGroup;
219 me.fireEvent('groupchange', me, newGroup, oldGroup);
228 * Creates the TreeStore used by the GroupTabBar.
230 createItemsStore: function() {
236 me.activeGroup = me.activeGroup || 0;
238 Ext.each(me.items, function(item, idx){
239 var items = item.items,
240 rootItem = (items[item.mainItem] || items[0]),
246 rootItem.id = Ext.id();
249 root.id = rootItem.id;
250 root.text = rootItem.title;
251 root.iconCls = rootItem.iconCls;
252 delete rootItem.iconCls;
253 delete rootItem.title;
254 root.expanded = true;
255 root.activeGroup = (me.activeGroup === idx);
256 root.activeTab = root.activeGroup ? true : false;
257 if (root.activeTab) {
258 me.activeTab = root.id;
261 if (root.activeGroup) {
262 me.mainItem = item.mainItem || 0;
263 me.activeGroup = root.id;
266 Ext.each(item.items, function(childItem) {
268 childItem.id = Ext.id();
270 if(childItem.id !== root.id) {
274 text: childItem.title,
275 iconCls: childItem.iconCls,
278 delete childItem.title;
279 delete childItem.iconCls;
281 child.activeGroup = root.activeGroup;
282 root.children.push(child);
286 data.children.push(root);
290 return Ext.create('Ext.data.TreeStore', {
291 fields: ['id', 'text', 'activeGroup', 'activeTab'],
292 root: {expanded: true},
301 * Returns the item that is currently active inside this GroupTabPanel.
302 * @return {Ext.Component/Integer} The currently active item
304 getActiveTab: function() {
305 return this.activeTab;
309 * Returns the root group item that is currently active inside this GroupTabPanel.
310 * @return {Ext.Component/Integer} The currently active root group item
312 getActiveGroup: function() {
313 return this.activeGroup;