Roo/bootstrap/TabPanel.js
[roojs1] / Roo / bootstrap / TabPanel.js
1 /*
2  * - LGPL
3  *
4  * TabPanel
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.TabPanel
10  * @extends Roo.bootstrap.Component
11  * Bootstrap TabPanel class
12  * @cfg {Boolean} active panel active
13  * @cfg {String} html panel content
14  * @cfg {String} tabId tab relate id
15  * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
16  * 
17  * 
18  * @constructor
19  * Create a new TabPanel
20  * @param {Object} config The config object
21  */
22
23 Roo.bootstrap.TabPanel = function(config){
24     Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
25      this.addEvents({
26         /**
27              * @event changed
28              * Fires when the active status changes
29              * @param {Roo.bootstrap.TabPanel} this
30              * @param {Boolean} state the new state
31             
32          */
33         'changed': true
34      });
35 };
36
37 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component,  {
38     
39     active: false,
40     html: false,
41     tabId: false,
42     navId : false,
43     
44     getAutoCreate : function(){
45         var cfg = {
46             tag: 'div',
47             cls: 'tab-pane',
48             html: this.html || ''
49         };
50         
51         if(this.active){
52             cfg.cls += ' active';
53         }
54         
55         if(this.tabId){
56             cfg.tabId = this.tabId;
57         }
58         
59         return cfg;
60     },
61     onRender : function(ct, position)
62     {
63        // Roo.log("Call onRender: " + this.xtype);
64         
65         Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
66         
67         // registration with navgroups..
68         if (this.navId && this.tabId) {
69             var item = Roo.bootstrap.NavGroup.get(this.navId).getNavItem(this.tabId);
70             if (!item) {
71                 Roo.log("could not find navID:"  + this.navId + ", tabId: " + this.tabId);
72             } else {
73                 item.on('changed', function(item, state) {
74                     this.setActive(state);
75                 }, this);
76             }
77         }
78         // tabgroup.
79         var p = this.parent();
80         if (typeof(p.navId) != 'undefined') {
81             // not really needed.. but just in case.. parent should be a NavGroup.
82             var tg = Roo.bootstrap.TabGroup.get(p.navId);
83             this.navId = this.navId || p.navId;
84             tg.register(this);
85         }
86         
87         
88     },
89     setActive: function(state)
90     {
91         Roo.log("panel - set active " + this.tabId + "=" + state);
92         
93         this.active = state;
94         if (!state) {
95             this.el.removeClass('active');
96             
97         } else  if (!this.el.hasClass('active')) {
98             this.el.addClass('active');
99         }
100         this.fireEvent('changed', this, state);
101     }
102     
103     
104 });
105  
106
107  
108
109