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',
197 cls : 'card-header d-none',
202 if (this.collapsable) {
209 cls : 'fa fa-chevron-down float-right'
214 hdr.cn.push(hdr_ctr);
216 if (this.header.length) {
219 cls: 'roo-card-header-ctr',
224 if (this.header_image.length) {
227 cls : 'card-img-top',
228 src: this.header_image // escape?
233 cls : 'card-img-top d-none'
243 if (this.collapsable) {
246 cls : 'roo-collapsable collapse ' + (this.collapsed ? '' : 'show'),
253 if (this.title.length) {
257 src: this.title // escape?
261 if (this.subtitle.length) {
265 src: this.subtitle // escape?
271 cls : 'roo-card-body-ctr'
274 if (this.html.length) {
280 // fixme ? handle objects?
281 if (this.footer.length) {
285 html: this.footer // escape?
294 getCardHeader : function()
296 var ret = this.el.select('.card-header',true).first();
297 if (ret.hasClass('d-none')) {
298 ret.removeClass('d-none');
304 getCardImageTop : function()
306 var ret = this.el.select('.card-img-top',true).first();
307 if (ret.hasClass('d-none')) {
308 ret.removeClass('d-none');
314 getChildContainer : function()
320 return this.el.select('.roo-card-body-ctr',true).first();
323 initEvents: function()
326 this.bodyEl = this.getChildContainer();
328 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
329 containerScroll: true,
330 ddGroup: this.drag_group || 'default_card_drag_group'
332 this.dragZone.getDragData = this.getDragData.createDelegate(this);
335 this.dropZone = new Roo.dd.DropZone(this.getChildContainer(), {
336 containerScroll: true,
337 ddGroup: this.drop_group || 'default_card_drag_group'
339 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
340 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
341 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
342 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
343 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
346 if (this.collapsable) {
347 this.el.select('.card-body .pull-right',true).on('click', this.onToggleCollapse, this);
350 getDragData : function(e) {
351 var target = this.getEl();
353 //this.handleSelection(e);
363 dragData.ddel = target.dom ; // the div element
364 Roo.log(target.getWidth( ));
365 dragData.ddel.style.width = target.getWidth() + 'px';
372 * Part of the Roo.dd.DropZone interface. If no target node is found, the
373 * whole Element becomes the target, and this causes the drop gesture to append.
375 getTargetFromEvent : function(e)
377 var target = e.getTarget();
378 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
379 target = target.parentNode;
381 // see if target is one of the 'cards'...
384 for (var i = 0;i< this.items.length;i++) {
385 if (this.items[i].xtype != 'Card') {
388 cards.push(this.items[i].el.dom);
389 if (target == this.items[i].el.dom) {
395 ctarget = cards[cards.length-1] || this.el.dom;
399 Roo.log(['getTargetFromEvent', ctarget]);
403 onNodeEnter : function(n, dd, e, data){
406 onNodeOver : function(n, dd, e, data)
408 var pt = this.getDropPoint(e, n, dd);
409 // set the insert point style on the target node
410 //var dragElClass = this.dropNotAllowed;
414 return false; //dragElClass;
416 onNodeOut : function(n, dd, e, data){
417 //this.removeDropIndicators(n);
419 onNodeDrop : function(n, dd, e, data)
423 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
426 var pt = this.getDropPoint(e, n, dd);
427 var insertAt = (n == this.bodyEl.dom) ? this.items.length : n.nodeIndex;
431 for (var i = 0; i < this.items.length; i++) {
432 var r = this.items[i];
433 //var dup = this.store.getById(r.id);
434 if (dup && (dd != this.dragZone)) {
435 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
438 this.store.insert(insertAt++, r.copy());
440 data.source.isDirtyFlag = true;
442 this.store.insert(insertAt++, r);
444 this.isDirtyFlag = true;
447 this.dragZone.cachedTarget = null;
451 /** Decide whether to drop above or below a View node. */
452 getDropPoint : function(e, n, dd)
454 if (n == this.bodyEl.dom) {
457 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
458 var c = t + (b - t) / 2;
459 var y = Roo.lib.Event.getPageY(e);
466 onToggleCollapse : function(e)
468 if (this.collapsed) {
469 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
470 this.el.select('.roo-collapse').addClass('show');
471 this.collapsed = false;
474 this.el.select('.roo-collapse-toggle').addClass('collapsed');
475 this.el.select('.roo-collapse').removeClass('show');
476 this.collapsed = true;