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('.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 tab = ctr.createChild({
103             tag : 'li',
104             cls : 'active nav-tab',
105             cn : [
106                 {
107                     tag : 'a',
108                     href:'#',
109                     html : pane.title
110                 }
111             ]
112             
113             
114         });
115         pane.tab = tab;
116         
117         tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
118                 
119     },
120     onTabClick : function(ev,un,ob,pane)
121     {
122         
123         this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
124         panel.tab.addClass('active');
125         Roo.log(pane.title);
126         
127     }
128     
129     
130 });
131
132