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);
66 * When a element a card is dropped
67 * @param {Roo.bootstrap.Element} this
68 * @param {Roo.Element} n the node being dropped?
69 * @param {Object} dd Drag and drop data
70 * @param {Roo.EventObject} e
71 * @param {Roo.EventObject} data the data passed via getDragData
79 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
84 margin: '', /// may be better in component?
121 childContainer : false,
122 dropEl : false, /// the dom placeholde element that indicates drop location.
124 layoutCls : function()
128 Roo.log(this.margin_bottom.length);
129 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
130 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
132 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
133 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
135 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
136 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
140 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
141 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
142 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v]
146 // more generic support?
154 // Roo.log("Call onRender: " + this.xtype);
155 /* We are looking at something like this.
157 <img src="..." class="card-img-top" alt="...">
158 <div class="card-body">
159 <h5 class="card-title">Card title</h5>
160 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
162 >> this bit is really the body...
163 <div> << we will ad dthis in hopefully it will not break shit.
165 ** card text does not actually have any styling...
167 <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>
170 <a href="#" class="card-link">Card link</a>
173 <div class="card-footer">
174 <small class="text-muted">Last updated 3 mins ago</small>
178 getAutoCreate : function(){
186 if (this.weight.length && this.weight != 'light') {
187 cfg.cls += ' text-white';
189 cfg.cls += ' text-dark'; // need as it's nested..
191 if (this.weight.length) {
192 cfg.cls += ' bg-' + this.weight;
195 cfg.cls += this.layoutCls();
198 if (this.header.length) {
200 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
209 cls : 'card-header d-none',
214 if (this.collapsable) {
217 cls : 'd-block user-select-none',
221 cls : 'roo-collapse-toggle fa fa-chevron-down float-right'
226 hdr.cn.push(hdr_ctr);
228 if (this.header.length) {
231 cls: 'roo-card-header-ctr',
236 if (this.header_image.length) {
239 cls : 'card-img-top',
240 src: this.header_image // escape?
245 cls : 'card-img-top d-none'
255 if (this.collapsable) {
258 cls : 'roo-collapsable collapse ' + (this.collapsed ? '' : 'show'),
265 if (this.title.length) {
269 src: this.title // escape?
273 if (this.subtitle.length) {
277 src: this.subtitle // escape?
283 cls : 'roo-card-body-ctr'
286 if (this.html.length) {
292 // fixme ? handle objects?
293 if (this.footer.length) {
297 html: this.footer // escape?
306 getCardHeader : function()
308 var ret = this.el.select('.card-header',true).first();
309 if (ret.hasClass('d-none')) {
310 ret.removeClass('d-none');
316 getCardImageTop : function()
318 var ret = this.el.select('.card-img-top',true).first();
319 if (ret.hasClass('d-none')) {
320 ret.removeClass('d-none');
326 getChildContainer : function()
332 return this.el.select('.roo-card-body-ctr',true).first();
335 initEvents: function()
338 this.bodyEl = this.getChildContainer();
340 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
341 containerScroll: true,
342 ddGroup: this.drag_group || 'default_card_drag_group'
344 this.dragZone.getDragData = this.getDragData.createDelegate(this);
347 this.dropZone = new Roo.dd.DropZone(this.el.select('.card-body',true).first() , {
348 containerScroll: true,
349 ddGroup: this.drop_group || 'default_card_drag_group'
351 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
352 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
353 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
354 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
355 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
358 if (this.collapsable) {
359 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
362 getDragData : function(e)
364 var target = this.getEl();
366 //this.handleSelection(e);
376 dragData.ddel = target.dom ; // the div element
377 Roo.log(target.getWidth( ));
378 dragData.ddel.style.width = target.getWidth() + 'px';
385 * Part of the Roo.dd.DropZone interface. If no target node is found, the
386 * whole Element becomes the target, and this causes the drop gesture to append.
388 getTargetFromEvent : function(e, dragged_card_el)
390 var target = e.getTarget();
391 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
392 target = target.parentNode;
403 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
404 // see if target is one of the 'cards'...
407 //Roo.log(this.items.length);
412 for (var i = 0;i< this.items.length;i++) {
414 if (!this.items[i].el.hasClass('card')) {
417 pos = this.getDropPoint(e, this.items[i].el.dom);
419 cards_len = ret.cards.length;
420 //Roo.log(this.items[i].el.dom.id);
421 ret.cards.push(this.items[i]);
423 if (ret.card_n < 0 && pos == 'above') {
424 ret.position = cards_len > 0 ? 'below' : pos;
425 ret.items_n = i > 0 ? i - 1 : 0;
426 ret.card_n = cards_len > 0 ? cards_len - 1 : 0;
429 if (!ret.cards.length) {
431 ret.position = below;
435 // could not find a card.. stick it at the end..
436 if (ret.card_n < 0) {
437 ret.card_n = last_card_pos;
438 ret.items_n = this.items.indexOf(ret.cards[last_card_pos]);
442 if (this.items[ret.items_n].el == dragged_card_el) {
446 if (cpos == 'below') {
447 var card_after = ret.card_n+1 == ret.cards.length ? false : ret.cards[ret.card_n+1];
449 if (card_after && card_after.el == dragged_card_el) {
456 var card_before = ret.card_n > 0 ? ret.cards[ret.card_n-1] : false;
458 if (card_before && card_before.el == dragged_card_el) {
465 onNodeEnter : function(n, dd, e, data){
468 onNodeOver : function(n, dd, e, data)
471 var target_info = this.getTargetFromEvent(e,data.source.el);
472 if (target_info === false) {
473 this.dropPlaceHolder('hide');
476 Roo.log(['getTargetFromEvent', target_info ]);
479 this.dropPlaceHolder('show', target_info,data);
483 onNodeOut : function(n, dd, e, data){
484 this.dropPlaceHolder('hide');
487 onNodeDrop : function(n, dd, e, data)
490 // call drop - return false if
491 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
495 var target_info = this.getTargetFromEvent(e,data.source.el);
496 if (target_info === false) {
500 var pt = this.getDropPoint(e, n, dd);
501 var insertAt = (n == this.bodyEl.dom) ? this.items.length : n.nodeIndex;
505 for (var i = 0; i < this.items.length; i++) {
506 var r = this.items[i];
507 //var dup = this.store.getById(r.id);
508 if (dup && (dd != this.dragZone)) {
509 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
512 this.store.insert(insertAt++, r.copy());
514 data.source.isDirtyFlag = true;
516 this.store.insert(insertAt++, r);
518 this.isDirtyFlag = true;
521 this.dragZone.cachedTarget = null;
525 /** Decide whether to drop above or below a View node. */
526 getDropPoint : function(e, n, dd)
531 if (n == this.bodyEl.dom) {
534 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
535 var c = t + (b - t) / 2;
536 var y = Roo.lib.Event.getPageY(e);
543 onToggleCollapse : function(e)
545 if (this.collapsed) {
546 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
547 this.el.select('.roo-collapsable').addClass('show');
548 this.collapsed = false;
551 this.el.select('.roo-collapse-toggle').addClass('collapsed');
552 this.el.select('.roo-collapsable').removeClass('show');
553 this.collapsed = true;
557 dropPlaceHolder: function (action, info, data)
559 if (this.dropEl === false) {
560 this.dropEl = Roo.DomHelper.append(this.bodyEl, {
564 this.dropEl.removeClass(['d-none', 'd-block']);
565 if (action == 'hide') {
567 this.dropEl.addClass('d-none');
570 var cardel = info.card.el.dom;
572 this.dropEl.dom.parentNode.removeChild(this.dropEl.dom);
573 if (info.position == 'above') {
574 cardel.parentNode.insertBefore(this.dropEl.dom, cardel);
575 } else if (cardel.nextSibling) {
576 cardel.parentNode.insertBefore(this.dropEl.dom,cardel.nextSibling);
578 cardel.parentNode.append(this.dropEl.dom);
580 this.dropEl.addClass('d-block roo-card-dropzone');
582 this.dropEl.setHeight( Roo.get(data.ddel).getHeight() );