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|Boolean} html -- html contents - or just use children.. use false to hide it..
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?
123 childContainer : false,
124 dropEl : false, /// the dom placeholde element that indicates drop location.
126 layoutCls : function()
130 Roo.log(this.margin_bottom.length);
131 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
132 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
134 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
135 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
137 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
138 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
142 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
143 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
144 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v]
148 // more generic support?
156 // Roo.log("Call onRender: " + this.xtype);
157 /* We are looking at something like this.
159 <img src="..." class="card-img-top" alt="...">
160 <div class="card-body">
161 <h5 class="card-title">Card title</h5>
162 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
164 >> this bit is really the body...
165 <div> << we will ad dthis in hopefully it will not break shit.
167 ** card text does not actually have any styling...
169 <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>
172 <a href="#" class="card-link">Card link</a>
175 <div class="card-footer">
176 <small class="text-muted">Last updated 3 mins ago</small>
180 getAutoCreate : function(){
188 if (this.weight.length && this.weight != 'light') {
189 cfg.cls += ' text-white';
191 cfg.cls += ' text-dark'; // need as it's nested..
193 if (this.weight.length) {
194 cfg.cls += ' bg-' + this.weight;
197 cfg.cls += this.layoutCls();
200 if (this.header.length) {
202 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
211 cls : 'card-header d-none',
216 if (this.collapsable) {
219 cls : 'd-block user-select-none',
223 cls : 'roo-collapse-toggle fa fa-chevron-down float-right ' + (this.collapsed ? 'collapsed' : '')
228 hdr.cn.push(hdr_ctr);
230 if (this.header.length) {
233 cls: 'roo-card-header-ctr',
238 if (this.header_image.length) {
241 cls : 'card-img-top',
242 src: this.header_image // escape?
247 cls : 'card-img-top d-none'
253 cls : 'card-body' + (this.html === false ? ' d-none' : ''),
257 if (this.collapsable) {
260 cls : 'roo-collapsable collapse ' + (this.collapsed ? '' : 'show'),
267 if (this.title.length) {
271 src: this.title // escape?
275 if (this.subtitle.length) {
279 src: this.subtitle // escape?
285 cls : 'roo-card-body-ctr'
288 if (this.html.length) {
294 // fixme ? handle objects?
296 if (this.footer.length) {
304 cfg.cn.push({cls : 'card-footer d-none'});
313 getCardHeader : function()
315 var ret = this.el.select('.card-header',true).first();
316 if (ret.hasClass('d-none')) {
317 ret.removeClass('d-none');
322 getCardFooter : function()
324 var ret = this.el.select('.card-footer',true).first();
325 if (ret.hasClass('d-none')) {
326 ret.removeClass('d-none');
331 getCardImageTop : function()
333 var ret = this.el.select('.card-img-top',true).first();
334 if (ret.hasClass('d-none')) {
335 ret.removeClass('d-none');
341 getChildContainer : function()
347 return this.el.select('.roo-card-body-ctr',true).first();
350 initEvents: function()
353 this.bodyEl = this.getChildContainer();
355 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
356 containerScroll: true,
357 ddGroup: this.drag_group || 'default_card_drag_group'
359 this.dragZone.getDragData = this.getDragData.createDelegate(this);
362 this.dropZone = new Roo.dd.DropZone(this.el.select('.card-body',true).first() , {
363 containerScroll: true,
364 ddGroup: this.drop_group || 'default_card_drag_group'
366 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
367 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
368 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
369 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
370 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
373 if (this.collapsable) {
374 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
376 if (this.rotateable) {
377 this.el.select('.card-header',true).on('click', this.onToggleRotate, this);
381 getDragData : function(e)
383 var target = this.getEl();
385 //this.handleSelection(e);
395 dragData.ddel = target.dom ; // the div element
396 Roo.log(target.getWidth( ));
397 dragData.ddel.style.width = target.getWidth() + 'px';
404 * Part of the Roo.dd.DropZone interface. If no target node is found, the
405 * whole Element becomes the target, and this causes the drop gesture to append.
407 getTargetFromEvent : function(e, dragged_card_el)
409 var target = e.getTarget();
410 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
411 target = target.parentNode;
422 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
423 // see if target is one of the 'cards'...
426 //Roo.log(this.items.length);
431 for (var i = 0;i< this.items.length;i++) {
433 if (!this.items[i].el.hasClass('card')) {
436 pos = this.getDropPoint(e, this.items[i].el.dom);
438 cards_len = ret.cards.length;
439 //Roo.log(this.items[i].el.dom.id);
440 ret.cards.push(this.items[i]);
442 if (ret.card_n < 0 && pos == 'above') {
443 ret.position = cards_len > 0 ? 'below' : pos;
444 ret.items_n = i > 0 ? i - 1 : 0;
445 ret.card_n = cards_len > 0 ? cards_len - 1 : 0;
446 ret.card = ret.cards[ret.card_n];
449 if (!ret.cards.length) {
451 ret.position = 'below';
455 // could not find a card.. stick it at the end..
456 if (ret.card_n < 0) {
457 ret.card_n = last_card_n;
458 ret.card = ret.cards[last_card_n];
459 ret.items_n = this.items.indexOf(ret.cards[last_card_n]);
460 ret.position = 'below';
463 if (this.items[ret.items_n].el == dragged_card_el) {
467 if (ret.position == 'below') {
468 var card_after = ret.card_n+1 == ret.cards.length ? false : ret.cards[ret.card_n+1];
470 if (card_after && card_after.el == dragged_card_el) {
477 var card_before = ret.card_n > 0 ? ret.cards[ret.card_n-1] : false;
479 if (card_before && card_before.el == dragged_card_el) {
486 onNodeEnter : function(n, dd, e, data){
489 onNodeOver : function(n, dd, e, data)
492 var target_info = this.getTargetFromEvent(e,data.source.el);
493 if (target_info === false) {
494 this.dropPlaceHolder('hide');
497 Roo.log(['getTargetFromEvent', target_info ]);
500 this.dropPlaceHolder('show', target_info,data);
504 onNodeOut : function(n, dd, e, data){
505 this.dropPlaceHolder('hide');
508 onNodeDrop : function(n, dd, e, data)
511 // call drop - return false if
513 // this could actually fail - if the Network drops..
514 // we will ignore this at present..- client should probably reload
515 // the whole set of cards if stuff like that fails.
518 var info = this.getTargetFromEvent(e,data.source.el);
519 if (info === false) {
523 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
527 this.dropPlaceHolder('hide');
529 // do the dom manipulation first..
530 var dom = data.source.el.dom;
531 dom.parentNode.removeChild(dom);
534 if (info.card !== true) {
535 var cardel = info.card.el.dom;
537 if (info.position == 'above') {
538 cardel.parentNode.insertBefore(dom, cardel);
539 } else if (cardel.nextSibling) {
540 cardel.parentNode.insertBefore(dom,cardel.nextSibling);
542 cardel.parentNode.append(dom);
546 this.bodyEl.dom.append(dom);
549 //FIXME HANDLE card = true
551 // add this to the correct place in items.
555 // remove Card from items.
557 var old_parent = data.source.parent();
559 old_parent.items = old_parent.items.filter(function(e) { return e != data.source });
561 if (this.items.length) {
563 Roo.log([info.items_n, info.position, this.items.length])
564 for (var i =0; i < this.items.length; i++) {
565 if (i == info.items_n && info.position == 'above') {
566 nitems.push(data.source);
568 nitems.push(this.items[i]);
569 if (i == info.items_n && info.position == 'below') {
570 nitems.push(data.source);
576 this.items.push(data.source);
584 /** Decide whether to drop above or below a View node. */
585 getDropPoint : function(e, n, dd)
590 if (n == this.bodyEl.dom) {
593 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
594 var c = t + (b - t) / 2;
595 var y = Roo.lib.Event.getPageY(e);
602 onToggleCollapse : function(e)
604 if (this.collapsed) {
605 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
606 this.el.select('.roo-collapsable').addClass('show');
607 this.collapsed = false;
610 this.el.select('.roo-collapse-toggle').addClass('collapsed');
611 this.el.select('.roo-collapsable').removeClass('show');
612 this.collapsed = true;
616 dropPlaceHolder: function (action, info, data)
618 if (this.dropEl === false) {
619 this.dropEl = Roo.DomHelper.append(this.bodyEl, {
623 this.dropEl.removeClass(['d-none', 'd-block']);
624 if (action == 'hide') {
626 this.dropEl.addClass('d-none');
629 // FIXME - info.card == true!!!
630 this.dropEl.dom.parentNode.removeChild(this.dropEl.dom);
632 if (info.card !== true) {
633 var cardel = info.card.el.dom;
635 if (info.position == 'above') {
636 cardel.parentNode.insertBefore(this.dropEl.dom, cardel);
637 } else if (cardel.nextSibling) {
638 cardel.parentNode.insertBefore(this.dropEl.dom,cardel.nextSibling);
640 cardel.parentNode.append(this.dropEl.dom);
644 this.bodyEl.dom.append(this.dropEl.dom);
647 this.dropEl.addClass('d-block roo-card-dropzone');
649 this.dropEl.setHeight( Roo.get(data.ddel).getHeight() );