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...
54 * @config {Boolean} rotateable can the body be rotated by clicking on it..
55 * @config {Boolean} rotated is the body rotated when rendered...
58 * Create a new Container
59 * @param {Object} config The config object
62 Roo.bootstrap.Card = function(config){
63 Roo.bootstrap.Card.superclass.constructor.call(this, config);
69 * When a element a card is dropped
70 * @param {Roo.bootstrap.Element} this
71 * @param {Roo.Element} n the node being dropped?
72 * @param {Object} dd Drag and drop data
73 * @param {Roo.EventObject} e
74 * @param {Roo.EventObject} data the data passed via getDragData
82 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
87 margin: '', /// may be better in component?
126 childContainer : false,
127 dropEl : false, /// the dom placeholde element that indicates drop location.
129 layoutCls : function()
133 Roo.log(this.margin_bottom.length);
134 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
135 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
137 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
138 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
140 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
141 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
145 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
146 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
147 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v]
151 // more generic support?
159 // Roo.log("Call onRender: " + this.xtype);
160 /* We are looking at something like this.
162 <img src="..." class="card-img-top" alt="...">
163 <div class="card-body">
164 <h5 class="card-title">Card title</h5>
165 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
167 >> this bit is really the body...
168 <div> << we will ad dthis in hopefully it will not break shit.
170 ** card text does not actually have any styling...
172 <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>
175 <a href="#" class="card-link">Card link</a>
178 <div class="card-footer">
179 <small class="text-muted">Last updated 3 mins ago</small>
183 getAutoCreate : function(){
191 if (this.weight.length && this.weight != 'light') {
192 cfg.cls += ' text-white';
194 cfg.cls += ' text-dark'; // need as it's nested..
196 if (this.weight.length) {
197 cfg.cls += ' bg-' + this.weight;
200 cfg.cls += this.layoutCls();
203 if (this.header.length) {
205 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
214 cls : 'card-header d-none',
219 if (this.collapsable) {
222 cls : 'd-block user-select-none',
226 cls : 'roo-collapse-toggle fa fa-chevron-down float-right ' + (this.collapsed ? 'collapsed' : '')
231 hdr.cn.push(hdr_ctr);
233 if (this.header.length) {
236 cls: 'roo-card-header-ctr',
241 if (this.header_image.length) {
244 cls : 'card-img-top',
245 src: this.header_image // escape?
250 cls : 'card-img-top d-none'
256 cls : 'card-body' + (this.html === false ? ' d-none' : ''),
260 if (this.collapsable || this.rotateable) {
263 cls : 'roo-collapsable collapse ' + (this.collapsed || this.rotated ? '' : 'show'),
270 if (this.title.length) {
274 src: this.title // escape?
278 if (this.subtitle.length) {
282 src: this.subtitle // escape?
288 cls : 'roo-card-body-ctr'
291 if (this.html.length) {
297 // fixme ? handle objects?
299 if (this.footer.length) {
302 cls : 'card-footer ' + (this.rotated ? 'd-none' : ''),
307 cfg.cn.push({cls : 'card-footer d-none'});
316 getCardHeader : function()
318 var ret = this.el.select('.card-header',true).first();
319 if (ret.hasClass('d-none')) {
320 ret.removeClass('d-none');
325 getCardFooter : function()
327 var ret = this.el.select('.card-footer',true).first();
328 if (ret.hasClass('d-none')) {
329 ret.removeClass('d-none');
334 getCardImageTop : function()
336 var ret = this.el.select('.card-img-top',true).first();
337 if (ret.hasClass('d-none')) {
338 ret.removeClass('d-none');
344 getChildContainer : function()
350 return this.el.select('.roo-card-body-ctr',true).first();
353 initEvents: function()
356 this.bodyEl = this.getChildContainer();
358 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
359 containerScroll: true,
360 ddGroup: this.drag_group || 'default_card_drag_group'
362 this.dragZone.getDragData = this.getDragData.createDelegate(this);
365 this.dropZone = new Roo.dd.DropZone(this.el.select('.card-body',true).first() , {
366 containerScroll: true,
367 ddGroup: this.drop_group || 'default_card_drag_group'
369 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
370 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
371 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
372 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
373 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
376 if (this.collapsable) {
377 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
379 if (this.rotateable) {
380 this.el.select('.card-header',true).on('click', this.onToggleRotate, this);
384 getDragData : function(e)
386 var target = this.getEl();
388 //this.handleSelection(e);
398 dragData.ddel = target.dom ; // the div element
399 Roo.log(target.getWidth( ));
400 dragData.ddel.style.width = target.getWidth() + 'px';
407 * Part of the Roo.dd.DropZone interface. If no target node is found, the
408 * whole Element becomes the target, and this causes the drop gesture to append.
410 getTargetFromEvent : function(e, dragged_card_el)
412 var target = e.getTarget();
413 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
414 target = target.parentNode;
425 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
426 // see if target is one of the 'cards'...
429 //Roo.log(this.items.length);
434 for (var i = 0;i< this.items.length;i++) {
436 if (!this.items[i].el.hasClass('card')) {
439 pos = this.getDropPoint(e, this.items[i].el.dom);
441 cards_len = ret.cards.length;
442 //Roo.log(this.items[i].el.dom.id);
443 ret.cards.push(this.items[i]);
445 if (ret.card_n < 0 && pos == 'above') {
446 ret.position = cards_len > 0 ? 'below' : pos;
447 ret.items_n = i > 0 ? i - 1 : 0;
448 ret.card_n = cards_len > 0 ? cards_len - 1 : 0;
449 ret.card = ret.cards[ret.card_n];
452 if (!ret.cards.length) {
454 ret.position = 'below';
458 // could not find a card.. stick it at the end..
459 if (ret.card_n < 0) {
460 ret.card_n = last_card_n;
461 ret.card = ret.cards[last_card_n];
462 ret.items_n = this.items.indexOf(ret.cards[last_card_n]);
463 ret.position = 'below';
466 if (this.items[ret.items_n].el == dragged_card_el) {
470 if (ret.position == 'below') {
471 var card_after = ret.card_n+1 == ret.cards.length ? false : ret.cards[ret.card_n+1];
473 if (card_after && card_after.el == dragged_card_el) {
480 var card_before = ret.card_n > 0 ? ret.cards[ret.card_n-1] : false;
482 if (card_before && card_before.el == dragged_card_el) {
489 onNodeEnter : function(n, dd, e, data){
492 onNodeOver : function(n, dd, e, data)
495 var target_info = this.getTargetFromEvent(e,data.source.el);
496 if (target_info === false) {
497 this.dropPlaceHolder('hide');
500 Roo.log(['getTargetFromEvent', target_info ]);
503 this.dropPlaceHolder('show', target_info,data);
507 onNodeOut : function(n, dd, e, data){
508 this.dropPlaceHolder('hide');
511 onNodeDrop : function(n, dd, e, data)
514 // call drop - return false if
516 // this could actually fail - if the Network drops..
517 // we will ignore this at present..- client should probably reload
518 // the whole set of cards if stuff like that fails.
521 var info = this.getTargetFromEvent(e,data.source.el);
522 if (info === false) {
526 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
530 this.dropPlaceHolder('hide');
532 // do the dom manipulation first..
533 var dom = data.source.el.dom;
534 dom.parentNode.removeChild(dom);
537 if (info.card !== true) {
538 var cardel = info.card.el.dom;
540 if (info.position == 'above') {
541 cardel.parentNode.insertBefore(dom, cardel);
542 } else if (cardel.nextSibling) {
543 cardel.parentNode.insertBefore(dom,cardel.nextSibling);
545 cardel.parentNode.append(dom);
549 this.bodyEl.dom.append(dom);
552 //FIXME HANDLE card = true
554 // add this to the correct place in items.
558 // remove Card from items.
560 var old_parent = data.source.parent();
562 old_parent.items = old_parent.items.filter(function(e) { return e != data.source });
564 if (this.items.length) {
566 Roo.log([info.items_n, info.position, this.items.length])
567 for (var i =0; i < this.items.length; i++) {
568 if (i == info.items_n && info.position == 'above') {
569 nitems.push(data.source);
571 nitems.push(this.items[i]);
572 if (i == info.items_n && info.position == 'below') {
573 nitems.push(data.source);
579 this.items.push(data.source);
587 /** Decide whether to drop above or below a View node. */
588 getDropPoint : function(e, n, dd)
593 if (n == this.bodyEl.dom) {
596 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
597 var c = t + (b - t) / 2;
598 var y = Roo.lib.Event.getPageY(e);
605 onToggleCollapse : function(e)
607 if (this.collapsed) {
608 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
609 this.el.select('.roo-collapsable').addClass('show');
610 this.collapsed = false;
613 this.el.select('.roo-collapse-toggle').addClass('collapsed');
614 this.el.select('.roo-collapsable').removeClass('show');
615 this.collapsed = true;
620 onToggleRotate : function(e)
622 this.el.select('.roo-collapsable').first().removeClass('show');
623 this.el.select('.roo-collapsable').first().removeClass('show');
626 this.el.select('.roo-collapsable').addClass('show');
627 this.rotated = false;
630 this.el.select('.roo-collapse-toggle').addClass('collapsed');
631 this.el.select('.roo-collapsable').removeClass('show');
637 dropPlaceHolder: function (action, info, data)
639 if (this.dropEl === false) {
640 this.dropEl = Roo.DomHelper.append(this.bodyEl, {
644 this.dropEl.removeClass(['d-none', 'd-block']);
645 if (action == 'hide') {
647 this.dropEl.addClass('d-none');
650 // FIXME - info.card == true!!!
651 this.dropEl.dom.parentNode.removeChild(this.dropEl.dom);
653 if (info.card !== true) {
654 var cardel = info.card.el.dom;
656 if (info.position == 'above') {
657 cardel.parentNode.insertBefore(this.dropEl.dom, cardel);
658 } else if (cardel.nextSibling) {
659 cardel.parentNode.insertBefore(this.dropEl.dom,cardel.nextSibling);
661 cardel.parentNode.append(this.dropEl.dom);
665 this.bodyEl.dom.append(this.dropEl.dom);
668 this.dropEl.addClass('d-block roo-card-dropzone');
670 this.dropEl.setHeight( Roo.get(data.ddel).getHeight() );