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
54 * Create a new Container
55 * @param {Object} config The config object
58 Roo.bootstrap.Card = function(config){
59 Roo.bootstrap.Card.superclass.constructor.call(this, config);
67 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
72 margin: '', /// may be better in component?
106 childContainer : false,
108 layoutCls : function()
112 Roo.log(this.margin_bottom.length);
113 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
114 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
116 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
117 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
119 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
120 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
124 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
125 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
126 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v]
130 // more generic support?
138 // Roo.log("Call onRender: " + this.xtype);
139 /* We are looking at something like this.
141 <img src="..." class="card-img-top" alt="...">
142 <div class="card-body">
143 <h5 class="card-title">Card title</h5>
144 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
146 >> this bit is really the body...
147 <div> << we will ad dthis in hopefully it will not break shit.
149 ** card text does not actually have any styling...
151 <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>
154 <a href="#" class="card-link">Card link</a>
157 <div class="card-footer">
158 <small class="text-muted">Last updated 3 mins ago</small>
162 getAutoCreate : function(){
170 if (this.weight.length && this.weight != 'light') {
171 cfg.cls += ' text-white';
173 cfg.cls += ' text-dark'; // need as it's nested..
175 if (this.weight.length) {
176 cfg.cls += ' bg-' + this.weight;
179 cfg.cls += this.layoutCls();
181 if (this.header.length) {
183 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
185 html : this.header // escape?
190 cls : 'card-header d-none'
193 if (this.header_image.length) {
196 cls : 'card-img-top',
197 src: this.header_image // escape?
202 cls : 'card-img-top d-none'
213 if (this.title.length) {
217 src: this.title // escape?
221 if (this.subtitle.length) {
225 src: this.subtitle // escape?
231 cls : 'roo-card-body-ctr'
234 if (this.html.length) {
240 // fixme ? handle objects?
241 if (this.footer.length) {
245 html: this.footer // escape?
254 getCardHeader : function()
256 var ret = this.el.select('.card-header',true).first();
257 if (ret.hasClass('d-none')) {
258 ret.removeClass('d-none');
264 getCardImageTop : function()
266 var ret = this.el.select('.card-img-top',true).first();
267 if (ret.hasClass('d-none')) {
268 ret.removeClass('d-none');
274 getChildContainer : function()
280 return this.el.select('.roo-card-body-ctr',true).first();
283 initEvents: function()
286 this.bodyEl = this.getChildContainer();
288 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
289 containerScroll: true,
290 ddGroup: this.drag_group || 'default_card_drag_group'
292 this.dragZone.getDragData = this.getDragData.createDelegate(this);
295 this.dropZone = new Roo.dd.DropZone(this.getChildContainer(), {
296 containerScroll: true,
297 ddGroup: his.drop_group || 'default_card_drag_group'
299 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
300 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
301 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
302 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
303 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
308 getDragData : function(e) {
309 var target = this.getEl();
311 //this.handleSelection(e);
321 dragData.ddel = target.dom ; // the div element
322 Roo.log(target.getWidth( ));
323 dragData.ddel.style.width = target.getWidth() + 'px';
330 * Part of the Roo.dd.DropZone interface. If no target node is found, the
331 * whole Element becomes the target, and this causes the drop gesture to append.
333 getTargetFromEvent : function(e)
335 var target = e.getTarget();
336 while ((target !== null) && (target.parentNode != this.bodyEl.dom)) {
337 target = target.parentNode;
340 target = this.el.dom.lastChild || this.el.dom;
342 Roo.log(['getTargetFromEvent', target]);
346 onNodeEnter : function(n, dd, e, data){
349 onNodeOver : function(n, dd, e, data)
351 var pt = this.getDropPoint(e, n, dd);
352 // set the insert point style on the target node
353 var dragElClass = this.dropNotAllowed;
357 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
358 targetElClass = "x-view-drag-insert-above";
360 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
361 targetElClass = "x-view-drag-insert-below";
363 if (this.lastInsertClass != targetElClass){
364 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
365 this.lastInsertClass = targetElClass;
370 onNodeOut : function(n, dd, e, data){
371 this.removeDropIndicators(n);
373 onNodeDrop : function(n, dd, e, data)
377 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
380 var pt = this.getDropPoint(e, n, dd);
381 var insertAt = (n == this.bodyEl.dom) ? this.nodes.length : n.nodeIndex;
382 if (pt == "below") { insertAt++; }
383 for (var i = 0; i < data.records.length; i++) {
384 var r = data.records[i];
385 var dup = this.store.getById(r.id);
386 if (dup && (dd != this.dragZone)) {
387 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
390 this.store.insert(insertAt++, r.copy());
392 data.source.isDirtyFlag = true;
394 this.store.insert(insertAt++, r);
396 this.isDirtyFlag = true;
399 this.dragZone.cachedTarget = null;
403 /** Decide whether to drop above or below a View node. */
404 getDropPoint : function(e, n, dd)
406 if (n == this.bodyEl.dom) {
409 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
410 var c = t + (b - t) / 2;
411 var y = Roo.lib.Event.getPageY(e);