Roo/bootstrap/Card.js
[roojs1] / Roo / bootstrap / Card.js
1 /*
2  * This is BS4's Card element.. - similar to our containers probably..
3  * 
4  */
5 /**
6  * @class Roo.bootstrap.Card
7  * @extends Roo.bootstrap.Component
8  * Bootstrap Card class
9  *
10  *
11  * possible... may not be implemented..
12  * @cfg {String} header content of header (for panel)
13  * @cfg {String|Object} title
14  * @cfg {String|Object} subtitle
15  * @cfg {String|Object} body
16  * @cfg {String|Object} footer
17  * @cfg {Array} - links
18  *
19  * @cfg {String} weight (primary|warning|info|danger|secondary|success|light|dark)
20  * @cfg {String} margin (0|1|2|3|4|5|auto|t-0|t-1|t-2|t-3|t-4|t-5|t-auto|b-0|b-1|b-2|b-3|b-4|b-5|b-auto|l-0|l-1|l-2|l-3|l-4|l-5|l-auto|r-0|r-1|r-2|r-3|r-4|r-5|r-auto|x-0|x-1|x-2|x-3|x-4|x-5|x-auto|y-0|y-1|y-2|y-3|y-4|y-5|y-auto)
21  * @cfg {String} padding (0|1|2|3|4|5|t-0|t-1|t-2|t-3|t-4|t-5|b-0|b-1|b-2|b-3|b-4|b-5|l-0|l-1|l-2|l-3|l-4|l-5|r-0|r-1|r-2|r-3|r-4|r-5|x-0|x-1|x-2|x-3|x-4|x-5|y-0|y-1|y-2|y-3|y-4|y-5)
22  * @constructor
23  * Create a new Container
24  * @param {Object} config The config object
25  */
26
27 Roo.bootstrap.Card = function(config){
28     Roo.bootstrap.Card.superclass.constructor.call(this, config);
29     
30     this.addEvents({
31         
32     });
33 };
34
35
36 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component,  {
37     
38     weight : '',
39    
40    
41        // Roo.log("Call onRender: " + this.xtype);
42         /*  We are looking at something like this.
43 <div class="card">
44     <img src="..." class="card-img-top" alt="...">
45     <div class="card-body">
46         <h5 class="card-title">Card title</h5>
47          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
48
49         >> this bit is really the body...
50         <div> << we will ad dthis in hopefully it will not break shit.
51         
52             <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
53         
54         </div> <<
55           <a href="#" class="card-link">Card link</a>
56           
57     </div>
58     <div class="card-footer">
59         <small class="text-muted">Last updated 3 mins ago</small>
60     </div>
61 </div>
62          */
63     getAutoCreate : function(){
64         
65         var cfg = {
66             tag : this.tag || 'div',
67             html : '',
68             cls : 'card'
69         };
70         
71         if (this.weight.length && this.weight != 'light') {
72             cfg.cls += ' text-white'
73         }
74         if (this.weight.length) {
75             cfg.cls += ' bg-' + this.weight;
76         }
77         
78         // margin?
79         
80         
81         
82         // - this is applied by the parent..
83         //if (this.cls) {
84         //    cfg.cls = this.cls + '';
85         //}
86         
87         if (this.sticky.length) {
88             
89             var bd = Roo.get(document.body);
90             if (!bd.hasClass('bootstrap-sticky')) {
91                 bd.addClass('bootstrap-sticky');
92                 Roo.select('html',true).setStyle('height', '100%');
93             }
94              
95             cfg.cls += 'bootstrap-sticky-' + this.sticky;
96         }
97         
98         
99         if (this.well.length) {
100             switch (this.well) {
101                 case 'lg':
102                 case 'sm':
103                     cfg.cls +=' well well-' +this.well;
104                     break;
105                 default:
106                     cfg.cls +=' well';
107                     break;
108             }
109         }
110         
111         if (this.hidden) {
112             cfg.cls += ' hidden';
113         }
114         
115         
116         if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
117             cfg.cls +=' alert alert-' + this.alert;
118         }
119         
120         var body = cfg;
121         
122         if (this.panel.length) {
123             cfg.cls += ' panel panel-' + this.panel;
124             cfg.cn = [];
125             if (this.header.length) {
126                 
127                 var h = [];
128                 
129                 if(this.expandable){
130                     
131                     cfg.cls = cfg.cls + ' expandable';
132                     
133                     h.push({
134                         tag: 'i',
135                         cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus') 
136                     });
137                     
138                 }
139                 
140                 h.push(
141                     {
142                         tag: 'span',
143                         cls : 'panel-title',
144                         html : (this.expandable ? '&nbsp;' : '') + this.header
145                     },
146                     {
147                         tag: 'span',
148                         cls: 'panel-header-right',
149                         html: this.rheader
150                     }
151                 );
152                 
153                 cfg.cn.push({
154                     cls : 'panel-heading',
155                     style : this.expandable ? 'cursor: pointer' : '',
156                     cn : h
157                 });
158                 
159             }
160             
161             body = false;
162             cfg.cn.push({
163                 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
164                 html : this.html
165             });
166             
167             
168             if (this.footer.length) {
169                 cfg.cn.push({
170                     cls : 'panel-footer',
171                     html : this.footer
172                     
173                 });
174             }
175             
176         }
177         
178         if (body) {
179             body.html = this.html || cfg.html;
180             // prefix with the icons..
181             if (this.fa) {
182                 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
183             }
184             if (this.icon) {
185                 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
186             }
187             
188             
189         }
190         if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
191             cfg.cls =  'container';
192         }
193         
194         return cfg;
195     },
196 }