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);
68 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
73 margin: '', /// may be better in component?
110 childContainer : false,
111 dropEl : false, /// the dom placeholde element that indicates drop location.
113 layoutCls : function()
117 Roo.log(this.margin_bottom.length);
118 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
119 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
121 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
122 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
124 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
125 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
129 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
130 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
131 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v]
135 // more generic support?
143 // Roo.log("Call onRender: " + this.xtype);
144 /* We are looking at something like this.
146 <img src="..." class="card-img-top" alt="...">
147 <div class="card-body">
148 <h5 class="card-title">Card title</h5>
149 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
151 >> this bit is really the body...
152 <div> << we will ad dthis in hopefully it will not break shit.
154 ** card text does not actually have any styling...
156 <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>
159 <a href="#" class="card-link">Card link</a>
162 <div class="card-footer">
163 <small class="text-muted">Last updated 3 mins ago</small>
167 getAutoCreate : function(){
175 if (this.weight.length && this.weight != 'light') {
176 cfg.cls += ' text-white';
178 cfg.cls += ' text-dark'; // need as it's nested..
180 if (this.weight.length) {
181 cfg.cls += ' bg-' + this.weight;
184 cfg.cls += this.layoutCls();
187 if (this.header.length) {
189 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
198 cls : 'card-header d-none',
203 if (this.collapsable) {
206 cls : 'd-block user-select-none',
210 cls : 'roo-collapse-toggle fa fa-chevron-down float-right'
215 hdr.cn.push(hdr_ctr);
217 if (this.header.length) {
220 cls: 'roo-card-header-ctr',
225 if (this.header_image.length) {
228 cls : 'card-img-top',
229 src: this.header_image // escape?
234 cls : 'card-img-top d-none'
244 if (this.collapsable) {
247 cls : 'roo-collapsable collapse ' + (this.collapsed ? '' : 'show'),
254 if (this.title.length) {
258 src: this.title // escape?
262 if (this.subtitle.length) {
266 src: this.subtitle // escape?
272 cls : 'roo-card-body-ctr'
275 if (this.html.length) {
281 // fixme ? handle objects?
282 if (this.footer.length) {
286 html: this.footer // escape?
295 getCardHeader : function()
297 var ret = this.el.select('.card-header',true).first();
298 if (ret.hasClass('d-none')) {
299 ret.removeClass('d-none');
305 getCardImageTop : function()
307 var ret = this.el.select('.card-img-top',true).first();
308 if (ret.hasClass('d-none')) {
309 ret.removeClass('d-none');
315 getChildContainer : function()
321 return this.el.select('.roo-card-body-ctr',true).first();
324 initEvents: function()
327 this.bodyEl = this.getChildContainer();
329 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
330 containerScroll: true,
331 ddGroup: this.drag_group || 'default_card_drag_group'
333 this.dragZone.getDragData = this.getDragData.createDelegate(this);
336 this.dropZone = new Roo.dd.DropZone(this.getChildContainer(), {
337 containerScroll: true,
338 ddGroup: this.drop_group || 'default_card_drag_group'
340 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
341 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
342 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
343 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
344 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
347 if (this.collapsable) {
348 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
351 getDragData : function(e) {
352 var target = this.getEl();
354 //this.handleSelection(e);
364 dragData.ddel = target.dom ; // the div element
365 Roo.log(target.getWidth( ));
366 dragData.ddel.style.width = target.getWidth() + 'px';
373 * Part of the Roo.dd.DropZone interface. If no target node is found, the
374 * whole Element becomes the target, and this causes the drop gesture to append.
376 getTargetFromEvent : function(e)
378 var target = e.getTarget();
379 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
380 target = target.parentNode;
382 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
383 // see if target is one of the 'cards'...
386 //Roo.log(this.items.length);
387 var lpos = pos = false;
388 for (var i = 0;i< this.items.length;i++) {
390 if (!this.items[i].el.hasClass('card')) {
393 pos = this.getDropPoint(e, this.items[i].el.dom);
395 //Roo.log(this.items[i].el.dom.id);
396 cards.push(this.items[i]);
397 if (pos == 'above') {
398 ctarget = this.items[i > 0 ? i-1 : 0];
399 pos = i > 0 ? 'below' : pos;
405 ctarget = cards[cards.length-1] || this.el.dom;
410 //Roo.log(['getTargetFromEvent', ctarget]);
411 return [ ctarget, pos ];
414 onNodeEnter : function(n, dd, e, data){
417 onNodeOver : function(n, dd, e, data)
419 // Roo.log(['onNodeOver'])
421 var pt = this.getDropPoint(e, n, dd);
422 // set the insert point style on the target node
423 //var dragElClass = this.dropNotAllowed;
425 this.dropPlaceHolder('hide');
430 target_info = this.getTargetFromEvent(e);
431 Roo.log(['getTargetFromEvent', target_info[0].el.dom.id,target_info[1]]);
434 this.dropPlaceHolder('show', targetinfo,data);
435 return false; //dragElClass;
437 onNodeOut : function(n, dd, e, data){
438 //this.removeDropIndicators(n);
440 onNodeDrop : function(n, dd, e, data)
444 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
447 var pt = this.getDropPoint(e, n, dd);
448 var insertAt = (n == this.bodyEl.dom) ? this.items.length : n.nodeIndex;
452 for (var i = 0; i < this.items.length; i++) {
453 var r = this.items[i];
454 //var dup = this.store.getById(r.id);
455 if (dup && (dd != this.dragZone)) {
456 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
459 this.store.insert(insertAt++, r.copy());
461 data.source.isDirtyFlag = true;
463 this.store.insert(insertAt++, r);
465 this.isDirtyFlag = true;
468 this.dragZone.cachedTarget = null;
472 /** Decide whether to drop above or below a View node. */
473 getDropPoint : function(e, n, dd)
478 if (n == this.bodyEl.dom) {
481 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
482 var c = t + (b - t) / 2;
483 var y = Roo.lib.Event.getPageY(e);
490 onToggleCollapse : function(e)
492 if (this.collapsed) {
493 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
494 this.el.select('.roo-collapsable').addClass('show');
495 this.collapsed = false;
498 this.el.select('.roo-collapse-toggle').addClass('collapsed');
499 this.el.select('.roo-collapsable').removeClass('show');
500 this.collapsed = true;
504 dropPlaceHolder: function (action, where_ar, data)
506 if (this.dropEl === false) {
507 this.dropEl = new Roo.DomHelper.append(this.dom.bodyEl, {
512 if (action == 'hide') {
513 this.dropEl.removeClass(['d-none', 'd-block']);
514 this.dropEl.addClass('d-none');
517 var cardel = where_ar[0].el.dom;
519 this.dropEl.parentNode.removeChild(this.dropEl);
520 if (where_ar[0] == 'before') {
521 this.cardel.parentNode.insertBefore(this.dropEl, cardel);
522 } else if (cardel.nextSibling) {
523 this.cardel.parentNode.insertBefore(this.dropEl,ns);
525 this.cardel.parentNode.append(this.dropEl);
527 this.cardel.style.width = "100%";
528 this.cardel.style.height = Roo.get(data.ddel).getHeight() + 'px';