ff2c42b3a1dd7587a993a1eec18b0ed762647f6d
[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_image  
13  * @cfg {String|Object} header
14  * @cfg {String|Object} header_size (0|1|2|3|4|5) H1 or H2 etc.. 0 indicates default
15  * 
16  * @cfg {String|Object} title
17  * @cfg {String|Object} subtitle
18  * @cfg {String|Object} body
19  * @cfg {String|Object} footer
20  * @cfg {Array} - links
21  *
22  * @cfg {String} weight (primary|warning|info|danger|secondary|success|light|dark)
23  * 
24  * @cfg {String} margin (0|1|2|3|4|5|auto)
25  * @cfg {String} margin_top (0|1|2|3|4|5|auto)
26  * @cfg {String} margin_bottom (0|1|2|3|4|5|auto)
27  * @cfg {String} margin_left (0|1|2|3|4|5|auto)
28  * @cfg {String} margin_right (0|1|2|3|4|5|auto)
29  * @cfg {String} margin_x (0|1|2|3|4|5|auto)
30  * @cfg {String} margin_y (0|1|2|3|4|5|auto)
31  *
32  * @cfg {String} padding (0|1|2|3|4|5)
33  * @cfg {String} padding_top (0|1|2|3|4|5)
34  * @cfg {String} padding_bottom (0|1|2|3|4|5)
35  * @cfg {String} padding_left (0|1|2|3|4|5)
36  * @cfg {String} padding_right (0|1|2|3|4|5)
37  * @cfg {String} padding_x (0|1|2|3|4|5)
38  * @cfg {String} padding_y (0|1|2|3|4|5)
39  *
40  * @cfg {String} display (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
41  * @cfg {String} display_xs (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
42  * @cfg {String} display_sm (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
43  * @cfg {String} display_lg (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
44  * @cfg {String} display_xl (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
45  
46  * @constructor
47  * Create a new Container
48  * @param {Object} config The config object
49  */
50
51 Roo.bootstrap.Card = function(config){
52     Roo.bootstrap.Card.superclass.constructor.call(this, config);
53     
54     this.addEvents({
55         
56     });
57 };
58
59
60 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component,  {
61     
62     
63     weight : '',
64     
65     margin: '', /// may be better in component?
66     margin_top: '', 
67     margin_bottom: '', 
68     margin_left: '',
69     margin_right: '',
70     margin_x: '',
71     margin_y: '',
72     
73     padding : '',
74     padding_top: '', 
75     padding_bottom: '', 
76     padding_left: '',
77     padding_right: '',
78     padding_x: '',
79     padding_y: '',
80     
81     display: '', 
82     display_xs: '', 
83     display_sm: '', 
84     display_lg: '',
85     display_xl: '',
86  
87     header_image  : '',
88     header : '',
89     header_size : 0,
90     title : '',
91     html : '',
92
93     layoutCls : function()
94     {
95         var cls = '';
96         var t = this;
97         
98         ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
99             // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
100             
101             if (t['margin' + (v.length ? '_' : '') + v].length) {
102                 cls += ' m' +  (v.length ? v[0]  : '') + '-' +  t['margin' + (v.length ? '_' : '') + v];
103             }
104             if (t['padding' + (v.length ? '_' : '') + v].length) {
105                 cls += ' p' +  (v.length ? v[0]  : '') + '-' +  t['padding' + (v.length ? '_' : '') + v];
106             }
107         });
108         
109         ['', 'xs', 'sm', 'lg', 'xl',   ].forEach(function(v) {
110             if (t['display' + (v.length ? '_' : '') + v].length) {
111                 cls += ' d' +  (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v].length
112             }
113         });
114         
115         // more generic support?
116         if (this.hidden) {
117             cls += ' d-none';
118         }
119         
120         return cls;
121     },
122  
123        // Roo.log("Call onRender: " + this.xtype);
124         /*  We are looking at something like this.
125 <div class="card">
126     <img src="..." class="card-img-top" alt="...">
127     <div class="card-body">
128         <h5 class="card-title">Card title</h5>
129          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
130
131         >> this bit is really the body...
132         <div> << we will ad dthis in hopefully it will not break shit.
133         
134             <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>
135         
136         </div> <<
137           <a href="#" class="card-link">Card link</a>
138           
139     </div>
140     <div class="card-footer">
141         <small class="text-muted">Last updated 3 mins ago</small>
142     </div>
143 </div>
144          */
145     getAutoCreate : function(){
146         
147         var cfg = {
148             tag : 'div',
149             cls : 'card',
150             cn : [ ]
151         };
152         
153         if (this.weight.length && this.weight != 'light') {
154             cfg.cls += ' text-white'
155         }
156         if (this.weight.length) {
157             cfg.cls += ' bg-' + this.weight;
158         }
159         
160         cfg.cls += this.layoutCls(); 
161         
162         if (this.header) {
163             cfg.cn.push({
164                 tag : 'div',
165                 cls : 'card-header',
166                 html : this.header // escape?
167             });
168         }
169         if (this.header_image) {
170             cfg.cn.push({
171                 tag : 'img',
172                 cls : 'card-img-top',
173                 src: this.header_image // escape?
174             });
175         }
176         
177
178         
179         
180         if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
181             cfg.cls +=' alert alert-' + this.alert;
182         }
183         
184         var body = cfg;
185         
186         if (this.panel.length) {
187             cfg.cls += ' panel panel-' + this.panel;
188             cfg.cn = [];
189             if (this.header.length) {
190                 
191                 var h = [];
192                 
193                 if(this.expandable){
194                     
195                     cfg.cls = cfg.cls + ' expandable';
196                     
197                     h.push({
198                         tag: 'i',
199                         cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus') 
200                     });
201                     
202                 }
203                 
204                 h.push(
205                     {
206                         tag: 'span',
207                         cls : 'panel-title',
208                         html : (this.expandable ? '&nbsp;' : '') + this.header
209                     },
210                     {
211                         tag: 'span',
212                         cls: 'panel-header-right',
213                         html: this.rheader
214                     }
215                 );
216                 
217                 cfg.cn.push({
218                     cls : 'panel-heading',
219                     style : this.expandable ? 'cursor: pointer' : '',
220                     cn : h
221                 });
222                 
223             }
224             
225             body = false;
226             cfg.cn.push({
227                 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
228                 html : this.html
229             });
230             
231             
232             if (this.footer.length) {
233                 cfg.cn.push({
234                     cls : 'panel-footer',
235                     html : this.footer
236                     
237                 });
238             }
239             
240         }
241         
242         if (body) {
243             body.html = this.html || cfg.html;
244             // prefix with the icons..
245             if (this.fa) {
246                 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
247             }
248             if (this.icon) {
249                 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
250             }
251             
252             
253         }
254         if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
255             cfg.cls =  'container';
256         }
257         
258         return cfg;
259     },
260 }