Roo/bootstrap/dash/TabBox.js
[roojs1] / Roo / bootstrap / dash / TabBox.js
1 /*
2  * - LGPL
3  *
4  * TabBox
5  * 
6  */
7 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
8
9 /**
10  * @class Roo.bootstrap.dash.TabBox
11  * @extends Roo.bootstrap.Component
12  * Bootstrap TabBox class
13  * @cfg {String} title Title of the TabBox
14  * @cfg {String} icon Icon of the TabBox
15  * 
16  * @constructor
17  * Create a new TabBox
18  * @param {Object} config The config object
19  */
20
21
22 Roo.bootstrap.dash.TabBox = function(config){
23     Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
24     this.addEvents({
25         // raw events
26         /**
27          * @event addpane
28          * When a pane is added
29          * @param {Roo.bootstrap.dash.TabPane} pane
30          */
31         "addpane" : true
32          
33     });
34 };
35
36 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component,  {
37
38     title : '',
39     icon : false,
40     
41     getChildContainer : function()
42     {
43         return this.el.select('.tab-content', true).first();
44     },
45     
46     getAutoCreate : function(){
47         
48         var header = {
49             tag: 'li',
50             cls: 'pull-left header',
51             html: this.title,
52             cn : []
53         };
54         
55         if(this.icon){
56             header.cn.push({
57                 tag: 'i',
58                 cls: 'fa ' + this.icon
59             });
60         }
61         
62         
63         var cfg = {
64             tag: 'div',
65             cls: 'nav-tabs-custom',
66             cn: [
67                 {
68                     tag: 'ul',
69                     cls: 'nav nav-tabs pull-right',
70                     cn: [
71                         header
72                     ]
73                 },
74                 {
75                     tag: 'div',
76                     cls: 'tab-content no-padding',
77                     cn: []
78                 }
79             ]
80         }
81
82         return  cfg;
83     },
84     initEvents : function()
85     {
86         Roo.log('add add pane handler');
87         this.on('addpane', this.onAddPane, this);
88     },
89     
90     setTitle : function(value)
91     {
92         this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
93     },
94     onAddPane : function(pane)
95     {
96         Roo.log('addpane');
97         Roo.log(pane);
98         // tabs are rendere left to right..
99         var ctr = this.el.select('.nav-tabs', true).first();
100          
101          
102         var existing = ctr.select('.nav-tab',true);
103         var qty = existing.getCount();;
104         
105         
106         var tab = ctr.createChild({
107             tag : 'li',
108             cls : 'nav-tab' + (qty ? '' : ' active'),
109             cn : [
110                 {
111                     tag : 'a',
112                     href:'#',
113                     html : pane.title
114                 }
115             ]
116         }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
117         pane.tab = tab;
118         
119         tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
120         if (!qty) {
121             pane.el.addClass('active');
122         }
123         
124                 
125     },
126     onTabClick : function(ev,un,ob,pane)
127     {
128         
129         this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
130         pane.tab.addClass('active');
131         //Roo.log(pane.title);
132         this.getChildContainer().select('.tab-pane',true).removeClass('active');
133         pane.el.addClass('active');
134         
135     }
136     
137     
138 });
139
140