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.EventObject} e
76 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
81 margin: '', /// may be better in component?
118 childContainer : false,
119 dropEl : false, /// the dom placeholde element that indicates drop location.
121 layoutCls : function()
125 Roo.log(this.margin_bottom.length);
126 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
127 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
129 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
130 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
132 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
133 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
137 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
138 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
139 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v]
143 // more generic support?
151 // Roo.log("Call onRender: " + this.xtype);
152 /* We are looking at something like this.
154 <img src="..." class="card-img-top" alt="...">
155 <div class="card-body">
156 <h5 class="card-title">Card title</h5>
157 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
159 >> this bit is really the body...
160 <div> << we will ad dthis in hopefully it will not break shit.
162 ** card text does not actually have any styling...
164 <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>
167 <a href="#" class="card-link">Card link</a>
170 <div class="card-footer">
171 <small class="text-muted">Last updated 3 mins ago</small>
175 getAutoCreate : function(){
183 if (this.weight.length && this.weight != 'light') {
184 cfg.cls += ' text-white';
186 cfg.cls += ' text-dark'; // need as it's nested..
188 if (this.weight.length) {
189 cfg.cls += ' bg-' + this.weight;
192 cfg.cls += this.layoutCls();
195 if (this.header.length) {
197 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
206 cls : 'card-header d-none',
211 if (this.collapsable) {
214 cls : 'd-block user-select-none',
218 cls : 'roo-collapse-toggle fa fa-chevron-down float-right'
223 hdr.cn.push(hdr_ctr);
225 if (this.header.length) {
228 cls: 'roo-card-header-ctr',
233 if (this.header_image.length) {
236 cls : 'card-img-top',
237 src: this.header_image // escape?
242 cls : 'card-img-top d-none'
252 if (this.collapsable) {
255 cls : 'roo-collapsable collapse ' + (this.collapsed ? '' : 'show'),
262 if (this.title.length) {
266 src: this.title // escape?
270 if (this.subtitle.length) {
274 src: this.subtitle // escape?
280 cls : 'roo-card-body-ctr'
283 if (this.html.length) {
289 // fixme ? handle objects?
290 if (this.footer.length) {
294 html: this.footer // escape?
303 getCardHeader : function()
305 var ret = this.el.select('.card-header',true).first();
306 if (ret.hasClass('d-none')) {
307 ret.removeClass('d-none');
313 getCardImageTop : function()
315 var ret = this.el.select('.card-img-top',true).first();
316 if (ret.hasClass('d-none')) {
317 ret.removeClass('d-none');
323 getChildContainer : function()
329 return this.el.select('.roo-card-body-ctr',true).first();
332 initEvents: function()
335 this.bodyEl = this.getChildContainer();
337 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
338 containerScroll: true,
339 ddGroup: this.drag_group || 'default_card_drag_group'
341 this.dragZone.getDragData = this.getDragData.createDelegate(this);
344 this.dropZone = new Roo.dd.DropZone(this.el.select('.card-body',true).first() , {
345 containerScroll: true,
346 ddGroup: this.drop_group || 'default_card_drag_group'
348 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
349 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
350 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
351 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
352 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
355 if (this.collapsable) {
356 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
359 getDragData : function(e)
361 var target = this.getEl();
363 //this.handleSelection(e);
373 dragData.ddel = target.dom ; // the div element
374 Roo.log(target.getWidth( ));
375 dragData.ddel.style.width = target.getWidth() + 'px';
382 * Part of the Roo.dd.DropZone interface. If no target node is found, the
383 * whole Element becomes the target, and this causes the drop gesture to append.
385 getTargetFromEvent : function(e, dragged_card_el)
387 var target = e.getTarget();
388 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
389 target = target.parentNode;
391 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
392 // see if target is one of the 'cards'...
395 //Roo.log(this.items.length);
396 var lpos = pos = cpos = false;
397 for (var i = 0;i< this.items.length;i++) {
399 if (!this.items[i].el.hasClass('card')) {
402 pos = this.getDropPoint(e, this.items[i].el.dom);
404 //Roo.log(this.items[i].el.dom.id);
405 cards.push(this.items[i]);
406 if (ctarget < 0 && pos == 'above') {
407 ctarget = i > 0 ? i - 1 : 0;
408 cpos = i > 0 ? 'below' : pos;
412 return [ true, 'below' ];
416 ctarget = cards.length -1;
419 if (cards[ctarget].el == dragged_card_el) {
423 if (cpos == 'below') {
424 var card_after = ctarget+1 == cards.length ? false : cards[ctarget+1];
426 // then above should not be dragged_card_el.
429 if (card_after && card_after.el == dragged_card_el) {
432 return [ cards[ctarget], cpos ];
436 var card_before = ctarget > 0 ? cards[ctarget-1] : false;
439 if (card_before && card_before.el == dragged_card_el) {
443 return [ cards[ctarget], cpos ];
446 onNodeEnter : function(n, dd, e, data){
449 onNodeOver : function(n, dd, e, data)
452 var target_info = this.getTargetFromEvent(e,data.source.el);
453 if (target_info === false) {
454 this.dropPlaceHolder('hide');
457 Roo.log(['getTargetFromEvent', target_info[0].el.dom.id,target_info[1]]);
460 this.dropPlaceHolder('show', target_info,data);
464 onNodeOut : function(n, dd, e, data){
465 this.dropPlaceHolder('hide');
468 onNodeDrop : function(n, dd, e, data)
471 // call drop - return false if
472 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
478 var pt = this.getDropPoint(e, n, dd);
479 var insertAt = (n == this.bodyEl.dom) ? this.items.length : n.nodeIndex;
483 for (var i = 0; i < this.items.length; i++) {
484 var r = this.items[i];
485 //var dup = this.store.getById(r.id);
486 if (dup && (dd != this.dragZone)) {
487 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
490 this.store.insert(insertAt++, r.copy());
492 data.source.isDirtyFlag = true;
494 this.store.insert(insertAt++, r);
496 this.isDirtyFlag = true;
499 this.dragZone.cachedTarget = null;
503 /** Decide whether to drop above or below a View node. */
504 getDropPoint : function(e, n, dd)
509 if (n == this.bodyEl.dom) {
512 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
513 var c = t + (b - t) / 2;
514 var y = Roo.lib.Event.getPageY(e);
521 onToggleCollapse : function(e)
523 if (this.collapsed) {
524 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
525 this.el.select('.roo-collapsable').addClass('show');
526 this.collapsed = false;
529 this.el.select('.roo-collapse-toggle').addClass('collapsed');
530 this.el.select('.roo-collapsable').removeClass('show');
531 this.collapsed = true;
535 dropPlaceHolder: function (action, where_ar, data)
537 if (this.dropEl === false) {
538 this.dropEl = Roo.DomHelper.append(this.bodyEl, {
542 this.dropEl.removeClass(['d-none', 'd-block']);
543 if (action == 'hide') {
545 this.dropEl.addClass('d-none');
548 var cardel = where_ar[0].el.dom;
550 this.dropEl.dom.parentNode.removeChild(this.dropEl.dom);
551 if (where_ar[1] == 'above') {
552 cardel.parentNode.insertBefore(this.dropEl.dom, cardel);
553 } else if (cardel.nextSibling) {
554 cardel.parentNode.insertBefore(this.dropEl.dom,cardel.nextSibling);
556 cardel.parentNode.append(this.dropEl.dom);
558 this.dropEl.addClass('d-block roo-card-dropzone');
560 this.dropEl.setHeight( Roo.get(data.ddel).getHeight() );