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  unique tab ID (will be autogenerated if not set.)
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     this.tabId = this.tabId || Roo.id();
36     if (typeof(p.navId) != 'undefined') {
37           // not really needed.. but just in case.. parent should be a NavGroup.
38         var tg = Roo.bootstrap.TabGroup.get(p.navId);
39         this.navId = this.navId || p.navId;
40         Roo.log(['register', tg, this]);
41         tg.register(this);
42     }
43 };
44
45 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component,  {
46     
47     active: false,
48     html: false,
49     tabId: false,
50     navId : false,
51     
52     getAutoCreate : function(){
53         var cfg = {
54             tag: 'div',
55             cls: 'tab-pane',
56             html: this.html || ''
57         };
58         
59         if(this.active){
60             cfg.cls += ' active';
61         }
62         
63         if(this.tabId){
64             cfg.tabId = this.tabId;
65         }
66         
67         return cfg;
68     },
69     onRender : function(ct, position)
70     {
71        // Roo.log("Call onRender: " + this.xtype);
72         
73         Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
74         
75         // registration with navgroups..
76         if (this.navId && this.tabId) {
77             var grp = Roo.bootstrap.NavGroup.get(this.navId);
78             if (grp) {
79                 //code
80                 var item = grp.getNavItem(this.tabId);
81                 if (!item) {
82                     Roo.log("could not find navID:"  + this.navId + ", tabId: " + this.tabId);
83                 } else {
84                     item.on('changed', function(item, state) {
85                         this.setActive(state);
86                     }, this);
87                 }
88             }
89         }
90         // tabgroup.
91         var p = this.parent();
92        
93         
94         
95     },
96     setActive: function(state)
97     {
98         Roo.log("panel - set active " + this.tabId + "=" + state);
99         
100         this.active = state;
101         if (!state) {
102             this.el.removeClass('active');
103             
104         } else  if (!this.el.hasClass('active')) {
105             this.el.addClass('active');
106         }
107         this.fireEvent('changed', this, state);
108     }
109     
110     
111 });
112  
113
114  
115
116