4 * This is BS4's Card element.. - similar to our containers probably..
8 * @class Roo.bootstrap.Card
9 * @extends Roo.bootstrap.Component
10 * Bootstrap Card class
13 * possible... may not be implemented..
14 * @cfg {String} header_image src url of image.
15 * @cfg {String|Object} header
16 * @cfg {Number} header_size (0|1|2|3|4|5) H1 or H2 etc.. 0 indicates default
19 * @cfg {String} subtitle
20 * @cfg {String} html -- html contents - or just use children..
21 * @cfg {String} footer
23 * @cfg {String} weight (primary|warning|info|danger|secondary|success|light|dark)
25 * @cfg {String} margin (0|1|2|3|4|5|auto)
26 * @cfg {String} margin_top (0|1|2|3|4|5|auto)
27 * @cfg {String} margin_bottom (0|1|2|3|4|5|auto)
28 * @cfg {String} margin_left (0|1|2|3|4|5|auto)
29 * @cfg {String} margin_right (0|1|2|3|4|5|auto)
30 * @cfg {String} margin_x (0|1|2|3|4|5|auto)
31 * @cfg {String} margin_y (0|1|2|3|4|5|auto)
33 * @cfg {String} padding (0|1|2|3|4|5)
34 * @cfg {String} padding_top (0|1|2|3|4|5)
35 * @cfg {String} padding_bottom (0|1|2|3|4|5)
36 * @cfg {String} padding_left (0|1|2|3|4|5)
37 * @cfg {String} padding_right (0|1|2|3|4|5)
38 * @cfg {String} padding_x (0|1|2|3|4|5)
39 * @cfg {String} padding_y (0|1|2|3|4|5)
41 * @cfg {String} display (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
42 * @cfg {String} display_xs (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
43 * @cfg {String} display_sm (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
44 * @cfg {String} display_lg (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
45 * @cfg {String} display_xl (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
47 * @config {Boolean} dragable if this card can be dragged.
48 * @config {String} drag_group group for drag
49 * @config {Boolean} dropable if this card can recieve other cards being dropped onto it..
50 * @config {String} drop_group group for drag
52 * @config {Boolean} collapsable can the body be collapsed.
53 * @config {Boolean} collapsed is the body collapsed when rendered...
55 * Create a new Container
56 * @param {Object} config The config object
59 Roo.bootstrap.Card = function(config){
60 Roo.bootstrap.Card.superclass.constructor.call(this, config);
68 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
73 margin: '', /// may be better in component?
110 childContainer : false,
112 layoutCls : function()
116 Roo.log(this.margin_bottom.length);
117 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
118 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
120 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
121 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
123 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
124 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
128 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
129 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
130 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v]
134 // more generic support?
142 // Roo.log("Call onRender: " + this.xtype);
143 /* We are looking at something like this.
145 <img src="..." class="card-img-top" alt="...">
146 <div class="card-body">
147 <h5 class="card-title">Card title</h5>
148 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
150 >> this bit is really the body...
151 <div> << we will ad dthis in hopefully it will not break shit.
153 ** card text does not actually have any styling...
155 <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>
158 <a href="#" class="card-link">Card link</a>
161 <div class="card-footer">
162 <small class="text-muted">Last updated 3 mins ago</small>
166 getAutoCreate : function(){
174 if (this.weight.length && this.weight != 'light') {
175 cfg.cls += ' text-white';
177 cfg.cls += ' text-dark'; // need as it's nested..
179 if (this.weight.length) {
180 cfg.cls += ' bg-' + this.weight;
183 cfg.cls += this.layoutCls();
186 if (this.header.length) {
188 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
191 html : this.header // escape?
198 cls : 'card-header d-none',
203 if (this.collapsable) {
206 cls : 'fa fa-chevron-down pull-right'
210 if (this.header_image.length) {
213 cls : 'card-img-top',
214 src: this.header_image // escape?
219 cls : 'card-img-top d-none'
229 if (this.collapsable) {
232 cls : 'roo-collapsable collapse ' + (this.collapsed ? '' : 'show'),
239 if (this.title.length) {
243 src: this.title // escape?
247 if (this.subtitle.length) {
251 src: this.subtitle // escape?
257 cls : 'roo-card-body-ctr'
260 if (this.html.length) {
266 // fixme ? handle objects?
267 if (this.footer.length) {
271 html: this.footer // escape?
280 getCardHeader : function()
282 var ret = this.el.select('.card-header',true).first();
283 if (ret.hasClass('d-none')) {
284 ret.removeClass('d-none');
290 getCardImageTop : function()
292 var ret = this.el.select('.card-img-top',true).first();
293 if (ret.hasClass('d-none')) {
294 ret.removeClass('d-none');
300 getChildContainer : function()
306 return this.el.select('.roo-card-body-ctr',true).first();
309 initEvents: function()
312 this.bodyEl = this.getChildContainer();
314 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
315 containerScroll: true,
316 ddGroup: this.drag_group || 'default_card_drag_group'
318 this.dragZone.getDragData = this.getDragData.createDelegate(this);
321 this.dropZone = new Roo.dd.DropZone(this.getChildContainer(), {
322 containerScroll: true,
323 ddGroup: this.drop_group || 'default_card_drag_group'
325 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
326 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
327 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
328 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
329 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
332 if (this.collapsable) {
333 this.el.select('.card-body .pull-right',true).on('click', this.onToggleCollapse, this);
336 getDragData : function(e) {
337 var target = this.getEl();
339 //this.handleSelection(e);
349 dragData.ddel = target.dom ; // the div element
350 Roo.log(target.getWidth( ));
351 dragData.ddel.style.width = target.getWidth() + 'px';
358 * Part of the Roo.dd.DropZone interface. If no target node is found, the
359 * whole Element becomes the target, and this causes the drop gesture to append.
361 getTargetFromEvent : function(e)
363 var target = e.getTarget();
364 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
365 target = target.parentNode;
367 // see if target is one of the 'cards'...
370 for (var i = 0;i< this.items.length;i++) {
371 if (this.items[i].xtype != 'Card') {
374 cards.push(this.items[i].el.dom);
375 if (target == this.items[i].el.dom) {
381 ctarget = cards[cards.length-1] || this.el.dom;
385 Roo.log(['getTargetFromEvent', ctarget]);
389 onNodeEnter : function(n, dd, e, data){
392 onNodeOver : function(n, dd, e, data)
394 var pt = this.getDropPoint(e, n, dd);
395 // set the insert point style on the target node
396 //var dragElClass = this.dropNotAllowed;
400 return false; //dragElClass;
402 onNodeOut : function(n, dd, e, data){
403 //this.removeDropIndicators(n);
405 onNodeDrop : function(n, dd, e, data)
409 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
412 var pt = this.getDropPoint(e, n, dd);
413 var insertAt = (n == this.bodyEl.dom) ? this.items.length : n.nodeIndex;
417 for (var i = 0; i < this.items.length; i++) {
418 var r = this.items[i];
419 //var dup = this.store.getById(r.id);
420 if (dup && (dd != this.dragZone)) {
421 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
424 this.store.insert(insertAt++, r.copy());
426 data.source.isDirtyFlag = true;
428 this.store.insert(insertAt++, r);
430 this.isDirtyFlag = true;
433 this.dragZone.cachedTarget = null;
437 /** Decide whether to drop above or below a View node. */
438 getDropPoint : function(e, n, dd)
440 if (n == this.bodyEl.dom) {
443 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
444 var c = t + (b - t) / 2;
445 var y = Roo.lib.Event.getPageY(e);
452 onToggleCollapse : function(e)
454 if (this.collapsed) {
455 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
456 this.el.select('.roo-collapse').addClass('show');
457 this.collapsed = false;
460 this.el.select('.roo-collapse-toggle').addClass('collapsed');
461 this.el.select('.roo-collapse').removeClass('show');
462 this.collapsed = true;