sync
[roojs1] / Roo / bootstrap / Component.js
1 /*
2  * - LGPL
3  *
4  * base class for bootstrap elements.
5  * 
6  */
7
8 Roo.bootstrap = Roo.bootstrap || {};
9 /**
10  * @class Roo.bootstrap.Component
11  * @extends Roo.Component
12  * Bootstrap Component base class
13  * @cfg {String} cls css class
14  * @cfg {String} style any extra css
15  * 
16  * @constructor
17  * Do not use directly - it does not do anything..
18  * @param {Object} config The config object
19  */
20
21
22
23 Roo.bootstrap.Component = function(config){
24     Roo.bootstrap.Component.superclass.constructor.call(this, config);
25 };
26
27 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent,  {
28     
29     cls : false,
30     
31     style : false,
32     
33     autoCreate : false,
34     
35     initEvents : function() {  },
36     
37     parentId : false,
38     
39     parent: function() {
40         // returns the parent component..
41         return Roo.ComponentMgr.get(this.parentId)
42         
43         
44     },
45     
46     // private
47     onRender : function(ct, position)
48     {
49         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
50         if(this.el){
51             return;
52         }
53         var cfg = Roo.apply({},  this.getAutoCreate());
54         cfg.id = Roo.id();
55         
56         if (this.cls) {
57             cfg.cls += ' ' + this.cls;
58         }
59         if (this.style) { // fixme needs to support more complex style data.
60             cfg.style = this.style;
61         }
62         this.el = ct.createChild(cfg, position);
63         if(this.tabIndex !== undefined){
64             this.el.dom.setAttribute('tabIndex', this.tabIndex);
65         }
66         this.initEvents();
67         
68         
69     },
70     
71     getChildContainer : function()
72     {
73         return this.el;
74     },
75     
76     addxtype : function (tree, cntr) {
77         var cn = this;
78         cntr = typeof(cntr == 'undefined' ) ? 'getChildContainer' : cntr;
79         
80         if (tree.xtype != 'Body') {
81             
82             cn = Roo.factory(tree);
83             
84             cn.parentType = this.xtype; //??
85             cn.parentId = this.id;
86             cn.render(this[cntr]());
87             // then add the element..
88         }
89         var nitems = [];
90         if (typeof (tree.menu) != 'undefined') {
91             tree.menu.parentType = cn.xtype;
92             tree.menu.triggerEl = cn.el;
93             nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
94             
95         }
96         if (typeof (tree.buttons) != 'undefined' && typeof(cn.getButtonContainer) == 'function') {
97             
98             for(var i =0;i < tree.buttons.length;i++) {
99                 nitems.push(cn.addxtype(Roo.apply({}, tree.buttons[i]), 'getButtonContainer'));
100             }
101             
102             
103         }
104         if (!tree.items || !tree.items.length) {
105             this.items = nitems;
106             return this;
107         }
108         var items = tree.items;
109         delete tree.items;
110         
111         //Roo.log(items.length);
112             // add the items..
113         for(var i =0;i < items.length;i++) {
114             nitems.push(cn.addxtype(Roo.apply({}, items[i])));
115         }
116         
117         this.items = nitems;
118         
119         
120         return this;
121     }
122     
123     
124     
125     
126 });
127
128