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 ' + (this.collapsed ? 'collapsed' : '')
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?
294 if (this.footer.length) {
302 cfg.cn.push({cls : 'card-footer d-none'});
311 getCardHeader : function()
313 var ret = this.el.select('.card-header',true).first();
314 if (ret.hasClass('d-none')) {
315 ret.removeClass('d-none');
320 getCardFooter : function()
322 var ret = this.el.select('.card-footer',true).first();
323 if (ret.hasClass('d-none')) {
324 ret.removeClass('d-none');
329 getCardImageTop : function()
331 var ret = this.el.select('.card-img-top',true).first();
332 if (ret.hasClass('d-none')) {
333 ret.removeClass('d-none');
339 getChildContainer : function()
345 return this.el.select('.roo-card-body-ctr',true).first();
348 initEvents: function()
351 this.bodyEl = this.getChildContainer();
353 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
354 containerScroll: true,
355 ddGroup: this.drag_group || 'default_card_drag_group'
357 this.dragZone.getDragData = this.getDragData.createDelegate(this);
360 this.dropZone = new Roo.dd.DropZone(this.el.select('.card-body',true).first() , {
361 containerScroll: true,
362 ddGroup: this.drop_group || 'default_card_drag_group'
364 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
365 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
366 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
367 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
368 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
371 if (this.collapsable) {
372 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
375 getDragData : function(e)
377 var target = this.getEl();
379 //this.handleSelection(e);
389 dragData.ddel = target.dom ; // the div element
390 Roo.log(target.getWidth( ));
391 dragData.ddel.style.width = target.getWidth() + 'px';
398 * Part of the Roo.dd.DropZone interface. If no target node is found, the
399 * whole Element becomes the target, and this causes the drop gesture to append.
401 getTargetFromEvent : function(e, dragged_card_el)
403 var target = e.getTarget();
404 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
405 target = target.parentNode;
416 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
417 // see if target is one of the 'cards'...
420 //Roo.log(this.items.length);
425 for (var i = 0;i< this.items.length;i++) {
427 if (!this.items[i].el.hasClass('card')) {
430 pos = this.getDropPoint(e, this.items[i].el.dom);
432 cards_len = ret.cards.length;
433 //Roo.log(this.items[i].el.dom.id);
434 ret.cards.push(this.items[i]);
436 if (ret.card_n < 0 && pos == 'above') {
437 ret.position = cards_len > 0 ? 'below' : pos;
438 ret.items_n = i > 0 ? i - 1 : 0;
439 ret.card_n = cards_len > 0 ? cards_len - 1 : 0;
440 ret.card = ret.cards[ret.card_n];
443 if (!ret.cards.length) {
445 ret.position = below;
449 // could not find a card.. stick it at the end..
450 if (ret.card_n < 0) {
451 ret.card_n = last_card_n;
452 ret.card = ret.cards[last_card_n];
453 ret.items_n = this.items.indexOf(ret.cards[last_card_n]);
457 if (this.items[ret.items_n].el == dragged_card_el) {
461 if (ret.position == 'below') {
462 var card_after = ret.card_n+1 == ret.cards.length ? false : ret.cards[ret.card_n+1];
464 if (card_after && card_after.el == dragged_card_el) {
471 var card_before = ret.card_n > 0 ? ret.cards[ret.card_n-1] : false;
473 if (card_before && card_before.el == dragged_card_el) {
480 onNodeEnter : function(n, dd, e, data){
483 onNodeOver : function(n, dd, e, data)
486 var target_info = this.getTargetFromEvent(e,data.source.el);
487 if (target_info === false) {
488 this.dropPlaceHolder('hide');
491 Roo.log(['getTargetFromEvent', target_info ]);
494 this.dropPlaceHolder('show', target_info,data);
498 onNodeOut : function(n, dd, e, data){
499 this.dropPlaceHolder('hide');
502 onNodeDrop : function(n, dd, e, data)
505 // call drop - return false if
506 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
510 var target_info = this.getTargetFromEvent(e,data.source.el);
511 if (target_info === false) {
515 this.dropPlaceHolder('hide');
517 // do the dom manipulation first..
518 var dom = data.source.el.dom;
519 dom.parentNode.removeChild(dom);
523 // remove Card from items.
525 var old_parent = data.source.parent();
527 old_parent.items = old_parent.items.filter(function(e) { return e != data.source });
528 if (this.items.length) {
530 for (var i =0; i < this.items; i++) {
531 if (i == target_info.item_n && target_info.position == 'before') {
532 nitems.push(data.source);
534 nitems.push(this.items[i]);
535 if (i == target_info.item_n && target_info.position == 'after') {
536 nitems.push(data.source);
541 this.items.push(data.source);
545 //FIXME HANDLE card = true
547 // add this to the correct place in items.
553 /** Decide whether to drop above or below a View node. */
554 getDropPoint : function(e, n, dd)
559 if (n == this.bodyEl.dom) {
562 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
563 var c = t + (b - t) / 2;
564 var y = Roo.lib.Event.getPageY(e);
571 onToggleCollapse : function(e)
573 if (this.collapsed) {
574 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
575 this.el.select('.roo-collapsable').addClass('show');
576 this.collapsed = false;
579 this.el.select('.roo-collapse-toggle').addClass('collapsed');
580 this.el.select('.roo-collapsable').removeClass('show');
581 this.collapsed = true;
585 dropPlaceHolder: function (action, info, data)
587 if (this.dropEl === false) {
588 this.dropEl = Roo.DomHelper.append(this.bodyEl, {
592 this.dropEl.removeClass(['d-none', 'd-block']);
593 if (action == 'hide') {
595 this.dropEl.addClass('d-none');
598 // FIXME - info.card == true!!!
599 this.dropEl.dom.parentNode.removeChild(this.dropEl.dom);
601 if (info.card !== true) {
602 var cardel = info.card.el.dom;
604 if (info.position == 'above') {
605 cardel.parentNode.insertBefore(this.dropEl.dom, cardel);
606 } else if (cardel.nextSibling) {
607 cardel.parentNode.insertBefore(this.dropEl.dom,cardel.nextSibling);
609 cardel.parentNode.append(this.dropEl.dom);
613 this.bodyEl.dom.append(this.dropEl.dom);
616 this.dropEl.addClass('d-block roo-card-dropzone');
618 this.dropEl.setHeight( Roo.get(data.ddel).getHeight() );