2 * set the version of bootstrap based on the stylesheet...
6 Roo.bootstrap.version = ( function() {
8 Roo.each(document.styleSheets, function(s) {
9 if ( s.href && s.href.match(/css-bootstrap4/)) {
14 Roo.Element.prototype.visibilityMode = Roo.Element.DISPLAY;
17 })(); Roo.bootstrap.menu = Roo.bootstrap.menu || {};
18 Roo.bootstrap.nav = {};
20 Roo.bootstrap.form = {};Roo.bootstrap.panel = {};Roo.bootstrap.layout = {};/*
22 * Ext JS Library 1.1.1
23 * Copyright(c) 2006-2007, Ext JS, LLC.
25 * Originally Released Under LGPL - original licence link has changed is not relivant.
28 * <script type="text/javascript">
34 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
35 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
36 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
39 * @param {Object} config The config object
41 Roo.Shadow = function(config){
42 Roo.apply(this, config);
43 if(typeof this.mode != "string"){
44 this.mode = this.defaultMode;
46 var o = this.offset, a = {h: 0};
47 var rad = Math.floor(this.offset/2);
48 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
54 a.l -= this.offset + rad;
55 a.t -= this.offset + rad;
66 a.l -= (this.offset - rad);
67 a.t -= this.offset + rad;
69 a.w -= (this.offset - rad)*2;
80 a.l -= (this.offset - rad);
81 a.t -= (this.offset - rad);
83 a.w -= (this.offset + rad + 1);
84 a.h -= (this.offset + rad);
93 Roo.Shadow.prototype = {
96 * The shadow display mode. Supports the following options:<br />
97 * sides: Shadow displays on both sides and bottom only<br />
98 * frame: Shadow displays equally on all four sides<br />
99 * drop: Traditional bottom-right drop shadow (default)
103 * @cfg {String} offset
104 * The number of pixels to offset the shadow from the element (defaults to 4)
112 * Displays the shadow under the target element
113 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
115 show : function(target){
116 target = Roo.get(target);
118 this.el = Roo.Shadow.Pool.pull();
119 if(this.el.dom.nextSibling != target.dom){
120 this.el.insertBefore(target);
123 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
125 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
128 target.getLeft(true),
133 this.el.dom.style.display = "block";
137 * Returns true if the shadow is visible, else false
139 isVisible : function(){
140 return this.el ? true : false;
144 * Direct alignment when values are already available. Show must be called at least once before
145 * calling this method to ensure it is initialized.
146 * @param {Number} left The target element left position
147 * @param {Number} top The target element top position
148 * @param {Number} width The target element width
149 * @param {Number} height The target element height
151 realign : function(l, t, w, h){
155 var a = this.adjusts, d = this.el.dom, s = d.style;
157 s.left = (l+a.l)+"px";
158 s.top = (t+a.t)+"px";
159 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
161 if(s.width != sws || s.height != shs){
165 var cn = d.childNodes;
166 var sww = Math.max(0, (sw-12))+"px";
167 cn[0].childNodes[1].style.width = sww;
168 cn[1].childNodes[1].style.width = sww;
169 cn[2].childNodes[1].style.width = sww;
170 cn[1].style.height = Math.max(0, (sh-12))+"px";
180 this.el.dom.style.display = "none";
181 Roo.Shadow.Pool.push(this.el);
187 * Adjust the z-index of this shadow
188 * @param {Number} zindex The new z-index
190 setZIndex : function(z){
193 this.el.setStyle("z-index", z);
198 // Private utility class that manages the internal Shadow cache
199 Roo.Shadow.Pool = function(){
201 var markup = Roo.isIE ?
202 '<div class="x-ie-shadow"></div>' :
203 '<div class="x-shadow"><div class="xst"><div class="xstl"></div><div class="xstc"></div><div class="xstr"></div></div><div class="xsc"><div class="xsml"></div><div class="xsmc"></div><div class="xsmr"></div></div><div class="xsb"><div class="xsbl"></div><div class="xsbc"></div><div class="xsbr"></div></div></div>';
208 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
209 sh.autoBoxAdjust = false;
221 * base class for bootstrap elements.
225 Roo.bootstrap = Roo.bootstrap || {};
227 * @class Roo.bootstrap.Component
228 * @extends Roo.Component
230 * @children Roo.bootstrap.Component
231 * Bootstrap Component base class
232 * @cfg {String} cls css class
233 * @cfg {String} style any extra css
234 * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.)
235 * @cfg {Boolean} can_build_overlaid True if element can be rebuild from a HTML page
236 * @cfg {string} dataId cutomer id
237 * @cfg {string} name Specifies name attribute
238 * @cfg {string} tooltip Text for the tooltip
239 * @cfg {string} container_method method to fetch parents container element (used by NavHeaderbar - getHeaderChildContainer)
240 * @cfg {string|object} visibilityEl (el|parent) What element to use for visibility (@see getVisibilityEl())
243 * Do not use directly - it does not do anything..
244 * @param {Object} config The config object
249 Roo.bootstrap.Component = function(config){
250 Roo.bootstrap.Component.superclass.constructor.call(this, config);
254 * @event childrenrendered
255 * Fires when the children have been rendered..
256 * @param {Roo.bootstrap.Component} this
258 "childrenrendered" : true
267 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, {
270 allowDomMove : false, // to stop relocations in parent onRender...
280 * Initialize Events for the element
282 initEvents : function() { },
288 can_build_overlaid : true,
290 container_method : false,
297 // returns the parent component..
298 return Roo.ComponentMgr.get(this.parentId)
304 onRender : function(ct, position)
306 // Roo.log("Call onRender: " + this.xtype);
308 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
311 if (this.el.attr('xtype')) {
312 this.el.attr('xtypex', this.el.attr('xtype'));
313 this.el.dom.removeAttribute('xtype');
323 var cfg = Roo.apply({}, this.getAutoCreate());
325 cfg.id = this.id || Roo.id();
327 // fill in the extra attributes
328 if (this.xattr && typeof(this.xattr) =='object') {
329 for (var i in this.xattr) {
330 cfg[i] = this.xattr[i];
335 cfg.dataId = this.dataId;
339 cfg.cls = (typeof(cfg.cls) == 'undefined' ? this.cls : cfg.cls) + ' ' + this.cls;
342 if (this.style) { // fixme needs to support more complex style data.
343 cfg.style = (typeof(cfg.style) == 'undefined' ? this.style : cfg.style) + '; ' + this.style;
347 cfg.name = this.name;
350 this.el = ct.createChild(cfg, position);
353 this.tooltipEl().attr('tooltip', this.tooltip);
356 if(this.tabIndex !== undefined){
357 this.el.dom.setAttribute('tabIndex', this.tabIndex);
364 * Fetch the element to add children to
365 * @return {Roo.Element} defaults to this.el
367 getChildContainer : function()
371 getDocumentBody : function() // used by menus - as they are attached to the body so zIndexes work
373 return Roo.get(document.body);
377 * Fetch the element to display the tooltip on.
378 * @return {Roo.Element} defaults to this.el
380 tooltipEl : function()
385 addxtype : function(tree,cntr)
389 cn = Roo.factory(tree);
390 //Roo.log(['addxtype', cn]);
392 cn.parentType = this.xtype; //??
393 cn.parentId = this.id;
395 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
396 if (typeof(cn.container_method) == 'string') {
397 cntr = cn.container_method;
401 var has_flexy_each = (typeof(tree['flexy:foreach']) != 'undefined');
403 var has_flexy_if = (typeof(tree['flexy:if']) != 'undefined');
405 var build_from_html = Roo.XComponent.build_from_html;
407 var is_body = (tree.xtype == 'Body') ;
409 var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
411 var self_cntr_el = Roo.get(this[cntr](false));
413 // do not try and build conditional elements
414 if ((has_flexy_each || has_flexy_if || this.can_build_overlaid == false ) && build_from_html) {
418 if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
419 if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
420 return this.addxtypeChild(tree,cntr, is_body);
423 var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
426 return this.addxtypeChild(Roo.apply({}, tree),cntr);
429 Roo.log('skipping render');
435 if (!build_from_html) {
439 // this i think handles overlaying multiple children of the same type
440 // with the sam eelement.. - which might be buggy..
442 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
448 if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
452 ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
459 addxtypeChild : function (tree, cntr, is_body)
461 Roo.debug && Roo.log('addxtypeChild:' + cntr);
463 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
466 var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
467 (typeof(tree['flexy:foreach']) != 'undefined');
471 skip_children = false;
472 // render the element if it's not BODY.
475 // if parent was disabled, then do not try and create the children..
476 if(!this[cntr](true)){
481 cn = Roo.factory(tree);
483 cn.parentType = this.xtype; //??
484 cn.parentId = this.id;
486 var build_from_html = Roo.XComponent.build_from_html;
489 // does the container contain child eleemnts with 'xtype' attributes.
490 // that match this xtype..
491 // note - when we render we create these as well..
492 // so we should check to see if body has xtype set.
493 if (build_from_html && Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
495 var self_cntr_el = Roo.get(this[cntr](false));
496 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
498 //Roo.log(Roo.XComponent.build_from_html);
499 //Roo.log("got echild:");
502 // there is a scenario where some of the child elements are flexy:if (and all of the same type)
503 // and are not displayed -this causes this to use up the wrong element when matching.
504 // at present the only work around for this is to nest flexy:if elements in another element that is always rendered.
507 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
508 // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
514 //echild.dom.removeAttribute('xtype');
516 Roo.debug && Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
517 Roo.debug && Roo.log(self_cntr_el);
518 Roo.debug && Roo.log(echild);
519 Roo.debug && Roo.log(cn);
525 // if object has flexy:if - then it may or may not be rendered.
526 if (build_from_html && has_flexy && !cn.el && cn.can_build_overlaid) {
527 // skip a flexy if element.
528 Roo.debug && Roo.log('skipping render');
529 Roo.debug && Roo.log(tree);
531 Roo.debug && Roo.log('skipping all children');
532 skip_children = true;
537 // actually if flexy:foreach is found, we really want to create
538 // multiple copies here...
540 //Roo.log(this[cntr]());
541 // some elements do not have render methods.. like the layouts...
543 if(this[cntr](true) === false){
548 cn.render && cn.render(this[cntr](true));
551 // then add the element..
558 if (typeof (tree.menu) != 'undefined') {
559 tree.menu.parentType = cn.xtype;
560 tree.menu.triggerEl = cn.el;
561 nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
565 if (!tree.items || !tree.items.length) {
567 //Roo.log(["no children", this]);
572 var items = tree.items;
575 //Roo.log(items.length);
577 if (!skip_children) {
578 for(var i =0;i < items.length;i++) {
579 // Roo.log(['add child', items[i]]);
580 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
586 //Roo.log("fire childrenrendered");
588 cn.fireEvent('childrenrendered', this);
594 * Set the element that will be used to show or hide
596 setVisibilityEl : function(el)
598 this.visibilityEl = el;
602 * Get the element that will be used to show or hide
604 getVisibilityEl : function()
606 if (typeof(this.visibilityEl) == 'object') {
607 return this.visibilityEl;
610 if (typeof(this.visibilityEl) == 'string') {
611 return this.visibilityEl == 'parent' ? this.parent().getEl() : this.getEl();
618 * Show a component - removes 'hidden' class
622 if(!this.getVisibilityEl()){
626 this.getVisibilityEl().removeClass(['hidden','d-none']);
628 this.fireEvent('show', this);
633 * Hide a component - adds 'hidden' class
637 if(!this.getVisibilityEl()){
641 this.getVisibilityEl().addClass(['hidden','d-none']);
643 this.fireEvent('hide', this);
656 * @class Roo.bootstrap.Element
657 * @extends Roo.bootstrap.Component
658 * @children Roo.bootstrap.Component
659 * Bootstrap Element class (basically a DIV used to make random stuff )
661 * @cfg {String} html contents of the element
662 * @cfg {String} tag tag of the element
663 * @cfg {String} cls class of the element
664 * @cfg {Boolean} preventDefault (true|false) default false
665 * @cfg {Boolean} clickable (true|false) default false
666 * @cfg {String} role default blank - set to button to force cursor pointer
670 * Create a new Element
671 * @param {Object} config The config object
674 Roo.bootstrap.Element = function(config){
675 Roo.bootstrap.Element.superclass.constructor.call(this, config);
681 * When a element is chick
682 * @param {Roo.bootstrap.Element} this
683 * @param {Roo.EventObject} e
691 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
696 preventDefault: false,
701 getAutoCreate : function(){
705 // cls: this.cls, double assign in parent class Component.js :: onRender
708 if (this.role !== false) {
709 cfg.role = this.role;
715 initEvents: function()
717 Roo.bootstrap.Element.superclass.initEvents.call(this);
720 this.el.on('click', this.onClick, this);
726 onClick : function(e)
728 if(this.preventDefault){
732 this.fireEvent('click', this, e); // why was this double click before?
740 getValue : function()
742 return this.el.dom.innerHTML;
745 setValue : function(value)
747 this.el.dom.innerHTML = value;
762 * @class Roo.bootstrap.DropTarget
763 * @extends Roo.bootstrap.Element
764 * Bootstrap DropTarget class
766 * @cfg {string} name dropable name
769 * Create a new Dropable Area
770 * @param {Object} config The config object
773 Roo.bootstrap.DropTarget = function(config){
774 Roo.bootstrap.DropTarget.superclass.constructor.call(this, config);
780 * When a element is chick
781 * @param {Roo.bootstrap.Element} this
782 * @param {Roo.EventObject} e
788 Roo.extend(Roo.bootstrap.DropTarget, Roo.bootstrap.Element, {
791 getAutoCreate : function(){
796 initEvents: function()
798 Roo.bootstrap.DropTarget.superclass.initEvents.call(this);
799 this.dropZone = new Roo.dd.DropTarget(this.getEl(), {
802 drop : this.dragDrop.createDelegate(this),
803 enter : this.dragEnter.createDelegate(this),
804 out : this.dragOut.createDelegate(this),
805 over : this.dragOver.createDelegate(this)
809 this.dropZone.DDM.useCache = false // so data gets refreshed when we resize stuff
812 dragDrop : function(source,e,data)
814 // user has to decide how to impliment this.
817 //this.fireEvent('drop', this, source, e ,data);
821 dragEnter : function(n, dd, e, data)
823 // probably want to resize the element to match the dropped element..
825 this.originalSize = this.el.getSize();
826 this.el.setSize( n.el.getSize());
827 this.dropZone.DDM.refreshCache(this.name);
828 Roo.log([n, dd, e, data]);
831 dragOut : function(value)
833 // resize back to normal
835 this.el.setSize(this.originalSize);
836 this.dropZone.resetConstraints();
839 dragOver : function()
856 * @class Roo.bootstrap.Body
857 * @extends Roo.bootstrap.Component
858 * @children Roo.bootstrap.Component
859 * @parent none builder
860 * Bootstrap Body class
864 * @param {Object} config The config object
867 Roo.bootstrap.Body = function(config){
869 config = config || {};
871 Roo.bootstrap.Body.superclass.constructor.call(this, config);
872 this.el = Roo.get(config.el ? config.el : document.body );
873 if (this.cls && this.cls.length) {
874 Roo.get(document.body).addClass(this.cls);
878 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
880 is_body : true,// just to make sure it's constructed?
885 onRender : function(ct, position)
887 /* Roo.log("Roo.bootstrap.Body - onRender");
888 if (this.cls && this.cls.length) {
889 Roo.get(document.body).addClass(this.cls);
908 * @class Roo.bootstrap.ButtonGroup
909 * @extends Roo.bootstrap.Component
910 * Bootstrap ButtonGroup class
911 * @children Roo.bootstrap.Button Roo.bootstrap.form.Form
913 * @cfg {String} size lg | sm | xs (default empty normal)
914 * @cfg {String} align vertical | justified (default none)
915 * @cfg {String} direction up | down (default down)
916 * @cfg {Boolean} toolbar false | true
917 * @cfg {Boolean} btn true | false
922 * @param {Object} config The config object
925 Roo.bootstrap.ButtonGroup = function(config){
926 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
929 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
937 getAutoCreate : function(){
943 cfg.html = this.html || cfg.html;
954 if (['vertical','justified'].indexOf(this.align)!==-1) {
955 cfg.cls = 'btn-group-' + this.align;
957 if (this.align == 'justified') {
958 console.log(this.items);
962 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
963 cfg.cls += ' btn-group-' + this.size;
966 if (this.direction == 'up') {
967 cfg.cls += ' dropup' ;
973 * Add a button to the group (similar to NavItem API.)
975 addItem : function(cfg)
977 var cn = new Roo.bootstrap.Button(cfg);
979 cn.parentId = this.id;
980 cn.onRender(this.el, null);
994 * @class Roo.bootstrap.Button
995 * @extends Roo.bootstrap.Component
996 * Bootstrap Button class
997 * @cfg {String} html The button content
998 * @cfg {String} weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default
999 * @cfg {String} badge_weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default (same as button)
1000 * @cfg {Boolean} outline default false (except for weight=default which emulates old behaveiour with an outline)
1001 * @cfg {String} size (lg|sm|xs)
1002 * @cfg {String} tag (a|input|submit)
1003 * @cfg {String} href empty or href
1004 * @cfg {Boolean} disabled default false;
1005 * @cfg {Boolean} isClose default false;
1006 * @cfg {String} glyphicon depricated - use fa
1007 * @cfg {String} fa fontawesome icon - eg. 'comment' - without the fa/fas etc..
1008 * @cfg {String} badge text for badge
1009 * @cfg {String} theme (default|glow)
1010 * @cfg {Boolean} inverse dark themed version
1011 * @cfg {Boolean} toggle is it a slidy toggle button
1012 * @cfg {Boolean} pressed default null - if the button ahs active state
1013 * @cfg {String} ontext text for on slidy toggle state
1014 * @cfg {String} offtext text for off slidy toggle state
1015 * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.)
1016 * @cfg {Boolean} removeClass remove the standard class..
1017 * @cfg {String} target (_self|_blank|_parent|_top|other) target for a href.
1018 * @cfg {Boolean} grpup if parent is a btn group - then it turns it into a toogleGroup.
1019 * @cfg {Roo.bootstrap.menu.Menu} menu a Menu
1022 * Create a new button
1023 * @param {Object} config The config object
1027 Roo.bootstrap.Button = function(config){
1028 Roo.bootstrap.Button.superclass.constructor.call(this, config);
1034 * When a button is pressed
1035 * @param {Roo.bootstrap.Button} btn
1036 * @param {Roo.EventObject} e
1041 * When a button is double clicked
1042 * @param {Roo.bootstrap.Button} btn
1043 * @param {Roo.EventObject} e
1048 * After the button has been toggles
1049 * @param {Roo.bootstrap.Button} btn
1050 * @param {Roo.EventObject} e
1051 * @param {boolean} pressed (also available as button.pressed)
1057 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
1078 preventDefault: true,
1087 getAutoCreate : function(){
1095 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
1096 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
1097 this.tag = 'button';
1101 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
1103 if (this.toggle == true) {
1106 cls: 'slider-frame roo-button',
1110 'data-on-text':'ON',
1111 'data-off-text':'OFF',
1112 cls: 'slider-button',
1117 // why are we validating the weights?
1118 if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) {
1119 cfg.cls += ' ' + this.weight;
1126 cfg.cls += ' close';
1128 cfg["aria-hidden"] = true;
1130 cfg.html = "×";
1136 if (this.theme==='default') {
1137 cfg.cls = 'btn roo-button';
1139 //if (this.parentType != 'Navbar') {
1140 this.weight = this.weight.length ? this.weight : 'default';
1142 if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) {
1144 var outline = this.outline || this.weight == 'default' ? 'outline-' : '';
1145 var weight = this.weight == 'default' ? 'secondary' : this.weight;
1146 cfg.cls += ' btn-' + outline + weight;
1147 if (this.weight == 'default') {
1149 cfg.cls += ' btn-' + this.weight;
1152 } else if (this.theme==='glow') {
1155 cfg.cls = 'btn-glow roo-button';
1157 if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) {
1159 cfg.cls += ' ' + this.weight;
1165 this.cls += ' inverse';
1169 if (this.active || this.pressed === true) {
1170 cfg.cls += ' active';
1173 if (this.disabled) {
1174 cfg.disabled = 'disabled';
1178 Roo.log('changing to ul' );
1180 this.glyphicon = 'caret';
1181 if (Roo.bootstrap.version == 4) {
1182 this.fa = 'caret-down';
1187 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
1189 //gsRoo.log(this.parentType);
1190 if (this.parentType === 'Navbar' && !this.parent().bar) {
1191 Roo.log('changing to li?');
1200 href : this.href || '#'
1203 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
1204 cfg.cls += ' dropdown';
1211 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
1213 if (this.glyphicon) {
1214 cfg.html = ' ' + cfg.html;
1219 cls: 'glyphicon glyphicon-' + this.glyphicon
1224 cfg.html = ' ' + cfg.html;
1229 cls: 'fa fas fa-' + this.fa
1239 // cfg.cls='btn roo-button';
1243 var value = cfg.html;
1248 cls: 'glyphicon glyphicon-' + this.glyphicon,
1255 cls: 'fa fas fa-' + this.fa,
1260 var bw = this.badge_weight.length ? this.badge_weight :
1261 (this.weight.length ? this.weight : 'secondary');
1262 bw = bw == 'default' ? 'secondary' : bw;
1268 cls: 'badge badge-' + bw,
1277 cfg.cls += ' dropdown';
1278 cfg.html = typeof(cfg.html) != 'undefined' ?
1279 cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
1282 if (cfg.tag !== 'a' && this.href !== '') {
1283 throw "Tag must be a to set href.";
1284 } else if (this.href.length > 0) {
1285 cfg.href = this.href;
1288 if(this.removeClass){
1293 cfg.target = this.target;
1298 initEvents: function() {
1299 // Roo.log('init events?');
1300 // Roo.log(this.el.dom);
1303 if (typeof (this.menu) != 'undefined') {
1304 this.menu.parentType = this.xtype;
1305 this.menu.triggerEl = this.el;
1306 this.addxtype(Roo.apply({}, this.menu));
1310 if (this.el.hasClass('roo-button')) {
1311 this.el.on('click', this.onClick, this);
1312 this.el.on('dblclick', this.onDblClick, this);
1314 this.el.select('.roo-button').on('click', this.onClick, this);
1315 this.el.select('.roo-button').on('dblclick', this.onDblClick, this);
1319 if(this.removeClass){
1320 this.el.on('click', this.onClick, this);
1323 if (this.group === true) {
1324 if (this.pressed === false || this.pressed === true) {
1327 this.pressed = false;
1328 this.setActive(this.pressed);
1333 this.el.enableDisplayMode();
1336 onClick : function(e)
1338 if (this.disabled) {
1342 Roo.log('button on click ');
1343 if(this.href === '' || this.preventDefault){
1352 this.setActive(true);
1353 var pi = this.parent().items;
1354 for (var i = 0;i < pi.length;i++) {
1355 if (this == pi[i]) {
1358 if (pi[i].el.hasClass('roo-button')) {
1359 pi[i].setActive(false);
1362 this.fireEvent('click', this, e);
1366 if (this.pressed === true || this.pressed === false) {
1367 this.toggleActive(e);
1371 this.fireEvent('click', this, e);
1373 onDblClick: function(e)
1375 if (this.disabled) {
1378 if(this.preventDefault){
1381 this.fireEvent('dblclick', this, e);
1384 * Enables this button
1388 this.disabled = false;
1389 this.el.removeClass('disabled');
1390 this.el.dom.removeAttribute("disabled");
1394 * Disable this button
1396 disable : function()
1398 this.disabled = true;
1399 this.el.addClass('disabled');
1400 this.el.attr("disabled", "disabled")
1403 * sets the active state on/off,
1404 * @param {Boolean} state (optional) Force a particular state
1406 setActive : function(v) {
1408 this.el[v ? 'addClass' : 'removeClass']('active');
1412 * toggles the current active state
1414 toggleActive : function(e)
1416 this.setActive(!this.pressed); // this modifies pressed...
1417 this.fireEvent('toggle', this, e, this.pressed);
1420 * get the current active state
1421 * @return {boolean} true if it's active
1423 isActive : function()
1425 return this.el.hasClass('active');
1428 * set the text of the first selected button
1430 setText : function(str)
1432 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
1435 * get the text of the first selected button
1437 getText : function()
1439 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
1442 setWeight : function(str)
1444 this.el.removeClass(Roo.bootstrap.Button.weights.map(function(w) { return 'btn-' + w; } ) );
1445 this.el.removeClass(Roo.bootstrap.Button.weights.map(function(w) { return 'btn-outline-' + w; } ) );
1447 var outline = this.outline ? 'outline-' : '';
1448 if (str == 'default') {
1449 this.el.addClass('btn-default btn-outline-secondary');
1452 this.el.addClass('btn-' + outline + str);
1457 // fixme - this is probably generic bootstrap - should go in some kind of enum file.. - like sizes.
1459 Roo.bootstrap.Button.weights = [
1479 * @class Roo.bootstrap.Column
1480 * @extends Roo.bootstrap.Component
1481 * @children Roo.bootstrap.Component
1482 * Bootstrap Column class
1483 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
1484 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
1485 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
1486 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
1487 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
1488 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
1489 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
1490 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
1493 * @cfg {Boolean} hidden (true|false) hide the element
1494 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1495 * @cfg {String} fa (ban|check|...) font awesome icon
1496 * @cfg {Number} fasize (1|2|....) font awsome size
1498 * @cfg {String} icon (info-sign|check|...) glyphicon name
1500 * @cfg {String} html content of column.
1503 * Create a new Column
1504 * @param {Object} config The config object
1507 Roo.bootstrap.Column = function(config){
1508 Roo.bootstrap.Column.superclass.constructor.call(this, config);
1511 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
1529 getAutoCreate : function(){
1530 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
1538 var sizes = ['xs','sm','md','lg'];
1539 sizes.map(function(size ,ix){
1540 //Roo.log( size + ':' + settings[size]);
1542 if (settings[size+'off'] !== false) {
1543 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1546 if (settings[size] === false) {
1550 if (!settings[size]) { // 0 = hidden
1551 cfg.cls += ' hidden-' + size + ' hidden-' + size + '-down';
1553 for (var i = ix; i > -1; i--) {
1554 cfg.cls += ' d-' + sizes[i] + '-none';
1560 cfg.cls += ' col-' + size + '-' + settings[size] + (
1561 size == 'xs' ? (' col-' + settings[size] ) : '' // bs4 col-{num} replaces col-xs
1567 cfg.cls += ' hidden';
1570 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1571 cfg.cls +=' alert alert-' + this.alert;
1575 if (this.html.length) {
1576 cfg.html = this.html;
1580 if (this.fasize > 1) {
1581 fasize = ' fa-' + this.fasize + 'x';
1583 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1588 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1607 * @class Roo.bootstrap.Container
1608 * @extends Roo.bootstrap.Component
1609 * @children Roo.bootstrap.Component
1611 * Bootstrap Container class
1612 * @cfg {Boolean} jumbotron is it a jumbotron element
1613 * @cfg {String} html content of element
1614 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1615 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1616 * @cfg {String} header content of header (for panel)
1617 * @cfg {String} footer content of footer (for panel)
1618 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1619 * @cfg {String} tag (header|aside|section) type of HTML tag.
1620 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1621 * @cfg {String} fa font awesome icon
1622 * @cfg {String} icon (info-sign|check|...) glyphicon name
1623 * @cfg {Boolean} hidden (true|false) hide the element
1624 * @cfg {Boolean} expandable (true|false) default false
1625 * @cfg {Boolean} expanded (true|false) default true
1626 * @cfg {String} rheader contet on the right of header
1627 * @cfg {Boolean} clickable (true|false) default false
1631 * Create a new Container
1632 * @param {Object} config The config object
1635 Roo.bootstrap.Container = function(config){
1636 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1642 * After the panel has been expand
1644 * @param {Roo.bootstrap.Container} this
1649 * After the panel has been collapsed
1651 * @param {Roo.bootstrap.Container} this
1656 * When a element is chick
1657 * @param {Roo.bootstrap.Container} this
1658 * @param {Roo.EventObject} e
1664 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1682 getChildContainer : function() {
1688 if (this.panel.length) {
1689 return this.el.select('.panel-body',true).first();
1696 getAutoCreate : function(){
1699 tag : this.tag || 'div',
1703 if (this.jumbotron) {
1704 cfg.cls = 'jumbotron';
1709 // - this is applied by the parent..
1711 // cfg.cls = this.cls + '';
1714 if (this.sticky.length) {
1716 var bd = Roo.get(document.body);
1717 if (!bd.hasClass('bootstrap-sticky')) {
1718 bd.addClass('bootstrap-sticky');
1719 Roo.select('html',true).setStyle('height', '100%');
1722 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1726 if (this.well.length) {
1727 switch (this.well) {
1730 cfg.cls +=' well well-' +this.well;
1739 cfg.cls += ' hidden';
1743 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1744 cfg.cls +=' alert alert-' + this.alert;
1749 if (this.panel.length) {
1750 cfg.cls += ' panel panel-' + this.panel;
1752 if (this.header.length) {
1756 if(this.expandable){
1758 cfg.cls = cfg.cls + ' expandable';
1762 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1770 cls : 'panel-title',
1771 html : (this.expandable ? ' ' : '') + this.header
1775 cls: 'panel-header-right',
1781 cls : 'panel-heading',
1782 style : this.expandable ? 'cursor: pointer' : '',
1790 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1795 if (this.footer.length) {
1797 cls : 'panel-footer',
1806 body.html = this.html || cfg.html;
1807 // prefix with the icons..
1809 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1812 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1817 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1818 cfg.cls = 'container';
1824 initEvents: function()
1826 if(this.expandable){
1827 var headerEl = this.headerEl();
1830 headerEl.on('click', this.onToggleClick, this);
1835 this.el.on('click', this.onClick, this);
1840 onToggleClick : function()
1842 var headerEl = this.headerEl();
1858 if(this.fireEvent('expand', this)) {
1860 this.expanded = true;
1862 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1864 this.el.select('.panel-body',true).first().removeClass('hide');
1866 var toggleEl = this.toggleEl();
1872 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1877 collapse : function()
1879 if(this.fireEvent('collapse', this)) {
1881 this.expanded = false;
1883 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1884 this.el.select('.panel-body',true).first().addClass('hide');
1886 var toggleEl = this.toggleEl();
1892 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1896 toggleEl : function()
1898 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1902 return this.el.select('.panel-heading .fa',true).first();
1905 headerEl : function()
1907 if(!this.el || !this.panel.length || !this.header.length){
1911 return this.el.select('.panel-heading',true).first()
1916 if(!this.el || !this.panel.length){
1920 return this.el.select('.panel-body',true).first()
1923 titleEl : function()
1925 if(!this.el || !this.panel.length || !this.header.length){
1929 return this.el.select('.panel-title',true).first();
1932 setTitle : function(v)
1934 var titleEl = this.titleEl();
1940 titleEl.dom.innerHTML = v;
1943 getTitle : function()
1946 var titleEl = this.titleEl();
1952 return titleEl.dom.innerHTML;
1955 setRightTitle : function(v)
1957 var t = this.el.select('.panel-header-right',true).first();
1963 t.dom.innerHTML = v;
1966 onClick : function(e)
1970 this.fireEvent('click', this, e);
1975 * @class Roo.bootstrap.Card
1976 * @extends Roo.bootstrap.Component
1977 * @children Roo.bootstrap.Component
1979 * Bootstrap Card class - note this has children as CardHeader/ImageTop/Footer.. - which should really be listed properties?
1982 * possible... may not be implemented..
1983 * @cfg {String} header_image src url of image.
1984 * @cfg {String|Object} header
1985 * @cfg {Number} header_size (0|1|2|3|4|5) H1 or H2 etc.. 0 indicates default
1986 * @cfg {Number} header_weight (primary|secondary|success|info|warning|danger|light|dark)
1988 * @cfg {String} title
1989 * @cfg {String} subtitle
1990 * @cfg {String|Boolean} html -- html contents - or just use children.. use false to hide it..
1991 * @cfg {String} footer
1993 * @cfg {String} weight (primary|warning|info|danger|secondary|success|light|dark)
1995 * @cfg {String} margin (0|1|2|3|4|5|auto)
1996 * @cfg {String} margin_top (0|1|2|3|4|5|auto)
1997 * @cfg {String} margin_bottom (0|1|2|3|4|5|auto)
1998 * @cfg {String} margin_left (0|1|2|3|4|5|auto)
1999 * @cfg {String} margin_right (0|1|2|3|4|5|auto)
2000 * @cfg {String} margin_x (0|1|2|3|4|5|auto)
2001 * @cfg {String} margin_y (0|1|2|3|4|5|auto)
2003 * @cfg {String} padding (0|1|2|3|4|5)
2004 * @cfg {String} padding_top (0|1|2|3|4|5)next_to_card
2005 * @cfg {String} padding_bottom (0|1|2|3|4|5)
2006 * @cfg {String} padding_left (0|1|2|3|4|5)
2007 * @cfg {String} padding_right (0|1|2|3|4|5)
2008 * @cfg {String} padding_x (0|1|2|3|4|5)
2009 * @cfg {String} padding_y (0|1|2|3|4|5)
2011 * @cfg {String} display (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2012 * @cfg {String} display_xs (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2013 * @cfg {String} display_sm (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2014 * @cfg {String} display_lg (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2015 * @cfg {String} display_xl (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2017 * @config {Boolean} dragable if this card can be dragged.
2018 * @config {String} drag_group group for drag
2019 * @config {Boolean} dropable if this card can recieve other cards being dropped onto it..
2020 * @config {String} drop_group group for drag
2022 * @config {Boolean} collapsable can the body be collapsed.
2023 * @config {Boolean} collapsed is the body collapsed when rendered...
2024 * @config {Boolean} rotateable can the body be rotated by clicking on it..
2025 * @config {Boolean} rotated is the body rotated when rendered...
2028 * Create a new Container
2029 * @param {Object} config The config object
2032 Roo.bootstrap.Card = function(config){
2033 Roo.bootstrap.Card.superclass.constructor.call(this, config);
2039 * When a element a card is dropped
2040 * @param {Roo.bootstrap.Card} this
2043 * @param {Roo.bootstrap.Card} move_card the card being dropped?
2044 * @param {String} position 'above' or 'below'
2045 * @param {Roo.bootstrap.Card} next_to_card What card position is relative to of 'false' for empty list.
2051 * When a element a card is rotate
2052 * @param {Roo.bootstrap.Card} this
2053 * @param {Roo.Element} n the node being dropped?
2054 * @param {Boolean} rotate status
2059 * When a card element is dragged over ready to drop (return false to block dropable)
2060 * @param {Roo.bootstrap.Card} this
2061 * @param {Object} data from dragdrop
2069 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
2074 margin: '', /// may be better in component?
2104 collapsable : false,
2113 childContainer : false,
2114 dropEl : false, /// the dom placeholde element that indicates drop location.
2115 containerEl: false, // body container
2116 bodyEl: false, // card-body
2117 headerContainerEl : false, //
2119 header_imageEl : false,
2122 layoutCls : function()
2126 Roo.log(this.margin_bottom.length);
2127 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
2128 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
2130 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
2131 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
2133 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
2134 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
2138 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
2139 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
2140 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['display' + (v.length ? '_' : '') + v]
2144 // more generic support?
2152 // Roo.log("Call onRender: " + this.xtype);
2153 /* We are looking at something like this.
2155 <img src="..." class="card-img-top" alt="...">
2156 <div class="card-body">
2157 <h5 class="card-title">Card title</h5>
2158 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
2160 >> this bit is really the body...
2161 <div> << we will ad dthis in hopefully it will not break shit.
2163 ** card text does not actually have any styling...
2165 <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>
2168 <a href="#" class="card-link">Card link</a>
2171 <div class="card-footer">
2172 <small class="text-muted">Last updated 3 mins ago</small>
2176 getAutoCreate : function(){
2184 if (this.weight.length && this.weight != 'light') {
2185 cfg.cls += ' text-white';
2187 cfg.cls += ' text-dark'; // need as it's nested..
2189 if (this.weight.length) {
2190 cfg.cls += ' bg-' + this.weight;
2193 cfg.cls += ' ' + this.layoutCls();
2196 var hdr_ctr = false;
2197 if (this.header.length) {
2199 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
2200 cls : 'card-header ' + (this.header_weight ? 'bg-' + this.header_weight : ''),
2208 cls : 'card-header d-none ' + (this.header_weight ? 'bg-' + this.header_weight : ''),
2214 if (this.collapsable) {
2217 cls : 'd-block user-select-none',
2221 cls : 'roo-collapse-toggle fa fa-chevron-down float-right ' + (this.collapsed ? 'collapsed' : '')
2226 hdr.cn.push(hdr_ctr);
2231 cls: 'roo-card-header-ctr' + ( this.header.length ? '' : ' d-none'),
2236 if (this.header_image.length) {
2239 cls : 'card-img-top',
2240 src: this.header_image // escape?
2245 cls : 'card-img-top d-none'
2251 cls : 'card-body' + (this.html === false ? ' d-none' : ''),
2255 if (this.collapsable || this.rotateable) {
2258 cls : 'roo-collapsable collapse ' + (this.collapsed || this.rotated ? '' : 'show'),
2265 if (this.title.length) {
2269 src: this.title // escape?
2273 if (this.subtitle.length) {
2277 src: this.subtitle // escape?
2283 cls : 'roo-card-body-ctr'
2286 if (this.html.length) {
2292 // fixme ? handle objects?
2294 if (this.footer.length) {
2297 cls : 'card-footer ' + (this.rotated ? 'd-none' : ''),
2302 cfg.cn.push({cls : 'card-footer d-none'});
2311 getCardHeader : function()
2313 var ret = this.el.select('.card-header',true).first();
2314 if (ret.hasClass('d-none')) {
2315 ret.removeClass('d-none');
2320 getCardFooter : function()
2322 var ret = this.el.select('.card-footer',true).first();
2323 if (ret.hasClass('d-none')) {
2324 ret.removeClass('d-none');
2329 getCardImageTop : function()
2331 var ret = this.header_imageEl;
2332 if (ret.hasClass('d-none')) {
2333 ret.removeClass('d-none');
2339 getChildContainer : function()
2345 return this.el.select('.roo-card-body-ctr',true).first();
2348 initEvents: function()
2350 this.bodyEl = this.el.select('.card-body',true).first();
2351 this.containerEl = this.getChildContainer();
2353 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
2354 containerScroll: true,
2355 ddGroup: this.drag_group || 'default_card_drag_group'
2357 this.dragZone.getDragData = this.getDragData.createDelegate(this);
2359 if (this.dropable) {
2360 this.dropZone = new Roo.dd.DropZone(this.el.select('.card-body',true).first() , {
2361 containerScroll: true,
2362 ddGroup: this.drop_group || 'default_card_drag_group'
2364 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
2365 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
2366 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
2367 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
2368 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
2371 if (this.collapsable) {
2372 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
2374 if (this.rotateable) {
2375 this.el.select('.card-header',true).on('click', this.onToggleRotate, this);
2377 this.collapsableEl = this.el.select('.roo-collapsable',true).first();
2379 this.footerEl = this.el.select('.card-footer',true).first();
2380 this.collapsableToggleEl = this.el.select('.roo-collapse-toggle',true).first();
2381 this.headerContainerEl = this.el.select('.roo-card-header-ctr',true).first();
2382 this.headerEl = this.el.select('.card-header',true).first();
2385 this.el.addClass('roo-card-rotated');
2386 this.fireEvent('rotate', this, true);
2388 this.header_imageEl = this.el.select('.card-img-top',true).first();
2389 this.header_imageEl.on('load', this.onHeaderImageLoad, this );
2392 getDragData : function(e)
2394 var target = this.getEl();
2396 //this.handleSelection(e);
2401 nodes: this.getEl(),
2406 dragData.ddel = target.dom ; // the div element
2407 Roo.log(target.getWidth( ));
2408 dragData.ddel.style.width = target.getWidth() + 'px';
2415 * Part of the Roo.dd.DropZone interface. If no target node is found, the
2416 * whole Element becomes the target, and this causes the drop gesture to append.
2418 * Returns an object:
2421 position : 'below' or 'above'
2422 card : relateive to card OBJECT (or true for no cards listed)
2423 items_n : relative to nth item in list
2424 card_n : relative to nth card in list
2429 getTargetFromEvent : function(e, dragged_card_el)
2431 var target = e.getTarget();
2432 while ((target !== null) && (target.parentNode != this.containerEl.dom)) {
2433 target = target.parentNode;
2444 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
2445 // see if target is one of the 'cards'...
2448 //Roo.log(this.items.length);
2451 var last_card_n = 0;
2453 for (var i = 0;i< this.items.length;i++) {
2455 if (!this.items[i].el.hasClass('card')) {
2458 pos = this.getDropPoint(e, this.items[i].el.dom);
2460 cards_len = ret.cards.length;
2461 //Roo.log(this.items[i].el.dom.id);
2462 ret.cards.push(this.items[i]);
2464 if (ret.card_n < 0 && pos == 'above') {
2465 ret.position = cards_len > 0 ? 'below' : pos;
2466 ret.items_n = i > 0 ? i - 1 : 0;
2467 ret.card_n = cards_len > 0 ? cards_len - 1 : 0;
2468 ret.card = ret.cards[ret.card_n];
2471 if (!ret.cards.length) {
2473 ret.position = 'below';
2477 // could not find a card.. stick it at the end..
2478 if (ret.card_n < 0) {
2479 ret.card_n = last_card_n;
2480 ret.card = ret.cards[last_card_n];
2481 ret.items_n = this.items.indexOf(ret.cards[last_card_n]);
2482 ret.position = 'below';
2485 if (this.items[ret.items_n].el == dragged_card_el) {
2489 if (ret.position == 'below') {
2490 var card_after = ret.card_n+1 == ret.cards.length ? false : ret.cards[ret.card_n+1];
2492 if (card_after && card_after.el == dragged_card_el) {
2499 var card_before = ret.card_n > 0 ? ret.cards[ret.card_n-1] : false;
2501 if (card_before && card_before.el == dragged_card_el) {
2508 onNodeEnter : function(n, dd, e, data){
2511 onNodeOver : function(n, dd, e, data)
2514 var target_info = this.getTargetFromEvent(e,data.source.el);
2515 if (target_info === false) {
2516 this.dropPlaceHolder('hide');
2519 Roo.log(['getTargetFromEvent', target_info ]);
2522 if (this.fireEvent('cardover', this, [ data ]) === false) {
2526 this.dropPlaceHolder('show', target_info,data);
2530 onNodeOut : function(n, dd, e, data){
2531 this.dropPlaceHolder('hide');
2534 onNodeDrop : function(n, dd, e, data)
2537 // call drop - return false if
2539 // this could actually fail - if the Network drops..
2540 // we will ignore this at present..- client should probably reload
2541 // the whole set of cards if stuff like that fails.
2544 var info = this.getTargetFromEvent(e,data.source.el);
2545 if (info === false) {
2548 this.dropPlaceHolder('hide');
2552 this.acceptCard(data.source, info.position, info.card, info.items_n);
2556 firstChildCard : function()
2558 for (var i = 0;i< this.items.length;i++) {
2560 if (!this.items[i].el.hasClass('card')) {
2563 return this.items[i];
2565 return this.items.length ? this.items[this.items.length-1] : false; // don't try and put stuff after the cards...
2570 * - card.acceptCard(move_card, info.position, info.card, info.items_n);
2572 acceptCard : function(move_card, position, next_to_card )
2574 if (this.fireEvent("drop", this, move_card, position, next_to_card) === false) {
2578 var to_items_n = next_to_card ? this.items.indexOf(next_to_card) : 0;
2580 move_card.parent().removeCard(move_card);
2583 var dom = move_card.el.dom;
2584 dom.style.width = ''; // clear with - which is set by drag.
2586 if (next_to_card !== false && next_to_card !== true && next_to_card.el.dom.parentNode) {
2587 var cardel = next_to_card.el.dom;
2589 if (position == 'above' ) {
2590 cardel.parentNode.insertBefore(dom, cardel);
2591 } else if (cardel.nextSibling) {
2592 cardel.parentNode.insertBefore(dom,cardel.nextSibling);
2594 cardel.parentNode.append(dom);
2597 // card container???
2598 this.containerEl.dom.append(dom);
2601 //FIXME HANDLE card = true
2603 // add this to the correct place in items.
2605 // remove Card from items.
2608 if (this.items.length) {
2610 //Roo.log([info.items_n, info.position, this.items.length]);
2611 for (var i =0; i < this.items.length; i++) {
2612 if (i == to_items_n && position == 'above') {
2613 nitems.push(move_card);
2615 nitems.push(this.items[i]);
2616 if (i == to_items_n && position == 'below') {
2617 nitems.push(move_card);
2620 this.items = nitems;
2621 Roo.log(this.items);
2623 this.items.push(move_card);
2626 move_card.parentId = this.id;
2632 removeCard : function(c)
2634 this.items = this.items.filter(function(e) { return e != c });
2637 dom.parentNode.removeChild(dom);
2638 dom.style.width = ''; // clear with - which is set by drag.
2643 /** Decide whether to drop above or below a View node. */
2644 getDropPoint : function(e, n, dd)
2649 if (n == this.containerEl.dom) {
2652 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
2653 var c = t + (b - t) / 2;
2654 var y = Roo.lib.Event.getPageY(e);
2661 onToggleCollapse : function(e)
2663 if (this.collapsed) {
2664 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
2665 this.collapsableEl.addClass('show');
2666 this.collapsed = false;
2669 this.el.select('.roo-collapse-toggle').addClass('collapsed');
2670 this.collapsableEl.removeClass('show');
2671 this.collapsed = true;
2676 onToggleRotate : function(e)
2678 this.collapsableEl.removeClass('show');
2679 this.footerEl.removeClass('d-none');
2680 this.el.removeClass('roo-card-rotated');
2681 this.el.removeClass('d-none');
2684 this.collapsableEl.addClass('show');
2685 this.rotated = false;
2686 this.fireEvent('rotate', this, this.rotated);
2689 this.el.addClass('roo-card-rotated');
2690 this.footerEl.addClass('d-none');
2691 this.el.select('.roo-collapsable').removeClass('show');
2693 this.rotated = true;
2694 this.fireEvent('rotate', this, this.rotated);
2698 dropPlaceHolder: function (action, info, data)
2700 if (this.dropEl === false) {
2701 this.dropEl = Roo.DomHelper.append(this.containerEl, {
2705 this.dropEl.removeClass(['d-none', 'd-block']);
2706 if (action == 'hide') {
2708 this.dropEl.addClass('d-none');
2711 // FIXME - info.card == true!!!
2712 this.dropEl.dom.parentNode.removeChild(this.dropEl.dom);
2714 if (info.card !== true) {
2715 var cardel = info.card.el.dom;
2717 if (info.position == 'above') {
2718 cardel.parentNode.insertBefore(this.dropEl.dom, cardel);
2719 } else if (cardel.nextSibling) {
2720 cardel.parentNode.insertBefore(this.dropEl.dom,cardel.nextSibling);
2722 cardel.parentNode.append(this.dropEl.dom);
2725 // card container???
2726 this.containerEl.dom.append(this.dropEl.dom);
2729 this.dropEl.addClass('d-block roo-card-dropzone');
2731 this.dropEl.setHeight( Roo.get(data.ddel).getHeight() );
2738 setHeaderText: function(html)
2741 if (this.headerContainerEl) {
2742 this.headerContainerEl.dom.innerHTML = html;
2745 onHeaderImageLoad : function(ev, he)
2747 if (!this.header_image_fit_square) {
2751 var hw = he.naturalHeight / he.naturalWidth;
2754 //var w = he.dom.naturalWidth;
2757 he.style.position = 'relative';
2759 var nw = (ww * (1/hw));
2760 Roo.get(he).setSize( ww * (1/hw), ww);
2761 he.style.left = ((ww - nw)/ 2) + 'px';
2762 he.style.position = 'relative';
2773 * Card header - holder for the card header elements.
2778 * @class Roo.bootstrap.CardHeader
2779 * @extends Roo.bootstrap.Element
2780 * @parent Roo.bootstrap.Card
2781 * @children Roo.bootstrap.Component
2782 * Bootstrap CardHeader class
2784 * Create a new Card Header - that you can embed children into
2785 * @param {Object} config The config object
2788 Roo.bootstrap.CardHeader = function(config){
2789 Roo.bootstrap.CardHeader.superclass.constructor.call(this, config);
2792 Roo.extend(Roo.bootstrap.CardHeader, Roo.bootstrap.Element, {
2795 container_method : 'getCardHeader'
2808 * Card footer - holder for the card footer elements.
2813 * @class Roo.bootstrap.CardFooter
2814 * @extends Roo.bootstrap.Element
2815 * @parent Roo.bootstrap.Card
2816 * @children Roo.bootstrap.Component
2817 * Bootstrap CardFooter class
2820 * Create a new Card Footer - that you can embed children into
2821 * @param {Object} config The config object
2824 Roo.bootstrap.CardFooter = function(config){
2825 Roo.bootstrap.CardFooter.superclass.constructor.call(this, config);
2828 Roo.extend(Roo.bootstrap.CardFooter, Roo.bootstrap.Element, {
2831 container_method : 'getCardFooter'
2844 * Card header - holder for the card header elements.
2849 * @class Roo.bootstrap.CardImageTop
2850 * @extends Roo.bootstrap.Element
2851 * @parent Roo.bootstrap.Card
2852 * @children Roo.bootstrap.Component
2853 * Bootstrap CardImageTop class
2856 * Create a new Card Image Top container
2857 * @param {Object} config The config object
2860 Roo.bootstrap.CardImageTop = function(config){
2861 Roo.bootstrap.CardImageTop.superclass.constructor.call(this, config);
2864 Roo.extend(Roo.bootstrap.CardImageTop, Roo.bootstrap.Element, {
2867 container_method : 'getCardImageTop'
2882 * @class Roo.bootstrap.ButtonUploader
2883 * @extends Roo.bootstrap.Button
2884 * Bootstrap Button Uploader class - it's a button which when you add files to it
2887 * @cfg {Number} errorTimeout default 3000
2888 * @cfg {Array} images an array of ?? Img objects ??? when loading existing files..
2889 * @cfg {Array} html The button text.
2890 * @cfg {Boolean} multiple (default true) Should the upload allow multiple files to be uploaded.
2893 * Create a new CardUploader
2894 * @param {Object} config The config object
2897 Roo.bootstrap.ButtonUploader = function(config){
2901 Roo.bootstrap.ButtonUploader.superclass.constructor.call(this, config);
2907 * @event beforeselect
2908 * When button is pressed, before show upload files dialog is shown
2909 * @param {Roo.bootstrap.UploaderButton} this
2912 'beforeselect' : true,
2914 * @event fired when files have been selected,
2915 * When a the download link is clicked
2916 * @param {Roo.bootstrap.UploaderButton} this
2917 * @param {Array} Array of files that have been uploaded
2924 Roo.extend(Roo.bootstrap.ButtonUploader, Roo.bootstrap.Button, {
2927 errorTimeout : 3000,
2931 fileCollection : false,
2936 getAutoCreate : function()
2943 Roo.bootstrap.Button.prototype.getAutoCreate.call(this)
2951 initEvents : function()
2954 Roo.bootstrap.Button.prototype.initEvents.call(this);
2960 this.urlAPI = (window.createObjectURL && window) ||
2961 (window.URL && URL.revokeObjectURL && URL) ||
2962 (window.webkitURL && webkitURL);
2967 cls : 'd-none roo-card-upload-selector'
2970 if (this.multiple) {
2971 im.multiple = 'multiple';
2973 this.selectorEl = Roo.get(document.body).createChild(im); // so it does not capture click event for navitem.
2975 //this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
2977 this.selectorEl.on('change', this.onFileSelected, this);
2984 onClick : function(e)
2988 if ( this.fireEvent('beforeselect', this) === false) {
2992 this.selectorEl.dom.click();
2996 onFileSelected : function(e)
3000 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
3003 var files = Array.prototype.slice.call(this.selectorEl.dom.files);
3004 this.selectorEl.dom.value = '';// hopefully reset..
3006 this.fireEvent('uploaded', this, files );
3014 * addCard - add an Attachment to the uploader
3015 * @param data - the data about the image to upload
3019 title : "Title of file",
3020 is_uploaded : false,
3021 src : "http://.....",
3022 srcfile : { the File upload object },
3023 mimetype : file.type,
3026 .. any other data...
3051 * @class Roo.bootstrap.Img
3052 * @extends Roo.bootstrap.Component
3053 * Bootstrap Img class
3054 * @cfg {Boolean} imgResponsive false | true
3055 * @cfg {String} border rounded | circle | thumbnail
3056 * @cfg {String} src image source
3057 * @cfg {String} alt image alternative text
3058 * @cfg {String} href a tag href
3059 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
3060 * @cfg {String} xsUrl xs image source
3061 * @cfg {String} smUrl sm image source
3062 * @cfg {String} mdUrl md image source
3063 * @cfg {String} lgUrl lg image source
3064 * @cfg {Boolean} backgroundContain (use style background and contain image in content)
3067 * Create a new Input
3068 * @param {Object} config The config object
3071 Roo.bootstrap.Img = function(config){
3072 Roo.bootstrap.Img.superclass.constructor.call(this, config);
3078 * The img click event for the img.
3079 * @param {Roo.EventObject} e
3084 * The when any image loads
3085 * @param {Roo.EventObject} e
3091 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
3093 imgResponsive: true,
3102 backgroundContain : false,
3104 getAutoCreate : function()
3106 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
3107 return this.createSingleImg();
3112 cls: 'roo-image-responsive-group',
3117 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
3119 if(!_this[size + 'Url']){
3125 cls: (_this.imgResponsive) ? 'img-responsive' : '',
3126 html: _this.html || cfg.html,
3127 src: _this[size + 'Url']
3130 img.cls += ' roo-image-responsive-' + size;
3132 var s = ['xs', 'sm', 'md', 'lg'];
3134 s.splice(s.indexOf(size), 1);
3136 Roo.each(s, function(ss){
3137 img.cls += ' hidden-' + ss;
3140 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
3141 cfg.cls += ' img-' + _this.border;
3145 cfg.alt = _this.alt;
3158 a.target = _this.target;
3162 cfg.cn.push((_this.href) ? a : img);
3169 createSingleImg : function()
3173 cls: (this.imgResponsive) ? 'img-responsive' : '',
3175 src : Roo.BLANK_IMAGE_URL // just incase src get's set to undefined?!?
3178 if (this.backgroundContain) {
3179 cfg.cls += ' background-contain';
3182 cfg.html = this.html || cfg.html;
3184 if (this.backgroundContain) {
3185 cfg.style="background-image: url(" + this.src + ')';
3187 cfg.src = this.src || cfg.src;
3190 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
3191 cfg.cls += ' img-' + this.border;
3208 a.target = this.target;
3213 return (this.href) ? a : cfg;
3216 initEvents: function()
3219 this.el.on('click', this.onClick, this);
3221 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
3222 this.el.on('load', this.onImageLoad, this);
3224 // not sure if this works.. not tested
3225 this.el.select('img', true).on('load', this.onImageLoad, this);
3230 onClick : function(e)
3232 Roo.log('img onclick');
3233 this.fireEvent('click', this, e);
3235 onImageLoad: function(e)
3237 Roo.log('img load');
3238 this.fireEvent('load', this, e);
3242 * Sets the url of the image - used to update it
3243 * @param {String} url the url of the image
3246 setSrc : function(url)
3250 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
3251 if (this.backgroundContain) {
3252 this.el.dom.style.backgroundImage = 'url(' + url + ')';
3254 this.el.dom.src = url;
3259 this.el.select('img', true).first().dom.src = url;
3275 * @class Roo.bootstrap.Link
3276 * @extends Roo.bootstrap.Component
3277 * @children Roo.bootstrap.Component
3278 * Bootstrap Link Class (eg. '<a href>')
3280 * @cfg {String} alt image alternative text
3281 * @cfg {String} href a tag href
3282 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
3283 * @cfg {String} html the content of the link.
3284 * @cfg {String} anchor name for the anchor link
3285 * @cfg {String} fa - favicon
3287 * @cfg {Boolean} preventDefault (true | false) default false
3291 * Create a new Input
3292 * @param {Object} config The config object
3295 Roo.bootstrap.Link = function(config){
3296 Roo.bootstrap.Link.superclass.constructor.call(this, config);
3302 * The img click event for the img.
3303 * @param {Roo.EventObject} e
3309 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
3313 preventDefault: false,
3319 getAutoCreate : function()
3321 var html = this.html || '';
3323 if (this.fa !== false) {
3324 html = '<i class="fa fa-' + this.fa + '"></i>';
3329 // anchor's do not require html/href...
3330 if (this.anchor === false) {
3332 cfg.href = this.href || '#';
3334 cfg.name = this.anchor;
3335 if (this.html !== false || this.fa !== false) {
3338 if (this.href !== false) {
3339 cfg.href = this.href;
3343 if(this.alt !== false){
3348 if(this.target !== false) {
3349 cfg.target = this.target;
3355 initEvents: function() {
3357 if(!this.href || this.preventDefault){
3358 this.el.on('click', this.onClick, this);
3362 onClick : function(e)
3364 if(this.preventDefault){
3367 //Roo.log('img onclick');
3368 this.fireEvent('click', this, e);
3381 * @class Roo.bootstrap.Header
3382 * @extends Roo.bootstrap.Component
3383 * @children Roo.bootstrap.Component
3384 * Bootstrap Header class
3387 * @cfg {String} html content of header
3388 * @cfg {Number} level (1|2|3|4|5|6) default 1
3391 * Create a new Header
3392 * @param {Object} config The config object
3396 Roo.bootstrap.Header = function(config){
3397 Roo.bootstrap.Header.superclass.constructor.call(this, config);
3400 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
3408 getAutoCreate : function(){
3413 tag: 'h' + (1 *this.level),
3414 html: this.html || ''
3425 * @class Roo.bootstrap.MenuMgr
3427 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
3430 Roo.bootstrap.menu.Manager = function(){
3431 var menus, active, groups = {}, attached = false, lastShow = new Date();
3433 // private - called when first menu is created
3436 active = new Roo.util.MixedCollection();
3437 Roo.get(document).addKeyListener(27, function(){
3438 if(active.length > 0){
3446 if(active && active.length > 0){
3447 var c = active.clone();
3457 if(active.length < 1){
3458 Roo.get(document).un("mouseup", onMouseDown);
3466 var last = active.last();
3467 lastShow = new Date();
3470 Roo.get(document).on("mouseup", onMouseDown);
3475 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
3476 m.parentMenu.activeChild = m;
3477 }else if(last && last.isVisible()){
3478 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
3483 function onBeforeHide(m){
3485 m.activeChild.hide();
3487 if(m.autoHideTimer){
3488 clearTimeout(m.autoHideTimer);
3489 delete m.autoHideTimer;
3494 function onBeforeShow(m){
3495 var pm = m.parentMenu;
3496 if(!pm && !m.allowOtherMenus){
3498 }else if(pm && pm.activeChild && active != m){
3499 pm.activeChild.hide();
3503 // private this should really trigger on mouseup..
3504 function onMouseDown(e){
3505 Roo.log("on Mouse Up");
3507 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
3508 Roo.log("MenuManager hideAll");
3517 function onBeforeCheck(mi, state){
3519 var g = groups[mi.group];
3520 for(var i = 0, l = g.length; i < l; i++){
3522 g[i].setChecked(false);
3531 * Hides all menus that are currently visible
3533 hideAll : function(){
3538 register : function(menu){
3542 menus[menu.id] = menu;
3543 menu.on("beforehide", onBeforeHide);
3544 menu.on("hide", onHide);
3545 menu.on("beforeshow", onBeforeShow);
3546 menu.on("show", onShow);
3548 if(g && menu.events["checkchange"]){
3552 groups[g].push(menu);
3553 menu.on("checkchange", onCheck);
3558 * Returns a {@link Roo.menu.Menu} object
3559 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
3560 * be used to generate and return a new Menu instance.
3562 get : function(menu){
3563 if(typeof menu == "string"){ // menu id
3565 }else if(menu.events){ // menu instance
3568 /*else if(typeof menu.length == 'number'){ // array of menu items?
3569 return new Roo.bootstrap.Menu({items:menu});
3570 }else{ // otherwise, must be a config
3571 return new Roo.bootstrap.Menu(menu);
3578 unregister : function(menu){
3579 delete menus[menu.id];
3580 menu.un("beforehide", onBeforeHide);
3581 menu.un("hide", onHide);
3582 menu.un("beforeshow", onBeforeShow);
3583 menu.un("show", onShow);
3585 if(g && menu.events["checkchange"]){
3586 groups[g].remove(menu);
3587 menu.un("checkchange", onCheck);
3592 registerCheckable : function(menuItem){
3593 var g = menuItem.group;
3598 groups[g].push(menuItem);
3599 menuItem.on("beforecheckchange", onBeforeCheck);
3604 unregisterCheckable : function(menuItem){
3605 var g = menuItem.group;
3607 groups[g].remove(menuItem);
3608 menuItem.un("beforecheckchange", onBeforeCheck);
3614 * @class Roo.bootstrap.menu.Menu
3615 * @extends Roo.bootstrap.Component
3617 * @children Roo.bootstrap.menu.Item Roo.bootstrap.menu.Separator
3619 * Bootstrap Menu class - container for MenuItems - normally has to be added to a object that supports the menu property
3621 * @cfg {String} type (dropdown|treeview|submenu) type of menu
3622 * @cfg {bool} hidden if the menu should be hidden when rendered.
3623 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
3624 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
3625 * @cfg {bool} hideTrigger (true|false) default false - hide the carret for trigger.
3626 * @cfg {String} align default tl-bl? == below - how the menu should be aligned.
3630 * @param {Object} config The config objectQ
3634 Roo.bootstrap.menu.Menu = function(config){
3636 if (config.type == 'treeview') {
3637 // normally menu's are drawn attached to the document to handle layering etc..
3638 // however treeview (used by the docs menu is drawn into the parent element)
3639 this.container_method = 'getChildContainer';
3642 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
3643 if (this.registerMenu && this.type != 'treeview') {
3644 Roo.bootstrap.menu.Manager.register(this);
3651 * Fires before this menu is displayed (return false to block)
3652 * @param {Roo.menu.Menu} this
3657 * Fires before this menu is hidden (return false to block)
3658 * @param {Roo.menu.Menu} this
3663 * Fires after this menu is displayed
3664 * @param {Roo.menu.Menu} this
3669 * Fires after this menu is hidden
3670 * @param {Roo.menu.Menu} this
3675 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
3676 * @param {Roo.menu.Menu} this
3677 * @param {Roo.menu.Item} menuItem The menu item that was clicked
3678 * @param {Roo.EventObject} e
3683 * Fires when the mouse is hovering over this menu
3684 * @param {Roo.menu.Menu} this
3685 * @param {Roo.EventObject} e
3686 * @param {Roo.menu.Item} menuItem The menu item that was clicked
3691 * Fires when the mouse exits this menu
3692 * @param {Roo.menu.Menu} this
3693 * @param {Roo.EventObject} e
3694 * @param {Roo.menu.Item} menuItem The menu item that was clicked
3699 * Fires when a menu item contained in this menu is clicked
3700 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
3701 * @param {Roo.EventObject} e
3705 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
3708 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
3712 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
3715 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
3717 registerMenu : true,
3719 menuItems :false, // stores the menu items..
3729 container_method : 'getDocumentBody', // so the menu is rendered on the body and zIndex works.
3731 hideTrigger : false,
3736 getChildContainer : function() {
3740 getAutoCreate : function(){
3742 //if (['right'].indexOf(this.align)!==-1) {
3743 // cfg.cn[1].cls += ' pull-right'
3748 cls : 'dropdown-menu shadow' ,
3749 style : 'z-index:1000'
3753 if (this.type === 'submenu') {
3754 cfg.cls = 'submenu active';
3756 if (this.type === 'treeview') {
3757 cfg.cls = 'treeview-menu';
3762 initEvents : function() {
3764 // Roo.log("ADD event");
3765 // Roo.log(this.triggerEl.dom);
3766 if (this.triggerEl) {
3768 this.triggerEl.on('click', this.onTriggerClick, this);
3770 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
3772 if (!this.hideTrigger) {
3773 if (this.triggerEl.hasClass('nav-item') && this.triggerEl.select('.nav-link',true).length) {
3774 // dropdown toggle on the 'a' in BS4?
3775 this.triggerEl.select('.nav-link',true).first().addClass('dropdown-toggle');
3777 this.triggerEl.addClass('dropdown-toggle');
3783 this.el.on('touchstart' , this.onTouch, this);
3785 this.el.on('click' , this.onClick, this);
3787 this.el.on("mouseover", this.onMouseOver, this);
3788 this.el.on("mouseout", this.onMouseOut, this);
3792 findTargetItem : function(e)
3794 var t = e.getTarget(".dropdown-menu-item", this.el, true);
3798 //Roo.log(t); Roo.log(t.id);
3800 //Roo.log(this.menuitems);
3801 return this.menuitems.get(t.id);
3803 //return this.items.get(t.menuItemId);
3809 onTouch : function(e)
3811 Roo.log("menu.onTouch");
3812 //e.stopEvent(); this make the user popdown broken
3816 onClick : function(e)
3818 Roo.log("menu.onClick");
3820 var t = this.findTargetItem(e);
3821 if(!t || t.isContainer){
3826 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
3827 if(t == this.activeItem && t.shouldDeactivate(e)){
3828 this.activeItem.deactivate();
3829 delete this.activeItem;
3833 this.setActiveItem(t, true);
3841 Roo.log('pass click event');
3845 this.fireEvent("click", this, t, e);
3849 if(!t.href.length || t.href == '#'){
3850 (function() { _this.hide(); }).defer(100);
3855 onMouseOver : function(e){
3856 var t = this.findTargetItem(e);
3859 // if(t.canActivate && !t.disabled){
3860 // this.setActiveItem(t, true);
3864 this.fireEvent("mouseover", this, e, t);
3866 isVisible : function(){
3867 return !this.hidden;
3869 onMouseOut : function(e){
3870 var t = this.findTargetItem(e);
3873 // if(t == this.activeItem && t.shouldDeactivate(e)){
3874 // this.activeItem.deactivate();
3875 // delete this.activeItem;
3878 this.fireEvent("mouseout", this, e, t);
3883 * Displays this menu relative to another element
3884 * @param {String/HTMLElement/Roo.Element} element The element to align to
3885 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
3886 * the element (defaults to this.defaultAlign)
3887 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
3889 show : function(el, pos, parentMenu)
3891 if (false === this.fireEvent("beforeshow", this)) {
3892 Roo.log("show canceled");
3895 this.parentMenu = parentMenu;
3899 this.el.addClass('show'); // show otherwise we do not know how big we are..
3901 var xy = this.el.getAlignToXY(el, pos);
3903 // bl-tl << left align below
3904 // tl-bl << left align
3906 if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
3907 // if it goes to far to the right.. -> align left.
3908 xy = this.el.getAlignToXY(el, this.align.replace('/l/g', 'r'))
3911 // was left align - go right?
3912 xy = this.el.getAlignToXY(el, this.align.replace('/r/g', 'l'))
3915 // goes down the bottom
3916 if(this.el.getHeight() + xy[1] >= Roo.lib.Dom.getViewHeight() ||
3918 var a = this.align.replace('?', '').split('-');
3919 xy = this.el.getAlignToXY(el, a[1] + '-' + a[0] + '?')
3923 this.showAt( xy , parentMenu, false);
3926 * Displays this menu at a specific xy position
3927 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
3928 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
3930 showAt : function(xy, parentMenu, /* private: */_e){
3931 this.parentMenu = parentMenu;
3936 this.fireEvent("beforeshow", this);
3937 //xy = this.el.adjustForConstraints(xy);
3941 this.hideMenuItems();
3942 this.hidden = false;
3943 if (this.triggerEl) {
3944 this.triggerEl.addClass('open');
3947 this.el.addClass('show');
3951 // reassign x when hitting right
3953 // reassign y when hitting bottom
3955 // but the list may align on trigger left or trigger top... should it be a properity?
3957 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
3962 this.fireEvent("show", this);
3968 this.doFocus.defer(50, this);
3972 doFocus : function(){
3974 this.focusEl.focus();
3979 * Hides this menu and optionally all parent menus
3980 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
3982 hide : function(deep)
3984 if (false === this.fireEvent("beforehide", this)) {
3985 Roo.log("hide canceled");
3988 this.hideMenuItems();
3989 if(this.el && this.isVisible()){
3991 if(this.activeItem){
3992 this.activeItem.deactivate();
3993 this.activeItem = null;
3995 if (this.triggerEl) {
3996 this.triggerEl.removeClass('open');
3999 this.el.removeClass('show');
4001 this.fireEvent("hide", this);
4003 if(deep === true && this.parentMenu){
4004 this.parentMenu.hide(true);
4008 onTriggerClick : function(e)
4010 Roo.log('trigger click');
4012 var target = e.getTarget();
4014 Roo.log(target.nodeName.toLowerCase());
4016 if(target.nodeName.toLowerCase() === 'i'){
4022 onTriggerPress : function(e)
4024 Roo.log('trigger press');
4025 //Roo.log(e.getTarget());
4026 // Roo.log(this.triggerEl.dom);
4028 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
4029 var pel = Roo.get(e.getTarget());
4030 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
4031 Roo.log('is treeview or dropdown?');
4035 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
4039 if (this.isVisible()) {
4045 this.show(this.triggerEl, this.align, false);
4048 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
4055 hideMenuItems : function()
4057 Roo.log("hide Menu Items");
4062 this.el.select('.open',true).each(function(aa) {
4064 aa.removeClass('open');
4068 addxtypeChild : function (tree, cntr) {
4069 var comp= Roo.bootstrap.menu.Menu.superclass.addxtypeChild.call(this, tree, cntr);
4071 this.menuitems.add(comp);
4083 this.getEl().dom.innerHTML = '';
4084 this.menuitems.clear();
4090 * @class Roo.bootstrap.menu.Item
4091 * @extends Roo.bootstrap.Component
4092 * @children Roo.bootstrap.Button Roo.bootstrap.ButtonUploader Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Container
4093 * @parent Roo.bootstrap.menu.Menu
4095 * Bootstrap MenuItem class
4097 * @cfg {String} html the menu label
4098 * @cfg {String} href the link
4099 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
4100 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
4101 * @cfg {Boolean} active used on sidebars to highlight active itesm
4102 * @cfg {String} fa favicon to show on left of menu item.
4103 * @cfg {Roo.bootsrap.Menu} menu the child menu.
4107 * Create a new MenuItem
4108 * @param {Object} config The config object
4112 Roo.bootstrap.menu.Item = function(config){
4113 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
4118 * The raw click event for the entire grid.
4119 * @param {Roo.bootstrap.menu.Item} this
4120 * @param {Roo.EventObject} e
4126 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
4130 preventDefault: false,
4131 isContainer : false,
4135 getAutoCreate : function(){
4137 if(this.isContainer){
4140 cls: 'dropdown-menu-item '
4150 cls : 'dropdown-item',
4155 if (this.fa !== false) {
4158 cls : 'fa fa-' + this.fa
4167 cls: 'dropdown-menu-item',
4170 if (this.parent().type == 'treeview') {
4171 cfg.cls = 'treeview-menu';
4174 cfg.cls += ' active';
4179 anc.href = this.href || cfg.cn[0].href ;
4180 ctag.html = this.html || cfg.cn[0].html ;
4184 initEvents: function()
4186 if (this.parent().type == 'treeview') {
4187 this.el.select('a').on('click', this.onClick, this);
4191 this.menu.parentType = this.xtype;
4192 this.menu.triggerEl = this.el;
4193 this.menu = this.addxtype(Roo.apply({}, this.menu));
4197 onClick : function(e)
4199 //Roo.log('item on click ');
4201 if(this.href === false || this.preventDefault){
4204 //this.parent().hideMenuItems();
4206 this.fireEvent('click', this, e);
4220 * @class Roo.bootstrap.menu.Separator
4221 * @extends Roo.bootstrap.Component
4223 * @parent Roo.bootstrap.menu.Menu
4224 * Bootstrap Separator class
4227 * Create a new Separator
4228 * @param {Object} config The config object
4232 Roo.bootstrap.menu.Separator = function(config){
4233 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
4236 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
4238 getAutoCreate : function(){
4241 cls: 'dropdown-divider divider'
4257 * @class Roo.bootstrap.Modal
4258 * @extends Roo.bootstrap.Component
4259 * @parent none builder
4260 * @children Roo.bootstrap.Component
4261 * Bootstrap Modal class
4262 * @cfg {String} title Title of dialog
4263 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
4264 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
4265 * @cfg {Boolean} specificTitle default false
4266 * @cfg {Roo.bootstrap.Button} buttons[] Array of buttons or standard button set..
4267 * @cfg {String} buttonPosition (left|right|center) default right (DEPRICATED) - use mr-auto on buttons to put them on the left
4268 * @cfg {Boolean} animate default true
4269 * @cfg {Boolean} allow_close default true
4270 * @cfg {Boolean} fitwindow default false
4271 * @cfg {Boolean} bodyOverflow should the body element have overflow auto added default false
4272 * @cfg {Number} width fixed width - usefull for chrome extension only really.
4273 * @cfg {Number} height fixed height - usefull for chrome extension only really.
4274 * @cfg {String} size (sm|lg|xl) default empty
4275 * @cfg {Number} max_width set the max width of modal
4276 * @cfg {Boolean} editableTitle can the title be edited
4281 * Create a new Modal Dialog
4282 * @param {Object} config The config object
4285 Roo.bootstrap.Modal = function(config){
4286 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
4291 * The raw btnclick event for the button
4292 * @param {Roo.EventObject} e
4297 * Fire when dialog resize
4298 * @param {Roo.bootstrap.Modal} this
4299 * @param {Roo.EventObject} e
4303 * @event titlechanged
4304 * Fire when the editable title has been changed
4305 * @param {Roo.bootstrap.Modal} this
4306 * @param {Roo.EventObject} value
4308 "titlechanged" : true
4311 this.buttons = this.buttons || [];
4314 this.tmpl = Roo.factory(this.tmpl);
4319 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
4321 title : 'test dialog',
4331 specificTitle: false,
4333 buttonPosition: 'right',
4355 editableTitle : false,
4357 onRender : function(ct, position)
4359 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
4362 var cfg = Roo.apply({}, this.getAutoCreate());
4365 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
4367 //if (!cfg.name.length) {
4371 cfg.cls += ' ' + this.cls;
4374 cfg.style = this.style;
4376 this.el = Roo.get(document.body).createChild(cfg, position);
4378 //var type = this.el.dom.type;
4381 if(this.tabIndex !== undefined){
4382 this.el.dom.setAttribute('tabIndex', this.tabIndex);
4385 this.dialogEl = this.el.select('.modal-dialog',true).first();
4386 this.bodyEl = this.el.select('.modal-body',true).first();
4387 this.closeEl = this.el.select('.modal-header .close', true).first();
4388 this.headerEl = this.el.select('.modal-header',true).first();
4389 this.titleEl = this.el.select('.modal-title',true).first();
4390 this.footerEl = this.el.select('.modal-footer',true).first();
4392 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
4394 //this.el.addClass("x-dlg-modal");
4396 if (this.buttons.length) {
4397 Roo.each(this.buttons, function(bb) {
4398 var b = Roo.apply({}, bb);
4399 b.xns = b.xns || Roo.bootstrap;
4400 b.xtype = b.xtype || 'Button';
4401 if (typeof(b.listeners) == 'undefined') {
4402 b.listeners = { click : this.onButtonClick.createDelegate(this) };
4405 var btn = Roo.factory(b);
4407 btn.render(this.getButtonContainer());
4411 // render the children.
4414 if(typeof(this.items) != 'undefined'){
4415 var items = this.items;
4418 for(var i =0;i < items.length;i++) {
4419 // we force children not to montor widnow resize - as we do that for them.
4420 items[i].monitorWindowResize = false;
4421 nitems.push(this.addxtype(Roo.apply({}, items[i])));
4425 this.items = nitems;
4427 // where are these used - they used to be body/close/footer
4431 //this.el.addClass([this.fieldClass, this.cls]);
4435 getAutoCreate : function()
4437 // we will default to modal-body-overflow - might need to remove or make optional later.
4439 cls : 'modal-body ' + (this.bodyOverflow ? 'overflow-auto' : ''),
4440 html : this.html || ''
4445 cls : 'modal-title',
4449 if(this.specificTitle){ // WTF is this?
4454 if (this.allow_close && Roo.bootstrap.version == 3) {
4464 if (this.editableTitle) {
4466 cls: 'form-control roo-editable-title d-none',
4472 if (this.allow_close && Roo.bootstrap.version == 4) {
4482 if(this.size.length){
4483 size = 'modal-' + this.size;
4486 var footer = Roo.bootstrap.version == 3 ?
4488 cls : 'modal-footer',
4492 cls: 'btn-' + this.buttonPosition
4497 { // BS4 uses mr-auto on left buttons....
4498 cls : 'modal-footer'
4509 cls: "modal-dialog " + size,
4512 cls : "modal-content",
4515 cls : 'modal-header',
4530 modal.cls += ' fade';
4536 getChildContainer : function() {
4541 getButtonContainer : function() {
4543 return Roo.bootstrap.version == 4 ?
4544 this.el.select('.modal-footer',true).first()
4545 : this.el.select('.modal-footer div',true).first();
4548 initEvents : function()
4550 if (this.allow_close) {
4551 this.closeEl.on('click', this.hide, this);
4553 Roo.EventManager.onWindowResize(this.resize, this, true);
4554 if (this.editableTitle) {
4555 this.headerEditEl = this.headerEl.select('.form-control',true).first();
4556 this.headerEl.on('click', function() { this.toggleHeaderInput(true) } , this);
4557 this.headerEditEl.on('keyup', function(e) {
4558 if([ e.RETURN , e.TAB , e.ESC ].indexOf(e.keyCode) > -1) {
4559 this.toggleHeaderInput(false)
4562 this.headerEditEl.on('blur', function(e) {
4563 this.toggleHeaderInput(false)
4572 this.maskEl.setSize(
4573 Roo.lib.Dom.getViewWidth(true),
4574 Roo.lib.Dom.getViewHeight(true)
4577 if (this.fitwindow) {
4579 this.dialogEl.setStyle( { 'max-width' : '100%' });
4581 this.width || Roo.lib.Dom.getViewportWidth(true) - 30,
4582 this.height || Roo.lib.Dom.getViewportHeight(true) // catering margin-top 30 margin-bottom 30
4587 if(this.max_width !== 0) {
4589 var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
4592 this.setSize(w, this.height);
4596 if(this.max_height) {
4597 this.setSize(w,Math.min(
4599 Roo.lib.Dom.getViewportHeight(true) - 60
4605 if(!this.fit_content) {
4606 this.setSize(w, Roo.lib.Dom.getViewportHeight(true) - 60);
4610 this.setSize(w, Math.min(
4612 this.headerEl.getHeight() +
4613 this.footerEl.getHeight() +
4614 this.getChildHeight(this.bodyEl.dom.childNodes),
4615 Roo.lib.Dom.getViewportHeight(true) - 60)
4621 setSize : function(w,h)
4628 // any layout/border etc.. resize..
4630 this.items.forEach( function(e) {
4631 e.layout ? e.layout() : false;
4640 if (!this.rendered) {
4643 this.toggleHeaderInput(false);
4644 //this.el.setStyle('display', 'block');
4645 this.el.removeClass('hideing');
4646 this.el.dom.style.display='block';
4648 Roo.get(document.body).addClass('modal-open');
4650 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
4653 this.el.addClass('show');
4654 this.el.addClass('in');
4657 this.el.addClass('show');
4658 this.el.addClass('in');
4661 // not sure how we can show data in here..
4663 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
4666 Roo.get(document.body).addClass("x-body-masked");
4668 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
4669 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
4670 this.maskEl.dom.style.display = 'block';
4671 this.maskEl.addClass('show');
4676 this.fireEvent('show', this);
4678 // set zindex here - otherwise it appears to be ignored...
4679 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
4682 // this is for children that are... layout.Border
4684 this.items.forEach( function(e) {
4685 e.layout ? e.layout() : false;
4693 if(this.fireEvent("beforehide", this) !== false){
4695 this.maskEl.removeClass('show');
4697 this.maskEl.dom.style.display = '';
4698 Roo.get(document.body).removeClass("x-body-masked");
4699 this.el.removeClass('in');
4700 this.el.select('.modal-dialog', true).first().setStyle('transform','');
4702 if(this.animate){ // why
4703 this.el.addClass('hideing');
4704 this.el.removeClass('show');
4706 if (!this.el.hasClass('hideing')) {
4707 return; // it's been shown again...
4710 this.el.dom.style.display='';
4712 Roo.get(document.body).removeClass('modal-open');
4713 this.el.removeClass('hideing');
4717 this.el.removeClass('show');
4718 this.el.dom.style.display='';
4719 Roo.get(document.body).removeClass('modal-open');
4722 this.fireEvent('hide', this);
4725 isVisible : function()
4728 return this.el.hasClass('show') && !this.el.hasClass('hideing');
4732 addButton : function(str, cb)
4736 var b = Roo.apply({}, { html : str } );
4737 b.xns = b.xns || Roo.bootstrap;
4738 b.xtype = b.xtype || 'Button';
4739 if (typeof(b.listeners) == 'undefined') {
4740 b.listeners = { click : cb.createDelegate(this) };
4743 var btn = Roo.factory(b);
4745 btn.render(this.getButtonContainer());
4751 setDefaultButton : function(btn)
4753 //this.el.select('.modal-footer').()
4756 resizeTo: function(w,h)
4758 this.dialogEl.setWidth(w);
4760 var diff = this.headerEl.getHeight() + this.footerEl.getHeight() + 60; // dialog margin-bottom: 30
4762 this.bodyEl.setHeight(h - diff);
4764 this.fireEvent('resize', this);
4767 setContentSize : function(w, h)
4771 onButtonClick: function(btn,e)
4774 this.fireEvent('btnclick', btn.name, e);
4777 * Set the title of the Dialog
4778 * @param {String} str new Title
4780 setTitle: function(str) {
4781 this.titleEl.dom.innerHTML = str;
4785 * Set the body of the Dialog
4786 * @param {String} str new Title
4788 setBody: function(str) {
4789 this.bodyEl.dom.innerHTML = str;
4792 * Set the body of the Dialog using the template
4793 * @param {Obj} data - apply this data to the template and replace the body contents.
4795 applyBody: function(obj)
4798 Roo.log("Error - using apply Body without a template");
4801 this.tmpl.overwrite(this.bodyEl, obj);
4804 getChildHeight : function(child_nodes)
4808 child_nodes.length == 0
4813 var child_height = 0;
4815 for(var i = 0; i < child_nodes.length; i++) {
4818 * for modal with tabs...
4819 if(child_nodes[i].classList.contains('roo-layout-panel')) {
4821 var layout_childs = child_nodes[i].childNodes;
4823 for(var j = 0; j < layout_childs.length; j++) {
4825 if(layout_childs[j].classList.contains('roo-layout-panel-body')) {
4827 var layout_body_childs = layout_childs[j].childNodes;
4829 for(var k = 0; k < layout_body_childs.length; k++) {
4831 if(layout_body_childs[k].classList.contains('navbar')) {
4832 child_height += layout_body_childs[k].offsetHeight;
4836 if(layout_body_childs[k].classList.contains('roo-layout-tabs-body')) {
4838 var layout_body_tab_childs = layout_body_childs[k].childNodes;
4840 for(var m = 0; m < layout_body_tab_childs.length; m++) {
4842 if(layout_body_tab_childs[m].classList.contains('roo-layout-active-content')) {
4843 child_height += this.getChildHeight(layout_body_tab_childs[m].childNodes);
4858 child_height += child_nodes[i].offsetHeight;
4859 // Roo.log(child_nodes[i].offsetHeight);
4862 return child_height;
4864 toggleHeaderInput : function(is_edit)
4866 if (!this.editableTitle) {
4867 return; // not editable.
4869 if (is_edit && this.is_header_editing) {
4870 return; // already editing..
4874 this.headerEditEl.dom.value = this.title;
4875 this.headerEditEl.removeClass('d-none');
4876 this.headerEditEl.dom.focus();
4877 this.titleEl.addClass('d-none');
4879 this.is_header_editing = true;
4882 // flip back to not editing.
4883 this.title = this.headerEditEl.dom.value;
4884 this.headerEditEl.addClass('d-none');
4885 this.titleEl.removeClass('d-none');
4886 this.titleEl.dom.innerHTML = String.format('{0}', this.title);
4887 this.is_header_editing = false;
4888 this.fireEvent('titlechanged', this, this.title);
4897 Roo.apply(Roo.bootstrap.Modal, {
4899 * Button config that displays a single OK button
4908 * Button config that displays Yes and No buttons
4924 * Button config that displays OK and Cancel buttons
4939 * Button config that displays Yes, No and Cancel buttons
4964 * messagebox - can be used as a replace
4968 * @class Roo.MessageBox
4969 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
4973 Roo.Msg.alert('Status', 'Changes saved successfully.');
4975 // Prompt for user data:
4976 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
4978 // process text value...
4982 // Show a dialog using config options:
4984 title:'Save Changes?',
4985 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
4986 buttons: Roo.Msg.YESNOCANCEL,
4993 Roo.bootstrap.MessageBox = function(){
4994 var dlg, opt, mask, waitTimer;
4995 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
4996 var buttons, activeTextEl, bwidth;
5000 var handleButton = function(button){
5002 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
5006 var handleHide = function(){
5008 dlg.el.removeClass(opt.cls);
5011 // Roo.TaskMgr.stop(waitTimer);
5012 // waitTimer = null;
5017 var updateButtons = function(b){
5020 buttons["ok"].hide();
5021 buttons["cancel"].hide();
5022 buttons["yes"].hide();
5023 buttons["no"].hide();
5024 dlg.footerEl.hide();
5028 dlg.footerEl.show();
5029 for(var k in buttons){
5030 if(typeof buttons[k] != "function"){
5033 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
5034 width += buttons[k].el.getWidth()+15;
5044 var handleEsc = function(d, k, e){
5045 if(opt && opt.closable !== false){
5055 * Returns a reference to the underlying {@link Roo.BasicDialog} element
5056 * @return {Roo.BasicDialog} The BasicDialog element
5058 getDialog : function(){
5060 dlg = new Roo.bootstrap.Modal( {
5063 //constraintoviewport:false,
5065 //collapsible : false,
5070 //buttonAlign:"center",
5071 closeClick : function(){
5072 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
5075 handleButton("cancel");
5080 dlg.on("hide", handleHide);
5082 //dlg.addKeyListener(27, handleEsc);
5084 this.buttons = buttons;
5085 var bt = this.buttonText;
5086 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
5087 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
5088 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
5089 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
5091 bodyEl = dlg.bodyEl.createChild({
5093 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
5094 '<textarea class="roo-mb-textarea"></textarea>' +
5095 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
5097 msgEl = bodyEl.dom.firstChild;
5098 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
5099 textboxEl.enableDisplayMode();
5100 textboxEl.addKeyListener([10,13], function(){
5101 if(dlg.isVisible() && opt && opt.buttons){
5104 }else if(opt.buttons.yes){
5105 handleButton("yes");
5109 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
5110 textareaEl.enableDisplayMode();
5111 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
5112 progressEl.enableDisplayMode();
5114 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
5115 var pf = progressEl.dom.firstChild;
5117 pp = Roo.get(pf.firstChild);
5118 pp.setHeight(pf.offsetHeight);
5126 * Updates the message box body text
5127 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
5128 * the XHTML-compliant non-breaking space character '&#160;')
5129 * @return {Roo.MessageBox} This message box
5131 updateText : function(text)
5133 if(!dlg.isVisible() && !opt.width){
5134 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
5135 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
5137 msgEl.innerHTML = text || ' ';
5139 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
5140 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
5142 Math.min(opt.width || cw , this.maxWidth),
5143 Math.max(opt.minWidth || this.minWidth, bwidth)
5146 activeTextEl.setWidth(w);
5148 if(dlg.isVisible()){
5149 dlg.fixedcenter = false;
5151 // to big, make it scroll. = But as usual stupid IE does not support
5154 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
5155 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
5156 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
5158 bodyEl.dom.style.height = '';
5159 bodyEl.dom.style.overflowY = '';
5162 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
5164 bodyEl.dom.style.overflowX = '';
5167 dlg.setContentSize(w, bodyEl.getHeight());
5168 if(dlg.isVisible()){
5169 dlg.fixedcenter = true;
5175 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
5176 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
5177 * @param {Number} value Any number between 0 and 1 (e.g., .5)
5178 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
5179 * @return {Roo.MessageBox} This message box
5181 updateProgress : function(value, text){
5183 this.updateText(text);
5186 if (pp) { // weird bug on my firefox - for some reason this is not defined
5187 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
5188 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
5194 * Returns true if the message box is currently displayed
5195 * @return {Boolean} True if the message box is visible, else false
5197 isVisible : function(){
5198 return dlg && dlg.isVisible();
5202 * Hides the message box if it is displayed
5205 if(this.isVisible()){
5211 * Displays a new message box, or reinitializes an existing message box, based on the config options
5212 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
5213 * The following config object properties are supported:
5215 Property Type Description
5216 ---------- --------------- ------------------------------------------------------------------------------------
5217 animEl String/Element An id or Element from which the message box should animate as it opens and
5218 closes (defaults to undefined)
5219 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
5220 cancel:'Bar'}), or false to not show any buttons (defaults to false)
5221 closable Boolean False to hide the top-right close button (defaults to true). Note that
5222 progress and wait dialogs will ignore this property and always hide the
5223 close button as they can only be closed programmatically.
5224 cls String A custom CSS class to apply to the message box element
5225 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
5226 displayed (defaults to 75)
5227 fn Function A callback function to execute after closing the dialog. The arguments to the
5228 function will be btn (the name of the button that was clicked, if applicable,
5229 e.g. "ok"), and text (the value of the active text field, if applicable).
5230 Progress and wait dialogs will ignore this option since they do not respond to
5231 user actions and can only be closed programmatically, so any required function
5232 should be called by the same code after it closes the dialog.
5233 icon String A CSS class that provides a background image to be used as an icon for
5234 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
5235 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
5236 minWidth Number The minimum width in pixels of the message box (defaults to 100)
5237 modal Boolean False to allow user interaction with the page while the message box is
5238 displayed (defaults to true)
5239 msg String A string that will replace the existing message box body text (defaults
5240 to the XHTML-compliant non-breaking space character ' ')
5241 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
5242 progress Boolean True to display a progress bar (defaults to false)
5243 progressText String The text to display inside the progress bar if progress = true (defaults to '')
5244 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
5245 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
5246 title String The title text
5247 value String The string value to set into the active textbox element if displayed
5248 wait Boolean True to display a progress bar (defaults to false)
5249 width Number The width of the dialog in pixels
5256 msg: 'Please enter your address:',
5258 buttons: Roo.MessageBox.OKCANCEL,
5261 animEl: 'addAddressBtn'
5264 * @param {Object} config Configuration options
5265 * @return {Roo.MessageBox} This message box
5267 show : function(options)
5270 // this causes nightmares if you show one dialog after another
5271 // especially on callbacks..
5273 if(this.isVisible()){
5276 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
5277 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
5278 Roo.log("New Dialog Message:" + options.msg )
5279 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
5280 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
5283 var d = this.getDialog();
5285 d.setTitle(opt.title || " ");
5286 d.closeEl.setDisplayed(opt.closable !== false);
5287 activeTextEl = textboxEl;
5288 opt.prompt = opt.prompt || (opt.multiline ? true : false);
5293 textareaEl.setHeight(typeof opt.multiline == "number" ?
5294 opt.multiline : this.defaultTextHeight);
5295 activeTextEl = textareaEl;
5304 progressEl.setDisplayed(opt.progress === true);
5306 d.animate = false; // do not animate progress, as it may not have finished animating before we close it..
5308 this.updateProgress(0);
5309 activeTextEl.dom.value = opt.value || "";
5311 dlg.setDefaultButton(activeTextEl);
5313 var bs = opt.buttons;
5317 }else if(bs && bs.yes){
5318 db = buttons["yes"];
5320 dlg.setDefaultButton(db);
5322 bwidth = updateButtons(opt.buttons);
5323 this.updateText(opt.msg);
5325 d.el.addClass(opt.cls);
5327 d.proxyDrag = opt.proxyDrag === true;
5328 d.modal = opt.modal !== false;
5329 d.mask = opt.modal !== false ? mask : false;
5331 // force it to the end of the z-index stack so it gets a cursor in FF
5332 document.body.appendChild(dlg.el.dom);
5333 d.animateTarget = null;
5334 d.show(options.animEl);
5340 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
5341 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
5342 * and closing the message box when the process is complete.
5343 * @param {String} title The title bar text
5344 * @param {String} msg The message box body text
5345 * @return {Roo.MessageBox} This message box
5347 progress : function(title, msg){
5354 minWidth: this.minProgressWidth,
5361 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
5362 * If a callback function is passed it will be called after the user clicks the button, and the
5363 * id of the button that was clicked will be passed as the only parameter to the callback
5364 * (could also be the top-right close button).
5365 * @param {String} title The title bar text
5366 * @param {String} msg The message box body text
5367 * @param {Function} fn (optional) The callback function invoked after the message box is closed
5368 * @param {Object} scope (optional) The scope of the callback function
5369 * @return {Roo.MessageBox} This message box
5371 alert : function(title, msg, fn, scope)
5386 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
5387 * interaction while waiting for a long-running process to complete that does not have defined intervals.
5388 * You are responsible for closing the message box when the process is complete.
5389 * @param {String} msg The message box body text
5390 * @param {String} title (optional) The title bar text
5391 * @return {Roo.MessageBox} This message box
5393 wait : function(msg, title){
5404 waitTimer = Roo.TaskMgr.start({
5406 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
5414 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
5415 * If a callback function is passed it will be called after the user clicks either button, and the id of the
5416 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
5417 * @param {String} title The title bar text
5418 * @param {String} msg The message box body text
5419 * @param {Function} fn (optional) The callback function invoked after the message box is closed
5420 * @param {Object} scope (optional) The scope of the callback function
5421 * @return {Roo.MessageBox} This message box
5423 confirm : function(title, msg, fn, scope){
5427 buttons: this.YESNO,
5436 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
5437 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
5438 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
5439 * (could also be the top-right close button) and the text that was entered will be passed as the two
5440 * parameters to the callback.
5441 * @param {String} title The title bar text
5442 * @param {String} msg The message box body text
5443 * @param {Function} fn (optional) The callback function invoked after the message box is closed
5444 * @param {Object} scope (optional) The scope of the callback function
5445 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
5446 * property, or the height in pixels to create the textbox (defaults to false / single-line)
5447 * @return {Roo.MessageBox} This message box
5449 prompt : function(title, msg, fn, scope, multiline){
5453 buttons: this.OKCANCEL,
5458 multiline: multiline,
5465 * Button config that displays a single OK button
5470 * Button config that displays Yes and No buttons
5473 YESNO : {yes:true, no:true},
5475 * Button config that displays OK and Cancel buttons
5478 OKCANCEL : {ok:true, cancel:true},
5480 * Button config that displays Yes, No and Cancel buttons
5483 YESNOCANCEL : {yes:true, no:true, cancel:true},
5486 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
5489 defaultTextHeight : 75,
5491 * The maximum width in pixels of the message box (defaults to 600)
5496 * The minimum width in pixels of the message box (defaults to 100)
5501 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
5502 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
5505 minProgressWidth : 250,
5507 * An object containing the default button text strings that can be overriden for localized language support.
5508 * Supported properties are: ok, cancel, yes and no.
5509 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
5522 * Shorthand for {@link Roo.MessageBox}
5524 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
5525 Roo.Msg = Roo.Msg || Roo.MessageBox;
5534 * @class Roo.bootstrap.nav.Bar
5535 * @extends Roo.bootstrap.Component
5537 * Bootstrap Navbar class
5540 * Create a new Navbar
5541 * @param {Object} config The config object
5545 Roo.bootstrap.nav.Bar = function(config){
5546 Roo.bootstrap.nav.Bar.superclass.constructor.call(this, config);
5550 * @event beforetoggle
5551 * Fire before toggle the menu
5552 * @param {Roo.EventObject} e
5554 "beforetoggle" : true
5558 Roo.extend(Roo.bootstrap.nav.Bar, Roo.bootstrap.Component, {
5567 getAutoCreate : function(){
5570 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
5574 initEvents :function ()
5576 //Roo.log(this.el.select('.navbar-toggle',true));
5577 this.el.select('.navbar-toggle',true).on('click', this.onToggle , this);
5584 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
5586 var size = this.el.getSize();
5587 this.maskEl.setSize(size.width, size.height);
5588 this.maskEl.enableDisplayMode("block");
5597 getChildContainer : function()
5599 if (this.el && this.el.select('.collapse').getCount()) {
5600 return this.el.select('.collapse',true).first();
5615 onToggle : function()
5618 if(this.fireEvent('beforetoggle', this) === false){
5621 var ce = this.el.select('.navbar-collapse',true).first();
5623 if (!ce.hasClass('show')) {
5633 * Expand the navbar pulldown
5635 expand : function ()
5638 var ce = this.el.select('.navbar-collapse',true).first();
5639 if (ce.hasClass('collapsing')) {
5642 ce.dom.style.height = '';
5644 ce.addClass('in'); // old...
5645 ce.removeClass('collapse');
5646 ce.addClass('show');
5647 var h = ce.getHeight();
5649 ce.removeClass('show');
5650 // at this point we should be able to see it..
5651 ce.addClass('collapsing');
5653 ce.setHeight(0); // resize it ...
5654 ce.on('transitionend', function() {
5655 //Roo.log('done transition');
5656 ce.removeClass('collapsing');
5657 ce.addClass('show');
5658 ce.removeClass('collapse');
5660 ce.dom.style.height = '';
5661 }, this, { single: true} );
5663 ce.dom.scrollTop = 0;
5666 * Collapse the navbar pulldown
5668 collapse : function()
5670 var ce = this.el.select('.navbar-collapse',true).first();
5672 if (ce.hasClass('collapsing') || ce.hasClass('collapse') ) {
5673 // it's collapsed or collapsing..
5676 ce.removeClass('in'); // old...
5677 ce.setHeight(ce.getHeight());
5678 ce.removeClass('show');
5679 ce.addClass('collapsing');
5681 ce.on('transitionend', function() {
5682 ce.dom.style.height = '';
5683 ce.removeClass('collapsing');
5684 ce.addClass('collapse');
5685 }, this, { single: true} );
5705 * @class Roo.bootstrap.nav.Simplebar
5706 * @extends Roo.bootstrap.nav.Bar
5707 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container Roo.bootstrap.form.Form Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Link
5708 * Bootstrap Sidebar class
5710 * @cfg {Boolean} inverse is inverted color
5712 * @cfg {String} type (nav | pills | tabs)
5713 * @cfg {Boolean} arrangement stacked | justified
5714 * @cfg {String} align (left | right) alignment
5716 * @cfg {Boolean} main (true|false) main nav bar? default false
5717 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
5719 * @cfg {String} tag (header|footer|nav|div) default is nav
5721 * @cfg {String} weight (light|primary|secondary|success|danger|warning|info|dark|white) default is light.
5725 * Create a new Sidebar
5726 * @param {Object} config The config object
5730 Roo.bootstrap.nav.Simplebar = function(config){
5731 Roo.bootstrap.nav.Simplebar.superclass.constructor.call(this, config);
5734 Roo.extend(Roo.bootstrap.nav.Simplebar, Roo.bootstrap.nav.Bar, {
5750 getAutoCreate : function(){
5754 tag : this.tag || 'div',
5755 cls : 'navbar roo-navbar-simple' //navbar-expand-lg ??
5757 if (['light','white'].indexOf(this.weight) > -1) {
5758 cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
5760 cfg.cls += ' bg-' + this.weight;
5763 cfg.cls += ' navbar-inverse';
5767 // i'm not actually sure these are really used - normally we add a navGroup to a navbar
5769 if (Roo.bootstrap.version == 4 && this.xtype == 'NavSimplebar') {
5778 cls: 'nav nav-' + this.xtype,
5784 this.type = this.type || 'nav';
5785 if (['tabs','pills'].indexOf(this.type) != -1) {
5786 cfg.cn[0].cls += ' nav-' + this.type
5790 if (this.type!=='nav') {
5791 Roo.log('nav type must be nav/tabs/pills')
5793 cfg.cn[0].cls += ' navbar-nav'
5799 if (['stacked','justified'].indexOf(this.arrangement) != -1) {
5800 cfg.cn[0].cls += ' nav-' + this.arrangement;
5804 if (this.align === 'right') {
5805 cfg.cn[0].cls += ' navbar-right';
5830 * navbar-expand-md fixed-top
5834 * @class Roo.bootstrap.nav.Headerbar
5835 * @extends Roo.bootstrap.nav.Simplebar
5836 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container Roo.bootstrap.form.Form Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Link
5837 * Bootstrap Sidebar class
5839 * @cfg {String} brand what is brand
5840 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
5841 * @cfg {String} brand_href href of the brand
5842 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
5843 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
5844 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
5845 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
5848 * Create a new Sidebar
5849 * @param {Object} config The config object
5853 Roo.bootstrap.nav.Headerbar = function(config){
5854 Roo.bootstrap.nav.Headerbar.superclass.constructor.call(this, config);
5858 Roo.extend(Roo.bootstrap.nav.Headerbar, Roo.bootstrap.nav.Simplebar, {
5865 desktopCenter : false,
5868 getAutoCreate : function(){
5871 tag: this.nav || 'nav',
5872 cls: 'navbar navbar-expand-md',
5878 if (this.desktopCenter) {
5879 cn.push({cls : 'container', cn : []});
5887 cls: 'navbar-toggle navbar-toggler',
5888 'data-toggle': 'collapse',
5893 html: 'Toggle navigation'
5897 cls: 'icon-bar navbar-toggler-icon'
5910 cn.push( Roo.bootstrap.version == 4 ? btn : {
5912 cls: 'navbar-header',
5921 cls: Roo.bootstrap.version == 4 ? 'nav flex-row roo-navbar-collapse collapse navbar-collapse' : 'collapse navbar-collapse roo-navbar-collapse',
5925 cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
5927 if (['light','white'].indexOf(this.weight) > -1) {
5928 cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
5930 cfg.cls += ' bg-' + this.weight;
5933 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
5934 cfg.cls += ' navbar-' + this.position + ' ' + this.position ;
5936 // tag can override this..
5938 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
5941 if (this.brand !== '') {
5942 var cp = Roo.bootstrap.version == 4 ? cn : cn[0].cn;
5943 cp.unshift({ // changed from push ?? BS4 needs it at the start? - does this break or exsiting?
5945 href: this.brand_href ? this.brand_href : '#',
5946 cls: 'navbar-brand',
5954 cfg.cls += ' main-nav';
5962 getHeaderChildContainer : function()
5964 if (this.srButton && this.el.select('.navbar-header').getCount()) {
5965 return this.el.select('.navbar-header',true).first();
5968 return this.getChildContainer();
5971 getChildContainer : function()
5974 return this.el.select('.roo-navbar-collapse',true).first();
5979 initEvents : function()
5981 Roo.bootstrap.nav.Headerbar.superclass.initEvents.call(this);
5983 if (this.autohide) {
5988 Roo.get(document).on('scroll',function(e) {
5989 var ns = Roo.get(document).getScroll().top;
5990 var os = prevScroll;
5994 ft.removeClass('slideDown');
5995 ft.addClass('slideUp');
5998 ft.removeClass('slideUp');
5999 ft.addClass('slideDown');
6020 * @class Roo.bootstrap.nav.Sidebar
6021 * @extends Roo.bootstrap.nav.Bar
6022 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container Roo.bootstrap.form.Form Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Link
6023 * Bootstrap Sidebar class
6026 * Create a new Sidebar
6027 * @param {Object} config The config object
6031 Roo.bootstrap.nav.Sidebar = function(config){
6032 Roo.bootstrap.nav.Sidebar.superclass.constructor.call(this, config);
6035 Roo.extend(Roo.bootstrap.nav.Sidebar, Roo.bootstrap.nav.Bar, {
6037 sidebar : true, // used by Navbar Item and NavbarGroup at present...
6039 getAutoCreate : function(){
6044 cls: 'sidebar sidebar-nav'
6066 * @class Roo.bootstrap.nav.Group
6067 * @extends Roo.bootstrap.Component
6068 * @children Roo.bootstrap.nav.Item
6069 * Bootstrap NavGroup class
6070 * @cfg {String} align (left|right)
6071 * @cfg {Boolean} inverse
6072 * @cfg {String} type (nav|pills|tab) default nav
6073 * @cfg {String} navId - reference Id for navbar.
6074 * @cfg {Boolean} pilltype default true (turn to off to disable active toggle)
6077 * Create a new nav group
6078 * @param {Object} config The config object
6081 Roo.bootstrap.nav.Group = function(config){
6082 Roo.bootstrap.nav.Group.superclass.constructor.call(this, config);
6085 Roo.bootstrap.nav.Group.register(this);
6089 * Fires when the active item changes
6090 * @param {Roo.bootstrap.nav.Group} this
6091 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
6092 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
6099 Roo.extend(Roo.bootstrap.nav.Group, Roo.bootstrap.Component, {
6111 getAutoCreate : function()
6113 var cfg = Roo.apply({}, Roo.bootstrap.nav.Group.superclass.getAutoCreate.call(this));
6119 if (Roo.bootstrap.version == 4) {
6120 if (['tabs','pills'].indexOf(this.type) != -1) {
6121 cfg.cls += ' nav-' + this.type;
6123 // trying to remove so header bar can right align top?
6124 if (this.parent() && this.parent().xtype != 'NavHeaderbar') {
6125 // do not use on header bar...
6126 cfg.cls += ' navbar-nav';
6131 if (['tabs','pills'].indexOf(this.type) != -1) {
6132 cfg.cls += ' nav-' + this.type
6134 if (this.type !== 'nav') {
6135 Roo.log('nav type must be nav/tabs/pills')
6137 cfg.cls += ' navbar-nav'
6141 if (this.parent() && this.parent().sidebar) {
6144 cls: 'dashboard-menu sidebar-menu'
6150 if (this.form === true) {
6153 cls: 'navbar-form form-inline'
6155 //nav navbar-right ml-md-auto
6156 if (this.align === 'right') {
6157 cfg.cls += ' navbar-right ml-md-auto';
6159 cfg.cls += ' navbar-left';
6163 if (this.align === 'right') {
6164 cfg.cls += ' navbar-right ml-md-auto';
6166 cfg.cls += ' mr-auto';
6170 cfg.cls += ' navbar-inverse';
6178 * sets the active Navigation item
6179 * @param {Roo.bootstrap.nav.Item} the new current navitem
6181 setActiveItem : function(item)
6184 Roo.each(this.navItems, function(v){
6189 v.setActive(false, true);
6196 item.setActive(true, true);
6197 this.fireEvent('changed', this, item, prev);
6202 * gets the active Navigation item
6203 * @return {Roo.bootstrap.nav.Item} the current navitem
6205 getActive : function()
6209 Roo.each(this.navItems, function(v){
6220 indexOfNav : function()
6224 Roo.each(this.navItems, function(v,i){
6235 * adds a Navigation item
6236 * @param {Roo.bootstrap.nav.Item} the navitem to add
6238 addItem : function(cfg)
6240 if (this.form && Roo.bootstrap.version == 4) {
6243 var cn = new Roo.bootstrap.nav.Item(cfg);
6245 cn.parentId = this.id;
6246 cn.onRender(this.el, null);
6250 * register a Navigation item
6251 * @param {Roo.bootstrap.nav.Item} the navitem to add
6253 register : function(item)
6255 this.navItems.push( item);
6256 item.navId = this.navId;
6261 * clear all the Navigation item
6264 clearAll : function()
6267 this.el.dom.innerHTML = '';
6270 getNavItem: function(tabId)
6273 Roo.each(this.navItems, function(e) {
6274 if (e.tabId == tabId) {
6284 setActiveNext : function()
6286 var i = this.indexOfNav(this.getActive());
6287 if (i > this.navItems.length) {
6290 this.setActiveItem(this.navItems[i+1]);
6292 setActivePrev : function()
6294 var i = this.indexOfNav(this.getActive());
6298 this.setActiveItem(this.navItems[i-1]);
6300 clearWasActive : function(except) {
6301 Roo.each(this.navItems, function(e) {
6302 if (e.tabId != except.tabId && e.was_active) {
6303 e.was_active = false;
6310 getWasActive : function ()
6313 Roo.each(this.navItems, function(e) {
6328 Roo.apply(Roo.bootstrap.nav.Group, {
6332 * register a Navigation Group
6333 * @param {Roo.bootstrap.nav.Group} the navgroup to add
6335 register : function(navgrp)
6337 this.groups[navgrp.navId] = navgrp;
6341 * fetch a Navigation Group based on the navigation ID
6342 * @param {string} the navgroup to add
6343 * @returns {Roo.bootstrap.nav.Group} the navgroup
6345 get: function(navId) {
6346 if (typeof(this.groups[navId]) == 'undefined') {
6348 //this.register(new Roo.bootstrap.nav.Group({ navId : navId }));
6350 return this.groups[navId] ;
6358 * @class Roo.bootstrap.nav.Item
6359 * @extends Roo.bootstrap.Component
6360 * @children Roo.bootstrap.Container Roo.bootstrap.Button
6361 * @parent Roo.bootstrap.nav.Group
6363 * Bootstrap Navbar.NavItem class
6365 * @cfg {String} href link to
6366 * @cfg {String} button_weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default none
6367 * @cfg {Boolean} button_outline show and outlined button
6368 * @cfg {String} html content of button
6369 * @cfg {String} badge text inside badge
6370 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
6371 * @cfg {String} glyphicon DEPRICATED - use fa
6372 * @cfg {String} icon DEPRICATED - use fa
6373 * @cfg {String} fa - Fontawsome icon name (can add stuff to it like fa-2x)
6374 * @cfg {Boolean} active Is item active
6375 * @cfg {Boolean} disabled Is item disabled
6376 * @cfg {String} linkcls Link Class
6377 * @cfg {Boolean} preventDefault (true | false) default false
6378 * @cfg {String} tabId the tab that this item activates.
6379 * @cfg {String} tagtype (a|span) render as a href or span?
6380 * @cfg {Boolean} animateRef (true|false) link to element default false
6381 * @cfg {Roo.bootstrap.menu.Menu} menu a Menu
6384 * Create a new Navbar Item
6385 * @param {Object} config The config object
6387 Roo.bootstrap.nav.Item = function(config){
6388 Roo.bootstrap.nav.Item.superclass.constructor.call(this, config);
6393 * The raw click event for the entire grid.
6394 * @param {Roo.EventObject} e
6399 * Fires when the active item active state changes
6400 * @param {Roo.bootstrap.nav.Item} this
6401 * @param {boolean} state the new state
6407 * Fires when scroll to element
6408 * @param {Roo.bootstrap.nav.Item} this
6409 * @param {Object} options
6410 * @param {Roo.EventObject} e
6418 Roo.extend(Roo.bootstrap.nav.Item, Roo.bootstrap.Component, {
6427 preventDefault : false,
6435 button_outline : false,
6439 getAutoCreate : function(){
6446 cfg.cls = typeof(cfg.cls) == 'undefined' ? '' : cfg.cls;
6449 cfg.cls += ' active' ;
6451 if (this.disabled) {
6452 cfg.cls += ' disabled';
6456 if (this.button_weight.length) {
6457 cfg.tag = this.href ? 'a' : 'button';
6458 cfg.html = this.html || '';
6459 cfg.cls += ' btn btn' + (this.button_outline ? '-outline' : '') + '-' + this.button_weight;
6461 cfg.href = this.href;
6464 cfg.html = '<i class="fa fas fa-'+this.fa+'"></i> <span class="nav-html">' + this.html + '</span>';
6466 cfg.cls += " nav-html";
6469 // menu .. should add dropdown-menu class - so no need for carat..
6471 if (this.badge !== '') {
6473 cfg.html += ' <span class="badge badge-secondary">' + this.badge + '</span>';
6478 if (this.href || this.html || this.glyphicon || this.icon || this.fa) {
6482 href : this.href || "#",
6483 html: this.html || '',
6487 if (this.tagtype == 'a') {
6488 cfg.cn[0].cls = 'nav-link' + (this.active ? ' active' : '') + ' ' + this.linkcls;
6492 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span class="nav-html">' + cfg.cn[0].html + '</span>';
6493 } else if (this.fa) {
6494 cfg.cn[0].html = '<i class="fa fas fa-'+this.fa+'"></i> <span class="nav-html">' + cfg.cn[0].html + '</span>';
6495 } else if(this.glyphicon) {
6496 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
6498 cfg.cn[0].cls += " nav-html";
6502 cfg.cn[0].html += " <span class='caret'></span>";
6506 if (this.badge !== '') {
6507 cfg.cn[0].html += ' <span class="badge badge-secondary">' + this.badge + '</span>';
6515 onRender : function(ct, position)
6517 // Roo.log("Call onRender: " + this.xtype);
6518 if (Roo.bootstrap.version == 4 && ct.dom.type != 'ul') {
6522 var ret = Roo.bootstrap.nav.Item.superclass.onRender.call(this, ct, position);
6523 this.navLink = this.el.select('.nav-link',true).first();
6524 this.htmlEl = this.el.hasClass('nav-html') ? this.el : this.el.select('.nav-html',true).first();
6529 initEvents: function()
6531 if (typeof (this.menu) != 'undefined') {
6532 this.menu.parentType = this.xtype;
6533 this.menu.triggerEl = this.el;
6534 this.menu = this.addxtype(Roo.apply({}, this.menu));
6537 this.el.on('click', this.onClick, this);
6539 //if(this.tagtype == 'span'){
6540 // this.el.select('span',true).on('click', this.onClick, this);
6543 // at this point parent should be available..
6544 this.parent().register(this);
6547 onClick : function(e)
6549 if (e.getTarget('.dropdown-menu-item')) {
6550 // did you click on a menu itemm.... - then don't trigger onclick..
6555 this.preventDefault ||
6556 this.href === false ||
6559 //Roo.log("NavItem - prevent Default?");
6563 if (this.disabled) {
6567 var tg = Roo.bootstrap.TabGroup.get(this.navId);
6568 if (tg && tg.transition) {
6569 Roo.log("waiting for the transitionend");
6575 //Roo.log("fire event clicked");
6576 if(this.fireEvent('click', this, e) === false){
6580 if(this.tagtype == 'span'){
6584 //Roo.log(this.href);
6585 var ael = this.el.select('a',true).first();
6588 if(ael && this.animateRef && this.href.indexOf('#') > -1){
6589 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
6590 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
6591 return; // ignore... - it's a 'hash' to another page.
6593 Roo.log("NavItem - prevent Default?");
6595 this.scrollToElement(e);
6599 var p = this.parent();
6601 if (['tabs','pills'].indexOf(p.type)!==-1 && p.pilltype) {
6602 if (typeof(p.setActiveItem) !== 'undefined') {
6603 p.setActiveItem(this);
6607 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
6608 if (p.parentType == 'NavHeaderbar' && !this.menu) {
6609 // remove the collapsed menu expand...
6610 p.parent().el.select('.roo-navbar-collapse',true).removeClass('in');
6614 isActive: function () {
6617 setActive : function(state, fire, is_was_active)
6619 if (this.active && !state && this.navId) {
6620 this.was_active = true;
6621 var nv = Roo.bootstrap.nav.Group.get(this.navId);
6623 nv.clearWasActive(this);
6627 this.active = state;
6630 this.el.removeClass('active');
6631 this.navLink ? this.navLink.removeClass('active') : false;
6632 } else if (!this.el.hasClass('active')) {
6634 this.el.addClass('active');
6635 if (Roo.bootstrap.version == 4 && this.navLink ) {
6636 this.navLink.addClass('active');
6641 this.fireEvent('changed', this, state);
6644 // show a panel if it's registered and related..
6646 if (!this.navId || !this.tabId || !state || is_was_active) {
6650 var tg = Roo.bootstrap.TabGroup.get(this.navId);
6654 var pan = tg.getPanelByName(this.tabId);
6658 // if we can not flip to new panel - go back to old nav highlight..
6659 if (false == tg.showPanel(pan)) {
6660 var nv = Roo.bootstrap.nav.Group.get(this.navId);
6662 var onav = nv.getWasActive();
6664 onav.setActive(true, false, true);
6673 // this should not be here...
6674 setDisabled : function(state)
6676 this.disabled = state;
6678 this.el.removeClass('disabled');
6679 } else if (!this.el.hasClass('disabled')) {
6680 this.el.addClass('disabled');
6686 * Fetch the element to display the tooltip on.
6687 * @return {Roo.Element} defaults to this.el
6689 tooltipEl : function()
6691 return this.el; //this.tagtype == 'a' ? this.el : this.el.select('' + this.tagtype + '', true).first();
6694 scrollToElement : function(e)
6696 var c = document.body;
6699 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
6701 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
6702 c = document.documentElement;
6705 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
6711 var o = target.calcOffsetsTo(c);
6718 this.fireEvent('scrollto', this, options, e);
6720 Roo.get(c).scrollTo('top', options.value, true);
6725 * Set the HTML (text content) of the item
6726 * @param {string} html content for the nav item
6728 setHtml : function(html)
6731 this.htmlEl.dom.innerHTML = html;
6743 * <span> icon </span>
6744 * <span> text </span>
6745 * <span>badge </span>
6749 * @class Roo.bootstrap.nav.SidebarItem
6750 * @extends Roo.bootstrap.nav.Item
6751 * Bootstrap Navbar.NavSidebarItem class
6753 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
6754 * {Boolean} open is the menu open
6755 * {Boolean} buttonView use button as the tigger el rather that a (default false)
6756 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
6757 * {String} buttonSize (sm|md|lg)the extra classes for the button
6758 * {Boolean} showArrow show arrow next to the text (default true)
6760 * Create a new Navbar Button
6761 * @param {Object} config The config object
6763 Roo.bootstrap.nav.SidebarItem = function(config){
6764 Roo.bootstrap.nav.SidebarItem.superclass.constructor.call(this, config);
6769 * The raw click event for the entire grid.
6770 * @param {Roo.EventObject} e
6775 * Fires when the active item active state changes
6776 * @param {Roo.bootstrap.nav.SidebarItem} this
6777 * @param {boolean} state the new state
6785 Roo.extend(Roo.bootstrap.nav.SidebarItem, Roo.bootstrap.nav.Item, {
6787 badgeWeight : 'default',
6793 buttonWeight : 'default',
6799 getAutoCreate : function(){
6804 href : this.href || '#',
6810 if(this.buttonView){
6813 href : this.href || '#',
6814 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
6827 cfg.cls += ' active';
6830 if (this.disabled) {
6831 cfg.cls += ' disabled';
6834 cfg.cls += ' open x-open';
6837 if (this.glyphicon || this.icon) {
6838 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
6839 a.cn.push({ tag : 'i', cls : c }) ;
6842 if(!this.buttonView){
6845 html : this.html || ''
6852 if (this.badge !== '') {
6853 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
6859 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
6862 a.cls += ' dropdown-toggle treeview' ;
6868 initEvents : function()
6870 if (typeof (this.menu) != 'undefined') {
6871 this.menu.parentType = this.xtype;
6872 this.menu.triggerEl = this.el;
6873 this.menu = this.addxtype(Roo.apply({}, this.menu));
6876 this.el.on('click', this.onClick, this);
6878 if(this.badge !== ''){
6879 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
6884 onClick : function(e)
6891 if(this.preventDefault){
6895 this.fireEvent('click', this, e);
6898 disable : function()
6900 this.setDisabled(true);
6905 this.setDisabled(false);
6908 setDisabled : function(state)
6910 if(this.disabled == state){
6914 this.disabled = state;
6917 this.el.addClass('disabled');
6921 this.el.removeClass('disabled');
6926 setActive : function(state)
6928 if(this.active == state){
6932 this.active = state;
6935 this.el.addClass('active');
6939 this.el.removeClass('active');
6944 isActive: function ()
6949 setBadge : function(str)
6955 this.badgeEl.dom.innerHTML = str;
6972 * @class Roo.bootstrap.nav.ProgressBar
6973 * @extends Roo.bootstrap.Component
6974 * @children Roo.bootstrap.nav.ProgressBarItem
6975 * Bootstrap NavProgressBar class
6978 * Create a new nav progress bar - a bar indicating step along a process
6979 * @param {Object} config The config object
6982 Roo.bootstrap.nav.ProgressBar = function(config){
6983 Roo.bootstrap.nav.ProgressBar.superclass.constructor.call(this, config);
6985 this.bullets = this.bullets || [];
6987 // Roo.bootstrap.nav.ProgressBar.register(this);
6991 * Fires when the active item changes
6992 * @param {Roo.bootstrap.nav.ProgressBar} this
6993 * @param {Roo.bootstrap.nav.ProgressItem} selected The item selected
6994 * @param {Roo.bootstrap.nav.ProgressItem} prev The previously selected item
7001 Roo.extend(Roo.bootstrap.nav.ProgressBar, Roo.bootstrap.Component, {
7003 * @cfg {Roo.bootstrap.nav.ProgressItem} NavProgressBar:bullets[]
7004 * Bullets for the Nav Progress bar for the toolbar
7009 getAutoCreate : function()
7011 var cfg = Roo.apply({}, Roo.bootstrap.nav.ProgressBar.superclass.getAutoCreate.call(this));
7015 cls : 'roo-navigation-bar-group',
7019 cls : 'roo-navigation-top-bar'
7023 cls : 'roo-navigation-bullets-bar',
7027 cls : 'roo-navigation-bar'
7034 cls : 'roo-navigation-bottom-bar'
7044 initEvents: function()
7049 onRender : function(ct, position)
7051 Roo.bootstrap.nav.ProgressBar.superclass.onRender.call(this, ct, position);
7053 if(this.bullets.length){
7054 Roo.each(this.bullets, function(b){
7063 addItem : function(cfg)
7065 var item = new Roo.bootstrap.nav.ProgressItem(cfg);
7067 item.parentId = this.id;
7068 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
7071 var top = new Roo.bootstrap.Element({
7073 cls : 'roo-navigation-bar-text'
7076 var bottom = new Roo.bootstrap.Element({
7078 cls : 'roo-navigation-bar-text'
7081 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
7082 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
7084 var topText = new Roo.bootstrap.Element({
7086 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
7089 var bottomText = new Roo.bootstrap.Element({
7091 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
7094 topText.onRender(top.el, null);
7095 bottomText.onRender(bottom.el, null);
7098 item.bottomEl = bottom;
7101 this.barItems.push(item);
7106 getActive : function()
7110 Roo.each(this.barItems, function(v){
7112 if (!v.isActive()) {
7124 setActiveItem : function(item)
7128 Roo.each(this.barItems, function(v){
7129 if (v.rid == item.rid) {
7139 item.setActive(true);
7141 this.fireEvent('changed', this, item, prev);
7144 getBarItem: function(rid)
7148 Roo.each(this.barItems, function(e) {
7160 indexOfItem : function(item)
7164 Roo.each(this.barItems, function(v, i){
7166 if (v.rid != item.rid) {
7177 setActiveNext : function()
7179 var i = this.indexOfItem(this.getActive());
7181 if (i > this.barItems.length) {
7185 this.setActiveItem(this.barItems[i+1]);
7188 setActivePrev : function()
7190 var i = this.indexOfItem(this.getActive());
7196 this.setActiveItem(this.barItems[i-1]);
7201 if(!this.barItems.length){
7205 var width = 100 / this.barItems.length;
7207 Roo.each(this.barItems, function(i){
7208 i.el.setStyle('width', width + '%');
7209 i.topEl.el.setStyle('width', width + '%');
7210 i.bottomEl.el.setStyle('width', width + '%');
7224 * @class Roo.bootstrap.nav.ProgressBarItem
7225 * @extends Roo.bootstrap.Component
7226 * Bootstrap NavProgressBarItem class
7227 * @cfg {String} rid the reference id
7228 * @cfg {Boolean} active (true|false) Is item active default false
7229 * @cfg {Boolean} disabled (true|false) Is item active default false
7230 * @cfg {String} html
7231 * @cfg {String} position (top|bottom) text position default bottom
7232 * @cfg {String} icon show icon instead of number
7235 * Create a new NavProgressBarItem
7236 * @param {Object} config The config object
7238 Roo.bootstrap.nav.ProgressBarItem = function(config){
7239 Roo.bootstrap.nav.ProgressBarItem.superclass.constructor.call(this, config);
7244 * The raw click event for the entire grid.
7245 * @param {Roo.bootstrap.nav.ProgressBarItem} this
7246 * @param {Roo.EventObject} e
7253 Roo.extend(Roo.bootstrap.nav.ProgressBarItem, Roo.bootstrap.Component, {
7259 position : 'bottom',
7262 getAutoCreate : function()
7264 var iconCls = 'roo-navigation-bar-item-icon';
7266 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
7270 cls: 'roo-navigation-bar-item',
7280 cfg.cls += ' active';
7283 cfg.cls += ' disabled';
7289 disable : function()
7291 this.setDisabled(true);
7296 this.setDisabled(false);
7299 initEvents: function()
7301 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
7303 this.iconEl.on('click', this.onClick, this);
7306 onClick : function(e)
7314 if(this.fireEvent('click', this, e) === false){
7318 this.parent().setActiveItem(this);
7321 isActive: function ()
7326 setActive : function(state)
7328 if(this.active == state){
7332 this.active = state;
7335 this.el.addClass('active');
7339 this.el.removeClass('active');
7344 setDisabled : function(state)
7346 if(this.disabled == state){
7350 this.disabled = state;
7353 this.el.addClass('disabled');
7357 this.el.removeClass('disabled');
7360 tooltipEl : function()
7362 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
7373 Roo.namespace('Roo.bootstrap.breadcrumb');
7377 * @class Roo.bootstrap.breadcrumb.Nav
7378 * @extends Roo.bootstrap.Component
7379 * Bootstrap Breadcrumb Nav Class
7381 * @children Roo.bootstrap.breadcrumb.Item
7384 * Create a new breadcrumb.Nav
7385 * @param {Object} config The config object
7389 Roo.bootstrap.breadcrumb.Nav = function(config){
7390 Roo.bootstrap.breadcrumb.Nav.superclass.constructor.call(this, config);
7395 Roo.extend(Roo.bootstrap.breadcrumb.Nav, Roo.bootstrap.Component, {
7397 getAutoCreate : function()
7414 initEvents: function()
7416 this.olEl = this.el.select('ol',true).first();
7418 getChildContainer : function()
7434 * @class Roo.bootstrap.breadcrumb.Nav
7435 * @extends Roo.bootstrap.Component
7436 * @children Roo.bootstrap.Component
7437 * @parent Roo.bootstrap.breadcrumb.Nav
7438 * Bootstrap Breadcrumb Nav Class
7441 * @cfg {String} html the content of the link.
7442 * @cfg {String} href where it links to if '#' is used the link will be handled by onClick.
7443 * @cfg {Boolean} active is it active
7447 * Create a new breadcrumb.Nav
7448 * @param {Object} config The config object
7451 Roo.bootstrap.breadcrumb.Item = function(config){
7452 Roo.bootstrap.breadcrumb.Item.superclass.constructor.call(this, config);
7457 * The img click event for the img.
7458 * @param {Roo.EventObject} e
7465 Roo.extend(Roo.bootstrap.breadcrumb.Item, Roo.bootstrap.Component, {
7470 getAutoCreate : function()
7475 cls : 'breadcrumb-item' + (this.active ? ' active' : '')
7477 if (this.href !== false) {
7484 cfg.html = this.html;
7490 initEvents: function()
7493 this.el.select('a', true).first().on('click',this.onClick, this)
7497 onClick : function(e)
7500 this.fireEvent('click',this, e);
7513 * @class Roo.bootstrap.Row
7514 * @extends Roo.bootstrap.Component
7515 * @children Roo.bootstrap.Component
7516 * Bootstrap Row class (contains columns...)
7520 * @param {Object} config The config object
7523 Roo.bootstrap.Row = function(config){
7524 Roo.bootstrap.Row.superclass.constructor.call(this, config);
7527 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
7529 getAutoCreate : function(){
7548 * @class Roo.bootstrap.Pagination
7549 * @extends Roo.bootstrap.Component
7550 * @children Roo.bootstrap.Pagination
7551 * Bootstrap Pagination class
7553 * @cfg {String} size (xs|sm|md|lg|xl)
7554 * @cfg {Boolean} inverse
7557 * Create a new Pagination
7558 * @param {Object} config The config object
7561 Roo.bootstrap.Pagination = function(config){
7562 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
7565 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
7571 getAutoCreate : function(){
7577 cfg.cls += ' inverse';
7583 cfg.cls += " " + this.cls;
7601 * @class Roo.bootstrap.PaginationItem
7602 * @extends Roo.bootstrap.Component
7603 * Bootstrap PaginationItem class
7604 * @cfg {String} html text
7605 * @cfg {String} href the link
7606 * @cfg {Boolean} preventDefault (true | false) default true
7607 * @cfg {Boolean} active (true | false) default false
7608 * @cfg {Boolean} disabled default false
7612 * Create a new PaginationItem
7613 * @param {Object} config The config object
7617 Roo.bootstrap.PaginationItem = function(config){
7618 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
7623 * The raw click event for the entire grid.
7624 * @param {Roo.EventObject} e
7630 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
7634 preventDefault: true,
7639 getAutoCreate : function(){
7645 href : this.href ? this.href : '#',
7646 html : this.html ? this.html : ''
7656 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
7660 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
7666 initEvents: function() {
7668 this.el.on('click', this.onClick, this);
7671 onClick : function(e)
7673 Roo.log('PaginationItem on click ');
7674 if(this.preventDefault){
7682 this.fireEvent('click', this, e);
7698 * @class Roo.bootstrap.Slider
7699 * @extends Roo.bootstrap.Component
7700 * Bootstrap Slider class
7703 * Create a new Slider
7704 * @param {Object} config The config object
7707 Roo.bootstrap.Slider = function(config){
7708 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
7711 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
7713 getAutoCreate : function(){
7717 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
7721 cls: 'ui-slider-handle ui-state-default ui-corner-all'
7733 * Ext JS Library 1.1.1
7734 * Copyright(c) 2006-2007, Ext JS, LLC.
7736 * Originally Released Under LGPL - original licence link has changed is not relivant.
7739 * <script type="text/javascript">
7742 * @extends Roo.dd.DDProxy
7743 * @class Roo.grid.SplitDragZone
7744 * Support for Column Header resizing
7746 * @param {Object} config
7749 // This is a support class used internally by the Grid components
7750 Roo.grid.SplitDragZone = function(grid, hd, hd2){
7752 this.view = grid.getView();
7753 this.proxy = this.view.resizeProxy;
7754 Roo.grid.SplitDragZone.superclass.constructor.call(
7757 "gridSplitters" + this.grid.getGridEl().id, // SGROUP
7759 dragElId : Roo.id(this.proxy.dom),
7764 this.setHandleElId(Roo.id(hd));
7765 if (hd2 !== false) {
7766 this.setOuterHandleElId(Roo.id(hd2));
7769 this.scroll = false;
7771 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
7772 fly: Roo.Element.fly,
7774 b4StartDrag : function(x, y){
7775 this.view.headersDisabled = true;
7776 var h = this.view.mainWrap ? this.view.mainWrap.getHeight() : (
7777 this.view.headEl.getHeight() + this.view.bodyEl.getHeight()
7779 this.proxy.setHeight(h);
7781 // for old system colWidth really stored the actual width?
7782 // in bootstrap we tried using xs/ms/etc.. to do % sizing?
7783 // which in reality did not work.. - it worked only for fixed sizes
7784 // for resizable we need to use actual sizes.
7785 var w = this.cm.getColumnWidth(this.cellIndex);
7786 if (!this.view.mainWrap) {
7788 w = this.view.getHeaderIndex(this.cellIndex).getWidth();
7793 // this was w-this.grid.minColumnWidth;
7794 // doesnt really make sense? - w = thie curren width or the rendered one?
7795 var minw = Math.max(w-this.grid.minColumnWidth, 0);
7796 this.resetConstraints();
7797 this.setXConstraint(minw, 1000);
7798 this.setYConstraint(0, 0);
7799 this.minX = x - minw;
7800 this.maxX = x + 1000;
7802 if (!this.view.mainWrap) { // this is Bootstrap code..
7803 this.getDragEl().style.display='block';
7806 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
7810 handleMouseDown : function(e){
7811 ev = Roo.EventObject.setEvent(e);
7812 var t = this.fly(ev.getTarget());
7813 if(t.hasClass("x-grid-split")){
7814 this.cellIndex = this.view.getCellIndex(t.dom);
7816 this.cm = this.grid.colModel;
7817 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
7818 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
7823 endDrag : function(e){
7824 this.view.headersDisabled = false;
7825 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
7826 var diff = endX - this.startPos;
7828 var w = this.cm.getColumnWidth(this.cellIndex);
7829 if (!this.view.mainWrap) {
7832 this.view.onColumnSplitterMoved(this.cellIndex, w+diff);
7835 autoOffset : function(){
7840 * Ext JS Library 1.1.1
7841 * Copyright(c) 2006-2007, Ext JS, LLC.
7843 * Originally Released Under LGPL - original licence link has changed is not relivant.
7846 * <script type="text/javascript">
7850 * @class Roo.grid.AbstractSelectionModel
7851 * @extends Roo.util.Observable
7853 * Abstract base class for grid SelectionModels. It provides the interface that should be
7854 * implemented by descendant classes. This class should not be directly instantiated.
7857 Roo.grid.AbstractSelectionModel = function(){
7858 this.locked = false;
7859 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
7862 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
7863 /** @ignore Called by the grid automatically. Do not call directly. */
7864 init : function(grid){
7870 * Locks the selections.
7877 * Unlocks the selections.
7879 unlock : function(){
7880 this.locked = false;
7884 * Returns true if the selections are locked.
7887 isLocked : function(){
7892 * Ext JS Library 1.1.1
7893 * Copyright(c) 2006-2007, Ext JS, LLC.
7895 * Originally Released Under LGPL - original licence link has changed is not relivant.
7898 * <script type="text/javascript">
7901 * @extends Roo.grid.AbstractSelectionModel
7902 * @class Roo.grid.RowSelectionModel
7903 * The default SelectionModel used by {@link Roo.grid.Grid}.
7904 * It supports multiple selections and keyboard selection/navigation.
7906 * @param {Object} config
7908 Roo.grid.RowSelectionModel = function(config){
7909 Roo.apply(this, config);
7910 this.selections = new Roo.util.MixedCollection(false, function(o){
7915 this.lastActive = false;
7919 * @event selectionchange
7920 * Fires when the selection changes
7921 * @param {SelectionModel} this
7923 "selectionchange" : true,
7925 * @event afterselectionchange
7926 * Fires after the selection changes (eg. by key press or clicking)
7927 * @param {SelectionModel} this
7929 "afterselectionchange" : true,
7931 * @event beforerowselect
7932 * Fires when a row is selected being selected, return false to cancel.
7933 * @param {SelectionModel} this
7934 * @param {Number} rowIndex The selected index
7935 * @param {Boolean} keepExisting False if other selections will be cleared
7937 "beforerowselect" : true,
7940 * Fires when a row is selected.
7941 * @param {SelectionModel} this
7942 * @param {Number} rowIndex The selected index
7943 * @param {Roo.data.Record} r The record
7947 * @event rowdeselect
7948 * Fires when a row is deselected.
7949 * @param {SelectionModel} this
7950 * @param {Number} rowIndex The selected index
7952 "rowdeselect" : true
7954 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
7955 this.locked = false;
7958 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
7960 * @cfg {Boolean} singleSelect
7961 * True to allow selection of only one row at a time (defaults to false)
7963 singleSelect : false,
7966 initEvents : function(){
7968 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
7969 this.grid.on("mousedown", this.handleMouseDown, this);
7970 }else{ // allow click to work like normal
7971 this.grid.on("rowclick", this.handleDragableRowClick, this);
7973 // bootstrap does not have a view..
7974 var view = this.grid.view ? this.grid.view : this.grid;
7975 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
7978 this.selectPrevious(e.shiftKey);
7979 }else if(this.last !== false && this.lastActive !== false){
7980 var last = this.last;
7981 this.selectRange(this.last, this.lastActive-1);
7982 view.focusRow(this.lastActive);
7987 this.selectFirstRow();
7989 this.fireEvent("afterselectionchange", this);
7991 "down" : function(e){
7993 this.selectNext(e.shiftKey);
7994 }else if(this.last !== false && this.lastActive !== false){
7995 var last = this.last;
7996 this.selectRange(this.last, this.lastActive+1);
7997 view.focusRow(this.lastActive);
8002 this.selectFirstRow();
8004 this.fireEvent("afterselectionchange", this);
8010 view.on("refresh", this.onRefresh, this);
8011 view.on("rowupdated", this.onRowUpdated, this);
8012 view.on("rowremoved", this.onRemove, this);
8016 onRefresh : function(){
8017 var ds = this.grid.ds, i, v = this.grid.view;
8018 var s = this.selections;
8020 if((i = ds.indexOfId(r.id)) != -1){
8022 s.add(ds.getAt(i)); // updating the selection relate data
8030 onRemove : function(v, index, r){
8031 this.selections.remove(r);
8035 onRowUpdated : function(v, index, r){
8036 if(this.isSelected(r)){
8037 v.onRowSelect(index);
8043 * @param {Array} records The records to select
8044 * @param {Boolean} keepExisting (optional) True to keep existing selections
8046 selectRecords : function(records, keepExisting){
8048 this.clearSelections();
8050 var ds = this.grid.ds;
8051 for(var i = 0, len = records.length; i < len; i++){
8052 this.selectRow(ds.indexOf(records[i]), true);
8057 * Gets the number of selected rows.
8060 getCount : function(){
8061 return this.selections.length;
8065 * Selects the first row in the grid.
8067 selectFirstRow : function(){
8072 * Select the last row.
8073 * @param {Boolean} keepExisting (optional) True to keep existing selections
8075 selectLastRow : function(keepExisting){
8076 this.selectRow(this.grid.ds.getCount() - 1, keepExisting);
8080 * Selects the row immediately following the last selected row.
8081 * @param {Boolean} keepExisting (optional) True to keep existing selections
8083 selectNext : function(keepExisting){
8084 if(this.last !== false && (this.last+1) < this.grid.ds.getCount()){
8085 this.selectRow(this.last+1, keepExisting);
8086 var view = this.grid.view ? this.grid.view : this.grid;
8087 view.focusRow(this.last);
8092 * Selects the row that precedes the last selected row.
8093 * @param {Boolean} keepExisting (optional) True to keep existing selections
8095 selectPrevious : function(keepExisting){
8097 this.selectRow(this.last-1, keepExisting);
8098 var view = this.grid.view ? this.grid.view : this.grid;
8099 view.focusRow(this.last);
8104 * Returns the selected records
8105 * @return {Array} Array of selected records
8107 getSelections : function(){
8108 return [].concat(this.selections.items);
8112 * Returns the first selected record.
8115 getSelected : function(){
8116 return this.selections.itemAt(0);
8121 * Clears all selections.
8123 clearSelections : function(fast){
8128 var ds = this.grid.ds;
8129 var s = this.selections;
8131 this.deselectRow(ds.indexOfId(r.id));
8135 this.selections.clear();
8144 selectAll : function(){
8148 this.selections.clear();
8149 for(var i = 0, len = this.grid.ds.getCount(); i < len; i++){
8150 this.selectRow(i, true);
8155 * Returns True if there is a selection.
8158 hasSelection : function(){
8159 return this.selections.length > 0;
8163 * Returns True if the specified row is selected.
8164 * @param {Number/Record} record The record or index of the record to check
8167 isSelected : function(index){
8168 var r = typeof index == "number" ? this.grid.ds.getAt(index) : index;
8169 return (r && this.selections.key(r.id) ? true : false);
8173 * Returns True if the specified record id is selected.
8174 * @param {String} id The id of record to check
8177 isIdSelected : function(id){
8178 return (this.selections.key(id) ? true : false);
8182 handleMouseDown : function(e, t)
8184 var view = this.grid.view ? this.grid.view : this.grid;
8186 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
8189 if(e.shiftKey && this.last !== false){
8190 var last = this.last;
8191 this.selectRange(last, rowIndex, e.ctrlKey);
8192 this.last = last; // reset the last
8193 view.focusRow(rowIndex);
8195 var isSelected = this.isSelected(rowIndex);
8196 if(e.button !== 0 && isSelected){
8197 view.focusRow(rowIndex);
8198 }else if(e.ctrlKey && isSelected){
8199 this.deselectRow(rowIndex);
8200 }else if(!isSelected){
8201 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
8202 view.focusRow(rowIndex);
8205 this.fireEvent("afterselectionchange", this);
8208 handleDragableRowClick : function(grid, rowIndex, e)
8210 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
8211 this.selectRow(rowIndex, false);
8212 var view = this.grid.view ? this.grid.view : this.grid;
8213 view.focusRow(rowIndex);
8214 this.fireEvent("afterselectionchange", this);
8219 * Selects multiple rows.
8220 * @param {Array} rows Array of the indexes of the row to select
8221 * @param {Boolean} keepExisting (optional) True to keep existing selections
8223 selectRows : function(rows, keepExisting){
8225 this.clearSelections();
8227 for(var i = 0, len = rows.length; i < len; i++){
8228 this.selectRow(rows[i], true);
8233 * Selects a range of rows. All rows in between startRow and endRow are also selected.
8234 * @param {Number} startRow The index of the first row in the range
8235 * @param {Number} endRow The index of the last row in the range
8236 * @param {Boolean} keepExisting (optional) True to retain existing selections
8238 selectRange : function(startRow, endRow, keepExisting){
8243 this.clearSelections();
8245 if(startRow <= endRow){
8246 for(var i = startRow; i <= endRow; i++){
8247 this.selectRow(i, true);
8250 for(var i = startRow; i >= endRow; i--){
8251 this.selectRow(i, true);
8257 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
8258 * @param {Number} startRow The index of the first row in the range
8259 * @param {Number} endRow The index of the last row in the range
8261 deselectRange : function(startRow, endRow, preventViewNotify){
8265 for(var i = startRow; i <= endRow; i++){
8266 this.deselectRow(i, preventViewNotify);
8272 * @param {Number} row The index of the row to select
8273 * @param {Boolean} keepExisting (optional) True to keep existing selections
8275 selectRow : function(index, keepExisting, preventViewNotify){
8276 if(this.locked || (index < 0 || index >= this.grid.ds.getCount())) {
8279 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
8280 if(!keepExisting || this.singleSelect){
8281 this.clearSelections();
8283 var r = this.grid.ds.getAt(index);
8284 this.selections.add(r);
8285 this.last = this.lastActive = index;
8286 if(!preventViewNotify){
8287 var view = this.grid.view ? this.grid.view : this.grid;
8288 view.onRowSelect(index);
8290 this.fireEvent("rowselect", this, index, r);
8291 this.fireEvent("selectionchange", this);
8297 * @param {Number} row The index of the row to deselect
8299 deselectRow : function(index, preventViewNotify){
8303 if(this.last == index){
8306 if(this.lastActive == index){
8307 this.lastActive = false;
8309 var r = this.grid.ds.getAt(index);
8310 this.selections.remove(r);
8311 if(!preventViewNotify){
8312 var view = this.grid.view ? this.grid.view : this.grid;
8313 view.onRowDeselect(index);
8315 this.fireEvent("rowdeselect", this, index);
8316 this.fireEvent("selectionchange", this);
8320 restoreLast : function(){
8322 this.last = this._last;
8327 acceptsNav : function(row, col, cm){
8328 return !cm.isHidden(col) && cm.isCellEditable(col, row);
8332 onEditorKey : function(field, e){
8333 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
8338 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
8340 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
8342 }else if(k == e.ENTER && !e.ctrlKey){
8346 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
8348 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
8350 }else if(k == e.ESC){
8354 g.startEditing(newCell[0], newCell[1]);
8359 * Ext JS Library 1.1.1
8360 * Copyright(c) 2006-2007, Ext JS, LLC.
8362 * Originally Released Under LGPL - original licence link has changed is not relivant.
8365 * <script type="text/javascript">
8370 * @class Roo.grid.ColumnModel
8371 * @extends Roo.util.Observable
8372 * This is the default implementation of a ColumnModel used by the Grid. It defines
8373 * the columns in the grid.
8376 var colModel = new Roo.grid.ColumnModel([
8377 {header: "Ticker", width: 60, sortable: true, locked: true},
8378 {header: "Company Name", width: 150, sortable: true},
8379 {header: "Market Cap.", width: 100, sortable: true},
8380 {header: "$ Sales", width: 100, sortable: true, renderer: money},
8381 {header: "Employees", width: 100, sortable: true, resizable: false}
8386 * The config options listed for this class are options which may appear in each
8387 * individual column definition.
8388 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
8390 * @param {Object} config An Array of column config objects. See this class's
8391 * config objects for details.
8393 Roo.grid.ColumnModel = function(config){
8395 * The config passed into the constructor
8397 this.config = []; //config;
8400 // if no id, create one
8401 // if the column does not have a dataIndex mapping,
8402 // map it to the order it is in the config
8403 for(var i = 0, len = config.length; i < len; i++){
8404 this.addColumn(config[i]);
8409 * The width of columns which have no width specified (defaults to 100)
8412 this.defaultWidth = 100;
8415 * Default sortable of columns which have no sortable specified (defaults to false)
8418 this.defaultSortable = false;
8422 * @event widthchange
8423 * Fires when the width of a column changes.
8424 * @param {ColumnModel} this
8425 * @param {Number} columnIndex The column index
8426 * @param {Number} newWidth The new width
8428 "widthchange": true,
8430 * @event headerchange
8431 * Fires when the text of a header changes.
8432 * @param {ColumnModel} this
8433 * @param {Number} columnIndex The column index
8434 * @param {Number} newText The new header text
8436 "headerchange": true,
8438 * @event hiddenchange
8439 * Fires when a column is hidden or "unhidden".
8440 * @param {ColumnModel} this
8441 * @param {Number} columnIndex The column index
8442 * @param {Boolean} hidden true if hidden, false otherwise
8444 "hiddenchange": true,
8446 * @event columnmoved
8447 * Fires when a column is moved.
8448 * @param {ColumnModel} this
8449 * @param {Number} oldIndex
8450 * @param {Number} newIndex
8452 "columnmoved" : true,
8454 * @event columlockchange
8455 * Fires when a column's locked state is changed
8456 * @param {ColumnModel} this
8457 * @param {Number} colIndex
8458 * @param {Boolean} locked true if locked
8460 "columnlockchange" : true
8462 Roo.grid.ColumnModel.superclass.constructor.call(this);
8464 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
8466 * @cfg {String} header [required] The header text to display in the Grid view.
8469 * @cfg {String} xsHeader Header at Bootsrap Extra Small width (default for all)
8472 * @cfg {String} smHeader Header at Bootsrap Small width
8475 * @cfg {String} mdHeader Header at Bootsrap Medium width
8478 * @cfg {String} lgHeader Header at Bootsrap Large width
8481 * @cfg {String} xlHeader Header at Bootsrap extra Large width
8484 * @cfg {String} dataIndex The name of the field in the grid's {@link Roo.data.Store}'s
8485 * {@link Roo.data.Record} definition from which to draw the column's value. If not
8486 * specified, the column's index is used as an index into the Record's data Array.
8489 * @cfg {Number} width The initial width in pixels of the column. Using this
8490 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
8493 * @cfg {Boolean} sortable True if sorting is to be allowed on this column.
8494 * Defaults to the value of the {@link #defaultSortable} property.
8495 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
8498 * @cfg {Boolean} locked True to lock the column in place while scrolling the Grid. Defaults to false.
8501 * @cfg {Boolean} fixed True if the column width cannot be changed. Defaults to false.
8504 * @cfg {Boolean} resizable False to disable column resizing. Defaults to true.
8507 * @cfg {Boolean} hidden True to hide the column. Defaults to false.
8510 * @cfg {Function} renderer A function used to generate HTML markup for a cell
8511 * given the cell's data value. See {@link #setRenderer}. If not specified, the
8512 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
8513 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
8516 * @cfg {Roo.grid.GridEditor} editor For grid editors - returns the grid editor
8519 * @cfg {String} align (left|right) Set the CSS text-align property of the column. Defaults to undefined (left).
8522 * @cfg {String} valign (top|bottom|middle) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined (middle)
8525 * @cfg {String} cursor ( auto|default|none|context-menu|help|pointer|progress|wait|cell|crosshair|text|vertical-text|alias|copy|move|no-drop|not-allowed|e-resize|n-resize|ne-resize|nw-resize|s-resize|se-resize|sw-resize|w-resize|ew-resize|ns-resize|nesw-resize|nwse-resize|col-resize|row-resize|all-scroll|zoom-in|zoom-out|grab|grabbing)
8528 * @cfg {String} tooltip mouse over tooltip text
8531 * @cfg {Number} xs can be '0' for hidden at this size (number less than 12)
8534 * @cfg {Number} sm can be '0' for hidden at this size (number less than 12)
8537 * @cfg {Number} md can be '0' for hidden at this size (number less than 12)
8540 * @cfg {Number} lg can be '0' for hidden at this size (number less than 12)
8543 * @cfg {Number} xl can be '0' for hidden at this size (number less than 12)
8546 * Returns the id of the column at the specified index.
8547 * @param {Number} index The column index
8548 * @return {String} the id
8550 getColumnId : function(index){
8551 return this.config[index].id;
8555 * Returns the column for a specified id.
8556 * @param {String} id The column id
8557 * @return {Object} the column
8559 getColumnById : function(id){
8560 return this.lookup[id];
8565 * Returns the column Object for a specified dataIndex.
8566 * @param {String} dataIndex The column dataIndex
8567 * @return {Object|Boolean} the column or false if not found
8569 getColumnByDataIndex: function(dataIndex){
8570 var index = this.findColumnIndex(dataIndex);
8571 return index > -1 ? this.config[index] : false;
8575 * Returns the index for a specified column id.
8576 * @param {String} id The column id
8577 * @return {Number} the index, or -1 if not found
8579 getIndexById : function(id){
8580 for(var i = 0, len = this.config.length; i < len; i++){
8581 if(this.config[i].id == id){
8589 * Returns the index for a specified column dataIndex.
8590 * @param {String} dataIndex The column dataIndex
8591 * @return {Number} the index, or -1 if not found
8594 findColumnIndex : function(dataIndex){
8595 for(var i = 0, len = this.config.length; i < len; i++){
8596 if(this.config[i].dataIndex == dataIndex){
8604 moveColumn : function(oldIndex, newIndex){
8605 var c = this.config[oldIndex];
8606 this.config.splice(oldIndex, 1);
8607 this.config.splice(newIndex, 0, c);
8608 this.dataMap = null;
8609 this.fireEvent("columnmoved", this, oldIndex, newIndex);
8612 isLocked : function(colIndex){
8613 return this.config[colIndex].locked === true;
8616 setLocked : function(colIndex, value, suppressEvent){
8617 if(this.isLocked(colIndex) == value){
8620 this.config[colIndex].locked = value;
8622 this.fireEvent("columnlockchange", this, colIndex, value);
8626 getTotalLockedWidth : function(){
8628 for(var i = 0; i < this.config.length; i++){
8629 if(this.isLocked(i) && !this.isHidden(i)){
8630 this.totalWidth += this.getColumnWidth(i);
8636 getLockedCount : function(){
8637 for(var i = 0, len = this.config.length; i < len; i++){
8638 if(!this.isLocked(i)){
8643 return this.config.length;
8647 * Returns the number of columns.
8650 getColumnCount : function(visibleOnly){
8651 if(visibleOnly === true){
8653 for(var i = 0, len = this.config.length; i < len; i++){
8654 if(!this.isHidden(i)){
8660 return this.config.length;
8664 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
8665 * @param {Function} fn
8666 * @param {Object} scope (optional)
8667 * @return {Array} result
8669 getColumnsBy : function(fn, scope){
8671 for(var i = 0, len = this.config.length; i < len; i++){
8672 var c = this.config[i];
8673 if(fn.call(scope||this, c, i) === true){
8681 * Returns true if the specified column is sortable.
8682 * @param {Number} col The column index
8685 isSortable : function(col){
8686 if(typeof this.config[col].sortable == "undefined"){
8687 return this.defaultSortable;
8689 return this.config[col].sortable;
8693 * Returns the rendering (formatting) function defined for the column.
8694 * @param {Number} col The column index.
8695 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
8697 getRenderer : function(col){
8698 if(!this.config[col].renderer){
8699 return Roo.grid.ColumnModel.defaultRenderer;
8701 return this.config[col].renderer;
8705 * Sets the rendering (formatting) function for a column.
8706 * @param {Number} col The column index
8707 * @param {Function} fn The function to use to process the cell's raw data
8708 * to return HTML markup for the grid view. The render function is called with
8709 * the following parameters:<ul>
8710 * <li>Data value.</li>
8711 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
8712 * <li>css A CSS style string to apply to the table cell.</li>
8713 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
8714 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
8715 * <li>Row index</li>
8716 * <li>Column index</li>
8717 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
8719 setRenderer : function(col, fn){
8720 this.config[col].renderer = fn;
8724 * Returns the width for the specified column.
8725 * @param {Number} col The column index
8726 * @param (optional) {String} gridSize bootstrap width size.
8729 getColumnWidth : function(col, gridSize)
8731 var cfg = this.config[col];
8733 if (typeof(gridSize) == 'undefined') {
8734 return cfg.width * 1 || this.defaultWidth;
8736 if (gridSize === false) { // if we set it..
8737 return cfg.width || false;
8739 var sizes = ['xl', 'lg', 'md', 'sm', 'xs'];
8741 for(var i = sizes.indexOf(gridSize); i < sizes.length; i++) {
8742 if (typeof(cfg[ sizes[i] ] ) == 'undefined') {
8745 return cfg[ sizes[i] ];
8752 * Sets the width for a column.
8753 * @param {Number} col The column index
8754 * @param {Number} width The new width
8756 setColumnWidth : function(col, width, suppressEvent){
8757 this.config[col].width = width;
8758 this.totalWidth = null;
8760 this.fireEvent("widthchange", this, col, width);
8765 * Returns the total width of all columns.
8766 * @param {Boolean} includeHidden True to include hidden column widths
8769 getTotalWidth : function(includeHidden){
8770 if(!this.totalWidth){
8771 this.totalWidth = 0;
8772 for(var i = 0, len = this.config.length; i < len; i++){
8773 if(includeHidden || !this.isHidden(i)){
8774 this.totalWidth += this.getColumnWidth(i);
8778 return this.totalWidth;
8782 * Returns the header for the specified column.
8783 * @param {Number} col The column index
8786 getColumnHeader : function(col){
8787 return this.config[col].header;
8791 * Sets the header for a column.
8792 * @param {Number} col The column index
8793 * @param {String} header The new header
8795 setColumnHeader : function(col, header){
8796 this.config[col].header = header;
8797 this.fireEvent("headerchange", this, col, header);
8801 * Returns the tooltip for the specified column.
8802 * @param {Number} col The column index
8805 getColumnTooltip : function(col){
8806 return this.config[col].tooltip;
8809 * Sets the tooltip for a column.
8810 * @param {Number} col The column index
8811 * @param {String} tooltip The new tooltip
8813 setColumnTooltip : function(col, tooltip){
8814 this.config[col].tooltip = tooltip;
8818 * Returns the dataIndex for the specified column.
8819 * @param {Number} col The column index
8822 getDataIndex : function(col){
8823 return this.config[col].dataIndex;
8827 * Sets the dataIndex for a column.
8828 * @param {Number} col The column index
8829 * @param {Number} dataIndex The new dataIndex
8831 setDataIndex : function(col, dataIndex){
8832 this.config[col].dataIndex = dataIndex;
8838 * Returns true if the cell is editable.
8839 * @param {Number} colIndex The column index
8840 * @param {Number} rowIndex The row index - this is nto actually used..?
8843 isCellEditable : function(colIndex, rowIndex){
8844 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
8848 * Returns the editor defined for the cell/column.
8849 * return false or null to disable editing.
8850 * @param {Number} colIndex The column index
8851 * @param {Number} rowIndex The row index
8854 getCellEditor : function(colIndex, rowIndex){
8855 return this.config[colIndex].editor;
8859 * Sets if a column is editable.
8860 * @param {Number} col The column index
8861 * @param {Boolean} editable True if the column is editable
8863 setEditable : function(col, editable){
8864 this.config[col].editable = editable;
8869 * Returns true if the column is hidden.
8870 * @param {Number} colIndex The column index
8873 isHidden : function(colIndex){
8874 return this.config[colIndex].hidden;
8879 * Returns true if the column width cannot be changed
8881 isFixed : function(colIndex){
8882 return this.config[colIndex].fixed;
8886 * Returns true if the column can be resized
8889 isResizable : function(colIndex){
8890 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
8893 * Sets if a column is hidden.
8894 * @param {Number} colIndex The column index
8895 * @param {Boolean} hidden True if the column is hidden
8897 setHidden : function(colIndex, hidden){
8898 this.config[colIndex].hidden = hidden;
8899 this.totalWidth = null;
8900 this.fireEvent("hiddenchange", this, colIndex, hidden);
8904 * Sets the editor for a column.
8905 * @param {Number} col The column index
8906 * @param {Object} editor The editor object
8908 setEditor : function(col, editor){
8909 this.config[col].editor = editor;
8912 * Add a column (experimental...) - defaults to adding to the end..
8913 * @param {Object} config
8915 addColumn : function(c)
8918 var i = this.config.length;
8921 if(typeof c.dataIndex == "undefined"){
8924 if(typeof c.renderer == "string"){
8925 c.renderer = Roo.util.Format[c.renderer];
8927 if(typeof c.id == "undefined"){
8930 if(c.editor && c.editor.xtype){
8931 c.editor = Roo.factory(c.editor, Roo.grid);
8933 if(c.editor && c.editor.isFormField){
8934 c.editor = new Roo.grid.GridEditor(c.editor);
8936 this.lookup[c.id] = c;
8941 Roo.grid.ColumnModel.defaultRenderer = function(value)
8943 if(typeof value == "object") {
8946 if(typeof value == "string" && value.length < 1){
8950 return String.format("{0}", value);
8953 // Alias for backwards compatibility
8954 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
8957 * Ext JS Library 1.1.1
8958 * Copyright(c) 2006-2007, Ext JS, LLC.
8960 * Originally Released Under LGPL - original licence link has changed is not relivant.
8963 * <script type="text/javascript">
8967 * @class Roo.LoadMask
8968 * A simple utility class for generically masking elements while loading data. If the element being masked has
8969 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
8970 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
8971 * element's UpdateManager load indicator and will be destroyed after the initial load.
8973 * Create a new LoadMask
8974 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
8975 * @param {Object} config The config object
8977 Roo.LoadMask = function(el, config){
8978 this.el = Roo.get(el);
8979 Roo.apply(this, config);
8981 this.store.on('beforeload', this.onBeforeLoad, this);
8982 this.store.on('load', this.onLoad, this);
8983 this.store.on('loadexception', this.onLoadException, this);
8984 this.removeMask = false;
8986 var um = this.el.getUpdateManager();
8987 um.showLoadIndicator = false; // disable the default indicator
8988 um.on('beforeupdate', this.onBeforeLoad, this);
8989 um.on('update', this.onLoad, this);
8990 um.on('failure', this.onLoad, this);
8991 this.removeMask = true;
8995 Roo.LoadMask.prototype = {
8997 * @cfg {Boolean} removeMask
8998 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
8999 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
9004 * The text to display in a centered loading message box (defaults to 'Loading...')
9008 * @cfg {String} msgCls
9009 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
9011 msgCls : 'x-mask-loading',
9014 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
9020 * Disables the mask to prevent it from being displayed
9022 disable : function(){
9023 this.disabled = true;
9027 * Enables the mask so that it can be displayed
9029 enable : function(){
9030 this.disabled = false;
9033 onLoadException : function()
9037 if (typeof(arguments[3]) != 'undefined') {
9038 Roo.MessageBox.alert("Error loading",arguments[3]);
9042 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
9043 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
9050 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
9055 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
9059 onBeforeLoad : function(){
9061 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
9066 destroy : function(){
9068 this.store.un('beforeload', this.onBeforeLoad, this);
9069 this.store.un('load', this.onLoad, this);
9070 this.store.un('loadexception', this.onLoadException, this);
9072 var um = this.el.getUpdateManager();
9073 um.un('beforeupdate', this.onBeforeLoad, this);
9074 um.un('update', this.onLoad, this);
9075 um.un('failure', this.onLoad, this);
9079 * @class Roo.bootstrap.Table
9081 * @extends Roo.bootstrap.Component
9082 * @children Roo.bootstrap.TableBody
9083 * Bootstrap Table class. This class represents the primary interface of a component based grid control.
9084 * Similar to Roo.grid.Grid
9086 var table = Roo.factory({
9088 xns : Roo.bootstrap,
9089 autoSizeColumns: true,
9096 sortInfo : { direction : 'ASC', field: 'name' },
9098 xtype : 'HttpProxy',
9101 url : 'https://example.com/some.data.url.json'
9104 xtype : 'JsonReader',
9106 fields : [ 'id', 'name', whatever' ],
9113 xtype : 'ColumnModel',
9117 dataIndex : 'is_in_group',
9120 renderer : function(v, x , r) {
9122 return String.format("{0}", v)
9128 xtype : 'RowSelectionModel',
9129 xns : Roo.bootstrap.Table
9130 // you can add listeners to catch selection change here....
9136 grid.render(Roo.get("some-div"));
9139 Currently the Table uses multiple headers to try and handle XL / Medium etc... styling
9144 * @cfg {Roo.grid.AbstractSelectionModel} sm The selection model to use (cell selection is not supported yet)
9145 * @cfg {Roo.data.Store} store The data store to use
9146 * @cfg {Roo.grid.ColumnModel} cm[] A column for the grid.
9148 * @cfg {String} cls table class
9151 * @cfg {string} empty_results Text to display for no results
9152 * @cfg {boolean} striped Should the rows be alternative striped
9153 * @cfg {boolean} bordered Add borders to the table
9154 * @cfg {boolean} hover Add hover highlighting
9155 * @cfg {boolean} condensed Format condensed
9156 * @cfg {boolean} responsive default false - if this is on, columns are rendered with col-xs-4 etc. classes, otherwise columns will be sized by CSS,
9157 * also adds table-responsive (see bootstrap docs for details)
9158 * @cfg {Boolean} loadMask (true|false) default false
9159 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
9160 * @cfg {Boolean} summaryFooterShow (true|false) generate tfoot for summary, default false
9161 * @cfg {Boolean} headerShow (true|false) generate thead, default true
9162 * @cfg {Boolean} rowSelection (true|false) default false
9163 * @cfg {Boolean} cellSelection (true|false) default false
9164 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header (with resizable columns)
9165 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
9166 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
9167 * @cfg {Boolean} auto_hide_footer auto hide footer if only one page (default false)
9168 * @cfg {Boolean} enableColumnResize default true if columns can be resized = needs scrollBody to be set to work (drag/drop)
9169 * @cfg {Boolean} disableAutoSize disable autoSize() and initCSS()
9172 * @cfg {Number} minColumnWidth default 50 pixels minimum column width
9175 * Create a new Table
9176 * @param {Object} config The config object
9179 Roo.bootstrap.Table = function(config)
9181 Roo.bootstrap.Table.superclass.constructor.call(this, config);
9184 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
9185 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
9186 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
9187 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
9189 this.view = this; // compat with grid.
9191 this.sm = this.sm || {xtype: 'RowSelectionModel'};
9193 this.sm.grid = this;
9194 this.selModel = Roo.factory(this.sm, Roo.grid);
9195 this.sm = this.selModel;
9196 this.sm.xmodule = this.xmodule || false;
9199 if (this.cm && typeof(this.cm.config) == 'undefined') {
9200 this.colModel = new Roo.grid.ColumnModel(this.cm);
9201 this.cm = this.colModel;
9202 this.cm.xmodule = this.xmodule || false;
9205 this.store= Roo.factory(this.store, Roo.data);
9206 this.ds = this.store;
9207 this.ds.xmodule = this.xmodule || false;
9210 if (this.footer && this.store) {
9211 this.footer.dataSource = this.ds;
9212 this.footer = Roo.factory(this.footer);
9219 * Fires when a cell is clicked
9220 * @param {Roo.bootstrap.Table} this
9221 * @param {Roo.Element} el
9222 * @param {Number} rowIndex
9223 * @param {Number} columnIndex
9224 * @param {Roo.EventObject} e
9228 * @event celldblclick
9229 * Fires when a cell is double clicked
9230 * @param {Roo.bootstrap.Table} this
9231 * @param {Roo.Element} el
9232 * @param {Number} rowIndex
9233 * @param {Number} columnIndex
9234 * @param {Roo.EventObject} e
9236 "celldblclick" : true,
9239 * Fires when a row is clicked
9240 * @param {Roo.bootstrap.Table} this
9241 * @param {Roo.Element} el
9242 * @param {Number} rowIndex
9243 * @param {Roo.EventObject} e
9247 * @event rowdblclick
9248 * Fires when a row is double clicked
9249 * @param {Roo.bootstrap.Table} this
9250 * @param {Roo.Element} el
9251 * @param {Number} rowIndex
9252 * @param {Roo.EventObject} e
9254 "rowdblclick" : true,
9257 * Fires when a mouseover occur
9258 * @param {Roo.bootstrap.Table} this
9259 * @param {Roo.Element} el
9260 * @param {Number} rowIndex
9261 * @param {Number} columnIndex
9262 * @param {Roo.EventObject} e
9267 * Fires when a mouseout occur
9268 * @param {Roo.bootstrap.Table} this
9269 * @param {Roo.Element} el
9270 * @param {Number} rowIndex
9271 * @param {Number} columnIndex
9272 * @param {Roo.EventObject} e
9277 * Fires when a row is rendered, so you can change add a style to it.
9278 * @param {Roo.bootstrap.Table} this
9279 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
9283 * @event rowsrendered
9284 * Fires when all the rows have been rendered
9285 * @param {Roo.bootstrap.Table} this
9287 'rowsrendered' : true,
9289 * @event contextmenu
9290 * The raw contextmenu event for the entire grid.
9291 * @param {Roo.EventObject} e
9293 "contextmenu" : true,
9295 * @event rowcontextmenu
9296 * Fires when a row is right clicked
9297 * @param {Roo.bootstrap.Table} this
9298 * @param {Number} rowIndex
9299 * @param {Roo.EventObject} e
9301 "rowcontextmenu" : true,
9303 * @event cellcontextmenu
9304 * Fires when a cell is right clicked
9305 * @param {Roo.bootstrap.Table} this
9306 * @param {Number} rowIndex
9307 * @param {Number} cellIndex
9308 * @param {Roo.EventObject} e
9310 "cellcontextmenu" : true,
9312 * @event headercontextmenu
9313 * Fires when a header is right clicked
9314 * @param {Roo.bootstrap.Table} this
9315 * @param {Number} columnIndex
9316 * @param {Roo.EventObject} e
9318 "headercontextmenu" : true,
9321 * The raw mousedown event for the entire grid.
9322 * @param {Roo.EventObject} e
9329 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
9345 summaryFooterShow : false,
9347 enableColumnResize: true,
9348 disableAutoSize: false,
9350 rowSelection : false,
9351 cellSelection : false,
9354 minColumnWidth : 50,
9356 // Roo.Element - the tbody
9357 bodyEl: false, // <tbody> Roo.Element - thead element
9358 headEl: false, // <thead> Roo.Element - thead element
9359 resizeProxy : false, // proxy element for dragging?
9363 container: false, // used by gridpanel...
9369 auto_hide_footer : false,
9371 view: false, // actually points to this..
9373 getAutoCreate : function()
9375 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
9382 // this get's auto added by panel.Grid
9383 if (this.scrollBody) {
9384 cfg.cls += ' table-body-fixed';
9387 cfg.cls += ' table-striped';
9391 cfg.cls += ' table-hover';
9393 if (this.bordered) {
9394 cfg.cls += ' table-bordered';
9396 if (this.condensed) {
9397 cfg.cls += ' table-condensed';
9400 if (this.responsive) {
9401 cfg.cls += ' table-responsive';
9405 cfg.cls+= ' ' +this.cls;
9411 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
9414 if(this.store || this.cm){
9415 if(this.headerShow){
9416 cfg.cn.push(this.renderHeader());
9419 cfg.cn.push(this.renderBody());
9421 if(this.footerShow || this.summaryFooterShow){
9422 cfg.cn.push(this.renderFooter());
9425 // where does this come from?
9426 //cfg.cls+= ' TableGrid';
9429 return { cn : [ cfg ] };
9432 initEvents : function()
9434 if(!this.store || !this.cm){
9437 if (this.selModel) {
9438 this.selModel.initEvents();
9442 //Roo.log('initEvents with ds!!!!');
9444 this.bodyEl = this.el.select('tbody', true).first();
9445 this.headEl = this.el.select('thead', true).first();
9446 this.mainFoot = this.el.select('tfoot', true).first();
9451 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
9452 e.on('click', this.sort, this);
9456 // why is this done????? = it breaks dialogs??
9457 //this.parent().el.setStyle('position', 'relative');
9461 this.footer.parentId = this.id;
9462 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
9465 this.el.select('tfoot tr td').first().addClass('hide');
9470 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
9473 this.store.on('load', this.onLoad, this);
9474 this.store.on('beforeload', this.onBeforeLoad, this);
9475 this.store.on('update', this.onUpdate, this);
9476 this.store.on('add', this.onAdd, this);
9477 this.store.on("clear", this.clear, this);
9479 this.el.on("contextmenu", this.onContextMenu, this);
9482 this.cm.on("headerchange", this.onHeaderChange, this);
9483 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
9485 //?? does bodyEl get replaced on render?
9486 this.bodyEl.on("click", this.onClick, this);
9487 this.bodyEl.on("dblclick", this.onDblClick, this);
9488 this.bodyEl.on('scroll', this.onBodyScroll, this);
9490 // guessing mainbody will work - this relays usually caught by selmodel at present.
9491 this.relayEvents(this.bodyEl, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
9494 this.resizeProxy = Roo.get(document.body).createChild({ cls:"x-grid-resize-proxy", html: ' ' });
9497 if(this.headEl && this.enableColumnResize !== false && Roo.grid.SplitDragZone){
9498 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
9503 // Compatibility with grid - we implement all the view features at present.
9504 getView : function()
9509 initCSS : function()
9511 if(this.disableAutoSize) {
9515 var cm = this.cm, styles = [];
9516 this.CSS.removeStyleSheet(this.id + '-cssrules');
9517 var headHeight = this.headEl ? this.headEl.dom.clientHeight : 0;
9518 // we can honour xs/sm/md/xl as widths...
9519 // we first have to decide what widht we are currently at...
9520 var sz = Roo.getGridSize();
9524 var cols = []; // visable cols.
9526 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
9527 var w = cm.getColumnWidth(i, false);
9529 cols.push( { rel : false, abs : 0 });
9533 cols.push( { rel : false, abs : w });
9535 last = i; // not really..
9538 var w = cm.getColumnWidth(i, sz);
9543 cols.push( { rel : w, abs : false });
9546 var avail = this.bodyEl.dom.clientWidth - total_abs;
9548 var unitWidth = Math.floor(avail / total);
9549 var rem = avail - (unitWidth * total);
9551 var hidden, width, pos = 0 , splithide , left;
9552 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
9554 hidden = 'display:none;';
9556 width = 'width:0px;';
9558 if(!cm.isHidden(i)){
9562 // we can honour xs/sm/md/xl ?
9563 var w = cols[i].rel == false ? cols[i].abs : (cols[i].rel * unitWidth);
9565 hidden = 'display:none;';
9567 // width should return a small number...
9569 w+=rem; // add the remaining with..
9572 left = "left:" + (pos -4) + "px;";
9573 width = "width:" + w+ "px;";
9576 if (this.responsive) {
9579 hidden = cm.isHidden(i) ? 'display:none;' : '';
9580 splithide = 'display: none;';
9583 styles.push( '#' , this.id , ' .x-col-' , i, " {", cm.config[i].css, width, hidden, "}\n" );
9586 splithide = 'display:none;';
9589 styles.push('#' , this.id , ' .x-hcol-' , i, " { ", width, hidden," }\n",
9590 '#' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', (headHeight - 4), "px;}\n",
9591 // this is the popover version..
9592 '.popover-inner #' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', 100, "%;}\n"
9597 //Roo.log(styles.join(''));
9598 this.CSS.createStyleSheet( styles.join(''), this.id + '-cssrules');
9604 onContextMenu : function(e, t)
9606 this.processEvent("contextmenu", e);
9609 processEvent : function(name, e)
9611 if (name != 'touchstart' ) {
9612 this.fireEvent(name, e);
9615 var t = e.getTarget();
9617 var cell = Roo.get(t);
9623 if(cell.findParent('tfoot', false, true)){
9627 if(cell.findParent('thead', false, true)){
9629 if(e.getTarget().nodeName.toLowerCase() != 'th'){
9630 cell = Roo.get(t).findParent('th', false, true);
9632 Roo.log("failed to find th in thead?");
9633 Roo.log(e.getTarget());
9638 var cellIndex = cell.dom.cellIndex;
9640 var ename = name == 'touchstart' ? 'click' : name;
9641 this.fireEvent("header" + ename, this, cellIndex, e);
9646 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9647 cell = Roo.get(t).findParent('td', false, true);
9649 Roo.log("failed to find th in tbody?");
9650 Roo.log(e.getTarget());
9655 var row = cell.findParent('tr', false, true);
9656 var cellIndex = cell.dom.cellIndex;
9657 var rowIndex = row.dom.rowIndex - 1;
9661 this.fireEvent("row" + name, this, rowIndex, e);
9665 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
9671 onMouseover : function(e, el)
9673 var cell = Roo.get(el);
9679 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9680 cell = cell.findParent('td', false, true);
9683 var row = cell.findParent('tr', false, true);
9684 var cellIndex = cell.dom.cellIndex;
9685 var rowIndex = row.dom.rowIndex - 1; // start from 0
9687 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
9691 onMouseout : function(e, el)
9693 var cell = Roo.get(el);
9699 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9700 cell = cell.findParent('td', false, true);
9703 var row = cell.findParent('tr', false, true);
9704 var cellIndex = cell.dom.cellIndex;
9705 var rowIndex = row.dom.rowIndex - 1; // start from 0
9707 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
9711 onClick : function(e, el)
9713 var cell = Roo.get(el);
9715 if(!cell || (!this.cellSelection && !this.rowSelection)){
9719 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9720 cell = cell.findParent('td', false, true);
9723 if(!cell || typeof(cell) == 'undefined'){
9727 var row = cell.findParent('tr', false, true);
9729 if(!row || typeof(row) == 'undefined'){
9733 var cellIndex = cell.dom.cellIndex;
9734 var rowIndex = this.getRowIndex(row);
9736 // why??? - should these not be based on SelectionModel?
9737 //if(this.cellSelection){
9738 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
9741 //if(this.rowSelection){
9742 this.fireEvent('rowclick', this, row, rowIndex, e);
9747 onDblClick : function(e,el)
9749 var cell = Roo.get(el);
9751 if(!cell || (!this.cellSelection && !this.rowSelection)){
9755 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9756 cell = cell.findParent('td', false, true);
9759 if(!cell || typeof(cell) == 'undefined'){
9763 var row = cell.findParent('tr', false, true);
9765 if(!row || typeof(row) == 'undefined'){
9769 var cellIndex = cell.dom.cellIndex;
9770 var rowIndex = this.getRowIndex(row);
9772 if(this.cellSelection){
9773 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
9776 if(this.rowSelection){
9777 this.fireEvent('rowdblclick', this, row, rowIndex, e);
9780 findRowIndex : function(el)
9782 var cell = Roo.get(el);
9786 var row = cell.findParent('tr', false, true);
9788 if(!row || typeof(row) == 'undefined'){
9791 return this.getRowIndex(row);
9793 sort : function(e,el)
9795 var col = Roo.get(el);
9797 if(!col.hasClass('sortable')){
9801 var sort = col.attr('sort');
9804 if(col.select('i', true).first().hasClass('fa-arrow-up')){
9808 this.store.sortInfo = {field : sort, direction : dir};
9811 Roo.log("calling footer first");
9812 this.footer.onClick('first');
9815 this.store.load({ params : { start : 0 } });
9819 renderHeader : function()
9827 this.totalWidth = 0;
9829 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
9831 var config = cm.config[i];
9835 cls : 'x-hcol-' + i,
9838 html: cm.getColumnHeader(i)
9841 var tooltip = cm.getColumnTooltip(i);
9843 c.tooltip = tooltip;
9849 if(typeof(config.sortable) != 'undefined' && config.sortable){
9850 c.cls += ' sortable';
9851 c.html = '<i class="fa"></i>' + c.html;
9854 // could use BS4 hidden-..-down
9856 if(typeof(config.lgHeader) != 'undefined'){
9857 hh += '<span class="hidden-xs hidden-sm hidden-md ">' + config.lgHeader + '</span>';
9860 if(typeof(config.mdHeader) != 'undefined'){
9861 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
9864 if(typeof(config.smHeader) != 'undefined'){
9865 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
9868 if(typeof(config.xsHeader) != 'undefined'){
9869 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
9876 if(typeof(config.tooltip) != 'undefined'){
9877 c.tooltip = config.tooltip;
9880 if(typeof(config.colspan) != 'undefined'){
9881 c.colspan = config.colspan;
9884 // hidden is handled by CSS now
9886 if(typeof(config.dataIndex) != 'undefined'){
9887 c.sort = config.dataIndex;
9892 if(typeof(config.align) != 'undefined' && config.align.length){
9893 c.style += ' text-align:' + config.align + ';';
9896 /* width is done in CSS
9897 *if(typeof(config.width) != 'undefined'){
9898 c.style += ' width:' + config.width + 'px;';
9899 this.totalWidth += config.width;
9901 this.totalWidth += 100; // assume minimum of 100 per column?
9905 if(typeof(config.cls) != 'undefined'){
9906 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
9908 // this is the bit that doesnt reall work at all...
9910 if (this.responsive) {
9913 ['xs','sm','md','lg'].map(function(size){
9915 if(typeof(config[size]) == 'undefined'){
9919 if (!config[size]) { // 0 = hidden
9920 // BS 4 '0' is treated as hide that column and below.
9921 c.cls += ' hidden-' + size + ' hidden' + size + '-down';
9925 c.cls += ' col-' + size + '-' + config[size] + (
9926 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
9934 c.html +=' <span class="x-grid-split x-grid-split-' + i + '"></span>';
9945 renderBody : function()
9955 colspan : this.cm.getColumnCount()
9965 renderFooter : function()
9975 colspan : this.cm.getColumnCount()
9987 // Roo.log('ds onload');
9992 var ds = this.store;
9994 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
9995 e.select('i', true).removeClass(['fa-arrow-up', 'fa-arrow-down']);
9996 if (_this.store.sortInfo) {
9998 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
9999 e.select('i', true).addClass(['fa-arrow-up']);
10002 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
10003 e.select('i', true).addClass(['fa-arrow-down']);
10008 var tbody = this.bodyEl;
10010 if(ds.getCount() > 0){
10011 ds.data.each(function(d,rowIndex){
10012 var row = this.renderRow(cm, ds, rowIndex);
10014 tbody.createChild(row);
10018 if(row.cellObjects.length){
10019 Roo.each(row.cellObjects, function(r){
10020 _this.renderCellObject(r);
10025 } else if (this.empty_results.length) {
10026 this.el.mask(this.empty_results, 'no-spinner');
10029 var tfoot = this.el.select('tfoot', true).first();
10031 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
10033 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
10035 var total = this.ds.getTotalCount();
10037 if(this.footer.pageSize < total){
10038 this.mainFoot.show();
10042 if(!this.footerShow && this.summaryFooterShow) {
10049 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
10051 var value = cm.config[i].summaryFooter;
10053 Roo.log('value [' + i + '] : ' + value);
10057 cls : ' x-fcol-' + i,
10059 html: cm.config[i].summaryFooter
10066 tfoot.createChild(row);
10069 Roo.each(this.el.select('tbody td', true).elements, function(e){
10070 e.on('mouseover', _this.onMouseover, _this);
10073 Roo.each(this.el.select('tbody td', true).elements, function(e){
10074 e.on('mouseout', _this.onMouseout, _this);
10076 this.fireEvent('rowsrendered', this);
10080 this.initCSS(); /// resize cols
10086 onUpdate : function(ds,record)
10088 this.refreshRow(record);
10092 onRemove : function(ds, record, index, isUpdate){
10093 if(isUpdate !== true){
10094 this.fireEvent("beforerowremoved", this, index, record);
10096 var bt = this.bodyEl.dom;
10098 var rows = this.el.select('tbody > tr', true).elements;
10100 if(typeof(rows[index]) != 'undefined'){
10101 bt.removeChild(rows[index].dom);
10104 // if(bt.rows[index]){
10105 // bt.removeChild(bt.rows[index]);
10108 if(isUpdate !== true){
10109 //this.stripeRows(index);
10110 //this.syncRowHeights(index, index);
10112 this.fireEvent("rowremoved", this, index, record);
10116 onAdd : function(ds, records, rowIndex)
10118 //Roo.log('on Add called');
10119 // - note this does not handle multiple adding very well..
10120 var bt = this.bodyEl.dom;
10121 for (var i =0 ; i < records.length;i++) {
10122 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
10123 //Roo.log(records[i]);
10124 //Roo.log(this.store.getAt(rowIndex+i));
10125 this.insertRow(this.store, rowIndex + i, false);
10132 refreshRow : function(record){
10133 var ds = this.store, index;
10134 if(typeof record == 'number'){
10136 record = ds.getAt(index);
10138 index = ds.indexOf(record);
10140 return; // should not happen - but seems to
10143 this.insertRow(ds, index, true);
10145 this.onRemove(ds, record, index+1, true);
10147 //this.syncRowHeights(index, index);
10149 this.fireEvent("rowupdated", this, index, record);
10151 // private - called by RowSelection
10152 onRowSelect : function(rowIndex){
10153 var row = this.getRowDom(rowIndex);
10154 row.addClass(['bg-info','info']);
10156 // private - called by RowSelection
10157 onRowDeselect : function(rowIndex)
10159 if (rowIndex < 0) {
10162 var row = this.getRowDom(rowIndex);
10163 row.removeClass(['bg-info','info']);
10166 * Focuses the specified row.
10167 * @param {Number} row The row index
10169 focusRow : function(row)
10171 //Roo.log('GridView.focusRow');
10172 var x = this.bodyEl.dom.scrollLeft;
10173 this.focusCell(row, 0, false);
10174 this.bodyEl.dom.scrollLeft = x;
10178 * Focuses the specified cell.
10179 * @param {Number} row The row index
10180 * @param {Number} col The column index
10181 * @param {Boolean} hscroll false to disable horizontal scrolling
10183 focusCell : function(row, col, hscroll)
10185 //Roo.log('GridView.focusCell');
10186 var el = this.ensureVisible(row, col, hscroll);
10187 // not sure what focusEL achives = it's a <a> pos relative
10188 //this.focusEl.alignTo(el, "tl-tl");
10190 // this.focusEl.focus();
10192 // this.focusEl.focus.defer(1, this.focusEl);
10197 * Scrolls the specified cell into view
10198 * @param {Number} row The row index
10199 * @param {Number} col The column index
10200 * @param {Boolean} hscroll false to disable horizontal scrolling
10202 ensureVisible : function(row, col, hscroll)
10204 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
10205 //return null; //disable for testing.
10206 if(typeof row != "number"){
10207 row = row.rowIndex;
10209 if(row < 0 && row >= this.ds.getCount()){
10212 col = (col !== undefined ? col : 0);
10214 while(cm.isHidden(col)){
10218 var el = this.getCellDom(row, col);
10222 var c = this.bodyEl.dom;
10224 var ctop = parseInt(el.offsetTop, 10);
10225 var cleft = parseInt(el.offsetLeft, 10);
10226 var cbot = ctop + el.offsetHeight;
10227 var cright = cleft + el.offsetWidth;
10229 //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
10230 var ch = 0; //?? header is not withing the area?
10231 var stop = parseInt(c.scrollTop, 10);
10232 var sleft = parseInt(c.scrollLeft, 10);
10233 var sbot = stop + ch;
10234 var sright = sleft + c.clientWidth;
10236 Roo.log('GridView.ensureVisible:' +
10238 ' c.clientHeight:' + c.clientHeight +
10239 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
10247 c.scrollTop = ctop;
10248 //Roo.log("set scrolltop to ctop DISABLE?");
10249 }else if(cbot > sbot){
10250 //Roo.log("set scrolltop to cbot-ch");
10251 c.scrollTop = cbot-ch;
10254 if(hscroll !== false){
10256 c.scrollLeft = cleft;
10257 }else if(cright > sright){
10258 c.scrollLeft = cright-c.clientWidth;
10266 insertRow : function(dm, rowIndex, isUpdate){
10269 this.fireEvent("beforerowsinserted", this, rowIndex);
10271 //var s = this.getScrollState();
10272 var row = this.renderRow(this.cm, this.store, rowIndex);
10273 // insert before rowIndex..
10274 var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
10278 if(row.cellObjects.length){
10279 Roo.each(row.cellObjects, function(r){
10280 _this.renderCellObject(r);
10285 this.fireEvent("rowsinserted", this, rowIndex);
10286 //this.syncRowHeights(firstRow, lastRow);
10287 //this.stripeRows(firstRow);
10294 getRowDom : function(rowIndex)
10296 var rows = this.el.select('tbody > tr', true).elements;
10298 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
10301 getCellDom : function(rowIndex, colIndex)
10303 var row = this.getRowDom(rowIndex);
10304 if (row === false) {
10307 var cols = row.select('td', true).elements;
10308 return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
10312 // returns the object tree for a tr..
10315 renderRow : function(cm, ds, rowIndex)
10317 var d = ds.getAt(rowIndex);
10321 cls : 'x-row-' + rowIndex,
10325 var cellObjects = [];
10327 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
10328 var config = cm.config[i];
10330 var renderer = cm.getRenderer(i);
10334 if(typeof(renderer) !== 'undefined'){
10335 value = renderer(d.data[cm.getDataIndex(i)], false, d);
10337 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
10338 // and are rendered into the cells after the row is rendered - using the id for the element.
10340 if(typeof(value) === 'object'){
10350 rowIndex : rowIndex,
10355 this.fireEvent('rowclass', this, rowcfg);
10359 // this might end up displaying HTML?
10360 // this is too messy... - better to only do it on columsn you know are going to be too long
10361 //tooltip : (typeof(value) === 'object') ? '' : value,
10362 cls : rowcfg.rowClass + ' x-col-' + i,
10364 html: (typeof(value) === 'object') ? '' : value
10371 if(typeof(config.colspan) != 'undefined'){
10372 td.colspan = config.colspan;
10377 if(typeof(config.align) != 'undefined' && config.align.length){
10378 td.style += ' text-align:' + config.align + ';';
10380 if(typeof(config.valign) != 'undefined' && config.valign.length){
10381 td.style += ' vertical-align:' + config.valign + ';';
10384 if(typeof(config.width) != 'undefined'){
10385 td.style += ' width:' + config.width + 'px;';
10389 if(typeof(config.cursor) != 'undefined'){
10390 td.style += ' cursor:' + config.cursor + ';';
10393 if(typeof(config.cls) != 'undefined'){
10394 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
10396 if (this.responsive) {
10397 ['xs','sm','md','lg'].map(function(size){
10399 if(typeof(config[size]) == 'undefined'){
10405 if (!config[size]) { // 0 = hidden
10406 // BS 4 '0' is treated as hide that column and below.
10407 td.cls += ' hidden-' + size + ' hidden' + size + '-down';
10411 td.cls += ' col-' + size + '-' + config[size] + (
10412 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
10422 row.cellObjects = cellObjects;
10430 onBeforeLoad : function()
10432 this.el.unmask(); // if needed.
10439 this.el.select('tbody', true).first().dom.innerHTML = '';
10442 * Show or hide a row.
10443 * @param {Number} rowIndex to show or hide
10444 * @param {Boolean} state hide
10446 setRowVisibility : function(rowIndex, state)
10448 var bt = this.bodyEl.dom;
10450 var rows = this.el.select('tbody > tr', true).elements;
10452 if(typeof(rows[rowIndex]) == 'undefined'){
10455 rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
10460 getSelectionModel : function(){
10461 if(!this.selModel){
10462 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
10464 return this.selModel;
10467 * Render the Roo.bootstrap object from renderder
10469 renderCellObject : function(r)
10473 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
10475 var t = r.cfg.render(r.container);
10478 Roo.each(r.cfg.cn, function(c){
10480 container: t.getChildContainer(),
10483 _this.renderCellObject(child);
10488 * get the Row Index from a dom element.
10489 * @param {Roo.Element} row The row to look for
10490 * @returns {Number} the row
10492 getRowIndex : function(row)
10496 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
10507 * get the header TH element for columnIndex
10508 * @param {Number} columnIndex
10509 * @returns {Roo.Element}
10511 getHeaderIndex: function(colIndex)
10513 var cols = this.headEl.select('th', true).elements;
10514 return cols[colIndex];
10517 * get the Column Index from a dom element. (using regex on x-hcol-{colid})
10518 * @param {domElement} cell to look for
10519 * @returns {Number} the column
10521 getCellIndex : function(cell)
10523 var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
10525 return parseInt(id[1], 10);
10530 * Returns the grid's underlying element = used by panel.Grid
10531 * @return {Element} The element
10533 getGridEl : function(){
10537 * Forces a resize - used by panel.Grid
10538 * @return {Element} The element
10540 autoSize : function()
10542 if(this.disableAutoSize) {
10545 //var ctr = Roo.get(this.container.dom.parentElement);
10546 var ctr = Roo.get(this.el.dom);
10548 var thd = this.getGridEl().select('thead',true).first();
10549 var tbd = this.getGridEl().select('tbody', true).first();
10550 var tfd = this.getGridEl().select('tfoot', true).first();
10552 var cw = ctr.getWidth();
10553 this.getGridEl().select('tfoot tr, tfoot td',true).setWidth(cw);
10557 tbd.setWidth(ctr.getWidth());
10558 // if the body has a max height - and then scrolls - we should perhaps set up the height here
10559 // this needs fixing for various usage - currently only hydra job advers I think..
10561 // ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
10563 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
10566 cw = Math.max(cw, this.totalWidth);
10567 this.getGridEl().select('tbody tr',true).setWidth(cw);
10570 // resize 'expandable coloumn?
10572 return; // we doe not have a view in this design..
10575 onBodyScroll: function()
10577 //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
10579 this.headEl.setStyle({
10580 'position' : 'relative',
10581 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
10587 var scrollHeight = this.bodyEl.dom.scrollHeight;
10589 var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
10591 var height = this.bodyEl.getHeight();
10593 if(scrollHeight - height == scrollTop) {
10595 var total = this.ds.getTotalCount();
10597 if(this.footer.cursor + this.footer.pageSize < total){
10599 this.footer.ds.load({
10601 start : this.footer.cursor + this.footer.pageSize,
10602 limit : this.footer.pageSize
10611 onColumnSplitterMoved : function(i, diff)
10613 this.userResized = true;
10615 var cm = this.colModel;
10617 var w = this.getHeaderIndex(i).getWidth() + diff;
10620 cm.setColumnWidth(i, w, true);
10622 //var cid = cm.getColumnId(i); << not used in this version?
10623 /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
10625 this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
10626 this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
10627 this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
10629 //this.updateSplitters();
10630 //this.layout(); << ??
10631 this.fireEvent("columnresize", i, w);
10633 onHeaderChange : function()
10635 var header = this.renderHeader();
10636 var table = this.el.select('table', true).first();
10638 this.headEl.remove();
10639 this.headEl = table.createChild(header, this.bodyEl, false);
10641 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
10642 e.on('click', this.sort, this);
10645 if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
10646 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
10651 onHiddenChange : function(colModel, colIndex, hidden)
10654 this.cm.setHidden()
10655 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
10656 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
10658 this.CSS.updateRule(thSelector, "display", "");
10659 this.CSS.updateRule(tdSelector, "display", "");
10662 this.CSS.updateRule(thSelector, "display", "none");
10663 this.CSS.updateRule(tdSelector, "display", "none");
10666 // onload calls initCSS()
10667 this.onHeaderChange();
10671 setColumnWidth: function(col_index, width)
10673 // width = "md-2 xs-2..."
10674 if(!this.colModel.config[col_index]) {
10678 var w = width.split(" ");
10680 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
10682 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
10685 for(var j = 0; j < w.length; j++) {
10691 var size_cls = w[j].split("-");
10693 if(!Number.isInteger(size_cls[1] * 1)) {
10697 if(!this.colModel.config[col_index][size_cls[0]]) {
10701 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
10705 h_row[0].classList.replace(
10706 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
10707 "col-"+size_cls[0]+"-"+size_cls[1]
10710 for(var i = 0; i < rows.length; i++) {
10712 var size_cls = w[j].split("-");
10714 if(!Number.isInteger(size_cls[1] * 1)) {
10718 if(!this.colModel.config[col_index][size_cls[0]]) {
10722 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
10726 rows[i].classList.replace(
10727 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
10728 "col-"+size_cls[0]+"-"+size_cls[1]
10732 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
10737 // currently only used to find the split on drag..
10738 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
10743 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
10744 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;
10753 * @class Roo.bootstrap.TableCell
10754 * @extends Roo.bootstrap.Component
10755 * @children Roo.bootstrap.Component
10756 * @parent Roo.bootstrap.TableRow
10757 * Bootstrap TableCell class
10759 * @cfg {String} html cell contain text
10760 * @cfg {String} cls cell class
10761 * @cfg {String} tag cell tag (td|th) default td
10762 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
10763 * @cfg {String} align Aligns the content in a cell
10764 * @cfg {String} axis Categorizes cells
10765 * @cfg {String} bgcolor Specifies the background color of a cell
10766 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
10767 * @cfg {Number} colspan Specifies the number of columns a cell should span
10768 * @cfg {String} headers Specifies one or more header cells a cell is related to
10769 * @cfg {Number} height Sets the height of a cell
10770 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
10771 * @cfg {Number} rowspan Sets the number of rows a cell should span
10772 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
10773 * @cfg {String} valign Vertical aligns the content in a cell
10774 * @cfg {Number} width Specifies the width of a cell
10777 * Create a new TableCell
10778 * @param {Object} config The config object
10781 Roo.bootstrap.TableCell = function(config){
10782 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
10785 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
10805 getAutoCreate : function(){
10806 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
10813 cfg.tag = this.tag;
10826 cfg.align=this.align
10831 if (this.bgcolor) {
10832 cfg.bgcolor=this.bgcolor
10834 if (this.charoff) {
10835 cfg.charoff=this.charoff
10837 if (this.colspan) {
10838 cfg.colspan=this.colspan
10840 if (this.headers) {
10841 cfg.headers=this.headers
10844 cfg.height=this.height
10847 cfg.nowrap=this.nowrap
10849 if (this.rowspan) {
10850 cfg.rowspan=this.rowspan
10853 cfg.scope=this.scope
10856 cfg.valign=this.valign
10859 cfg.width=this.width
10878 * @class Roo.bootstrap.TableRow
10879 * @extends Roo.bootstrap.Component
10880 * @children Roo.bootstrap.TableCell
10881 * @parent Roo.bootstrap.TableBody
10882 * Bootstrap TableRow class
10883 * @cfg {String} cls row class
10884 * @cfg {String} align Aligns the content in a table row
10885 * @cfg {String} bgcolor Specifies a background color for a table row
10886 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
10887 * @cfg {String} valign Vertical aligns the content in a table row
10890 * Create a new TableRow
10891 * @param {Object} config The config object
10894 Roo.bootstrap.TableRow = function(config){
10895 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
10898 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
10906 getAutoCreate : function(){
10907 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
10914 cfg.cls = this.cls;
10917 cfg.align = this.align;
10920 cfg.bgcolor = this.bgcolor;
10923 cfg.charoff = this.charoff;
10926 cfg.valign = this.valign;
10944 * @class Roo.bootstrap.TableBody
10945 * @extends Roo.bootstrap.Component
10946 * @children Roo.bootstrap.TableRow
10947 * @parent Roo.bootstrap.Table
10948 * Bootstrap TableBody class
10949 * @cfg {String} cls element class
10950 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
10951 * @cfg {String} align Aligns the content inside the element
10952 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
10953 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
10956 * Create a new TableBody
10957 * @param {Object} config The config object
10960 Roo.bootstrap.TableBody = function(config){
10961 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
10964 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
10972 getAutoCreate : function(){
10973 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
10983 cfg.tag = this.tag;
10987 cfg.align = this.align;
10990 cfg.charoff = this.charoff;
10993 cfg.valign = this.valign;
11000 // initEvents : function()
11003 // if(!this.store){
11007 // this.store = Roo.factory(this.store, Roo.data);
11008 // this.store.on('load', this.onLoad, this);
11010 // this.store.load();
11014 // onLoad: function ()
11016 // this.fireEvent('load', this);
11026 * Ext JS Library 1.1.1
11027 * Copyright(c) 2006-2007, Ext JS, LLC.
11029 * Originally Released Under LGPL - original licence link has changed is not relivant.
11032 * <script type="text/javascript">
11035 // as we use this in bootstrap.
11036 Roo.namespace('Roo.form');
11038 * @class Roo.form.Action
11039 * Internal Class used to handle form actions
11041 * @param {Roo.form.BasicForm} el The form element or its id
11042 * @param {Object} config Configuration options
11047 // define the action interface
11048 Roo.form.Action = function(form, options){
11050 this.options = options || {};
11053 * Client Validation Failed
11056 Roo.form.Action.CLIENT_INVALID = 'client';
11058 * Server Validation Failed
11061 Roo.form.Action.SERVER_INVALID = 'server';
11063 * Connect to Server Failed
11066 Roo.form.Action.CONNECT_FAILURE = 'connect';
11068 * Reading Data from Server Failed
11071 Roo.form.Action.LOAD_FAILURE = 'load';
11073 Roo.form.Action.prototype = {
11075 failureType : undefined,
11076 response : undefined,
11077 result : undefined,
11079 // interface method
11080 run : function(options){
11084 // interface method
11085 success : function(response){
11089 // interface method
11090 handleResponse : function(response){
11094 // default connection failure
11095 failure : function(response){
11097 this.response = response;
11098 this.failureType = Roo.form.Action.CONNECT_FAILURE;
11099 this.form.afterAction(this, false);
11102 processResponse : function(response){
11103 this.response = response;
11104 if(!response.responseText){
11107 this.result = this.handleResponse(response);
11108 return this.result;
11111 // utility functions used internally
11112 getUrl : function(appendParams){
11113 var url = this.options.url || this.form.url || this.form.el.dom.action;
11115 var p = this.getParams();
11117 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11123 getMethod : function(){
11124 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
11127 getParams : function(){
11128 var bp = this.form.baseParams;
11129 var p = this.options.params;
11131 if(typeof p == "object"){
11132 p = Roo.urlEncode(Roo.applyIf(p, bp));
11133 }else if(typeof p == 'string' && bp){
11134 p += '&' + Roo.urlEncode(bp);
11137 p = Roo.urlEncode(bp);
11142 createCallback : function(){
11144 success: this.success,
11145 failure: this.failure,
11147 timeout: (this.form.timeout*1000),
11148 upload: this.form.fileUpload ? this.success : undefined
11153 Roo.form.Action.Submit = function(form, options){
11154 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
11157 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
11160 haveProgress : false,
11161 uploadComplete : false,
11163 // uploadProgress indicator.
11164 uploadProgress : function()
11166 if (!this.form.progressUrl) {
11170 if (!this.haveProgress) {
11171 Roo.MessageBox.progress("Uploading", "Uploading");
11173 if (this.uploadComplete) {
11174 Roo.MessageBox.hide();
11178 this.haveProgress = true;
11180 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
11182 var c = new Roo.data.Connection();
11184 url : this.form.progressUrl,
11189 success : function(req){
11190 //console.log(data);
11194 rdata = Roo.decode(req.responseText)
11196 Roo.log("Invalid data from server..");
11200 if (!rdata || !rdata.success) {
11202 Roo.MessageBox.alert(Roo.encode(rdata));
11205 var data = rdata.data;
11207 if (this.uploadComplete) {
11208 Roo.MessageBox.hide();
11213 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
11214 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
11217 this.uploadProgress.defer(2000,this);
11220 failure: function(data) {
11221 Roo.log('progress url failed ');
11232 // run get Values on the form, so it syncs any secondary forms.
11233 this.form.getValues();
11235 var o = this.options;
11236 var method = this.getMethod();
11237 var isPost = method == 'POST';
11238 if(o.clientValidation === false || this.form.isValid()){
11240 if (this.form.progressUrl) {
11241 this.form.findField('UPLOAD_IDENTIFIER').setValue(
11242 (new Date() * 1) + '' + Math.random());
11247 Roo.Ajax.request(Roo.apply(this.createCallback(), {
11248 form:this.form.el.dom,
11249 url:this.getUrl(!isPost),
11251 params:isPost ? this.getParams() : null,
11252 isUpload: this.form.fileUpload,
11253 formData : this.form.formData
11256 this.uploadProgress();
11258 }else if (o.clientValidation !== false){ // client validation failed
11259 this.failureType = Roo.form.Action.CLIENT_INVALID;
11260 this.form.afterAction(this, false);
11264 success : function(response)
11266 this.uploadComplete= true;
11267 if (this.haveProgress) {
11268 Roo.MessageBox.hide();
11272 var result = this.processResponse(response);
11273 if(result === true || result.success){
11274 this.form.afterAction(this, true);
11278 this.form.markInvalid(result.errors);
11279 this.failureType = Roo.form.Action.SERVER_INVALID;
11281 this.form.afterAction(this, false);
11283 failure : function(response)
11285 this.uploadComplete= true;
11286 if (this.haveProgress) {
11287 Roo.MessageBox.hide();
11290 this.response = response;
11291 this.failureType = Roo.form.Action.CONNECT_FAILURE;
11292 this.form.afterAction(this, false);
11295 handleResponse : function(response){
11296 if(this.form.errorReader){
11297 var rs = this.form.errorReader.read(response);
11300 for(var i = 0, len = rs.records.length; i < len; i++) {
11301 var r = rs.records[i];
11302 errors[i] = r.data;
11305 if(errors.length < 1){
11309 success : rs.success,
11315 ret = Roo.decode(response.responseText);
11319 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
11329 Roo.form.Action.Load = function(form, options){
11330 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
11331 this.reader = this.form.reader;
11334 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
11339 Roo.Ajax.request(Roo.apply(
11340 this.createCallback(), {
11341 method:this.getMethod(),
11342 url:this.getUrl(false),
11343 params:this.getParams()
11347 success : function(response){
11349 var result = this.processResponse(response);
11350 if(result === true || !result.success || !result.data){
11351 this.failureType = Roo.form.Action.LOAD_FAILURE;
11352 this.form.afterAction(this, false);
11355 this.form.clearInvalid();
11356 this.form.setValues(result.data);
11357 this.form.afterAction(this, true);
11360 handleResponse : function(response){
11361 if(this.form.reader){
11362 var rs = this.form.reader.read(response);
11363 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
11365 success : rs.success,
11369 return Roo.decode(response.responseText);
11373 Roo.form.Action.ACTION_TYPES = {
11374 'load' : Roo.form.Action.Load,
11375 'submit' : Roo.form.Action.Submit
11384 * @class Roo.bootstrap.form.Form
11385 * @extends Roo.bootstrap.Component
11386 * @children Roo.bootstrap.Component
11387 * Bootstrap Form class
11388 * @cfg {String} method GET | POST (default POST)
11389 * @cfg {String} labelAlign top | left (default top)
11390 * @cfg {String} align left | right - for navbars
11391 * @cfg {Boolean} loadMask load mask when submit (default true)
11395 * Create a new Form
11396 * @param {Object} config The config object
11400 Roo.bootstrap.form.Form = function(config){
11402 Roo.bootstrap.form.Form.superclass.constructor.call(this, config);
11404 Roo.bootstrap.form.Form.popover.apply();
11408 * @event clientvalidation
11409 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
11410 * @param {Form} this
11411 * @param {Boolean} valid true if the form has passed client-side validation
11413 clientvalidation: true,
11415 * @event beforeaction
11416 * Fires before any action is performed. Return false to cancel the action.
11417 * @param {Form} this
11418 * @param {Action} action The action to be performed
11420 beforeaction: true,
11422 * @event actionfailed
11423 * Fires when an action fails.
11424 * @param {Form} this
11425 * @param {Action} action The action that failed
11427 actionfailed : true,
11429 * @event actioncomplete
11430 * Fires when an action is completed.
11431 * @param {Form} this
11432 * @param {Action} action The action that completed
11434 actioncomplete : true
11438 Roo.extend(Roo.bootstrap.form.Form, Roo.bootstrap.Component, {
11441 * @cfg {String} method
11442 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
11446 * @cfg {String} url
11447 * The URL to use for form actions if one isn't supplied in the action options.
11450 * @cfg {Boolean} fileUpload
11451 * Set to true if this form is a file upload.
11455 * @cfg {Object} baseParams
11456 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
11460 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
11464 * @cfg {Sting} align (left|right) for navbar forms
11469 activeAction : null,
11472 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
11473 * element by passing it or its id or mask the form itself by passing in true.
11476 waitMsgTarget : false,
11481 * @cfg {Boolean} errorMask (true|false) default false
11486 * @cfg {Number} maskOffset Default 100
11491 * @cfg {Boolean} maskBody
11495 getAutoCreate : function(){
11499 method : this.method || 'POST',
11500 id : this.id || Roo.id(),
11503 if (this.parent().xtype.match(/^Nav/)) {
11504 cfg.cls = 'navbar-form form-inline navbar-' + this.align;
11508 if (this.labelAlign == 'left' ) {
11509 cfg.cls += ' form-horizontal';
11515 initEvents : function()
11517 this.el.on('submit', this.onSubmit, this);
11518 // this was added as random key presses on the form where triggering form submit.
11519 this.el.on('keypress', function(e) {
11520 if (e.getCharCode() != 13) {
11523 // we might need to allow it for textareas.. and some other items.
11524 // check e.getTarget().
11526 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
11530 Roo.log("keypress blocked");
11532 e.preventDefault();
11538 onSubmit : function(e){
11543 * Returns true if client-side validation on the form is successful.
11546 isValid : function(){
11547 var items = this.getItems();
11549 var target = false;
11551 items.each(function(f){
11557 Roo.log('invalid field: ' + f.name);
11561 if(!target && f.el.isVisible(true)){
11567 if(this.errorMask && !valid){
11568 Roo.bootstrap.form.Form.popover.mask(this, target);
11575 * Returns true if any fields in this form have changed since their original load.
11578 isDirty : function(){
11580 var items = this.getItems();
11581 items.each(function(f){
11591 * Performs a predefined action (submit or load) or custom actions you define on this form.
11592 * @param {String} actionName The name of the action type
11593 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
11594 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
11595 * accept other config options):
11597 Property Type Description
11598 ---------------- --------------- ----------------------------------------------------------------------------------
11599 url String The url for the action (defaults to the form's url)
11600 method String The form method to use (defaults to the form's method, or POST if not defined)
11601 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
11602 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
11603 validate the form on the client (defaults to false)
11605 * @return {BasicForm} this
11607 doAction : function(action, options){
11608 if(typeof action == 'string'){
11609 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
11611 if(this.fireEvent('beforeaction', this, action) !== false){
11612 this.beforeAction(action);
11613 action.run.defer(100, action);
11619 beforeAction : function(action){
11620 var o = action.options;
11625 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
11627 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
11630 // not really supported yet.. ??
11632 //if(this.waitMsgTarget === true){
11633 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
11634 //}else if(this.waitMsgTarget){
11635 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
11636 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
11638 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
11644 afterAction : function(action, success){
11645 this.activeAction = null;
11646 var o = action.options;
11651 Roo.get(document.body).unmask();
11657 //if(this.waitMsgTarget === true){
11658 // this.el.unmask();
11659 //}else if(this.waitMsgTarget){
11660 // this.waitMsgTarget.unmask();
11662 // Roo.MessageBox.updateProgress(1);
11663 // Roo.MessageBox.hide();
11670 Roo.callback(o.success, o.scope, [this, action]);
11671 this.fireEvent('actioncomplete', this, action);
11675 // failure condition..
11676 // we have a scenario where updates need confirming.
11677 // eg. if a locking scenario exists..
11678 // we look for { errors : { needs_confirm : true }} in the response.
11680 (typeof(action.result) != 'undefined') &&
11681 (typeof(action.result.errors) != 'undefined') &&
11682 (typeof(action.result.errors.needs_confirm) != 'undefined')
11685 Roo.log("not supported yet");
11688 Roo.MessageBox.confirm(
11689 "Change requires confirmation",
11690 action.result.errorMsg,
11695 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
11705 Roo.callback(o.failure, o.scope, [this, action]);
11706 // show an error message if no failed handler is set..
11707 if (!this.hasListener('actionfailed')) {
11708 Roo.log("need to add dialog support");
11710 Roo.MessageBox.alert("Error",
11711 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
11712 action.result.errorMsg :
11713 "Saving Failed, please check your entries or try again"
11718 this.fireEvent('actionfailed', this, action);
11723 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
11724 * @param {String} id The value to search for
11727 findField : function(id){
11728 var items = this.getItems();
11729 var field = items.get(id);
11731 items.each(function(f){
11732 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
11739 return field || null;
11742 * Mark fields in this form invalid in bulk.
11743 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
11744 * @return {BasicForm} this
11746 markInvalid : function(errors){
11747 if(errors instanceof Array){
11748 for(var i = 0, len = errors.length; i < len; i++){
11749 var fieldError = errors[i];
11750 var f = this.findField(fieldError.id);
11752 f.markInvalid(fieldError.msg);
11758 if(typeof errors[id] != 'function' && (field = this.findField(id))){
11759 field.markInvalid(errors[id]);
11763 //Roo.each(this.childForms || [], function (f) {
11764 // f.markInvalid(errors);
11771 * Set values for fields in this form in bulk.
11772 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
11773 * @return {BasicForm} this
11775 setValues : function(values){
11776 if(values instanceof Array){ // array of objects
11777 for(var i = 0, len = values.length; i < len; i++){
11779 var f = this.findField(v.id);
11781 f.setValue(v.value);
11782 if(this.trackResetOnLoad){
11783 f.originalValue = f.getValue();
11787 }else{ // object hash
11790 if(typeof values[id] != 'function' && (field = this.findField(id))){
11792 if (field.setFromData &&
11793 field.valueField &&
11794 field.displayField &&
11795 // combos' with local stores can
11796 // be queried via setValue()
11797 // to set their value..
11798 (field.store && !field.store.isLocal)
11802 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
11803 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
11804 field.setFromData(sd);
11806 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
11808 field.setFromData(values);
11811 field.setValue(values[id]);
11815 if(this.trackResetOnLoad){
11816 field.originalValue = field.getValue();
11822 //Roo.each(this.childForms || [], function (f) {
11823 // f.setValues(values);
11830 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
11831 * they are returned as an array.
11832 * @param {Boolean} asString
11835 getValues : function(asString){
11836 //if (this.childForms) {
11837 // copy values from the child forms
11838 // Roo.each(this.childForms, function (f) {
11839 // this.setValues(f.getValues());
11845 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
11846 if(asString === true){
11849 return Roo.urlDecode(fs);
11853 * Returns the fields in this form as an object with key/value pairs.
11854 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
11857 getFieldValues : function(with_hidden)
11859 var items = this.getItems();
11861 items.each(function(f){
11863 if (!f.getName()) {
11867 var v = f.getValue();
11869 if (f.inputType =='radio') {
11870 if (typeof(ret[f.getName()]) == 'undefined') {
11871 ret[f.getName()] = ''; // empty..
11874 if (!f.el.dom.checked) {
11878 v = f.el.dom.value;
11882 if(f.xtype == 'MoneyField'){
11883 ret[f.currencyName] = f.getCurrency();
11886 // not sure if this supported any more..
11887 if ((typeof(v) == 'object') && f.getRawValue) {
11888 v = f.getRawValue() ; // dates..
11890 // combo boxes where name != hiddenName...
11891 if (f.name !== false && f.name != '' && f.name != f.getName()) {
11892 ret[f.name] = f.getRawValue();
11894 ret[f.getName()] = v;
11901 * Clears all invalid messages in this form.
11902 * @return {BasicForm} this
11904 clearInvalid : function(){
11905 var items = this.getItems();
11907 items.each(function(f){
11915 * Resets this form.
11916 * @return {BasicForm} this
11918 reset : function(){
11919 var items = this.getItems();
11920 items.each(function(f){
11924 Roo.each(this.childForms || [], function (f) {
11932 getItems : function()
11934 var r=new Roo.util.MixedCollection(false, function(o){
11935 return o.id || (o.id = Roo.id());
11937 var iter = function(el) {
11944 Roo.each(el.items,function(e) {
11953 hideFields : function(items)
11955 Roo.each(items, function(i){
11957 var f = this.findField(i);
11968 showFields : function(items)
11970 Roo.each(items, function(i){
11972 var f = this.findField(i);
11985 Roo.apply(Roo.bootstrap.form.Form, {
12001 intervalID : false,
12007 if(this.isApplied){
12012 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
12013 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
12014 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
12015 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
12018 this.maskEl.top.enableDisplayMode("block");
12019 this.maskEl.left.enableDisplayMode("block");
12020 this.maskEl.bottom.enableDisplayMode("block");
12021 this.maskEl.right.enableDisplayMode("block");
12023 this.toolTip = new Roo.bootstrap.Tooltip({
12024 cls : 'roo-form-error-popover',
12026 'left' : ['r-l', [-2,0], 'right'],
12027 'right' : ['l-r', [2,0], 'left'],
12028 'bottom' : ['tl-bl', [0,2], 'top'],
12029 'top' : [ 'bl-tl', [0,-2], 'bottom']
12033 this.toolTip.render(Roo.get(document.body));
12035 this.toolTip.el.enableDisplayMode("block");
12037 Roo.get(document.body).on('click', function(){
12041 Roo.get(document.body).on('touchstart', function(){
12045 this.isApplied = true
12048 mask : function(form, target)
12052 this.target = target;
12054 if(!this.form.errorMask || !target.el){
12058 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
12060 Roo.log(scrollable);
12062 var ot = this.target.el.calcOffsetsTo(scrollable);
12064 var scrollTo = ot[1] - this.form.maskOffset;
12066 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
12068 scrollable.scrollTo('top', scrollTo);
12070 var box = this.target.el.getBox();
12072 var zIndex = Roo.bootstrap.Modal.zIndex++;
12075 this.maskEl.top.setStyle('position', 'absolute');
12076 this.maskEl.top.setStyle('z-index', zIndex);
12077 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
12078 this.maskEl.top.setLeft(0);
12079 this.maskEl.top.setTop(0);
12080 this.maskEl.top.show();
12082 this.maskEl.left.setStyle('position', 'absolute');
12083 this.maskEl.left.setStyle('z-index', zIndex);
12084 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
12085 this.maskEl.left.setLeft(0);
12086 this.maskEl.left.setTop(box.y - this.padding);
12087 this.maskEl.left.show();
12089 this.maskEl.bottom.setStyle('position', 'absolute');
12090 this.maskEl.bottom.setStyle('z-index', zIndex);
12091 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
12092 this.maskEl.bottom.setLeft(0);
12093 this.maskEl.bottom.setTop(box.bottom + this.padding);
12094 this.maskEl.bottom.show();
12096 this.maskEl.right.setStyle('position', 'absolute');
12097 this.maskEl.right.setStyle('z-index', zIndex);
12098 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
12099 this.maskEl.right.setLeft(box.right + this.padding);
12100 this.maskEl.right.setTop(box.y - this.padding);
12101 this.maskEl.right.show();
12103 this.toolTip.bindEl = this.target.el;
12105 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
12107 var tip = this.target.blankText;
12109 if(this.target.getValue() !== '' ) {
12111 if (this.target.invalidText.length) {
12112 tip = this.target.invalidText;
12113 } else if (this.target.regexText.length){
12114 tip = this.target.regexText;
12118 this.toolTip.show(tip);
12120 this.intervalID = window.setInterval(function() {
12121 Roo.bootstrap.form.Form.popover.unmask();
12124 window.onwheel = function(){ return false;};
12126 (function(){ this.isMasked = true; }).defer(500, this);
12130 unmask : function()
12132 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
12136 this.maskEl.top.setStyle('position', 'absolute');
12137 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
12138 this.maskEl.top.hide();
12140 this.maskEl.left.setStyle('position', 'absolute');
12141 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
12142 this.maskEl.left.hide();
12144 this.maskEl.bottom.setStyle('position', 'absolute');
12145 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
12146 this.maskEl.bottom.hide();
12148 this.maskEl.right.setStyle('position', 'absolute');
12149 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
12150 this.maskEl.right.hide();
12152 this.toolTip.hide();
12154 this.toolTip.el.hide();
12156 window.onwheel = function(){ return true;};
12158 if(this.intervalID){
12159 window.clearInterval(this.intervalID);
12160 this.intervalID = false;
12163 this.isMasked = false;
12173 * Ext JS Library 1.1.1
12174 * Copyright(c) 2006-2007, Ext JS, LLC.
12176 * Originally Released Under LGPL - original licence link has changed is not relivant.
12179 * <script type="text/javascript">
12182 * @class Roo.form.VTypes
12183 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
12186 Roo.form.VTypes = function(){
12187 // closure these in so they are only created once.
12188 var alpha = /^[a-zA-Z_]+$/;
12189 var alphanum = /^[a-zA-Z0-9_]+$/;
12190 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
12191 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
12193 // All these messages and functions are configurable
12196 * The function used to validate email addresses
12197 * @param {String} value The email address
12199 email : function(v){
12200 return email.test(v);
12203 * The error text to display when the email validation function returns false
12206 emailText : 'This field should be an e-mail address in the format "user@domain.com"',
12208 * The keystroke filter mask to be applied on email input
12211 emailMask : /[a-z0-9_\.\-@]/i,
12214 * The function used to validate URLs
12215 * @param {String} value The URL
12218 return url.test(v);
12221 * The error text to display when the url validation function returns false
12224 urlText : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
12227 * The function used to validate alpha values
12228 * @param {String} value The value
12230 alpha : function(v){
12231 return alpha.test(v);
12234 * The error text to display when the alpha validation function returns false
12237 alphaText : 'This field should only contain letters and _',
12239 * The keystroke filter mask to be applied on alpha input
12242 alphaMask : /[a-z_]/i,
12245 * The function used to validate alphanumeric values
12246 * @param {String} value The value
12248 alphanum : function(v){
12249 return alphanum.test(v);
12252 * The error text to display when the alphanumeric validation function returns false
12255 alphanumText : 'This field should only contain letters, numbers and _',
12257 * The keystroke filter mask to be applied on alphanumeric input
12260 alphanumMask : /[a-z0-9_]/i
12270 * @class Roo.bootstrap.form.Input
12271 * @extends Roo.bootstrap.Component
12272 * Bootstrap Input class
12273 * @cfg {Boolean} disabled is it disabled
12274 * @cfg {String} inputType (button|checkbox|email|file|hidden|image|number|password|radio|range|reset|search|submit|text)
12275 * @cfg {String} name name of the input
12276 * @cfg {string} fieldLabel - the label associated
12277 * @cfg {string} placeholder - placeholder to put in text.
12278 * @cfg {string} before - input group add on before
12279 * @cfg {string} after - input group add on after
12280 * @cfg {string} size - (lg|sm) or leave empty..
12281 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
12282 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
12283 * @cfg {Number} md colspan out of 12 for computer-sized screens
12284 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
12285 * @cfg {string} value default value of the input
12286 * @cfg {Number} labelWidth set the width of label
12287 * @cfg {Number} labellg set the width of label (1-12)
12288 * @cfg {Number} labelmd set the width of label (1-12)
12289 * @cfg {Number} labelsm set the width of label (1-12)
12290 * @cfg {Number} labelxs set the width of label (1-12)
12291 * @cfg {String} labelAlign (top|left)
12292 * @cfg {Boolean} readOnly Specifies that the field should be read-only
12293 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
12294 * @cfg {String} indicatorpos (left|right) default left
12295 * @cfg {String} capture (user|camera) use for file input only. (default empty)
12296 * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
12297 * @cfg {Boolean} preventMark Do not show tick or cross if error/success
12298 * @cfg {Roo.bootstrap.Button} before Button to show before
12299 * @cfg {Roo.bootstrap.Button} afterButton to show before
12300 * @cfg {String} align (left|center|right) Default left
12301 * @cfg {Boolean} forceFeedback (true|false) Default false
12304 * Create a new Input
12305 * @param {Object} config The config object
12308 Roo.bootstrap.form.Input = function(config){
12310 Roo.bootstrap.form.Input.superclass.constructor.call(this, config);
12315 * Fires when this field receives input focus.
12316 * @param {Roo.form.Field} this
12321 * Fires when this field loses input focus.
12322 * @param {Roo.form.Field} this
12326 * @event specialkey
12327 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
12328 * {@link Roo.EventObject#getKey} to determine which key was pressed.
12329 * @param {Roo.form.Field} this
12330 * @param {Roo.EventObject} e The event object
12335 * Fires just before the field blurs if the field value has changed.
12336 * @param {Roo.form.Field} this
12337 * @param {Mixed} newValue The new value
12338 * @param {Mixed} oldValue The original value
12343 * Fires after the field has been marked as invalid.
12344 * @param {Roo.form.Field} this
12345 * @param {String} msg The validation message
12350 * Fires after the field has been validated with no errors.
12351 * @param {Roo.form.Field} this
12356 * Fires after the key up
12357 * @param {Roo.form.Field} this
12358 * @param {Roo.EventObject} e The event Object
12363 * Fires after the user pastes into input
12364 * @param {Roo.form.Field} this
12365 * @param {Roo.EventObject} e The event Object
12371 Roo.extend(Roo.bootstrap.form.Input, Roo.bootstrap.Component, {
12373 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
12374 automatic validation (defaults to "keyup").
12376 validationEvent : "keyup",
12378 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
12380 validateOnBlur : true,
12382 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
12384 validationDelay : 250,
12386 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
12388 focusClass : "x-form-focus", // not needed???
12392 * @cfg {String} invalidClass DEPRICATED - code uses BS4 - is-valid / is-invalid
12394 invalidClass : "has-warning",
12397 * @cfg {String} validClass DEPRICATED - code uses BS4 - is-valid / is-invalid
12399 validClass : "has-success",
12402 * @cfg {Boolean} hasFeedback (true|false) default true
12404 hasFeedback : true,
12407 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
12409 invalidFeedbackClass : "glyphicon-warning-sign",
12412 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
12414 validFeedbackClass : "glyphicon-ok",
12417 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
12419 selectOnFocus : false,
12422 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
12426 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
12431 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
12433 disableKeyFilter : false,
12436 * @cfg {Boolean} disabled True to disable the field (defaults to false).
12440 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
12444 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
12446 blankText : "Please complete this mandatory field",
12449 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
12453 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
12455 maxLength : Number.MAX_VALUE,
12457 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
12459 minLengthText : "The minimum length for this field is {0}",
12461 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
12463 maxLengthText : "The maximum length for this field is {0}",
12467 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
12468 * If available, this function will be called only after the basic validators all return true, and will be passed the
12469 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
12473 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
12474 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
12475 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
12479 * @cfg {String} regexText -- Depricated - use Invalid Text
12484 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
12490 autocomplete: false,
12494 inputType : 'text',
12497 placeholder: false,
12502 preventMark: false,
12503 isFormField : true,
12506 labelAlign : false,
12509 formatedValue : false,
12510 forceFeedback : false,
12512 indicatorpos : 'left',
12522 parentLabelAlign : function()
12525 while (parent.parent()) {
12526 parent = parent.parent();
12527 if (typeof(parent.labelAlign) !='undefined') {
12528 return parent.labelAlign;
12535 getAutoCreate : function()
12537 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
12543 if(this.inputType != 'hidden'){
12544 cfg.cls = 'form-group' //input-group
12550 type : this.inputType,
12551 value : this.value,
12552 cls : 'form-control',
12553 placeholder : this.placeholder || '',
12554 autocomplete : this.autocomplete || 'new-password'
12556 if (this.inputType == 'file') {
12557 input.style = 'overflow:hidden'; // why not in CSS?
12560 if(this.capture.length){
12561 input.capture = this.capture;
12564 if(this.accept.length){
12565 input.accept = this.accept + "/*";
12569 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
12572 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
12573 input.maxLength = this.maxLength;
12576 if (this.disabled) {
12577 input.disabled=true;
12580 if (this.readOnly) {
12581 input.readonly=true;
12585 input.name = this.name;
12589 input.cls += ' input-' + this.size;
12593 ['xs','sm','md','lg'].map(function(size){
12594 if (settings[size]) {
12595 cfg.cls += ' col-' + size + '-' + settings[size];
12599 var inputblock = input;
12603 cls: 'glyphicon form-control-feedback'
12606 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
12609 cls : 'has-feedback',
12617 if (this.before || this.after) {
12620 cls : 'input-group',
12624 if (this.before && typeof(this.before) == 'string') {
12626 inputblock.cn.push({
12628 cls : 'roo-input-before input-group-addon input-group-prepend input-group-text',
12632 if (this.before && typeof(this.before) == 'object') {
12633 this.before = Roo.factory(this.before);
12635 inputblock.cn.push({
12637 cls : 'roo-input-before input-group-prepend input-group-' +
12638 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
12642 inputblock.cn.push(input);
12644 if (this.after && typeof(this.after) == 'string') {
12645 inputblock.cn.push({
12647 cls : 'roo-input-after input-group-append input-group-text input-group-addon',
12651 if (this.after && typeof(this.after) == 'object') {
12652 this.after = Roo.factory(this.after);
12654 inputblock.cn.push({
12656 cls : 'roo-input-after input-group-append input-group-' +
12657 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
12661 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
12662 inputblock.cls += ' has-feedback';
12663 inputblock.cn.push(feedback);
12668 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
12669 tooltip : 'This field is required'
12671 if (this.allowBlank ) {
12672 indicator.style = this.allowBlank ? ' display:none' : '';
12674 if (align ==='left' && this.fieldLabel.length) {
12676 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
12683 cls : 'control-label col-form-label',
12684 html : this.fieldLabel
12695 var labelCfg = cfg.cn[1];
12696 var contentCfg = cfg.cn[2];
12698 if(this.indicatorpos == 'right'){
12703 cls : 'control-label col-form-label',
12707 html : this.fieldLabel
12721 labelCfg = cfg.cn[0];
12722 contentCfg = cfg.cn[1];
12726 if(this.labelWidth > 12){
12727 labelCfg.style = "width: " + this.labelWidth + 'px';
12730 if(this.labelWidth < 13 && this.labelmd == 0){
12731 this.labellg = this.labellg > 0 ? this.labellg : this.labelWidth;
12734 if(this.labellg > 0){
12735 labelCfg.cls += ' col-lg-' + this.labellg;
12736 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
12739 if(this.labelmd > 0){
12740 labelCfg.cls += ' col-md-' + this.labelmd;
12741 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
12744 if(this.labelsm > 0){
12745 labelCfg.cls += ' col-sm-' + this.labelsm;
12746 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
12749 if(this.labelxs > 0){
12750 labelCfg.cls += ' col-xs-' + this.labelxs;
12751 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
12755 } else if ( this.fieldLabel.length) {
12762 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12763 tooltip : 'This field is required',
12764 style : this.allowBlank ? ' display:none' : ''
12768 //cls : 'input-group-addon',
12769 html : this.fieldLabel
12777 if(this.indicatorpos == 'right'){
12782 //cls : 'input-group-addon',
12783 html : this.fieldLabel
12788 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12789 tooltip : 'This field is required',
12790 style : this.allowBlank ? ' display:none' : ''
12810 if (this.parentType === 'Navbar' && this.parent().bar) {
12811 cfg.cls += ' navbar-form';
12814 if (this.parentType === 'NavGroup' && !(Roo.bootstrap.version == 4 && this.parent().form)) {
12815 // on BS4 we do this only if not form
12816 cfg.cls += ' navbar-form';
12824 * return the real input element.
12826 inputEl: function ()
12828 return this.el.select('input.form-control',true).first();
12831 tooltipEl : function()
12833 return this.inputEl();
12836 indicatorEl : function()
12838 if (Roo.bootstrap.version == 4) {
12839 return false; // not enabled in v4 yet.
12842 var indicator = this.el.select('i.roo-required-indicator',true).first();
12852 setDisabled : function(v)
12854 var i = this.inputEl().dom;
12856 i.removeAttribute('disabled');
12860 i.setAttribute('disabled','true');
12862 initEvents : function()
12865 this.inputEl().on("keydown" , this.fireKey, this);
12866 this.inputEl().on("focus", this.onFocus, this);
12867 this.inputEl().on("blur", this.onBlur, this);
12869 this.inputEl().relayEvent('keyup', this);
12870 this.inputEl().relayEvent('paste', this);
12872 this.indicator = this.indicatorEl();
12874 if(this.indicator){
12875 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? -
12878 // reference to original value for reset
12879 this.originalValue = this.getValue();
12880 //Roo.form.TextField.superclass.initEvents.call(this);
12881 if(this.validationEvent == 'keyup'){
12882 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
12883 this.inputEl().on('keyup', this.filterValidation, this);
12885 else if(this.validationEvent !== false){
12886 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
12889 if(this.selectOnFocus){
12890 this.on("focus", this.preFocus, this);
12893 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
12894 this.inputEl().on("keypress", this.filterKeys, this);
12896 this.inputEl().relayEvent('keypress', this);
12899 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
12900 this.el.on("click", this.autoSize, this);
12903 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
12904 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
12907 if (typeof(this.before) == 'object') {
12908 this.before.render(this.el.select('.roo-input-before',true).first());
12910 if (typeof(this.after) == 'object') {
12911 this.after.render(this.el.select('.roo-input-after',true).first());
12914 this.inputEl().on('change', this.onChange, this);
12917 filterValidation : function(e){
12918 if(!e.isNavKeyPress()){
12919 this.validationTask.delay(this.validationDelay);
12923 * Validates the field value
12924 * @return {Boolean} True if the value is valid, else false
12926 validate : function(){
12927 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
12928 if(this.disabled || this.validateValue(this.getRawValue())){
12933 this.markInvalid();
12939 * Validates a value according to the field's validation rules and marks the field as invalid
12940 * if the validation fails
12941 * @param {Mixed} value The value to validate
12942 * @return {Boolean} True if the value is valid, else false
12944 validateValue : function(value)
12946 if(this.getVisibilityEl().hasClass('hidden')){
12950 if(value.length < 1) { // if it's blank
12951 if(this.allowBlank){
12957 if(value.length < this.minLength){
12960 if(value.length > this.maxLength){
12964 var vt = Roo.form.VTypes;
12965 if(!vt[this.vtype](value, this)){
12969 if(typeof this.validator == "function"){
12970 var msg = this.validator(value);
12971 if (typeof(msg) == 'string') {
12972 this.invalidText = msg;
12979 if(this.regex && !this.regex.test(value)){
12987 fireKey : function(e){
12988 //Roo.log('field ' + e.getKey());
12989 if(e.isNavKeyPress()){
12990 this.fireEvent("specialkey", this, e);
12993 focus : function (selectText){
12995 this.inputEl().focus();
12996 if(selectText === true){
12997 this.inputEl().dom.select();
13003 onFocus : function(){
13004 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
13005 // this.el.addClass(this.focusClass);
13007 if(!this.hasFocus){
13008 this.hasFocus = true;
13009 this.startValue = this.getValue();
13010 this.fireEvent("focus", this);
13014 beforeBlur : Roo.emptyFn,
13018 onBlur : function(){
13020 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
13021 //this.el.removeClass(this.focusClass);
13023 this.hasFocus = false;
13024 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
13027 var v = this.getValue();
13028 if(String(v) !== String(this.startValue)){
13029 this.fireEvent('change', this, v, this.startValue);
13031 this.fireEvent("blur", this);
13034 onChange : function(e)
13036 var v = this.getValue();
13037 if(String(v) !== String(this.startValue)){
13038 this.fireEvent('change', this, v, this.startValue);
13044 * Resets the current field value to the originally loaded value and clears any validation messages
13046 reset : function(){
13047 this.setValue(this.originalValue);
13051 * Returns the name of the field
13052 * @return {Mixed} name The name field
13054 getName: function(){
13058 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
13059 * @return {Mixed} value The field value
13061 getValue : function(){
13063 var v = this.inputEl().getValue();
13068 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
13069 * @return {Mixed} value The field value
13071 getRawValue : function(){
13072 var v = this.inputEl().getValue();
13078 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
13079 * @param {Mixed} value The value to set
13081 setRawValue : function(v){
13082 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
13085 selectText : function(start, end){
13086 var v = this.getRawValue();
13088 start = start === undefined ? 0 : start;
13089 end = end === undefined ? v.length : end;
13090 var d = this.inputEl().dom;
13091 if(d.setSelectionRange){
13092 d.setSelectionRange(start, end);
13093 }else if(d.createTextRange){
13094 var range = d.createTextRange();
13095 range.moveStart("character", start);
13096 range.moveEnd("character", v.length-end);
13103 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
13104 * @param {Mixed} value The value to set
13106 setValue : function(v){
13109 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
13115 processValue : function(value){
13116 if(this.stripCharsRe){
13117 var newValue = value.replace(this.stripCharsRe, '');
13118 if(newValue !== value){
13119 this.setRawValue(newValue);
13126 preFocus : function(){
13128 if(this.selectOnFocus){
13129 this.inputEl().dom.select();
13132 filterKeys : function(e){
13133 var k = e.getKey();
13134 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
13137 var c = e.getCharCode(), cc = String.fromCharCode(c);
13138 if(Roo.isIE && (e.isSpecialKey() || !cc)){
13141 if(!this.maskRe.test(cc)){
13146 * Clear any invalid styles/messages for this field
13148 clearInvalid : function(){
13150 if(!this.el || this.preventMark){ // not rendered
13155 this.el.removeClass([this.invalidClass, 'is-invalid']);
13157 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13159 var feedback = this.el.select('.form-control-feedback', true).first();
13162 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
13167 if(this.indicator){
13168 this.indicator.removeClass('visible');
13169 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13172 this.fireEvent('valid', this);
13176 * Mark this field as valid
13178 markValid : function()
13180 if(!this.el || this.preventMark){ // not rendered...
13184 this.el.removeClass([this.invalidClass, this.validClass]);
13185 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13187 var feedback = this.el.select('.form-control-feedback', true).first();
13190 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13193 if(this.indicator){
13194 this.indicator.removeClass('visible');
13195 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13203 if(this.allowBlank && !this.getRawValue().length){
13206 if (Roo.bootstrap.version == 3) {
13207 this.el.addClass(this.validClass);
13209 this.inputEl().addClass('is-valid');
13212 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
13214 var feedback = this.el.select('.form-control-feedback', true).first();
13217 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13218 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
13223 this.fireEvent('valid', this);
13227 * Mark this field as invalid
13228 * @param {String} msg The validation message
13230 markInvalid : function(msg)
13232 if(!this.el || this.preventMark){ // not rendered
13236 this.el.removeClass([this.invalidClass, this.validClass]);
13237 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13239 var feedback = this.el.select('.form-control-feedback', true).first();
13242 this.el.select('.form-control-feedback', true).first().removeClass(
13243 [this.invalidFeedbackClass, this.validFeedbackClass]);
13250 if(this.allowBlank && !this.getRawValue().length){
13254 if(this.indicator){
13255 this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13256 this.indicator.addClass('visible');
13258 if (Roo.bootstrap.version == 3) {
13259 this.el.addClass(this.invalidClass);
13261 this.inputEl().addClass('is-invalid');
13266 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13268 var feedback = this.el.select('.form-control-feedback', true).first();
13271 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13273 if(this.getValue().length || this.forceFeedback){
13274 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
13281 this.fireEvent('invalid', this, msg);
13284 SafariOnKeyDown : function(event)
13286 // this is a workaround for a password hang bug on chrome/ webkit.
13287 if (this.inputEl().dom.type != 'password') {
13291 var isSelectAll = false;
13293 if(this.inputEl().dom.selectionEnd > 0){
13294 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
13296 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
13297 event.preventDefault();
13302 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
13304 event.preventDefault();
13305 // this is very hacky as keydown always get's upper case.
13307 var cc = String.fromCharCode(event.getCharCode());
13308 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
13312 adjustWidth : function(tag, w){
13313 tag = tag.toLowerCase();
13314 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
13315 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
13316 if(tag == 'input'){
13319 if(tag == 'textarea'){
13322 }else if(Roo.isOpera){
13323 if(tag == 'input'){
13326 if(tag == 'textarea'){
13334 setFieldLabel : function(v)
13336 if(!this.rendered){
13340 if(this.indicatorEl()){
13341 var ar = this.el.select('label > span',true);
13343 if (ar.elements.length) {
13344 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13345 this.fieldLabel = v;
13349 var br = this.el.select('label',true);
13351 if(br.elements.length) {
13352 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13353 this.fieldLabel = v;
13357 Roo.log('Cannot Found any of label > span || label in input');
13361 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13362 this.fieldLabel = v;
13377 * @class Roo.bootstrap.form.TextArea
13378 * @extends Roo.bootstrap.form.Input
13379 * Bootstrap TextArea class
13380 * @cfg {Number} cols Specifies the visible width of a text area
13381 * @cfg {Number} rows Specifies the visible number of lines in a text area
13382 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
13383 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
13384 * @cfg {string} html text
13387 * Create a new TextArea
13388 * @param {Object} config The config object
13391 Roo.bootstrap.form.TextArea = function(config){
13392 Roo.bootstrap.form.TextArea.superclass.constructor.call(this, config);
13396 Roo.extend(Roo.bootstrap.form.TextArea, Roo.bootstrap.form.Input, {
13406 getAutoCreate : function(){
13408 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
13414 if(this.inputType != 'hidden'){
13415 cfg.cls = 'form-group' //input-group
13423 value : this.value || '',
13424 html: this.html || '',
13425 cls : 'form-control',
13426 placeholder : this.placeholder || ''
13430 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
13431 input.maxLength = this.maxLength;
13435 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
13439 input.cols = this.cols;
13442 if (this.readOnly) {
13443 input.readonly = true;
13447 input.name = this.name;
13451 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
13455 ['xs','sm','md','lg'].map(function(size){
13456 if (settings[size]) {
13457 cfg.cls += ' col-' + size + '-' + settings[size];
13461 var inputblock = input;
13463 if(this.hasFeedback && !this.allowBlank){
13467 cls: 'glyphicon form-control-feedback'
13471 cls : 'has-feedback',
13480 if (this.before || this.after) {
13483 cls : 'input-group',
13487 inputblock.cn.push({
13489 cls : 'input-group-addon',
13494 inputblock.cn.push(input);
13496 if(this.hasFeedback && !this.allowBlank){
13497 inputblock.cls += ' has-feedback';
13498 inputblock.cn.push(feedback);
13502 inputblock.cn.push({
13504 cls : 'input-group-addon',
13511 if (align ==='left' && this.fieldLabel.length) {
13516 cls : 'control-label',
13517 html : this.fieldLabel
13528 if(this.labelWidth > 12){
13529 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
13532 if(this.labelWidth < 13 && this.labelmd == 0){
13533 this.labelmd = this.labelWidth;
13536 if(this.labellg > 0){
13537 cfg.cn[0].cls += ' col-lg-' + this.labellg;
13538 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
13541 if(this.labelmd > 0){
13542 cfg.cn[0].cls += ' col-md-' + this.labelmd;
13543 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
13546 if(this.labelsm > 0){
13547 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
13548 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
13551 if(this.labelxs > 0){
13552 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
13553 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
13556 } else if ( this.fieldLabel.length) {
13561 //cls : 'input-group-addon',
13562 html : this.fieldLabel
13580 if (this.disabled) {
13581 input.disabled=true;
13588 * return the real textarea element.
13590 inputEl: function ()
13592 return this.el.select('textarea.form-control',true).first();
13596 * Clear any invalid styles/messages for this field
13598 clearInvalid : function()
13601 if(!this.el || this.preventMark){ // not rendered
13605 var label = this.el.select('label', true).first();
13606 var icon = this.el.select('i.fa-star', true).first();
13611 this.el.removeClass( this.validClass);
13612 this.inputEl().removeClass('is-invalid');
13614 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13616 var feedback = this.el.select('.form-control-feedback', true).first();
13619 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
13624 this.fireEvent('valid', this);
13628 * Mark this field as valid
13630 markValid : function()
13632 if(!this.el || this.preventMark){ // not rendered
13636 this.el.removeClass([this.invalidClass, this.validClass]);
13637 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13639 var feedback = this.el.select('.form-control-feedback', true).first();
13642 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13645 if(this.disabled || this.allowBlank){
13649 var label = this.el.select('label', true).first();
13650 var icon = this.el.select('i.fa-star', true).first();
13655 if (Roo.bootstrap.version == 3) {
13656 this.el.addClass(this.validClass);
13658 this.inputEl().addClass('is-valid');
13662 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
13664 var feedback = this.el.select('.form-control-feedback', true).first();
13667 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13668 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
13673 this.fireEvent('valid', this);
13677 * Mark this field as invalid
13678 * @param {String} msg The validation message
13680 markInvalid : function(msg)
13682 if(!this.el || this.preventMark){ // not rendered
13686 this.el.removeClass([this.invalidClass, this.validClass]);
13687 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13689 var feedback = this.el.select('.form-control-feedback', true).first();
13692 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13695 if(this.disabled || this.allowBlank){
13699 var label = this.el.select('label', true).first();
13700 var icon = this.el.select('i.fa-star', true).first();
13702 if(!this.getValue().length && label && !icon){
13703 this.el.createChild({
13705 cls : 'text-danger fa fa-lg fa-star',
13706 tooltip : 'This field is required',
13707 style : 'margin-right:5px;'
13711 if (Roo.bootstrap.version == 3) {
13712 this.el.addClass(this.invalidClass);
13714 this.inputEl().addClass('is-invalid');
13717 // fixme ... this may be depricated need to test..
13718 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13720 var feedback = this.el.select('.form-control-feedback', true).first();
13723 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13725 if(this.getValue().length || this.forceFeedback){
13726 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
13733 this.fireEvent('invalid', this, msg);
13741 * trigger field - base class for combo..
13746 * @class Roo.bootstrap.form.TriggerField
13747 * @extends Roo.bootstrap.form.Input
13748 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
13749 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
13750 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
13751 * for which you can provide a custom implementation. For example:
13753 var trigger = new Roo.bootstrap.form.TriggerField();
13754 trigger.onTriggerClick = myTriggerFn;
13755 trigger.applyTo('my-field');
13758 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
13759 * {@link Roo.bootstrap.form.DateField} and {@link Roo.bootstrap.form.ComboBox} are perfect examples of this.
13760 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
13761 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
13762 * @cfg {String} caret (search|calendar) BS3 only - carat fa name
13765 * Create a new TriggerField.
13766 * @param {Object} config Configuration options (valid {@Roo.bootstrap.form.Input} config options will also be applied
13767 * to the base TextField)
13769 Roo.bootstrap.form.TriggerField = function(config){
13770 this.mimicing = false;
13771 Roo.bootstrap.form.TriggerField.superclass.constructor.call(this, config);
13774 Roo.extend(Roo.bootstrap.form.TriggerField, Roo.bootstrap.form.Input, {
13776 * @cfg {String} triggerClass A CSS class to apply to the trigger
13779 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
13784 * @cfg {Boolean} removable (true|false) special filter default false
13788 /** @cfg {Boolean} grow @hide */
13789 /** @cfg {Number} growMin @hide */
13790 /** @cfg {Number} growMax @hide */
13796 autoSize: Roo.emptyFn,
13800 deferHeight : true,
13803 actionMode : 'wrap',
13808 getAutoCreate : function(){
13810 var align = this.labelAlign || this.parentLabelAlign();
13815 cls: 'form-group' //input-group
13822 type : this.inputType,
13823 cls : 'form-control',
13824 autocomplete: 'new-password',
13825 placeholder : this.placeholder || ''
13829 input.name = this.name;
13832 input.cls += ' input-' + this.size;
13835 if (this.disabled) {
13836 input.disabled=true;
13839 var inputblock = input;
13841 if(this.hasFeedback && !this.allowBlank){
13845 cls: 'glyphicon form-control-feedback'
13848 if(this.removable && !this.editable ){
13850 cls : 'has-feedback',
13856 cls : 'roo-combo-removable-btn close'
13863 cls : 'has-feedback',
13872 if(this.removable && !this.editable ){
13874 cls : 'roo-removable',
13880 cls : 'roo-combo-removable-btn close'
13887 if (this.before || this.after) {
13890 cls : 'input-group',
13894 inputblock.cn.push({
13896 cls : 'input-group-addon input-group-prepend input-group-text',
13901 inputblock.cn.push(input);
13903 if(this.hasFeedback && !this.allowBlank){
13904 inputblock.cls += ' has-feedback';
13905 inputblock.cn.push(feedback);
13909 inputblock.cn.push({
13911 cls : 'input-group-addon input-group-append input-group-text',
13920 var ibwrap = inputblock;
13925 cls: 'roo-select2-choices',
13929 cls: 'roo-select2-search-field',
13941 cls: 'roo-select2-container input-group',
13946 cls: 'form-hidden-field'
13952 if(!this.multiple && this.showToggleBtn){
13958 if (this.caret != false) {
13961 cls: 'fa fa-' + this.caret
13968 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
13970 Roo.bootstrap.version == 3 ? caret : '',
13973 cls: 'combobox-clear',
13987 combobox.cls += ' roo-select2-container-multi';
13991 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
13992 tooltip : 'This field is required'
13994 if (Roo.bootstrap.version == 4) {
13997 style : 'display:none'
14002 if (align ==='left' && this.fieldLabel.length) {
14004 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
14011 cls : 'control-label',
14012 html : this.fieldLabel
14024 var labelCfg = cfg.cn[1];
14025 var contentCfg = cfg.cn[2];
14027 if(this.indicatorpos == 'right'){
14032 cls : 'control-label',
14036 html : this.fieldLabel
14050 labelCfg = cfg.cn[0];
14051 contentCfg = cfg.cn[1];
14054 if(this.labelWidth > 12){
14055 labelCfg.style = "width: " + this.labelWidth + 'px';
14058 if(this.labelWidth < 13 && this.labelmd == 0){
14059 this.labelmd = this.labelWidth;
14062 if(this.labellg > 0){
14063 labelCfg.cls += ' col-lg-' + this.labellg;
14064 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
14067 if(this.labelmd > 0){
14068 labelCfg.cls += ' col-md-' + this.labelmd;
14069 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
14072 if(this.labelsm > 0){
14073 labelCfg.cls += ' col-sm-' + this.labelsm;
14074 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
14077 if(this.labelxs > 0){
14078 labelCfg.cls += ' col-xs-' + this.labelxs;
14079 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
14082 } else if ( this.fieldLabel.length) {
14083 // Roo.log(" label");
14088 //cls : 'input-group-addon',
14089 html : this.fieldLabel
14097 if(this.indicatorpos == 'right'){
14105 html : this.fieldLabel
14119 // Roo.log(" no label && no align");
14126 ['xs','sm','md','lg'].map(function(size){
14127 if (settings[size]) {
14128 cfg.cls += ' col-' + size + '-' + settings[size];
14139 onResize : function(w, h){
14140 // Roo.bootstrap.form.TriggerField.superclass.onResize.apply(this, arguments);
14141 // if(typeof w == 'number'){
14142 // var x = w - this.trigger.getWidth();
14143 // this.inputEl().setWidth(this.adjustWidth('input', x));
14144 // this.trigger.setStyle('left', x+'px');
14149 adjustSize : Roo.BoxComponent.prototype.adjustSize,
14152 getResizeEl : function(){
14153 return this.inputEl();
14157 getPositionEl : function(){
14158 return this.inputEl();
14162 alignErrorIcon : function(){
14163 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
14167 initEvents : function(){
14171 Roo.bootstrap.form.TriggerField.superclass.initEvents.call(this);
14172 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
14173 if(!this.multiple && this.showToggleBtn){
14174 this.trigger = this.el.select('span.dropdown-toggle',true).first();
14175 if(this.hideTrigger){
14176 this.trigger.setDisplayed(false);
14178 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
14182 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
14185 if(this.removable && !this.editable && !this.tickable){
14186 var close = this.closeTriggerEl();
14189 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
14190 close.on('click', this.removeBtnClick, this, close);
14194 //this.trigger.addClassOnOver('x-form-trigger-over');
14195 //this.trigger.addClassOnClick('x-form-trigger-click');
14198 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
14202 closeTriggerEl : function()
14204 var close = this.el.select('.roo-combo-removable-btn', true).first();
14205 return close ? close : false;
14208 removeBtnClick : function(e, h, el)
14210 e.preventDefault();
14212 if(this.fireEvent("remove", this) !== false){
14214 this.fireEvent("afterremove", this)
14218 createList : function()
14220 this.list = Roo.get(document.body).createChild({
14221 tag: Roo.bootstrap.version == 4 ? 'div' : 'ul',
14222 cls: 'typeahead typeahead-long dropdown-menu shadow',
14223 style: 'display:none'
14226 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
14231 initTrigger : function(){
14236 onDestroy : function(){
14238 this.trigger.removeAllListeners();
14239 // this.trigger.remove();
14242 // this.wrap.remove();
14244 Roo.bootstrap.form.TriggerField.superclass.onDestroy.call(this);
14248 onFocus : function(){
14249 Roo.bootstrap.form.TriggerField.superclass.onFocus.call(this);
14251 if(!this.mimicing){
14252 this.wrap.addClass('x-trigger-wrap-focus');
14253 this.mimicing = true;
14254 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
14255 if(this.monitorTab){
14256 this.el.on("keydown", this.checkTab, this);
14263 checkTab : function(e){
14264 if(e.getKey() == e.TAB){
14265 this.triggerBlur();
14270 onBlur : function(){
14275 mimicBlur : function(e, t){
14277 if(!this.wrap.contains(t) && this.validateBlur()){
14278 this.triggerBlur();
14284 triggerBlur : function(){
14285 this.mimicing = false;
14286 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
14287 if(this.monitorTab){
14288 this.el.un("keydown", this.checkTab, this);
14290 //this.wrap.removeClass('x-trigger-wrap-focus');
14291 Roo.bootstrap.form.TriggerField.superclass.onBlur.call(this);
14295 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
14296 validateBlur : function(e, t){
14301 onDisable : function(){
14302 this.inputEl().dom.disabled = true;
14303 //Roo.bootstrap.form.TriggerField.superclass.onDisable.call(this);
14305 // this.wrap.addClass('x-item-disabled');
14310 onEnable : function(){
14311 this.inputEl().dom.disabled = false;
14312 //Roo.bootstrap.form.TriggerField.superclass.onEnable.call(this);
14314 // this.el.removeClass('x-item-disabled');
14319 onShow : function(){
14320 var ae = this.getActionEl();
14323 ae.dom.style.display = '';
14324 ae.dom.style.visibility = 'visible';
14330 onHide : function(){
14331 var ae = this.getActionEl();
14332 ae.dom.style.display = 'none';
14336 * The function that should handle the trigger's click event. This method does nothing by default until overridden
14337 * by an implementing function.
14339 * @param {EventObject} e
14341 onTriggerClick : Roo.emptyFn
14349 * @class Roo.bootstrap.form.CardUploader
14350 * @extends Roo.bootstrap.Button
14351 * Bootstrap Card Uploader class - it's a button which when you add files to it, adds cards below with preview and the name...
14352 * @cfg {Number} errorTimeout default 3000
14353 * @cfg {Array} images an array of ?? Img objects ??? when loading existing files..
14354 * @cfg {Array} html The button text.
14358 * Create a new CardUploader
14359 * @param {Object} config The config object
14362 Roo.bootstrap.form.CardUploader = function(config){
14366 Roo.bootstrap.form.CardUploader.superclass.constructor.call(this, config);
14369 this.fileCollection = new Roo.util.MixedCollection(false,function(r) {
14377 * When a image is clicked on - and needs to display a slideshow or similar..
14378 * @param {Roo.bootstrap.Card} this
14379 * @param {Object} The image information data
14385 * When a the download link is clicked
14386 * @param {Roo.bootstrap.Card} this
14387 * @param {Object} The image information data contains
14394 Roo.extend(Roo.bootstrap.form.CardUploader, Roo.bootstrap.form.Input, {
14397 errorTimeout : 3000,
14401 fileCollection : false,
14404 getAutoCreate : function()
14408 cls :'form-group' ,
14413 //cls : 'input-group-addon',
14414 html : this.fieldLabel
14422 value : this.value,
14423 cls : 'd-none form-control'
14428 multiple : 'multiple',
14430 cls : 'd-none roo-card-upload-selector'
14434 cls : 'roo-card-uploader-button-container w-100 mb-2'
14437 cls : 'card-columns roo-card-uploader-container'
14447 getChildContainer : function() /// what children are added to.
14449 return this.containerEl;
14452 getButtonContainer : function() /// what children are added to.
14454 return this.el.select(".roo-card-uploader-button-container").first();
14457 initEvents : function()
14460 Roo.bootstrap.form.Input.prototype.initEvents.call(this);
14464 xns: Roo.bootstrap,
14467 container_method : 'getButtonContainer' ,
14468 html : this.html, // fix changable?
14471 'click' : function(btn, e) {
14480 this.urlAPI = (window.createObjectURL && window) ||
14481 (window.URL && URL.revokeObjectURL && URL) ||
14482 (window.webkitURL && webkitURL);
14487 this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
14489 this.selectorEl.on('change', this.onFileSelected, this);
14492 this.images.forEach(function(img) {
14495 this.images = false;
14497 this.containerEl = this.el.select('.roo-card-uploader-container', true).first();
14503 onClick : function(e)
14505 e.preventDefault();
14507 this.selectorEl.dom.click();
14511 onFileSelected : function(e)
14513 e.preventDefault();
14515 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
14519 Roo.each(this.selectorEl.dom.files, function(file){
14520 this.addFile(file);
14529 addFile : function(file)
14532 if(typeof(file) === 'string'){
14533 throw "Add file by name?"; // should not happen
14537 if(!file || !this.urlAPI){
14547 var url = _this.urlAPI.createObjectURL( file);
14550 id : Roo.bootstrap.form.CardUploader.ID--,
14551 is_uploaded : false,
14555 mimetype : file.type,
14563 * addCard - add an Attachment to the uploader
14564 * @param data - the data about the image to upload
14568 title : "Title of file",
14569 is_uploaded : false,
14570 src : "http://.....",
14571 srcfile : { the File upload object },
14572 mimetype : file.type,
14575 .. any other data...
14581 addCard : function (data)
14583 // hidden input element?
14584 // if the file is not an image...
14585 //then we need to use something other that and header_image
14590 xns : Roo.bootstrap,
14591 xtype : 'CardFooter',
14594 xns : Roo.bootstrap,
14600 xns : Roo.bootstrap,
14602 html : String.format("<small>{0}</small>", data.title),
14603 cls : 'col-10 text-left',
14608 click : function() {
14610 t.fireEvent( "download", t, data );
14616 xns : Roo.bootstrap,
14618 style: 'max-height: 28px; ',
14624 click : function() {
14625 t.removeCard(data.id)
14637 var cn = this.addxtype(
14640 xns : Roo.bootstrap,
14643 header : !data.mimetype.match(/image/) && !data.preview ? "Document": false,
14644 header_image : data.mimetype.match(/image/) ? data.src : data.preview,
14645 header_image_fit_square: true, // fixme - we probably need to use the 'Img' element to do stuff like this.
14650 initEvents : function() {
14651 Roo.bootstrap.Card.prototype.initEvents.call(this);
14653 this.imgEl = this.el.select('.card-img-top').first();
14655 this.imgEl.on('click', function() { t.fireEvent( "preview", t, data ); }, this);
14656 this.imgEl.set({ 'pointer' : 'cursor' });
14659 this.getCardFooter().addClass('p-1');
14666 // dont' really need ot update items.
14667 // this.items.push(cn);
14668 this.fileCollection.add(cn);
14670 if (!data.srcfile) {
14671 this.updateInput();
14676 var reader = new FileReader();
14677 reader.addEventListener("load", function() {
14678 data.srcdata = reader.result;
14681 reader.readAsDataURL(data.srcfile);
14686 removeCard : function(id)
14689 var card = this.fileCollection.get(id);
14690 card.data.is_deleted = 1;
14691 card.data.src = ''; /// delete the source - so it reduces size of not uploaded images etc.
14692 //this.fileCollection.remove(card);
14693 //this.items = this.items.filter(function(e) { return e != card });
14694 // dont' really need ot update items.
14695 card.el.dom.parentNode.removeChild(card.el.dom);
14696 this.updateInput();
14702 this.fileCollection.each(function(card) {
14703 if (card.el.dom && card.el.dom.parentNode) {
14704 card.el.dom.parentNode.removeChild(card.el.dom);
14707 this.fileCollection.clear();
14708 this.updateInput();
14711 updateInput : function()
14714 this.fileCollection.each(function(e) {
14718 this.inputEl().dom.value = JSON.stringify(data);
14728 Roo.bootstrap.form.CardUploader.ID = -1;/*
14730 * Ext JS Library 1.1.1
14731 * Copyright(c) 2006-2007, Ext JS, LLC.
14733 * Originally Released Under LGPL - original licence link has changed is not relivant.
14736 * <script type="text/javascript">
14741 * @class Roo.data.SortTypes
14743 * Defines the default sorting (casting?) comparison functions used when sorting data.
14745 Roo.data.SortTypes = {
14747 * Default sort that does nothing
14748 * @param {Mixed} s The value being converted
14749 * @return {Mixed} The comparison value
14751 none : function(s){
14756 * The regular expression used to strip tags
14760 stripTagsRE : /<\/?[^>]+>/gi,
14763 * Strips all HTML tags to sort on text only
14764 * @param {Mixed} s The value being converted
14765 * @return {String} The comparison value
14767 asText : function(s){
14768 return String(s).replace(this.stripTagsRE, "");
14772 * Strips all HTML tags to sort on text only - Case insensitive
14773 * @param {Mixed} s The value being converted
14774 * @return {String} The comparison value
14776 asUCText : function(s){
14777 return String(s).toUpperCase().replace(this.stripTagsRE, "");
14781 * Case insensitive string
14782 * @param {Mixed} s The value being converted
14783 * @return {String} The comparison value
14785 asUCString : function(s) {
14786 return String(s).toUpperCase();
14791 * @param {Mixed} s The value being converted
14792 * @return {Number} The comparison value
14794 asDate : function(s) {
14798 if(s instanceof Date){
14799 return s.getTime();
14801 return Date.parse(String(s));
14806 * @param {Mixed} s The value being converted
14807 * @return {Float} The comparison value
14809 asFloat : function(s) {
14810 var val = parseFloat(String(s).replace(/,/g, ""));
14819 * @param {Mixed} s The value being converted
14820 * @return {Number} The comparison value
14822 asInt : function(s) {
14823 var val = parseInt(String(s).replace(/,/g, ""));
14831 * Ext JS Library 1.1.1
14832 * Copyright(c) 2006-2007, Ext JS, LLC.
14834 * Originally Released Under LGPL - original licence link has changed is not relivant.
14837 * <script type="text/javascript">
14841 * @class Roo.data.Record
14842 * Instances of this class encapsulate both record <em>definition</em> information, and record
14843 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
14844 * to access Records cached in an {@link Roo.data.Store} object.<br>
14846 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
14847 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
14850 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
14852 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
14853 * {@link #create}. The parameters are the same.
14854 * @param {Array} data An associative Array of data values keyed by the field name.
14855 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
14856 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
14857 * not specified an integer id is generated.
14859 Roo.data.Record = function(data, id){
14860 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
14865 * Generate a constructor for a specific record layout.
14866 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
14867 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
14868 * Each field definition object may contain the following properties: <ul>
14869 * <li><b>name</b> : String<p style="margin-left:1em">The name by which the field is referenced within the Record. This is referenced by,
14870 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
14871 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
14872 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
14873 * is being used, then this is a string containing the javascript expression to reference the data relative to
14874 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
14875 * to the data item relative to the record element. If the mapping expression is the same as the field name,
14876 * this may be omitted.</p></li>
14877 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
14878 * <ul><li>auto (Default, implies no conversion)</li>
14883 * <li>date</li></ul></p></li>
14884 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
14885 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
14886 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
14887 * by the Reader into an object that will be stored in the Record. It is passed the
14888 * following parameters:<ul>
14889 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
14891 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
14893 * <br>usage:<br><pre><code>
14894 var TopicRecord = Roo.data.Record.create(
14895 {name: 'title', mapping: 'topic_title'},
14896 {name: 'author', mapping: 'username'},
14897 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
14898 {name: 'lastPost', mapping: 'post_time', type: 'date'},
14899 {name: 'lastPoster', mapping: 'user2'},
14900 {name: 'excerpt', mapping: 'post_text'}
14903 var myNewRecord = new TopicRecord({
14904 title: 'Do my job please',
14907 lastPost: new Date(),
14908 lastPoster: 'Animal',
14909 excerpt: 'No way dude!'
14911 myStore.add(myNewRecord);
14916 Roo.data.Record.create = function(o){
14917 var f = function(){
14918 f.superclass.constructor.apply(this, arguments);
14920 Roo.extend(f, Roo.data.Record);
14921 var p = f.prototype;
14922 p.fields = new Roo.util.MixedCollection(false, function(field){
14925 for(var i = 0, len = o.length; i < len; i++){
14926 p.fields.add(new Roo.data.Field(o[i]));
14928 f.getField = function(name){
14929 return p.fields.get(name);
14934 Roo.data.Record.AUTO_ID = 1000;
14935 Roo.data.Record.EDIT = 'edit';
14936 Roo.data.Record.REJECT = 'reject';
14937 Roo.data.Record.COMMIT = 'commit';
14939 Roo.data.Record.prototype = {
14941 * Readonly flag - true if this record has been modified.
14950 join : function(store){
14951 this.store = store;
14955 * Set the named field to the specified value.
14956 * @param {String} name The name of the field to set.
14957 * @param {Object} value The value to set the field to.
14959 set : function(name, value){
14960 if(this.data[name] == value){
14964 if(!this.modified){
14965 this.modified = {};
14967 if(typeof this.modified[name] == 'undefined'){
14968 this.modified[name] = this.data[name];
14970 this.data[name] = value;
14971 if(!this.editing && this.store){
14972 this.store.afterEdit(this);
14977 * Get the value of the named field.
14978 * @param {String} name The name of the field to get the value of.
14979 * @return {Object} The value of the field.
14981 get : function(name){
14982 return this.data[name];
14986 beginEdit : function(){
14987 this.editing = true;
14988 this.modified = {};
14992 cancelEdit : function(){
14993 this.editing = false;
14994 delete this.modified;
14998 endEdit : function(){
14999 this.editing = false;
15000 if(this.dirty && this.store){
15001 this.store.afterEdit(this);
15006 * Usually called by the {@link Roo.data.Store} which owns the Record.
15007 * Rejects all changes made to the Record since either creation, or the last commit operation.
15008 * Modified fields are reverted to their original values.
15010 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
15011 * of reject operations.
15013 reject : function(){
15014 var m = this.modified;
15016 if(typeof m[n] != "function"){
15017 this.data[n] = m[n];
15020 this.dirty = false;
15021 delete this.modified;
15022 this.editing = false;
15024 this.store.afterReject(this);
15029 * Usually called by the {@link Roo.data.Store} which owns the Record.
15030 * Commits all changes made to the Record since either creation, or the last commit operation.
15032 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
15033 * of commit operations.
15035 commit : function(){
15036 this.dirty = false;
15037 delete this.modified;
15038 this.editing = false;
15040 this.store.afterCommit(this);
15045 hasError : function(){
15046 return this.error != null;
15050 clearError : function(){
15055 * Creates a copy of this record.
15056 * @param {String} id (optional) A new record id if you don't want to use this record's id
15059 copy : function(newId) {
15060 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
15064 * Ext JS Library 1.1.1
15065 * Copyright(c) 2006-2007, Ext JS, LLC.
15067 * Originally Released Under LGPL - original licence link has changed is not relivant.
15070 * <script type="text/javascript">
15076 * @class Roo.data.Store
15077 * @extends Roo.util.Observable
15078 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
15079 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
15081 * A Store object uses an implementation of {@link Roo.data.DataProxy} to access a data object unless you call loadData() directly and pass in your data. The Store object
15082 * has no knowledge of the format of the data returned by the Proxy.<br>
15084 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
15085 * instances from the data object. These records are cached and made available through accessor functions.
15087 * Creates a new Store.
15088 * @param {Object} config A config object containing the objects needed for the Store to access data,
15089 * and read the data into Records.
15091 Roo.data.Store = function(config){
15092 this.data = new Roo.util.MixedCollection(false);
15093 this.data.getKey = function(o){
15096 this.baseParams = {};
15098 this.paramNames = {
15103 "multisort" : "_multisort"
15106 if(config && config.data){
15107 this.inlineData = config.data;
15108 delete config.data;
15111 Roo.apply(this, config);
15113 if(this.reader){ // reader passed
15114 this.reader = Roo.factory(this.reader, Roo.data);
15115 this.reader.xmodule = this.xmodule || false;
15116 if(!this.recordType){
15117 this.recordType = this.reader.recordType;
15119 if(this.reader.onMetaChange){
15120 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
15124 if(this.recordType){
15125 this.fields = this.recordType.prototype.fields;
15127 this.modified = [];
15131 * @event datachanged
15132 * Fires when the data cache has changed, and a widget which is using this Store
15133 * as a Record cache should refresh its view.
15134 * @param {Store} this
15136 datachanged : true,
15138 * @event metachange
15139 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
15140 * @param {Store} this
15141 * @param {Object} meta The JSON metadata
15146 * Fires when Records have been added to the Store
15147 * @param {Store} this
15148 * @param {Roo.data.Record[]} records The array of Records added
15149 * @param {Number} index The index at which the record(s) were added
15154 * Fires when a Record has been removed from the Store
15155 * @param {Store} this
15156 * @param {Roo.data.Record} record The Record that was removed
15157 * @param {Number} index The index at which the record was removed
15162 * Fires when a Record has been updated
15163 * @param {Store} this
15164 * @param {Roo.data.Record} record The Record that was updated
15165 * @param {String} operation The update operation being performed. Value may be one of:
15167 Roo.data.Record.EDIT
15168 Roo.data.Record.REJECT
15169 Roo.data.Record.COMMIT
15175 * Fires when the data cache has been cleared.
15176 * @param {Store} this
15180 * @event beforeload
15181 * Fires before a request is made for a new data object. If the beforeload handler returns false
15182 * the load action will be canceled.
15183 * @param {Store} this
15184 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15188 * @event beforeloadadd
15189 * Fires after a new set of Records has been loaded.
15190 * @param {Store} this
15191 * @param {Roo.data.Record[]} records The Records that were loaded
15192 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15194 beforeloadadd : true,
15197 * Fires after a new set of Records has been loaded, before they are added to the store.
15198 * @param {Store} this
15199 * @param {Roo.data.Record[]} records The Records that were loaded
15200 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15201 * @params {Object} return from reader
15205 * @event loadexception
15206 * Fires if an exception occurs in the Proxy during loading.
15207 * Called with the signature of the Proxy's "loadexception" event.
15208 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
15211 * @param {Object} return from JsonData.reader() - success, totalRecords, records
15212 * @param {Object} load options
15213 * @param {Object} jsonData from your request (normally this contains the Exception)
15215 loadexception : true
15219 this.proxy = Roo.factory(this.proxy, Roo.data);
15220 this.proxy.xmodule = this.xmodule || false;
15221 this.relayEvents(this.proxy, ["loadexception"]);
15223 this.sortToggle = {};
15224 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
15226 Roo.data.Store.superclass.constructor.call(this);
15228 if(this.inlineData){
15229 this.loadData(this.inlineData);
15230 delete this.inlineData;
15234 Roo.extend(Roo.data.Store, Roo.util.Observable, {
15236 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
15237 * without a remote query - used by combo/forms at present.
15241 * @cfg {Roo.data.DataProxy} proxy [required] The Proxy object which provides access to a data object.
15244 * @cfg {Array} data Inline data to be loaded when the store is initialized.
15247 * @cfg {Roo.data.DataReader} reader [required] The Reader object which processes the data object and returns
15248 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
15251 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
15252 * on any HTTP request
15255 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
15258 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
15262 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
15263 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
15265 remoteSort : false,
15268 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
15269 * loaded or when a record is removed. (defaults to false).
15271 pruneModifiedRecords : false,
15274 lastOptions : null,
15277 * Add Records to the Store and fires the add event.
15278 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
15280 add : function(records){
15281 records = [].concat(records);
15282 for(var i = 0, len = records.length; i < len; i++){
15283 records[i].join(this);
15285 var index = this.data.length;
15286 this.data.addAll(records);
15287 this.fireEvent("add", this, records, index);
15291 * Remove a Record from the Store and fires the remove event.
15292 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
15294 remove : function(record){
15295 var index = this.data.indexOf(record);
15296 this.data.removeAt(index);
15298 if(this.pruneModifiedRecords){
15299 this.modified.remove(record);
15301 this.fireEvent("remove", this, record, index);
15305 * Remove all Records from the Store and fires the clear event.
15307 removeAll : function(){
15309 if(this.pruneModifiedRecords){
15310 this.modified = [];
15312 this.fireEvent("clear", this);
15316 * Inserts Records to the Store at the given index and fires the add event.
15317 * @param {Number} index The start index at which to insert the passed Records.
15318 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
15320 insert : function(index, records){
15321 records = [].concat(records);
15322 for(var i = 0, len = records.length; i < len; i++){
15323 this.data.insert(index, records[i]);
15324 records[i].join(this);
15326 this.fireEvent("add", this, records, index);
15330 * Get the index within the cache of the passed Record.
15331 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
15332 * @return {Number} The index of the passed Record. Returns -1 if not found.
15334 indexOf : function(record){
15335 return this.data.indexOf(record);
15339 * Get the index within the cache of the Record with the passed id.
15340 * @param {String} id The id of the Record to find.
15341 * @return {Number} The index of the Record. Returns -1 if not found.
15343 indexOfId : function(id){
15344 return this.data.indexOfKey(id);
15348 * Get the Record with the specified id.
15349 * @param {String} id The id of the Record to find.
15350 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
15352 getById : function(id){
15353 return this.data.key(id);
15357 * Get the Record at the specified index.
15358 * @param {Number} index The index of the Record to find.
15359 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
15361 getAt : function(index){
15362 return this.data.itemAt(index);
15366 * Returns a range of Records between specified indices.
15367 * @param {Number} startIndex (optional) The starting index (defaults to 0)
15368 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
15369 * @return {Roo.data.Record[]} An array of Records
15371 getRange : function(start, end){
15372 return this.data.getRange(start, end);
15376 storeOptions : function(o){
15377 o = Roo.apply({}, o);
15380 this.lastOptions = o;
15384 * Loads the Record cache from the configured Proxy using the configured Reader.
15386 * If using remote paging, then the first load call must specify the <em>start</em>
15387 * and <em>limit</em> properties in the options.params property to establish the initial
15388 * position within the dataset, and the number of Records to cache on each read from the Proxy.
15390 * <strong>It is important to note that for remote data sources, loading is asynchronous,
15391 * and this call will return before the new data has been loaded. Perform any post-processing
15392 * in a callback function, or in a "load" event handler.</strong>
15394 * @param {Object} options An object containing properties which control loading options:<ul>
15395 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
15396 * <li>params.data {Object} if you are using a MemoryProxy / JsonReader, use this as the data to load stuff..
15399 data : data, // array of key=>value data like JsonReader
15400 total : data.length,
15406 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
15407 * passed the following arguments:<ul>
15408 * <li>r : Roo.data.Record[]</li>
15409 * <li>options: Options object from the load call</li>
15410 * <li>success: Boolean success indicator</li></ul></li>
15411 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
15412 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
15415 load : function(options){
15416 options = options || {};
15417 if(this.fireEvent("beforeload", this, options) !== false){
15418 this.storeOptions(options);
15419 var p = Roo.apply(options.params || {}, this.baseParams);
15420 // if meta was not loaded from remote source.. try requesting it.
15421 if (!this.reader.metaFromRemote) {
15422 p._requestMeta = 1;
15424 if(this.sortInfo && this.remoteSort){
15425 var pn = this.paramNames;
15426 p[pn["sort"]] = this.sortInfo.field;
15427 p[pn["dir"]] = this.sortInfo.direction;
15429 if (this.multiSort) {
15430 var pn = this.paramNames;
15431 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
15434 this.proxy.load(p, this.reader, this.loadRecords, this, options);
15439 * Reloads the Record cache from the configured Proxy using the configured Reader and
15440 * the options from the last load operation performed.
15441 * @param {Object} options (optional) An object containing properties which may override the options
15442 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
15443 * the most recently used options are reused).
15445 reload : function(options){
15446 this.load(Roo.applyIf(options||{}, this.lastOptions));
15450 // Called as a callback by the Reader during a load operation.
15451 loadRecords : function(o, options, success){
15454 if(success !== false){
15455 this.fireEvent("load", this, [], options, o);
15457 if(options.callback){
15458 options.callback.call(options.scope || this, [], options, false);
15462 // if data returned failure - throw an exception.
15463 if (o.success === false) {
15464 // show a message if no listener is registered.
15465 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
15466 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
15468 // loadmask wil be hooked into this..
15469 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
15472 var r = o.records, t = o.totalRecords || r.length;
15474 this.fireEvent("beforeloadadd", this, r, options, o);
15476 if(!options || options.add !== true){
15477 if(this.pruneModifiedRecords){
15478 this.modified = [];
15480 for(var i = 0, len = r.length; i < len; i++){
15484 this.data = this.snapshot;
15485 delete this.snapshot;
15488 this.data.addAll(r);
15489 this.totalLength = t;
15491 this.fireEvent("datachanged", this);
15493 this.totalLength = Math.max(t, this.data.length+r.length);
15497 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
15499 var e = new Roo.data.Record({});
15501 e.set(this.parent.displayField, this.parent.emptyTitle);
15502 e.set(this.parent.valueField, '');
15507 this.fireEvent("load", this, r, options, o);
15508 if(options.callback){
15509 options.callback.call(options.scope || this, r, options, true);
15515 * Loads data from a passed data block. A Reader which understands the format of the data
15516 * must have been configured in the constructor.
15517 * @param {Object} data The data block from which to read the Records. The format of the data expected
15518 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
15519 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
15521 loadData : function(o, append){
15522 var r = this.reader.readRecords(o);
15523 this.loadRecords(r, {add: append}, true);
15527 * using 'cn' the nested child reader read the child array into it's child stores.
15528 * @param {Object} rec The record with a 'children array
15530 loadDataFromChildren : function(rec)
15532 this.loadData(this.reader.toLoadData(rec));
15537 * Gets the number of cached records.
15539 * <em>If using paging, this may not be the total size of the dataset. If the data object
15540 * used by the Reader contains the dataset size, then the getTotalCount() function returns
15541 * the data set size</em>
15543 getCount : function(){
15544 return this.data.length || 0;
15548 * Gets the total number of records in the dataset as returned by the server.
15550 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
15551 * the dataset size</em>
15553 getTotalCount : function(){
15554 return this.totalLength || 0;
15558 * Returns the sort state of the Store as an object with two properties:
15560 field {String} The name of the field by which the Records are sorted
15561 direction {String} The sort order, "ASC" or "DESC"
15564 getSortState : function(){
15565 return this.sortInfo;
15569 applySort : function(){
15570 if(this.sortInfo && !this.remoteSort){
15571 var s = this.sortInfo, f = s.field;
15572 var st = this.fields.get(f).sortType;
15573 var fn = function(r1, r2){
15574 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
15575 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
15577 this.data.sort(s.direction, fn);
15578 if(this.snapshot && this.snapshot != this.data){
15579 this.snapshot.sort(s.direction, fn);
15585 * Sets the default sort column and order to be used by the next load operation.
15586 * @param {String} fieldName The name of the field to sort by.
15587 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
15589 setDefaultSort : function(field, dir){
15590 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
15594 * Sort the Records.
15595 * If remote sorting is used, the sort is performed on the server, and the cache is
15596 * reloaded. If local sorting is used, the cache is sorted internally.
15597 * @param {String} fieldName The name of the field to sort by.
15598 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
15600 sort : function(fieldName, dir){
15601 var f = this.fields.get(fieldName);
15603 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
15605 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
15606 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
15611 this.sortToggle[f.name] = dir;
15612 this.sortInfo = {field: f.name, direction: dir};
15613 if(!this.remoteSort){
15615 this.fireEvent("datachanged", this);
15617 this.load(this.lastOptions);
15622 * Calls the specified function for each of the Records in the cache.
15623 * @param {Function} fn The function to call. The Record is passed as the first parameter.
15624 * Returning <em>false</em> aborts and exits the iteration.
15625 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
15627 each : function(fn, scope){
15628 this.data.each(fn, scope);
15632 * Gets all records modified since the last commit. Modified records are persisted across load operations
15633 * (e.g., during paging).
15634 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
15636 getModifiedRecords : function(){
15637 return this.modified;
15641 createFilterFn : function(property, value, anyMatch){
15642 if(!value.exec){ // not a regex
15643 value = String(value);
15644 if(value.length == 0){
15647 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
15649 return function(r){
15650 return value.test(r.data[property]);
15655 * Sums the value of <i>property</i> for each record between start and end and returns the result.
15656 * @param {String} property A field on your records
15657 * @param {Number} start The record index to start at (defaults to 0)
15658 * @param {Number} end The last record index to include (defaults to length - 1)
15659 * @return {Number} The sum
15661 sum : function(property, start, end){
15662 var rs = this.data.items, v = 0;
15663 start = start || 0;
15664 end = (end || end === 0) ? end : rs.length-1;
15666 for(var i = start; i <= end; i++){
15667 v += (rs[i].data[property] || 0);
15673 * Filter the records by a specified property.
15674 * @param {String} field A field on your records
15675 * @param {String/RegExp} value Either a string that the field
15676 * should start with or a RegExp to test against the field
15677 * @param {Boolean} anyMatch True to match any part not just the beginning
15679 filter : function(property, value, anyMatch){
15680 var fn = this.createFilterFn(property, value, anyMatch);
15681 return fn ? this.filterBy(fn) : this.clearFilter();
15685 * Filter by a function. The specified function will be called with each
15686 * record in this data source. If the function returns true the record is included,
15687 * otherwise it is filtered.
15688 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
15689 * @param {Object} scope (optional) The scope of the function (defaults to this)
15691 filterBy : function(fn, scope){
15692 this.snapshot = this.snapshot || this.data;
15693 this.data = this.queryBy(fn, scope||this);
15694 this.fireEvent("datachanged", this);
15698 * Query the records by a specified property.
15699 * @param {String} field A field on your records
15700 * @param {String/RegExp} value Either a string that the field
15701 * should start with or a RegExp to test against the field
15702 * @param {Boolean} anyMatch True to match any part not just the beginning
15703 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
15705 query : function(property, value, anyMatch){
15706 var fn = this.createFilterFn(property, value, anyMatch);
15707 return fn ? this.queryBy(fn) : this.data.clone();
15711 * Query by a function. The specified function will be called with each
15712 * record in this data source. If the function returns true the record is included
15714 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
15715 * @param {Object} scope (optional) The scope of the function (defaults to this)
15716 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
15718 queryBy : function(fn, scope){
15719 var data = this.snapshot || this.data;
15720 return data.filterBy(fn, scope||this);
15724 * Collects unique values for a particular dataIndex from this store.
15725 * @param {String} dataIndex The property to collect
15726 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
15727 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
15728 * @return {Array} An array of the unique values
15730 collect : function(dataIndex, allowNull, bypassFilter){
15731 var d = (bypassFilter === true && this.snapshot) ?
15732 this.snapshot.items : this.data.items;
15733 var v, sv, r = [], l = {};
15734 for(var i = 0, len = d.length; i < len; i++){
15735 v = d[i].data[dataIndex];
15737 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
15746 * Revert to a view of the Record cache with no filtering applied.
15747 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
15749 clearFilter : function(suppressEvent){
15750 if(this.snapshot && this.snapshot != this.data){
15751 this.data = this.snapshot;
15752 delete this.snapshot;
15753 if(suppressEvent !== true){
15754 this.fireEvent("datachanged", this);
15760 afterEdit : function(record){
15761 if(this.modified.indexOf(record) == -1){
15762 this.modified.push(record);
15764 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
15768 afterReject : function(record){
15769 this.modified.remove(record);
15770 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
15774 afterCommit : function(record){
15775 this.modified.remove(record);
15776 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
15780 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
15781 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
15783 commitChanges : function(){
15784 var m = this.modified.slice(0);
15785 this.modified = [];
15786 for(var i = 0, len = m.length; i < len; i++){
15792 * Cancel outstanding changes on all changed records.
15794 rejectChanges : function(){
15795 var m = this.modified.slice(0);
15796 this.modified = [];
15797 for(var i = 0, len = m.length; i < len; i++){
15802 onMetaChange : function(meta, rtype, o){
15803 this.recordType = rtype;
15804 this.fields = rtype.prototype.fields;
15805 delete this.snapshot;
15806 this.sortInfo = meta.sortInfo || this.sortInfo;
15807 this.modified = [];
15808 this.fireEvent('metachange', this, this.reader.meta);
15811 moveIndex : function(data, type)
15813 var index = this.indexOf(data);
15815 var newIndex = index + type;
15819 this.insert(newIndex, data);
15824 * Ext JS Library 1.1.1
15825 * Copyright(c) 2006-2007, Ext JS, LLC.
15827 * Originally Released Under LGPL - original licence link has changed is not relivant.
15830 * <script type="text/javascript">
15834 * @class Roo.data.SimpleStore
15835 * @extends Roo.data.Store
15836 * Small helper class to make creating Stores from Array data easier.
15837 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
15838 * @cfg {Array} fields An array of field definition objects, or field name strings.
15839 * @cfg {Object} an existing reader (eg. copied from another store)
15840 * @cfg {Array} data The multi-dimensional array of data
15841 * @cfg {Roo.data.DataProxy} proxy [not-required]
15842 * @cfg {Roo.data.Reader} reader [not-required]
15844 * @param {Object} config
15846 Roo.data.SimpleStore = function(config)
15848 Roo.data.SimpleStore.superclass.constructor.call(this, {
15850 reader: typeof(config.reader) != 'undefined' ? config.reader : new Roo.data.ArrayReader({
15853 Roo.data.Record.create(config.fields)
15855 proxy : new Roo.data.MemoryProxy(config.data)
15859 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
15861 * Ext JS Library 1.1.1
15862 * Copyright(c) 2006-2007, Ext JS, LLC.
15864 * Originally Released Under LGPL - original licence link has changed is not relivant.
15867 * <script type="text/javascript">
15872 * @extends Roo.data.Store
15873 * @class Roo.data.JsonStore
15874 * Small helper class to make creating Stores for JSON data easier. <br/>
15876 var store = new Roo.data.JsonStore({
15877 url: 'get-images.php',
15879 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
15882 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
15883 * JsonReader and HttpProxy (unless inline data is provided).</b>
15884 * @cfg {Array} fields An array of field definition objects, or field name strings.
15886 * @param {Object} config
15888 Roo.data.JsonStore = function(c){
15889 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
15890 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
15891 reader: new Roo.data.JsonReader(c, c.fields)
15894 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
15896 * Ext JS Library 1.1.1
15897 * Copyright(c) 2006-2007, Ext JS, LLC.
15899 * Originally Released Under LGPL - original licence link has changed is not relivant.
15902 * <script type="text/javascript">
15906 Roo.data.Field = function(config){
15907 if(typeof config == "string"){
15908 config = {name: config};
15910 Roo.apply(this, config);
15913 this.type = "auto";
15916 var st = Roo.data.SortTypes;
15917 // named sortTypes are supported, here we look them up
15918 if(typeof this.sortType == "string"){
15919 this.sortType = st[this.sortType];
15922 // set default sortType for strings and dates
15923 if(!this.sortType){
15926 this.sortType = st.asUCString;
15929 this.sortType = st.asDate;
15932 this.sortType = st.none;
15937 var stripRe = /[\$,%]/g;
15939 // prebuilt conversion function for this field, instead of
15940 // switching every time we're reading a value
15942 var cv, dateFormat = this.dateFormat;
15947 cv = function(v){ return v; };
15950 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
15954 return v !== undefined && v !== null && v !== '' ?
15955 parseInt(String(v).replace(stripRe, ""), 10) : '';
15960 return v !== undefined && v !== null && v !== '' ?
15961 parseFloat(String(v).replace(stripRe, ""), 10) : '';
15966 cv = function(v){ return v === true || v === "true" || v == 1; };
15973 if(v instanceof Date){
15977 if(dateFormat == "timestamp"){
15978 return new Date(v*1000);
15980 return Date.parseDate(v, dateFormat);
15982 var parsed = Date.parse(v);
15983 return parsed ? new Date(parsed) : null;
15992 Roo.data.Field.prototype = {
16000 * Ext JS Library 1.1.1
16001 * Copyright(c) 2006-2007, Ext JS, LLC.
16003 * Originally Released Under LGPL - original licence link has changed is not relivant.
16006 * <script type="text/javascript">
16009 // Base class for reading structured data from a data source. This class is intended to be
16010 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
16013 * @class Roo.data.DataReader
16015 * Base class for reading structured data from a data source. This class is intended to be
16016 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
16019 Roo.data.DataReader = function(meta, recordType){
16023 this.recordType = recordType instanceof Array ?
16024 Roo.data.Record.create(recordType) : recordType;
16027 Roo.data.DataReader.prototype = {
16030 readerType : 'Data',
16032 * Create an empty record
16033 * @param {Object} data (optional) - overlay some values
16034 * @return {Roo.data.Record} record created.
16036 newRow : function(d) {
16038 this.recordType.prototype.fields.each(function(c) {
16040 case 'int' : da[c.name] = 0; break;
16041 case 'date' : da[c.name] = new Date(); break;
16042 case 'float' : da[c.name] = 0.0; break;
16043 case 'boolean' : da[c.name] = false; break;
16044 default : da[c.name] = ""; break;
16048 return new this.recordType(Roo.apply(da, d));
16054 * Ext JS Library 1.1.1
16055 * Copyright(c) 2006-2007, Ext JS, LLC.
16057 * Originally Released Under LGPL - original licence link has changed is not relivant.
16060 * <script type="text/javascript">
16064 * @class Roo.data.DataProxy
16065 * @extends Roo.util.Observable
16067 * This class is an abstract base class for implementations which provide retrieval of
16068 * unformatted data objects.<br>
16070 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
16071 * (of the appropriate type which knows how to parse the data object) to provide a block of
16072 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
16074 * Custom implementations must implement the load method as described in
16075 * {@link Roo.data.HttpProxy#load}.
16077 Roo.data.DataProxy = function(){
16080 * @event beforeload
16081 * Fires before a network request is made to retrieve a data object.
16082 * @param {Object} This DataProxy object.
16083 * @param {Object} params The params parameter to the load function.
16088 * Fires before the load method's callback is called.
16089 * @param {Object} This DataProxy object.
16090 * @param {Object} o The data object.
16091 * @param {Object} arg The callback argument object passed to the load function.
16095 * @event loadexception
16096 * Fires if an Exception occurs during data retrieval.
16097 * @param {Object} This DataProxy object.
16098 * @param {Object} o The data object.
16099 * @param {Object} arg The callback argument object passed to the load function.
16100 * @param {Object} e The Exception.
16102 loadexception : true
16104 Roo.data.DataProxy.superclass.constructor.call(this);
16107 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
16110 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
16114 * Ext JS Library 1.1.1
16115 * Copyright(c) 2006-2007, Ext JS, LLC.
16117 * Originally Released Under LGPL - original licence link has changed is not relivant.
16120 * <script type="text/javascript">
16123 * @class Roo.data.MemoryProxy
16124 * @extends Roo.data.DataProxy
16125 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
16126 * to the Reader when its load method is called.
16128 * @param {Object} config A config object containing the objects needed for the Store to access data,
16130 Roo.data.MemoryProxy = function(config){
16132 if (typeof(config) != 'undefined' && typeof(config.data) != 'undefined') {
16133 data = config.data;
16135 Roo.data.MemoryProxy.superclass.constructor.call(this);
16139 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
16142 * @cfg {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
16145 * Load data from the requested source (in this case an in-memory
16146 * data object passed to the constructor), read the data object into
16147 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
16148 * process that block using the passed callback.
16149 * @param {Object} params This parameter is not used by the MemoryProxy class.
16150 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16151 * object into a block of Roo.data.Records.
16152 * @param {Function} callback The function into which to pass the block of Roo.data.records.
16153 * The function must be passed <ul>
16154 * <li>The Record block object</li>
16155 * <li>The "arg" argument from the load function</li>
16156 * <li>A boolean success indicator</li>
16158 * @param {Object} scope The scope in which to call the callback
16159 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16161 load : function(params, reader, callback, scope, arg){
16162 params = params || {};
16165 result = reader.readRecords(params.data ? params.data :this.data);
16167 this.fireEvent("loadexception", this, arg, null, e);
16168 callback.call(scope, null, arg, false);
16171 callback.call(scope, result, arg, true);
16175 update : function(params, records){
16180 * Ext JS Library 1.1.1
16181 * Copyright(c) 2006-2007, Ext JS, LLC.
16183 * Originally Released Under LGPL - original licence link has changed is not relivant.
16186 * <script type="text/javascript">
16189 * @class Roo.data.HttpProxy
16190 * @extends Roo.data.DataProxy
16191 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
16192 * configured to reference a certain URL.<br><br>
16194 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
16195 * from which the running page was served.<br><br>
16197 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
16199 * Be aware that to enable the browser to parse an XML document, the server must set
16200 * the Content-Type header in the HTTP response to "text/xml".
16202 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
16203 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
16204 * will be used to make the request.
16206 Roo.data.HttpProxy = function(conn){
16207 Roo.data.HttpProxy.superclass.constructor.call(this);
16208 // is conn a conn config or a real conn?
16210 this.useAjax = !conn || !conn.events;
16214 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
16215 // thse are take from connection...
16218 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
16221 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
16222 * extra parameters to each request made by this object. (defaults to undefined)
16225 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
16226 * to each request made by this object. (defaults to undefined)
16229 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
16232 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
16235 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
16241 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
16245 * Return the {@link Roo.data.Connection} object being used by this Proxy.
16246 * @return {Connection} The Connection object. This object may be used to subscribe to events on
16247 * a finer-grained basis than the DataProxy events.
16249 getConnection : function(){
16250 return this.useAjax ? Roo.Ajax : this.conn;
16254 * Load data from the configured {@link Roo.data.Connection}, read the data object into
16255 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
16256 * process that block using the passed callback.
16257 * @param {Object} params An object containing properties which are to be used as HTTP parameters
16258 * for the request to the remote server.
16259 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16260 * object into a block of Roo.data.Records.
16261 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
16262 * The function must be passed <ul>
16263 * <li>The Record block object</li>
16264 * <li>The "arg" argument from the load function</li>
16265 * <li>A boolean success indicator</li>
16267 * @param {Object} scope The scope in which to call the callback
16268 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16270 load : function(params, reader, callback, scope, arg){
16271 if(this.fireEvent("beforeload", this, params) !== false){
16273 params : params || {},
16275 callback : callback,
16280 callback : this.loadResponse,
16284 Roo.applyIf(o, this.conn);
16285 if(this.activeRequest){
16286 Roo.Ajax.abort(this.activeRequest);
16288 this.activeRequest = Roo.Ajax.request(o);
16290 this.conn.request(o);
16293 callback.call(scope||this, null, arg, false);
16298 loadResponse : function(o, success, response){
16299 delete this.activeRequest;
16301 this.fireEvent("loadexception", this, o, response);
16302 o.request.callback.call(o.request.scope, null, o.request.arg, false);
16307 result = o.reader.read(response);
16310 o.raw = { errorMsg : response.responseText };
16311 this.fireEvent("loadexception", this, o, response, e);
16312 o.request.callback.call(o.request.scope, o, o.request.arg, false);
16316 this.fireEvent("load", this, o, o.request.arg);
16317 o.request.callback.call(o.request.scope, result, o.request.arg, true);
16321 update : function(dataSet){
16326 updateResponse : function(dataSet){
16331 * Ext JS Library 1.1.1
16332 * Copyright(c) 2006-2007, Ext JS, LLC.
16334 * Originally Released Under LGPL - original licence link has changed is not relivant.
16337 * <script type="text/javascript">
16341 * @class Roo.data.ScriptTagProxy
16342 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
16343 * other than the originating domain of the running page.<br><br>
16345 * <em>Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain
16346 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
16348 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
16349 * source code that is used as the source inside a <script> tag.<br><br>
16351 * In order for the browser to process the returned data, the server must wrap the data object
16352 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
16353 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
16354 * depending on whether the callback name was passed:
16357 boolean scriptTag = false;
16358 String cb = request.getParameter("callback");
16361 response.setContentType("text/javascript");
16363 response.setContentType("application/x-json");
16365 Writer out = response.getWriter();
16367 out.write(cb + "(");
16369 out.print(dataBlock.toJsonString());
16376 * @param {Object} config A configuration object.
16378 Roo.data.ScriptTagProxy = function(config){
16379 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
16380 Roo.apply(this, config);
16381 this.head = document.getElementsByTagName("head")[0];
16384 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
16386 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
16388 * @cfg {String} url The URL from which to request the data object.
16391 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
16395 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
16396 * the server the name of the callback function set up by the load call to process the returned data object.
16397 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
16398 * javascript output which calls this named function passing the data object as its only parameter.
16400 callbackParam : "callback",
16402 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
16403 * name to the request.
16408 * Load data from the configured URL, read the data object into
16409 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
16410 * process that block using the passed callback.
16411 * @param {Object} params An object containing properties which are to be used as HTTP parameters
16412 * for the request to the remote server.
16413 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16414 * object into a block of Roo.data.Records.
16415 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
16416 * The function must be passed <ul>
16417 * <li>The Record block object</li>
16418 * <li>The "arg" argument from the load function</li>
16419 * <li>A boolean success indicator</li>
16421 * @param {Object} scope The scope in which to call the callback
16422 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16424 load : function(params, reader, callback, scope, arg){
16425 if(this.fireEvent("beforeload", this, params) !== false){
16427 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
16429 var url = this.url;
16430 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
16432 url += "&_dc=" + (new Date().getTime());
16434 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
16437 cb : "stcCallback"+transId,
16438 scriptId : "stcScript"+transId,
16442 callback : callback,
16448 window[trans.cb] = function(o){
16449 conn.handleResponse(o, trans);
16452 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
16454 if(this.autoAbort !== false){
16458 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
16460 var script = document.createElement("script");
16461 script.setAttribute("src", url);
16462 script.setAttribute("type", "text/javascript");
16463 script.setAttribute("id", trans.scriptId);
16464 this.head.appendChild(script);
16466 this.trans = trans;
16468 callback.call(scope||this, null, arg, false);
16473 isLoading : function(){
16474 return this.trans ? true : false;
16478 * Abort the current server request.
16480 abort : function(){
16481 if(this.isLoading()){
16482 this.destroyTrans(this.trans);
16487 destroyTrans : function(trans, isLoaded){
16488 this.head.removeChild(document.getElementById(trans.scriptId));
16489 clearTimeout(trans.timeoutId);
16491 window[trans.cb] = undefined;
16493 delete window[trans.cb];
16496 // if hasn't been loaded, wait for load to remove it to prevent script error
16497 window[trans.cb] = function(){
16498 window[trans.cb] = undefined;
16500 delete window[trans.cb];
16507 handleResponse : function(o, trans){
16508 this.trans = false;
16509 this.destroyTrans(trans, true);
16512 result = trans.reader.readRecords(o);
16514 this.fireEvent("loadexception", this, o, trans.arg, e);
16515 trans.callback.call(trans.scope||window, null, trans.arg, false);
16518 this.fireEvent("load", this, o, trans.arg);
16519 trans.callback.call(trans.scope||window, result, trans.arg, true);
16523 handleFailure : function(trans){
16524 this.trans = false;
16525 this.destroyTrans(trans, false);
16526 this.fireEvent("loadexception", this, null, trans.arg);
16527 trans.callback.call(trans.scope||window, null, trans.arg, false);
16531 * Ext JS Library 1.1.1
16532 * Copyright(c) 2006-2007, Ext JS, LLC.
16534 * Originally Released Under LGPL - original licence link has changed is not relivant.
16537 * <script type="text/javascript">
16541 * @class Roo.data.JsonReader
16542 * @extends Roo.data.DataReader
16543 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
16544 * based on mappings in a provided Roo.data.Record constructor.
16546 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
16547 * in the reply previously.
16552 var RecordDef = Roo.data.Record.create([
16553 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
16554 {name: 'occupation'} // This field will use "occupation" as the mapping.
16556 var myReader = new Roo.data.JsonReader({
16557 totalProperty: "results", // The property which contains the total dataset size (optional)
16558 root: "rows", // The property which contains an Array of row objects
16559 id: "id" // The property within each row object that provides an ID for the record (optional)
16563 * This would consume a JSON file like this:
16565 { 'results': 2, 'rows': [
16566 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
16567 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
16570 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
16571 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
16572 * paged from the remote server.
16573 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
16574 * @cfg {String} root name of the property which contains the Array of row objects.
16575 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
16576 * @cfg {Array} fields Array of field definition objects
16578 * Create a new JsonReader
16579 * @param {Object} meta Metadata configuration options
16580 * @param {Object} recordType Either an Array of field definition objects,
16581 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
16583 Roo.data.JsonReader = function(meta, recordType){
16586 // set some defaults:
16587 Roo.applyIf(meta, {
16588 totalProperty: 'total',
16589 successProperty : 'success',
16594 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
16596 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
16598 readerType : 'Json',
16601 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
16602 * Used by Store query builder to append _requestMeta to params.
16605 metaFromRemote : false,
16607 * This method is only used by a DataProxy which has retrieved data from a remote server.
16608 * @param {Object} response The XHR object which contains the JSON data in its responseText.
16609 * @return {Object} data A data block which is used by an Roo.data.Store object as
16610 * a cache of Roo.data.Records.
16612 read : function(response){
16613 var json = response.responseText;
16615 var o = /* eval:var:o */ eval("("+json+")");
16617 throw {message: "JsonReader.read: Json object not found"};
16623 this.metaFromRemote = true;
16624 this.meta = o.metaData;
16625 this.recordType = Roo.data.Record.create(o.metaData.fields);
16626 this.onMetaChange(this.meta, this.recordType, o);
16628 return this.readRecords(o);
16631 // private function a store will implement
16632 onMetaChange : function(meta, recordType, o){
16639 simpleAccess: function(obj, subsc) {
16646 getJsonAccessor: function(){
16648 return function(expr) {
16650 return(re.test(expr))
16651 ? new Function("obj", "return obj." + expr)
16656 return Roo.emptyFn;
16661 * Create a data block containing Roo.data.Records from an XML document.
16662 * @param {Object} o An object which contains an Array of row objects in the property specified
16663 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
16664 * which contains the total size of the dataset.
16665 * @return {Object} data A data block which is used by an Roo.data.Store object as
16666 * a cache of Roo.data.Records.
16668 readRecords : function(o){
16670 * After any data loads, the raw JSON data is available for further custom processing.
16674 var s = this.meta, Record = this.recordType,
16675 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
16677 // Generate extraction functions for the totalProperty, the root, the id, and for each field
16679 if(s.totalProperty) {
16680 this.getTotal = this.getJsonAccessor(s.totalProperty);
16682 if(s.successProperty) {
16683 this.getSuccess = this.getJsonAccessor(s.successProperty);
16685 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
16687 var g = this.getJsonAccessor(s.id);
16688 this.getId = function(rec) {
16690 return (r === undefined || r === "") ? null : r;
16693 this.getId = function(){return null;};
16696 for(var jj = 0; jj < fl; jj++){
16698 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
16699 this.ef[jj] = this.getJsonAccessor(map);
16703 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
16704 if(s.totalProperty){
16705 var vt = parseInt(this.getTotal(o), 10);
16710 if(s.successProperty){
16711 var vs = this.getSuccess(o);
16712 if(vs === false || vs === 'false'){
16717 for(var i = 0; i < c; i++){
16720 var id = this.getId(n);
16721 for(var j = 0; j < fl; j++){
16723 var v = this.ef[j](n);
16725 Roo.log('missing convert for ' + f.name);
16729 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
16733 raw : { errorMsg : "JSON Reader Error: fields or metadata not available to create Record" },
16739 var record = new Record(values, id);
16741 records[i] = record;
16747 totalRecords : totalRecords
16750 // used when loading children.. @see loadDataFromChildren
16751 toLoadData: function(rec)
16753 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
16754 var data = typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
16755 return { data : data, total : data.length };
16760 * Ext JS Library 1.1.1
16761 * Copyright(c) 2006-2007, Ext JS, LLC.
16763 * Originally Released Under LGPL - original licence link has changed is not relivant.
16766 * <script type="text/javascript">
16770 * @class Roo.data.ArrayReader
16771 * @extends Roo.data.DataReader
16772 * Data reader class to create an Array of Roo.data.Record objects from an Array.
16773 * Each element of that Array represents a row of data fields. The
16774 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
16775 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
16779 var RecordDef = Roo.data.Record.create([
16780 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
16781 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
16783 var myReader = new Roo.data.ArrayReader({
16784 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
16788 * This would consume an Array like this:
16790 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
16794 * Create a new JsonReader
16795 * @param {Object} meta Metadata configuration options.
16796 * @param {Object|Array} recordType Either an Array of field definition objects
16798 * @cfg {Array} fields Array of field definition objects
16799 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
16800 * as specified to {@link Roo.data.Record#create},
16801 * or an {@link Roo.data.Record} object
16804 * created using {@link Roo.data.Record#create}.
16806 Roo.data.ArrayReader = function(meta, recordType)
16808 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType||meta.fields);
16811 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
16814 * Create a data block containing Roo.data.Records from an XML document.
16815 * @param {Object} o An Array of row objects which represents the dataset.
16816 * @return {Object} A data block which is used by an {@link Roo.data.Store} object as
16817 * a cache of Roo.data.Records.
16819 readRecords : function(o)
16821 var sid = this.meta ? this.meta.id : null;
16822 var recordType = this.recordType, fields = recordType.prototype.fields;
16825 for(var i = 0; i < root.length; i++){
16828 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
16829 for(var j = 0, jlen = fields.length; j < jlen; j++){
16830 var f = fields.items[j];
16831 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
16832 var v = n[k] !== undefined ? n[k] : f.defaultValue;
16834 values[f.name] = v;
16836 var record = new recordType(values, id);
16838 records[records.length] = record;
16842 totalRecords : records.length
16845 // used when loading children.. @see loadDataFromChildren
16846 toLoadData: function(rec)
16848 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
16849 return typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
16860 * @class Roo.bootstrap.form.ComboBox
16861 * @extends Roo.bootstrap.form.TriggerField
16862 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
16863 * @cfg {Boolean} append (true|false) default false
16864 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
16865 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
16866 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
16867 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
16868 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16869 * @cfg {Boolean} animate default true
16870 * @cfg {Boolean} emptyResultText only for touch device
16871 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
16872 * @cfg {String} emptyTitle default ''
16873 * @cfg {Number} width fixed with? experimental
16875 * Create a new ComboBox.
16876 * @param {Object} config Configuration options
16878 Roo.bootstrap.form.ComboBox = function(config){
16879 Roo.bootstrap.form.ComboBox.superclass.constructor.call(this, config);
16883 * Fires when the dropdown list is expanded
16884 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16889 * Fires when the dropdown list is collapsed
16890 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16894 * @event beforeselect
16895 * Fires before a list item is selected. Return false to cancel the selection.
16896 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16897 * @param {Roo.data.Record} record The data record returned from the underlying store
16898 * @param {Number} index The index of the selected item in the dropdown list
16900 'beforeselect' : true,
16903 * Fires when a list item is selected
16904 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16905 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
16906 * @param {Number} index The index of the selected item in the dropdown list
16910 * @event beforequery
16911 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
16912 * The event object passed has these properties:
16913 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16914 * @param {String} query The query
16915 * @param {Boolean} forceAll true to force "all" query
16916 * @param {Boolean} cancel true to cancel the query
16917 * @param {Object} e The query event object
16919 'beforequery': true,
16922 * Fires when the 'add' icon is pressed (add a listener to enable add button)
16923 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16928 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
16929 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16930 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
16935 * Fires when the remove value from the combobox array
16936 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16940 * @event afterremove
16941 * Fires when the remove value from the combobox array
16942 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16944 'afterremove' : true,
16946 * @event specialfilter
16947 * Fires when specialfilter
16948 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16950 'specialfilter' : true,
16953 * Fires when tick the element
16954 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16958 * @event touchviewdisplay
16959 * Fires when touch view require special display (default is using displayField)
16960 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16961 * @param {Object} cfg set html .
16963 'touchviewdisplay' : true
16968 this.tickItems = [];
16970 this.selectedIndex = -1;
16971 if(this.mode == 'local'){
16972 if(config.queryDelay === undefined){
16973 this.queryDelay = 10;
16975 if(config.minChars === undefined){
16981 Roo.extend(Roo.bootstrap.form.ComboBox, Roo.bootstrap.form.TriggerField, {
16984 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
16985 * rendering into an Roo.Editor, defaults to false)
16988 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
16989 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
16992 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
16995 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
16996 * the dropdown list (defaults to undefined, with no header element)
17000 * @cfg {String/Roo.Template} tpl The template to use to render the output default is '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>'
17004 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
17006 listWidth: undefined,
17008 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
17009 * mode = 'remote' or 'text' if mode = 'local')
17011 displayField: undefined,
17014 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
17015 * mode = 'remote' or 'value' if mode = 'local').
17016 * Note: use of a valueField requires the user make a selection
17017 * in order for a value to be mapped.
17019 valueField: undefined,
17021 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
17026 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
17027 * field's data value (defaults to the underlying DOM element's name)
17029 hiddenName: undefined,
17031 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
17035 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
17037 selectedClass: 'active',
17040 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
17044 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
17045 * anchor positions (defaults to 'tl-bl')
17047 listAlign: 'tl-bl?',
17049 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
17053 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
17054 * query specified by the allQuery config option (defaults to 'query')
17056 triggerAction: 'query',
17058 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
17059 * (defaults to 4, does not apply if editable = false)
17063 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
17064 * delay (typeAheadDelay) if it matches a known value (defaults to false)
17068 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
17069 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
17073 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
17074 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
17078 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
17079 * when editable = true (defaults to false)
17081 selectOnFocus:false,
17083 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
17085 queryParam: 'query',
17087 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
17088 * when mode = 'remote' (defaults to 'Loading...')
17090 loadingText: 'Loading...',
17092 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
17096 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
17100 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
17101 * traditional select (defaults to true)
17105 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
17109 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
17113 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
17114 * listWidth has a higher value)
17118 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
17119 * allow the user to set arbitrary text into the field (defaults to false)
17121 forceSelection:false,
17123 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
17124 * if typeAhead = true (defaults to 250)
17126 typeAheadDelay : 250,
17128 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
17129 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
17131 valueNotFoundText : undefined,
17133 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
17135 blockFocus : false,
17138 * @cfg {Boolean} disableClear Disable showing of clear button.
17140 disableClear : false,
17142 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
17144 alwaysQuery : false,
17147 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
17152 * @cfg {String} invalidClass DEPRICATED - uses BS4 is-valid now
17154 invalidClass : "has-warning",
17157 * @cfg {String} validClass DEPRICATED - uses BS4 is-valid now
17159 validClass : "has-success",
17162 * @cfg {Boolean} specialFilter (true|false) special filter default false
17164 specialFilter : false,
17167 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
17169 mobileTouchView : true,
17172 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
17174 useNativeIOS : false,
17177 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
17179 mobile_restrict_height : false,
17181 ios_options : false,
17193 btnPosition : 'right',
17194 triggerList : true,
17195 showToggleBtn : true,
17197 emptyResultText: 'Empty',
17198 triggerText : 'Select',
17202 // element that contains real text value.. (when hidden is used..)
17204 getAutoCreate : function()
17209 * Render classic select for iso
17212 if(Roo.isIOS && this.useNativeIOS){
17213 cfg = this.getAutoCreateNativeIOS();
17221 if(Roo.isTouch && this.mobileTouchView){
17222 cfg = this.getAutoCreateTouchView();
17229 if(!this.tickable){
17230 cfg = Roo.bootstrap.form.ComboBox.superclass.getAutoCreate.call(this);
17235 * ComboBox with tickable selections
17238 var align = this.labelAlign || this.parentLabelAlign();
17241 cls : 'form-group roo-combobox-tickable' //input-group
17244 var btn_text_select = '';
17245 var btn_text_done = '';
17246 var btn_text_cancel = '';
17248 if (this.btn_text_show) {
17249 btn_text_select = 'Select';
17250 btn_text_done = 'Done';
17251 btn_text_cancel = 'Cancel';
17256 cls : 'tickable-buttons',
17261 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
17262 //html : this.triggerText
17263 html: btn_text_select
17269 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
17271 html: btn_text_done
17277 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
17279 html: btn_text_cancel
17285 buttons.cn.unshift({
17287 cls: 'roo-select2-search-field-input'
17293 Roo.each(buttons.cn, function(c){
17295 c.cls += ' btn-' + _this.size;
17298 if (_this.disabled) {
17305 style : 'display: contents',
17310 cls: 'form-hidden-field'
17314 cls: 'roo-select2-choices',
17318 cls: 'roo-select2-search-field',
17329 cls: 'roo-select2-container input-group roo-select2-container-multi',
17335 // cls: 'typeahead typeahead-long dropdown-menu',
17336 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
17341 if(this.hasFeedback && !this.allowBlank){
17345 cls: 'glyphicon form-control-feedback'
17348 combobox.cn.push(feedback);
17355 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
17356 tooltip : 'This field is required'
17358 if (Roo.bootstrap.version == 4) {
17361 style : 'display:none'
17364 if (align ==='left' && this.fieldLabel.length) {
17366 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
17373 cls : 'control-label col-form-label',
17374 html : this.fieldLabel
17386 var labelCfg = cfg.cn[1];
17387 var contentCfg = cfg.cn[2];
17390 if(this.indicatorpos == 'right'){
17396 cls : 'control-label col-form-label',
17400 html : this.fieldLabel
17416 labelCfg = cfg.cn[0];
17417 contentCfg = cfg.cn[1];
17421 if(this.labelWidth > 12){
17422 labelCfg.style = "width: " + this.labelWidth + 'px';
17424 if(this.width * 1 > 0){
17425 contentCfg.style = "width: " + this.width + 'px';
17427 if(this.labelWidth < 13 && this.labelmd == 0){
17428 this.labelmd = this.labelWidth;
17431 if(this.labellg > 0){
17432 labelCfg.cls += ' col-lg-' + this.labellg;
17433 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
17436 if(this.labelmd > 0){
17437 labelCfg.cls += ' col-md-' + this.labelmd;
17438 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
17441 if(this.labelsm > 0){
17442 labelCfg.cls += ' col-sm-' + this.labelsm;
17443 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
17446 if(this.labelxs > 0){
17447 labelCfg.cls += ' col-xs-' + this.labelxs;
17448 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
17452 } else if ( this.fieldLabel.length) {
17453 // Roo.log(" label");
17458 //cls : 'input-group-addon',
17459 html : this.fieldLabel
17464 if(this.indicatorpos == 'right'){
17468 //cls : 'input-group-addon',
17469 html : this.fieldLabel
17479 // Roo.log(" no label && no align");
17486 ['xs','sm','md','lg'].map(function(size){
17487 if (settings[size]) {
17488 cfg.cls += ' col-' + size + '-' + settings[size];
17496 _initEventsCalled : false,
17499 initEvents: function()
17501 if (this._initEventsCalled) { // as we call render... prevent looping...
17504 this._initEventsCalled = true;
17507 throw "can not find store for combo";
17510 this.indicator = this.indicatorEl();
17512 this.store = Roo.factory(this.store, Roo.data);
17513 this.store.parent = this;
17515 // if we are building from html. then this element is so complex, that we can not really
17516 // use the rendered HTML.
17517 // so we have to trash and replace the previous code.
17518 if (Roo.XComponent.build_from_html) {
17519 // remove this element....
17520 var e = this.el.dom, k=0;
17521 while (e ) { e = e.previousSibling; ++k;}
17526 this.rendered = false;
17528 this.render(this.parent().getChildContainer(true), k);
17531 if(Roo.isIOS && this.useNativeIOS){
17532 this.initIOSView();
17540 if(Roo.isTouch && this.mobileTouchView){
17541 this.initTouchView();
17546 this.initTickableEvents();
17550 Roo.bootstrap.form.ComboBox.superclass.initEvents.call(this);
17552 if(this.hiddenName){
17554 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
17556 this.hiddenField.dom.value =
17557 this.hiddenValue !== undefined ? this.hiddenValue :
17558 this.value !== undefined ? this.value : '';
17560 // prevent input submission
17561 this.el.dom.removeAttribute('name');
17562 this.hiddenField.dom.setAttribute('name', this.hiddenName);
17567 // this.el.dom.setAttribute('autocomplete', 'off');
17570 var cls = 'x-combo-list';
17572 //this.list = new Roo.Layer({
17573 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
17579 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
17580 _this.list.setWidth(lw);
17583 this.list.on('mouseover', this.onViewOver, this);
17584 this.list.on('mousemove', this.onViewMove, this);
17585 this.list.on('scroll', this.onViewScroll, this);
17588 this.list.swallowEvent('mousewheel');
17589 this.assetHeight = 0;
17592 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
17593 this.assetHeight += this.header.getHeight();
17596 this.innerList = this.list.createChild({cls:cls+'-inner'});
17597 this.innerList.on('mouseover', this.onViewOver, this);
17598 this.innerList.on('mousemove', this.onViewMove, this);
17599 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
17601 if(this.allowBlank && !this.pageSize && !this.disableClear){
17602 this.footer = this.list.createChild({cls:cls+'-ft'});
17603 this.pageTb = new Roo.Toolbar(this.footer);
17607 this.footer = this.list.createChild({cls:cls+'-ft'});
17608 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
17609 {pageSize: this.pageSize});
17613 if (this.pageTb && this.allowBlank && !this.disableClear) {
17615 this.pageTb.add(new Roo.Toolbar.Fill(), {
17616 cls: 'x-btn-icon x-btn-clear',
17618 handler: function()
17621 _this.clearValue();
17622 _this.onSelect(false, -1);
17627 this.assetHeight += this.footer.getHeight();
17632 this.tpl = Roo.bootstrap.version == 4 ?
17633 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
17634 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
17637 this.view = new Roo.View(this.list, this.tpl, {
17638 singleSelect:true, store: this.store, selectedClass: this.selectedClass
17640 //this.view.wrapEl.setDisplayed(false);
17641 this.view.on('click', this.onViewClick, this);
17644 this.store.on('beforeload', this.onBeforeLoad, this);
17645 this.store.on('load', this.onLoad, this);
17646 this.store.on('loadexception', this.onLoadException, this);
17648 if(this.resizable){
17649 this.resizer = new Roo.Resizable(this.list, {
17650 pinned:true, handles:'se'
17652 this.resizer.on('resize', function(r, w, h){
17653 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
17654 this.listWidth = w;
17655 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
17656 this.restrictHeight();
17658 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
17661 if(!this.editable){
17662 this.editable = true;
17663 this.setEditable(false);
17668 if (typeof(this.events.add.listeners) != 'undefined') {
17670 this.addicon = this.wrap.createChild(
17671 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
17673 this.addicon.on('click', function(e) {
17674 this.fireEvent('add', this);
17677 if (typeof(this.events.edit.listeners) != 'undefined') {
17679 this.editicon = this.wrap.createChild(
17680 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
17681 if (this.addicon) {
17682 this.editicon.setStyle('margin-left', '40px');
17684 this.editicon.on('click', function(e) {
17686 // we fire even if inothing is selected..
17687 this.fireEvent('edit', this, this.lastData );
17693 this.keyNav = new Roo.KeyNav(this.inputEl(), {
17694 "up" : function(e){
17695 this.inKeyMode = true;
17699 "down" : function(e){
17700 if(!this.isExpanded()){
17701 this.onTriggerClick();
17703 this.inKeyMode = true;
17708 "enter" : function(e){
17709 // this.onViewClick();
17713 if(this.fireEvent("specialkey", this, e)){
17714 this.onViewClick(false);
17720 "esc" : function(e){
17724 "tab" : function(e){
17727 if(this.fireEvent("specialkey", this, e)){
17728 this.onViewClick(false);
17736 doRelay : function(foo, bar, hname){
17737 if(hname == 'down' || this.scope.isExpanded()){
17738 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
17747 this.queryDelay = Math.max(this.queryDelay || 10,
17748 this.mode == 'local' ? 10 : 250);
17751 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
17753 if(this.typeAhead){
17754 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
17756 if(this.editable !== false){
17757 this.inputEl().on("keyup", this.onKeyUp, this);
17759 if(this.forceSelection){
17760 this.inputEl().on('blur', this.doForce, this);
17764 this.choices = this.el.select('ul.roo-select2-choices', true).first();
17765 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
17769 initTickableEvents: function()
17773 if(this.hiddenName){
17775 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
17777 this.hiddenField.dom.value =
17778 this.hiddenValue !== undefined ? this.hiddenValue :
17779 this.value !== undefined ? this.value : '';
17781 // prevent input submission
17782 this.el.dom.removeAttribute('name');
17783 this.hiddenField.dom.setAttribute('name', this.hiddenName);
17788 // this.list = this.el.select('ul.dropdown-menu',true).first();
17790 this.choices = this.el.select('ul.roo-select2-choices', true).first();
17791 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
17792 if(this.triggerList){
17793 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
17796 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
17797 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
17799 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
17800 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
17802 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
17803 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
17805 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
17806 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
17807 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
17810 this.cancelBtn.hide();
17815 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
17816 _this.list.setWidth(lw);
17819 this.list.on('mouseover', this.onViewOver, this);
17820 this.list.on('mousemove', this.onViewMove, this);
17822 this.list.on('scroll', this.onViewScroll, this);
17825 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
17826 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
17829 this.view = new Roo.View(this.list, this.tpl, {
17834 selectedClass: this.selectedClass
17837 //this.view.wrapEl.setDisplayed(false);
17838 this.view.on('click', this.onViewClick, this);
17842 this.store.on('beforeload', this.onBeforeLoad, this);
17843 this.store.on('load', this.onLoad, this);
17844 this.store.on('loadexception', this.onLoadException, this);
17847 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
17848 "up" : function(e){
17849 this.inKeyMode = true;
17853 "down" : function(e){
17854 this.inKeyMode = true;
17858 "enter" : function(e){
17859 if(this.fireEvent("specialkey", this, e)){
17860 this.onViewClick(false);
17866 "esc" : function(e){
17867 this.onTickableFooterButtonClick(e, false, false);
17870 "tab" : function(e){
17871 this.fireEvent("specialkey", this, e);
17873 this.onTickableFooterButtonClick(e, false, false);
17880 doRelay : function(e, fn, key){
17881 if(this.scope.isExpanded()){
17882 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
17891 this.queryDelay = Math.max(this.queryDelay || 10,
17892 this.mode == 'local' ? 10 : 250);
17895 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
17897 if(this.typeAhead){
17898 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
17901 if(this.editable !== false){
17902 this.tickableInputEl().on("keyup", this.onKeyUp, this);
17905 this.indicator = this.indicatorEl();
17907 if(this.indicator){
17908 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
17909 this.indicator.hide();
17914 onDestroy : function(){
17916 this.view.setStore(null);
17917 this.view.el.removeAllListeners();
17918 this.view.el.remove();
17919 this.view.purgeListeners();
17922 this.list.dom.innerHTML = '';
17926 this.store.un('beforeload', this.onBeforeLoad, this);
17927 this.store.un('load', this.onLoad, this);
17928 this.store.un('loadexception', this.onLoadException, this);
17930 Roo.bootstrap.form.ComboBox.superclass.onDestroy.call(this);
17934 fireKey : function(e){
17935 if(e.isNavKeyPress() && !this.list.isVisible()){
17936 this.fireEvent("specialkey", this, e);
17941 onResize: function(w, h)
17945 // Roo.bootstrap.form.ComboBox.superclass.onResize.apply(this, arguments);
17947 // if(typeof w != 'number'){
17948 // // we do not handle it!?!?
17951 // var tw = this.trigger.getWidth();
17952 // // tw += this.addicon ? this.addicon.getWidth() : 0;
17953 // // tw += this.editicon ? this.editicon.getWidth() : 0;
17955 // this.inputEl().setWidth( this.adjustWidth('input', x));
17957 // //this.trigger.setStyle('left', x+'px');
17959 // if(this.list && this.listWidth === undefined){
17960 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
17961 // this.list.setWidth(lw);
17962 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
17970 * Allow or prevent the user from directly editing the field text. If false is passed,
17971 * the user will only be able to select from the items defined in the dropdown list. This method
17972 * is the runtime equivalent of setting the 'editable' config option at config time.
17973 * @param {Boolean} value True to allow the user to directly edit the field text
17975 setEditable : function(value){
17976 if(value == this.editable){
17979 this.editable = value;
17981 this.inputEl().dom.setAttribute('readOnly', true);
17982 this.inputEl().on('mousedown', this.onTriggerClick, this);
17983 this.inputEl().addClass('x-combo-noedit');
17985 this.inputEl().dom.removeAttribute('readOnly');
17986 this.inputEl().un('mousedown', this.onTriggerClick, this);
17987 this.inputEl().removeClass('x-combo-noedit');
17993 onBeforeLoad : function(combo,opts){
17994 if(!this.hasFocus){
17998 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
18000 this.restrictHeight();
18001 this.selectedIndex = -1;
18005 onLoad : function(){
18007 this.hasQuery = false;
18009 if(!this.hasFocus){
18013 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
18014 this.loading.hide();
18017 if(this.store.getCount() > 0){
18020 this.restrictHeight();
18021 if(this.lastQuery == this.allQuery){
18022 if(this.editable && !this.tickable){
18023 this.inputEl().dom.select();
18027 !this.selectByValue(this.value, true) &&
18030 !this.store.lastOptions ||
18031 typeof(this.store.lastOptions.add) == 'undefined' ||
18032 this.store.lastOptions.add != true
18035 this.select(0, true);
18038 if(this.autoFocus){
18041 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
18042 this.taTask.delay(this.typeAheadDelay);
18046 this.onEmptyResults();
18052 onLoadException : function()
18054 this.hasQuery = false;
18056 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
18057 this.loading.hide();
18060 if(this.tickable && this.editable){
18065 // only causes errors at present
18066 //Roo.log(this.store.reader.jsonData);
18067 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
18069 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
18075 onTypeAhead : function(){
18076 if(this.store.getCount() > 0){
18077 var r = this.store.getAt(0);
18078 var newValue = r.data[this.displayField];
18079 var len = newValue.length;
18080 var selStart = this.getRawValue().length;
18082 if(selStart != len){
18083 this.setRawValue(newValue);
18084 this.selectText(selStart, newValue.length);
18090 onSelect : function(record, index){
18092 if(this.fireEvent('beforeselect', this, record, index) !== false){
18094 this.setFromData(index > -1 ? record.data : false);
18097 this.fireEvent('select', this, record, index);
18102 * Returns the currently selected field value or empty string if no value is set.
18103 * @return {String} value The selected value
18105 getValue : function()
18107 if(Roo.isIOS && this.useNativeIOS){
18108 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
18112 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
18115 if(this.valueField){
18116 return typeof this.value != 'undefined' ? this.value : '';
18118 return Roo.bootstrap.form.ComboBox.superclass.getValue.call(this);
18122 getRawValue : function()
18124 if(Roo.isIOS && this.useNativeIOS){
18125 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
18128 var v = this.inputEl().getValue();
18134 * Clears any text/value currently set in the field
18136 clearValue : function(){
18138 if(this.hiddenField){
18139 this.hiddenField.dom.value = '';
18142 this.setRawValue('');
18143 this.lastSelectionText = '';
18144 this.lastData = false;
18146 var close = this.closeTriggerEl();
18157 * Sets the specified value into the field. If the value finds a match, the corresponding record text
18158 * will be displayed in the field. If the value does not match the data value of an existing item,
18159 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
18160 * Otherwise the field will be blank (although the value will still be set).
18161 * @param {String} value The value to match
18163 setValue : function(v)
18165 if(Roo.isIOS && this.useNativeIOS){
18166 this.setIOSValue(v);
18176 if(this.valueField){
18177 var r = this.findRecord(this.valueField, v);
18179 text = r.data[this.displayField];
18180 }else if(this.valueNotFoundText !== undefined){
18181 text = this.valueNotFoundText;
18184 this.lastSelectionText = text;
18185 if(this.hiddenField){
18186 this.hiddenField.dom.value = v;
18188 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, text);
18191 var close = this.closeTriggerEl();
18194 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
18200 * @property {Object} the last set data for the element
18205 * Sets the value of the field based on a object which is related to the record format for the store.
18206 * @param {Object} value the value to set as. or false on reset?
18208 setFromData : function(o){
18215 var dv = ''; // display value
18216 var vv = ''; // value value..
18218 if (this.displayField) {
18219 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
18221 // this is an error condition!!!
18222 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
18225 if(this.valueField){
18226 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
18229 var close = this.closeTriggerEl();
18232 if(dv.length || vv * 1 > 0){
18234 this.blockFocus=true;
18240 if(this.hiddenField){
18241 this.hiddenField.dom.value = vv;
18243 this.lastSelectionText = dv;
18244 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
18248 // no hidden field.. - we store the value in 'value', but still display
18249 // display field!!!!
18250 this.lastSelectionText = dv;
18251 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
18258 reset : function(){
18259 // overridden so that last data is reset..
18266 this.setValue(this.originalValue);
18267 //this.clearInvalid();
18268 this.lastData = false;
18270 this.view.clearSelections();
18276 findRecord : function(prop, value){
18278 if(this.store.getCount() > 0){
18279 this.store.each(function(r){
18280 if(r.data[prop] == value){
18290 getName: function()
18292 // returns hidden if it's set..
18293 if (!this.rendered) {return ''};
18294 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
18298 onViewMove : function(e, t){
18299 this.inKeyMode = false;
18303 onViewOver : function(e, t){
18304 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
18307 var item = this.view.findItemFromChild(t);
18310 var index = this.view.indexOf(item);
18311 this.select(index, false);
18316 onViewClick : function(view, doFocus, el, e)
18318 var index = this.view.getSelectedIndexes()[0];
18320 var r = this.store.getAt(index);
18324 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
18331 Roo.each(this.tickItems, function(v,k){
18333 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
18335 _this.tickItems.splice(k, 1);
18337 if(typeof(e) == 'undefined' && view == false){
18338 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
18350 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
18351 this.tickItems.push(r.data);
18354 if(typeof(e) == 'undefined' && view == false){
18355 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
18362 this.onSelect(r, index);
18364 if(doFocus !== false && !this.blockFocus){
18365 this.inputEl().focus();
18370 restrictHeight : function(){
18371 //this.innerList.dom.style.height = '';
18372 //var inner = this.innerList.dom;
18373 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
18374 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
18375 //this.list.beginUpdate();
18376 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
18377 this.list.alignTo(this.inputEl(), this.listAlign);
18378 this.list.alignTo(this.inputEl(), this.listAlign);
18379 //this.list.endUpdate();
18383 onEmptyResults : function(){
18385 if(this.tickable && this.editable){
18386 this.hasFocus = false;
18387 this.restrictHeight();
18395 * Returns true if the dropdown list is expanded, else false.
18397 isExpanded : function(){
18398 return this.list.isVisible();
18402 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
18403 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
18404 * @param {String} value The data value of the item to select
18405 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
18406 * selected item if it is not currently in view (defaults to true)
18407 * @return {Boolean} True if the value matched an item in the list, else false
18409 selectByValue : function(v, scrollIntoView){
18410 if(v !== undefined && v !== null){
18411 var r = this.findRecord(this.valueField || this.displayField, v);
18413 this.select(this.store.indexOf(r), scrollIntoView);
18421 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
18422 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
18423 * @param {Number} index The zero-based index of the list item to select
18424 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
18425 * selected item if it is not currently in view (defaults to true)
18427 select : function(index, scrollIntoView){
18428 this.selectedIndex = index;
18429 this.view.select(index);
18430 if(scrollIntoView !== false){
18431 var el = this.view.getNode(index);
18433 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
18436 this.list.scrollChildIntoView(el, false);
18442 selectNext : function(){
18443 var ct = this.store.getCount();
18445 if(this.selectedIndex == -1){
18447 }else if(this.selectedIndex < ct-1){
18448 this.select(this.selectedIndex+1);
18454 selectPrev : function(){
18455 var ct = this.store.getCount();
18457 if(this.selectedIndex == -1){
18459 }else if(this.selectedIndex != 0){
18460 this.select(this.selectedIndex-1);
18466 onKeyUp : function(e){
18467 if(this.editable !== false && !e.isSpecialKey()){
18468 this.lastKey = e.getKey();
18469 this.dqTask.delay(this.queryDelay);
18474 validateBlur : function(){
18475 return !this.list || !this.list.isVisible();
18479 initQuery : function(){
18481 var v = this.getRawValue();
18483 if(this.tickable && this.editable){
18484 v = this.tickableInputEl().getValue();
18491 doForce : function(){
18492 if(this.inputEl().dom.value.length > 0){
18493 this.inputEl().dom.value =
18494 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
18500 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
18501 * query allowing the query action to be canceled if needed.
18502 * @param {String} query The SQL query to execute
18503 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
18504 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
18505 * saved in the current store (defaults to false)
18507 doQuery : function(q, forceAll){
18509 if(q === undefined || q === null){
18514 forceAll: forceAll,
18518 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
18523 forceAll = qe.forceAll;
18524 if(forceAll === true || (q.length >= this.minChars)){
18526 this.hasQuery = true;
18528 if(this.lastQuery != q || this.alwaysQuery){
18529 this.lastQuery = q;
18530 if(this.mode == 'local'){
18531 this.selectedIndex = -1;
18533 this.store.clearFilter();
18536 if(this.specialFilter){
18537 this.fireEvent('specialfilter', this);
18542 this.store.filter(this.displayField, q);
18545 this.store.fireEvent("datachanged", this.store);
18552 this.store.baseParams[this.queryParam] = q;
18554 var options = {params : this.getParams(q)};
18557 options.add = true;
18558 options.params.start = this.page * this.pageSize;
18561 this.store.load(options);
18564 * this code will make the page width larger, at the beginning, the list not align correctly,
18565 * we should expand the list on onLoad
18566 * so command out it
18571 this.selectedIndex = -1;
18576 this.loadNext = false;
18580 getParams : function(q){
18582 //p[this.queryParam] = q;
18586 p.limit = this.pageSize;
18592 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
18594 collapse : function(){
18595 if(!this.isExpanded()){
18601 this.hasFocus = false;
18605 this.cancelBtn.hide();
18606 this.trigger.show();
18609 this.tickableInputEl().dom.value = '';
18610 this.tickableInputEl().blur();
18615 Roo.get(document).un('mousedown', this.collapseIf, this);
18616 Roo.get(document).un('mousewheel', this.collapseIf, this);
18617 if (!this.editable) {
18618 Roo.get(document).un('keydown', this.listKeyPress, this);
18620 this.fireEvent('collapse', this);
18626 collapseIf : function(e){
18627 var in_combo = e.within(this.el);
18628 var in_list = e.within(this.list);
18629 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
18631 if (in_combo || in_list || is_list) {
18632 //e.stopPropagation();
18637 this.onTickableFooterButtonClick(e, false, false);
18645 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
18647 expand : function(){
18649 if(this.isExpanded() || !this.hasFocus){
18653 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
18654 this.list.setWidth(lw);
18660 this.restrictHeight();
18664 this.tickItems = Roo.apply([], this.item);
18667 this.cancelBtn.show();
18668 this.trigger.hide();
18671 this.tickableInputEl().focus();
18676 Roo.get(document).on('mousedown', this.collapseIf, this);
18677 Roo.get(document).on('mousewheel', this.collapseIf, this);
18678 if (!this.editable) {
18679 Roo.get(document).on('keydown', this.listKeyPress, this);
18682 this.fireEvent('expand', this);
18686 // Implements the default empty TriggerField.onTriggerClick function
18687 onTriggerClick : function(e)
18689 Roo.log('trigger click');
18691 if(this.disabled || !this.triggerList){
18696 this.loadNext = false;
18698 if(this.isExpanded()){
18700 if (!this.blockFocus) {
18701 this.inputEl().focus();
18705 this.hasFocus = true;
18706 if(this.triggerAction == 'all') {
18707 this.doQuery(this.allQuery, true);
18709 this.doQuery(this.getRawValue());
18711 if (!this.blockFocus) {
18712 this.inputEl().focus();
18717 onTickableTriggerClick : function(e)
18724 this.loadNext = false;
18725 this.hasFocus = true;
18727 if(this.triggerAction == 'all') {
18728 this.doQuery(this.allQuery, true);
18730 this.doQuery(this.getRawValue());
18734 onSearchFieldClick : function(e)
18736 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
18737 this.onTickableFooterButtonClick(e, false, false);
18741 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
18746 this.loadNext = false;
18747 this.hasFocus = true;
18749 if(this.triggerAction == 'all') {
18750 this.doQuery(this.allQuery, true);
18752 this.doQuery(this.getRawValue());
18756 listKeyPress : function(e)
18758 //Roo.log('listkeypress');
18759 // scroll to first matching element based on key pres..
18760 if (e.isSpecialKey()) {
18763 var k = String.fromCharCode(e.getKey()).toUpperCase();
18766 var csel = this.view.getSelectedNodes();
18767 var cselitem = false;
18769 var ix = this.view.indexOf(csel[0]);
18770 cselitem = this.store.getAt(ix);
18771 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
18777 this.store.each(function(v) {
18779 // start at existing selection.
18780 if (cselitem.id == v.id) {
18786 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
18787 match = this.store.indexOf(v);
18793 if (match === false) {
18794 return true; // no more action?
18797 this.view.select(match);
18798 var sn = Roo.get(this.view.getSelectedNodes()[0]);
18799 sn.scrollIntoView(sn.dom.parentNode, false);
18802 onViewScroll : function(e, t){
18804 if(this.view.el.getScroll().top == 0 ||this.view.el.getScroll().top < this.view.el.dom.scrollHeight - this.view.el.dom.clientHeight || !this.hasFocus || !this.append || this.hasQuery){
18808 this.hasQuery = true;
18810 this.loading = this.list.select('.loading', true).first();
18812 if(this.loading === null){
18813 this.list.createChild({
18815 cls: 'loading roo-select2-more-results roo-select2-active',
18816 html: 'Loading more results...'
18819 this.loading = this.list.select('.loading', true).first();
18821 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
18823 this.loading.hide();
18826 this.loading.show();
18831 this.loadNext = true;
18833 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
18838 addItem : function(o)
18840 var dv = ''; // display value
18842 if (this.displayField) {
18843 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
18845 // this is an error condition!!!
18846 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
18853 var choice = this.choices.createChild({
18855 cls: 'roo-select2-search-choice',
18864 cls: 'roo-select2-search-choice-close fa fa-times',
18869 }, this.searchField);
18871 var close = choice.select('a.roo-select2-search-choice-close', true).first();
18873 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
18881 this.inputEl().dom.value = '';
18886 onRemoveItem : function(e, _self, o)
18888 e.preventDefault();
18890 this.lastItem = Roo.apply([], this.item);
18892 var index = this.item.indexOf(o.data) * 1;
18895 Roo.log('not this item?!');
18899 this.item.splice(index, 1);
18904 this.fireEvent('remove', this, e);
18910 syncValue : function()
18912 if(!this.item.length){
18919 Roo.each(this.item, function(i){
18920 if(_this.valueField){
18921 value.push(i[_this.valueField]);
18928 this.value = value.join(',');
18930 if(this.hiddenField){
18931 this.hiddenField.dom.value = this.value;
18934 this.store.fireEvent("datachanged", this.store);
18939 clearItem : function()
18941 if(!this.multiple){
18947 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
18955 if(this.tickable && !Roo.isTouch){
18956 this.view.refresh();
18960 inputEl: function ()
18962 if(Roo.isIOS && this.useNativeIOS){
18963 return this.el.select('select.roo-ios-select', true).first();
18966 if(Roo.isTouch && this.mobileTouchView){
18967 return this.el.select('input.form-control',true).first();
18971 return this.searchField;
18974 return this.el.select('input.form-control',true).first();
18977 onTickableFooterButtonClick : function(e, btn, el)
18979 e.preventDefault();
18981 this.lastItem = Roo.apply([], this.item);
18983 if(btn && btn.name == 'cancel'){
18984 this.tickItems = Roo.apply([], this.item);
18993 Roo.each(this.tickItems, function(o){
19001 validate : function()
19003 if(this.getVisibilityEl().hasClass('hidden')){
19007 var v = this.getRawValue();
19010 v = this.getValue();
19013 if(this.disabled || this.allowBlank || v.length){
19018 this.markInvalid();
19022 tickableInputEl : function()
19024 if(!this.tickable || !this.editable){
19025 return this.inputEl();
19028 return this.inputEl().select('.roo-select2-search-field-input', true).first();
19032 getAutoCreateTouchView : function()
19037 cls: 'form-group' //input-group
19043 type : this.inputType,
19044 cls : 'form-control x-combo-noedit',
19045 autocomplete: 'new-password',
19046 placeholder : this.placeholder || '',
19051 input.name = this.name;
19055 input.cls += ' input-' + this.size;
19058 if (this.disabled) {
19059 input.disabled = true;
19063 cls : 'roo-combobox-wrap',
19070 inputblock.cls += ' input-group';
19072 inputblock.cn.unshift({
19074 cls : 'input-group-addon input-group-prepend input-group-text',
19079 if(this.removable && !this.multiple){
19080 inputblock.cls += ' roo-removable';
19082 inputblock.cn.push({
19085 cls : 'roo-combo-removable-btn close'
19089 if(this.hasFeedback && !this.allowBlank){
19091 inputblock.cls += ' has-feedback';
19093 inputblock.cn.push({
19095 cls: 'glyphicon form-control-feedback'
19102 inputblock.cls += (this.before) ? '' : ' input-group';
19104 inputblock.cn.push({
19106 cls : 'input-group-addon input-group-append input-group-text',
19112 var ibwrap = inputblock;
19117 cls: 'roo-select2-choices',
19121 cls: 'roo-select2-search-field',
19134 cls: 'roo-select2-container input-group roo-touchview-combobox ',
19139 cls: 'form-hidden-field'
19145 if(!this.multiple && this.showToggleBtn){
19151 if (this.caret != false) {
19154 cls: 'fa fa-' + this.caret
19161 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
19163 Roo.bootstrap.version == 3 ? caret : '',
19166 cls: 'combobox-clear',
19180 combobox.cls += ' roo-select2-container-multi';
19183 var required = this.allowBlank ? {
19185 style: 'display: none'
19188 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
19189 tooltip : 'This field is required'
19192 var align = this.labelAlign || this.parentLabelAlign();
19194 if (align ==='left' && this.fieldLabel.length) {
19200 cls : 'control-label col-form-label',
19201 html : this.fieldLabel
19205 cls : 'roo-combobox-wrap ',
19212 var labelCfg = cfg.cn[1];
19213 var contentCfg = cfg.cn[2];
19216 if(this.indicatorpos == 'right'){
19221 cls : 'control-label col-form-label',
19225 html : this.fieldLabel
19231 cls : "roo-combobox-wrap ",
19239 labelCfg = cfg.cn[0];
19240 contentCfg = cfg.cn[1];
19245 if(this.labelWidth > 12){
19246 labelCfg.style = "width: " + this.labelWidth + 'px';
19249 if(this.labelWidth < 13 && this.labelmd == 0){
19250 this.labelmd = this.labelWidth;
19253 if(this.labellg > 0){
19254 labelCfg.cls += ' col-lg-' + this.labellg;
19255 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
19258 if(this.labelmd > 0){
19259 labelCfg.cls += ' col-md-' + this.labelmd;
19260 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
19263 if(this.labelsm > 0){
19264 labelCfg.cls += ' col-sm-' + this.labelsm;
19265 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
19268 if(this.labelxs > 0){
19269 labelCfg.cls += ' col-xs-' + this.labelxs;
19270 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
19274 } else if ( this.fieldLabel.length) {
19279 cls : 'control-label',
19280 html : this.fieldLabel
19291 if(this.indicatorpos == 'right'){
19295 cls : 'control-label',
19296 html : this.fieldLabel,
19314 var settings = this;
19316 ['xs','sm','md','lg'].map(function(size){
19317 if (settings[size]) {
19318 cfg.cls += ' col-' + size + '-' + settings[size];
19325 initTouchView : function()
19327 this.renderTouchView();
19329 this.touchViewEl.on('scroll', function(){
19330 this.el.dom.scrollTop = 0;
19333 this.originalValue = this.getValue();
19335 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
19337 this.inputEl().on("click", this.showTouchView, this);
19338 if (this.triggerEl) {
19339 this.triggerEl.on("click", this.showTouchView, this);
19343 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
19344 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
19346 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
19348 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
19349 this.store.on('load', this.onTouchViewLoad, this);
19350 this.store.on('loadexception', this.onTouchViewLoadException, this);
19352 if(this.hiddenName){
19354 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
19356 this.hiddenField.dom.value =
19357 this.hiddenValue !== undefined ? this.hiddenValue :
19358 this.value !== undefined ? this.value : '';
19360 this.el.dom.removeAttribute('name');
19361 this.hiddenField.dom.setAttribute('name', this.hiddenName);
19365 this.choices = this.el.select('ul.roo-select2-choices', true).first();
19366 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
19369 if(this.removable && !this.multiple){
19370 var close = this.closeTriggerEl();
19372 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
19373 close.on('click', this.removeBtnClick, this, close);
19377 * fix the bug in Safari iOS8
19379 this.inputEl().on("focus", function(e){
19380 document.activeElement.blur();
19383 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
19390 renderTouchView : function()
19392 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.form.ComboBox.touchViewTemplate);
19393 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19395 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
19396 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19398 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
19399 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19400 this.touchViewBodyEl.setStyle('overflow', 'auto');
19402 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
19403 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19405 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
19406 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19410 showTouchView : function()
19416 this.touchViewHeaderEl.hide();
19418 if(this.modalTitle.length){
19419 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
19420 this.touchViewHeaderEl.show();
19423 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
19424 this.touchViewEl.show();
19426 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
19428 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
19429 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
19431 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
19433 if(this.modalTitle.length){
19434 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
19437 this.touchViewBodyEl.setHeight(bodyHeight);
19441 (function(){ _this.touchViewEl.addClass(['in','show']); }).defer(50);
19443 this.touchViewEl.addClass(['in','show']);
19446 if(this._touchViewMask){
19447 Roo.get(document.body).addClass("x-body-masked");
19448 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
19449 this._touchViewMask.setStyle('z-index', 10000);
19450 this._touchViewMask.addClass('show');
19453 this.doTouchViewQuery();
19457 hideTouchView : function()
19459 this.touchViewEl.removeClass(['in','show']);
19463 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
19465 this.touchViewEl.setStyle('display', 'none');
19468 if(this._touchViewMask){
19469 this._touchViewMask.removeClass('show');
19470 Roo.get(document.body).removeClass("x-body-masked");
19474 setTouchViewValue : function()
19481 Roo.each(this.tickItems, function(o){
19486 this.hideTouchView();
19489 doTouchViewQuery : function()
19498 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
19502 if(!this.alwaysQuery || this.mode == 'local'){
19503 this.onTouchViewLoad();
19510 onTouchViewBeforeLoad : function(combo,opts)
19516 onTouchViewLoad : function()
19518 if(this.store.getCount() < 1){
19519 this.onTouchViewEmptyResults();
19523 this.clearTouchView();
19525 var rawValue = this.getRawValue();
19527 var template = (this.multiple) ? Roo.bootstrap.form.ComboBox.listItemCheckbox : Roo.bootstrap.form.ComboBox.listItemRadio;
19529 this.tickItems = [];
19531 this.store.data.each(function(d, rowIndex){
19532 var row = this.touchViewListGroup.createChild(template);
19534 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
19535 row.addClass(d.data.cls);
19538 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
19541 html : d.data[this.displayField]
19544 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
19545 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
19548 row.removeClass('selected');
19549 if(!this.multiple && this.valueField &&
19550 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
19553 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19554 row.addClass('selected');
19557 if(this.multiple && this.valueField &&
19558 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
19562 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19563 this.tickItems.push(d.data);
19566 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
19570 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
19572 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
19574 if(this.modalTitle.length){
19575 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
19578 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
19580 if(this.mobile_restrict_height && listHeight < bodyHeight){
19581 this.touchViewBodyEl.setHeight(listHeight);
19586 if(firstChecked && listHeight > bodyHeight){
19587 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
19592 onTouchViewLoadException : function()
19594 this.hideTouchView();
19597 onTouchViewEmptyResults : function()
19599 this.clearTouchView();
19601 this.touchViewListGroup.createChild(Roo.bootstrap.form.ComboBox.emptyResult);
19603 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
19607 clearTouchView : function()
19609 this.touchViewListGroup.dom.innerHTML = '';
19612 onTouchViewClick : function(e, el, o)
19614 e.preventDefault();
19617 var rowIndex = o.rowIndex;
19619 var r = this.store.getAt(rowIndex);
19621 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
19623 if(!this.multiple){
19624 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
19625 c.dom.removeAttribute('checked');
19628 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19630 this.setFromData(r.data);
19632 var close = this.closeTriggerEl();
19638 this.hideTouchView();
19640 this.fireEvent('select', this, r, rowIndex);
19645 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
19646 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
19647 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
19651 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19652 this.addItem(r.data);
19653 this.tickItems.push(r.data);
19657 getAutoCreateNativeIOS : function()
19660 cls: 'form-group' //input-group,
19665 cls : 'roo-ios-select'
19669 combobox.name = this.name;
19672 if (this.disabled) {
19673 combobox.disabled = true;
19676 var settings = this;
19678 ['xs','sm','md','lg'].map(function(size){
19679 if (settings[size]) {
19680 cfg.cls += ' col-' + size + '-' + settings[size];
19690 initIOSView : function()
19692 this.store.on('load', this.onIOSViewLoad, this);
19697 onIOSViewLoad : function()
19699 if(this.store.getCount() < 1){
19703 this.clearIOSView();
19705 if(this.allowBlank) {
19707 var default_text = '-- SELECT --';
19709 if(this.placeholder.length){
19710 default_text = this.placeholder;
19713 if(this.emptyTitle.length){
19714 default_text += ' - ' + this.emptyTitle + ' -';
19717 var opt = this.inputEl().createChild({
19720 html : default_text
19724 o[this.valueField] = 0;
19725 o[this.displayField] = default_text;
19727 this.ios_options.push({
19734 this.store.data.each(function(d, rowIndex){
19738 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
19739 html = d.data[this.displayField];
19744 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
19745 value = d.data[this.valueField];
19754 if(this.value == d.data[this.valueField]){
19755 option['selected'] = true;
19758 var opt = this.inputEl().createChild(option);
19760 this.ios_options.push({
19767 this.inputEl().on('change', function(){
19768 this.fireEvent('select', this);
19773 clearIOSView: function()
19775 this.inputEl().dom.innerHTML = '';
19777 this.ios_options = [];
19780 setIOSValue: function(v)
19784 if(!this.ios_options){
19788 Roo.each(this.ios_options, function(opts){
19790 opts.el.dom.removeAttribute('selected');
19792 if(opts.data[this.valueField] != v){
19796 opts.el.dom.setAttribute('selected', true);
19802 * @cfg {Boolean} grow
19806 * @cfg {Number} growMin
19810 * @cfg {Number} growMax
19819 Roo.apply(Roo.bootstrap.form.ComboBox, {
19823 cls: 'modal-header',
19845 cls: 'list-group-item',
19849 cls: 'roo-combobox-list-group-item-value'
19853 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
19867 listItemCheckbox : {
19869 cls: 'list-group-item',
19873 cls: 'roo-combobox-list-group-item-value'
19877 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
19893 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
19898 cls: 'modal-footer',
19906 cls: 'col-xs-6 text-left',
19909 cls: 'btn btn-danger roo-touch-view-cancel',
19915 cls: 'col-xs-6 text-right',
19918 cls: 'btn btn-success roo-touch-view-ok',
19929 Roo.apply(Roo.bootstrap.form.ComboBox, {
19931 touchViewTemplate : {
19933 cls: 'modal fade roo-combobox-touch-view',
19937 cls: 'modal-dialog',
19938 style : 'position:fixed', // we have to fix position....
19942 cls: 'modal-content',
19944 Roo.bootstrap.form.ComboBox.header,
19945 Roo.bootstrap.form.ComboBox.body,
19946 Roo.bootstrap.form.ComboBox.footer
19955 * Ext JS Library 1.1.1
19956 * Copyright(c) 2006-2007, Ext JS, LLC.
19958 * Originally Released Under LGPL - original licence link has changed is not relivant.
19961 * <script type="text/javascript">
19966 * @extends Roo.util.Observable
19967 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
19968 * This class also supports single and multi selection modes. <br>
19969 * Create a data model bound view:
19971 var store = new Roo.data.Store(...);
19973 var view = new Roo.View({
19975 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
19977 singleSelect: true,
19978 selectedClass: "ydataview-selected",
19982 // listen for node click?
19983 view.on("click", function(vw, index, node, e){
19984 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
19988 dataModel.load("foobar.xml");
19990 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
19992 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
19993 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
19995 * Note: old style constructor is still suported (container, template, config)
19998 * Create a new View
19999 * @param {Object} config The config object
20002 Roo.View = function(config, depreciated_tpl, depreciated_config){
20004 this.parent = false;
20006 if (typeof(depreciated_tpl) == 'undefined') {
20007 // new way.. - universal constructor.
20008 Roo.apply(this, config);
20009 this.el = Roo.get(this.el);
20012 this.el = Roo.get(config);
20013 this.tpl = depreciated_tpl;
20014 Roo.apply(this, depreciated_config);
20016 this.wrapEl = this.el.wrap().wrap();
20017 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
20020 if(typeof(this.tpl) == "string"){
20021 this.tpl = new Roo.Template(this.tpl);
20023 // support xtype ctors..
20024 this.tpl = new Roo.factory(this.tpl, Roo);
20028 this.tpl.compile();
20033 * @event beforeclick
20034 * Fires before a click is processed. Returns false to cancel the default action.
20035 * @param {Roo.View} this
20036 * @param {Number} index The index of the target node
20037 * @param {HTMLElement} node The target node
20038 * @param {Roo.EventObject} e The raw event object
20040 "beforeclick" : true,
20043 * Fires when a template node is clicked.
20044 * @param {Roo.View} this
20045 * @param {Number} index The index of the target node
20046 * @param {HTMLElement} node The target node
20047 * @param {Roo.EventObject} e The raw event object
20052 * Fires when a template node is double clicked.
20053 * @param {Roo.View} this
20054 * @param {Number} index The index of the target node
20055 * @param {HTMLElement} node The target node
20056 * @param {Roo.EventObject} e The raw event object
20060 * @event contextmenu
20061 * Fires when a template node is right clicked.
20062 * @param {Roo.View} this
20063 * @param {Number} index The index of the target node
20064 * @param {HTMLElement} node The target node
20065 * @param {Roo.EventObject} e The raw event object
20067 "contextmenu" : true,
20069 * @event selectionchange
20070 * Fires when the selected nodes change.
20071 * @param {Roo.View} this
20072 * @param {Array} selections Array of the selected nodes
20074 "selectionchange" : true,
20077 * @event beforeselect
20078 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
20079 * @param {Roo.View} this
20080 * @param {HTMLElement} node The node to be selected
20081 * @param {Array} selections Array of currently selected nodes
20083 "beforeselect" : true,
20085 * @event preparedata
20086 * Fires on every row to render, to allow you to change the data.
20087 * @param {Roo.View} this
20088 * @param {Object} data to be rendered (change this)
20090 "preparedata" : true
20098 "click": this.onClick,
20099 "dblclick": this.onDblClick,
20100 "contextmenu": this.onContextMenu,
20104 this.selections = [];
20106 this.cmp = new Roo.CompositeElementLite([]);
20108 this.store = Roo.factory(this.store, Roo.data);
20109 this.setStore(this.store, true);
20112 if ( this.footer && this.footer.xtype) {
20114 var fctr = this.wrapEl.appendChild(document.createElement("div"));
20116 this.footer.dataSource = this.store;
20117 this.footer.container = fctr;
20118 this.footer = Roo.factory(this.footer, Roo);
20119 fctr.insertFirst(this.el);
20121 // this is a bit insane - as the paging toolbar seems to detach the el..
20122 // dom.parentNode.parentNode.parentNode
20123 // they get detached?
20127 Roo.View.superclass.constructor.call(this);
20132 Roo.extend(Roo.View, Roo.util.Observable, {
20135 * @cfg {Roo.data.Store} store Data store to load data from.
20140 * @cfg {String|Roo.Element} el The container element.
20145 * @cfg {String|Roo.Template} tpl The template used by this View
20149 * @cfg {String} dataName the named area of the template to use as the data area
20150 * Works with domtemplates roo-name="name"
20154 * @cfg {String} selectedClass The css class to add to selected nodes
20156 selectedClass : "x-view-selected",
20158 * @cfg {String} emptyText The empty text to show when nothing is loaded.
20163 * @cfg {String} text to display on mask (default Loading)
20167 * @cfg {Boolean} multiSelect Allow multiple selection
20169 multiSelect : false,
20171 * @cfg {Boolean} singleSelect Allow single selection
20173 singleSelect: false,
20176 * @cfg {Boolean} toggleSelect - selecting
20178 toggleSelect : false,
20181 * @cfg {Boolean} tickable - selecting
20186 * Returns the element this view is bound to.
20187 * @return {Roo.Element}
20189 getEl : function(){
20190 return this.wrapEl;
20196 * Refreshes the view. - called by datachanged on the store. - do not call directly.
20198 refresh : function(){
20199 //Roo.log('refresh');
20202 // if we are using something like 'domtemplate', then
20203 // the what gets used is:
20204 // t.applySubtemplate(NAME, data, wrapping data..)
20205 // the outer template then get' applied with
20206 // the store 'extra data'
20207 // and the body get's added to the
20208 // roo-name="data" node?
20209 // <span class='roo-tpl-{name}'></span> ?????
20213 this.clearSelections();
20214 this.el.update("");
20216 var records = this.store.getRange();
20217 if(records.length < 1) {
20219 // is this valid?? = should it render a template??
20221 this.el.update(this.emptyText);
20225 if (this.dataName) {
20226 this.el.update(t.apply(this.store.meta)); //????
20227 el = this.el.child('.roo-tpl-' + this.dataName);
20230 for(var i = 0, len = records.length; i < len; i++){
20231 var data = this.prepareData(records[i].data, i, records[i]);
20232 this.fireEvent("preparedata", this, data, i, records[i]);
20234 var d = Roo.apply({}, data);
20237 Roo.apply(d, {'roo-id' : Roo.id()});
20241 Roo.each(this.parent.item, function(item){
20242 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
20245 Roo.apply(d, {'roo-data-checked' : 'checked'});
20249 html[html.length] = Roo.util.Format.trim(
20251 t.applySubtemplate(this.dataName, d, this.store.meta) :
20258 el.update(html.join(""));
20259 this.nodes = el.dom.childNodes;
20260 this.updateIndexes(0);
20265 * Function to override to reformat the data that is sent to
20266 * the template for each node.
20267 * DEPRICATED - use the preparedata event handler.
20268 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
20269 * a JSON object for an UpdateManager bound view).
20271 prepareData : function(data, index, record)
20273 this.fireEvent("preparedata", this, data, index, record);
20277 onUpdate : function(ds, record){
20278 // Roo.log('on update');
20279 this.clearSelections();
20280 var index = this.store.indexOf(record);
20281 var n = this.nodes[index];
20282 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
20283 n.parentNode.removeChild(n);
20284 this.updateIndexes(index, index);
20290 onAdd : function(ds, records, index)
20292 //Roo.log(['on Add', ds, records, index] );
20293 this.clearSelections();
20294 if(this.nodes.length == 0){
20298 var n = this.nodes[index];
20299 for(var i = 0, len = records.length; i < len; i++){
20300 var d = this.prepareData(records[i].data, i, records[i]);
20302 this.tpl.insertBefore(n, d);
20305 this.tpl.append(this.el, d);
20308 this.updateIndexes(index);
20311 onRemove : function(ds, record, index){
20312 // Roo.log('onRemove');
20313 this.clearSelections();
20314 var el = this.dataName ?
20315 this.el.child('.roo-tpl-' + this.dataName) :
20318 el.dom.removeChild(this.nodes[index]);
20319 this.updateIndexes(index);
20323 * Refresh an individual node.
20324 * @param {Number} index
20326 refreshNode : function(index){
20327 this.onUpdate(this.store, this.store.getAt(index));
20330 updateIndexes : function(startIndex, endIndex){
20331 var ns = this.nodes;
20332 startIndex = startIndex || 0;
20333 endIndex = endIndex || ns.length - 1;
20334 for(var i = startIndex; i <= endIndex; i++){
20335 ns[i].nodeIndex = i;
20340 * Changes the data store this view uses and refresh the view.
20341 * @param {Store} store
20343 setStore : function(store, initial){
20344 if(!initial && this.store){
20345 this.store.un("datachanged", this.refresh);
20346 this.store.un("add", this.onAdd);
20347 this.store.un("remove", this.onRemove);
20348 this.store.un("update", this.onUpdate);
20349 this.store.un("clear", this.refresh);
20350 this.store.un("beforeload", this.onBeforeLoad);
20351 this.store.un("load", this.onLoad);
20352 this.store.un("loadexception", this.onLoad);
20356 store.on("datachanged", this.refresh, this);
20357 store.on("add", this.onAdd, this);
20358 store.on("remove", this.onRemove, this);
20359 store.on("update", this.onUpdate, this);
20360 store.on("clear", this.refresh, this);
20361 store.on("beforeload", this.onBeforeLoad, this);
20362 store.on("load", this.onLoad, this);
20363 store.on("loadexception", this.onLoad, this);
20371 * onbeforeLoad - masks the loading area.
20374 onBeforeLoad : function(store,opts)
20376 //Roo.log('onBeforeLoad');
20378 this.el.update("");
20380 this.el.mask(this.mask ? this.mask : "Loading" );
20382 onLoad : function ()
20389 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
20390 * @param {HTMLElement} node
20391 * @return {HTMLElement} The template node
20393 findItemFromChild : function(node){
20394 var el = this.dataName ?
20395 this.el.child('.roo-tpl-' + this.dataName,true) :
20398 if(!node || node.parentNode == el){
20401 var p = node.parentNode;
20402 while(p && p != el){
20403 if(p.parentNode == el){
20412 onClick : function(e){
20413 var item = this.findItemFromChild(e.getTarget());
20415 var index = this.indexOf(item);
20416 if(this.onItemClick(item, index, e) !== false){
20417 this.fireEvent("click", this, index, item, e);
20420 this.clearSelections();
20425 onContextMenu : function(e){
20426 var item = this.findItemFromChild(e.getTarget());
20428 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
20433 onDblClick : function(e){
20434 var item = this.findItemFromChild(e.getTarget());
20436 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
20440 onItemClick : function(item, index, e)
20442 if(this.fireEvent("beforeclick", this, index, item, e) === false){
20445 if (this.toggleSelect) {
20446 var m = this.isSelected(item) ? 'unselect' : 'select';
20449 _t[m](item, true, false);
20452 if(this.multiSelect || this.singleSelect){
20453 if(this.multiSelect && e.shiftKey && this.lastSelection){
20454 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
20456 this.select(item, this.multiSelect && e.ctrlKey);
20457 this.lastSelection = item;
20460 if(!this.tickable){
20461 e.preventDefault();
20469 * Get the number of selected nodes.
20472 getSelectionCount : function(){
20473 return this.selections.length;
20477 * Get the currently selected nodes.
20478 * @return {Array} An array of HTMLElements
20480 getSelectedNodes : function(){
20481 return this.selections;
20485 * Get the indexes of the selected nodes.
20488 getSelectedIndexes : function(){
20489 var indexes = [], s = this.selections;
20490 for(var i = 0, len = s.length; i < len; i++){
20491 indexes.push(s[i].nodeIndex);
20497 * Clear all selections
20498 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
20500 clearSelections : function(suppressEvent){
20501 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
20502 this.cmp.elements = this.selections;
20503 this.cmp.removeClass(this.selectedClass);
20504 this.selections = [];
20505 if(!suppressEvent){
20506 this.fireEvent("selectionchange", this, this.selections);
20512 * Returns true if the passed node is selected
20513 * @param {HTMLElement/Number} node The node or node index
20514 * @return {Boolean}
20516 isSelected : function(node){
20517 var s = this.selections;
20521 node = this.getNode(node);
20522 return s.indexOf(node) !== -1;
20527 * @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node, id of a template node or an array of any of those to select
20528 * @param {Boolean} keepExisting (optional) true to keep existing selections
20529 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
20531 select : function(nodeInfo, keepExisting, suppressEvent){
20532 if(nodeInfo instanceof Array){
20534 this.clearSelections(true);
20536 for(var i = 0, len = nodeInfo.length; i < len; i++){
20537 this.select(nodeInfo[i], true, true);
20541 var node = this.getNode(nodeInfo);
20542 if(!node || this.isSelected(node)){
20543 return; // already selected.
20546 this.clearSelections(true);
20549 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
20550 Roo.fly(node).addClass(this.selectedClass);
20551 this.selections.push(node);
20552 if(!suppressEvent){
20553 this.fireEvent("selectionchange", this, this.selections);
20561 * @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node, id of a template node or an array of any of those to select
20562 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
20563 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
20565 unselect : function(nodeInfo, keepExisting, suppressEvent)
20567 if(nodeInfo instanceof Array){
20568 Roo.each(this.selections, function(s) {
20569 this.unselect(s, nodeInfo);
20573 var node = this.getNode(nodeInfo);
20574 if(!node || !this.isSelected(node)){
20575 //Roo.log("not selected");
20576 return; // not selected.
20580 Roo.each(this.selections, function(s) {
20582 Roo.fly(node).removeClass(this.selectedClass);
20589 this.selections= ns;
20590 this.fireEvent("selectionchange", this, this.selections);
20594 * Gets a template node.
20595 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
20596 * @return {HTMLElement} The node or null if it wasn't found
20598 getNode : function(nodeInfo){
20599 if(typeof nodeInfo == "string"){
20600 return document.getElementById(nodeInfo);
20601 }else if(typeof nodeInfo == "number"){
20602 return this.nodes[nodeInfo];
20608 * Gets a range template nodes.
20609 * @param {Number} startIndex
20610 * @param {Number} endIndex
20611 * @return {Array} An array of nodes
20613 getNodes : function(start, end){
20614 var ns = this.nodes;
20615 start = start || 0;
20616 end = typeof end == "undefined" ? ns.length - 1 : end;
20619 for(var i = start; i <= end; i++){
20623 for(var i = start; i >= end; i--){
20631 * Finds the index of the passed node
20632 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
20633 * @return {Number} The index of the node or -1
20635 indexOf : function(node){
20636 node = this.getNode(node);
20637 if(typeof node.nodeIndex == "number"){
20638 return node.nodeIndex;
20640 var ns = this.nodes;
20641 for(var i = 0, len = ns.length; i < len; i++){
20652 * based on jquery fullcalendar
20656 Roo.bootstrap = Roo.bootstrap || {};
20658 * @class Roo.bootstrap.Calendar
20659 * @extends Roo.bootstrap.Component
20660 * Bootstrap Calendar class
20661 * @cfg {Boolean} loadMask (true|false) default false
20662 * @cfg {Object} header generate the user specific header of the calendar, default false
20665 * Create a new Container
20666 * @param {Object} config The config object
20671 Roo.bootstrap.Calendar = function(config){
20672 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
20676 * Fires when a date is selected
20677 * @param {DatePicker} this
20678 * @param {Date} date The selected date
20682 * @event monthchange
20683 * Fires when the displayed month changes
20684 * @param {DatePicker} this
20685 * @param {Date} date The selected month
20687 'monthchange': true,
20689 * @event evententer
20690 * Fires when mouse over an event
20691 * @param {Calendar} this
20692 * @param {event} Event
20694 'evententer': true,
20696 * @event eventleave
20697 * Fires when the mouse leaves an
20698 * @param {Calendar} this
20701 'eventleave': true,
20703 * @event eventclick
20704 * Fires when the mouse click an
20705 * @param {Calendar} this
20714 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
20717 * @cfg {Roo.data.Store} store
20718 * The data source for the calendar
20722 * @cfg {Number} startDay
20723 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
20731 getAutoCreate : function(){
20734 var fc_button = function(name, corner, style, content ) {
20735 return Roo.apply({},{
20737 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
20739 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
20742 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
20753 style : 'width:100%',
20760 cls : 'fc-header-left',
20762 fc_button('prev', 'left', 'arrow', '‹' ),
20763 fc_button('next', 'right', 'arrow', '›' ),
20764 { tag: 'span', cls: 'fc-header-space' },
20765 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
20773 cls : 'fc-header-center',
20777 cls: 'fc-header-title',
20780 html : 'month / year'
20788 cls : 'fc-header-right',
20790 /* fc_button('month', 'left', '', 'month' ),
20791 fc_button('week', '', '', 'week' ),
20792 fc_button('day', 'right', '', 'day' )
20804 header = this.header;
20807 var cal_heads = function() {
20809 // fixme - handle this.
20811 for (var i =0; i < Date.dayNames.length; i++) {
20812 var d = Date.dayNames[i];
20815 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
20816 html : d.substring(0,3)
20820 ret[0].cls += ' fc-first';
20821 ret[6].cls += ' fc-last';
20824 var cal_cell = function(n) {
20827 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
20832 cls: 'fc-day-number',
20836 cls: 'fc-day-content',
20840 style: 'position: relative;' // height: 17px;
20852 var cal_rows = function() {
20855 for (var r = 0; r < 6; r++) {
20862 for (var i =0; i < Date.dayNames.length; i++) {
20863 var d = Date.dayNames[i];
20864 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
20867 row.cn[0].cls+=' fc-first';
20868 row.cn[0].cn[0].style = 'min-height:90px';
20869 row.cn[6].cls+=' fc-last';
20873 ret[0].cls += ' fc-first';
20874 ret[4].cls += ' fc-prev-last';
20875 ret[5].cls += ' fc-last';
20882 cls: 'fc-border-separate',
20883 style : 'width:100%',
20891 cls : 'fc-first fc-last',
20909 cls : 'fc-content',
20910 style : "position: relative;",
20913 cls : 'fc-view fc-view-month fc-grid',
20914 style : 'position: relative',
20915 unselectable : 'on',
20918 cls : 'fc-event-container',
20919 style : 'position:absolute;z-index:8;top:0;left:0;'
20937 initEvents : function()
20940 throw "can not find store for calendar";
20946 style: "text-align:center",
20950 style: "background-color:white;width:50%;margin:250 auto",
20954 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
20965 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
20967 var size = this.el.select('.fc-content', true).first().getSize();
20968 this.maskEl.setSize(size.width, size.height);
20969 this.maskEl.enableDisplayMode("block");
20970 if(!this.loadMask){
20971 this.maskEl.hide();
20974 this.store = Roo.factory(this.store, Roo.data);
20975 this.store.on('load', this.onLoad, this);
20976 this.store.on('beforeload', this.onBeforeLoad, this);
20980 this.cells = this.el.select('.fc-day',true);
20981 //Roo.log(this.cells);
20982 this.textNodes = this.el.query('.fc-day-number');
20983 this.cells.addClassOnOver('fc-state-hover');
20985 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
20986 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
20987 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
20988 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
20990 this.on('monthchange', this.onMonthChange, this);
20992 this.update(new Date().clearTime());
20995 resize : function() {
20996 var sz = this.el.getSize();
20998 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
20999 this.el.select('.fc-day-content div',true).setHeight(34);
21004 showPrevMonth : function(e){
21005 this.update(this.activeDate.add("mo", -1));
21007 showToday : function(e){
21008 this.update(new Date().clearTime());
21011 showNextMonth : function(e){
21012 this.update(this.activeDate.add("mo", 1));
21016 showPrevYear : function(){
21017 this.update(this.activeDate.add("y", -1));
21021 showNextYear : function(){
21022 this.update(this.activeDate.add("y", 1));
21027 update : function(date)
21029 var vd = this.activeDate;
21030 this.activeDate = date;
21031 // if(vd && this.el){
21032 // var t = date.getTime();
21033 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
21034 // Roo.log('using add remove');
21036 // this.fireEvent('monthchange', this, date);
21038 // this.cells.removeClass("fc-state-highlight");
21039 // this.cells.each(function(c){
21040 // if(c.dateValue == t){
21041 // c.addClass("fc-state-highlight");
21042 // setTimeout(function(){
21043 // try{c.dom.firstChild.focus();}catch(e){}
21053 var days = date.getDaysInMonth();
21055 var firstOfMonth = date.getFirstDateOfMonth();
21056 var startingPos = firstOfMonth.getDay()-this.startDay;
21058 if(startingPos < this.startDay){
21062 var pm = date.add(Date.MONTH, -1);
21063 var prevStart = pm.getDaysInMonth()-startingPos;
21065 this.cells = this.el.select('.fc-day',true);
21066 this.textNodes = this.el.query('.fc-day-number');
21067 this.cells.addClassOnOver('fc-state-hover');
21069 var cells = this.cells.elements;
21070 var textEls = this.textNodes;
21072 Roo.each(cells, function(cell){
21073 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
21076 days += startingPos;
21078 // convert everything to numbers so it's fast
21079 var day = 86400000;
21080 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
21083 //Roo.log(prevStart);
21085 var today = new Date().clearTime().getTime();
21086 var sel = date.clearTime().getTime();
21087 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
21088 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
21089 var ddMatch = this.disabledDatesRE;
21090 var ddText = this.disabledDatesText;
21091 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
21092 var ddaysText = this.disabledDaysText;
21093 var format = this.format;
21095 var setCellClass = function(cal, cell){
21099 //Roo.log('set Cell Class');
21101 var t = d.getTime();
21105 cell.dateValue = t;
21107 cell.className += " fc-today";
21108 cell.className += " fc-state-highlight";
21109 cell.title = cal.todayText;
21112 // disable highlight in other month..
21113 //cell.className += " fc-state-highlight";
21118 cell.className = " fc-state-disabled";
21119 cell.title = cal.minText;
21123 cell.className = " fc-state-disabled";
21124 cell.title = cal.maxText;
21128 if(ddays.indexOf(d.getDay()) != -1){
21129 cell.title = ddaysText;
21130 cell.className = " fc-state-disabled";
21133 if(ddMatch && format){
21134 var fvalue = d.dateFormat(format);
21135 if(ddMatch.test(fvalue)){
21136 cell.title = ddText.replace("%0", fvalue);
21137 cell.className = " fc-state-disabled";
21141 if (!cell.initialClassName) {
21142 cell.initialClassName = cell.dom.className;
21145 cell.dom.className = cell.initialClassName + ' ' + cell.className;
21150 for(; i < startingPos; i++) {
21151 textEls[i].innerHTML = (++prevStart);
21152 d.setDate(d.getDate()+1);
21154 cells[i].className = "fc-past fc-other-month";
21155 setCellClass(this, cells[i]);
21160 for(; i < days; i++){
21161 intDay = i - startingPos + 1;
21162 textEls[i].innerHTML = (intDay);
21163 d.setDate(d.getDate()+1);
21165 cells[i].className = ''; // "x-date-active";
21166 setCellClass(this, cells[i]);
21170 for(; i < 42; i++) {
21171 textEls[i].innerHTML = (++extraDays);
21172 d.setDate(d.getDate()+1);
21174 cells[i].className = "fc-future fc-other-month";
21175 setCellClass(this, cells[i]);
21178 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
21180 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
21182 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
21183 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
21185 if(totalRows != 6){
21186 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
21187 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
21190 this.fireEvent('monthchange', this, date);
21194 if(!this.internalRender){
21195 var main = this.el.dom.firstChild;
21196 var w = main.offsetWidth;
21197 this.el.setWidth(w + this.el.getBorderWidth("lr"));
21198 Roo.fly(main).setWidth(w);
21199 this.internalRender = true;
21200 // opera does not respect the auto grow header center column
21201 // then, after it gets a width opera refuses to recalculate
21202 // without a second pass
21203 if(Roo.isOpera && !this.secondPass){
21204 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
21205 this.secondPass = true;
21206 this.update.defer(10, this, [date]);
21213 findCell : function(dt) {
21214 dt = dt.clearTime().getTime();
21216 this.cells.each(function(c){
21217 //Roo.log("check " +c.dateValue + '?=' + dt);
21218 if(c.dateValue == dt){
21228 findCells : function(ev) {
21229 var s = ev.start.clone().clearTime().getTime();
21231 var e= ev.end.clone().clearTime().getTime();
21234 this.cells.each(function(c){
21235 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
21237 if(c.dateValue > e){
21240 if(c.dateValue < s){
21249 // findBestRow: function(cells)
21253 // for (var i =0 ; i < cells.length;i++) {
21254 // ret = Math.max(cells[i].rows || 0,ret);
21261 addItem : function(ev)
21263 // look for vertical location slot in
21264 var cells = this.findCells(ev);
21266 // ev.row = this.findBestRow(cells);
21268 // work out the location.
21272 for(var i =0; i < cells.length; i++) {
21274 cells[i].row = cells[0].row;
21277 cells[i].row = cells[i].row + 1;
21287 if (crow.start.getY() == cells[i].getY()) {
21289 crow.end = cells[i];
21306 cells[0].events.push(ev);
21308 this.calevents.push(ev);
21311 clearEvents: function() {
21313 if(!this.calevents){
21317 Roo.each(this.cells.elements, function(c){
21323 Roo.each(this.calevents, function(e) {
21324 Roo.each(e.els, function(el) {
21325 el.un('mouseenter' ,this.onEventEnter, this);
21326 el.un('mouseleave' ,this.onEventLeave, this);
21331 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
21337 renderEvents: function()
21341 this.cells.each(function(c) {
21350 if(c.row != c.events.length){
21351 r = 4 - (4 - (c.row - c.events.length));
21354 c.events = ev.slice(0, r);
21355 c.more = ev.slice(r);
21357 if(c.more.length && c.more.length == 1){
21358 c.events.push(c.more.pop());
21361 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
21365 this.cells.each(function(c) {
21367 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
21370 for (var e = 0; e < c.events.length; e++){
21371 var ev = c.events[e];
21372 var rows = ev.rows;
21374 for(var i = 0; i < rows.length; i++) {
21376 // how many rows should it span..
21379 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
21380 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
21382 unselectable : "on",
21385 cls: 'fc-event-inner',
21389 // cls: 'fc-event-time',
21390 // html : cells.length > 1 ? '' : ev.time
21394 cls: 'fc-event-title',
21395 html : String.format('{0}', ev.title)
21402 cls: 'ui-resizable-handle ui-resizable-e',
21403 html : '  '
21410 cfg.cls += ' fc-event-start';
21412 if ((i+1) == rows.length) {
21413 cfg.cls += ' fc-event-end';
21416 var ctr = _this.el.select('.fc-event-container',true).first();
21417 var cg = ctr.createChild(cfg);
21419 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
21420 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
21422 var r = (c.more.length) ? 1 : 0;
21423 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
21424 cg.setWidth(ebox.right - sbox.x -2);
21426 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
21427 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
21428 cg.on('click', _this.onEventClick, _this, ev);
21439 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
21440 style : 'position: absolute',
21441 unselectable : "on",
21444 cls: 'fc-event-inner',
21448 cls: 'fc-event-title',
21456 cls: 'ui-resizable-handle ui-resizable-e',
21457 html : '  '
21463 var ctr = _this.el.select('.fc-event-container',true).first();
21464 var cg = ctr.createChild(cfg);
21466 var sbox = c.select('.fc-day-content',true).first().getBox();
21467 var ebox = c.select('.fc-day-content',true).first().getBox();
21469 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
21470 cg.setWidth(ebox.right - sbox.x -2);
21472 cg.on('click', _this.onMoreEventClick, _this, c.more);
21482 onEventEnter: function (e, el,event,d) {
21483 this.fireEvent('evententer', this, el, event);
21486 onEventLeave: function (e, el,event,d) {
21487 this.fireEvent('eventleave', this, el, event);
21490 onEventClick: function (e, el,event,d) {
21491 this.fireEvent('eventclick', this, el, event);
21494 onMonthChange: function () {
21498 onMoreEventClick: function(e, el, more)
21502 this.calpopover.placement = 'right';
21503 this.calpopover.setTitle('More');
21505 this.calpopover.setContent('');
21507 var ctr = this.calpopover.el.select('.popover-content', true).first();
21509 Roo.each(more, function(m){
21511 cls : 'fc-event-hori fc-event-draggable',
21514 var cg = ctr.createChild(cfg);
21516 cg.on('click', _this.onEventClick, _this, m);
21519 this.calpopover.show(el);
21524 onLoad: function ()
21526 this.calevents = [];
21529 if(this.store.getCount() > 0){
21530 this.store.data.each(function(d){
21533 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
21534 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
21535 time : d.data.start_time,
21536 title : d.data.title,
21537 description : d.data.description,
21538 venue : d.data.venue
21543 this.renderEvents();
21545 if(this.calevents.length && this.loadMask){
21546 this.maskEl.hide();
21550 onBeforeLoad: function()
21552 this.clearEvents();
21554 this.maskEl.show();
21568 * @class Roo.bootstrap.Popover
21569 * @extends Roo.bootstrap.Component
21570 * @parent none builder
21571 * @children Roo.bootstrap.Component
21572 * Bootstrap Popover class
21573 * @cfg {String} html contents of the popover (or false to use children..)
21574 * @cfg {String} title of popover (or false to hide)
21575 * @cfg {String|function} (right|top|bottom|left|auto) placement how it is placed
21576 * @cfg {String} trigger click || hover (or false to trigger manually)
21577 * @cfg {Boolean} modal - popovers that are modal will mask the screen, and must be closed with another event.
21578 * @cfg {String|Boolean|Roo.Element} add click hander to trigger show over what element
21579 * - if false and it has a 'parent' then it will be automatically added to that element
21580 * - if string - Roo.get will be called
21581 * @cfg {Number} delay - delay before showing
21584 * Create a new Popover
21585 * @param {Object} config The config object
21588 Roo.bootstrap.Popover = function(config){
21589 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
21595 * After the popover show
21597 * @param {Roo.bootstrap.Popover} this
21602 * After the popover hide
21604 * @param {Roo.bootstrap.Popover} this
21610 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
21615 placement : 'right',
21616 trigger : 'hover', // hover
21622 can_build_overlaid : false,
21624 maskEl : false, // the mask element
21627 alignEl : false, // when show is called with an element - this get's stored.
21629 getChildContainer : function()
21631 return this.contentEl;
21634 getPopoverHeader : function()
21636 this.title = true; // flag not to hide it..
21637 this.headerEl.addClass('p-0');
21638 return this.headerEl
21642 getAutoCreate : function(){
21645 cls : 'popover roo-dynamic shadow roo-popover' + (this.modal ? '-modal' : ''),
21646 style: 'display:block',
21652 cls : 'popover-inner ',
21656 cls: 'popover-title popover-header',
21657 html : this.title === false ? '' : this.title
21660 cls : 'popover-content popover-body ' + (this.cls || ''),
21661 html : this.html || ''
21672 * @param {string} the title
21674 setTitle: function(str)
21678 this.headerEl.dom.innerHTML = str;
21683 * @param {string} the body content
21685 setContent: function(str)
21688 if (this.contentEl) {
21689 this.contentEl.dom.innerHTML = str;
21693 // as it get's added to the bottom of the page.
21694 onRender : function(ct, position)
21696 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
21701 var cfg = Roo.apply({}, this.getAutoCreate());
21705 cfg.cls += ' ' + this.cls;
21708 cfg.style = this.style;
21710 //Roo.log("adding to ");
21711 this.el = Roo.get(document.body).createChild(cfg, position);
21712 // Roo.log(this.el);
21715 this.contentEl = this.el.select('.popover-content',true).first();
21716 this.headerEl = this.el.select('.popover-title',true).first();
21719 if(typeof(this.items) != 'undefined'){
21720 var items = this.items;
21723 for(var i =0;i < items.length;i++) {
21724 nitems.push(this.addxtype(Roo.apply({}, items[i])));
21728 this.items = nitems;
21730 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
21731 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
21738 resizeMask : function()
21740 this.maskEl.setSize(
21741 Roo.lib.Dom.getViewWidth(true),
21742 Roo.lib.Dom.getViewHeight(true)
21746 initEvents : function()
21750 Roo.bootstrap.Popover.register(this);
21753 this.arrowEl = this.el.select('.arrow',true).first();
21754 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY); // probably not needed as it's default in BS4
21755 this.el.enableDisplayMode('block');
21759 if (this.over === false && !this.parent()) {
21762 if (this.triggers === false) {
21767 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
21768 var triggers = this.trigger ? this.trigger.split(' ') : [];
21769 Roo.each(triggers, function(trigger) {
21771 if (trigger == 'click') {
21772 on_el.on('click', this.toggle, this);
21773 } else if (trigger != 'manual') {
21774 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
21775 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
21777 on_el.on(eventIn ,this.enter, this);
21778 on_el.on(eventOut, this.leave, this);
21788 toggle : function () {
21789 this.hoverState == 'in' ? this.leave() : this.enter();
21792 enter : function () {
21794 clearTimeout(this.timeout);
21796 this.hoverState = 'in';
21798 if (!this.delay || !this.delay.show) {
21803 this.timeout = setTimeout(function () {
21804 if (_t.hoverState == 'in') {
21807 }, this.delay.show)
21810 leave : function() {
21811 clearTimeout(this.timeout);
21813 this.hoverState = 'out';
21815 if (!this.delay || !this.delay.hide) {
21820 this.timeout = setTimeout(function () {
21821 if (_t.hoverState == 'out') {
21824 }, this.delay.hide)
21828 * update the position of the dialog
21829 * normally this is needed if the popover get's bigger - due to a Table reload etc..
21834 doAlign : function()
21837 if (this.alignEl) {
21838 this.updatePosition(this.placement, true);
21841 // this is usually just done by the builder = to show the popoup in the middle of the scren.
21842 var es = this.el.getSize();
21843 var x = Roo.lib.Dom.getViewWidth()/2;
21844 var y = Roo.lib.Dom.getViewHeight()/2;
21845 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
21857 * @param {Roo.Element|string|Boolean} - element to align and point to. (set align to [ pos, offset ])
21858 * @param {string} (left|right|top|bottom) position
21860 show : function (on_el, placement)
21862 this.placement = typeof(placement) == 'undefined' ? this.placement : placement;
21863 on_el = on_el || false; // default to false
21866 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
21867 on_el = this.parent().el;
21868 } else if (this.over) {
21869 on_el = Roo.get(this.over);
21874 this.alignEl = Roo.get( on_el );
21877 this.render(document.body);
21883 if (this.title === false) {
21884 this.headerEl.hide();
21889 this.el.dom.style.display = 'block';
21893 //var arrow = this.el.select('.arrow',true).first();
21894 //arrow.set(align[2],
21896 this.el.addClass('in');
21900 this.hoverState = 'in';
21903 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
21904 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
21905 this.maskEl.dom.style.display = 'block';
21906 this.maskEl.addClass('show');
21908 this.el.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
21910 this.fireEvent('show', this);
21914 * fire this manually after loading a grid in the table for example
21915 * @param {string} (left|right|top|bottom) where to try and put it (use false to use the last one)
21916 * @param {Boolean} try and move it if we cant get right position.
21918 updatePosition : function(placement, try_move)
21920 // allow for calling with no parameters
21921 placement = placement ? placement : this.placement;
21922 try_move = typeof(try_move) == 'undefined' ? true : try_move;
21924 this.el.removeClass([
21925 'fade','top','bottom', 'left', 'right','in',
21926 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
21928 this.el.addClass(placement + ' bs-popover-' + placement);
21930 if (!this.alignEl ) {
21934 switch (placement) {
21936 var exact = this.el.getAlignToXY(this.alignEl, 'tl-tr', [10,0]);
21937 var offset = this.el.getAlignToXY(this.alignEl, 'tl-tr?',[10,0]);
21938 if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
21939 //normal display... or moved up/down.
21940 this.el.setXY(offset);
21941 var xy = this.alignEl.getAnchorXY('tr', false);
21943 this.arrowEl.setXY(xy);
21946 // continue through...
21947 return this.updatePosition('left', false);
21951 var exact = this.el.getAlignToXY(this.alignEl, 'tr-tl', [-10,0]);
21952 var offset = this.el.getAlignToXY(this.alignEl, 'tr-tl?',[-10,0]);
21953 if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
21954 //normal display... or moved up/down.
21955 this.el.setXY(offset);
21956 var xy = this.alignEl.getAnchorXY('tl', false);
21957 xy[0]-=10;xy[1]+=5; // << fix me
21958 this.arrowEl.setXY(xy);
21962 return this.updatePosition('right', false);
21965 var exact = this.el.getAlignToXY(this.alignEl, 'b-t', [0,-10]);
21966 var offset = this.el.getAlignToXY(this.alignEl, 'b-t?',[0,-10]);
21967 if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
21968 //normal display... or moved up/down.
21969 this.el.setXY(offset);
21970 var xy = this.alignEl.getAnchorXY('t', false);
21971 xy[1]-=10; // << fix me
21972 this.arrowEl.setXY(xy);
21976 return this.updatePosition('bottom', false);
21979 var exact = this.el.getAlignToXY(this.alignEl, 't-b', [0,10]);
21980 var offset = this.el.getAlignToXY(this.alignEl, 't-b?',[0,10]);
21981 if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
21982 //normal display... or moved up/down.
21983 this.el.setXY(offset);
21984 var xy = this.alignEl.getAnchorXY('b', false);
21985 xy[1]+=2; // << fix me
21986 this.arrowEl.setXY(xy);
21990 return this.updatePosition('top', false);
22001 this.el.setXY([0,0]);
22002 this.el.removeClass('in');
22004 this.hoverState = null;
22005 this.maskEl.hide(); // always..
22006 this.fireEvent('hide', this);
22012 Roo.apply(Roo.bootstrap.Popover, {
22015 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
22016 'right' : ['l-br', [10,0], 'right bs-popover-right'],
22017 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
22018 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
22023 clickHander : false,
22027 onMouseDown : function(e)
22029 if (this.popups.length && !e.getTarget(".roo-popover")) {
22030 /// what is nothing is showing..
22039 register : function(popup)
22041 if (!Roo.bootstrap.Popover.clickHandler) {
22042 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
22044 // hide other popups.
22045 popup.on('show', Roo.bootstrap.Popover.onShow, popup);
22046 popup.on('hide', Roo.bootstrap.Popover.onHide, popup);
22047 this.hideAll(); //<< why?
22048 //this.popups.push(popup);
22050 hideAll : function()
22052 this.popups.forEach(function(p) {
22056 onShow : function() {
22057 Roo.bootstrap.Popover.popups.push(this);
22059 onHide : function() {
22060 Roo.bootstrap.Popover.popups.remove(this);
22065 * @class Roo.bootstrap.PopoverNav
22066 * @extends Roo.bootstrap.nav.Simplebar
22067 * @parent Roo.bootstrap.Popover
22068 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container
22070 * Bootstrap Popover header navigation class
22071 * FIXME? should this go under nav?
22075 * Create a new Popover Header Navigation
22076 * @param {Object} config The config object
22079 Roo.bootstrap.PopoverNav = function(config){
22080 Roo.bootstrap.PopoverNav.superclass.constructor.call(this, config);
22083 Roo.extend(Roo.bootstrap.PopoverNav, Roo.bootstrap.nav.Simplebar, {
22086 container_method : 'getPopoverHeader'
22104 * @class Roo.bootstrap.Progress
22105 * @extends Roo.bootstrap.Component
22106 * @children Roo.bootstrap.ProgressBar
22107 * Bootstrap Progress class
22108 * @cfg {Boolean} striped striped of the progress bar
22109 * @cfg {Boolean} active animated of the progress bar
22113 * Create a new Progress
22114 * @param {Object} config The config object
22117 Roo.bootstrap.Progress = function(config){
22118 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
22121 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
22126 getAutoCreate : function(){
22134 cfg.cls += ' progress-striped';
22138 cfg.cls += ' active';
22157 * @class Roo.bootstrap.ProgressBar
22158 * @extends Roo.bootstrap.Component
22159 * Bootstrap ProgressBar class
22160 * @cfg {Number} aria_valuenow aria-value now
22161 * @cfg {Number} aria_valuemin aria-value min
22162 * @cfg {Number} aria_valuemax aria-value max
22163 * @cfg {String} label label for the progress bar
22164 * @cfg {String} panel (success | info | warning | danger )
22165 * @cfg {String} role role of the progress bar
22166 * @cfg {String} sr_only text
22170 * Create a new ProgressBar
22171 * @param {Object} config The config object
22174 Roo.bootstrap.ProgressBar = function(config){
22175 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
22178 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
22182 aria_valuemax : 100,
22188 getAutoCreate : function()
22193 cls: 'progress-bar',
22194 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
22206 cfg.role = this.role;
22209 if(this.aria_valuenow){
22210 cfg['aria-valuenow'] = this.aria_valuenow;
22213 if(this.aria_valuemin){
22214 cfg['aria-valuemin'] = this.aria_valuemin;
22217 if(this.aria_valuemax){
22218 cfg['aria-valuemax'] = this.aria_valuemax;
22221 if(this.label && !this.sr_only){
22222 cfg.html = this.label;
22226 cfg.cls += ' progress-bar-' + this.panel;
22232 update : function(aria_valuenow)
22234 this.aria_valuenow = aria_valuenow;
22236 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
22244 * @class Roo.bootstrap.TabGroup
22245 * @extends Roo.bootstrap.Column
22246 * @children Roo.bootstrap.TabPanel
22247 * Bootstrap Column class
22248 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
22249 * @cfg {Boolean} carousel true to make the group behave like a carousel
22250 * @cfg {Boolean} bullets show bullets for the panels
22251 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
22252 * @cfg {Number} timer auto slide timer .. default 0 millisecond
22253 * @cfg {Boolean} showarrow (true|false) show arrow default true
22256 * Create a new TabGroup
22257 * @param {Object} config The config object
22260 Roo.bootstrap.TabGroup = function(config){
22261 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
22263 this.navId = Roo.id();
22266 Roo.bootstrap.TabGroup.register(this);
22270 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
22273 transition : false,
22278 slideOnTouch : false,
22281 getAutoCreate : function()
22283 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
22285 cfg.cls += ' tab-content';
22287 if (this.carousel) {
22288 cfg.cls += ' carousel slide';
22291 cls : 'carousel-inner',
22295 if(this.bullets && !Roo.isTouch){
22298 cls : 'carousel-bullets',
22302 if(this.bullets_cls){
22303 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
22310 cfg.cn[0].cn.push(bullets);
22313 if(this.showarrow){
22314 cfg.cn[0].cn.push({
22316 class : 'carousel-arrow',
22320 class : 'carousel-prev',
22324 class : 'fa fa-chevron-left'
22330 class : 'carousel-next',
22334 class : 'fa fa-chevron-right'
22347 initEvents: function()
22349 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
22350 // this.el.on("touchstart", this.onTouchStart, this);
22353 if(this.autoslide){
22356 this.slideFn = window.setInterval(function() {
22357 _this.showPanelNext();
22361 if(this.showarrow){
22362 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
22363 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
22369 // onTouchStart : function(e, el, o)
22371 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
22375 // this.showPanelNext();
22379 getChildContainer : function()
22381 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
22385 * register a Navigation item
22386 * @param {Roo.bootstrap.nav.Item} the navitem to add
22388 register : function(item)
22390 this.tabs.push( item);
22391 item.navId = this.navId; // not really needed..
22396 getActivePanel : function()
22399 Roo.each(this.tabs, function(t) {
22409 getPanelByName : function(n)
22412 Roo.each(this.tabs, function(t) {
22413 if (t.tabId == n) {
22421 indexOfPanel : function(p)
22424 Roo.each(this.tabs, function(t,i) {
22425 if (t.tabId == p.tabId) {
22434 * show a specific panel
22435 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
22436 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
22438 showPanel : function (pan)
22440 if(this.transition || typeof(pan) == 'undefined'){
22441 Roo.log("waiting for the transitionend");
22445 if (typeof(pan) == 'number') {
22446 pan = this.tabs[pan];
22449 if (typeof(pan) == 'string') {
22450 pan = this.getPanelByName(pan);
22453 var cur = this.getActivePanel();
22456 Roo.log('pan or acitve pan is undefined');
22460 if (pan.tabId == this.getActivePanel().tabId) {
22464 if (false === cur.fireEvent('beforedeactivate')) {
22468 if(this.bullets > 0 && !Roo.isTouch){
22469 this.setActiveBullet(this.indexOfPanel(pan));
22472 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
22474 //class="carousel-item carousel-item-next carousel-item-left"
22476 this.transition = true;
22477 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
22478 var lr = dir == 'next' ? 'left' : 'right';
22479 pan.el.addClass(dir); // or prev
22480 pan.el.addClass('carousel-item-' + dir); // or prev
22481 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
22482 cur.el.addClass(lr); // or right
22483 pan.el.addClass(lr);
22484 cur.el.addClass('carousel-item-' +lr); // or right
22485 pan.el.addClass('carousel-item-' +lr);
22489 cur.el.on('transitionend', function() {
22490 Roo.log("trans end?");
22492 pan.el.removeClass([lr,dir, 'carousel-item-' + lr, 'carousel-item-' + dir]);
22493 pan.setActive(true);
22495 cur.el.removeClass([lr, 'carousel-item-' + lr]);
22496 cur.setActive(false);
22498 _this.transition = false;
22500 }, this, { single: true } );
22505 cur.setActive(false);
22506 pan.setActive(true);
22511 showPanelNext : function()
22513 var i = this.indexOfPanel(this.getActivePanel());
22515 if (i >= this.tabs.length - 1 && !this.autoslide) {
22519 if (i >= this.tabs.length - 1 && this.autoslide) {
22523 this.showPanel(this.tabs[i+1]);
22526 showPanelPrev : function()
22528 var i = this.indexOfPanel(this.getActivePanel());
22530 if (i < 1 && !this.autoslide) {
22534 if (i < 1 && this.autoslide) {
22535 i = this.tabs.length;
22538 this.showPanel(this.tabs[i-1]);
22542 addBullet: function()
22544 if(!this.bullets || Roo.isTouch){
22547 var ctr = this.el.select('.carousel-bullets',true).first();
22548 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
22549 var bullet = ctr.createChild({
22550 cls : 'bullet bullet-' + i
22551 },ctr.dom.lastChild);
22556 bullet.on('click', (function(e, el, o, ii, t){
22558 e.preventDefault();
22560 this.showPanel(ii);
22562 if(this.autoslide && this.slideFn){
22563 clearInterval(this.slideFn);
22564 this.slideFn = window.setInterval(function() {
22565 _this.showPanelNext();
22569 }).createDelegate(this, [i, bullet], true));
22574 setActiveBullet : function(i)
22580 Roo.each(this.el.select('.bullet', true).elements, function(el){
22581 el.removeClass('selected');
22584 var bullet = this.el.select('.bullet-' + i, true).first();
22590 bullet.addClass('selected');
22601 Roo.apply(Roo.bootstrap.TabGroup, {
22605 * register a Navigation Group
22606 * @param {Roo.bootstrap.nav.Group} the navgroup to add
22608 register : function(navgrp)
22610 this.groups[navgrp.navId] = navgrp;
22614 * fetch a Navigation Group based on the navigation ID
22615 * if one does not exist , it will get created.
22616 * @param {string} the navgroup to add
22617 * @returns {Roo.bootstrap.nav.Group} the navgroup
22619 get: function(navId) {
22620 if (typeof(this.groups[navId]) == 'undefined') {
22621 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
22623 return this.groups[navId] ;
22638 * @class Roo.bootstrap.TabPanel
22639 * @extends Roo.bootstrap.Component
22640 * @children Roo.bootstrap.Component
22641 * Bootstrap TabPanel class
22642 * @cfg {Boolean} active panel active
22643 * @cfg {String} html panel content
22644 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
22645 * @cfg {String} navId The Roo.bootstrap.nav.Group which triggers show hide ()
22646 * @cfg {String} href click to link..
22647 * @cfg {Boolean} touchSlide if swiping slides tab to next panel (default off)
22651 * Create a new TabPanel
22652 * @param {Object} config The config object
22655 Roo.bootstrap.TabPanel = function(config){
22656 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
22660 * Fires when the active status changes
22661 * @param {Roo.bootstrap.TabPanel} this
22662 * @param {Boolean} state the new state
22667 * @event beforedeactivate
22668 * Fires before a tab is de-activated - can be used to do validation on a form.
22669 * @param {Roo.bootstrap.TabPanel} this
22670 * @return {Boolean} false if there is an error
22673 'beforedeactivate': true
22676 this.tabId = this.tabId || Roo.id();
22680 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
22687 touchSlide : false,
22688 getAutoCreate : function(){
22693 // item is needed for carousel - not sure if it has any effect otherwise
22694 cls: 'carousel-item tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
22695 html: this.html || ''
22699 cfg.cls += ' active';
22703 cfg.tabId = this.tabId;
22711 initEvents: function()
22713 var p = this.parent();
22715 this.navId = this.navId || p.navId;
22717 if (typeof(this.navId) != 'undefined') {
22718 // not really needed.. but just in case.. parent should be a NavGroup.
22719 var tg = Roo.bootstrap.TabGroup.get(this.navId);
22723 var i = tg.tabs.length - 1;
22725 if(this.active && tg.bullets > 0 && i < tg.bullets){
22726 tg.setActiveBullet(i);
22730 this.el.on('click', this.onClick, this);
22732 if(Roo.isTouch && this.touchSlide){
22733 this.el.on("touchstart", this.onTouchStart, this);
22734 this.el.on("touchmove", this.onTouchMove, this);
22735 this.el.on("touchend", this.onTouchEnd, this);
22740 onRender : function(ct, position)
22742 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
22745 setActive : function(state)
22747 Roo.log("panel - set active " + this.tabId + "=" + state);
22749 this.active = state;
22751 this.el.removeClass('active');
22753 } else if (!this.el.hasClass('active')) {
22754 this.el.addClass('active');
22757 this.fireEvent('changed', this, state);
22760 onClick : function(e)
22762 e.preventDefault();
22764 if(!this.href.length){
22768 window.location.href = this.href;
22777 onTouchStart : function(e)
22779 this.swiping = false;
22781 this.startX = e.browserEvent.touches[0].clientX;
22782 this.startY = e.browserEvent.touches[0].clientY;
22785 onTouchMove : function(e)
22787 this.swiping = true;
22789 this.endX = e.browserEvent.touches[0].clientX;
22790 this.endY = e.browserEvent.touches[0].clientY;
22793 onTouchEnd : function(e)
22800 var tabGroup = this.parent();
22802 if(this.endX > this.startX){ // swiping right
22803 tabGroup.showPanelPrev();
22807 if(this.startX > this.endX){ // swiping left
22808 tabGroup.showPanelNext();
22827 * @class Roo.bootstrap.form.DateField
22828 * @extends Roo.bootstrap.form.Input
22829 * Bootstrap DateField class
22830 * @cfg {Number} weekStart default 0
22831 * @cfg {String} viewMode default empty, (months|years)
22832 * @cfg {String} minViewMode default empty, (months|years)
22833 * @cfg {Number} startDate default -Infinity
22834 * @cfg {Number} endDate default Infinity
22835 * @cfg {Boolean} todayHighlight default false
22836 * @cfg {Boolean} todayBtn default false
22837 * @cfg {Boolean} calendarWeeks default false
22838 * @cfg {Object} daysOfWeekDisabled default empty
22839 * @cfg {Boolean} singleMode default false (true | false)
22841 * @cfg {Boolean} keyboardNavigation default true
22842 * @cfg {String} language default en
22845 * Create a new DateField
22846 * @param {Object} config The config object
22849 Roo.bootstrap.form.DateField = function(config){
22850 Roo.bootstrap.form.DateField.superclass.constructor.call(this, config);
22854 * Fires when this field show.
22855 * @param {Roo.bootstrap.form.DateField} this
22856 * @param {Mixed} date The date value
22861 * Fires when this field hide.
22862 * @param {Roo.bootstrap.form.DateField} this
22863 * @param {Mixed} date The date value
22868 * Fires when select a date.
22869 * @param {Roo.bootstrap.form.DateField} this
22870 * @param {Mixed} date The date value
22874 * @event beforeselect
22875 * Fires when before select a date.
22876 * @param {Roo.bootstrap.form.DateField} this
22877 * @param {Mixed} date The date value
22879 beforeselect : true
22883 Roo.extend(Roo.bootstrap.form.DateField, Roo.bootstrap.form.Input, {
22886 * @cfg {String} format
22887 * The default date format string which can be overriden for localization support. The format must be
22888 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
22892 * @cfg {String} altFormats
22893 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
22894 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
22896 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
22904 todayHighlight : false,
22910 keyboardNavigation: true,
22912 calendarWeeks: false,
22914 startDate: -Infinity,
22918 daysOfWeekDisabled: [],
22922 singleMode : false,
22924 UTCDate: function()
22926 return new Date(Date.UTC.apply(Date, arguments));
22929 UTCToday: function()
22931 var today = new Date();
22932 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
22935 getDate: function() {
22936 var d = this.getUTCDate();
22937 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
22940 getUTCDate: function() {
22944 setDate: function(d) {
22945 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
22948 setUTCDate: function(d) {
22950 this.setValue(this.formatDate(this.date));
22953 onRender: function(ct, position)
22956 Roo.bootstrap.form.DateField.superclass.onRender.call(this, ct, position);
22958 this.language = this.language || 'en';
22959 this.language = this.language in Roo.bootstrap.form.DateField.dates ? this.language : this.language.split('-')[0];
22960 this.language = this.language in Roo.bootstrap.form.DateField.dates ? this.language : "en";
22962 this.isRTL = Roo.bootstrap.form.DateField.dates[this.language].rtl || false;
22963 this.format = this.format || 'm/d/y';
22964 this.isInline = false;
22965 this.isInput = true;
22966 this.component = this.el.select('.add-on', true).first() || false;
22967 this.component = (this.component && this.component.length === 0) ? false : this.component;
22968 this.hasInput = this.component && this.inputEl().length;
22970 if (typeof(this.minViewMode === 'string')) {
22971 switch (this.minViewMode) {
22973 this.minViewMode = 1;
22976 this.minViewMode = 2;
22979 this.minViewMode = 0;
22984 if (typeof(this.viewMode === 'string')) {
22985 switch (this.viewMode) {
22998 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.DateField.template);
23000 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.form.DateField.template);
23002 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
23004 this.picker().on('mousedown', this.onMousedown, this);
23005 this.picker().on('click', this.onClick, this);
23007 this.picker().addClass('datepicker-dropdown');
23009 this.startViewMode = this.viewMode;
23011 if(this.singleMode){
23012 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
23013 v.setVisibilityMode(Roo.Element.DISPLAY);
23017 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
23018 v.setStyle('width', '189px');
23022 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
23023 if(!this.calendarWeeks){
23028 v.dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].today;
23029 v.attr('colspan', function(i, val){
23030 return parseInt(val) + 1;
23035 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
23037 this.setStartDate(this.startDate);
23038 this.setEndDate(this.endDate);
23040 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
23047 if(this.isInline) {
23052 picker : function()
23054 return this.pickerEl;
23055 // return this.el.select('.datepicker', true).first();
23058 fillDow: function()
23060 var dowCnt = this.weekStart;
23069 if(this.calendarWeeks){
23077 while (dowCnt < this.weekStart + 7) {
23081 html: Roo.bootstrap.form.DateField.dates[this.language].daysMin[(dowCnt++)%7]
23085 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
23088 fillMonths: function()
23091 var months = this.picker().select('>.datepicker-months td', true).first();
23093 months.dom.innerHTML = '';
23099 html: Roo.bootstrap.form.DateField.dates[this.language].monthsShort[i++]
23102 months.createChild(month);
23109 this.date = (typeof(this.date) === 'undefined' || ((typeof(this.date) === 'string') && !this.date.length)) ? this.UTCToday() : (typeof(this.date) === 'string') ? this.parseDate(this.date) : this.date;
23111 if (this.date < this.startDate) {
23112 this.viewDate = new Date(this.startDate);
23113 } else if (this.date > this.endDate) {
23114 this.viewDate = new Date(this.endDate);
23116 this.viewDate = new Date(this.date);
23124 var d = new Date(this.viewDate),
23125 year = d.getUTCFullYear(),
23126 month = d.getUTCMonth(),
23127 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
23128 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
23129 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
23130 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
23131 currentDate = this.date && this.date.valueOf(),
23132 today = this.UTCToday();
23134 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].months[month]+' '+year;
23136 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].today;
23138 // this.picker.select('>tfoot th.today').
23139 // .text(dates[this.language].today)
23140 // .toggle(this.todayBtn !== false);
23142 this.updateNavArrows();
23145 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
23147 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
23149 prevMonth.setUTCDate(day);
23151 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
23153 var nextMonth = new Date(prevMonth);
23155 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
23157 nextMonth = nextMonth.valueOf();
23159 var fillMonths = false;
23161 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
23163 while(prevMonth.valueOf() <= nextMonth) {
23166 if (prevMonth.getUTCDay() === this.weekStart) {
23168 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
23176 if(this.calendarWeeks){
23177 // ISO 8601: First week contains first thursday.
23178 // ISO also states week starts on Monday, but we can be more abstract here.
23180 // Start of current week: based on weekstart/current date
23181 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
23182 // Thursday of this week
23183 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
23184 // First Thursday of year, year from thursday
23185 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
23186 // Calendar week: ms between thursdays, div ms per day, div 7 days
23187 calWeek = (th - yth) / 864e5 / 7 + 1;
23189 fillMonths.cn.push({
23197 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
23199 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
23202 if (this.todayHighlight &&
23203 prevMonth.getUTCFullYear() == today.getFullYear() &&
23204 prevMonth.getUTCMonth() == today.getMonth() &&
23205 prevMonth.getUTCDate() == today.getDate()) {
23206 clsName += ' today';
23209 if (currentDate && prevMonth.valueOf() === currentDate) {
23210 clsName += ' active';
23213 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
23214 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
23215 clsName += ' disabled';
23218 fillMonths.cn.push({
23220 cls: 'day ' + clsName,
23221 html: prevMonth.getDate()
23224 prevMonth.setDate(prevMonth.getDate()+1);
23227 var currentYear = this.date && this.date.getUTCFullYear();
23228 var currentMonth = this.date && this.date.getUTCMonth();
23230 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
23232 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
23233 v.removeClass('active');
23235 if(currentYear === year && k === currentMonth){
23236 v.addClass('active');
23239 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
23240 v.addClass('disabled');
23246 year = parseInt(year/10, 10) * 10;
23248 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
23250 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
23253 for (var i = -1; i < 11; i++) {
23254 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
23256 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
23264 showMode: function(dir)
23267 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
23270 Roo.each(this.picker().select('>div',true).elements, function(v){
23271 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
23274 this.picker().select('>.datepicker-'+Roo.bootstrap.form.DateField.modes[this.viewMode].clsName, true).first().show();
23279 if(this.isInline) {
23283 this.picker().removeClass(['bottom', 'top']);
23285 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
23287 * place to the top of element!
23291 this.picker().addClass('top');
23292 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
23297 this.picker().addClass('bottom');
23299 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
23302 parseDate : function(value)
23304 if(!value || value instanceof Date){
23307 var v = Date.parseDate(value, this.format);
23308 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
23309 v = Date.parseDate(value, 'Y-m-d');
23311 if(!v && this.altFormats){
23312 if(!this.altFormatsArray){
23313 this.altFormatsArray = this.altFormats.split("|");
23315 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
23316 v = Date.parseDate(value, this.altFormatsArray[i]);
23322 formatDate : function(date, fmt)
23324 return (!date || !(date instanceof Date)) ?
23325 date : date.dateFormat(fmt || this.format);
23328 onFocus : function()
23330 Roo.bootstrap.form.DateField.superclass.onFocus.call(this);
23334 onBlur : function()
23336 Roo.bootstrap.form.DateField.superclass.onBlur.call(this);
23338 var d = this.inputEl().getValue();
23345 showPopup : function()
23347 this.picker().show();
23351 this.fireEvent('showpopup', this, this.date);
23354 hidePopup : function()
23356 if(this.isInline) {
23359 this.picker().hide();
23360 this.viewMode = this.startViewMode;
23363 this.fireEvent('hidepopup', this, this.date);
23367 onMousedown: function(e)
23369 e.stopPropagation();
23370 e.preventDefault();
23375 Roo.bootstrap.form.DateField.superclass.keyup.call(this);
23379 setValue: function(v)
23381 if(this.fireEvent('beforeselect', this, v) !== false){
23382 var d = new Date(this.parseDate(v) ).clearTime();
23384 if(isNaN(d.getTime())){
23385 this.date = this.viewDate = '';
23386 Roo.bootstrap.form.DateField.superclass.setValue.call(this, '');
23390 v = this.formatDate(d);
23392 Roo.bootstrap.form.DateField.superclass.setValue.call(this, v);
23394 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
23398 this.fireEvent('select', this, this.date);
23402 getValue: function()
23404 return this.formatDate(this.date);
23407 fireKey: function(e)
23409 if (!this.picker().isVisible()){
23410 if (e.keyCode == 27) { // allow escape to hide and re-show picker
23416 var dateChanged = false,
23418 newDate, newViewDate;
23423 e.preventDefault();
23427 if (!this.keyboardNavigation) {
23430 dir = e.keyCode == 37 ? -1 : 1;
23433 newDate = this.moveYear(this.date, dir);
23434 newViewDate = this.moveYear(this.viewDate, dir);
23435 } else if (e.shiftKey){
23436 newDate = this.moveMonth(this.date, dir);
23437 newViewDate = this.moveMonth(this.viewDate, dir);
23439 newDate = new Date(this.date);
23440 newDate.setUTCDate(this.date.getUTCDate() + dir);
23441 newViewDate = new Date(this.viewDate);
23442 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
23444 if (this.dateWithinRange(newDate)){
23445 this.date = newDate;
23446 this.viewDate = newViewDate;
23447 this.setValue(this.formatDate(this.date));
23449 e.preventDefault();
23450 dateChanged = true;
23455 if (!this.keyboardNavigation) {
23458 dir = e.keyCode == 38 ? -1 : 1;
23460 newDate = this.moveYear(this.date, dir);
23461 newViewDate = this.moveYear(this.viewDate, dir);
23462 } else if (e.shiftKey){
23463 newDate = this.moveMonth(this.date, dir);
23464 newViewDate = this.moveMonth(this.viewDate, dir);
23466 newDate = new Date(this.date);
23467 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
23468 newViewDate = new Date(this.viewDate);
23469 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
23471 if (this.dateWithinRange(newDate)){
23472 this.date = newDate;
23473 this.viewDate = newViewDate;
23474 this.setValue(this.formatDate(this.date));
23476 e.preventDefault();
23477 dateChanged = true;
23481 this.setValue(this.formatDate(this.date));
23483 e.preventDefault();
23486 this.setValue(this.formatDate(this.date));
23500 onClick: function(e)
23502 e.stopPropagation();
23503 e.preventDefault();
23505 var target = e.getTarget();
23507 if(target.nodeName.toLowerCase() === 'i'){
23508 target = Roo.get(target).dom.parentNode;
23511 var nodeName = target.nodeName;
23512 var className = target.className;
23513 var html = target.innerHTML;
23514 //Roo.log(nodeName);
23516 switch(nodeName.toLowerCase()) {
23518 switch(className) {
23524 var dir = Roo.bootstrap.form.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
23525 switch(this.viewMode){
23527 this.viewDate = this.moveMonth(this.viewDate, dir);
23531 this.viewDate = this.moveYear(this.viewDate, dir);
23537 var date = new Date();
23538 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
23540 this.setValue(this.formatDate(this.date));
23547 if (className.indexOf('disabled') < 0) {
23548 if (!this.viewDate) {
23549 this.viewDate = new Date();
23551 this.viewDate.setUTCDate(1);
23552 if (className.indexOf('month') > -1) {
23553 this.viewDate.setUTCMonth(Roo.bootstrap.form.DateField.dates[this.language].monthsShort.indexOf(html));
23555 var year = parseInt(html, 10) || 0;
23556 this.viewDate.setUTCFullYear(year);
23560 if(this.singleMode){
23561 this.setValue(this.formatDate(this.viewDate));
23572 //Roo.log(className);
23573 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
23574 var day = parseInt(html, 10) || 1;
23575 var year = (this.viewDate || new Date()).getUTCFullYear(),
23576 month = (this.viewDate || new Date()).getUTCMonth();
23578 if (className.indexOf('old') > -1) {
23585 } else if (className.indexOf('new') > -1) {
23593 //Roo.log([year,month,day]);
23594 this.date = this.UTCDate(year, month, day,0,0,0,0);
23595 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
23597 //Roo.log(this.formatDate(this.date));
23598 this.setValue(this.formatDate(this.date));
23605 setStartDate: function(startDate)
23607 this.startDate = startDate || -Infinity;
23608 if (this.startDate !== -Infinity) {
23609 this.startDate = this.parseDate(this.startDate);
23612 this.updateNavArrows();
23615 setEndDate: function(endDate)
23617 this.endDate = endDate || Infinity;
23618 if (this.endDate !== Infinity) {
23619 this.endDate = this.parseDate(this.endDate);
23622 this.updateNavArrows();
23625 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
23627 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
23628 if (typeof(this.daysOfWeekDisabled) !== 'object') {
23629 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
23631 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
23632 return parseInt(d, 10);
23635 this.updateNavArrows();
23638 updateNavArrows: function()
23640 if(this.singleMode){
23644 var d = new Date(this.viewDate),
23645 year = d.getUTCFullYear(),
23646 month = d.getUTCMonth();
23648 Roo.each(this.picker().select('.prev', true).elements, function(v){
23650 switch (this.viewMode) {
23653 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
23659 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
23666 Roo.each(this.picker().select('.next', true).elements, function(v){
23668 switch (this.viewMode) {
23671 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
23677 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
23685 moveMonth: function(date, dir)
23690 var new_date = new Date(date.valueOf()),
23691 day = new_date.getUTCDate(),
23692 month = new_date.getUTCMonth(),
23693 mag = Math.abs(dir),
23695 dir = dir > 0 ? 1 : -1;
23698 // If going back one month, make sure month is not current month
23699 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
23701 return new_date.getUTCMonth() == month;
23703 // If going forward one month, make sure month is as expected
23704 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
23706 return new_date.getUTCMonth() != new_month;
23708 new_month = month + dir;
23709 new_date.setUTCMonth(new_month);
23710 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
23711 if (new_month < 0 || new_month > 11) {
23712 new_month = (new_month + 12) % 12;
23715 // For magnitudes >1, move one month at a time...
23716 for (var i=0; i<mag; i++) {
23717 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
23718 new_date = this.moveMonth(new_date, dir);
23720 // ...then reset the day, keeping it in the new month
23721 new_month = new_date.getUTCMonth();
23722 new_date.setUTCDate(day);
23724 return new_month != new_date.getUTCMonth();
23727 // Common date-resetting loop -- if date is beyond end of month, make it
23730 new_date.setUTCDate(--day);
23731 new_date.setUTCMonth(new_month);
23736 moveYear: function(date, dir)
23738 return this.moveMonth(date, dir*12);
23741 dateWithinRange: function(date)
23743 return date >= this.startDate && date <= this.endDate;
23749 this.picker().remove();
23752 validateValue : function(value)
23754 if(this.getVisibilityEl().hasClass('hidden')){
23758 if(value.length < 1) {
23759 if(this.allowBlank){
23765 if(value.length < this.minLength){
23768 if(value.length > this.maxLength){
23772 var vt = Roo.form.VTypes;
23773 if(!vt[this.vtype](value, this)){
23777 if(typeof this.validator == "function"){
23778 var msg = this.validator(value);
23784 if(this.regex && !this.regex.test(value)){
23788 if(typeof(this.parseDate(value)) == 'undefined'){
23792 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
23796 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
23806 this.date = this.viewDate = '';
23808 Roo.bootstrap.form.DateField.superclass.setValue.call(this, '');
23813 Roo.apply(Roo.bootstrap.form.DateField, {
23824 html: '<i class="fa fa-arrow-left"/>'
23834 html: '<i class="fa fa-arrow-right"/>'
23876 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
23877 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
23878 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
23879 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
23880 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
23893 navFnc: 'FullYear',
23898 navFnc: 'FullYear',
23903 Roo.apply(Roo.bootstrap.form.DateField, {
23907 cls: 'datepicker dropdown-menu roo-dynamic shadow',
23911 cls: 'datepicker-days',
23915 cls: 'table-condensed',
23917 Roo.bootstrap.form.DateField.head,
23921 Roo.bootstrap.form.DateField.footer
23928 cls: 'datepicker-months',
23932 cls: 'table-condensed',
23934 Roo.bootstrap.form.DateField.head,
23935 Roo.bootstrap.form.DateField.content,
23936 Roo.bootstrap.form.DateField.footer
23943 cls: 'datepicker-years',
23947 cls: 'table-condensed',
23949 Roo.bootstrap.form.DateField.head,
23950 Roo.bootstrap.form.DateField.content,
23951 Roo.bootstrap.form.DateField.footer
23970 * @class Roo.bootstrap.form.TimeField
23971 * @extends Roo.bootstrap.form.Input
23972 * Bootstrap DateField class
23976 * Create a new TimeField
23977 * @param {Object} config The config object
23980 Roo.bootstrap.form.TimeField = function(config){
23981 Roo.bootstrap.form.TimeField.superclass.constructor.call(this, config);
23985 * Fires when this field show.
23986 * @param {Roo.bootstrap.form.DateField} thisthis
23987 * @param {Mixed} date The date value
23992 * Fires when this field hide.
23993 * @param {Roo.bootstrap.form.DateField} this
23994 * @param {Mixed} date The date value
23999 * Fires when select a date.
24000 * @param {Roo.bootstrap.form.DateField} this
24001 * @param {Mixed} date The date value
24007 Roo.extend(Roo.bootstrap.form.TimeField, Roo.bootstrap.form.Input, {
24010 * @cfg {String} format
24011 * The default time format string which can be overriden for localization support. The format must be
24012 * valid according to {@link Date#parseDate} (defaults to 'H:i').
24016 getAutoCreate : function()
24018 this.after = '<i class="fa far fa-clock"></i>';
24019 return Roo.bootstrap.form.TimeField.superclass.getAutoCreate.call(this);
24023 onRender: function(ct, position)
24026 Roo.bootstrap.form.TimeField.superclass.onRender.call(this, ct, position);
24028 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.TimeField.template);
24030 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24032 this.pop = this.picker().select('>.datepicker-time',true).first();
24033 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24035 this.picker().on('mousedown', this.onMousedown, this);
24036 this.picker().on('click', this.onClick, this);
24038 this.picker().addClass('datepicker-dropdown');
24043 this.pop.select('.hours-up', true).first().on('click', this.onIncrementHours, this);
24044 this.pop.select('.hours-down', true).first().on('click', this.onDecrementHours, this);
24045 this.pop.select('.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
24046 this.pop.select('.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
24047 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
24048 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
24052 fireKey: function(e){
24053 if (!this.picker().isVisible()){
24054 if (e.keyCode == 27) { // allow escape to hide and re-show picker
24060 e.preventDefault();
24068 this.onTogglePeriod();
24071 this.onIncrementMinutes();
24074 this.onDecrementMinutes();
24083 onClick: function(e) {
24084 e.stopPropagation();
24085 e.preventDefault();
24088 picker : function()
24090 return this.pickerEl;
24093 fillTime: function()
24095 var time = this.pop.select('tbody', true).first();
24097 time.dom.innerHTML = '';
24112 cls: 'hours-up fa fas fa-chevron-up'
24132 cls: 'minutes-up fa fas fa-chevron-up'
24153 cls: 'timepicker-hour',
24168 cls: 'timepicker-minute',
24183 cls: 'btn btn-primary period',
24205 cls: 'hours-down fa fas fa-chevron-down'
24225 cls: 'minutes-down fa fas fa-chevron-down'
24243 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
24250 var hours = this.time.getHours();
24251 var minutes = this.time.getMinutes();
24264 hours = hours - 12;
24268 hours = '0' + hours;
24272 minutes = '0' + minutes;
24275 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
24276 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
24277 this.pop.select('button', true).first().dom.innerHTML = period;
24283 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
24285 var cls = ['bottom'];
24287 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
24294 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
24298 //this.picker().setXY(20000,20000);
24299 this.picker().addClass(cls.join('-'));
24303 Roo.each(cls, function(c){
24308 _this.picker().alignTo(_this.inputEl(), "tr-br", [0, 10], false);
24309 //_this.picker().setTop(_this.inputEl().getHeight());
24313 _this.picker().alignTo(_this.inputEl(), "br-tr", [0, 10], false);
24315 //_this.picker().setTop(0 - _this.picker().getHeight());
24320 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
24324 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
24332 onFocus : function()
24334 Roo.bootstrap.form.TimeField.superclass.onFocus.call(this);
24338 onBlur : function()
24340 Roo.bootstrap.form.TimeField.superclass.onBlur.call(this);
24346 this.picker().show();
24351 this.fireEvent('show', this, this.date);
24356 this.picker().hide();
24359 this.fireEvent('hide', this, this.date);
24362 setTime : function()
24365 this.setValue(this.time.format(this.format));
24367 this.fireEvent('select', this, this.date);
24372 onMousedown: function(e){
24373 e.stopPropagation();
24374 e.preventDefault();
24377 onIncrementHours: function()
24379 Roo.log('onIncrementHours');
24380 this.time = this.time.add(Date.HOUR, 1);
24385 onDecrementHours: function()
24387 Roo.log('onDecrementHours');
24388 this.time = this.time.add(Date.HOUR, -1);
24392 onIncrementMinutes: function()
24394 Roo.log('onIncrementMinutes');
24395 this.time = this.time.add(Date.MINUTE, 1);
24399 onDecrementMinutes: function()
24401 Roo.log('onDecrementMinutes');
24402 this.time = this.time.add(Date.MINUTE, -1);
24406 onTogglePeriod: function()
24408 Roo.log('onTogglePeriod');
24409 this.time = this.time.add(Date.HOUR, 12);
24417 Roo.apply(Roo.bootstrap.form.TimeField, {
24421 cls: 'datepicker dropdown-menu',
24425 cls: 'datepicker-time',
24429 cls: 'table-condensed',
24458 cls: 'btn btn-info ok',
24486 * @class Roo.bootstrap.form.MonthField
24487 * @extends Roo.bootstrap.form.Input
24488 * Bootstrap MonthField class
24490 * @cfg {String} language default en
24493 * Create a new MonthField
24494 * @param {Object} config The config object
24497 Roo.bootstrap.form.MonthField = function(config){
24498 Roo.bootstrap.form.MonthField.superclass.constructor.call(this, config);
24503 * Fires when this field show.
24504 * @param {Roo.bootstrap.form.MonthField} this
24505 * @param {Mixed} date The date value
24510 * Fires when this field hide.
24511 * @param {Roo.bootstrap.form.MonthField} this
24512 * @param {Mixed} date The date value
24517 * Fires when select a date.
24518 * @param {Roo.bootstrap.form.MonthField} this
24519 * @param {String} oldvalue The old value
24520 * @param {String} newvalue The new value
24526 Roo.extend(Roo.bootstrap.form.MonthField, Roo.bootstrap.form.Input, {
24528 onRender: function(ct, position)
24531 Roo.bootstrap.form.MonthField.superclass.onRender.call(this, ct, position);
24533 this.language = this.language || 'en';
24534 this.language = this.language in Roo.bootstrap.form.MonthField.dates ? this.language : this.language.split('-')[0];
24535 this.language = this.language in Roo.bootstrap.form.MonthField.dates ? this.language : "en";
24537 this.isRTL = Roo.bootstrap.form.MonthField.dates[this.language].rtl || false;
24538 this.isInline = false;
24539 this.isInput = true;
24540 this.component = this.el.select('.add-on', true).first() || false;
24541 this.component = (this.component && this.component.length === 0) ? false : this.component;
24542 this.hasInput = this.component && this.inputEL().length;
24544 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.MonthField.template);
24546 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24548 this.picker().on('mousedown', this.onMousedown, this);
24549 this.picker().on('click', this.onClick, this);
24551 this.picker().addClass('datepicker-dropdown');
24553 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
24554 v.setStyle('width', '189px');
24561 if(this.isInline) {
24567 setValue: function(v, suppressEvent)
24569 var o = this.getValue();
24571 Roo.bootstrap.form.MonthField.superclass.setValue.call(this, v);
24575 if(suppressEvent !== true){
24576 this.fireEvent('select', this, o, v);
24581 getValue: function()
24586 onClick: function(e)
24588 e.stopPropagation();
24589 e.preventDefault();
24591 var target = e.getTarget();
24593 if(target.nodeName.toLowerCase() === 'i'){
24594 target = Roo.get(target).dom.parentNode;
24597 var nodeName = target.nodeName;
24598 var className = target.className;
24599 var html = target.innerHTML;
24601 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
24605 this.vIndex = Roo.bootstrap.form.MonthField.dates[this.language].monthsShort.indexOf(html);
24607 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24613 picker : function()
24615 return this.pickerEl;
24618 fillMonths: function()
24621 var months = this.picker().select('>.datepicker-months td', true).first();
24623 months.dom.innerHTML = '';
24629 html: Roo.bootstrap.form.MonthField.dates[this.language].monthsShort[i++]
24632 months.createChild(month);
24641 if(typeof(this.vIndex) == 'undefined' && this.value.length){
24642 this.vIndex = Roo.bootstrap.form.MonthField.dates[this.language].months.indexOf(this.value);
24645 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
24646 e.removeClass('active');
24648 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
24649 e.addClass('active');
24656 if(this.isInline) {
24660 this.picker().removeClass(['bottom', 'top']);
24662 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
24664 * place to the top of element!
24668 this.picker().addClass('top');
24669 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
24674 this.picker().addClass('bottom');
24676 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
24679 onFocus : function()
24681 Roo.bootstrap.form.MonthField.superclass.onFocus.call(this);
24685 onBlur : function()
24687 Roo.bootstrap.form.MonthField.superclass.onBlur.call(this);
24689 var d = this.inputEl().getValue();
24698 this.picker().show();
24699 this.picker().select('>.datepicker-months', true).first().show();
24703 this.fireEvent('show', this, this.date);
24708 if(this.isInline) {
24711 this.picker().hide();
24712 this.fireEvent('hide', this, this.date);
24716 onMousedown: function(e)
24718 e.stopPropagation();
24719 e.preventDefault();
24724 Roo.bootstrap.form.MonthField.superclass.keyup.call(this);
24728 fireKey: function(e)
24730 if (!this.picker().isVisible()){
24731 if (e.keyCode == 27) {// allow escape to hide and re-show picker
24742 e.preventDefault();
24746 dir = e.keyCode == 37 ? -1 : 1;
24748 this.vIndex = this.vIndex + dir;
24750 if(this.vIndex < 0){
24754 if(this.vIndex > 11){
24758 if(isNaN(this.vIndex)){
24762 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24768 dir = e.keyCode == 38 ? -1 : 1;
24770 this.vIndex = this.vIndex + dir * 4;
24772 if(this.vIndex < 0){
24776 if(this.vIndex > 11){
24780 if(isNaN(this.vIndex)){
24784 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24789 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
24790 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24794 e.preventDefault();
24797 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
24798 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24814 this.picker().remove();
24819 Roo.apply(Roo.bootstrap.form.MonthField, {
24838 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
24839 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
24844 Roo.apply(Roo.bootstrap.form.MonthField, {
24848 cls: 'datepicker dropdown-menu roo-dynamic',
24852 cls: 'datepicker-months',
24856 cls: 'table-condensed',
24858 Roo.bootstrap.form.DateField.content
24878 * @class Roo.bootstrap.form.CheckBox
24879 * @extends Roo.bootstrap.form.Input
24880 * Bootstrap CheckBox class
24882 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
24883 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
24884 * @cfg {String} boxLabel The text that appears beside the checkbox
24885 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
24886 * @cfg {Boolean} checked initnal the element
24887 * @cfg {Boolean} inline inline the element (default false)
24888 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
24889 * @cfg {String} tooltip label tooltip
24892 * Create a new CheckBox
24893 * @param {Object} config The config object
24896 Roo.bootstrap.form.CheckBox = function(config){
24897 Roo.bootstrap.form.CheckBox.superclass.constructor.call(this, config);
24902 * Fires when the element is checked or unchecked.
24903 * @param {Roo.bootstrap.form.CheckBox} this This input
24904 * @param {Boolean} checked The new checked value
24909 * Fires when the element is click.
24910 * @param {Roo.bootstrap.form.CheckBox} this This input
24917 Roo.extend(Roo.bootstrap.form.CheckBox, Roo.bootstrap.form.Input, {
24919 inputType: 'checkbox',
24928 // checkbox success does not make any sense really..
24933 getAutoCreate : function()
24935 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
24941 cfg.cls = 'form-group form-check ' + this.inputType; //input-group
24944 cfg.cls += ' ' + this.inputType + '-inline form-check-inline';
24950 type : this.inputType,
24951 value : this.inputValue,
24952 cls : 'roo-' + this.inputType, //'form-box',
24953 placeholder : this.placeholder || ''
24957 if(this.inputType != 'radio'){
24961 cls : 'roo-hidden-value',
24962 value : this.checked ? this.inputValue : this.valueOff
24967 if (this.weight) { // Validity check?
24968 cfg.cls += " " + this.inputType + "-" + this.weight;
24971 if (this.disabled) {
24972 input.disabled=true;
24976 input.checked = this.checked;
24981 input.name = this.name;
24983 if(this.inputType != 'radio'){
24984 hidden.name = this.name;
24985 input.name = '_hidden_' + this.name;
24990 input.cls += ' input-' + this.size;
24995 ['xs','sm','md','lg'].map(function(size){
24996 if (settings[size]) {
24997 cfg.cls += ' col-' + size + '-' + settings[size];
25001 var inputblock = input;
25003 if (this.before || this.after) {
25006 cls : 'input-group',
25011 inputblock.cn.push({
25013 cls : 'input-group-addon',
25018 inputblock.cn.push(input);
25020 if(this.inputType != 'radio'){
25021 inputblock.cn.push(hidden);
25025 inputblock.cn.push({
25027 cls : 'input-group-addon',
25033 var boxLabelCfg = false;
25039 //'for': id, // box label is handled by onclick - so no for...
25041 html: this.boxLabel
25044 boxLabelCfg.tooltip = this.tooltip;
25050 if (align ==='left' && this.fieldLabel.length) {
25051 // Roo.log("left and has label");
25056 cls : 'control-label',
25057 html : this.fieldLabel
25068 cfg.cn[1].cn.push(boxLabelCfg);
25071 if(this.labelWidth > 12){
25072 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
25075 if(this.labelWidth < 13 && this.labelmd == 0){
25076 this.labelmd = this.labelWidth;
25079 if(this.labellg > 0){
25080 cfg.cn[0].cls += ' col-lg-' + this.labellg;
25081 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
25084 if(this.labelmd > 0){
25085 cfg.cn[0].cls += ' col-md-' + this.labelmd;
25086 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
25089 if(this.labelsm > 0){
25090 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
25091 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
25094 if(this.labelxs > 0){
25095 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
25096 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
25099 } else if ( this.fieldLabel.length) {
25100 // Roo.log(" label");
25104 tag: this.boxLabel ? 'span' : 'label',
25106 cls: 'control-label box-input-label',
25107 //cls : 'input-group-addon',
25108 html : this.fieldLabel
25115 cfg.cn.push(boxLabelCfg);
25120 // Roo.log(" no label && no align");
25121 cfg.cn = [ inputblock ] ;
25123 cfg.cn.push(boxLabelCfg);
25131 if(this.inputType != 'radio'){
25132 cfg.cn.push(hidden);
25140 * return the real input element.
25142 inputEl: function ()
25144 return this.el.select('input.roo-' + this.inputType,true).first();
25146 hiddenEl: function ()
25148 return this.el.select('input.roo-hidden-value',true).first();
25151 labelEl: function()
25153 return this.el.select('label.control-label',true).first();
25155 /* depricated... */
25159 return this.labelEl();
25162 boxLabelEl: function()
25164 return this.el.select('label.box-label',true).first();
25167 initEvents : function()
25169 // Roo.bootstrap.form.CheckBox.superclass.initEvents.call(this);
25171 this.inputEl().on('click', this.onClick, this);
25173 if (this.boxLabel) {
25174 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
25177 this.startValue = this.getValue();
25180 Roo.bootstrap.form.CheckBox.register(this);
25184 onClick : function(e)
25186 if(this.fireEvent('click', this, e) !== false){
25187 this.setChecked(!this.checked);
25192 setChecked : function(state,suppressEvent)
25194 this.startValue = this.getValue();
25196 if(this.inputType == 'radio'){
25198 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25199 e.dom.checked = false;
25202 this.inputEl().dom.checked = true;
25204 this.inputEl().dom.value = this.inputValue;
25206 if(suppressEvent !== true){
25207 this.fireEvent('check', this, true);
25215 this.checked = state;
25217 this.inputEl().dom.checked = state;
25220 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
25222 if(suppressEvent !== true){
25223 this.fireEvent('check', this, state);
25229 getValue : function()
25231 if(this.inputType == 'radio'){
25232 return this.getGroupValue();
25235 return this.hiddenEl().dom.value;
25239 getGroupValue : function()
25241 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
25245 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
25248 setValue : function(v,suppressEvent)
25250 if(this.inputType == 'radio'){
25251 this.setGroupValue(v, suppressEvent);
25255 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
25260 setGroupValue : function(v, suppressEvent)
25262 this.startValue = this.getValue();
25264 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25265 e.dom.checked = false;
25267 if(e.dom.value == v){
25268 e.dom.checked = true;
25272 if(suppressEvent !== true){
25273 this.fireEvent('check', this, true);
25281 validate : function()
25283 if(this.getVisibilityEl().hasClass('hidden')){
25289 (this.inputType == 'radio' && this.validateRadio()) ||
25290 (this.inputType == 'checkbox' && this.validateCheckbox())
25296 this.markInvalid();
25300 validateRadio : function()
25302 if(this.getVisibilityEl().hasClass('hidden')){
25306 if(this.allowBlank){
25312 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25313 if(!e.dom.checked){
25325 validateCheckbox : function()
25328 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
25329 //return (this.getValue() == this.inputValue) ? true : false;
25332 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25340 for(var i in group){
25341 if(group[i].el.isVisible(true)){
25349 for(var i in group){
25354 r = (group[i].getValue() == group[i].inputValue) ? true : false;
25361 * Mark this field as valid
25363 markValid : function()
25367 this.fireEvent('valid', this);
25369 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25372 label = Roo.bootstrap.form.FieldLabel.get(this.groupId + '-group');
25379 if(this.inputType == 'radio'){
25380 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25381 var fg = e.findParent('.form-group', false, true);
25382 if (Roo.bootstrap.version == 3) {
25383 fg.removeClass([_this.invalidClass, _this.validClass]);
25384 fg.addClass(_this.validClass);
25386 fg.removeClass(['is-valid', 'is-invalid']);
25387 fg.addClass('is-valid');
25395 var fg = this.el.findParent('.form-group', false, true);
25396 if (Roo.bootstrap.version == 3) {
25397 fg.removeClass([this.invalidClass, this.validClass]);
25398 fg.addClass(this.validClass);
25400 fg.removeClass(['is-valid', 'is-invalid']);
25401 fg.addClass('is-valid');
25406 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25412 for(var i in group){
25413 var fg = group[i].el.findParent('.form-group', false, true);
25414 if (Roo.bootstrap.version == 3) {
25415 fg.removeClass([this.invalidClass, this.validClass]);
25416 fg.addClass(this.validClass);
25418 fg.removeClass(['is-valid', 'is-invalid']);
25419 fg.addClass('is-valid');
25425 * Mark this field as invalid
25426 * @param {String} msg The validation message
25428 markInvalid : function(msg)
25430 if(this.allowBlank){
25436 this.fireEvent('invalid', this, msg);
25438 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25441 label = Roo.bootstrap.form.FieldLabel.get(this.groupId + '-group');
25445 label.markInvalid();
25448 if(this.inputType == 'radio'){
25450 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25451 var fg = e.findParent('.form-group', false, true);
25452 if (Roo.bootstrap.version == 3) {
25453 fg.removeClass([_this.invalidClass, _this.validClass]);
25454 fg.addClass(_this.invalidClass);
25456 fg.removeClass(['is-invalid', 'is-valid']);
25457 fg.addClass('is-invalid');
25465 var fg = this.el.findParent('.form-group', false, true);
25466 if (Roo.bootstrap.version == 3) {
25467 fg.removeClass([_this.invalidClass, _this.validClass]);
25468 fg.addClass(_this.invalidClass);
25470 fg.removeClass(['is-invalid', 'is-valid']);
25471 fg.addClass('is-invalid');
25476 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25482 for(var i in group){
25483 var fg = group[i].el.findParent('.form-group', false, true);
25484 if (Roo.bootstrap.version == 3) {
25485 fg.removeClass([_this.invalidClass, _this.validClass]);
25486 fg.addClass(_this.invalidClass);
25488 fg.removeClass(['is-invalid', 'is-valid']);
25489 fg.addClass('is-invalid');
25495 clearInvalid : function()
25497 Roo.bootstrap.form.Input.prototype.clearInvalid.call(this);
25499 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
25501 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25503 if (label && label.iconEl) {
25504 label.iconEl.removeClass([ label.validClass, label.invalidClass ]);
25505 label.iconEl.removeClass(['is-invalid', 'is-valid']);
25509 disable : function()
25511 if(this.inputType != 'radio'){
25512 Roo.bootstrap.form.CheckBox.superclass.disable.call(this);
25519 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25520 _this.getActionEl().addClass(this.disabledClass);
25521 e.dom.disabled = true;
25525 this.disabled = true;
25526 this.fireEvent("disable", this);
25530 enable : function()
25532 if(this.inputType != 'radio'){
25533 Roo.bootstrap.form.CheckBox.superclass.enable.call(this);
25540 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25541 _this.getActionEl().removeClass(this.disabledClass);
25542 e.dom.disabled = false;
25546 this.disabled = false;
25547 this.fireEvent("enable", this);
25551 setBoxLabel : function(v)
25556 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
25562 Roo.apply(Roo.bootstrap.form.CheckBox, {
25567 * register a CheckBox Group
25568 * @param {Roo.bootstrap.form.CheckBox} the CheckBox to add
25570 register : function(checkbox)
25572 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
25573 this.groups[checkbox.groupId] = {};
25576 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
25580 this.groups[checkbox.groupId][checkbox.name] = checkbox;
25584 * fetch a CheckBox Group based on the group ID
25585 * @param {string} the group ID
25586 * @returns {Roo.bootstrap.form.CheckBox} the CheckBox group
25588 get: function(groupId) {
25589 if (typeof(this.groups[groupId]) == 'undefined') {
25593 return this.groups[groupId] ;
25606 * @class Roo.bootstrap.form.Radio
25607 * @extends Roo.bootstrap.Component
25608 * Bootstrap Radio class
25609 * @cfg {String} boxLabel - the label associated
25610 * @cfg {String} value - the value of radio
25613 * Create a new Radio
25614 * @param {Object} config The config object
25616 Roo.bootstrap.form.Radio = function(config){
25617 Roo.bootstrap.form.Radio.superclass.constructor.call(this, config);
25621 Roo.extend(Roo.bootstrap.form.Radio, Roo.bootstrap.Component, {
25627 getAutoCreate : function()
25631 cls : 'form-group radio',
25636 html : this.boxLabel
25644 initEvents : function()
25646 this.parent().register(this);
25648 this.el.on('click', this.onClick, this);
25652 onClick : function(e)
25654 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
25655 this.setChecked(true);
25659 setChecked : function(state, suppressEvent)
25661 this.parent().setValue(this.value, suppressEvent);
25665 setBoxLabel : function(v)
25670 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
25685 * @class Roo.bootstrap.form.SecurePass
25686 * @extends Roo.bootstrap.form.Input
25687 * Bootstrap SecurePass class
25691 * Create a new SecurePass
25692 * @param {Object} config The config object
25695 Roo.bootstrap.form.SecurePass = function (config) {
25696 // these go here, so the translation tool can replace them..
25698 PwdEmpty: "Please type a password, and then retype it to confirm.",
25699 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
25700 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
25701 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
25702 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
25703 FNInPwd: "Your password can't contain your first name. Please type a different password.",
25704 LNInPwd: "Your password can't contain your last name. Please type a different password.",
25705 TooWeak: "Your password is Too Weak."
25707 this.meterLabel = "Password strength:";
25708 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
25709 this.meterClass = [
25710 "roo-password-meter-tooweak",
25711 "roo-password-meter-weak",
25712 "roo-password-meter-medium",
25713 "roo-password-meter-strong",
25714 "roo-password-meter-grey"
25719 Roo.bootstrap.form.SecurePass.superclass.constructor.call(this, config);
25722 Roo.extend(Roo.bootstrap.form.SecurePass, Roo.bootstrap.form.Input, {
25724 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
25726 * PwdEmpty: "Please type a password, and then retype it to confirm.",
25727 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
25728 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
25729 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
25730 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
25731 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
25732 * LNInPwd: "Your password can't contain your last name. Please type a different password."
25742 * @cfg {String/Object} Label for the strength meter (defaults to
25743 * 'Password strength:')
25748 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
25749 * ['Weak', 'Medium', 'Strong'])
25752 pwdStrengths: false,
25765 initEvents: function ()
25767 Roo.bootstrap.form.SecurePass.superclass.initEvents.call(this);
25769 if (this.el.is('input[type=password]') && Roo.isSafari) {
25770 this.el.on('keydown', this.SafariOnKeyDown, this);
25773 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
25776 onRender: function (ct, position)
25778 Roo.bootstrap.form.SecurePass.superclass.onRender.call(this, ct, position);
25779 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
25780 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
25782 this.trigger.createChild({
25787 cls: 'roo-password-meter-grey col-xs-12',
25790 //width: this.meterWidth + 'px'
25794 cls: 'roo-password-meter-text'
25800 if (this.hideTrigger) {
25801 this.trigger.setDisplayed(false);
25803 this.setSize(this.width || '', this.height || '');
25806 onDestroy: function ()
25808 if (this.trigger) {
25809 this.trigger.removeAllListeners();
25810 this.trigger.remove();
25813 this.wrap.remove();
25815 Roo.bootstrap.form.TriggerField.superclass.onDestroy.call(this);
25818 checkStrength: function ()
25820 var pwd = this.inputEl().getValue();
25821 if (pwd == this._lastPwd) {
25826 if (this.ClientSideStrongPassword(pwd)) {
25828 } else if (this.ClientSideMediumPassword(pwd)) {
25830 } else if (this.ClientSideWeakPassword(pwd)) {
25836 Roo.log('strength1: ' + strength);
25838 //var pm = this.trigger.child('div/div/div').dom;
25839 var pm = this.trigger.child('div/div');
25840 pm.removeClass(this.meterClass);
25841 pm.addClass(this.meterClass[strength]);
25844 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25846 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
25848 this._lastPwd = pwd;
25852 Roo.bootstrap.form.SecurePass.superclass.reset.call(this);
25854 this._lastPwd = '';
25856 var pm = this.trigger.child('div/div');
25857 pm.removeClass(this.meterClass);
25858 pm.addClass('roo-password-meter-grey');
25861 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25864 this.inputEl().dom.type='password';
25867 validateValue: function (value)
25869 if (!Roo.bootstrap.form.SecurePass.superclass.validateValue.call(this, value)) {
25872 if (value.length == 0) {
25873 if (this.allowBlank) {
25874 this.clearInvalid();
25878 this.markInvalid(this.errors.PwdEmpty);
25879 this.errorMsg = this.errors.PwdEmpty;
25887 if (!value.match(/[\x21-\x7e]+/)) {
25888 this.markInvalid(this.errors.PwdBadChar);
25889 this.errorMsg = this.errors.PwdBadChar;
25892 if (value.length < 6) {
25893 this.markInvalid(this.errors.PwdShort);
25894 this.errorMsg = this.errors.PwdShort;
25897 if (value.length > 16) {
25898 this.markInvalid(this.errors.PwdLong);
25899 this.errorMsg = this.errors.PwdLong;
25903 if (this.ClientSideStrongPassword(value)) {
25905 } else if (this.ClientSideMediumPassword(value)) {
25907 } else if (this.ClientSideWeakPassword(value)) {
25914 if (strength < 2) {
25915 //this.markInvalid(this.errors.TooWeak);
25916 this.errorMsg = this.errors.TooWeak;
25921 console.log('strength2: ' + strength);
25923 //var pm = this.trigger.child('div/div/div').dom;
25925 var pm = this.trigger.child('div/div');
25926 pm.removeClass(this.meterClass);
25927 pm.addClass(this.meterClass[strength]);
25929 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25931 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
25933 this.errorMsg = '';
25937 CharacterSetChecks: function (type)
25940 this.fResult = false;
25943 isctype: function (character, type)
25946 case this.kCapitalLetter:
25947 if (character >= 'A' && character <= 'Z') {
25952 case this.kSmallLetter:
25953 if (character >= 'a' && character <= 'z') {
25959 if (character >= '0' && character <= '9') {
25964 case this.kPunctuation:
25965 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
25976 IsLongEnough: function (pwd, size)
25978 return !(pwd == null || isNaN(size) || pwd.length < size);
25981 SpansEnoughCharacterSets: function (word, nb)
25983 if (!this.IsLongEnough(word, nb))
25988 var characterSetChecks = new Array(
25989 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
25990 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
25993 for (var index = 0; index < word.length; ++index) {
25994 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
25995 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
25996 characterSetChecks[nCharSet].fResult = true;
26003 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
26004 if (characterSetChecks[nCharSet].fResult) {
26009 if (nCharSets < nb) {
26015 ClientSideStrongPassword: function (pwd)
26017 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
26020 ClientSideMediumPassword: function (pwd)
26022 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
26025 ClientSideWeakPassword: function (pwd)
26027 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
26031 Roo.htmleditor = {};
26034 * @class Roo.htmleditor.Filter
26035 * Base Class for filtering htmleditor stuff. - do not use this directly - extend it.
26036 * @cfg {DomElement} node The node to iterate and filter
26037 * @cfg {boolean|String|Array} tag Tags to replace
26039 * Create a new Filter.
26040 * @param {Object} config Configuration options
26045 Roo.htmleditor.Filter = function(cfg) {
26046 Roo.apply(this.cfg);
26047 // this does not actually call walk as it's really just a abstract class
26051 Roo.htmleditor.Filter.prototype = {
26057 // overrride to do replace comments.
26058 replaceComment : false,
26060 // overrride to do replace or do stuff with tags..
26061 replaceTag : false,
26063 walk : function(dom)
26065 Roo.each( Array.from(dom.childNodes), function( e ) {
26068 case e.nodeType == 8 && this.replaceComment !== false: // comment
26069 this.replaceComment(e);
26072 case e.nodeType != 1: //not a node.
26075 case this.tag === true: // everything
26076 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1:
26077 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":":
26078 case typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1: // array and it matches.
26079 case typeof(this.tag) == 'string' && this.tag == e.tagName: // array and it matches.
26080 if (this.replaceTag && false === this.replaceTag(e)) {
26083 if (e.hasChildNodes()) {
26088 default: // tags .. that do not match.
26089 if (e.hasChildNodes()) {
26099 removeNodeKeepChildren : function( node)
26102 ar = Array.from(node.childNodes);
26103 for (var i = 0; i < ar.length; i++) {
26105 node.removeChild(ar[i]);
26106 // what if we need to walk these???
26107 node.parentNode.insertBefore(ar[i], node);
26110 node.parentNode.removeChild(node);
26115 * @class Roo.htmleditor.FilterAttributes
26116 * clean attributes and styles including http:// etc.. in attribute
26118 * Run a new Attribute Filter
26119 * @param {Object} config Configuration options
26121 Roo.htmleditor.FilterAttributes = function(cfg)
26123 Roo.apply(this, cfg);
26124 this.attrib_black = this.attrib_black || [];
26125 this.attrib_white = this.attrib_white || [];
26127 this.attrib_clean = this.attrib_clean || [];
26128 this.style_white = this.style_white || [];
26129 this.style_black = this.style_black || [];
26130 this.walk(cfg.node);
26133 Roo.extend(Roo.htmleditor.FilterAttributes, Roo.htmleditor.Filter,
26135 tag: true, // all tags
26137 attrib_black : false, // array
26138 attrib_clean : false,
26139 attrib_white : false,
26141 style_white : false,
26142 style_black : false,
26145 replaceTag : function(node)
26147 if (!node.attributes || !node.attributes.length) {
26151 for (var i = node.attributes.length-1; i > -1 ; i--) {
26152 var a = node.attributes[i];
26154 if (this.attrib_white.length && this.attrib_white.indexOf(a.name.toLowerCase()) < 0) {
26155 node.removeAttribute(a.name);
26161 if (a.name.toLowerCase().substr(0,2)=='on') {
26162 node.removeAttribute(a.name);
26167 if (this.attrib_black.indexOf(a.name.toLowerCase()) > -1) {
26168 node.removeAttribute(a.name);
26171 if (this.attrib_clean.indexOf(a.name.toLowerCase()) > -1) {
26172 this.cleanAttr(node,a.name,a.value); // fixme..
26175 if (a.name == 'style') {
26176 this.cleanStyle(node,a.name,a.value);
26179 /// clean up MS crap..
26180 // tecnically this should be a list of valid class'es..
26183 if (a.name == 'class') {
26184 if (a.value.match(/^Mso/)) {
26185 node.removeAttribute('class');
26188 if (a.value.match(/^body$/)) {
26189 node.removeAttribute('class');
26199 return true; // clean children
26202 cleanAttr: function(node, n,v)
26205 if (v.match(/^\./) || v.match(/^\//)) {
26208 if (v.match(/^(http|https):\/\//)
26209 || v.match(/^mailto:/)
26210 || v.match(/^ftp:/)
26211 || v.match(/^data:/)
26215 if (v.match(/^#/)) {
26218 if (v.match(/^\{/)) { // allow template editing.
26221 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
26222 node.removeAttribute(n);
26225 cleanStyle : function(node, n,v)
26227 if (v.match(/expression/)) { //XSS?? should we even bother..
26228 node.removeAttribute(n);
26232 var parts = v.split(/;/);
26235 Roo.each(parts, function(p) {
26236 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
26240 var l = p.split(':').shift().replace(/\s+/g,'');
26241 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
26243 if ( this.style_black.length && (this.style_black.indexOf(l) > -1 || this.style_black.indexOf(l.toLowerCase()) > -1)) {
26247 // only allow 'c whitelisted system attributes'
26248 if ( this.style_white.length && style_white.indexOf(l) < 0 && style_white.indexOf(l.toLowerCase()) < 0 ) {
26256 if (clean.length) {
26257 node.setAttribute(n, clean.join(';'));
26259 node.removeAttribute(n);
26268 * @class Roo.htmleditor.FilterBlack
26269 * remove blacklisted elements.
26271 * Run a new Blacklisted Filter
26272 * @param {Object} config Configuration options
26275 Roo.htmleditor.FilterBlack = function(cfg)
26277 Roo.apply(this, cfg);
26278 this.walk(cfg.node);
26281 Roo.extend(Roo.htmleditor.FilterBlack, Roo.htmleditor.Filter,
26283 tag : true, // all elements.
26285 replaceTag : function(n)
26287 n.parentNode.removeChild(n);
26291 * @class Roo.htmleditor.FilterComment
26294 * Run a new Comments Filter
26295 * @param {Object} config Configuration options
26297 Roo.htmleditor.FilterComment = function(cfg)
26299 this.walk(cfg.node);
26302 Roo.extend(Roo.htmleditor.FilterComment, Roo.htmleditor.Filter,
26305 replaceComment : function(n)
26307 n.parentNode.removeChild(n);
26310 * @class Roo.htmleditor.FilterKeepChildren
26311 * remove tags but keep children
26313 * Run a new Keep Children Filter
26314 * @param {Object} config Configuration options
26317 Roo.htmleditor.FilterKeepChildren = function(cfg)
26319 Roo.apply(this, cfg);
26320 if (this.tag === false) {
26321 return; // dont walk.. (you can use this to use this just to do a child removal on a single tag )
26324 if ((typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)) {
26325 this.cleanNamespace = true;
26328 this.walk(cfg.node);
26331 Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack,
26333 cleanNamespace : false, // should really be an option, rather than using ':' inside of this tag.
26335 replaceTag : function(node)
26337 // walk children...
26338 //Roo.log(node.tagName);
26339 var ar = Array.from(node.childNodes);
26342 for (var i = 0; i < ar.length; i++) {
26344 if (e.nodeType == 1) {
26346 (typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1)
26347 || // array and it matches
26348 (typeof(this.tag) == 'string' && this.tag == e.tagName)
26350 (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)
26352 (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":")
26354 this.replaceTag(ar[i]); // child is blacklisted as well...
26359 ar = Array.from(node.childNodes);
26360 for (var i = 0; i < ar.length; i++) {
26362 node.removeChild(ar[i]);
26363 // what if we need to walk these???
26364 node.parentNode.insertBefore(ar[i], node);
26365 if (this.tag !== false) {
26370 //Roo.log("REMOVE:" + node.tagName);
26371 node.parentNode.removeChild(node);
26372 return false; // don't walk children
26377 * @class Roo.htmleditor.FilterParagraph
26378 * paragraphs cause a nightmare for shared content - this filter is designed to be called ? at various points when editing
26379 * like on 'push' to remove the <p> tags and replace them with line breaks.
26381 * Run a new Paragraph Filter
26382 * @param {Object} config Configuration options
26385 Roo.htmleditor.FilterParagraph = function(cfg)
26387 // no need to apply config.
26388 this.walk(cfg.node);
26391 Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter,
26398 replaceTag : function(node)
26401 if (node.childNodes.length == 1 &&
26402 node.childNodes[0].nodeType == 3 &&
26403 node.childNodes[0].textContent.trim().length < 1
26405 // remove and replace with '<BR>';
26406 node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node);
26407 return false; // no need to walk..
26409 var ar = Array.from(node.childNodes);
26410 for (var i = 0; i < ar.length; i++) {
26411 node.removeChild(ar[i]);
26412 // what if we need to walk these???
26413 node.parentNode.insertBefore(ar[i], node);
26415 // now what about this?
26419 node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
26420 node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
26421 node.parentNode.removeChild(node);
26428 * @class Roo.htmleditor.FilterSpan
26429 * filter span's with no attributes out..
26431 * Run a new Span Filter
26432 * @param {Object} config Configuration options
26435 Roo.htmleditor.FilterSpan = function(cfg)
26437 // no need to apply config.
26438 this.walk(cfg.node);
26441 Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterKeepChildren,
26447 replaceTag : function(node)
26449 if (node.attributes && node.attributes.length > 0) {
26450 return true; // walk if there are any.
26452 Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this, node);
26458 * @class Roo.htmleditor.FilterTableWidth
26459 try and remove table width data - as that frequently messes up other stuff.
26461 * was cleanTableWidths.
26463 * Quite often pasting from word etc.. results in tables with column and widths.
26464 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
26467 * Run a new Table Filter
26468 * @param {Object} config Configuration options
26471 Roo.htmleditor.FilterTableWidth = function(cfg)
26473 // no need to apply config.
26474 this.tag = ['TABLE', 'TD', 'TR', 'TH', 'THEAD', 'TBODY' ];
26475 this.walk(cfg.node);
26478 Roo.extend(Roo.htmleditor.FilterTableWidth, Roo.htmleditor.Filter,
26483 replaceTag: function(node) {
26487 if (node.hasAttribute('width')) {
26488 node.removeAttribute('width');
26492 if (node.hasAttribute("style")) {
26495 var styles = node.getAttribute("style").split(";");
26497 Roo.each(styles, function(s) {
26498 if (!s.match(/:/)) {
26501 var kv = s.split(":");
26502 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
26505 // what ever is left... we allow.
26508 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
26509 if (!nstyle.length) {
26510 node.removeAttribute('style');
26514 return true; // continue doing children..
26517 * @class Roo.htmleditor.FilterWord
26518 * try and clean up all the mess that Word generates.
26520 * This is the 'nice version' - see 'Heavy' that white lists a very short list of elements, and multi-filters
26523 * Run a new Span Filter
26524 * @param {Object} config Configuration options
26527 Roo.htmleditor.FilterWord = function(cfg)
26529 // no need to apply config.
26530 this.replaceDocBullets(cfg.node);
26532 this.replaceAname(cfg.node);
26533 // this is disabled as the removal is done by other filters;
26534 // this.walk(cfg.node);
26539 Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
26545 * Clean up MS wordisms...
26547 replaceTag : function(node)
26550 // no idea what this does - span with text, replaceds with just text.
26552 node.nodeName == 'SPAN' &&
26553 !node.hasAttributes() &&
26554 node.childNodes.length == 1 &&
26555 node.firstChild.nodeName == "#text"
26557 var textNode = node.firstChild;
26558 node.removeChild(textNode);
26559 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
26560 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node);
26562 node.parentNode.insertBefore(textNode, node);
26563 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
26564 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node);
26567 node.parentNode.removeChild(node);
26568 return false; // dont do chidren - we have remove our node - so no need to do chdhilren?
26573 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
26574 node.parentNode.removeChild(node);
26575 return false; // dont do chidlren
26577 //Roo.log(node.tagName);
26578 // remove - but keep children..
26579 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) {
26580 //Roo.log('-- removed');
26581 while (node.childNodes.length) {
26582 var cn = node.childNodes[0];
26583 node.removeChild(cn);
26584 node.parentNode.insertBefore(cn, node);
26585 // move node to parent - and clean it..
26586 if (cn.nodeType == 1) {
26587 this.replaceTag(cn);
26591 node.parentNode.removeChild(node);
26592 /// no need to iterate chidlren = it's got none..
26593 //this.iterateChildren(node, this.cleanWord);
26594 return false; // no need to iterate children.
26597 if (node.className.length) {
26599 var cn = node.className.split(/\W+/);
26601 Roo.each(cn, function(cls) {
26602 if (cls.match(/Mso[a-zA-Z]+/)) {
26607 node.className = cna.length ? cna.join(' ') : '';
26609 node.removeAttribute("class");
26613 if (node.hasAttribute("lang")) {
26614 node.removeAttribute("lang");
26617 if (node.hasAttribute("style")) {
26619 var styles = node.getAttribute("style").split(";");
26621 Roo.each(styles, function(s) {
26622 if (!s.match(/:/)) {
26625 var kv = s.split(":");
26626 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
26629 // what ever is left... we allow.
26632 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
26633 if (!nstyle.length) {
26634 node.removeAttribute('style');
26637 return true; // do children
26643 styleToObject: function(node)
26645 var styles = (node.getAttribute("style") || '').split(";");
26647 Roo.each(styles, function(s) {
26648 if (!s.match(/:/)) {
26651 var kv = s.split(":");
26653 // what ever is left... we allow.
26654 ret[kv[0].trim()] = kv[1];
26660 replaceAname : function (doc)
26662 // replace all the a/name without..
26663 var aa = Array.from(doc.getElementsByTagName('a'));
26664 for (var i = 0; i < aa.length; i++) {
26666 if (a.hasAttribute("name")) {
26667 a.removeAttribute("name");
26669 if (a.hasAttribute("href")) {
26672 // reparent children.
26673 this.removeNodeKeepChildren(a);
26683 replaceDocBullets : function(doc)
26685 // this is a bit odd - but it appears some indents use ql-indent-1
26686 //Roo.log(doc.innerHTML);
26688 var listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpFirst'));
26689 for( var i = 0; i < listpara.length; i ++) {
26690 listpara[i].className = "MsoListParagraph";
26693 listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpMiddle'));
26694 for( var i = 0; i < listpara.length; i ++) {
26695 listpara[i].className = "MsoListParagraph";
26697 listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpLast'));
26698 for( var i = 0; i < listpara.length; i ++) {
26699 listpara[i].className = "MsoListParagraph";
26701 listpara = Array.from(doc.getElementsByClassName('ql-indent-1'));
26702 for( var i = 0; i < listpara.length; i ++) {
26703 listpara[i].className = "MsoListParagraph";
26706 // this is a bit hacky - we had one word document where h2 had a miso-list attribute.
26707 var htwo = Array.from(doc.getElementsByTagName('h2'));
26708 for( var i = 0; i < htwo.length; i ++) {
26709 if (htwo[i].hasAttribute('style') && htwo[i].getAttribute('style').match(/mso-list:/)) {
26710 htwo[i].className = "MsoListParagraph";
26713 listpara = Array.from(doc.getElementsByClassName('MsoNormal'));
26714 for( var i = 0; i < listpara.length; i ++) {
26715 if (listpara[i].hasAttribute('style') && listpara[i].getAttribute('style').match(/mso-list:/)) {
26716 listpara[i].className = "MsoListParagraph";
26718 listpara[i].className = "MsoNormalx";
26722 listpara = doc.getElementsByClassName('MsoListParagraph');
26723 // Roo.log(doc.innerHTML);
26727 while(listpara.length) {
26729 this.replaceDocBullet(listpara.item(0));
26736 replaceDocBullet : function(p)
26738 // gather all the siblings.
26740 parent = p.parentNode,
26741 doc = parent.ownerDocument,
26744 var listtype = 'ul';
26746 if (ns.nodeType != 1) {
26747 ns = ns.nextSibling;
26750 if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) {
26753 var spans = ns.getElementsByTagName('span');
26754 if (ns.hasAttribute('style') && ns.getAttribute('style').match(/mso-list/)) {
26756 ns = ns.nextSibling;
26758 if (spans.length && spans[0].hasAttribute('style')) {
26759 var style = this.styleToObject(spans[0]);
26760 if (typeof(style['font-family']) != 'undefined' && !style['font-family'].match(/Symbol/)) {
26767 var spans = ns.getElementsByTagName('span');
26768 if (!spans.length) {
26771 var has_list = false;
26772 for(var i = 0; i < spans.length; i++) {
26773 if (spans[i].hasAttribute('style') && spans[i].getAttribute('style').match(/mso-list/)) {
26782 ns = ns.nextSibling;
26786 if (!items.length) {
26791 var ul = parent.ownerDocument.createElement(listtype); // what about number lists...
26792 parent.insertBefore(ul, p);
26794 var stack = [ ul ];
26795 var last_li = false;
26797 var margin_to_depth = {};
26800 items.forEach(function(n, ipos) {
26801 //Roo.log("got innertHMLT=" + n.innerHTML);
26803 var spans = n.getElementsByTagName('span');
26804 if (!spans.length) {
26805 //Roo.log("No spans found");
26807 parent.removeChild(n);
26810 return; // skip it...
26816 for(var i = 0; i < spans.length; i++) {
26818 style = this.styleToObject(spans[i]);
26819 if (typeof(style['mso-list']) == 'undefined') {
26822 if (listtype == 'ol') {
26823 num = spans[i].innerText.replace(/[^0-9]+]/g,'') * 1;
26825 spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet.
26828 //Roo.log("NOW GOT innertHMLT=" + n.innerHTML);
26829 style = this.styleToObject(n); // mo-list is from the parent node.
26830 if (typeof(style['mso-list']) == 'undefined') {
26831 //Roo.log("parent is missing level");
26833 parent.removeChild(n);
26838 var margin = style['margin-left'];
26839 if (typeof(margin_to_depth[margin]) == 'undefined') {
26841 margin_to_depth[margin] = max_margins;
26843 nlvl = margin_to_depth[margin] ;
26847 var nul = doc.createElement(listtype); // what about number lists...
26849 last_li = doc.createElement('li');
26850 stack[lvl].appendChild(last_li);
26852 last_li.appendChild(nul);
26858 // not starting at 1..
26859 if (!stack[nlvl].hasAttribute("start") && listtype == "ol") {
26860 stack[nlvl].setAttribute("start", num);
26863 var nli = stack[nlvl].appendChild(doc.createElement('li'));
26865 nli.innerHTML = n.innerHTML;
26866 //Roo.log("innerHTML = " + n.innerHTML);
26867 parent.removeChild(n);
26883 * @class Roo.htmleditor.FilterStyleToTag
26884 * part of the word stuff... - certain 'styles' should be converted to tags.
26886 * font-weight: bold -> bold
26887 * ?? super / subscrit etc..
26890 * Run a new style to tag filter.
26891 * @param {Object} config Configuration options
26893 Roo.htmleditor.FilterStyleToTag = function(cfg)
26897 B : [ 'fontWeight' , 'bold'],
26898 I : [ 'fontStyle' , 'italic'],
26899 //pre : [ 'font-style' , 'italic'],
26900 // h1.. h6 ?? font-size?
26901 SUP : [ 'verticalAlign' , 'super' ],
26902 SUB : [ 'verticalAlign' , 'sub' ]
26907 Roo.apply(this, cfg);
26910 this.walk(cfg.node);
26917 Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter,
26919 tag: true, // all tags
26924 replaceTag : function(node)
26928 if (node.getAttribute("style") === null) {
26932 for (var k in this.tags) {
26933 if (node.style[this.tags[k][0]] == this.tags[k][1]) {
26935 node.style.removeProperty(this.tags[k][0]);
26938 if (!inject.length) {
26941 var cn = Array.from(node.childNodes);
26943 Roo.each(inject, function(t) {
26944 var nc = node.ownerDocument.createElement(t);
26945 nn.appendChild(nc);
26948 for(var i = 0;i < cn.length;cn++) {
26949 node.removeChild(cn[i]);
26950 nn.appendChild(cn[i]);
26952 return true /// iterate thru
26956 * @class Roo.htmleditor.FilterLongBr
26957 * BR/BR/BR - keep a maximum of 2...
26959 * Run a new Long BR Filter
26960 * @param {Object} config Configuration options
26963 Roo.htmleditor.FilterLongBr = function(cfg)
26965 // no need to apply config.
26966 this.walk(cfg.node);
26969 Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter,
26976 replaceTag : function(node)
26979 var ps = node.nextSibling;
26980 while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
26981 ps = ps.nextSibling;
26984 if (!ps && [ 'TD', 'TH', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(node.parentNode.tagName) > -1) {
26985 node.parentNode.removeChild(node); // remove last BR inside one fo these tags
26989 if (!ps || ps.nodeType != 1) {
26993 if (!ps || ps.tagName != 'BR') {
27002 if (!node.previousSibling) {
27005 var ps = node.previousSibling;
27007 while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
27008 ps = ps.previousSibling;
27010 if (!ps || ps.nodeType != 1) {
27013 // if header or BR before.. then it's a candidate for removal.. - as we only want '2' of these..
27014 if (!ps || [ 'BR', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(ps.tagName) < 0) {
27018 node.parentNode.removeChild(node); // remove me...
27020 return false; // no need to do children
27027 * @class Roo.htmleditor.FilterBlock
27028 * removes id / data-block and contenteditable that are associated with blocks
27029 * usage should be done on a cloned copy of the dom
27031 * Run a new Attribute Filter { node : xxxx }}
27032 * @param {Object} config Configuration options
27034 Roo.htmleditor.FilterBlock = function(cfg)
27036 Roo.apply(this, cfg);
27037 var qa = cfg.node.querySelectorAll;
27038 this.removeAttributes('data-block');
27039 this.removeAttributes('contenteditable');
27040 this.removeAttributes('id');
27044 Roo.apply(Roo.htmleditor.FilterBlock.prototype,
27046 node: true, // all tags
27049 removeAttributes : function(attr)
27051 var ar = this.node.querySelectorAll('*[' + attr + ']');
27052 for (var i =0;i<ar.length;i++) {
27053 ar[i].removeAttribute(attr);
27062 * This is based loosely on tinymce
27063 * @class Roo.htmleditor.TidySerializer
27064 * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js
27066 * @method Serializer
27067 * @param {Object} settings Name/value settings object.
27071 Roo.htmleditor.TidySerializer = function(settings)
27073 Roo.apply(this, settings);
27075 this.writer = new Roo.htmleditor.TidyWriter(settings);
27080 Roo.htmleditor.TidySerializer.prototype = {
27083 * @param {boolean} inner do the inner of the node.
27090 * Serializes the specified node into a string.
27093 * new tinymce.html.Serializer().serialize(new tinymce.html.DomParser().parse('<p>text</p>'));
27094 * @method serialize
27095 * @param {DomElement} node Node instance to serialize.
27096 * @return {String} String with HTML based on DOM tree.
27098 serialize : function(node) {
27100 // = settings.validate;
27101 var writer = this.writer;
27105 3: function(node) {
27107 writer.text(node.nodeValue, node);
27110 8: function(node) {
27111 writer.comment(node.nodeValue);
27113 // Processing instruction
27114 7: function(node) {
27115 writer.pi(node.name, node.nodeValue);
27118 10: function(node) {
27119 writer.doctype(node.nodeValue);
27122 4: function(node) {
27123 writer.cdata(node.nodeValue);
27125 // Document fragment
27126 11: function(node) {
27127 node = node.firstChild;
27133 node = node.nextSibling
27138 1 != node.nodeType || this.inner ? this.handlers[11](node) : this.walk(node);
27139 return writer.getContent();
27142 walk: function(node)
27144 var attrName, attrValue, sortedAttrs, i, l, elementRule,
27145 handler = this.handlers[node.nodeType];
27152 var name = node.nodeName;
27153 var isEmpty = node.childNodes.length < 1;
27155 var writer = this.writer;
27156 var attrs = node.attributes;
27159 writer.start(node.nodeName, attrs, isEmpty, node);
27163 node = node.firstChild;
27170 node = node.nextSibling;
27176 // Serialize element and treat all non elements as fragments
27181 * This is based loosely on tinymce
27182 * @class Roo.htmleditor.TidyWriter
27183 * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js
27186 * - not tested much with 'PRE' formated elements.
27192 Roo.htmleditor.TidyWriter = function(settings)
27195 // indent, indentBefore, indentAfter, encode, htmlOutput, html = [];
27196 Roo.apply(this, settings);
27200 this.encode = Roo.htmleditor.TidyEntities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
27203 Roo.htmleditor.TidyWriter.prototype = {
27210 // part of state...
27214 last_inline : false,
27219 * Writes the a start element such as <p id="a">.
27222 * @param {String} name Name of the element.
27223 * @param {Array} attrs Optional attribute array or undefined if it hasn't any.
27224 * @param {Boolean} empty Optional empty state if the tag should end like <br />.
27226 start: function(name, attrs, empty, node)
27228 var i, l, attr, value;
27230 // there are some situations where adding line break && indentation will not work. will not work.
27231 // <span / b / i ... formating?
27233 var in_inline = this.in_inline || Roo.htmleditor.TidyWriter.inline_elements.indexOf(name) > -1;
27234 var in_pre = this.in_pre || Roo.htmleditor.TidyWriter.whitespace_elements.indexOf(name) > -1;
27236 var is_short = empty ? Roo.htmleditor.TidyWriter.shortend_elements.indexOf(name) > -1 : false;
27238 var add_lb = name == 'BR' ? false : in_inline;
27240 if (!add_lb && !this.in_pre && this.lastElementEndsWS()) {
27244 var indentstr = this.indentstr;
27246 // e_inline = elements that can be inline, but still allow \n before and after?
27247 // only 'BR' ??? any others?
27249 // ADD LINE BEFORE tage
27250 if (!this.in_pre) {
27253 if (name == 'BR') {
27255 } else if (this.lastElementEndsWS()) {
27258 // otherwise - no new line. (and dont indent.)
27269 this.html.push(indentstr + '<', name.toLowerCase());
27272 for (i = 0, l = attrs.length; i < l; i++) {
27274 this.html.push(' ', attr.name, '="', this.encode(attr.value, true), '"');
27280 this.html[this.html.length] = '/>';
27282 this.html[this.html.length] = '></' + name.toLowerCase() + '>';
27284 var e_inline = name == 'BR' ? false : this.in_inline;
27286 if (!e_inline && !this.in_pre) {
27293 this.html[this.html.length] = '>';
27295 // there is a special situation, where we need to turn on in_inline - if any of the imediate chidlren are one of these.
27297 if (!in_inline && !in_pre) {
27298 var cn = node.firstChild;
27300 if (Roo.htmleditor.TidyWriter.inline_elements.indexOf(cn.nodeName) > -1) {
27304 cn = cn.nextSibling;
27312 indentstr : in_pre ? '' : (this.indentstr + this.indent),
27314 in_inline : in_inline
27316 // add a line after if we are not in a
27318 if (!in_inline && !in_pre) {
27327 lastElementEndsWS : function()
27329 var value = this.html.length > 0 ? this.html[this.html.length-1] : false;
27330 if (value === false) {
27333 return value.match(/\s+$/);
27338 * Writes the a end element such as </p>.
27341 * @param {String} name Name of the element.
27343 end: function(name) {
27346 var indentstr = '';
27347 var in_inline = this.in_inline || Roo.htmleditor.TidyWriter.inline_elements.indexOf(name) > -1;
27349 if (!this.in_pre && !in_inline) {
27351 indentstr = this.indentstr;
27353 this.html.push(indentstr + '</', name.toLowerCase(), '>');
27354 this.last_inline = in_inline;
27356 // pop the indent state..
27359 * Writes a text node.
27361 * In pre - we should not mess with the contents.
27365 * @param {String} text String to write out.
27366 * @param {Boolean} raw Optional raw state if true the contents wont get encoded.
27368 text: function(in_text, node)
27370 // if not in whitespace critical
27371 if (in_text.length < 1) {
27374 var text = new XMLSerializer().serializeToString(document.createTextNode(in_text)); // escape it properly?
27377 this.html[this.html.length] = text;
27381 if (this.in_inline) {
27382 text = text.replace(/\s+/g,' '); // all white space inc line breaks to a slingle' '
27384 text = text.replace(/\s+/,' '); // all white space to single white space
27387 // if next tag is '<BR>', then we can trim right..
27388 if (node.nextSibling &&
27389 node.nextSibling.nodeType == 1 &&
27390 node.nextSibling.nodeName == 'BR' )
27392 text = text.replace(/\s+$/g,'');
27394 // if previous tag was a BR, we can also trim..
27395 if (node.previousSibling &&
27396 node.previousSibling.nodeType == 1 &&
27397 node.previousSibling.nodeName == 'BR' )
27399 text = this.indentstr + text.replace(/^\s+/g,'');
27401 if (text.match(/\n/)) {
27402 text = text.replace(
27403 /(?![^\n]{1,64}$)([^\n]{1,64})\s/g, '$1\n' + this.indentstr
27405 // remoeve the last whitespace / line break.
27406 text = text.replace(/\n\s+$/,'');
27408 // repace long lines
27412 this.html[this.html.length] = text;
27415 // see if previous element was a inline element.
27416 var indentstr = this.indentstr;
27418 text = text.replace(/\s+/g," "); // all whitespace into single white space.
27420 // should trim left?
27421 if (node.previousSibling &&
27422 node.previousSibling.nodeType == 1 &&
27423 Roo.htmleditor.TidyWriter.inline_elements.indexOf(node.previousSibling.nodeName) > -1)
27429 text = text.replace(/^\s+/,''); // trim left
27432 // should trim right?
27433 if (node.nextSibling &&
27434 node.nextSibling.nodeType == 1 &&
27435 Roo.htmleditor.TidyWriter.inline_elements.indexOf(node.nextSibling.nodeName) > -1)
27440 text = text.replace(/\s+$/,''); // trim right
27447 if (text.length < 1) {
27450 if (!text.match(/\n/)) {
27451 this.html.push(indentstr + text);
27455 text = this.indentstr + text.replace(
27456 /(?![^\n]{1,64}$)([^\n]{1,64})\s/g, '$1\n' + this.indentstr
27458 // remoeve the last whitespace / line break.
27459 text = text.replace(/\s+$/,'');
27461 this.html.push(text);
27463 // split and indent..
27468 * Writes a cdata node such as <![CDATA[data]]>.
27471 * @param {String} text String to write out inside the cdata.
27473 cdata: function(text) {
27474 this.html.push('<![CDATA[', text, ']]>');
27477 * Writes a comment node such as <!-- Comment -->.
27480 * @param {String} text String to write out inside the comment.
27482 comment: function(text) {
27483 this.html.push('<!--', text, '-->');
27486 * Writes a PI node such as <?xml attr="value" ?>.
27489 * @param {String} name Name of the pi.
27490 * @param {String} text String to write out inside the pi.
27492 pi: function(name, text) {
27493 text ? this.html.push('<?', name, ' ', this.encode(text), '?>') : this.html.push('<?', name, '?>');
27494 this.indent != '' && this.html.push('\n');
27497 * Writes a doctype node such as <!DOCTYPE data>.
27500 * @param {String} text String to write out inside the doctype.
27502 doctype: function(text) {
27503 this.html.push('<!DOCTYPE', text, '>', this.indent != '' ? '\n' : '');
27506 * Resets the internal buffer if one wants to reuse the writer.
27510 reset: function() {
27511 this.html.length = 0;
27520 * Returns the contents that got serialized.
27522 * @method getContent
27523 * @return {String} HTML contents that got written down.
27525 getContent: function() {
27526 return this.html.join('').replace(/\n$/, '');
27529 pushState : function(cfg)
27531 this.state.push(cfg);
27532 Roo.apply(this, cfg);
27535 popState : function()
27537 if (this.state.length < 1) {
27538 return; // nothing to push
27545 if (this.state.length > 0) {
27546 cfg = this.state[this.state.length-1];
27548 Roo.apply(this, cfg);
27551 addLine: function()
27553 if (this.html.length < 1) {
27558 var value = this.html[this.html.length - 1];
27559 if (value.length > 0 && '\n' !== value) {
27560 this.html.push('\n');
27565 //'pre script noscript style textarea video audio iframe object code'
27566 // shortended... 'area base basefont br col frame hr img input isindex link meta param embed source wbr track');
27570 Roo.htmleditor.TidyWriter.inline_elements = [
27571 'SPAN','STRONG','B','EM','I','FONT','STRIKE','U','VAR',
27572 'CITE','DFN','CODE','MARK','Q','SUP','SUB','SAMP', 'A'
27574 Roo.htmleditor.TidyWriter.shortend_elements = [
27575 'AREA','BASE','BASEFONT','BR','COL','FRAME','HR','IMG','INPUT',
27576 'ISINDEX','LINK','','META','PARAM','EMBED','SOURCE','WBR','TRACK'
27579 Roo.htmleditor.TidyWriter.whitespace_elements = [
27580 'PRE','SCRIPT','NOSCRIPT','STYLE','TEXTAREA','VIDEO','AUDIO','IFRAME','OBJECT','CODE'
27582 * This is based loosely on tinymce
27583 * @class Roo.htmleditor.TidyEntities
27585 * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js
27587 * Not 100% sure this is actually used or needed.
27590 Roo.htmleditor.TidyEntities = {
27593 * initialize data..
27595 init : function (){
27597 this.namedEntities = this.buildEntitiesLookup(this.namedEntitiesData, 32);
27602 buildEntitiesLookup: function(items, radix) {
27603 var i, chr, entity, lookup = {};
27607 items = typeof(items) == 'string' ? items.split(',') : items;
27608 radix = radix || 10;
27609 // Build entities lookup table
27610 for (i = 0; i < items.length; i += 2) {
27611 chr = String.fromCharCode(parseInt(items[i], radix));
27612 // Only add non base entities
27613 if (!this.baseEntities[chr]) {
27614 entity = '&' + items[i + 1] + ';';
27615 lookup[chr] = entity;
27616 lookup[entity] = chr;
27655 // Needs to be escaped since the YUI compressor would otherwise break the code
27662 // Reverse lookup table for raw entities
27663 reverseEntities : {
27671 attrsCharsRegExp : /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
27672 textCharsRegExp : /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
27673 rawCharsRegExp : /[<>&\"\']/g,
27674 entityRegExp : /&#([a-z0-9]+);?|&([a-z0-9]+);/gi,
27675 namedEntities : false,
27676 namedEntitiesData : [
28177 * Encodes the specified string using raw entities. This means only the required XML base entities will be encoded.
28179 * @method encodeRaw
28180 * @param {String} text Text to encode.
28181 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
28182 * @return {String} Entity encoded text.
28184 encodeRaw: function(text, attr)
28187 return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
28188 return t.baseEntities[chr] || chr;
28192 * Encoded the specified text with both the attributes and text entities. This function will produce larger text contents
28193 * since it doesn't know if the context is within a attribute or text node. This was added for compatibility
28194 * and is exposed as the DOMUtils.encode function.
28196 * @method encodeAllRaw
28197 * @param {String} text Text to encode.
28198 * @return {String} Entity encoded text.
28200 encodeAllRaw: function(text) {
28202 return ('' + text).replace(this.rawCharsRegExp, function(chr) {
28203 return t.baseEntities[chr] || chr;
28207 * Encodes the specified string using numeric entities. The core entities will be
28208 * encoded as named ones but all non lower ascii characters will be encoded into numeric entities.
28210 * @method encodeNumeric
28211 * @param {String} text Text to encode.
28212 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
28213 * @return {String} Entity encoded text.
28215 encodeNumeric: function(text, attr) {
28217 return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
28218 // Multi byte sequence convert it to a single entity
28219 if (chr.length > 1) {
28220 return '&#' + (1024 * (chr.charCodeAt(0) - 55296) + (chr.charCodeAt(1) - 56320) + 65536) + ';';
28222 return t.baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
28226 * Encodes the specified string using named entities. The core entities will be encoded
28227 * as named ones but all non lower ascii characters will be encoded into named entities.
28229 * @method encodeNamed
28230 * @param {String} text Text to encode.
28231 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
28232 * @param {Object} entities Optional parameter with entities to use.
28233 * @return {String} Entity encoded text.
28235 encodeNamed: function(text, attr, entities) {
28237 entities = entities || this.namedEntities;
28238 return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
28239 return t.baseEntities[chr] || entities[chr] || chr;
28243 * Returns an encode function based on the name(s) and it's optional entities.
28245 * @method getEncodeFunc
28246 * @param {String} name Comma separated list of encoders for example named,numeric.
28247 * @param {String} entities Optional parameter with entities to use instead of the built in set.
28248 * @return {function} Encode function to be used.
28250 getEncodeFunc: function(name, entities) {
28251 entities = this.buildEntitiesLookup(entities) || this.namedEntities;
28253 function encodeNamedAndNumeric(text, attr) {
28254 return text.replace(attr ? t.attrsCharsRegExp : t.textCharsRegExp, function(chr) {
28255 return t.baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
28259 function encodeCustomNamed(text, attr) {
28260 return t.encodeNamed(text, attr, entities);
28262 // Replace + with , to be compatible with previous TinyMCE versions
28263 name = this.makeMap(name.replace(/\+/g, ','));
28264 // Named and numeric encoder
28265 if (name.named && name.numeric) {
28266 return this.encodeNamedAndNumeric;
28272 return encodeCustomNamed;
28274 return this.encodeNamed;
28277 if (name.numeric) {
28278 return this.encodeNumeric;
28281 return this.encodeRaw;
28284 * Decodes the specified string, this will replace entities with raw UTF characters.
28287 * @param {String} text Text to entity decode.
28288 * @return {String} Entity decoded string.
28290 decode: function(text)
28293 return text.replace(this.entityRegExp, function(all, numeric) {
28295 numeric = 'x' === numeric.charAt(0).toLowerCase() ? parseInt(numeric.substr(1), 16) : parseInt(numeric, 10);
28296 // Support upper UTF
28297 if (numeric > 65535) {
28299 return String.fromCharCode(55296 + (numeric >> 10), 56320 + (1023 & numeric));
28301 return t.asciiMap[numeric] || String.fromCharCode(numeric);
28303 return t.reverseEntities[all] || t.namedEntities[all] || t.nativeDecode(all);
28306 nativeDecode : function (text) {
28309 makeMap : function (items, delim, map) {
28311 items = items || [];
28312 delim = delim || ',';
28313 if (typeof items == "string") {
28314 items = items.split(delim);
28319 map[items[i]] = {};
28327 Roo.htmleditor.TidyEntities.init();
28329 * @class Roo.htmleditor.KeyEnter
28330 * Handle Enter press..
28331 * @cfg {Roo.HtmlEditorCore} core the editor.
28333 * Create a new Filter.
28334 * @param {Object} config Configuration options
28341 Roo.htmleditor.KeyEnter = function(cfg) {
28342 Roo.apply(this, cfg);
28343 // this does not actually call walk as it's really just a abstract class
28345 Roo.get(this.core.doc.body).on('keypress', this.keypress, this);
28348 //Roo.htmleditor.KeyEnter.i = 0;
28351 Roo.htmleditor.KeyEnter.prototype = {
28355 keypress : function(e)
28357 if (e.charCode != 13 && e.charCode != 10) {
28358 Roo.log([e.charCode,e]);
28361 e.preventDefault();
28362 // https://stackoverflow.com/questions/18552336/prevent-contenteditable-adding-div-on-enter-chrome
28363 var doc = this.core.doc;
28367 var sel = this.core.getSelection();
28368 var range = sel.getRangeAt(0);
28369 var n = range.commonAncestorContainer;
28370 var pc = range.closest([ 'ol', 'ul']);
28371 var pli = range.closest('li');
28372 if (!pc || e.ctrlKey) {
28373 // on it list, or ctrl pressed.
28375 sel.insertNode('br', 'after');
28377 // only do this if we have ctrl key..
28378 var br = doc.createElement('br');
28379 br.className = 'clear';
28380 br.setAttribute('style', 'clear: both');
28381 sel.insertNode(br, 'after');
28385 this.core.undoManager.addEvent();
28386 this.core.fireEditorEvent(e);
28390 // deal with <li> insetion
28391 if (pli.innerText.trim() == '' &&
28392 pli.previousSibling &&
28393 pli.previousSibling.nodeName == 'LI' &&
28394 pli.previousSibling.innerText.trim() == '') {
28395 pli.parentNode.removeChild(pli.previousSibling);
28396 sel.cursorAfter(pc);
28397 this.core.undoManager.addEvent();
28398 this.core.fireEditorEvent(e);
28402 var li = doc.createElement('LI');
28403 li.innerHTML = ' ';
28404 if (!pli || !pli.firstSibling) {
28405 pc.appendChild(li);
28407 pli.parentNode.insertBefore(li, pli.firstSibling);
28409 sel.cursorText (li.firstChild);
28411 this.core.undoManager.addEvent();
28412 this.core.fireEditorEvent(e);
28424 * @class Roo.htmleditor.Block
28425 * Base class for html editor blocks - do not use it directly .. extend it..
28426 * @cfg {DomElement} node The node to apply stuff to.
28427 * @cfg {String} friendly_name the name that appears in the context bar about this block
28428 * @cfg {Object} Context menu - see Roo.form.HtmlEditor.ToolbarContext
28431 * Create a new Filter.
28432 * @param {Object} config Configuration options
28435 Roo.htmleditor.Block = function(cfg)
28437 // do nothing .. should not be called really.
28440 * factory method to get the block from an element (using cache if necessary)
28442 * @param {HtmlElement} the dom element
28444 Roo.htmleditor.Block.factory = function(node)
28446 var cc = Roo.htmleditor.Block.cache;
28447 var id = Roo.get(node).id;
28448 if (typeof(cc[id]) != 'undefined' && (!cc[id].node || cc[id].node.closest('body'))) {
28449 Roo.htmleditor.Block.cache[id].readElement(node);
28450 return Roo.htmleditor.Block.cache[id];
28452 var db = node.getAttribute('data-block');
28454 db = node.nodeName.toLowerCase().toUpperCaseFirst();
28456 var cls = Roo.htmleditor['Block' + db];
28457 if (typeof(cls) == 'undefined') {
28458 //Roo.log(node.getAttribute('data-block'));
28459 Roo.log("OOps missing block : " + 'Block' + db);
28462 Roo.htmleditor.Block.cache[id] = new cls({ node: node });
28463 return Roo.htmleditor.Block.cache[id]; /// should trigger update element
28467 * initalize all Elements from content that are 'blockable'
28469 * @param the body element
28471 Roo.htmleditor.Block.initAll = function(body, type)
28473 if (typeof(type) == 'undefined') {
28474 var ia = Roo.htmleditor.Block.initAll;
28480 Roo.each(Roo.get(body).query(type), function(e) {
28481 Roo.htmleditor.Block.factory(e);
28484 // question goes here... do we need to clear out this cache sometimes?
28485 // or show we make it relivant to the htmleditor.
28486 Roo.htmleditor.Block.cache = {};
28488 Roo.htmleditor.Block.prototype = {
28492 // used by context menu
28493 friendly_name : 'Based Block',
28495 // text for button to delete this element
28496 deleteTitle : false,
28500 * Update a node with values from this object
28501 * @param {DomElement} node
28503 updateElement : function(node)
28505 Roo.DomHelper.update(node === undefined ? this.node : node, this.toObject());
28508 * convert to plain HTML for calling insertAtCursor..
28510 toHTML : function()
28512 return Roo.DomHelper.markup(this.toObject());
28515 * used by readEleemnt to extract data from a node
28516 * may need improving as it's pretty basic
28518 * @param {DomElement} node
28519 * @param {String} tag - tag to find, eg. IMG ?? might be better to use DomQuery ?
28520 * @param {String} attribute (use html - for contents, style for using next param as style, or false to return the node)
28521 * @param {String} style the style property - eg. text-align
28523 getVal : function(node, tag, attr, style)
28526 if (tag !== true && n.tagName != tag.toUpperCase()) {
28527 // in theory we could do figure[3] << 3rd figure? or some more complex search..?
28528 // but kiss for now.
28529 n = node.getElementsByTagName(tag).item(0);
28534 if (attr === false) {
28537 if (attr == 'html') {
28538 return n.innerHTML;
28540 if (attr == 'style') {
28541 return n.style[style];
28544 return n.hasAttribute(attr) ? n.getAttribute(attr) : '';
28548 * create a DomHelper friendly object - for use with
28549 * Roo.DomHelper.markup / overwrite / etc..
28552 toObject : function()
28557 * Read a node that has a 'data-block' property - and extract the values from it.
28558 * @param {DomElement} node - the node
28560 readElement : function(node)
28571 * @class Roo.htmleditor.BlockFigure
28572 * Block that has an image and a figcaption
28573 * @cfg {String} image_src the url for the image
28574 * @cfg {String} align (left|right) alignment for the block default left
28575 * @cfg {String} caption the text to appear below (and in the alt tag)
28576 * @cfg {String} caption_display (block|none) display or not the caption
28577 * @cfg {String|number} image_width the width of the image number or %?
28578 * @cfg {String|number} image_height the height of the image number or %?
28581 * Create a new Filter.
28582 * @param {Object} config Configuration options
28585 Roo.htmleditor.BlockFigure = function(cfg)
28588 this.readElement(cfg.node);
28589 this.updateElement(cfg.node);
28591 Roo.apply(this, cfg);
28593 Roo.extend(Roo.htmleditor.BlockFigure, Roo.htmleditor.Block, {
28600 caption_display : 'block',
28606 // margin: '2%', not used
28608 text_align: 'left', // (left|right) alignment for the text caption default left. - not used at present
28611 // used by context menu
28612 friendly_name : 'Image with caption',
28613 deleteTitle : "Delete Image and Caption",
28615 contextMenu : function(toolbar)
28618 var block = function() {
28619 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
28623 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
28625 var syncValue = toolbar.editorcore.syncValue;
28631 xtype : 'TextItem',
28633 xns : rooui.Toolbar //Boostrap?
28637 text: 'Change Image URL',
28640 click: function (btn, state)
28644 Roo.MessageBox.show({
28645 title : "Image Source URL",
28646 msg : "Enter the url for the image",
28647 buttons: Roo.MessageBox.OKCANCEL,
28648 fn: function(btn, val){
28655 toolbar.editorcore.onEditorEvent();
28659 //multiline: multiline,
28661 value : b.image_src
28665 xns : rooui.Toolbar
28670 text: 'Change Link URL',
28673 click: function (btn, state)
28677 Roo.MessageBox.show({
28678 title : "Link URL",
28679 msg : "Enter the url for the link - leave blank to have no link",
28680 buttons: Roo.MessageBox.OKCANCEL,
28681 fn: function(btn, val){
28688 toolbar.editorcore.onEditorEvent();
28692 //multiline: multiline,
28698 xns : rooui.Toolbar
28702 text: 'Show Video URL',
28705 click: function (btn, state)
28707 Roo.MessageBox.alert("Video URL",
28708 block().video_url == '' ? 'This image is not linked ot a video' :
28709 'The image is linked to: <a target="_new" href="' + block().video_url + '">' + block().video_url + '</a>');
28712 xns : rooui.Toolbar
28717 xtype : 'TextItem',
28719 xns : rooui.Toolbar //Boostrap?
28722 xtype : 'ComboBox',
28723 allowBlank : false,
28724 displayField : 'val',
28727 triggerAction : 'all',
28729 valueField : 'val',
28733 select : function (combo, r, index)
28735 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28737 b.width = r.get('val');
28740 toolbar.editorcore.onEditorEvent();
28745 xtype : 'SimpleStore',
28758 xtype : 'TextItem',
28760 xns : rooui.Toolbar //Boostrap?
28763 xtype : 'ComboBox',
28764 allowBlank : false,
28765 displayField : 'val',
28768 triggerAction : 'all',
28770 valueField : 'val',
28774 select : function (combo, r, index)
28776 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28778 b.align = r.get('val');
28781 toolbar.editorcore.onEditorEvent();
28786 xtype : 'SimpleStore',
28800 text: 'Hide Caption',
28801 name : 'caption_display',
28803 enableToggle : true,
28804 setValue : function(v) {
28805 // this trigger toggle.
28807 this.setText(v ? "Hide Caption" : "Show Caption");
28808 this.setPressed(v != 'block');
28811 toggle: function (btn, state)
28814 b.caption_display = b.caption_display == 'block' ? 'none' : 'block';
28815 this.setText(b.caption_display == 'block' ? "Hide Caption" : "Show Caption");
28818 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28819 toolbar.editorcore.onEditorEvent();
28822 xns : rooui.Toolbar
28828 * create a DomHelper friendly object - for use with
28829 * Roo.DomHelper.markup / overwrite / etc..
28831 toObject : function()
28833 var d = document.createElement('div');
28834 d.innerHTML = this.caption;
28836 var m = this.width != '100%' && this.align == 'center' ? '0 auto' : 0;
28838 var iw = this.align == 'center' ? this.width : '100%';
28841 contenteditable : 'false',
28842 src : this.image_src,
28843 alt : d.innerText.replace(/\n/g, " ").replace(/\s+/g, ' ').trim(), // removeHTML and reduce spaces..
28846 maxWidth : iw + ' !important', // this is not getting rendered?
28852 '<div class="{0}" width="420" height="315" src="{1}" frameborder="0" allowfullscreen>' +
28854 '<img class="{0}-thumbnail" src="{3}/Images/{4}/{5}#image-{4}" />' +
28859 if (this.href.length > 0) {
28863 contenteditable : 'true',
28871 if (this.video_url.length > 0) {
28876 allowfullscreen : true,
28877 width : 420, // these are for video tricks - that we replace the outer
28879 src : this.video_url,
28885 // we remove caption totally if its hidden... - will delete data.. but otherwise we end up with fake caption
28886 var captionhtml = this.caption_display == 'none' ? '' : (this.caption.length ? this.caption : "Caption");
28891 'data-block' : 'Figure',
28892 'data-width' : this.width,
28893 contenteditable : 'false',
28897 float : this.align ,
28898 maxWidth : this.align == 'center' ? '100% !important' : (this.width + ' !important'),
28899 width : this.align == 'center' ? '100%' : this.width,
28901 padding: this.align == 'center' ? '0' : '0 10px' ,
28902 textAlign : this.align // seems to work for email..
28907 align : this.align,
28913 'data-display' : this.caption_display,
28915 textAlign : 'left',
28917 lineHeight : '24px',
28918 display : this.caption_display,
28919 maxWidth : (this.align == 'center' ? this.width : '100%' ) + ' !important',
28921 width: this.align == 'center' ? this.width : '100%'
28925 cls : this.cls.length > 0 ? (this.cls + '-thumbnail' ) : '',
28930 marginTop : '16px',
28936 // we can not rely on yahoo syndication to use CSS elements - so have to use '<i>' to encase stuff.
28938 contenteditable : true,
28954 readElement : function(node)
28956 // this should not really come from the link...
28957 this.video_url = this.getVal(node, 'div', 'src');
28958 this.cls = this.getVal(node, 'div', 'class');
28959 this.href = this.getVal(node, 'a', 'href');
28962 this.image_src = this.getVal(node, 'img', 'src');
28964 this.align = this.getVal(node, 'figure', 'align');
28965 var figcaption = this.getVal(node, 'figcaption', false);
28966 if (figcaption !== '') {
28967 this.caption = this.getVal(figcaption, 'i', 'html');
28971 this.caption_display = this.getVal(node, 'figcaption', 'data-display');
28972 //this.text_align = this.getVal(node, 'figcaption', 'style','text-align');
28973 this.width = this.getVal(node, true, 'data-width');
28974 //this.margin = this.getVal(node, 'figure', 'style', 'margin');
28977 removeNode : function()
28994 * @class Roo.htmleditor.BlockTable
28995 * Block that manages a table
28998 * Create a new Filter.
28999 * @param {Object} config Configuration options
29002 Roo.htmleditor.BlockTable = function(cfg)
29005 this.readElement(cfg.node);
29006 this.updateElement(cfg.node);
29008 Roo.apply(this, cfg);
29011 for(var r = 0; r < this.no_row; r++) {
29013 for(var c = 0; c < this.no_col; c++) {
29014 this.rows[r][c] = this.emptyCell();
29021 Roo.extend(Roo.htmleditor.BlockTable, Roo.htmleditor.Block, {
29030 // used by context menu
29031 friendly_name : 'Table',
29032 deleteTitle : 'Delete Table',
29033 // context menu is drawn once..
29035 contextMenu : function(toolbar)
29038 var block = function() {
29039 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
29043 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
29045 var syncValue = toolbar.editorcore.syncValue;
29051 xtype : 'TextItem',
29053 xns : rooui.Toolbar //Boostrap?
29056 xtype : 'ComboBox',
29057 allowBlank : false,
29058 displayField : 'val',
29061 triggerAction : 'all',
29063 valueField : 'val',
29067 select : function (combo, r, index)
29069 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29071 b.width = r.get('val');
29074 toolbar.editorcore.onEditorEvent();
29079 xtype : 'SimpleStore',
29091 xtype : 'TextItem',
29092 text : "Columns: ",
29093 xns : rooui.Toolbar //Boostrap?
29100 click : function (_self, e)
29102 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29103 block().removeColumn();
29105 toolbar.editorcore.onEditorEvent();
29108 xns : rooui.Toolbar
29114 click : function (_self, e)
29116 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29117 block().addColumn();
29119 toolbar.editorcore.onEditorEvent();
29122 xns : rooui.Toolbar
29126 xtype : 'TextItem',
29128 xns : rooui.Toolbar //Boostrap?
29135 click : function (_self, e)
29137 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29138 block().removeRow();
29140 toolbar.editorcore.onEditorEvent();
29143 xns : rooui.Toolbar
29149 click : function (_self, e)
29153 toolbar.editorcore.onEditorEvent();
29156 xns : rooui.Toolbar
29161 text: 'Reset Column Widths',
29164 click : function (_self, e)
29166 block().resetWidths();
29168 toolbar.editorcore.onEditorEvent();
29171 xns : rooui.Toolbar
29182 * create a DomHelper friendly object - for use with
29183 * Roo.DomHelper.markup / overwrite / etc..
29184 * ?? should it be called with option to hide all editing features?
29186 toObject : function()
29191 contenteditable : 'false', // this stops cell selection from picking the table.
29192 'data-block' : 'Table',
29195 border : 'solid 1px #000', // ??? hard coded?
29196 'border-collapse' : 'collapse'
29199 { tag : 'tbody' , cn : [] }
29203 // do we have a head = not really
29205 Roo.each(this.rows, function( row ) {
29210 border : 'solid 1px #000',
29216 ret.cn[0].cn.push(tr);
29217 // does the row have any properties? ?? height?
29219 Roo.each(row, function( cell ) {
29223 contenteditable : 'true',
29224 'data-block' : 'Td',
29228 if (cell.colspan > 1) {
29229 td.colspan = cell.colspan ;
29230 nc += cell.colspan;
29234 if (cell.rowspan > 1) {
29235 td.rowspan = cell.rowspan ;
29244 ncols = Math.max(nc, ncols);
29248 // add the header row..
29257 readElement : function(node)
29259 node = node ? node : this.node ;
29260 this.width = this.getVal(node, true, 'style', 'width') || '100%';
29264 var trs = Array.from(node.rows);
29265 trs.forEach(function(tr) {
29267 this.rows.push(row);
29271 Array.from(tr.cells).forEach(function(td) {
29274 colspan : td.hasAttribute('colspan') ? td.getAttribute('colspan')*1 : 1,
29275 rowspan : td.hasAttribute('rowspan') ? td.getAttribute('rowspan')*1 : 1,
29276 style : td.hasAttribute('style') ? td.getAttribute('style') : '',
29277 html : td.innerHTML
29279 no_column += add.colspan;
29286 this.no_col = Math.max(this.no_col, no_column);
29293 normalizeRows: function()
29297 this.rows.forEach(function(row) {
29300 row = this.normalizeRow(row);
29302 row.forEach(function(c) {
29303 while (typeof(ret[rid][cid]) != 'undefined') {
29306 if (typeof(ret[rid]) == 'undefined') {
29312 if (c.rowspan < 2) {
29316 for(var i = 1 ;i < c.rowspan; i++) {
29317 if (typeof(ret[rid+i]) == 'undefined') {
29320 ret[rid+i][cid] = c;
29328 normalizeRow: function(row)
29331 row.forEach(function(c) {
29332 if (c.colspan < 2) {
29336 for(var i =0 ;i < c.colspan; i++) {
29344 deleteColumn : function(sel)
29346 if (!sel || sel.type != 'col') {
29349 if (this.no_col < 2) {
29353 this.rows.forEach(function(row) {
29354 var cols = this.normalizeRow(row);
29355 var col = cols[sel.col];
29356 if (col.colspan > 1) {
29366 removeColumn : function()
29368 this.deleteColumn({
29370 col : this.no_col-1
29372 this.updateElement();
29376 addColumn : function()
29379 this.rows.forEach(function(row) {
29380 row.push(this.emptyCell());
29383 this.updateElement();
29386 deleteRow : function(sel)
29388 if (!sel || sel.type != 'row') {
29392 if (this.no_row < 2) {
29396 var rows = this.normalizeRows();
29399 rows[sel.row].forEach(function(col) {
29400 if (col.rowspan > 1) {
29403 col.remove = 1; // flage it as removed.
29408 this.rows.forEach(function(row) {
29410 row.forEach(function(c) {
29411 if (typeof(c.remove) == 'undefined') {
29416 if (newrow.length > 0) {
29420 this.rows = newrows;
29425 this.updateElement();
29428 removeRow : function()
29432 row : this.no_row-1
29438 addRow : function()
29442 for (var i = 0; i < this.no_col; i++ ) {
29444 row.push(this.emptyCell());
29447 this.rows.push(row);
29448 this.updateElement();
29452 // the default cell object... at present...
29453 emptyCell : function() {
29454 return (new Roo.htmleditor.BlockTd({})).toObject();
29459 removeNode : function()
29466 resetWidths : function()
29468 Array.from(this.node.getElementsByTagName('td')).forEach(function(n) {
29469 var nn = Roo.htmleditor.Block.factory(n);
29471 nn.updateElement(n);
29484 * since selections really work on the table cell, then editing really should work from there
29486 * The original plan was to support merging etc... - but that may not be needed yet..
29488 * So this simple version will support:
29490 * adjust the width +/-
29491 * reset the width...
29500 * @class Roo.htmleditor.BlockTable
29501 * Block that manages a table
29504 * Create a new Filter.
29505 * @param {Object} config Configuration options
29508 Roo.htmleditor.BlockTd = function(cfg)
29511 this.readElement(cfg.node);
29512 this.updateElement(cfg.node);
29514 Roo.apply(this, cfg);
29519 Roo.extend(Roo.htmleditor.BlockTd, Roo.htmleditor.Block, {
29524 textAlign : 'left',
29531 // used by context menu
29532 friendly_name : 'Table Cell',
29533 deleteTitle : false, // use our customer delete
29535 // context menu is drawn once..
29537 contextMenu : function(toolbar)
29540 var cell = function() {
29541 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
29544 var table = function() {
29545 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode.closest('table'));
29549 var saveSel = function()
29551 lr = toolbar.editorcore.getSelection().getRangeAt(0);
29553 var restoreSel = function()
29557 toolbar.editorcore.focus();
29558 var cr = toolbar.editorcore.getSelection();
29559 cr.removeAllRanges();
29561 toolbar.editorcore.onEditorEvent();
29562 }).defer(10, this);
29568 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
29570 var syncValue = toolbar.editorcore.syncValue;
29577 text : 'Edit Table',
29579 click : function() {
29580 var t = toolbar.tb.selectedNode.closest('table');
29581 toolbar.editorcore.selectNode(t);
29582 toolbar.editorcore.onEditorEvent();
29591 xtype : 'TextItem',
29592 text : "Column Width: ",
29593 xns : rooui.Toolbar
29600 click : function (_self, e)
29602 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29603 cell().shrinkColumn();
29605 toolbar.editorcore.onEditorEvent();
29608 xns : rooui.Toolbar
29614 click : function (_self, e)
29616 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29617 cell().growColumn();
29619 toolbar.editorcore.onEditorEvent();
29622 xns : rooui.Toolbar
29626 xtype : 'TextItem',
29627 text : "Vertical Align: ",
29628 xns : rooui.Toolbar //Boostrap?
29631 xtype : 'ComboBox',
29632 allowBlank : false,
29633 displayField : 'val',
29636 triggerAction : 'all',
29638 valueField : 'val',
29642 select : function (combo, r, index)
29644 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29646 b.valign = r.get('val');
29649 toolbar.editorcore.onEditorEvent();
29654 xtype : 'SimpleStore',
29658 ['bottom'] // there are afew more...
29666 xtype : 'TextItem',
29667 text : "Merge Cells: ",
29668 xns : rooui.Toolbar
29677 click : function (_self, e)
29679 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29680 cell().mergeRight();
29681 //block().growColumn();
29683 toolbar.editorcore.onEditorEvent();
29686 xns : rooui.Toolbar
29693 click : function (_self, e)
29695 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29696 cell().mergeBelow();
29697 //block().growColumn();
29699 toolbar.editorcore.onEditorEvent();
29702 xns : rooui.Toolbar
29705 xtype : 'TextItem',
29707 xns : rooui.Toolbar
29715 click : function (_self, e)
29717 //toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29720 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29721 toolbar.editorcore.onEditorEvent();
29725 xns : rooui.Toolbar
29729 xns : rooui.Toolbar
29738 xns : rooui.Toolbar,
29747 click : function (_self, e)
29751 cell().deleteColumn();
29753 toolbar.editorcore.selectNode(t.node);
29754 toolbar.editorcore.onEditorEvent();
29763 click : function (_self, e)
29766 cell().deleteRow();
29769 toolbar.editorcore.selectNode(t.node);
29770 toolbar.editorcore.onEditorEvent();
29777 xtype : 'Separator',
29784 click : function (_self, e)
29787 var nn = t.node.nextSibling || t.node.previousSibling;
29788 t.node.parentNode.removeChild(t.node);
29790 toolbar.editorcore.selectNode(nn, true);
29792 toolbar.editorcore.onEditorEvent();
29802 // align... << fixme
29810 * create a DomHelper friendly object - for use with
29811 * Roo.DomHelper.markup / overwrite / etc..
29812 * ?? should it be called with option to hide all editing features?
29815 * create a DomHelper friendly object - for use with
29816 * Roo.DomHelper.markup / overwrite / etc..
29817 * ?? should it be called with option to hide all editing features?
29819 toObject : function()
29823 contenteditable : 'true', // this stops cell selection from picking the table.
29824 'data-block' : 'Td',
29825 valign : this.valign,
29827 'text-align' : this.textAlign,
29828 border : 'solid 1px rgb(0, 0, 0)', // ??? hard coded?
29829 'border-collapse' : 'collapse',
29830 padding : '6px', // 8 for desktop / 4 for mobile
29831 'vertical-align': this.valign
29835 if (this.width != '') {
29836 ret.width = this.width;
29837 ret.style.width = this.width;
29841 if (this.colspan > 1) {
29842 ret.colspan = this.colspan ;
29844 if (this.rowspan > 1) {
29845 ret.rowspan = this.rowspan ;
29854 readElement : function(node)
29856 node = node ? node : this.node ;
29857 this.width = node.style.width;
29858 this.colspan = Math.max(1,1*node.getAttribute('colspan'));
29859 this.rowspan = Math.max(1,1*node.getAttribute('rowspan'));
29860 this.html = node.innerHTML;
29861 if (node.style.textAlign != '') {
29862 this.textAlign = node.style.textAlign;
29868 // the default cell object... at present...
29869 emptyCell : function() {
29873 textAlign : 'left',
29874 html : " " // is this going to be editable now?
29879 removeNode : function()
29881 return this.node.closest('table');
29889 toTableArray : function()
29892 var tab = this.node.closest('tr').closest('table');
29893 Array.from(tab.rows).forEach(function(r, ri){
29897 this.colWidths = [];
29898 var all_auto = true;
29899 Array.from(tab.rows).forEach(function(r, ri){
29902 Array.from(r.cells).forEach(function(ce, ci){
29907 colspan : ce.colSpan,
29908 rowspan : ce.rowSpan
29910 if (ce.isEqualNode(this.node)) {
29913 // if we have been filled up by a row?
29914 if (typeof(ret[rn][cn]) != 'undefined') {
29915 while(typeof(ret[rn][cn]) != 'undefined') {
29921 if (typeof(this.colWidths[cn]) == 'undefined' && c.colspan < 2) {
29922 this.colWidths[cn] = ce.style.width;
29923 if (this.colWidths[cn] != '') {
29929 if (c.colspan < 2 && c.rowspan < 2 ) {
29934 for(var j = 0; j < c.rowspan; j++) {
29935 if (typeof(ret[rn+j]) == 'undefined') {
29936 continue; // we have a problem..
29939 for(var i = 0; i < c.colspan; i++) {
29940 ret[rn+j][cn+i] = c;
29949 // initalize widths.?
29950 // either all widths or no widths..
29952 this.colWidths[0] = false; // no widths flag.
29963 mergeRight: function()
29966 // get the contents of the next cell along..
29967 var tr = this.node.closest('tr');
29968 var i = Array.prototype.indexOf.call(tr.childNodes, this.node);
29969 if (i >= tr.childNodes.length - 1) {
29970 return; // no cells on right to merge with.
29972 var table = this.toTableArray();
29974 if (typeof(table[this.cellData.row][this.cellData.col+this.cellData.colspan]) == 'undefined') {
29975 return; // nothing right?
29977 var rc = table[this.cellData.row][this.cellData.col+this.cellData.colspan];
29978 // right cell - must be same rowspan and on the same row.
29979 if (rc.rowspan != this.cellData.rowspan || rc.row != this.cellData.row) {
29980 return; // right hand side is not same rowspan.
29985 this.node.innerHTML += ' ' + rc.cell.innerHTML;
29986 tr.removeChild(rc.cell);
29987 this.colspan += rc.colspan;
29988 this.node.setAttribute('colspan', this.colspan);
29990 var table = this.toTableArray();
29991 this.normalizeWidths(table);
29992 this.updateWidths(table);
29996 mergeBelow : function()
29998 var table = this.toTableArray();
29999 if (typeof(table[this.cellData.row+this.cellData.rowspan]) == 'undefined') {
30000 return; // no row below
30002 if (typeof(table[this.cellData.row+this.cellData.rowspan][this.cellData.col]) == 'undefined') {
30003 return; // nothing right?
30005 var rc = table[this.cellData.row+this.cellData.rowspan][this.cellData.col];
30007 if (rc.colspan != this.cellData.colspan || rc.col != this.cellData.col) {
30008 return; // right hand side is not same rowspan.
30010 this.node.innerHTML = this.node.innerHTML + rc.cell.innerHTML ;
30011 rc.cell.parentNode.removeChild(rc.cell);
30012 this.rowspan += rc.rowspan;
30013 this.node.setAttribute('rowspan', this.rowspan);
30018 if (this.node.rowSpan < 2 && this.node.colSpan < 2) {
30021 var table = this.toTableArray();
30022 var cd = this.cellData;
30026 for(var r = cd.row; r < cd.row + cd.rowspan; r++) {
30029 for(var c = cd.col; c < cd.col + cd.colspan; c++) {
30030 if (r == cd.row && c == cd.col) {
30031 this.node.removeAttribute('rowspan');
30032 this.node.removeAttribute('colspan');
30035 var ntd = this.node.cloneNode(); // which col/row should be 0..
30036 ntd.removeAttribute('id');
30037 ntd.style.width = this.colWidths[c];
30038 ntd.innerHTML = '';
30039 table[r][c] = { cell : ntd, col : c, row: r , colspan : 1 , rowspan : 1 };
30043 this.redrawAllCells(table);
30049 redrawAllCells: function(table)
30053 var tab = this.node.closest('tr').closest('table');
30054 var ctr = tab.rows[0].parentNode;
30055 Array.from(tab.rows).forEach(function(r, ri){
30057 Array.from(r.cells).forEach(function(ce, ci){
30058 ce.parentNode.removeChild(ce);
30060 r.parentNode.removeChild(r);
30062 for(var r = 0 ; r < table.length; r++) {
30063 var re = tab.rows[r];
30065 var re = tab.ownerDocument.createElement('tr');
30066 ctr.appendChild(re);
30067 for(var c = 0 ; c < table[r].length; c++) {
30068 if (table[r][c].cell === false) {
30072 re.appendChild(table[r][c].cell);
30074 table[r][c].cell = false;
30079 updateWidths : function(table)
30081 for(var r = 0 ; r < table.length; r++) {
30083 for(var c = 0 ; c < table[r].length; c++) {
30084 if (table[r][c].cell === false) {
30088 if (this.colWidths[0] != false && table[r][c].colspan < 2) {
30089 var el = Roo.htmleditor.Block.factory(table[r][c].cell);
30090 el.width = Math.floor(this.colWidths[c]) +'%';
30091 el.updateElement(el.node);
30093 if (this.colWidths[0] != false && table[r][c].colspan > 1) {
30094 var el = Roo.htmleditor.Block.factory(table[r][c].cell);
30096 for(var i = 0; i < table[r][c].colspan; i ++) {
30097 width += Math.floor(this.colWidths[c + i]);
30099 el.width = width +'%';
30100 el.updateElement(el.node);
30102 table[r][c].cell = false; // done
30106 normalizeWidths : function(table)
30108 if (this.colWidths[0] === false) {
30109 var nw = 100.0 / this.colWidths.length;
30110 this.colWidths.forEach(function(w,i) {
30111 this.colWidths[i] = nw;
30116 var t = 0, missing = [];
30118 this.colWidths.forEach(function(w,i) {
30120 this.colWidths[i] = this.colWidths[i] == '' ? 0 : (this.colWidths[i]+'').replace(/[^0-9]+/g,'')*1;
30121 var add = this.colWidths[i];
30130 var nc = this.colWidths.length;
30131 if (missing.length) {
30132 var mult = (nc - missing.length) / (1.0 * nc);
30134 var ew = (100 -t) / (1.0 * missing.length);
30135 this.colWidths.forEach(function(w,i) {
30137 this.colWidths[i] = w * mult;
30141 this.colWidths[i] = ew;
30143 // have to make up numbers..
30146 // now we should have all the widths..
30151 shrinkColumn : function()
30153 var table = this.toTableArray();
30154 this.normalizeWidths(table);
30155 var col = this.cellData.col;
30156 var nw = this.colWidths[col] * 0.8;
30160 var otherAdd = (this.colWidths[col] * 0.2) / (this.colWidths.length -1);
30161 this.colWidths.forEach(function(w,i) {
30163 this.colWidths[i] = nw;
30166 this.colWidths[i] += otherAdd
30168 this.updateWidths(table);
30171 growColumn : function()
30173 var table = this.toTableArray();
30174 this.normalizeWidths(table);
30175 var col = this.cellData.col;
30176 var nw = this.colWidths[col] * 1.2;
30180 var otherSub = (this.colWidths[col] * 0.2) / (this.colWidths.length -1);
30181 this.colWidths.forEach(function(w,i) {
30183 this.colWidths[i] = nw;
30186 this.colWidths[i] -= otherSub
30188 this.updateWidths(table);
30191 deleteRow : function()
30193 // delete this rows 'tr'
30194 // if any of the cells in this row have a rowspan > 1 && row!= this row..
30195 // then reduce the rowspan.
30196 var table = this.toTableArray();
30197 // this.cellData.row;
30198 for (var i =0;i< table[this.cellData.row].length ; i++) {
30199 var c = table[this.cellData.row][i];
30200 if (c.row != this.cellData.row) {
30203 c.cell.setAttribute('rowspan', c.rowspan);
30206 if (c.rowspan > 1) {
30208 c.cell.setAttribute('rowspan', c.rowspan);
30211 table.splice(this.cellData.row,1);
30212 this.redrawAllCells(table);
30215 deleteColumn : function()
30217 var table = this.toTableArray();
30219 for (var i =0;i< table.length ; i++) {
30220 var c = table[i][this.cellData.col];
30221 if (c.col != this.cellData.col) {
30222 table[i][this.cellData.col].colspan--;
30223 } else if (c.colspan > 1) {
30225 c.cell.setAttribute('colspan', c.colspan);
30227 table[i].splice(this.cellData.col,1);
30230 this.redrawAllCells(table);
30238 //<script type="text/javascript">
30241 * Based Ext JS Library 1.1.1
30242 * Copyright(c) 2006-2007, Ext JS, LLC.
30248 * @class Roo.HtmlEditorCore
30249 * @extends Roo.Component
30250 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
30252 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
30255 Roo.HtmlEditorCore = function(config){
30258 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
30263 * @event initialize
30264 * Fires when the editor is fully initialized (including the iframe)
30265 * @param {Roo.HtmlEditorCore} this
30270 * Fires when the editor is first receives the focus. Any insertion must wait
30271 * until after this event.
30272 * @param {Roo.HtmlEditorCore} this
30276 * @event beforesync
30277 * Fires before the textarea is updated with content from the editor iframe. Return false
30278 * to cancel the sync.
30279 * @param {Roo.HtmlEditorCore} this
30280 * @param {String} html
30284 * @event beforepush
30285 * Fires before the iframe editor is updated with content from the textarea. Return false
30286 * to cancel the push.
30287 * @param {Roo.HtmlEditorCore} this
30288 * @param {String} html
30293 * Fires when the textarea is updated with content from the editor iframe.
30294 * @param {Roo.HtmlEditorCore} this
30295 * @param {String} html
30300 * Fires when the iframe editor is updated with content from the textarea.
30301 * @param {Roo.HtmlEditorCore} this
30302 * @param {String} html
30307 * @event editorevent
30308 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
30309 * @param {Roo.HtmlEditorCore} this
30316 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
30318 // defaults : white / black...
30319 this.applyBlacklists();
30326 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
30330 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
30336 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
30341 * @cfg {Number} height (in pixels)
30345 * @cfg {Number} width (in pixels)
30349 * @cfg {boolean} autoClean - default true - loading and saving will remove quite a bit of formating,
30350 * if you are doing an email editor, this probably needs disabling, it's designed
30355 * @cfg {boolean} enableBlocks - default true - if the block editor (table and figure should be enabled)
30357 enableBlocks : true,
30359 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
30362 stylesheets: false,
30364 * @cfg {String} language default en - language of text (usefull for rtl languages)
30370 * @cfg {boolean} allowComments - default false - allow comments in HTML source
30371 * - by default they are stripped - if you are editing email you may need this.
30373 allowComments: false,
30377 // private properties
30378 validationEvent : false,
30380 initialized : false,
30382 sourceEditMode : false,
30383 onFocus : Roo.emptyFn,
30385 hideMode:'offsets',
30389 // blacklist + whitelisted elements..
30396 undoManager : false,
30398 * Protected method that will not generally be called directly. It
30399 * is called when the editor initializes the iframe with HTML contents. Override this method if you
30400 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
30402 getDocMarkup : function(){
30406 // inherit styels from page...??
30407 if (this.stylesheets === false) {
30409 Roo.get(document.head).select('style').each(function(node) {
30410 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
30413 Roo.get(document.head).select('link').each(function(node) {
30414 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
30417 } else if (!this.stylesheets.length) {
30419 st = '<style type="text/css">' +
30420 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
30423 for (var i in this.stylesheets) {
30424 if (typeof(this.stylesheets[i]) != 'string') {
30427 st += '<link rel="stylesheet" href="' + this.stylesheets[i] +'" type="text/css">';
30432 st += '<style type="text/css">' +
30433 'IMG { cursor: pointer } ' +
30436 st += '<meta name="google" content="notranslate">';
30438 var cls = 'notranslate roo-htmleditor-body';
30440 if(this.bodyCls.length){
30441 cls += ' ' + this.bodyCls;
30444 return '<html class="notranslate" translate="no"><head>' + st +
30445 //<style type="text/css">' +
30446 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
30448 ' </head><body contenteditable="true" data-enable-grammerly="true" class="' + cls + '"></body></html>';
30452 onRender : function(ct, position)
30455 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
30456 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
30459 this.el.dom.style.border = '0 none';
30460 this.el.dom.setAttribute('tabIndex', -1);
30461 this.el.addClass('x-hidden hide');
30465 if(Roo.isIE){ // fix IE 1px bogus margin
30466 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
30470 this.frameId = Roo.id();
30474 var iframe = this.owner.wrap.createChild({
30476 cls: 'form-control', // bootstrap..
30478 name: this.frameId,
30479 frameBorder : 'no',
30480 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
30485 this.iframe = iframe.dom;
30487 this.assignDocWin();
30489 this.doc.designMode = 'on';
30492 this.doc.write(this.getDocMarkup());
30496 var task = { // must defer to wait for browser to be ready
30498 //console.log("run task?" + this.doc.readyState);
30499 this.assignDocWin();
30500 if(this.doc.body || this.doc.readyState == 'complete'){
30502 this.doc.designMode="on";
30507 Roo.TaskMgr.stop(task);
30508 this.initEditor.defer(10, this);
30515 Roo.TaskMgr.start(task);
30520 onResize : function(w, h)
30522 Roo.log('resize: ' +w + ',' + h );
30523 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
30527 if(typeof w == 'number'){
30529 this.iframe.style.width = w + 'px';
30531 if(typeof h == 'number'){
30533 this.iframe.style.height = h + 'px';
30535 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
30542 * Toggles the editor between standard and source edit mode.
30543 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
30545 toggleSourceEdit : function(sourceEditMode){
30547 this.sourceEditMode = sourceEditMode === true;
30549 if(this.sourceEditMode){
30551 Roo.get(this.iframe).addClass(['x-hidden','hide', 'd-none']); //FIXME - what's the BS styles for these
30554 Roo.get(this.iframe).removeClass(['x-hidden','hide', 'd-none']);
30555 //this.iframe.className = '';
30558 //this.setSize(this.owner.wrap.getSize());
30559 //this.fireEvent('editmodechange', this, this.sourceEditMode);
30566 * Protected method that will not generally be called directly. If you need/want
30567 * custom HTML cleanup, this is the method you should override.
30568 * @param {String} html The HTML to be cleaned
30569 * return {String} The cleaned HTML
30571 cleanHtml : function(html)
30573 html = String(html);
30574 if(html.length > 5){
30575 if(Roo.isSafari){ // strip safari nonsense
30576 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
30579 if(html == ' '){
30586 * HTML Editor -> Textarea
30587 * Protected method that will not generally be called directly. Syncs the contents
30588 * of the editor iframe with the textarea.
30590 syncValue : function()
30592 //Roo.log("HtmlEditorCore:syncValue (EDITOR->TEXT)");
30593 if(this.initialized){
30595 if (this.undoManager) {
30596 this.undoManager.addEvent();
30600 var bd = (this.doc.body || this.doc.documentElement);
30603 var sel = this.win.getSelection();
30605 var div = document.createElement('div');
30606 div.innerHTML = bd.innerHTML;
30607 var gtx = div.getElementsByClassName('gtx-trans-icon'); // google translate - really annoying and difficult to get rid of.
30608 if (gtx.length > 0) {
30609 var rm = gtx.item(0).parentNode;
30610 rm.parentNode.removeChild(rm);
30614 if (this.enableBlocks) {
30615 new Roo.htmleditor.FilterBlock({ node : div });
30618 var html = div.innerHTML;
30621 if (this.autoClean) {
30623 new Roo.htmleditor.FilterAttributes({
30644 attrib_clean : ['href', 'src' ]
30647 var tidy = new Roo.htmleditor.TidySerializer({
30650 html = tidy.serialize(div);
30656 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
30657 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
30659 html = '<div style="'+m[0]+'">' + html + '</div>';
30662 html = this.cleanHtml(html);
30663 // fix up the special chars.. normaly like back quotes in word...
30664 // however we do not want to do this with chinese..
30665 html = html.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g, function(match) {
30667 var cc = match.charCodeAt();
30669 // Get the character value, handling surrogate pairs
30670 if (match.length == 2) {
30671 // It's a surrogate pair, calculate the Unicode code point
30672 var high = match.charCodeAt(0) - 0xD800;
30673 var low = match.charCodeAt(1) - 0xDC00;
30674 cc = (high * 0x400) + low + 0x10000;
30676 (cc >= 0x4E00 && cc < 0xA000 ) ||
30677 (cc >= 0x3400 && cc < 0x4E00 ) ||
30678 (cc >= 0xf900 && cc < 0xfb00 )
30683 // No, use a numeric entity. Here we brazenly (and possibly mistakenly)
30684 return "&#" + cc + ";";
30691 if(this.owner.fireEvent('beforesync', this, html) !== false){
30692 this.el.dom.value = html;
30693 this.owner.fireEvent('sync', this, html);
30699 * TEXTAREA -> EDITABLE
30700 * Protected method that will not generally be called directly. Pushes the value of the textarea
30701 * into the iframe editor.
30703 pushValue : function()
30705 //Roo.log("HtmlEditorCore:pushValue (TEXT->EDITOR)");
30706 if(this.initialized){
30707 var v = this.el.dom.value.trim();
30710 if(this.owner.fireEvent('beforepush', this, v) !== false){
30711 var d = (this.doc.body || this.doc.documentElement);
30714 this.el.dom.value = d.innerHTML;
30715 this.owner.fireEvent('push', this, v);
30717 if (this.autoClean) {
30718 new Roo.htmleditor.FilterParagraph({node : this.doc.body}); // paragraphs
30719 new Roo.htmleditor.FilterSpan({node : this.doc.body}); // empty spans
30721 if (this.enableBlocks) {
30722 Roo.htmleditor.Block.initAll(this.doc.body);
30725 this.updateLanguage();
30727 var lc = this.doc.body.lastChild;
30728 if (lc && lc.nodeType == 1 && lc.getAttribute("contenteditable") == "false") {
30729 // add an extra line at the end.
30730 this.doc.body.appendChild(this.doc.createElement('br'));
30738 deferFocus : function(){
30739 this.focus.defer(10, this);
30743 focus : function(){
30744 if(this.win && !this.sourceEditMode){
30751 assignDocWin: function()
30753 var iframe = this.iframe;
30756 this.doc = iframe.contentWindow.document;
30757 this.win = iframe.contentWindow;
30759 // if (!Roo.get(this.frameId)) {
30762 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
30763 // this.win = Roo.get(this.frameId).dom.contentWindow;
30765 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
30769 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
30770 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
30775 initEditor : function(){
30776 //console.log("INIT EDITOR");
30777 this.assignDocWin();
30781 this.doc.designMode="on";
30783 this.doc.write(this.getDocMarkup());
30786 var dbody = (this.doc.body || this.doc.documentElement);
30787 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
30788 // this copies styles from the containing element into thsi one..
30789 // not sure why we need all of this..
30790 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
30792 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
30793 //ss['background-attachment'] = 'fixed'; // w3c
30794 dbody.bgProperties = 'fixed'; // ie
30795 dbody.setAttribute("translate", "no");
30797 //Roo.DomHelper.applyStyles(dbody, ss);
30798 Roo.EventManager.on(this.doc, {
30800 'mouseup': this.onEditorEvent,
30801 'dblclick': this.onEditorEvent,
30802 'click': this.onEditorEvent,
30803 'keyup': this.onEditorEvent,
30808 Roo.EventManager.on(this.doc, {
30809 'paste': this.onPasteEvent,
30813 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
30816 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
30817 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
30819 this.initialized = true;
30822 // initialize special key events - enter
30823 new Roo.htmleditor.KeyEnter({core : this});
30827 this.owner.fireEvent('initialize', this);
30830 // this is to prevent a href clicks resulting in a redirect?
30832 onPasteEvent : function(e,v)
30834 // I think we better assume paste is going to be a dirty load of rubish from word..
30836 // even pasting into a 'email version' of this widget will have to clean up that mess.
30837 var cd = (e.browserEvent.clipboardData || window.clipboardData);
30839 // check what type of paste - if it's an image, then handle it differently.
30840 if (cd.files && cd.files.length > 0) {
30842 var urlAPI = (window.createObjectURL && window) ||
30843 (window.URL && URL.revokeObjectURL && URL) ||
30844 (window.webkitURL && webkitURL);
30846 var url = urlAPI.createObjectURL( cd.files[0]);
30847 this.insertAtCursor('<img src=" + url + ">');
30850 if (cd.types.indexOf('text/html') < 0 ) {
30854 var html = cd.getData('text/html'); // clipboard event
30855 if (cd.types.indexOf('text/rtf') > -1) {
30856 var parser = new Roo.rtf.Parser(cd.getData('text/rtf'));
30857 images = parser.doc ? parser.doc.getElementsByType('pict') : [];
30862 images = images.filter(function(g) { return !g.path.match(/^rtf\/(head|pgdsctbl|listtable|footerf)/); }) // ignore headers/footers etc.
30863 .map(function(g) { return g.toDataURL(); })
30864 .filter(function(g) { return g != 'about:blank'; });
30867 html = this.cleanWordChars(html);
30869 var d = (new DOMParser().parseFromString(html, 'text/html')).body;
30872 var sn = this.getParentElement();
30873 // check if d contains a table, and prevent nesting??
30874 //Roo.log(d.getElementsByTagName('table'));
30876 //Roo.log(sn.closest('table'));
30877 if (d.getElementsByTagName('table').length && sn && sn.closest('table')) {
30878 e.preventDefault();
30879 this.insertAtCursor("You can not nest tables");
30880 //Roo.log("prevent?"); // fixme -
30886 if (images.length > 0) {
30887 // replace all v:imagedata - with img.
30888 var ar = Array.from(d.getElementsByTagName('v:imagedata'));
30889 Roo.each(ar, function(node) {
30890 node.parentNode.insertBefore(d.ownerDocument.createElement('img'), node );
30891 node.parentNode.removeChild(node);
30895 Roo.each(d.getElementsByTagName('img'), function(img, i) {
30896 img.setAttribute('src', images[i]);
30899 if (this.autoClean) {
30900 new Roo.htmleditor.FilterWord({ node : d });
30902 new Roo.htmleditor.FilterStyleToTag({ node : d });
30903 new Roo.htmleditor.FilterAttributes({
30905 attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'],
30906 attrib_clean : ['href', 'src' ]
30908 new Roo.htmleditor.FilterBlack({ node : d, tag : this.black});
30909 // should be fonts..
30910 new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT', ':' ]} );
30911 new Roo.htmleditor.FilterParagraph({ node : d });
30912 new Roo.htmleditor.FilterSpan({ node : d });
30913 new Roo.htmleditor.FilterLongBr({ node : d });
30914 new Roo.htmleditor.FilterComment({ node : d });
30918 if (this.enableBlocks) {
30920 Array.from(d.getElementsByTagName('img')).forEach(function(img) {
30921 if (img.closest('figure')) { // assume!! that it's aready
30924 var fig = new Roo.htmleditor.BlockFigure({
30925 image_src : img.src
30927 fig.updateElement(img); // replace it..
30933 this.insertAtCursor(d.innerHTML.replace(/ /g,' '));
30934 if (this.enableBlocks) {
30935 Roo.htmleditor.Block.initAll(this.doc.body);
30939 e.preventDefault();
30941 // default behaveiour should be our local cleanup paste? (optional?)
30942 // for simple editor - we want to hammer the paste and get rid of everything... - so over-rideable..
30943 //this.owner.fireEvent('paste', e, v);
30946 onDestroy : function(){
30952 //for (var i =0; i < this.toolbars.length;i++) {
30953 // // fixme - ask toolbars for heights?
30954 // this.toolbars[i].onDestroy();
30957 //this.wrap.dom.innerHTML = '';
30958 //this.wrap.remove();
30963 onFirstFocus : function(){
30965 this.assignDocWin();
30966 this.undoManager = new Roo.lib.UndoManager(100,(this.doc.body || this.doc.documentElement));
30968 this.activated = true;
30971 if(Roo.isGecko){ // prevent silly gecko errors
30973 var s = this.win.getSelection();
30974 if(!s.focusNode || s.focusNode.nodeType != 3){
30975 var r = s.getRangeAt(0);
30976 r.selectNodeContents((this.doc.body || this.doc.documentElement));
30981 this.execCmd('useCSS', true);
30982 this.execCmd('styleWithCSS', false);
30985 this.owner.fireEvent('activate', this);
30989 adjustFont: function(btn){
30990 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
30991 //if(Roo.isSafari){ // safari
30994 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
30995 if(Roo.isSafari){ // safari
30996 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
30997 v = (v < 10) ? 10 : v;
30998 v = (v > 48) ? 48 : v;
30999 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
31004 v = Math.max(1, v+adjust);
31006 this.execCmd('FontSize', v );
31009 onEditorEvent : function(e)
31013 if (e && (e.ctrlKey || e.metaKey) && e.keyCode === 90) {
31014 return; // we do not handle this.. (undo manager does..)
31016 // in theory this detects if the last element is not a br, then we try and do that.
31017 // its so clicking in space at bottom triggers adding a br and moving the cursor.
31019 e.target.nodeName == 'BODY' &&
31020 e.type == "mouseup" &&
31021 this.doc.body.lastChild
31023 var lc = this.doc.body.lastChild;
31024 // gtx-trans is google translate plugin adding crap.
31025 while ((lc.nodeType == 3 && lc.nodeValue == '') || lc.id == 'gtx-trans') {
31026 lc = lc.previousSibling;
31028 if (lc.nodeType == 1 && lc.nodeName != 'BR') {
31029 // if last element is <BR> - then dont do anything.
31031 var ns = this.doc.createElement('br');
31032 this.doc.body.appendChild(ns);
31033 range = this.doc.createRange();
31034 range.setStartAfter(ns);
31035 range.collapse(true);
31036 var sel = this.win.getSelection();
31037 sel.removeAllRanges();
31038 sel.addRange(range);
31044 this.fireEditorEvent(e);
31045 // this.updateToolbar();
31046 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
31049 fireEditorEvent: function(e)
31051 this.owner.fireEvent('editorevent', this, e);
31054 insertTag : function(tg)
31056 // could be a bit smarter... -> wrap the current selected tRoo..
31057 if (tg.toLowerCase() == 'span' ||
31058 tg.toLowerCase() == 'code' ||
31059 tg.toLowerCase() == 'sup' ||
31060 tg.toLowerCase() == 'sub'
31063 range = this.createRange(this.getSelection());
31064 var wrappingNode = this.doc.createElement(tg.toLowerCase());
31065 wrappingNode.appendChild(range.extractContents());
31066 range.insertNode(wrappingNode);
31073 this.execCmd("formatblock", tg);
31074 this.undoManager.addEvent();
31077 insertText : function(txt)
31081 var range = this.createRange();
31082 range.deleteContents();
31083 //alert(Sender.getAttribute('label'));
31085 range.insertNode(this.doc.createTextNode(txt));
31086 this.undoManager.addEvent();
31092 * Executes a Midas editor command on the editor document and performs necessary focus and
31093 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
31094 * @param {String} cmd The Midas command
31095 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
31097 relayCmd : function(cmd, value)
31101 case 'justifyleft':
31102 case 'justifyright':
31103 case 'justifycenter':
31104 // if we are in a cell, then we will adjust the
31105 var n = this.getParentElement();
31106 var td = n.closest('td');
31108 var bl = Roo.htmleditor.Block.factory(td);
31109 bl.textAlign = cmd.replace('justify','');
31110 bl.updateElement();
31111 this.owner.fireEvent('editorevent', this);
31114 this.execCmd('styleWithCSS', true); //
31118 // if there is no selection, then we insert, and set the curson inside it..
31119 this.execCmd('styleWithCSS', false);
31129 this.execCmd(cmd, value);
31130 this.owner.fireEvent('editorevent', this);
31131 //this.updateToolbar();
31132 this.owner.deferFocus();
31136 * Executes a Midas editor command directly on the editor document.
31137 * For visual commands, you should use {@link #relayCmd} instead.
31138 * <b>This should only be called after the editor is initialized.</b>
31139 * @param {String} cmd The Midas command
31140 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
31142 execCmd : function(cmd, value){
31143 this.doc.execCommand(cmd, false, value === undefined ? null : value);
31150 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
31152 * @param {String} text | dom node..
31154 insertAtCursor : function(text)
31157 if(!this.activated){
31161 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
31165 // from jquery ui (MIT licenced)
31167 var win = this.win;
31169 if (win.getSelection && win.getSelection().getRangeAt) {
31171 // delete the existing?
31173 this.createRange(this.getSelection()).deleteContents();
31174 range = win.getSelection().getRangeAt(0);
31175 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
31176 range.insertNode(node);
31177 range = range.cloneRange();
31178 range.collapse(false);
31180 win.getSelection().removeAllRanges();
31181 win.getSelection().addRange(range);
31185 } else if (win.document.selection && win.document.selection.createRange) {
31186 // no firefox support
31187 var txt = typeof(text) == 'string' ? text : text.outerHTML;
31188 win.document.selection.createRange().pasteHTML(txt);
31191 // no firefox support
31192 var txt = typeof(text) == 'string' ? text : text.outerHTML;
31193 this.execCmd('InsertHTML', txt);
31201 mozKeyPress : function(e){
31203 var c = e.getCharCode(), cmd;
31206 c = String.fromCharCode(c).toLowerCase();
31220 // this.cleanUpPaste.defer(100, this);
31226 this.relayCmd(cmd);
31227 //this.win.focus();
31228 //this.execCmd(cmd);
31229 //this.deferFocus();
31230 e.preventDefault();
31238 fixKeys : function(){ // load time branching for fastest keydown performance
31242 return function(e){
31243 var k = e.getKey(), r;
31246 r = this.doc.selection.createRange();
31249 r.pasteHTML('    ');
31254 /// this is handled by Roo.htmleditor.KeyEnter
31257 r = this.doc.selection.createRange();
31259 var target = r.parentElement();
31260 if(!target || target.tagName.toLowerCase() != 'li'){
31262 r.pasteHTML('<br/>');
31269 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
31270 // this.cleanUpPaste.defer(100, this);
31276 }else if(Roo.isOpera){
31277 return function(e){
31278 var k = e.getKey();
31282 this.execCmd('InsertHTML','    ');
31286 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
31287 // this.cleanUpPaste.defer(100, this);
31292 }else if(Roo.isSafari){
31293 return function(e){
31294 var k = e.getKey();
31298 this.execCmd('InsertText','\t');
31302 this.mozKeyPress(e);
31304 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
31305 // this.cleanUpPaste.defer(100, this);
31313 getAllAncestors: function()
31315 var p = this.getSelectedNode();
31318 a.push(p); // push blank onto stack..
31319 p = this.getParentElement();
31323 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
31327 a.push(this.doc.body);
31331 lastSelNode : false,
31334 getSelection : function()
31336 this.assignDocWin();
31337 return Roo.lib.Selection.wrap(Roo.isIE ? this.doc.selection : this.win.getSelection(), this.doc);
31340 * Select a dom node
31341 * @param {DomElement} node the node to select
31343 selectNode : function(node, collapse)
31345 var nodeRange = node.ownerDocument.createRange();
31347 nodeRange.selectNode(node);
31349 nodeRange.selectNodeContents(node);
31351 if (collapse === true) {
31352 nodeRange.collapse(true);
31355 var s = this.win.getSelection();
31356 s.removeAllRanges();
31357 s.addRange(nodeRange);
31360 getSelectedNode: function()
31362 // this may only work on Gecko!!!
31364 // should we cache this!!!!
31368 var range = this.createRange(this.getSelection()).cloneRange();
31371 var parent = range.parentElement();
31373 var testRange = range.duplicate();
31374 testRange.moveToElementText(parent);
31375 if (testRange.inRange(range)) {
31378 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
31381 parent = parent.parentElement;
31386 // is ancestor a text element.
31387 var ac = range.commonAncestorContainer;
31388 if (ac.nodeType == 3) {
31389 ac = ac.parentNode;
31392 var ar = ac.childNodes;
31395 var other_nodes = [];
31396 var has_other_nodes = false;
31397 for (var i=0;i<ar.length;i++) {
31398 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
31401 // fullly contained node.
31403 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
31408 // probably selected..
31409 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
31410 other_nodes.push(ar[i]);
31414 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
31419 has_other_nodes = true;
31421 if (!nodes.length && other_nodes.length) {
31422 nodes= other_nodes;
31424 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
31432 createRange: function(sel)
31434 // this has strange effects when using with
31435 // top toolbar - not sure if it's a great idea.
31436 //this.editor.contentWindow.focus();
31437 if (typeof sel != "undefined") {
31439 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
31441 return this.doc.createRange();
31444 return this.doc.createRange();
31447 getParentElement: function()
31450 this.assignDocWin();
31451 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
31453 var range = this.createRange(sel);
31456 var p = range.commonAncestorContainer;
31457 while (p.nodeType == 3) { // text node
31468 * Range intersection.. the hard stuff...
31472 * [ -- selected range --- ]
31476 * if end is before start or hits it. fail.
31477 * if start is after end or hits it fail.
31479 * if either hits (but other is outside. - then it's not
31485 // @see http://www.thismuchiknow.co.uk/?p=64.
31486 rangeIntersectsNode : function(range, node)
31488 var nodeRange = node.ownerDocument.createRange();
31490 nodeRange.selectNode(node);
31492 nodeRange.selectNodeContents(node);
31495 var rangeStartRange = range.cloneRange();
31496 rangeStartRange.collapse(true);
31498 var rangeEndRange = range.cloneRange();
31499 rangeEndRange.collapse(false);
31501 var nodeStartRange = nodeRange.cloneRange();
31502 nodeStartRange.collapse(true);
31504 var nodeEndRange = nodeRange.cloneRange();
31505 nodeEndRange.collapse(false);
31507 return rangeStartRange.compareBoundaryPoints(
31508 Range.START_TO_START, nodeEndRange) == -1 &&
31509 rangeEndRange.compareBoundaryPoints(
31510 Range.START_TO_START, nodeStartRange) == 1;
31514 rangeCompareNode : function(range, node)
31516 var nodeRange = node.ownerDocument.createRange();
31518 nodeRange.selectNode(node);
31520 nodeRange.selectNodeContents(node);
31524 range.collapse(true);
31526 nodeRange.collapse(true);
31528 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
31529 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
31531 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
31533 var nodeIsBefore = ss == 1;
31534 var nodeIsAfter = ee == -1;
31536 if (nodeIsBefore && nodeIsAfter) {
31539 if (!nodeIsBefore && nodeIsAfter) {
31540 return 1; //right trailed.
31543 if (nodeIsBefore && !nodeIsAfter) {
31544 return 2; // left trailed.
31550 cleanWordChars : function(input) {// change the chars to hex code
31553 [ 8211, "–" ],
31554 [ 8212, "—" ],
31562 var output = input;
31563 Roo.each(swapCodes, function(sw) {
31564 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
31566 output = output.replace(swapper, sw[1]);
31576 cleanUpChild : function (node)
31579 new Roo.htmleditor.FilterComment({node : node});
31580 new Roo.htmleditor.FilterAttributes({
31582 attrib_black : this.ablack,
31583 attrib_clean : this.aclean,
31584 style_white : this.cwhite,
31585 style_black : this.cblack
31587 new Roo.htmleditor.FilterBlack({ node : node, tag : this.black});
31588 new Roo.htmleditor.FilterKeepChildren({node : node, tag : this.tag_remove} );
31594 * Clean up MS wordisms...
31595 * @deprecated - use filter directly
31597 cleanWord : function(node)
31599 new Roo.htmleditor.FilterWord({ node : node ? node : this.doc.body });
31600 new Roo.htmleditor.FilterKeepChildren({node : node ? node : this.doc.body, tag : [ 'FONT', ':' ]} );
31607 * @deprecated - use filters
31609 cleanTableWidths : function(node)
31611 new Roo.htmleditor.FilterTableWidth({ node : node ? node : this.doc.body});
31618 applyBlacklists : function()
31620 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
31621 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
31623 this.aclean = typeof(this.owner.aclean) != 'undefined' && this.owner.aclean ? this.owner.aclean : Roo.HtmlEditorCore.aclean;
31624 this.ablack = typeof(this.owner.ablack) != 'undefined' && this.owner.ablack ? this.owner.ablack : Roo.HtmlEditorCore.ablack;
31625 this.tag_remove = typeof(this.owner.tag_remove) != 'undefined' && this.owner.tag_remove ? this.owner.tag_remove : Roo.HtmlEditorCore.tag_remove;
31629 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
31630 if (b.indexOf(tag) > -1) {
31633 this.white.push(tag);
31637 Roo.each(w, function(tag) {
31638 if (b.indexOf(tag) > -1) {
31641 if (this.white.indexOf(tag) > -1) {
31644 this.white.push(tag);
31649 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
31650 if (w.indexOf(tag) > -1) {
31653 this.black.push(tag);
31657 Roo.each(b, function(tag) {
31658 if (w.indexOf(tag) > -1) {
31661 if (this.black.indexOf(tag) > -1) {
31664 this.black.push(tag);
31669 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
31670 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
31674 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
31675 if (b.indexOf(tag) > -1) {
31678 this.cwhite.push(tag);
31682 Roo.each(w, function(tag) {
31683 if (b.indexOf(tag) > -1) {
31686 if (this.cwhite.indexOf(tag) > -1) {
31689 this.cwhite.push(tag);
31694 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
31695 if (w.indexOf(tag) > -1) {
31698 this.cblack.push(tag);
31702 Roo.each(b, function(tag) {
31703 if (w.indexOf(tag) > -1) {
31706 if (this.cblack.indexOf(tag) > -1) {
31709 this.cblack.push(tag);
31714 setStylesheets : function(stylesheets)
31716 if(typeof(stylesheets) == 'string'){
31717 Roo.get(this.iframe.contentDocument.head).createChild({
31719 rel : 'stylesheet',
31728 Roo.each(stylesheets, function(s) {
31733 Roo.get(_this.iframe.contentDocument.head).createChild({
31735 rel : 'stylesheet',
31745 updateLanguage : function()
31747 if (!this.iframe || !this.iframe.contentDocument) {
31750 Roo.get(this.iframe.contentDocument.body).attr("lang", this.language);
31754 removeStylesheets : function()
31758 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
31763 setStyle : function(style)
31765 Roo.get(this.iframe.contentDocument.head).createChild({
31774 // hide stuff that is not compatible
31788 * @event specialkey
31792 * @cfg {String} fieldClass @hide
31795 * @cfg {String} focusClass @hide
31798 * @cfg {String} autoCreate @hide
31801 * @cfg {String} inputType @hide
31804 * @cfg {String} invalidClass @hide
31807 * @cfg {String} invalidText @hide
31810 * @cfg {String} msgFx @hide
31813 * @cfg {String} validateOnBlur @hide
31817 Roo.HtmlEditorCore.white = [
31818 'AREA', 'BR', 'IMG', 'INPUT', 'HR', 'WBR',
31820 'ADDRESS', 'BLOCKQUOTE', 'CENTER', 'DD', 'DIR', 'DIV',
31821 'DL', 'DT', 'H1', 'H2', 'H3', 'H4',
31822 'H5', 'H6', 'HR', 'ISINDEX', 'LISTING', 'MARQUEE',
31823 'MENU', 'MULTICOL', 'OL', 'P', 'PLAINTEXT', 'PRE',
31824 'TABLE', 'UL', 'XMP',
31826 'CAPTION', 'COL', 'COLGROUP', 'TBODY', 'TD', 'TFOOT', 'TH',
31829 'DIR', 'MENU', 'OL', 'UL', 'DL',
31835 Roo.HtmlEditorCore.black = [
31836 // 'embed', 'object', // enable - backend responsiblity to clean thiese
31838 'BASE', 'BASEFONT', 'BGSOUND', 'BLINK', 'BODY',
31839 'FRAME', 'FRAMESET', 'HEAD', 'HTML', 'ILAYER',
31840 'IFRAME', 'LAYER', 'LINK', 'META', 'OBJECT',
31841 'SCRIPT', 'STYLE' ,'TITLE', 'XML',
31842 //'FONT' // CLEAN LATER..
31843 'COLGROUP', 'COL' // messy tables.
31847 Roo.HtmlEditorCore.clean = [ // ?? needed???
31848 'SCRIPT', 'STYLE', 'TITLE', 'XML'
31850 Roo.HtmlEditorCore.tag_remove = [
31855 Roo.HtmlEditorCore.ablack = [
31859 Roo.HtmlEditorCore.aclean = [
31860 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
31864 Roo.HtmlEditorCore.pwhite= [
31865 'http', 'https', 'mailto'
31868 // white listed style attributes.
31869 Roo.HtmlEditorCore.cwhite= [
31870 // 'text-align', /// default is to allow most things..
31876 // black listed style attributes.
31877 Roo.HtmlEditorCore.cblack= [
31878 // 'font-size' -- this can be set by the project
31892 * @class Roo.bootstrap.form.HtmlEditor
31893 * @extends Roo.bootstrap.form.TextArea
31894 * Bootstrap HtmlEditor class
31897 * Create a new HtmlEditor
31898 * @param {Object} config The config object
31901 Roo.bootstrap.form.HtmlEditor = function(config){
31902 Roo.bootstrap.form.HtmlEditor.superclass.constructor.call(this, config);
31903 if (!this.toolbars) {
31904 this.toolbars = [];
31907 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
31910 * @event initialize
31911 * Fires when the editor is fully initialized (including the iframe)
31912 * @param {HtmlEditor} this
31917 * Fires when the editor is first receives the focus. Any insertion must wait
31918 * until after this event.
31919 * @param {HtmlEditor} this
31923 * @event beforesync
31924 * Fires before the textarea is updated with content from the editor iframe. Return false
31925 * to cancel the sync.
31926 * @param {HtmlEditor} this
31927 * @param {String} html
31931 * @event beforepush
31932 * Fires before the iframe editor is updated with content from the textarea. Return false
31933 * to cancel the push.
31934 * @param {HtmlEditor} this
31935 * @param {String} html
31940 * Fires when the textarea is updated with content from the editor iframe.
31941 * @param {HtmlEditor} this
31942 * @param {String} html
31947 * Fires when the iframe editor is updated with content from the textarea.
31948 * @param {HtmlEditor} this
31949 * @param {String} html
31953 * @event editmodechange
31954 * Fires when the editor switches edit modes
31955 * @param {HtmlEditor} this
31956 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
31958 editmodechange: true,
31960 * @event editorevent
31961 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
31962 * @param {HtmlEditor} this
31966 * @event firstfocus
31967 * Fires when on first focus - needed by toolbars..
31968 * @param {HtmlEditor} this
31973 * Auto save the htmlEditor value as a file into Events
31974 * @param {HtmlEditor} this
31978 * @event savedpreview
31979 * preview the saved version of htmlEditor
31980 * @param {HtmlEditor} this
31987 Roo.extend(Roo.bootstrap.form.HtmlEditor, Roo.bootstrap.form.TextArea, {
31991 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
31996 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
32001 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
32006 * @cfg {Number} height (in pixels)
32010 * @cfg {Number} width (in pixels)
32015 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
32018 stylesheets: false,
32023 // private properties
32024 validationEvent : false,
32026 initialized : false,
32029 onFocus : Roo.emptyFn,
32031 hideMode:'offsets',
32033 tbContainer : false,
32037 toolbarContainer :function() {
32038 return this.wrap.select('.x-html-editor-tb',true).first();
32042 * Protected method that will not generally be called directly. It
32043 * is called when the editor creates its toolbar. Override this method if you need to
32044 * add custom toolbar buttons.
32045 * @param {HtmlEditor} editor
32047 createToolbar : function(){
32048 Roo.log('renewing');
32049 Roo.log("create toolbars");
32051 this.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard({editor: this} ) ];
32052 this.toolbars[0].render(this.toolbarContainer());
32056 // if (!editor.toolbars || !editor.toolbars.length) {
32057 // editor.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard() ]; // can be empty?
32060 // for (var i =0 ; i < editor.toolbars.length;i++) {
32061 // editor.toolbars[i] = Roo.factory(
32062 // typeof(editor.toolbars[i]) == 'string' ?
32063 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
32064 // Roo.bootstrap.form.HtmlEditor);
32065 // editor.toolbars[i].init(editor);
32071 onRender : function(ct, position)
32073 // Roo.log("Call onRender: " + this.xtype);
32075 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
32077 this.wrap = this.inputEl().wrap({
32078 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
32081 this.editorcore.onRender(ct, position);
32083 if (this.resizable) {
32084 this.resizeEl = new Roo.Resizable(this.wrap, {
32088 minHeight : this.height,
32089 height: this.height,
32090 handles : this.resizable,
32093 resize : function(r, w, h) {
32094 _t.onResize(w,h); // -something
32100 this.createToolbar(this);
32103 if(!this.width && this.resizable){
32104 this.setSize(this.wrap.getSize());
32106 if (this.resizeEl) {
32107 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
32108 // should trigger onReize..
32114 onResize : function(w, h)
32116 Roo.log('resize: ' +w + ',' + h );
32117 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
32121 if(this.inputEl() ){
32122 if(typeof w == 'number'){
32123 var aw = w - this.wrap.getFrameWidth('lr');
32124 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
32127 if(typeof h == 'number'){
32128 var tbh = -11; // fixme it needs to tool bar size!
32129 for (var i =0; i < this.toolbars.length;i++) {
32130 // fixme - ask toolbars for heights?
32131 tbh += this.toolbars[i].el.getHeight();
32132 //if (this.toolbars[i].footer) {
32133 // tbh += this.toolbars[i].footer.el.getHeight();
32141 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
32142 ah -= 5; // knock a few pixes off for look..
32143 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
32147 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
32148 this.editorcore.onResize(ew,eh);
32153 * Toggles the editor between standard and source edit mode.
32154 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
32156 toggleSourceEdit : function(sourceEditMode)
32158 this.editorcore.toggleSourceEdit(sourceEditMode);
32160 if(this.editorcore.sourceEditMode){
32161 Roo.log('editor - showing textarea');
32164 // Roo.log(this.syncValue());
32166 this.inputEl().removeClass(['hide', 'x-hidden']);
32167 this.inputEl().dom.removeAttribute('tabIndex');
32168 this.inputEl().focus();
32170 Roo.log('editor - hiding textarea');
32172 // Roo.log(this.pushValue());
32175 this.inputEl().addClass(['hide', 'x-hidden']);
32176 this.inputEl().dom.setAttribute('tabIndex', -1);
32177 //this.deferFocus();
32180 if(this.resizable){
32181 this.setSize(this.wrap.getSize());
32184 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
32187 // private (for BoxComponent)
32188 adjustSize : Roo.BoxComponent.prototype.adjustSize,
32190 // private (for BoxComponent)
32191 getResizeEl : function(){
32195 // private (for BoxComponent)
32196 getPositionEl : function(){
32201 initEvents : function(){
32202 this.originalValue = this.getValue();
32206 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
32209 // markInvalid : Roo.emptyFn,
32211 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
32214 // clearInvalid : Roo.emptyFn,
32216 setValue : function(v){
32217 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
32218 this.editorcore.pushValue();
32223 deferFocus : function(){
32224 this.focus.defer(10, this);
32228 focus : function(){
32229 this.editorcore.focus();
32235 onDestroy : function(){
32241 for (var i =0; i < this.toolbars.length;i++) {
32242 // fixme - ask toolbars for heights?
32243 this.toolbars[i].onDestroy();
32246 this.wrap.dom.innerHTML = '';
32247 this.wrap.remove();
32252 onFirstFocus : function(){
32253 //Roo.log("onFirstFocus");
32254 this.editorcore.onFirstFocus();
32255 for (var i =0; i < this.toolbars.length;i++) {
32256 this.toolbars[i].onFirstFocus();
32262 syncValue : function()
32264 this.editorcore.syncValue();
32267 pushValue : function()
32269 this.editorcore.pushValue();
32273 // hide stuff that is not compatible
32287 * @event specialkey
32291 * @cfg {String} fieldClass @hide
32294 * @cfg {String} focusClass @hide
32297 * @cfg {String} autoCreate @hide
32300 * @cfg {String} inputType @hide
32304 * @cfg {String} invalidText @hide
32307 * @cfg {String} msgFx @hide
32310 * @cfg {String} validateOnBlur @hide
32319 Roo.namespace('Roo.bootstrap.form.HtmlEditor');
32321 * @class Roo.bootstrap.form.HtmlEditorToolbarStandard
32322 * @parent Roo.bootstrap.form.HtmlEditor
32323 * @extends Roo.bootstrap.nav.Simplebar
32329 new Roo.bootstrap.form.HtmlEditor({
32332 new Roo.bootstrap.form.HtmlEditorToolbarStandard({
32333 disable : { fonts: 1 , format: 1, ..., ... , ...],
32339 * @cfg {Object} disable List of elements to disable..
32340 * @cfg {Array} btns List of additional buttons.
32344 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
32347 Roo.bootstrap.form.HtmlEditorToolbarStandard = function(config)
32350 Roo.apply(this, config);
32352 // default disabled, based on 'good practice'..
32353 this.disable = this.disable || {};
32354 Roo.applyIf(this.disable, {
32357 specialElements : true
32359 Roo.bootstrap.form.HtmlEditorToolbarStandard.superclass.constructor.call(this, config);
32361 this.editor = config.editor;
32362 this.editorcore = config.editor.editorcore;
32364 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
32366 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
32367 // dont call parent... till later.
32369 Roo.extend(Roo.bootstrap.form.HtmlEditorToolbarStandard, Roo.bootstrap.nav.Simplebar, {
32374 editorcore : false,
32379 "h1","h2","h3","h4","h5","h6",
32381 "abbr", "acronym", "address", "cite", "samp", "var",
32385 onRender : function(ct, position)
32387 // Roo.log("Call onRender: " + this.xtype);
32389 Roo.bootstrap.form.HtmlEditorToolbarStandard.superclass.onRender.call(this, ct, position);
32391 this.el.dom.style.marginBottom = '0';
32393 var editorcore = this.editorcore;
32394 var editor= this.editor;
32397 var btn = function(id,cmd , toggle, handler, html){
32399 var event = toggle ? 'toggle' : 'click';
32404 xns: Roo.bootstrap,
32408 enableToggle:toggle !== false,
32410 pressed : toggle ? false : null,
32413 a.listeners[toggle ? 'toggle' : 'click'] = function() {
32414 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
32420 // var cb_box = function...
32425 xns: Roo.bootstrap,
32430 xns: Roo.bootstrap,
32434 Roo.each(this.formats, function(f) {
32435 style.menu.items.push({
32437 xns: Roo.bootstrap,
32438 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
32443 editorcore.insertTag(this.tagname);
32450 children.push(style);
32452 btn('bold',false,true);
32453 btn('italic',false,true);
32454 btn('align-left', 'justifyleft',true);
32455 btn('align-center', 'justifycenter',true);
32456 btn('align-right' , 'justifyright',true);
32457 btn('link', false, false, function(btn) {
32458 //Roo.log("create link?");
32459 var url = prompt(this.createLinkText, this.defaultLinkValue);
32460 if(url && url != 'http:/'+'/'){
32461 this.editorcore.relayCmd('createlink', url);
32464 btn('list','insertunorderedlist',true);
32465 btn('pencil', false,true, function(btn){
32467 this.toggleSourceEdit(btn.pressed);
32470 if (this.editor.btns.length > 0) {
32471 for (var i = 0; i<this.editor.btns.length; i++) {
32472 children.push(this.editor.btns[i]);
32480 xns: Roo.bootstrap,
32485 xns: Roo.bootstrap,
32490 cog.menu.items.push({
32492 xns: Roo.bootstrap,
32493 html : Clean styles,
32498 editorcore.insertTag(this.tagname);
32507 this.xtype = 'NavSimplebar';
32509 for(var i=0;i< children.length;i++) {
32511 this.buttons.add(this.addxtypeChild(children[i]));
32515 editor.on('editorevent', this.updateToolbar, this);
32517 onBtnClick : function(id)
32519 this.editorcore.relayCmd(id);
32520 this.editorcore.focus();
32524 * Protected method that will not generally be called directly. It triggers
32525 * a toolbar update by reading the markup state of the current selection in the editor.
32527 updateToolbar: function(){
32529 if(!this.editorcore.activated){
32530 this.editor.onFirstFocus(); // is this neeed?
32534 var btns = this.buttons;
32535 var doc = this.editorcore.doc;
32536 btns.get('bold').setActive(doc.queryCommandState('bold'));
32537 btns.get('italic').setActive(doc.queryCommandState('italic'));
32538 //btns.get('underline').setActive(doc.queryCommandState('underline'));
32540 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
32541 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
32542 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
32544 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
32545 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
32548 var ans = this.editorcore.getAllAncestors();
32549 if (this.formatCombo) {
32552 var store = this.formatCombo.store;
32553 this.formatCombo.setValue("");
32554 for (var i =0; i < ans.length;i++) {
32555 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
32557 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
32565 // hides menus... - so this cant be on a menu...
32566 Roo.bootstrap.MenuMgr.hideAll();
32568 Roo.bootstrap.menu.Manager.hideAll();
32569 //this.editorsyncValue();
32571 onFirstFocus: function() {
32572 this.buttons.each(function(item){
32576 toggleSourceEdit : function(sourceEditMode){
32579 if(sourceEditMode){
32580 Roo.log("disabling buttons");
32581 this.buttons.each( function(item){
32582 if(item.cmd != 'pencil'){
32588 Roo.log("enabling buttons");
32589 if(this.editorcore.initialized){
32590 this.buttons.each( function(item){
32596 Roo.log("calling toggole on editor");
32597 // tell the editor that it's been pressed..
32598 this.editor.toggleSourceEdit(sourceEditMode);
32612 * @class Roo.bootstrap.form.Markdown
32613 * @extends Roo.bootstrap.form.TextArea
32614 * Bootstrap Showdown editable area
32615 * @cfg {string} content
32618 * Create a new Showdown
32621 Roo.bootstrap.form.Markdown = function(config){
32622 Roo.bootstrap.form.Markdown.superclass.constructor.call(this, config);
32626 Roo.extend(Roo.bootstrap.form.Markdown, Roo.bootstrap.form.TextArea, {
32630 initEvents : function()
32633 Roo.bootstrap.form.TextArea.prototype.initEvents.call(this);
32634 this.markdownEl = this.el.createChild({
32635 cls : 'roo-markdown-area'
32637 this.inputEl().addClass('d-none');
32638 if (this.getValue() == '') {
32639 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
32642 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
32644 this.markdownEl.on('click', this.toggleTextEdit, this);
32645 this.on('blur', this.toggleTextEdit, this);
32646 this.on('specialkey', this.resizeTextArea, this);
32649 toggleTextEdit : function()
32651 var sh = this.markdownEl.getHeight();
32652 this.inputEl().addClass('d-none');
32653 this.markdownEl.addClass('d-none');
32654 if (!this.editing) {
32656 this.inputEl().setHeight(Math.min(500, Math.max(sh,(this.getValue().split("\n").length+1) * 30)));
32657 this.inputEl().removeClass('d-none');
32658 this.inputEl().focus();
32659 this.editing = true;
32662 // show showdown...
32663 this.updateMarkdown();
32664 this.markdownEl.removeClass('d-none');
32665 this.editing = false;
32668 updateMarkdown : function()
32670 if (this.getValue() == '') {
32671 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
32675 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
32678 resizeTextArea: function () {
32681 Roo.log([sh, this.getValue().split("\n").length * 30]);
32682 this.inputEl().setHeight(Math.min(500, Math.max(sh, (this.getValue().split("\n").length +1) * 30)));
32684 setValue : function(val)
32686 Roo.bootstrap.form.TextArea.prototype.setValue.call(this,val);
32687 if (!this.editing) {
32688 this.updateMarkdown();
32694 if (!this.editing) {
32695 this.toggleTextEdit();
32703 * Ext JS Library 1.1.1
32704 * Copyright(c) 2006-2007, Ext JS, LLC.
32706 * Originally Released Under LGPL - original licence link has changed is not relivant.
32709 * <script type="text/javascript">
32713 * @class Roo.bootstrap.PagingToolbar
32714 * @extends Roo.bootstrap.nav.Simplebar
32715 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
32717 * Create a new PagingToolbar
32718 * @param {Object} config The config object
32719 * @param {Roo.data.Store} store
32721 Roo.bootstrap.PagingToolbar = function(config)
32723 // old args format still supported... - xtype is prefered..
32724 // created from xtype...
32726 this.ds = config.dataSource;
32728 if (config.store && !this.ds) {
32729 this.store= Roo.factory(config.store, Roo.data);
32730 this.ds = this.store;
32731 this.ds.xmodule = this.xmodule || false;
32734 this.toolbarItems = [];
32735 if (config.items) {
32736 this.toolbarItems = config.items;
32739 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
32744 this.bind(this.ds);
32747 if (Roo.bootstrap.version == 4) {
32748 this.navgroup = new Roo.bootstrap.ButtonGroup({ cls: 'pagination' });
32750 this.navgroup = new Roo.bootstrap.nav.Group({ cls: 'pagination' });
32755 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.nav.Simplebar, {
32757 * @cfg {Roo.bootstrap.Button} buttons[]
32758 * Buttons for the toolbar
32761 * @cfg {Roo.data.Store} store
32762 * The underlying data store providing the paged data
32765 * @cfg {String/HTMLElement/Element} container
32766 * container The id or element that will contain the toolbar
32769 * @cfg {Boolean} displayInfo
32770 * True to display the displayMsg (defaults to false)
32773 * @cfg {Number} pageSize
32774 * The number of records to display per page (defaults to 20)
32778 * @cfg {String} displayMsg
32779 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
32781 displayMsg : 'Displaying {0} - {1} of {2}',
32783 * @cfg {String} emptyMsg
32784 * The message to display when no records are found (defaults to "No data to display")
32786 emptyMsg : 'No data to display',
32788 * Customizable piece of the default paging text (defaults to "Page")
32791 beforePageText : "Page",
32793 * Customizable piece of the default paging text (defaults to "of %0")
32796 afterPageText : "of {0}",
32798 * Customizable piece of the default paging text (defaults to "First Page")
32801 firstText : "First Page",
32803 * Customizable piece of the default paging text (defaults to "Previous Page")
32806 prevText : "Previous Page",
32808 * Customizable piece of the default paging text (defaults to "Next Page")
32811 nextText : "Next Page",
32813 * Customizable piece of the default paging text (defaults to "Last Page")
32816 lastText : "Last Page",
32818 * Customizable piece of the default paging text (defaults to "Refresh")
32821 refreshText : "Refresh",
32825 onRender : function(ct, position)
32827 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
32828 this.navgroup.parentId = this.id;
32829 this.navgroup.onRender(this.el, null);
32830 // add the buttons to the navgroup
32832 if(this.displayInfo){
32833 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
32834 this.displayEl = this.el.select('.x-paging-info', true).first();
32835 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
32836 // this.displayEl = navel.el.select('span',true).first();
32842 Roo.each(_this.buttons, function(e){ // this might need to use render????
32843 Roo.factory(e).render(_this.el);
32847 Roo.each(_this.toolbarItems, function(e) {
32848 _this.navgroup.addItem(e);
32852 this.first = this.navgroup.addItem({
32853 tooltip: this.firstText,
32854 cls: "prev btn-outline-secondary",
32855 html : ' <i class="fa fa-step-backward"></i>',
32857 preventDefault: true,
32858 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
32861 this.prev = this.navgroup.addItem({
32862 tooltip: this.prevText,
32863 cls: "prev btn-outline-secondary",
32864 html : ' <i class="fa fa-backward"></i>',
32866 preventDefault: true,
32867 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
32869 //this.addSeparator();
32872 var field = this.navgroup.addItem( {
32874 cls : 'x-paging-position btn-outline-secondary',
32876 html : this.beforePageText +
32877 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
32878 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
32881 this.field = field.el.select('input', true).first();
32882 this.field.on("keydown", this.onPagingKeydown, this);
32883 this.field.on("focus", function(){this.dom.select();});
32886 this.afterTextEl = field.el.select('.x-paging-after',true).first();
32887 //this.field.setHeight(18);
32888 //this.addSeparator();
32889 this.next = this.navgroup.addItem({
32890 tooltip: this.nextText,
32891 cls: "next btn-outline-secondary",
32892 html : ' <i class="fa fa-forward"></i>',
32894 preventDefault: true,
32895 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
32897 this.last = this.navgroup.addItem({
32898 tooltip: this.lastText,
32899 html : ' <i class="fa fa-step-forward"></i>',
32900 cls: "next btn-outline-secondary",
32902 preventDefault: true,
32903 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
32905 //this.addSeparator();
32906 this.loading = this.navgroup.addItem({
32907 tooltip: this.refreshText,
32908 cls: "btn-outline-secondary",
32909 html : ' <i class="fa fa-refresh"></i>',
32910 preventDefault: true,
32911 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
32917 updateInfo : function(){
32918 if(this.displayEl){
32919 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
32920 var msg = count == 0 ?
32924 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
32926 this.displayEl.update(msg);
32931 onLoad : function(ds, r, o)
32933 this.cursor = o.params && o.params.start ? o.params.start : 0;
32935 var d = this.getPageData(),
32940 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
32941 this.field.dom.value = ap;
32942 this.first.setDisabled(ap == 1);
32943 this.prev.setDisabled(ap == 1);
32944 this.next.setDisabled(ap == ps);
32945 this.last.setDisabled(ap == ps);
32946 this.loading.enable();
32951 getPageData : function(){
32952 var total = this.ds.getTotalCount();
32955 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
32956 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
32961 onLoadError : function(proxy, o){
32962 this.loading.enable();
32963 if (this.ds.events.loadexception.listeners.length < 2) {
32964 // nothing has been assigned to loadexception except this...
32966 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
32972 onPagingKeydown : function(e){
32973 var k = e.getKey();
32974 var d = this.getPageData();
32976 var v = this.field.dom.value, pageNum;
32977 if(!v || isNaN(pageNum = parseInt(v, 10))){
32978 this.field.dom.value = d.activePage;
32981 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
32982 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
32985 else if(k == e.HOME || (k == e.UP && e.ctrlKey) || (k == e.PAGEUP && e.ctrlKey) || (k == e.RIGHT && e.ctrlKey) || k == e.END || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey))
32987 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
32988 this.field.dom.value = pageNum;
32989 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
32992 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
32994 var v = this.field.dom.value, pageNum;
32995 var increment = (e.shiftKey) ? 10 : 1;
32996 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
32999 if(!v || isNaN(pageNum = parseInt(v, 10))) {
33000 this.field.dom.value = d.activePage;
33003 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
33005 this.field.dom.value = parseInt(v, 10) + increment;
33006 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
33007 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
33014 beforeLoad : function(){
33016 this.loading.disable();
33021 onClick : function(which){
33030 ds.load({params:{start: 0, limit: this.pageSize}});
33033 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
33036 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
33039 var total = ds.getTotalCount();
33040 var extra = total % this.pageSize;
33041 var lastStart = extra ? (total - extra) : total-this.pageSize;
33042 ds.load({params:{start: lastStart, limit: this.pageSize}});
33045 ds.load({params:{start: this.cursor, limit: this.pageSize}});
33051 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
33052 * @param {Roo.data.Store} store The data store to unbind
33054 unbind : function(ds){
33055 ds.un("beforeload", this.beforeLoad, this);
33056 ds.un("load", this.onLoad, this);
33057 ds.un("loadexception", this.onLoadError, this);
33058 ds.un("remove", this.updateInfo, this);
33059 ds.un("add", this.updateInfo, this);
33060 this.ds = undefined;
33064 * Binds the paging toolbar to the specified {@link Roo.data.Store}
33065 * @param {Roo.data.Store} store The data store to bind
33067 bind : function(ds){
33068 ds.on("beforeload", this.beforeLoad, this);
33069 ds.on("load", this.onLoad, this);
33070 ds.on("loadexception", this.onLoadError, this);
33071 ds.on("remove", this.updateInfo, this);
33072 ds.on("add", this.updateInfo, this);
33083 * @class Roo.bootstrap.MessageBar
33084 * @extends Roo.bootstrap.Component
33085 * Bootstrap MessageBar class
33086 * @cfg {String} html contents of the MessageBar
33087 * @cfg {String} weight (info | success | warning | danger) default info
33088 * @cfg {String} beforeClass insert the bar before the given class
33089 * @cfg {Boolean} closable (true | false) default false
33090 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
33093 * Create a new Element
33094 * @param {Object} config The config object
33097 Roo.bootstrap.MessageBar = function(config){
33098 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
33101 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
33107 beforeClass: 'bootstrap-sticky-wrap',
33109 getAutoCreate : function(){
33113 cls: 'alert alert-dismissable alert-' + this.weight,
33118 html: this.html || ''
33124 cfg.cls += ' alert-messages-fixed';
33138 onRender : function(ct, position)
33140 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
33143 var cfg = Roo.apply({}, this.getAutoCreate());
33147 cfg.cls += ' ' + this.cls;
33150 cfg.style = this.style;
33152 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
33154 this.el.setVisibilityMode(Roo.Element.DISPLAY);
33157 this.el.select('>button.close').on('click', this.hide, this);
33163 if (!this.rendered) {
33169 this.fireEvent('show', this);
33175 if (!this.rendered) {
33181 this.fireEvent('hide', this);
33184 update : function()
33186 // var e = this.el.dom.firstChild;
33188 // if(this.closable){
33189 // e = e.nextSibling;
33192 // e.data = this.html || '';
33194 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
33210 * @class Roo.bootstrap.Graph
33211 * @extends Roo.bootstrap.Component
33212 * Bootstrap Graph class
33216 @cfg {String} graphtype bar | vbar | pie
33217 @cfg {number} g_x coodinator | centre x (pie)
33218 @cfg {number} g_y coodinator | centre y (pie)
33219 @cfg {number} g_r radius (pie)
33220 @cfg {number} g_height height of the chart (respected by all elements in the set)
33221 @cfg {number} g_width width of the chart (respected by all elements in the set)
33222 @cfg {Object} title The title of the chart
33225 -opts (object) options for the chart
33227 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
33228 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
33230 o colors (array) colors be used repeatedly to plot the bars. If multicolumn bar is used each sequence of bars with use a different color.
33231 o stacked (boolean) whether or not to tread values as in a stacked bar chart
33233 o stretch (boolean)
33235 -opts (object) options for the pie
33238 o startAngle (number)
33239 o endAngle (number)
33243 * Create a new Input
33244 * @param {Object} config The config object
33247 Roo.bootstrap.Graph = function(config){
33248 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
33254 * The img click event for the img.
33255 * @param {Roo.EventObject} e
33261 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
33272 //g_colors: this.colors,
33279 getAutoCreate : function(){
33290 onRender : function(ct,position){
33293 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
33295 if (typeof(Raphael) == 'undefined') {
33296 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
33300 this.raphael = Raphael(this.el.dom);
33302 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
33303 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
33304 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
33305 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
33307 r.text(160, 10, "Single Series Chart").attr(txtattr);
33308 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
33309 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
33310 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
33312 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
33313 r.barchart(330, 10, 300, 220, data1);
33314 r.barchart(10, 250, 300, 220, data2, {stacked: true});
33315 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
33318 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
33319 // r.barchart(30, 30, 560, 250, xdata, {
33320 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
33321 // axis : "0 0 1 1",
33322 // axisxlabels : xdata
33323 // //yvalues : cols,
33326 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
33328 // this.load(null,xdata,{
33329 // axis : "0 0 1 1",
33330 // axisxlabels : xdata
33335 load : function(graphtype,xdata,opts)
33337 this.raphael.clear();
33339 graphtype = this.graphtype;
33344 var r = this.raphael,
33345 fin = function () {
33346 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
33348 fout = function () {
33349 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
33351 pfin = function() {
33352 this.sector.stop();
33353 this.sector.scale(1.1, 1.1, this.cx, this.cy);
33356 this.label[0].stop();
33357 this.label[0].attr({ r: 7.5 });
33358 this.label[1].attr({ "font-weight": 800 });
33361 pfout = function() {
33362 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
33365 this.label[0].animate({ r: 5 }, 500, "bounce");
33366 this.label[1].attr({ "font-weight": 400 });
33372 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
33375 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
33378 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
33379 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
33381 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
33388 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
33393 setTitle: function(o)
33398 initEvents: function() {
33401 this.el.on('click', this.onClick, this);
33405 onClick : function(e)
33407 Roo.log('img onclick');
33408 this.fireEvent('click', this, e);
33414 Roo.bootstrap.dash = {};/*
33420 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
33423 * @class Roo.bootstrap.dash.NumberBox
33424 * @extends Roo.bootstrap.Component
33425 * Bootstrap NumberBox class
33426 * @cfg {String} headline Box headline
33427 * @cfg {String} content Box content
33428 * @cfg {String} icon Box icon
33429 * @cfg {String} footer Footer text
33430 * @cfg {String} fhref Footer href
33433 * Create a new NumberBox
33434 * @param {Object} config The config object
33438 Roo.bootstrap.dash.NumberBox = function(config){
33439 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
33443 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
33452 getAutoCreate : function(){
33456 cls : 'small-box ',
33464 cls : 'roo-headline',
33465 html : this.headline
33469 cls : 'roo-content',
33470 html : this.content
33484 cls : 'ion ' + this.icon
33493 cls : 'small-box-footer',
33494 href : this.fhref || '#',
33498 cfg.cn.push(footer);
33505 onRender : function(ct,position){
33506 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
33513 setHeadline: function (value)
33515 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
33518 setFooter: function (value, href)
33520 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
33523 this.el.select('a.small-box-footer',true).first().attr('href', href);
33528 setContent: function (value)
33530 this.el.select('.roo-content',true).first().dom.innerHTML = value;
33533 initEvents: function()
33547 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
33550 * @class Roo.bootstrap.dash.TabBox
33551 * @extends Roo.bootstrap.Component
33552 * @children Roo.bootstrap.dash.TabPane
33553 * Bootstrap TabBox class
33554 * @cfg {String} title Title of the TabBox
33555 * @cfg {String} icon Icon of the TabBox
33556 * @cfg {Boolean} showtabs (true|false) show the tabs default true
33557 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
33560 * Create a new TabBox
33561 * @param {Object} config The config object
33565 Roo.bootstrap.dash.TabBox = function(config){
33566 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
33571 * When a pane is added
33572 * @param {Roo.bootstrap.dash.TabPane} pane
33576 * @event activatepane
33577 * When a pane is activated
33578 * @param {Roo.bootstrap.dash.TabPane} pane
33580 "activatepane" : true
33588 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
33593 tabScrollable : false,
33595 getChildContainer : function()
33597 return this.el.select('.tab-content', true).first();
33600 getAutoCreate : function(){
33604 cls: 'pull-left header',
33612 cls: 'fa ' + this.icon
33618 cls: 'nav nav-tabs pull-right',
33624 if(this.tabScrollable){
33631 cls: 'nav nav-tabs pull-right',
33642 cls: 'nav-tabs-custom',
33647 cls: 'tab-content no-padding',
33655 initEvents : function()
33657 //Roo.log('add add pane handler');
33658 this.on('addpane', this.onAddPane, this);
33661 * Updates the box title
33662 * @param {String} html to set the title to.
33664 setTitle : function(value)
33666 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
33668 onAddPane : function(pane)
33670 this.panes.push(pane);
33671 //Roo.log('addpane');
33673 // tabs are rendere left to right..
33674 if(!this.showtabs){
33678 var ctr = this.el.select('.nav-tabs', true).first();
33681 var existing = ctr.select('.nav-tab',true);
33682 var qty = existing.getCount();;
33685 var tab = ctr.createChild({
33687 cls : 'nav-tab' + (qty ? '' : ' active'),
33695 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
33698 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
33700 pane.el.addClass('active');
33705 onTabClick : function(ev,un,ob,pane)
33707 //Roo.log('tab - prev default');
33708 ev.preventDefault();
33711 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
33712 pane.tab.addClass('active');
33713 //Roo.log(pane.title);
33714 this.getChildContainer().select('.tab-pane',true).removeClass('active');
33715 // technically we should have a deactivate event.. but maybe add later.
33716 // and it should not de-activate the selected tab...
33717 this.fireEvent('activatepane', pane);
33718 pane.el.addClass('active');
33719 pane.fireEvent('activate');
33724 getActivePane : function()
33727 Roo.each(this.panes, function(p) {
33728 if(p.el.hasClass('active')){
33749 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
33751 * @class Roo.bootstrap.TabPane
33752 * @extends Roo.bootstrap.Component
33753 * @children Roo.bootstrap.Graph Roo.bootstrap.Column
33754 * Bootstrap TabPane class
33755 * @cfg {Boolean} active (false | true) Default false
33756 * @cfg {String} title title of panel
33760 * Create a new TabPane
33761 * @param {Object} config The config object
33764 Roo.bootstrap.dash.TabPane = function(config){
33765 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
33771 * When a pane is activated
33772 * @param {Roo.bootstrap.dash.TabPane} pane
33779 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
33784 // the tabBox that this is attached to.
33787 getAutoCreate : function()
33795 cfg.cls += ' active';
33800 initEvents : function()
33802 //Roo.log('trigger add pane handler');
33803 this.parent().fireEvent('addpane', this)
33807 * Updates the tab title
33808 * @param {String} html to set the title to.
33810 setTitle: function(str)
33816 this.tab.select('a', true).first().dom.innerHTML = str;
33835 * @class Roo.bootstrap.Tooltip
33836 * Bootstrap Tooltip class
33837 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
33838 * to determine which dom element triggers the tooltip.
33840 * It needs to add support for additional attributes like tooltip-position
33843 * Create a new Toolti
33844 * @param {Object} config The config object
33847 Roo.bootstrap.Tooltip = function(config){
33848 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
33850 this.alignment = Roo.bootstrap.Tooltip.alignment;
33852 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
33853 this.alignment = config.alignment;
33858 Roo.apply(Roo.bootstrap.Tooltip, {
33860 * @function init initialize tooltip monitoring.
33864 currentTip : false,
33865 currentRegion : false,
33871 Roo.get(document).on('mouseover', this.enter ,this);
33872 Roo.get(document).on('mouseout', this.leave, this);
33875 this.currentTip = new Roo.bootstrap.Tooltip();
33878 enter : function(ev)
33880 var dom = ev.getTarget();
33882 //Roo.log(['enter',dom]);
33883 var el = Roo.fly(dom);
33884 if (this.currentEl) {
33886 //Roo.log(this.currentEl);
33887 //Roo.log(this.currentEl.contains(dom));
33888 if (this.currentEl == el) {
33891 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
33897 if (this.currentTip.el) {
33898 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
33902 if(!el || el.dom == document){
33908 if (!el.attr('tooltip')) {
33909 pel = el.findParent("[tooltip]");
33911 bindEl = Roo.get(pel);
33917 // you can not look for children, as if el is the body.. then everythign is the child..
33918 if (!pel && !el.attr('tooltip')) { //
33919 if (!el.select("[tooltip]").elements.length) {
33922 // is the mouse over this child...?
33923 bindEl = el.select("[tooltip]").first();
33924 var xy = ev.getXY();
33925 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
33926 //Roo.log("not in region.");
33929 //Roo.log("child element over..");
33932 this.currentEl = el;
33933 this.currentTip.bind(bindEl);
33934 this.currentRegion = Roo.lib.Region.getRegion(dom);
33935 this.currentTip.enter();
33938 leave : function(ev)
33940 var dom = ev.getTarget();
33941 //Roo.log(['leave',dom]);
33942 if (!this.currentEl) {
33947 if (dom != this.currentEl.dom) {
33950 var xy = ev.getXY();
33951 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
33954 // only activate leave if mouse cursor is outside... bounding box..
33959 if (this.currentTip) {
33960 this.currentTip.leave();
33962 //Roo.log('clear currentEl');
33963 this.currentEl = false;
33968 'left' : ['r-l', [-2,0], 'right'],
33969 'right' : ['l-r', [2,0], 'left'],
33970 'bottom' : ['t-b', [0,2], 'top'],
33971 'top' : [ 'b-t', [0,-2], 'bottom']
33977 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
33982 delay : null, // can be { show : 300 , hide: 500}
33986 hoverState : null, //???
33988 placement : 'bottom',
33992 getAutoCreate : function(){
33999 cls : 'tooltip-arrow arrow'
34002 cls : 'tooltip-inner'
34009 bind : function(el)
34014 initEvents : function()
34016 this.arrowEl = this.el.select('.arrow', true).first();
34017 this.innerEl = this.el.select('.tooltip-inner', true).first();
34020 enter : function () {
34022 if (this.timeout != null) {
34023 clearTimeout(this.timeout);
34026 this.hoverState = 'in';
34027 //Roo.log("enter - show");
34028 if (!this.delay || !this.delay.show) {
34033 this.timeout = setTimeout(function () {
34034 if (_t.hoverState == 'in') {
34037 }, this.delay.show);
34041 clearTimeout(this.timeout);
34043 this.hoverState = 'out';
34044 if (!this.delay || !this.delay.hide) {
34050 this.timeout = setTimeout(function () {
34051 //Roo.log("leave - timeout");
34053 if (_t.hoverState == 'out') {
34055 Roo.bootstrap.Tooltip.currentEl = false;
34060 show : function (msg)
34063 this.render(document.body);
34066 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
34068 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
34070 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
34072 this.el.removeClass(['fade','top','bottom', 'left', 'right','in',
34073 'bs-tooltip-top','bs-tooltip-bottom', 'bs-tooltip-left', 'bs-tooltip-right']);
34075 if(this.bindEl.attr('tooltip-class')) {
34076 this.el.addClass(this.bindEl.attr('tooltip-class'));
34079 var placement = typeof this.placement == 'function' ?
34080 this.placement.call(this, this.el, on_el) :
34083 if(this.bindEl.attr('tooltip-placement')) {
34084 placement = this.bindEl.attr('tooltip-placement');
34087 var autoToken = /\s?auto?\s?/i;
34088 var autoPlace = autoToken.test(placement);
34090 placement = placement.replace(autoToken, '') || 'top';
34094 //this.el.setXY([0,0]);
34096 //this.el.dom.style.display='block';
34098 //this.el.appendTo(on_el);
34100 var p = this.getPosition();
34101 var box = this.el.getBox();
34107 var align = this.alignment[placement];
34109 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
34111 if(placement == 'top' || placement == 'bottom'){
34113 placement = 'right';
34116 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
34117 placement = 'left';
34120 var scroll = Roo.select('body', true).first().getScroll();
34122 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
34126 align = this.alignment[placement];
34128 this.arrowEl.setLeft((this.innerEl.getWidth()/2) - 5);
34132 var elems = document.getElementsByTagName('div');
34133 var highest = Number.MIN_SAFE_INTEGER || -(Math.pow(2, 53) - 1);
34134 for (var i = 0; i < elems.length; i++) {
34135 var zindex = Number.parseInt(
34136 document.defaultView.getComputedStyle(elems[i], null).getPropertyValue("z-index"),
34139 if (zindex > highest) {
34146 this.el.dom.style.zIndex = highest;
34148 this.el.alignTo(this.bindEl, align[0],align[1]);
34149 //var arrow = this.el.select('.arrow',true).first();
34150 //arrow.set(align[2],
34152 this.el.addClass(placement);
34153 this.el.addClass("bs-tooltip-"+ placement);
34155 this.el.addClass('in fade show');
34157 this.hoverState = null;
34159 if (this.el.hasClass('fade')) {
34174 //this.el.setXY([0,0]);
34175 if(this.bindEl.attr('tooltip-class')) {
34176 this.el.removeClass(this.bindEl.attr('tooltip-class'));
34178 this.el.removeClass(['show', 'in']);
34194 * @class Roo.bootstrap.LocationPicker
34195 * @extends Roo.bootstrap.Component
34196 * Bootstrap LocationPicker class
34197 * @cfg {Number} latitude Position when init default 0
34198 * @cfg {Number} longitude Position when init default 0
34199 * @cfg {Number} zoom default 15
34200 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
34201 * @cfg {Boolean} mapTypeControl default false
34202 * @cfg {Boolean} disableDoubleClickZoom default false
34203 * @cfg {Boolean} scrollwheel default true
34204 * @cfg {Boolean} streetViewControl default false
34205 * @cfg {Number} radius default 0
34206 * @cfg {String} locationName
34207 * @cfg {Boolean} draggable default true
34208 * @cfg {Boolean} enableAutocomplete default false
34209 * @cfg {Boolean} enableReverseGeocode default true
34210 * @cfg {String} markerTitle
34213 * Create a new LocationPicker
34214 * @param {Object} config The config object
34218 Roo.bootstrap.LocationPicker = function(config){
34220 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
34225 * Fires when the picker initialized.
34226 * @param {Roo.bootstrap.LocationPicker} this
34227 * @param {Google Location} location
34231 * @event positionchanged
34232 * Fires when the picker position changed.
34233 * @param {Roo.bootstrap.LocationPicker} this
34234 * @param {Google Location} location
34236 positionchanged : true,
34239 * Fires when the map resize.
34240 * @param {Roo.bootstrap.LocationPicker} this
34245 * Fires when the map show.
34246 * @param {Roo.bootstrap.LocationPicker} this
34251 * Fires when the map hide.
34252 * @param {Roo.bootstrap.LocationPicker} this
34257 * Fires when click the map.
34258 * @param {Roo.bootstrap.LocationPicker} this
34259 * @param {Map event} e
34263 * @event mapRightClick
34264 * Fires when right click the map.
34265 * @param {Roo.bootstrap.LocationPicker} this
34266 * @param {Map event} e
34268 mapRightClick : true,
34270 * @event markerClick
34271 * Fires when click the marker.
34272 * @param {Roo.bootstrap.LocationPicker} this
34273 * @param {Map event} e
34275 markerClick : true,
34277 * @event markerRightClick
34278 * Fires when right click the marker.
34279 * @param {Roo.bootstrap.LocationPicker} this
34280 * @param {Map event} e
34282 markerRightClick : true,
34284 * @event OverlayViewDraw
34285 * Fires when OverlayView Draw
34286 * @param {Roo.bootstrap.LocationPicker} this
34288 OverlayViewDraw : true,
34290 * @event OverlayViewOnAdd
34291 * Fires when OverlayView Draw
34292 * @param {Roo.bootstrap.LocationPicker} this
34294 OverlayViewOnAdd : true,
34296 * @event OverlayViewOnRemove
34297 * Fires when OverlayView Draw
34298 * @param {Roo.bootstrap.LocationPicker} this
34300 OverlayViewOnRemove : true,
34302 * @event OverlayViewShow
34303 * Fires when OverlayView Draw
34304 * @param {Roo.bootstrap.LocationPicker} this
34305 * @param {Pixel} cpx
34307 OverlayViewShow : true,
34309 * @event OverlayViewHide
34310 * Fires when OverlayView Draw
34311 * @param {Roo.bootstrap.LocationPicker} this
34313 OverlayViewHide : true,
34315 * @event loadexception
34316 * Fires when load google lib failed.
34317 * @param {Roo.bootstrap.LocationPicker} this
34319 loadexception : true
34324 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
34326 gMapContext: false,
34332 mapTypeControl: false,
34333 disableDoubleClickZoom: false,
34335 streetViewControl: false,
34339 enableAutocomplete: false,
34340 enableReverseGeocode: true,
34343 getAutoCreate: function()
34348 cls: 'roo-location-picker'
34354 initEvents: function(ct, position)
34356 if(!this.el.getWidth() || this.isApplied()){
34360 this.el.setVisibilityMode(Roo.Element.DISPLAY);
34365 initial: function()
34367 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
34368 this.fireEvent('loadexception', this);
34372 if(!this.mapTypeId){
34373 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
34376 this.gMapContext = this.GMapContext();
34378 this.initOverlayView();
34380 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
34384 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
34385 _this.setPosition(_this.gMapContext.marker.position);
34388 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
34389 _this.fireEvent('mapClick', this, event);
34393 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
34394 _this.fireEvent('mapRightClick', this, event);
34398 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
34399 _this.fireEvent('markerClick', this, event);
34403 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
34404 _this.fireEvent('markerRightClick', this, event);
34408 this.setPosition(this.gMapContext.location);
34410 this.fireEvent('initial', this, this.gMapContext.location);
34413 initOverlayView: function()
34417 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
34421 _this.fireEvent('OverlayViewDraw', _this);
34426 _this.fireEvent('OverlayViewOnAdd', _this);
34429 onRemove: function()
34431 _this.fireEvent('OverlayViewOnRemove', _this);
34434 show: function(cpx)
34436 _this.fireEvent('OverlayViewShow', _this, cpx);
34441 _this.fireEvent('OverlayViewHide', _this);
34447 fromLatLngToContainerPixel: function(event)
34449 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
34452 isApplied: function()
34454 return this.getGmapContext() == false ? false : true;
34457 getGmapContext: function()
34459 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
34462 GMapContext: function()
34464 var position = new google.maps.LatLng(this.latitude, this.longitude);
34466 var _map = new google.maps.Map(this.el.dom, {
34469 mapTypeId: this.mapTypeId,
34470 mapTypeControl: this.mapTypeControl,
34471 disableDoubleClickZoom: this.disableDoubleClickZoom,
34472 scrollwheel: this.scrollwheel,
34473 streetViewControl: this.streetViewControl,
34474 locationName: this.locationName,
34475 draggable: this.draggable,
34476 enableAutocomplete: this.enableAutocomplete,
34477 enableReverseGeocode: this.enableReverseGeocode
34480 var _marker = new google.maps.Marker({
34481 position: position,
34483 title: this.markerTitle,
34484 draggable: this.draggable
34491 location: position,
34492 radius: this.radius,
34493 locationName: this.locationName,
34494 addressComponents: {
34495 formatted_address: null,
34496 addressLine1: null,
34497 addressLine2: null,
34499 streetNumber: null,
34503 stateOrProvince: null
34506 domContainer: this.el.dom,
34507 geodecoder: new google.maps.Geocoder()
34511 drawCircle: function(center, radius, options)
34513 if (this.gMapContext.circle != null) {
34514 this.gMapContext.circle.setMap(null);
34518 options = Roo.apply({}, options, {
34519 strokeColor: "#0000FF",
34520 strokeOpacity: .35,
34522 fillColor: "#0000FF",
34526 options.map = this.gMapContext.map;
34527 options.radius = radius;
34528 options.center = center;
34529 this.gMapContext.circle = new google.maps.Circle(options);
34530 return this.gMapContext.circle;
34536 setPosition: function(location)
34538 this.gMapContext.location = location;
34539 this.gMapContext.marker.setPosition(location);
34540 this.gMapContext.map.panTo(location);
34541 this.drawCircle(location, this.gMapContext.radius, {});
34545 if (this.gMapContext.settings.enableReverseGeocode) {
34546 this.gMapContext.geodecoder.geocode({
34547 latLng: this.gMapContext.location
34548 }, function(results, status) {
34550 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
34551 _this.gMapContext.locationName = results[0].formatted_address;
34552 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
34554 _this.fireEvent('positionchanged', this, location);
34561 this.fireEvent('positionchanged', this, location);
34566 google.maps.event.trigger(this.gMapContext.map, "resize");
34568 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
34570 this.fireEvent('resize', this);
34573 setPositionByLatLng: function(latitude, longitude)
34575 this.setPosition(new google.maps.LatLng(latitude, longitude));
34578 getCurrentPosition: function()
34581 latitude: this.gMapContext.location.lat(),
34582 longitude: this.gMapContext.location.lng()
34586 getAddressName: function()
34588 return this.gMapContext.locationName;
34591 getAddressComponents: function()
34593 return this.gMapContext.addressComponents;
34596 address_component_from_google_geocode: function(address_components)
34600 for (var i = 0; i < address_components.length; i++) {
34601 var component = address_components[i];
34602 if (component.types.indexOf("postal_code") >= 0) {
34603 result.postalCode = component.short_name;
34604 } else if (component.types.indexOf("street_number") >= 0) {
34605 result.streetNumber = component.short_name;
34606 } else if (component.types.indexOf("route") >= 0) {
34607 result.streetName = component.short_name;
34608 } else if (component.types.indexOf("neighborhood") >= 0) {
34609 result.city = component.short_name;
34610 } else if (component.types.indexOf("locality") >= 0) {
34611 result.city = component.short_name;
34612 } else if (component.types.indexOf("sublocality") >= 0) {
34613 result.district = component.short_name;
34614 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
34615 result.stateOrProvince = component.short_name;
34616 } else if (component.types.indexOf("country") >= 0) {
34617 result.country = component.short_name;
34621 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
34622 result.addressLine2 = "";
34626 setZoomLevel: function(zoom)
34628 this.gMapContext.map.setZoom(zoom);
34641 this.fireEvent('show', this);
34652 this.fireEvent('hide', this);
34657 Roo.apply(Roo.bootstrap.LocationPicker, {
34659 OverlayView : function(map, options)
34661 options = options || {};
34668 * @class Roo.bootstrap.Alert
34669 * @extends Roo.bootstrap.Component
34670 * Bootstrap Alert class - shows an alert area box
34672 * <div class="alert alert-danger" role="alert"><span class="fa fa-exclamation-triangle"></span><span class="sr-only">Error:</span>
34673 Enter a valid email address
34676 * @cfg {String} title The title of alert
34677 * @cfg {String} html The content of alert
34678 * @cfg {String} weight (success|info|warning|danger) Weight of the message
34679 * @cfg {String} fa font-awesomeicon
34680 * @cfg {Number} seconds default:-1 Number of seconds until it disapears (-1 means never.)
34681 * @cfg {Boolean} close true to show a x closer
34685 * Create a new alert
34686 * @param {Object} config The config object
34690 Roo.bootstrap.Alert = function(config){
34691 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
34695 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
34701 faicon: false, // BC
34705 getAutoCreate : function()
34717 style : this.close ? '' : 'display:none'
34721 cls : 'roo-alert-icon'
34726 cls : 'roo-alert-title',
34731 cls : 'roo-alert-text',
34738 cfg.cn[0].cls += ' fa ' + this.faicon;
34741 cfg.cn[0].cls += ' fa ' + this.fa;
34745 cfg.cls += ' alert-' + this.weight;
34751 initEvents: function()
34753 this.el.setVisibilityMode(Roo.Element.DISPLAY);
34754 this.titleEl = this.el.select('.roo-alert-title',true).first();
34755 this.iconEl = this.el.select('.roo-alert-icon',true).first();
34756 this.htmlEl = this.el.select('.roo-alert-text',true).first();
34757 if (this.seconds > 0) {
34758 this.hide.defer(this.seconds, this);
34762 * Set the Title Message HTML
34763 * @param {String} html
34765 setTitle : function(str)
34767 this.titleEl.dom.innerHTML = str;
34771 * Set the Body Message HTML
34772 * @param {String} html
34774 setHtml : function(str)
34776 this.htmlEl.dom.innerHTML = str;
34779 * Set the Weight of the alert
34780 * @param {String} (success|info|warning|danger) weight
34783 setWeight : function(weight)
34786 this.el.removeClass('alert-' + this.weight);
34789 this.weight = weight;
34791 this.el.addClass('alert-' + this.weight);
34794 * Set the Icon of the alert
34795 * @param {String} see fontawsome names (name without the 'fa-' bit)
34797 setIcon : function(icon)
34800 this.alertEl.removeClass(['fa', 'fa-' + this.faicon]);
34803 this.faicon = icon;
34805 this.alertEl.addClass(['fa', 'fa-' + this.faicon]);
34830 * @class Roo.bootstrap.UploadCropbox
34831 * @extends Roo.bootstrap.Component
34832 * Bootstrap UploadCropbox class
34833 * @cfg {String} emptyText show when image has been loaded
34834 * @cfg {String} rotateNotify show when image too small to rotate
34835 * @cfg {Number} errorTimeout default 3000
34836 * @cfg {Number} minWidth default 300
34837 * @cfg {Number} minHeight default 300
34838 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
34839 * @cfg {Boolean} isDocument (true|false) default false
34840 * @cfg {String} url action url
34841 * @cfg {String} paramName default 'imageUpload'
34842 * @cfg {String} method default POST
34843 * @cfg {Boolean} loadMask (true|false) default true
34844 * @cfg {Boolean} loadingText default 'Loading...'
34847 * Create a new UploadCropbox
34848 * @param {Object} config The config object
34851 Roo.bootstrap.UploadCropbox = function(config){
34852 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
34856 * @event beforeselectfile
34857 * Fire before select file
34858 * @param {Roo.bootstrap.UploadCropbox} this
34860 "beforeselectfile" : true,
34863 * Fire after initEvent
34864 * @param {Roo.bootstrap.UploadCropbox} this
34869 * Fire after initEvent
34870 * @param {Roo.bootstrap.UploadCropbox} this
34871 * @param {String} data
34876 * Fire when preparing the file data
34877 * @param {Roo.bootstrap.UploadCropbox} this
34878 * @param {Object} file
34883 * Fire when get exception
34884 * @param {Roo.bootstrap.UploadCropbox} this
34885 * @param {XMLHttpRequest} xhr
34887 "exception" : true,
34889 * @event beforeloadcanvas
34890 * Fire before load the canvas
34891 * @param {Roo.bootstrap.UploadCropbox} this
34892 * @param {String} src
34894 "beforeloadcanvas" : true,
34897 * Fire when trash image
34898 * @param {Roo.bootstrap.UploadCropbox} this
34903 * Fire when download the image
34904 * @param {Roo.bootstrap.UploadCropbox} this
34908 * @event footerbuttonclick
34909 * Fire when footerbuttonclick
34910 * @param {Roo.bootstrap.UploadCropbox} this
34911 * @param {String} type
34913 "footerbuttonclick" : true,
34917 * @param {Roo.bootstrap.UploadCropbox} this
34922 * Fire when rotate the image
34923 * @param {Roo.bootstrap.UploadCropbox} this
34924 * @param {String} pos
34929 * Fire when inspect the file
34930 * @param {Roo.bootstrap.UploadCropbox} this
34931 * @param {Object} file
34936 * Fire when xhr upload the file
34937 * @param {Roo.bootstrap.UploadCropbox} this
34938 * @param {Object} data
34943 * Fire when arrange the file data
34944 * @param {Roo.bootstrap.UploadCropbox} this
34945 * @param {Object} formData
34950 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
34953 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
34955 emptyText : 'Click to upload image',
34956 rotateNotify : 'Image is too small to rotate',
34957 errorTimeout : 3000,
34971 cropType : 'image/jpeg',
34973 canvasLoaded : false,
34974 isDocument : false,
34976 paramName : 'imageUpload',
34978 loadingText : 'Loading...',
34981 getAutoCreate : function()
34985 cls : 'roo-upload-cropbox',
34989 cls : 'roo-upload-cropbox-selector',
34994 cls : 'roo-upload-cropbox-body',
34995 style : 'cursor:pointer',
34999 cls : 'roo-upload-cropbox-preview'
35003 cls : 'roo-upload-cropbox-thumb'
35007 cls : 'roo-upload-cropbox-empty-notify',
35008 html : this.emptyText
35012 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
35013 html : this.rotateNotify
35019 cls : 'roo-upload-cropbox-footer',
35022 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
35032 onRender : function(ct, position)
35034 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
35036 if (this.buttons.length) {
35038 Roo.each(this.buttons, function(bb) {
35040 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
35042 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
35048 this.maskEl = this.el;
35052 initEvents : function()
35054 this.urlAPI = (window.createObjectURL && window) ||
35055 (window.URL && URL.revokeObjectURL && URL) ||
35056 (window.webkitURL && webkitURL);
35058 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
35059 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35061 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
35062 this.selectorEl.hide();
35064 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
35065 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35067 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
35068 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35069 this.thumbEl.hide();
35071 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
35072 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35074 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
35075 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35076 this.errorEl.hide();
35078 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
35079 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35080 this.footerEl.hide();
35082 this.setThumbBoxSize();
35088 this.fireEvent('initial', this);
35095 window.addEventListener("resize", function() { _this.resize(); } );
35097 this.bodyEl.on('click', this.beforeSelectFile, this);
35100 this.bodyEl.on('touchstart', this.onTouchStart, this);
35101 this.bodyEl.on('touchmove', this.onTouchMove, this);
35102 this.bodyEl.on('touchend', this.onTouchEnd, this);
35106 this.bodyEl.on('mousedown', this.onMouseDown, this);
35107 this.bodyEl.on('mousemove', this.onMouseMove, this);
35108 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
35109 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
35110 Roo.get(document).on('mouseup', this.onMouseUp, this);
35113 this.selectorEl.on('change', this.onFileSelected, this);
35119 this.baseScale = 1;
35121 this.baseRotate = 1;
35122 this.dragable = false;
35123 this.pinching = false;
35126 this.cropData = false;
35127 this.notifyEl.dom.innerHTML = this.emptyText;
35129 this.selectorEl.dom.value = '';
35133 resize : function()
35135 if(this.fireEvent('resize', this) != false){
35136 this.setThumbBoxPosition();
35137 this.setCanvasPosition();
35141 onFooterButtonClick : function(e, el, o, type)
35144 case 'rotate-left' :
35145 this.onRotateLeft(e);
35147 case 'rotate-right' :
35148 this.onRotateRight(e);
35151 this.beforeSelectFile(e);
35166 this.fireEvent('footerbuttonclick', this, type);
35169 beforeSelectFile : function(e)
35171 e.preventDefault();
35173 if(this.fireEvent('beforeselectfile', this) != false){
35174 this.selectorEl.dom.click();
35178 onFileSelected : function(e)
35180 e.preventDefault();
35182 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
35186 var file = this.selectorEl.dom.files[0];
35188 if(this.fireEvent('inspect', this, file) != false){
35189 this.prepare(file);
35194 trash : function(e)
35196 this.fireEvent('trash', this);
35199 download : function(e)
35201 this.fireEvent('download', this);
35204 loadCanvas : function(src)
35206 if(this.fireEvent('beforeloadcanvas', this, src) != false){
35210 this.imageEl = document.createElement('img');
35214 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
35216 this.imageEl.src = src;
35220 onLoadCanvas : function()
35222 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
35223 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
35225 this.bodyEl.un('click', this.beforeSelectFile, this);
35227 this.notifyEl.hide();
35228 this.thumbEl.show();
35229 this.footerEl.show();
35231 this.baseRotateLevel();
35233 if(this.isDocument){
35234 this.setThumbBoxSize();
35237 this.setThumbBoxPosition();
35239 this.baseScaleLevel();
35245 this.canvasLoaded = true;
35248 this.maskEl.unmask();
35253 setCanvasPosition : function()
35255 if(!this.canvasEl){
35259 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
35260 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
35262 this.previewEl.setLeft(pw);
35263 this.previewEl.setTop(ph);
35267 onMouseDown : function(e)
35271 this.dragable = true;
35272 this.pinching = false;
35274 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
35275 this.dragable = false;
35279 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
35280 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
35284 onMouseMove : function(e)
35288 if(!this.canvasLoaded){
35292 if (!this.dragable){
35296 var minX = Math.ceil(this.thumbEl.getLeft(true));
35297 var minY = Math.ceil(this.thumbEl.getTop(true));
35299 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
35300 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
35302 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
35303 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
35305 x = x - this.mouseX;
35306 y = y - this.mouseY;
35308 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
35309 var bgY = Math.ceil(y + this.previewEl.getTop(true));
35311 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
35312 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
35314 this.previewEl.setLeft(bgX);
35315 this.previewEl.setTop(bgY);
35317 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
35318 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
35321 onMouseUp : function(e)
35325 this.dragable = false;
35328 onMouseWheel : function(e)
35332 this.startScale = this.scale;
35334 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
35336 if(!this.zoomable()){
35337 this.scale = this.startScale;
35346 zoomable : function()
35348 var minScale = this.thumbEl.getWidth() / this.minWidth;
35350 if(this.minWidth < this.minHeight){
35351 minScale = this.thumbEl.getHeight() / this.minHeight;
35354 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
35355 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
35359 (this.rotate == 0 || this.rotate == 180) &&
35361 width > this.imageEl.OriginWidth ||
35362 height > this.imageEl.OriginHeight ||
35363 (width < this.minWidth && height < this.minHeight)
35371 (this.rotate == 90 || this.rotate == 270) &&
35373 width > this.imageEl.OriginWidth ||
35374 height > this.imageEl.OriginHeight ||
35375 (width < this.minHeight && height < this.minWidth)
35382 !this.isDocument &&
35383 (this.rotate == 0 || this.rotate == 180) &&
35385 width < this.minWidth ||
35386 width > this.imageEl.OriginWidth ||
35387 height < this.minHeight ||
35388 height > this.imageEl.OriginHeight
35395 !this.isDocument &&
35396 (this.rotate == 90 || this.rotate == 270) &&
35398 width < this.minHeight ||
35399 width > this.imageEl.OriginWidth ||
35400 height < this.minWidth ||
35401 height > this.imageEl.OriginHeight
35411 onRotateLeft : function(e)
35413 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
35415 var minScale = this.thumbEl.getWidth() / this.minWidth;
35417 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
35418 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
35420 this.startScale = this.scale;
35422 while (this.getScaleLevel() < minScale){
35424 this.scale = this.scale + 1;
35426 if(!this.zoomable()){
35431 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
35432 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
35437 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
35444 this.scale = this.startScale;
35446 this.onRotateFail();
35451 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
35453 if(this.isDocument){
35454 this.setThumbBoxSize();
35455 this.setThumbBoxPosition();
35456 this.setCanvasPosition();
35461 this.fireEvent('rotate', this, 'left');
35465 onRotateRight : function(e)
35467 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
35469 var minScale = this.thumbEl.getWidth() / this.minWidth;
35471 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
35472 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
35474 this.startScale = this.scale;
35476 while (this.getScaleLevel() < minScale){
35478 this.scale = this.scale + 1;
35480 if(!this.zoomable()){
35485 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
35486 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
35491 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
35498 this.scale = this.startScale;
35500 this.onRotateFail();
35505 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
35507 if(this.isDocument){
35508 this.setThumbBoxSize();
35509 this.setThumbBoxPosition();
35510 this.setCanvasPosition();
35515 this.fireEvent('rotate', this, 'right');
35518 onRotateFail : function()
35520 this.errorEl.show(true);
35524 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
35529 this.previewEl.dom.innerHTML = '';
35531 var canvasEl = document.createElement("canvas");
35533 var contextEl = canvasEl.getContext("2d");
35535 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
35536 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
35537 var center = this.imageEl.OriginWidth / 2;
35539 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
35540 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
35541 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
35542 center = this.imageEl.OriginHeight / 2;
35545 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
35547 contextEl.translate(center, center);
35548 contextEl.rotate(this.rotate * Math.PI / 180);
35550 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
35552 this.canvasEl = document.createElement("canvas");
35554 this.contextEl = this.canvasEl.getContext("2d");
35556 switch (this.rotate) {
35559 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
35560 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
35562 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35567 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
35568 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
35570 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35571 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35575 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35580 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
35581 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
35583 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35584 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35588 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35593 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
35594 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
35596 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35597 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35601 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35608 this.previewEl.appendChild(this.canvasEl);
35610 this.setCanvasPosition();
35615 if(!this.canvasLoaded){
35619 var imageCanvas = document.createElement("canvas");
35621 var imageContext = imageCanvas.getContext("2d");
35623 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
35624 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
35626 var center = imageCanvas.width / 2;
35628 imageContext.translate(center, center);
35630 imageContext.rotate(this.rotate * Math.PI / 180);
35632 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
35634 var canvas = document.createElement("canvas");
35636 var context = canvas.getContext("2d");
35638 canvas.width = this.minWidth;
35639 canvas.height = this.minHeight;
35641 switch (this.rotate) {
35644 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
35645 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
35647 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35648 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35650 var targetWidth = this.minWidth - 2 * x;
35651 var targetHeight = this.minHeight - 2 * y;
35655 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35656 scale = targetWidth / width;
35659 if(x > 0 && y == 0){
35660 scale = targetHeight / height;
35663 if(x > 0 && y > 0){
35664 scale = targetWidth / width;
35666 if(width < height){
35667 scale = targetHeight / height;
35671 context.scale(scale, scale);
35673 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35674 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35676 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35677 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35679 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35684 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
35685 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
35687 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35688 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35690 var targetWidth = this.minWidth - 2 * x;
35691 var targetHeight = this.minHeight - 2 * y;
35695 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35696 scale = targetWidth / width;
35699 if(x > 0 && y == 0){
35700 scale = targetHeight / height;
35703 if(x > 0 && y > 0){
35704 scale = targetWidth / width;
35706 if(width < height){
35707 scale = targetHeight / height;
35711 context.scale(scale, scale);
35713 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35714 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35716 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35717 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35719 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
35721 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35726 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
35727 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
35729 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35730 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35732 var targetWidth = this.minWidth - 2 * x;
35733 var targetHeight = this.minHeight - 2 * y;
35737 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35738 scale = targetWidth / width;
35741 if(x > 0 && y == 0){
35742 scale = targetHeight / height;
35745 if(x > 0 && y > 0){
35746 scale = targetWidth / width;
35748 if(width < height){
35749 scale = targetHeight / height;
35753 context.scale(scale, scale);
35755 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35756 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35758 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35759 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35761 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
35762 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
35764 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35769 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
35770 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
35772 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35773 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35775 var targetWidth = this.minWidth - 2 * x;
35776 var targetHeight = this.minHeight - 2 * y;
35780 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35781 scale = targetWidth / width;
35784 if(x > 0 && y == 0){
35785 scale = targetHeight / height;
35788 if(x > 0 && y > 0){
35789 scale = targetWidth / width;
35791 if(width < height){
35792 scale = targetHeight / height;
35796 context.scale(scale, scale);
35798 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35799 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35801 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35802 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35804 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
35806 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35813 this.cropData = canvas.toDataURL(this.cropType);
35815 if(this.fireEvent('crop', this, this.cropData) !== false){
35816 this.process(this.file, this.cropData);
35823 setThumbBoxSize : function()
35827 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
35828 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
35829 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
35831 this.minWidth = width;
35832 this.minHeight = height;
35834 if(this.rotate == 90 || this.rotate == 270){
35835 this.minWidth = height;
35836 this.minHeight = width;
35841 width = Math.ceil(this.minWidth * height / this.minHeight);
35843 if(this.minWidth > this.minHeight){
35845 height = Math.ceil(this.minHeight * width / this.minWidth);
35848 this.thumbEl.setStyle({
35849 width : width + 'px',
35850 height : height + 'px'
35857 setThumbBoxPosition : function()
35859 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
35860 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
35862 this.thumbEl.setLeft(x);
35863 this.thumbEl.setTop(y);
35867 baseRotateLevel : function()
35869 this.baseRotate = 1;
35872 typeof(this.exif) != 'undefined' &&
35873 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
35874 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
35876 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
35879 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
35883 baseScaleLevel : function()
35887 if(this.isDocument){
35889 if(this.baseRotate == 6 || this.baseRotate == 8){
35891 height = this.thumbEl.getHeight();
35892 this.baseScale = height / this.imageEl.OriginWidth;
35894 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
35895 width = this.thumbEl.getWidth();
35896 this.baseScale = width / this.imageEl.OriginHeight;
35902 height = this.thumbEl.getHeight();
35903 this.baseScale = height / this.imageEl.OriginHeight;
35905 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
35906 width = this.thumbEl.getWidth();
35907 this.baseScale = width / this.imageEl.OriginWidth;
35913 if(this.baseRotate == 6 || this.baseRotate == 8){
35915 width = this.thumbEl.getHeight();
35916 this.baseScale = width / this.imageEl.OriginHeight;
35918 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
35919 height = this.thumbEl.getWidth();
35920 this.baseScale = height / this.imageEl.OriginHeight;
35923 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35924 height = this.thumbEl.getWidth();
35925 this.baseScale = height / this.imageEl.OriginHeight;
35927 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
35928 width = this.thumbEl.getHeight();
35929 this.baseScale = width / this.imageEl.OriginWidth;
35936 width = this.thumbEl.getWidth();
35937 this.baseScale = width / this.imageEl.OriginWidth;
35939 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
35940 height = this.thumbEl.getHeight();
35941 this.baseScale = height / this.imageEl.OriginHeight;
35944 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35946 height = this.thumbEl.getHeight();
35947 this.baseScale = height / this.imageEl.OriginHeight;
35949 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
35950 width = this.thumbEl.getWidth();
35951 this.baseScale = width / this.imageEl.OriginWidth;
35959 getScaleLevel : function()
35961 return this.baseScale * Math.pow(1.1, this.scale);
35964 onTouchStart : function(e)
35966 if(!this.canvasLoaded){
35967 this.beforeSelectFile(e);
35971 var touches = e.browserEvent.touches;
35977 if(touches.length == 1){
35978 this.onMouseDown(e);
35982 if(touches.length != 2){
35988 for(var i = 0, finger; finger = touches[i]; i++){
35989 coords.push(finger.pageX, finger.pageY);
35992 var x = Math.pow(coords[0] - coords[2], 2);
35993 var y = Math.pow(coords[1] - coords[3], 2);
35995 this.startDistance = Math.sqrt(x + y);
35997 this.startScale = this.scale;
35999 this.pinching = true;
36000 this.dragable = false;
36004 onTouchMove : function(e)
36006 if(!this.pinching && !this.dragable){
36010 var touches = e.browserEvent.touches;
36017 this.onMouseMove(e);
36023 for(var i = 0, finger; finger = touches[i]; i++){
36024 coords.push(finger.pageX, finger.pageY);
36027 var x = Math.pow(coords[0] - coords[2], 2);
36028 var y = Math.pow(coords[1] - coords[3], 2);
36030 this.endDistance = Math.sqrt(x + y);
36032 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
36034 if(!this.zoomable()){
36035 this.scale = this.startScale;
36043 onTouchEnd : function(e)
36045 this.pinching = false;
36046 this.dragable = false;
36050 process : function(file, crop)
36053 this.maskEl.mask(this.loadingText);
36056 this.xhr = new XMLHttpRequest();
36058 file.xhr = this.xhr;
36060 this.xhr.open(this.method, this.url, true);
36063 "Accept": "application/json",
36064 "Cache-Control": "no-cache",
36065 "X-Requested-With": "XMLHttpRequest"
36068 for (var headerName in headers) {
36069 var headerValue = headers[headerName];
36071 this.xhr.setRequestHeader(headerName, headerValue);
36077 this.xhr.onload = function()
36079 _this.xhrOnLoad(_this.xhr);
36082 this.xhr.onerror = function()
36084 _this.xhrOnError(_this.xhr);
36087 var formData = new FormData();
36089 formData.append('returnHTML', 'NO');
36092 formData.append('crop', crop);
36095 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
36096 formData.append(this.paramName, file, file.name);
36099 if(typeof(file.filename) != 'undefined'){
36100 formData.append('filename', file.filename);
36103 if(typeof(file.mimetype) != 'undefined'){
36104 formData.append('mimetype', file.mimetype);
36107 if(this.fireEvent('arrange', this, formData) != false){
36108 this.xhr.send(formData);
36112 xhrOnLoad : function(xhr)
36115 this.maskEl.unmask();
36118 if (xhr.readyState !== 4) {
36119 this.fireEvent('exception', this, xhr);
36123 var response = Roo.decode(xhr.responseText);
36125 if(!response.success){
36126 this.fireEvent('exception', this, xhr);
36130 var response = Roo.decode(xhr.responseText);
36132 this.fireEvent('upload', this, response);
36136 xhrOnError : function()
36139 this.maskEl.unmask();
36142 Roo.log('xhr on error');
36144 var response = Roo.decode(xhr.responseText);
36150 prepare : function(file)
36153 this.maskEl.mask(this.loadingText);
36159 if(typeof(file) === 'string'){
36160 this.loadCanvas(file);
36164 if(!file || !this.urlAPI){
36169 this.cropType = file.type;
36173 if(this.fireEvent('prepare', this, this.file) != false){
36175 var reader = new FileReader();
36177 reader.onload = function (e) {
36178 if (e.target.error) {
36179 Roo.log(e.target.error);
36183 var buffer = e.target.result,
36184 dataView = new DataView(buffer),
36186 maxOffset = dataView.byteLength - 4,
36190 if (dataView.getUint16(0) === 0xffd8) {
36191 while (offset < maxOffset) {
36192 markerBytes = dataView.getUint16(offset);
36194 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
36195 markerLength = dataView.getUint16(offset + 2) + 2;
36196 if (offset + markerLength > dataView.byteLength) {
36197 Roo.log('Invalid meta data: Invalid segment size.');
36201 if(markerBytes == 0xffe1){
36202 _this.parseExifData(
36209 offset += markerLength;
36219 var url = _this.urlAPI.createObjectURL(_this.file);
36221 _this.loadCanvas(url);
36226 reader.readAsArrayBuffer(this.file);
36232 parseExifData : function(dataView, offset, length)
36234 var tiffOffset = offset + 10,
36238 if (dataView.getUint32(offset + 4) !== 0x45786966) {
36239 // No Exif data, might be XMP data instead
36243 // Check for the ASCII code for "Exif" (0x45786966):
36244 if (dataView.getUint32(offset + 4) !== 0x45786966) {
36245 // No Exif data, might be XMP data instead
36248 if (tiffOffset + 8 > dataView.byteLength) {
36249 Roo.log('Invalid Exif data: Invalid segment size.');
36252 // Check for the two null bytes:
36253 if (dataView.getUint16(offset + 8) !== 0x0000) {
36254 Roo.log('Invalid Exif data: Missing byte alignment offset.');
36257 // Check the byte alignment:
36258 switch (dataView.getUint16(tiffOffset)) {
36260 littleEndian = true;
36263 littleEndian = false;
36266 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
36269 // Check for the TIFF tag marker (0x002A):
36270 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
36271 Roo.log('Invalid Exif data: Missing TIFF marker.');
36274 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
36275 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
36277 this.parseExifTags(
36280 tiffOffset + dirOffset,
36285 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
36290 if (dirOffset + 6 > dataView.byteLength) {
36291 Roo.log('Invalid Exif data: Invalid directory offset.');
36294 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
36295 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
36296 if (dirEndOffset + 4 > dataView.byteLength) {
36297 Roo.log('Invalid Exif data: Invalid directory size.');
36300 for (i = 0; i < tagsNumber; i += 1) {
36304 dirOffset + 2 + 12 * i, // tag offset
36308 // Return the offset to the next directory:
36309 return dataView.getUint32(dirEndOffset, littleEndian);
36312 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
36314 var tag = dataView.getUint16(offset, littleEndian);
36316 this.exif[tag] = this.getExifValue(
36320 dataView.getUint16(offset + 2, littleEndian), // tag type
36321 dataView.getUint32(offset + 4, littleEndian), // tag length
36326 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
36328 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
36337 Roo.log('Invalid Exif data: Invalid tag type.');
36341 tagSize = tagType.size * length;
36342 // Determine if the value is contained in the dataOffset bytes,
36343 // or if the value at the dataOffset is a pointer to the actual data:
36344 dataOffset = tagSize > 4 ?
36345 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
36346 if (dataOffset + tagSize > dataView.byteLength) {
36347 Roo.log('Invalid Exif data: Invalid data offset.');
36350 if (length === 1) {
36351 return tagType.getValue(dataView, dataOffset, littleEndian);
36354 for (i = 0; i < length; i += 1) {
36355 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
36358 if (tagType.ascii) {
36360 // Concatenate the chars:
36361 for (i = 0; i < values.length; i += 1) {
36363 // Ignore the terminating NULL byte(s):
36364 if (c === '\u0000') {
36376 Roo.apply(Roo.bootstrap.UploadCropbox, {
36378 'Orientation': 0x0112
36382 1: 0, //'top-left',
36384 3: 180, //'bottom-right',
36385 // 4: 'bottom-left',
36387 6: 90, //'right-top',
36388 // 7: 'right-bottom',
36389 8: 270 //'left-bottom'
36393 // byte, 8-bit unsigned int:
36395 getValue: function (dataView, dataOffset) {
36396 return dataView.getUint8(dataOffset);
36400 // ascii, 8-bit byte:
36402 getValue: function (dataView, dataOffset) {
36403 return String.fromCharCode(dataView.getUint8(dataOffset));
36408 // short, 16 bit int:
36410 getValue: function (dataView, dataOffset, littleEndian) {
36411 return dataView.getUint16(dataOffset, littleEndian);
36415 // long, 32 bit int:
36417 getValue: function (dataView, dataOffset, littleEndian) {
36418 return dataView.getUint32(dataOffset, littleEndian);
36422 // rational = two long values, first is numerator, second is denominator:
36424 getValue: function (dataView, dataOffset, littleEndian) {
36425 return dataView.getUint32(dataOffset, littleEndian) /
36426 dataView.getUint32(dataOffset + 4, littleEndian);
36430 // slong, 32 bit signed int:
36432 getValue: function (dataView, dataOffset, littleEndian) {
36433 return dataView.getInt32(dataOffset, littleEndian);
36437 // srational, two slongs, first is numerator, second is denominator:
36439 getValue: function (dataView, dataOffset, littleEndian) {
36440 return dataView.getInt32(dataOffset, littleEndian) /
36441 dataView.getInt32(dataOffset + 4, littleEndian);
36451 cls : 'btn-group roo-upload-cropbox-rotate-left',
36452 action : 'rotate-left',
36456 cls : 'btn btn-default',
36457 html : '<i class="fa fa-undo"></i>'
36463 cls : 'btn-group roo-upload-cropbox-picture',
36464 action : 'picture',
36468 cls : 'btn btn-default',
36469 html : '<i class="fa fa-picture-o"></i>'
36475 cls : 'btn-group roo-upload-cropbox-rotate-right',
36476 action : 'rotate-right',
36480 cls : 'btn btn-default',
36481 html : '<i class="fa fa-repeat"></i>'
36489 cls : 'btn-group roo-upload-cropbox-rotate-left',
36490 action : 'rotate-left',
36494 cls : 'btn btn-default',
36495 html : '<i class="fa fa-undo"></i>'
36501 cls : 'btn-group roo-upload-cropbox-download',
36502 action : 'download',
36506 cls : 'btn btn-default',
36507 html : '<i class="fa fa-download"></i>'
36513 cls : 'btn-group roo-upload-cropbox-crop',
36518 cls : 'btn btn-default',
36519 html : '<i class="fa fa-crop"></i>'
36525 cls : 'btn-group roo-upload-cropbox-trash',
36530 cls : 'btn btn-default',
36531 html : '<i class="fa fa-trash"></i>'
36537 cls : 'btn-group roo-upload-cropbox-rotate-right',
36538 action : 'rotate-right',
36542 cls : 'btn btn-default',
36543 html : '<i class="fa fa-repeat"></i>'
36551 cls : 'btn-group roo-upload-cropbox-rotate-left',
36552 action : 'rotate-left',
36556 cls : 'btn btn-default',
36557 html : '<i class="fa fa-undo"></i>'
36563 cls : 'btn-group roo-upload-cropbox-rotate-right',
36564 action : 'rotate-right',
36568 cls : 'btn btn-default',
36569 html : '<i class="fa fa-repeat"></i>'
36582 * @class Roo.bootstrap.DocumentManager
36583 * @extends Roo.bootstrap.Component
36584 * Bootstrap DocumentManager class
36585 * @cfg {String} paramName default 'imageUpload'
36586 * @cfg {String} toolTipName default 'filename'
36587 * @cfg {String} method default POST
36588 * @cfg {String} url action url
36589 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
36590 * @cfg {Boolean} multiple multiple upload default true
36591 * @cfg {Number} thumbSize default 300
36592 * @cfg {String} fieldLabel
36593 * @cfg {Number} labelWidth default 4
36594 * @cfg {String} labelAlign (left|top) default left
36595 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
36596 * @cfg {Number} labellg set the width of label (1-12)
36597 * @cfg {Number} labelmd set the width of label (1-12)
36598 * @cfg {Number} labelsm set the width of label (1-12)
36599 * @cfg {Number} labelxs set the width of label (1-12)
36602 * Create a new DocumentManager
36603 * @param {Object} config The config object
36606 Roo.bootstrap.DocumentManager = function(config){
36607 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
36610 this.delegates = [];
36615 * Fire when initial the DocumentManager
36616 * @param {Roo.bootstrap.DocumentManager} this
36621 * inspect selected file
36622 * @param {Roo.bootstrap.DocumentManager} this
36623 * @param {File} file
36628 * Fire when xhr load exception
36629 * @param {Roo.bootstrap.DocumentManager} this
36630 * @param {XMLHttpRequest} xhr
36632 "exception" : true,
36634 * @event afterupload
36635 * Fire when xhr load exception
36636 * @param {Roo.bootstrap.DocumentManager} this
36637 * @param {XMLHttpRequest} xhr
36639 "afterupload" : true,
36642 * prepare the form data
36643 * @param {Roo.bootstrap.DocumentManager} this
36644 * @param {Object} formData
36649 * Fire when remove the file
36650 * @param {Roo.bootstrap.DocumentManager} this
36651 * @param {Object} file
36656 * Fire after refresh the file
36657 * @param {Roo.bootstrap.DocumentManager} this
36662 * Fire after click the image
36663 * @param {Roo.bootstrap.DocumentManager} this
36664 * @param {Object} file
36669 * Fire when upload a image and editable set to true
36670 * @param {Roo.bootstrap.DocumentManager} this
36671 * @param {Object} file
36675 * @event beforeselectfile
36676 * Fire before select file
36677 * @param {Roo.bootstrap.DocumentManager} this
36679 "beforeselectfile" : true,
36682 * Fire before process file
36683 * @param {Roo.bootstrap.DocumentManager} this
36684 * @param {Object} file
36688 * @event previewrendered
36689 * Fire when preview rendered
36690 * @param {Roo.bootstrap.DocumentManager} this
36691 * @param {Object} file
36693 "previewrendered" : true,
36696 "previewResize" : true
36701 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
36710 paramName : 'imageUpload',
36711 toolTipName : 'filename',
36714 labelAlign : 'left',
36724 getAutoCreate : function()
36726 var managerWidget = {
36728 cls : 'roo-document-manager',
36732 cls : 'roo-document-manager-selector',
36737 cls : 'roo-document-manager-uploader',
36741 cls : 'roo-document-manager-upload-btn',
36742 html : '<i class="fa fa-plus"></i>'
36753 cls : 'column col-md-12',
36758 if(this.fieldLabel.length){
36763 cls : 'column col-md-12',
36764 html : this.fieldLabel
36768 cls : 'column col-md-12',
36773 if(this.labelAlign == 'left'){
36778 html : this.fieldLabel
36787 if(this.labelWidth > 12){
36788 content[0].style = "width: " + this.labelWidth + 'px';
36791 if(this.labelWidth < 13 && this.labelmd == 0){
36792 this.labelmd = this.labelWidth;
36795 if(this.labellg > 0){
36796 content[0].cls += ' col-lg-' + this.labellg;
36797 content[1].cls += ' col-lg-' + (12 - this.labellg);
36800 if(this.labelmd > 0){
36801 content[0].cls += ' col-md-' + this.labelmd;
36802 content[1].cls += ' col-md-' + (12 - this.labelmd);
36805 if(this.labelsm > 0){
36806 content[0].cls += ' col-sm-' + this.labelsm;
36807 content[1].cls += ' col-sm-' + (12 - this.labelsm);
36810 if(this.labelxs > 0){
36811 content[0].cls += ' col-xs-' + this.labelxs;
36812 content[1].cls += ' col-xs-' + (12 - this.labelxs);
36820 cls : 'row clearfix',
36828 initEvents : function()
36830 this.managerEl = this.el.select('.roo-document-manager', true).first();
36831 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
36833 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
36834 this.selectorEl.hide();
36837 this.selectorEl.attr('multiple', 'multiple');
36840 this.selectorEl.on('change', this.onFileSelected, this);
36842 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
36843 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
36845 this.uploader.on('click', this.onUploaderClick, this);
36847 this.renderProgressDialog();
36851 window.addEventListener("resize", function() { _this.refresh(); } );
36853 this.fireEvent('initial', this);
36856 renderProgressDialog : function()
36860 this.progressDialog = new Roo.bootstrap.Modal({
36861 cls : 'roo-document-manager-progress-dialog',
36862 allow_close : false,
36873 btnclick : function() {
36874 _this.uploadCancel();
36880 this.progressDialog.render(Roo.get(document.body));
36882 this.progress = new Roo.bootstrap.Progress({
36883 cls : 'roo-document-manager-progress',
36888 this.progress.render(this.progressDialog.getChildContainer());
36890 this.progressBar = new Roo.bootstrap.ProgressBar({
36891 cls : 'roo-document-manager-progress-bar',
36894 aria_valuemax : 12,
36898 this.progressBar.render(this.progress.getChildContainer());
36901 onUploaderClick : function(e)
36903 e.preventDefault();
36905 if(this.fireEvent('beforeselectfile', this) != false){
36906 this.selectorEl.dom.click();
36911 onFileSelected : function(e)
36913 e.preventDefault();
36915 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
36919 Roo.each(this.selectorEl.dom.files, function(file){
36920 if(this.fireEvent('inspect', this, file) != false){
36921 this.files.push(file);
36931 this.selectorEl.dom.value = '';
36933 if(!this.files || !this.files.length){
36937 if(this.boxes > 0 && this.files.length > this.boxes){
36938 this.files = this.files.slice(0, this.boxes);
36941 this.uploader.show();
36943 if(this.boxes > 0 && this.files.length > this.boxes - 1){
36944 this.uploader.hide();
36953 Roo.each(this.files, function(file){
36955 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
36956 var f = this.renderPreview(file);
36961 if(file.type.indexOf('image') != -1){
36962 this.delegates.push(
36964 _this.process(file);
36965 }).createDelegate(this)
36973 _this.process(file);
36974 }).createDelegate(this)
36979 this.files = files;
36981 this.delegates = this.delegates.concat(docs);
36983 if(!this.delegates.length){
36988 this.progressBar.aria_valuemax = this.delegates.length;
36995 arrange : function()
36997 if(!this.delegates.length){
36998 this.progressDialog.hide();
37003 var delegate = this.delegates.shift();
37005 this.progressDialog.show();
37007 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
37009 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
37014 refresh : function()
37016 this.uploader.show();
37018 if(this.boxes > 0 && this.files.length > this.boxes - 1){
37019 this.uploader.hide();
37022 Roo.isTouch ? this.closable(false) : this.closable(true);
37024 this.fireEvent('refresh', this);
37027 onRemove : function(e, el, o)
37029 e.preventDefault();
37031 this.fireEvent('remove', this, o);
37035 remove : function(o)
37039 Roo.each(this.files, function(file){
37040 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
37049 this.files = files;
37056 Roo.each(this.files, function(file){
37061 file.target.remove();
37070 onClick : function(e, el, o)
37072 e.preventDefault();
37074 this.fireEvent('click', this, o);
37078 closable : function(closable)
37080 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
37082 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
37094 xhrOnLoad : function(xhr)
37096 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
37100 if (xhr.readyState !== 4) {
37102 this.fireEvent('exception', this, xhr);
37106 var response = Roo.decode(xhr.responseText);
37108 if(!response.success){
37110 this.fireEvent('exception', this, xhr);
37114 var file = this.renderPreview(response.data);
37116 this.files.push(file);
37120 this.fireEvent('afterupload', this, xhr);
37124 xhrOnError : function(xhr)
37126 Roo.log('xhr on error');
37128 var response = Roo.decode(xhr.responseText);
37135 process : function(file)
37137 if(this.fireEvent('process', this, file) !== false){
37138 if(this.editable && file.type.indexOf('image') != -1){
37139 this.fireEvent('edit', this, file);
37143 this.uploadStart(file, false);
37150 uploadStart : function(file, crop)
37152 this.xhr = new XMLHttpRequest();
37154 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
37159 file.xhr = this.xhr;
37161 this.managerEl.createChild({
37163 cls : 'roo-document-manager-loading',
37167 tooltip : file.name,
37168 cls : 'roo-document-manager-thumb',
37169 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
37175 this.xhr.open(this.method, this.url, true);
37178 "Accept": "application/json",
37179 "Cache-Control": "no-cache",
37180 "X-Requested-With": "XMLHttpRequest"
37183 for (var headerName in headers) {
37184 var headerValue = headers[headerName];
37186 this.xhr.setRequestHeader(headerName, headerValue);
37192 this.xhr.onload = function()
37194 _this.xhrOnLoad(_this.xhr);
37197 this.xhr.onerror = function()
37199 _this.xhrOnError(_this.xhr);
37202 var formData = new FormData();
37204 formData.append('returnHTML', 'NO');
37207 formData.append('crop', crop);
37210 formData.append(this.paramName, file, file.name);
37217 if(this.fireEvent('prepare', this, formData, options) != false){
37219 if(options.manually){
37223 this.xhr.send(formData);
37227 this.uploadCancel();
37230 uploadCancel : function()
37236 this.delegates = [];
37238 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
37245 renderPreview : function(file)
37247 if(typeof(file.target) != 'undefined' && file.target){
37251 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
37253 var previewEl = this.managerEl.createChild({
37255 cls : 'roo-document-manager-preview',
37259 tooltip : file[this.toolTipName],
37260 cls : 'roo-document-manager-thumb',
37261 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
37266 html : '<i class="fa fa-times-circle"></i>'
37271 var close = previewEl.select('button.close', true).first();
37273 close.on('click', this.onRemove, this, file);
37275 file.target = previewEl;
37277 var image = previewEl.select('img', true).first();
37281 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
37283 image.on('click', this.onClick, this, file);
37285 this.fireEvent('previewrendered', this, file);
37291 onPreviewLoad : function(file, image)
37293 if(typeof(file.target) == 'undefined' || !file.target){
37297 var width = image.dom.naturalWidth || image.dom.width;
37298 var height = image.dom.naturalHeight || image.dom.height;
37300 if(!this.previewResize) {
37304 if(width > height){
37305 file.target.addClass('wide');
37309 file.target.addClass('tall');
37314 uploadFromSource : function(file, crop)
37316 this.xhr = new XMLHttpRequest();
37318 this.managerEl.createChild({
37320 cls : 'roo-document-manager-loading',
37324 tooltip : file.name,
37325 cls : 'roo-document-manager-thumb',
37326 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
37332 this.xhr.open(this.method, this.url, true);
37335 "Accept": "application/json",
37336 "Cache-Control": "no-cache",
37337 "X-Requested-With": "XMLHttpRequest"
37340 for (var headerName in headers) {
37341 var headerValue = headers[headerName];
37343 this.xhr.setRequestHeader(headerName, headerValue);
37349 this.xhr.onload = function()
37351 _this.xhrOnLoad(_this.xhr);
37354 this.xhr.onerror = function()
37356 _this.xhrOnError(_this.xhr);
37359 var formData = new FormData();
37361 formData.append('returnHTML', 'NO');
37363 formData.append('crop', crop);
37365 if(typeof(file.filename) != 'undefined'){
37366 formData.append('filename', file.filename);
37369 if(typeof(file.mimetype) != 'undefined'){
37370 formData.append('mimetype', file.mimetype);
37375 if(this.fireEvent('prepare', this, formData) != false){
37376 this.xhr.send(formData);
37386 * @class Roo.bootstrap.DocumentViewer
37387 * @extends Roo.bootstrap.Component
37388 * Bootstrap DocumentViewer class
37389 * @cfg {Boolean} showDownload (true|false) show download button (default true)
37390 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
37393 * Create a new DocumentViewer
37394 * @param {Object} config The config object
37397 Roo.bootstrap.DocumentViewer = function(config){
37398 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
37403 * Fire after initEvent
37404 * @param {Roo.bootstrap.DocumentViewer} this
37410 * @param {Roo.bootstrap.DocumentViewer} this
37415 * Fire after download button
37416 * @param {Roo.bootstrap.DocumentViewer} this
37421 * Fire after trash button
37422 * @param {Roo.bootstrap.DocumentViewer} this
37429 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
37431 showDownload : true,
37435 getAutoCreate : function()
37439 cls : 'roo-document-viewer',
37443 cls : 'roo-document-viewer-body',
37447 cls : 'roo-document-viewer-thumb',
37451 cls : 'roo-document-viewer-image'
37459 cls : 'roo-document-viewer-footer',
37462 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
37466 cls : 'btn-group roo-document-viewer-download',
37470 cls : 'btn btn-default',
37471 html : '<i class="fa fa-download"></i>'
37477 cls : 'btn-group roo-document-viewer-trash',
37481 cls : 'btn btn-default',
37482 html : '<i class="fa fa-trash"></i>'
37495 initEvents : function()
37497 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
37498 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
37500 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
37501 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
37503 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
37504 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
37506 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
37507 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
37509 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
37510 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
37512 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
37513 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
37515 this.bodyEl.on('click', this.onClick, this);
37516 this.downloadBtn.on('click', this.onDownload, this);
37517 this.trashBtn.on('click', this.onTrash, this);
37519 this.downloadBtn.hide();
37520 this.trashBtn.hide();
37522 if(this.showDownload){
37523 this.downloadBtn.show();
37526 if(this.showTrash){
37527 this.trashBtn.show();
37530 if(!this.showDownload && !this.showTrash) {
37531 this.footerEl.hide();
37536 initial : function()
37538 this.fireEvent('initial', this);
37542 onClick : function(e)
37544 e.preventDefault();
37546 this.fireEvent('click', this);
37549 onDownload : function(e)
37551 e.preventDefault();
37553 this.fireEvent('download', this);
37556 onTrash : function(e)
37558 e.preventDefault();
37560 this.fireEvent('trash', this);
37572 * @class Roo.bootstrap.form.FieldLabel
37573 * @extends Roo.bootstrap.Component
37574 * Bootstrap FieldLabel class
37575 * @cfg {String} html contents of the element
37576 * @cfg {String} tag tag of the element default label
37577 * @cfg {String} cls class of the element
37578 * @cfg {String} target label target
37579 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
37580 * @cfg {String} invalidClass DEPRICATED - BS4 uses is-invalid
37581 * @cfg {String} validClass DEPRICATED - BS4 uses is-valid
37582 * @cfg {String} iconTooltip default "This field is required"
37583 * @cfg {String} indicatorpos (left|right) default left
37586 * Create a new FieldLabel
37587 * @param {Object} config The config object
37590 Roo.bootstrap.form.FieldLabel = function(config){
37591 Roo.bootstrap.Element.superclass.constructor.call(this, config);
37596 * Fires after the field has been marked as invalid.
37597 * @param {Roo.form.FieldLabel} this
37598 * @param {String} msg The validation message
37603 * Fires after the field has been validated with no errors.
37604 * @param {Roo.form.FieldLabel} this
37610 Roo.extend(Roo.bootstrap.form.FieldLabel, Roo.bootstrap.Component, {
37617 invalidClass : 'has-warning',
37618 validClass : 'has-success',
37619 iconTooltip : 'This field is required',
37620 indicatorpos : 'left',
37622 getAutoCreate : function(){
37625 if (!this.allowBlank) {
37631 cls : 'roo-bootstrap-field-label ' + this.cls,
37636 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
37637 tooltip : this.iconTooltip
37646 if(this.indicatorpos == 'right'){
37649 cls : 'roo-bootstrap-field-label ' + this.cls,
37658 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
37659 tooltip : this.iconTooltip
37668 initEvents: function()
37670 Roo.bootstrap.Element.superclass.initEvents.call(this);
37672 this.indicator = this.indicatorEl();
37674 if(this.indicator){
37675 this.indicator.removeClass('visible');
37676 this.indicator.addClass('invisible');
37679 Roo.bootstrap.form.FieldLabel.register(this);
37682 indicatorEl : function()
37684 var indicator = this.el.select('i.roo-required-indicator',true).first();
37695 * Mark this field as valid
37697 markValid : function()
37699 if(this.indicator){
37700 this.indicator.removeClass('visible');
37701 this.indicator.addClass('invisible');
37703 if (Roo.bootstrap.version == 3) {
37704 this.el.removeClass(this.invalidClass);
37705 this.el.addClass(this.validClass);
37707 this.el.removeClass('is-invalid');
37708 this.el.addClass('is-valid');
37712 this.fireEvent('valid', this);
37716 * Mark this field as invalid
37717 * @param {String} msg The validation message
37719 markInvalid : function(msg)
37721 if(this.indicator){
37722 this.indicator.removeClass('invisible');
37723 this.indicator.addClass('visible');
37725 if (Roo.bootstrap.version == 3) {
37726 this.el.removeClass(this.validClass);
37727 this.el.addClass(this.invalidClass);
37729 this.el.removeClass('is-valid');
37730 this.el.addClass('is-invalid');
37734 this.fireEvent('invalid', this, msg);
37740 Roo.apply(Roo.bootstrap.form.FieldLabel, {
37745 * register a FieldLabel Group
37746 * @param {Roo.bootstrap.form.FieldLabel} the FieldLabel to add
37748 register : function(label)
37750 if(this.groups.hasOwnProperty(label.target)){
37754 this.groups[label.target] = label;
37758 * fetch a FieldLabel Group based on the target
37759 * @param {string} target
37760 * @returns {Roo.bootstrap.form.FieldLabel} the CheckBox group
37762 get: function(target) {
37763 if (typeof(this.groups[target]) == 'undefined') {
37767 return this.groups[target] ;
37776 * page DateSplitField.
37782 * @class Roo.bootstrap.form.DateSplitField
37783 * @extends Roo.bootstrap.Component
37784 * Bootstrap DateSplitField class
37785 * @cfg {string} fieldLabel - the label associated
37786 * @cfg {Number} labelWidth set the width of label (0-12)
37787 * @cfg {String} labelAlign (top|left)
37788 * @cfg {Boolean} dayAllowBlank (true|false) default false
37789 * @cfg {Boolean} monthAllowBlank (true|false) default false
37790 * @cfg {Boolean} yearAllowBlank (true|false) default false
37791 * @cfg {string} dayPlaceholder
37792 * @cfg {string} monthPlaceholder
37793 * @cfg {string} yearPlaceholder
37794 * @cfg {string} dayFormat default 'd'
37795 * @cfg {string} monthFormat default 'm'
37796 * @cfg {string} yearFormat default 'Y'
37797 * @cfg {Number} labellg set the width of label (1-12)
37798 * @cfg {Number} labelmd set the width of label (1-12)
37799 * @cfg {Number} labelsm set the width of label (1-12)
37800 * @cfg {Number} labelxs set the width of label (1-12)
37804 * Create a new DateSplitField
37805 * @param {Object} config The config object
37808 Roo.bootstrap.form.DateSplitField = function(config){
37809 Roo.bootstrap.form.DateSplitField.superclass.constructor.call(this, config);
37815 * getting the data of years
37816 * @param {Roo.bootstrap.form.DateSplitField} this
37817 * @param {Object} years
37822 * getting the data of days
37823 * @param {Roo.bootstrap.form.DateSplitField} this
37824 * @param {Object} days
37829 * Fires after the field has been marked as invalid.
37830 * @param {Roo.form.Field} this
37831 * @param {String} msg The validation message
37836 * Fires after the field has been validated with no errors.
37837 * @param {Roo.form.Field} this
37843 Roo.extend(Roo.bootstrap.form.DateSplitField, Roo.bootstrap.Component, {
37846 labelAlign : 'top',
37848 dayAllowBlank : false,
37849 monthAllowBlank : false,
37850 yearAllowBlank : false,
37851 dayPlaceholder : '',
37852 monthPlaceholder : '',
37853 yearPlaceholder : '',
37857 isFormField : true,
37863 getAutoCreate : function()
37867 cls : 'row roo-date-split-field-group',
37872 cls : 'form-hidden-field roo-date-split-field-group-value',
37878 var labelCls = 'col-md-12';
37879 var contentCls = 'col-md-4';
37881 if(this.fieldLabel){
37885 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
37889 html : this.fieldLabel
37894 if(this.labelAlign == 'left'){
37896 if(this.labelWidth > 12){
37897 label.style = "width: " + this.labelWidth + 'px';
37900 if(this.labelWidth < 13 && this.labelmd == 0){
37901 this.labelmd = this.labelWidth;
37904 if(this.labellg > 0){
37905 labelCls = ' col-lg-' + this.labellg;
37906 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
37909 if(this.labelmd > 0){
37910 labelCls = ' col-md-' + this.labelmd;
37911 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
37914 if(this.labelsm > 0){
37915 labelCls = ' col-sm-' + this.labelsm;
37916 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
37919 if(this.labelxs > 0){
37920 labelCls = ' col-xs-' + this.labelxs;
37921 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
37925 label.cls += ' ' + labelCls;
37927 cfg.cn.push(label);
37930 Roo.each(['day', 'month', 'year'], function(t){
37933 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
37940 inputEl: function ()
37942 return this.el.select('.roo-date-split-field-group-value', true).first();
37945 onRender : function(ct, position)
37949 Roo.bootstrap.DateSplitFiel.superclass.onRender.call(this, ct, position);
37951 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
37953 this.dayField = new Roo.bootstrap.form.ComboBox({
37954 allowBlank : this.dayAllowBlank,
37955 alwaysQuery : true,
37956 displayField : 'value',
37959 forceSelection : true,
37961 placeholder : this.dayPlaceholder,
37962 selectOnFocus : true,
37963 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
37964 triggerAction : 'all',
37966 valueField : 'value',
37967 store : new Roo.data.SimpleStore({
37968 data : (function() {
37970 _this.fireEvent('days', _this, days);
37973 fields : [ 'value' ]
37976 select : function (_self, record, index)
37978 _this.setValue(_this.getValue());
37983 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
37985 this.monthField = new Roo.bootstrap.form.MonthField({
37986 after : '<i class=\"fa fa-calendar\"></i>',
37987 allowBlank : this.monthAllowBlank,
37988 placeholder : this.monthPlaceholder,
37991 render : function (_self)
37993 this.el.select('span.input-group-addon', true).first().on('click', function(e){
37994 e.preventDefault();
37998 select : function (_self, oldvalue, newvalue)
38000 _this.setValue(_this.getValue());
38005 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
38007 this.yearField = new Roo.bootstrap.form.ComboBox({
38008 allowBlank : this.yearAllowBlank,
38009 alwaysQuery : true,
38010 displayField : 'value',
38013 forceSelection : true,
38015 placeholder : this.yearPlaceholder,
38016 selectOnFocus : true,
38017 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
38018 triggerAction : 'all',
38020 valueField : 'value',
38021 store : new Roo.data.SimpleStore({
38022 data : (function() {
38024 _this.fireEvent('years', _this, years);
38027 fields : [ 'value' ]
38030 select : function (_self, record, index)
38032 _this.setValue(_this.getValue());
38037 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
38040 setValue : function(v, format)
38042 this.inputEl.dom.value = v;
38044 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
38046 var d = Date.parseDate(v, f);
38053 this.setDay(d.format(this.dayFormat));
38054 this.setMonth(d.format(this.monthFormat));
38055 this.setYear(d.format(this.yearFormat));
38062 setDay : function(v)
38064 this.dayField.setValue(v);
38065 this.inputEl.dom.value = this.getValue();
38070 setMonth : function(v)
38072 this.monthField.setValue(v, true);
38073 this.inputEl.dom.value = this.getValue();
38078 setYear : function(v)
38080 this.yearField.setValue(v);
38081 this.inputEl.dom.value = this.getValue();
38086 getDay : function()
38088 return this.dayField.getValue();
38091 getMonth : function()
38093 return this.monthField.getValue();
38096 getYear : function()
38098 return this.yearField.getValue();
38101 getValue : function()
38103 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
38105 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
38115 this.inputEl.dom.value = '';
38120 validate : function()
38122 var d = this.dayField.validate();
38123 var m = this.monthField.validate();
38124 var y = this.yearField.validate();
38129 (!this.dayAllowBlank && !d) ||
38130 (!this.monthAllowBlank && !m) ||
38131 (!this.yearAllowBlank && !y)
38136 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
38145 this.markInvalid();
38150 markValid : function()
38153 var label = this.el.select('label', true).first();
38154 var icon = this.el.select('i.fa-star', true).first();
38160 this.fireEvent('valid', this);
38164 * Mark this field as invalid
38165 * @param {String} msg The validation message
38167 markInvalid : function(msg)
38170 var label = this.el.select('label', true).first();
38171 var icon = this.el.select('i.fa-star', true).first();
38173 if(label && !icon){
38174 this.el.select('.roo-date-split-field-label', true).createChild({
38176 cls : 'text-danger fa fa-lg fa-star',
38177 tooltip : 'This field is required',
38178 style : 'margin-right:5px;'
38182 this.fireEvent('invalid', this, msg);
38185 clearInvalid : function()
38187 var label = this.el.select('label', true).first();
38188 var icon = this.el.select('i.fa-star', true).first();
38194 this.fireEvent('valid', this);
38197 getName: function()
38207 * @class Roo.bootstrap.LayoutMasonry
38208 * @extends Roo.bootstrap.Component
38209 * @children Roo.bootstrap.Element Roo.bootstrap.Img Roo.bootstrap.MasonryBrick
38210 * Bootstrap Layout Masonry class
38213 * http://masonry.desandro.com
38215 * The idea is to render all the bricks based on vertical width...
38217 * The original code extends 'outlayer' - we might need to use that....
38220 * Create a new Element
38221 * @param {Object} config The config object
38224 Roo.bootstrap.LayoutMasonry = function(config){
38226 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
38230 Roo.bootstrap.LayoutMasonry.register(this);
38236 * Fire after layout the items
38237 * @param {Roo.bootstrap.LayoutMasonry} this
38238 * @param {Roo.EventObject} e
38245 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
38248 * @cfg {Boolean} isLayoutInstant = no animation?
38250 isLayoutInstant : false, // needed?
38253 * @cfg {Number} boxWidth width of the columns
38258 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
38263 * @cfg {Number} padWidth padding below box..
38268 * @cfg {Number} gutter gutter width..
38273 * @cfg {Number} maxCols maximum number of columns
38279 * @cfg {Boolean} isAutoInitial defalut true
38281 isAutoInitial : true,
38286 * @cfg {Boolean} isHorizontal defalut false
38288 isHorizontal : false,
38290 currentSize : null,
38296 bricks: null, //CompositeElement
38300 _isLayoutInited : false,
38302 // isAlternative : false, // only use for vertical layout...
38305 * @cfg {Number} alternativePadWidth padding below box..
38307 alternativePadWidth : 50,
38309 selectedBrick : [],
38311 getAutoCreate : function(){
38313 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
38317 cls: 'blog-masonary-wrapper ' + this.cls,
38319 cls : 'mas-boxes masonary'
38326 getChildContainer: function( )
38328 if (this.boxesEl) {
38329 return this.boxesEl;
38332 this.boxesEl = this.el.select('.mas-boxes').first();
38334 return this.boxesEl;
38338 initEvents : function()
38342 if(this.isAutoInitial){
38343 Roo.log('hook children rendered');
38344 this.on('childrenrendered', function() {
38345 Roo.log('children rendered');
38351 initial : function()
38353 this.selectedBrick = [];
38355 this.currentSize = this.el.getBox(true);
38357 Roo.EventManager.onWindowResize(this.resize, this);
38359 if(!this.isAutoInitial){
38367 //this.layout.defer(500,this);
38371 resize : function()
38373 var cs = this.el.getBox(true);
38376 this.currentSize.width == cs.width &&
38377 this.currentSize.x == cs.x &&
38378 this.currentSize.height == cs.height &&
38379 this.currentSize.y == cs.y
38381 Roo.log("no change in with or X or Y");
38385 this.currentSize = cs;
38391 layout : function()
38393 this._resetLayout();
38395 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
38397 this.layoutItems( isInstant );
38399 this._isLayoutInited = true;
38401 this.fireEvent('layout', this);
38405 _resetLayout : function()
38407 if(this.isHorizontal){
38408 this.horizontalMeasureColumns();
38412 this.verticalMeasureColumns();
38416 verticalMeasureColumns : function()
38418 this.getContainerWidth();
38420 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
38421 // this.colWidth = Math.floor(this.containerWidth * 0.8);
38425 var boxWidth = this.boxWidth + this.padWidth;
38427 if(this.containerWidth < this.boxWidth){
38428 boxWidth = this.containerWidth
38431 var containerWidth = this.containerWidth;
38433 var cols = Math.floor(containerWidth / boxWidth);
38435 this.cols = Math.max( cols, 1 );
38437 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
38439 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
38441 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
38443 this.colWidth = boxWidth + avail - this.padWidth;
38445 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
38446 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
38449 horizontalMeasureColumns : function()
38451 this.getContainerWidth();
38453 var boxWidth = this.boxWidth;
38455 if(this.containerWidth < boxWidth){
38456 boxWidth = this.containerWidth;
38459 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
38461 this.el.setHeight(boxWidth);
38465 getContainerWidth : function()
38467 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
38470 layoutItems : function( isInstant )
38472 Roo.log(this.bricks);
38474 var items = Roo.apply([], this.bricks);
38476 if(this.isHorizontal){
38477 this._horizontalLayoutItems( items , isInstant );
38481 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
38482 // this._verticalAlternativeLayoutItems( items , isInstant );
38486 this._verticalLayoutItems( items , isInstant );
38490 _verticalLayoutItems : function ( items , isInstant)
38492 if ( !items || !items.length ) {
38497 ['xs', 'xs', 'xs', 'tall'],
38498 ['xs', 'xs', 'tall'],
38499 ['xs', 'xs', 'sm'],
38500 ['xs', 'xs', 'xs'],
38506 ['sm', 'xs', 'xs'],
38510 ['tall', 'xs', 'xs', 'xs'],
38511 ['tall', 'xs', 'xs'],
38523 Roo.each(items, function(item, k){
38525 switch (item.size) {
38526 // these layouts take up a full box,
38537 boxes.push([item]);
38560 var filterPattern = function(box, length)
38568 var pattern = box.slice(0, length);
38572 Roo.each(pattern, function(i){
38573 format.push(i.size);
38576 Roo.each(standard, function(s){
38578 if(String(s) != String(format)){
38587 if(!match && length == 1){
38592 filterPattern(box, length - 1);
38596 queue.push(pattern);
38598 box = box.slice(length, box.length);
38600 filterPattern(box, 4);
38606 Roo.each(boxes, function(box, k){
38612 if(box.length == 1){
38617 filterPattern(box, 4);
38621 this._processVerticalLayoutQueue( queue, isInstant );
38625 // _verticalAlternativeLayoutItems : function( items , isInstant )
38627 // if ( !items || !items.length ) {
38631 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
38635 _horizontalLayoutItems : function ( items , isInstant)
38637 if ( !items || !items.length || items.length < 3) {
38643 var eItems = items.slice(0, 3);
38645 items = items.slice(3, items.length);
38648 ['xs', 'xs', 'xs', 'wide'],
38649 ['xs', 'xs', 'wide'],
38650 ['xs', 'xs', 'sm'],
38651 ['xs', 'xs', 'xs'],
38657 ['sm', 'xs', 'xs'],
38661 ['wide', 'xs', 'xs', 'xs'],
38662 ['wide', 'xs', 'xs'],
38675 Roo.each(items, function(item, k){
38677 switch (item.size) {
38688 boxes.push([item]);
38712 var filterPattern = function(box, length)
38720 var pattern = box.slice(0, length);
38724 Roo.each(pattern, function(i){
38725 format.push(i.size);
38728 Roo.each(standard, function(s){
38730 if(String(s) != String(format)){
38739 if(!match && length == 1){
38744 filterPattern(box, length - 1);
38748 queue.push(pattern);
38750 box = box.slice(length, box.length);
38752 filterPattern(box, 4);
38758 Roo.each(boxes, function(box, k){
38764 if(box.length == 1){
38769 filterPattern(box, 4);
38776 var pos = this.el.getBox(true);
38780 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
38782 var hit_end = false;
38784 Roo.each(queue, function(box){
38788 Roo.each(box, function(b){
38790 b.el.setVisibilityMode(Roo.Element.DISPLAY);
38800 Roo.each(box, function(b){
38802 b.el.setVisibilityMode(Roo.Element.DISPLAY);
38805 mx = Math.max(mx, b.x);
38809 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
38813 Roo.each(box, function(b){
38815 b.el.setVisibilityMode(Roo.Element.DISPLAY);
38829 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
38832 /** Sets position of item in DOM
38833 * @param {Element} item
38834 * @param {Number} x - horizontal position
38835 * @param {Number} y - vertical position
38836 * @param {Boolean} isInstant - disables transitions
38838 _processVerticalLayoutQueue : function( queue, isInstant )
38840 var pos = this.el.getBox(true);
38845 for (var i = 0; i < this.cols; i++){
38849 Roo.each(queue, function(box, k){
38851 var col = k % this.cols;
38853 Roo.each(box, function(b,kk){
38855 b.el.position('absolute');
38857 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
38858 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
38860 if(b.size == 'md-left' || b.size == 'md-right'){
38861 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
38862 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
38865 b.el.setWidth(width);
38866 b.el.setHeight(height);
38868 b.el.select('iframe',true).setSize(width,height);
38872 for (var i = 0; i < this.cols; i++){
38874 if(maxY[i] < maxY[col]){
38879 col = Math.min(col, i);
38883 x = pos.x + col * (this.colWidth + this.padWidth);
38887 var positions = [];
38889 switch (box.length){
38891 positions = this.getVerticalOneBoxColPositions(x, y, box);
38894 positions = this.getVerticalTwoBoxColPositions(x, y, box);
38897 positions = this.getVerticalThreeBoxColPositions(x, y, box);
38900 positions = this.getVerticalFourBoxColPositions(x, y, box);
38906 Roo.each(box, function(b,kk){
38908 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
38910 var sz = b.el.getSize();
38912 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
38920 for (var i = 0; i < this.cols; i++){
38921 mY = Math.max(mY, maxY[i]);
38924 this.el.setHeight(mY - pos.y);
38928 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
38930 // var pos = this.el.getBox(true);
38933 // var maxX = pos.right;
38935 // var maxHeight = 0;
38937 // Roo.each(items, function(item, k){
38941 // item.el.position('absolute');
38943 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
38945 // item.el.setWidth(width);
38947 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
38949 // item.el.setHeight(height);
38952 // item.el.setXY([x, y], isInstant ? false : true);
38954 // item.el.setXY([maxX - width, y], isInstant ? false : true);
38957 // y = y + height + this.alternativePadWidth;
38959 // maxHeight = maxHeight + height + this.alternativePadWidth;
38963 // this.el.setHeight(maxHeight);
38967 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
38969 var pos = this.el.getBox(true);
38974 var maxX = pos.right;
38976 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
38978 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
38980 Roo.each(queue, function(box, k){
38982 Roo.each(box, function(b, kk){
38984 b.el.position('absolute');
38986 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
38987 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
38989 if(b.size == 'md-left' || b.size == 'md-right'){
38990 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
38991 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
38994 b.el.setWidth(width);
38995 b.el.setHeight(height);
39003 var positions = [];
39005 switch (box.length){
39007 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
39010 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
39013 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
39016 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
39022 Roo.each(box, function(b,kk){
39024 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
39026 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
39034 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
39036 Roo.each(eItems, function(b,k){
39038 b.size = (k == 0) ? 'sm' : 'xs';
39039 b.x = (k == 0) ? 2 : 1;
39040 b.y = (k == 0) ? 2 : 1;
39042 b.el.position('absolute');
39044 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
39046 b.el.setWidth(width);
39048 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
39050 b.el.setHeight(height);
39054 var positions = [];
39057 x : maxX - this.unitWidth * 2 - this.gutter,
39062 x : maxX - this.unitWidth,
39063 y : minY + (this.unitWidth + this.gutter) * 2
39067 x : maxX - this.unitWidth * 3 - this.gutter * 2,
39071 Roo.each(eItems, function(b,k){
39073 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
39079 getVerticalOneBoxColPositions : function(x, y, box)
39083 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
39085 if(box[0].size == 'md-left'){
39089 if(box[0].size == 'md-right'){
39094 x : x + (this.unitWidth + this.gutter) * rand,
39101 getVerticalTwoBoxColPositions : function(x, y, box)
39105 if(box[0].size == 'xs'){
39109 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
39113 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
39127 x : x + (this.unitWidth + this.gutter) * 2,
39128 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
39135 getVerticalThreeBoxColPositions : function(x, y, box)
39139 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
39147 x : x + (this.unitWidth + this.gutter) * 1,
39152 x : x + (this.unitWidth + this.gutter) * 2,
39160 if(box[0].size == 'xs' && box[1].size == 'xs'){
39169 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
39173 x : x + (this.unitWidth + this.gutter) * 1,
39187 x : x + (this.unitWidth + this.gutter) * 2,
39192 x : x + (this.unitWidth + this.gutter) * 2,
39193 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
39200 getVerticalFourBoxColPositions : function(x, y, box)
39204 if(box[0].size == 'xs'){
39213 y : y + (this.unitHeight + this.gutter) * 1
39218 y : y + (this.unitHeight + this.gutter) * 2
39222 x : x + (this.unitWidth + this.gutter) * 1,
39236 x : x + (this.unitWidth + this.gutter) * 2,
39241 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
39242 y : y + (this.unitHeight + this.gutter) * 1
39246 x : x + (this.unitWidth + this.gutter) * 2,
39247 y : y + (this.unitWidth + this.gutter) * 2
39254 getHorizontalOneBoxColPositions : function(maxX, minY, box)
39258 if(box[0].size == 'md-left'){
39260 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
39267 if(box[0].size == 'md-right'){
39269 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
39270 y : minY + (this.unitWidth + this.gutter) * 1
39276 var rand = Math.floor(Math.random() * (4 - box[0].y));
39279 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39280 y : minY + (this.unitWidth + this.gutter) * rand
39287 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
39291 if(box[0].size == 'xs'){
39294 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39299 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39300 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
39308 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39313 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39314 y : minY + (this.unitWidth + this.gutter) * 2
39321 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
39325 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
39328 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39333 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39334 y : minY + (this.unitWidth + this.gutter) * 1
39338 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39339 y : minY + (this.unitWidth + this.gutter) * 2
39346 if(box[0].size == 'xs' && box[1].size == 'xs'){
39349 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39354 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39359 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39360 y : minY + (this.unitWidth + this.gutter) * 1
39368 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39373 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39374 y : minY + (this.unitWidth + this.gutter) * 2
39378 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39379 y : minY + (this.unitWidth + this.gutter) * 2
39386 getHorizontalFourBoxColPositions : function(maxX, minY, box)
39390 if(box[0].size == 'xs'){
39393 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39398 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39403 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39408 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
39409 y : minY + (this.unitWidth + this.gutter) * 1
39417 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39422 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39423 y : minY + (this.unitWidth + this.gutter) * 2
39427 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39428 y : minY + (this.unitWidth + this.gutter) * 2
39432 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1) - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
39433 y : minY + (this.unitWidth + this.gutter) * 2
39441 * remove a Masonry Brick
39442 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
39444 removeBrick : function(brick_id)
39450 for (var i = 0; i<this.bricks.length; i++) {
39451 if (this.bricks[i].id == brick_id) {
39452 this.bricks.splice(i,1);
39453 this.el.dom.removeChild(Roo.get(brick_id).dom);
39460 * adds a Masonry Brick
39461 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
39463 addBrick : function(cfg)
39465 var cn = new Roo.bootstrap.MasonryBrick(cfg);
39466 //this.register(cn);
39467 cn.parentId = this.id;
39468 cn.render(this.el);
39473 * register a Masonry Brick
39474 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
39477 register : function(brick)
39479 this.bricks.push(brick);
39480 brick.masonryId = this.id;
39484 * clear all the Masonry Brick
39486 clearAll : function()
39489 //this.getChildContainer().dom.innerHTML = "";
39490 this.el.dom.innerHTML = '';
39493 getSelected : function()
39495 if (!this.selectedBrick) {
39499 return this.selectedBrick;
39503 Roo.apply(Roo.bootstrap.LayoutMasonry, {
39507 * register a Masonry Layout
39508 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
39511 register : function(layout)
39513 this.groups[layout.id] = layout;
39516 * fetch a Masonry Layout based on the masonry layout ID
39517 * @param {string} the masonry layout to add
39518 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
39521 get: function(layout_id) {
39522 if (typeof(this.groups[layout_id]) == 'undefined') {
39525 return this.groups[layout_id] ;
39537 * http://masonry.desandro.com
39539 * The idea is to render all the bricks based on vertical width...
39541 * The original code extends 'outlayer' - we might need to use that....
39547 * @class Roo.bootstrap.LayoutMasonryAuto
39548 * @extends Roo.bootstrap.Component
39549 * Bootstrap Layout Masonry class
39552 * Create a new Element
39553 * @param {Object} config The config object
39556 Roo.bootstrap.LayoutMasonryAuto = function(config){
39557 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
39560 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
39563 * @cfg {Boolean} isFitWidth - resize the width..
39565 isFitWidth : false, // options..
39567 * @cfg {Boolean} isOriginLeft = left align?
39569 isOriginLeft : true,
39571 * @cfg {Boolean} isOriginTop = top align?
39573 isOriginTop : false,
39575 * @cfg {Boolean} isLayoutInstant = no animation?
39577 isLayoutInstant : false, // needed?
39579 * @cfg {Boolean} isResizingContainer = not sure if this is used..
39581 isResizingContainer : true,
39583 * @cfg {Number} columnWidth width of the columns
39589 * @cfg {Number} maxCols maximum number of columns
39594 * @cfg {Number} padHeight padding below box..
39600 * @cfg {Boolean} isAutoInitial defalut true
39603 isAutoInitial : true,
39609 initialColumnWidth : 0,
39610 currentSize : null,
39612 colYs : null, // array.
39619 bricks: null, //CompositeElement
39620 cols : 0, // array?
39621 // element : null, // wrapped now this.el
39622 _isLayoutInited : null,
39625 getAutoCreate : function(){
39629 cls: 'blog-masonary-wrapper ' + this.cls,
39631 cls : 'mas-boxes masonary'
39638 getChildContainer: function( )
39640 if (this.boxesEl) {
39641 return this.boxesEl;
39644 this.boxesEl = this.el.select('.mas-boxes').first();
39646 return this.boxesEl;
39650 initEvents : function()
39654 if(this.isAutoInitial){
39655 Roo.log('hook children rendered');
39656 this.on('childrenrendered', function() {
39657 Roo.log('children rendered');
39664 initial : function()
39666 this.reloadItems();
39668 this.currentSize = this.el.getBox(true);
39670 /// was window resize... - let's see if this works..
39671 Roo.EventManager.onWindowResize(this.resize, this);
39673 if(!this.isAutoInitial){
39678 this.layout.defer(500,this);
39681 reloadItems: function()
39683 this.bricks = this.el.select('.masonry-brick', true);
39685 this.bricks.each(function(b) {
39686 //Roo.log(b.getSize());
39687 if (!b.attr('originalwidth')) {
39688 b.attr('originalwidth', b.getSize().width);
39693 Roo.log(this.bricks.elements.length);
39696 resize : function()
39699 var cs = this.el.getBox(true);
39701 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
39702 Roo.log("no change in with or X");
39705 this.currentSize = cs;
39709 layout : function()
39712 this._resetLayout();
39713 //this._manageStamps();
39715 // don't animate first layout
39716 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
39717 this.layoutItems( isInstant );
39719 // flag for initalized
39720 this._isLayoutInited = true;
39723 layoutItems : function( isInstant )
39725 //var items = this._getItemsForLayout( this.items );
39726 // original code supports filtering layout items.. we just ignore it..
39728 this._layoutItems( this.bricks , isInstant );
39730 this._postLayout();
39732 _layoutItems : function ( items , isInstant)
39734 //this.fireEvent( 'layout', this, items );
39737 if ( !items || !items.elements.length ) {
39738 // no items, emit event with empty array
39743 items.each(function(item) {
39744 Roo.log("layout item");
39746 // get x/y object from method
39747 var position = this._getItemLayoutPosition( item );
39749 position.item = item;
39750 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
39751 queue.push( position );
39754 this._processLayoutQueue( queue );
39756 /** Sets position of item in DOM
39757 * @param {Element} item
39758 * @param {Number} x - horizontal position
39759 * @param {Number} y - vertical position
39760 * @param {Boolean} isInstant - disables transitions
39762 _processLayoutQueue : function( queue )
39764 for ( var i=0, len = queue.length; i < len; i++ ) {
39765 var obj = queue[i];
39766 obj.item.position('absolute');
39767 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
39773 * Any logic you want to do after each layout,
39774 * i.e. size the container
39776 _postLayout : function()
39778 this.resizeContainer();
39781 resizeContainer : function()
39783 if ( !this.isResizingContainer ) {
39786 var size = this._getContainerSize();
39788 this.el.setSize(size.width,size.height);
39789 this.boxesEl.setSize(size.width,size.height);
39795 _resetLayout : function()
39797 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
39798 this.colWidth = this.el.getWidth();
39799 //this.gutter = this.el.getWidth();
39801 this.measureColumns();
39807 this.colYs.push( 0 );
39813 measureColumns : function()
39815 this.getContainerWidth();
39816 // if columnWidth is 0, default to outerWidth of first item
39817 if ( !this.columnWidth ) {
39818 var firstItem = this.bricks.first();
39819 Roo.log(firstItem);
39820 this.columnWidth = this.containerWidth;
39821 if (firstItem && firstItem.attr('originalwidth') ) {
39822 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
39824 // columnWidth fall back to item of first element
39825 Roo.log("set column width?");
39826 this.initialColumnWidth = this.columnWidth ;
39828 // if first elem has no width, default to size of container
39833 if (this.initialColumnWidth) {
39834 this.columnWidth = this.initialColumnWidth;
39839 // column width is fixed at the top - however if container width get's smaller we should
39842 // this bit calcs how man columns..
39844 var columnWidth = this.columnWidth += this.gutter;
39846 // calculate columns
39847 var containerWidth = this.containerWidth + this.gutter;
39849 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
39850 // fix rounding errors, typically with gutters
39851 var excess = columnWidth - containerWidth % columnWidth;
39854 // if overshoot is less than a pixel, round up, otherwise floor it
39855 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
39856 cols = Math[ mathMethod ]( cols );
39857 this.cols = Math.max( cols, 1 );
39858 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
39860 // padding positioning..
39861 var totalColWidth = this.cols * this.columnWidth;
39862 var padavail = this.containerWidth - totalColWidth;
39863 // so for 2 columns - we need 3 'pads'
39865 var padNeeded = (1+this.cols) * this.padWidth;
39867 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
39869 this.columnWidth += padExtra
39870 //this.padWidth = Math.floor(padavail / ( this.cols));
39872 // adjust colum width so that padding is fixed??
39874 // we have 3 columns ... total = width * 3
39875 // we have X left over... that should be used by
39877 //if (this.expandC) {
39885 getContainerWidth : function()
39887 /* // container is parent if fit width
39888 var container = this.isFitWidth ? this.element.parentNode : this.element;
39889 // check that this.size and size are there
39890 // IE8 triggers resize on body size change, so they might not be
39892 var size = getSize( container ); //FIXME
39893 this.containerWidth = size && size.innerWidth; //FIXME
39896 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
39900 _getItemLayoutPosition : function( item ) // what is item?
39902 // we resize the item to our columnWidth..
39904 item.setWidth(this.columnWidth);
39905 item.autoBoxAdjust = false;
39907 var sz = item.getSize();
39909 // how many columns does this brick span
39910 var remainder = this.containerWidth % this.columnWidth;
39912 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
39913 // round if off by 1 pixel, otherwise use ceil
39914 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
39915 colSpan = Math.min( colSpan, this.cols );
39917 // normally this should be '1' as we dont' currently allow multi width columns..
39919 var colGroup = this._getColGroup( colSpan );
39920 // get the minimum Y value from the columns
39921 var minimumY = Math.min.apply( Math, colGroup );
39922 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
39924 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
39926 // position the brick
39928 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
39929 y: this.currentSize.y + minimumY + this.padHeight
39933 // apply setHeight to necessary columns
39934 var setHeight = minimumY + sz.height + this.padHeight;
39935 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
39937 var setSpan = this.cols + 1 - colGroup.length;
39938 for ( var i = 0; i < setSpan; i++ ) {
39939 this.colYs[ shortColIndex + i ] = setHeight ;
39946 * @param {Number} colSpan - number of columns the element spans
39947 * @returns {Array} colGroup
39949 _getColGroup : function( colSpan )
39951 if ( colSpan < 2 ) {
39952 // if brick spans only one column, use all the column Ys
39957 // how many different places could this brick fit horizontally
39958 var groupCount = this.cols + 1 - colSpan;
39959 // for each group potential horizontal position
39960 for ( var i = 0; i < groupCount; i++ ) {
39961 // make an array of colY values for that one group
39962 var groupColYs = this.colYs.slice( i, i + colSpan );
39963 // and get the max value of the array
39964 colGroup[i] = Math.max.apply( Math, groupColYs );
39969 _manageStamp : function( stamp )
39971 var stampSize = stamp.getSize();
39972 var offset = stamp.getBox();
39973 // get the columns that this stamp affects
39974 var firstX = this.isOriginLeft ? offset.x : offset.right;
39975 var lastX = firstX + stampSize.width;
39976 var firstCol = Math.floor( firstX / this.columnWidth );
39977 firstCol = Math.max( 0, firstCol );
39979 var lastCol = Math.floor( lastX / this.columnWidth );
39980 // lastCol should not go over if multiple of columnWidth #425
39981 lastCol -= lastX % this.columnWidth ? 0 : 1;
39982 lastCol = Math.min( this.cols - 1, lastCol );
39984 // set colYs to bottom of the stamp
39985 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
39988 for ( var i = firstCol; i <= lastCol; i++ ) {
39989 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
39994 _getContainerSize : function()
39996 this.maxY = Math.max.apply( Math, this.colYs );
40001 if ( this.isFitWidth ) {
40002 size.width = this._getContainerFitWidth();
40008 _getContainerFitWidth : function()
40010 var unusedCols = 0;
40011 // count unused columns
40014 if ( this.colYs[i] !== 0 ) {
40019 // fit container to columns that have been used
40020 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
40023 needsResizeLayout : function()
40025 var previousWidth = this.containerWidth;
40026 this.getContainerWidth();
40027 return previousWidth !== this.containerWidth;
40042 * @class Roo.bootstrap.MasonryBrick
40043 * @extends Roo.bootstrap.Component
40044 * Bootstrap MasonryBrick class
40047 * Create a new MasonryBrick
40048 * @param {Object} config The config object
40051 Roo.bootstrap.MasonryBrick = function(config){
40053 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
40055 Roo.bootstrap.MasonryBrick.register(this);
40061 * When a MasonryBrick is clcik
40062 * @param {Roo.bootstrap.MasonryBrick} this
40063 * @param {Roo.EventObject} e
40069 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
40072 * @cfg {String} title
40076 * @cfg {String} html
40080 * @cfg {String} bgimage
40084 * @cfg {String} videourl
40088 * @cfg {String} cls
40092 * @cfg {String} href
40096 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
40101 * @cfg {String} placetitle (center|bottom)
40106 * @cfg {Boolean} isFitContainer defalut true
40108 isFitContainer : true,
40111 * @cfg {Boolean} preventDefault defalut false
40113 preventDefault : false,
40116 * @cfg {Boolean} inverse defalut false
40118 maskInverse : false,
40120 getAutoCreate : function()
40122 if(!this.isFitContainer){
40123 return this.getSplitAutoCreate();
40126 var cls = 'masonry-brick masonry-brick-full';
40128 if(this.href.length){
40129 cls += ' masonry-brick-link';
40132 if(this.bgimage.length){
40133 cls += ' masonry-brick-image';
40136 if(this.maskInverse){
40137 cls += ' mask-inverse';
40140 if(!this.html.length && !this.maskInverse && !this.videourl.length){
40141 cls += ' enable-mask';
40145 cls += ' masonry-' + this.size + '-brick';
40148 if(this.placetitle.length){
40150 switch (this.placetitle) {
40152 cls += ' masonry-center-title';
40155 cls += ' masonry-bottom-title';
40162 if(!this.html.length && !this.bgimage.length){
40163 cls += ' masonry-center-title';
40166 if(!this.html.length && this.bgimage.length){
40167 cls += ' masonry-bottom-title';
40172 cls += ' ' + this.cls;
40176 tag: (this.href.length) ? 'a' : 'div',
40181 cls: 'masonry-brick-mask'
40185 cls: 'masonry-brick-paragraph',
40191 if(this.href.length){
40192 cfg.href = this.href;
40195 var cn = cfg.cn[1].cn;
40197 if(this.title.length){
40200 cls: 'masonry-brick-title',
40205 if(this.html.length){
40208 cls: 'masonry-brick-text',
40213 if (!this.title.length && !this.html.length) {
40214 cfg.cn[1].cls += ' hide';
40217 if(this.bgimage.length){
40220 cls: 'masonry-brick-image-view',
40225 if(this.videourl.length){
40226 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
40227 // youtube support only?
40230 cls: 'masonry-brick-image-view',
40233 allowfullscreen : true
40241 getSplitAutoCreate : function()
40243 var cls = 'masonry-brick masonry-brick-split';
40245 if(this.href.length){
40246 cls += ' masonry-brick-link';
40249 if(this.bgimage.length){
40250 cls += ' masonry-brick-image';
40254 cls += ' masonry-' + this.size + '-brick';
40257 switch (this.placetitle) {
40259 cls += ' masonry-center-title';
40262 cls += ' masonry-bottom-title';
40265 if(!this.bgimage.length){
40266 cls += ' masonry-center-title';
40269 if(this.bgimage.length){
40270 cls += ' masonry-bottom-title';
40276 cls += ' ' + this.cls;
40280 tag: (this.href.length) ? 'a' : 'div',
40285 cls: 'masonry-brick-split-head',
40289 cls: 'masonry-brick-paragraph',
40296 cls: 'masonry-brick-split-body',
40302 if(this.href.length){
40303 cfg.href = this.href;
40306 if(this.title.length){
40307 cfg.cn[0].cn[0].cn.push({
40309 cls: 'masonry-brick-title',
40314 if(this.html.length){
40315 cfg.cn[1].cn.push({
40317 cls: 'masonry-brick-text',
40322 if(this.bgimage.length){
40323 cfg.cn[0].cn.push({
40325 cls: 'masonry-brick-image-view',
40330 if(this.videourl.length){
40331 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
40332 // youtube support only?
40333 cfg.cn[0].cn.cn.push({
40335 cls: 'masonry-brick-image-view',
40338 allowfullscreen : true
40345 initEvents: function()
40347 switch (this.size) {
40380 this.el.on('touchstart', this.onTouchStart, this);
40381 this.el.on('touchmove', this.onTouchMove, this);
40382 this.el.on('touchend', this.onTouchEnd, this);
40383 this.el.on('contextmenu', this.onContextMenu, this);
40385 this.el.on('mouseenter' ,this.enter, this);
40386 this.el.on('mouseleave', this.leave, this);
40387 this.el.on('click', this.onClick, this);
40390 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
40391 this.parent().bricks.push(this);
40396 onClick: function(e, el)
40398 var time = this.endTimer - this.startTimer;
40399 // Roo.log(e.preventDefault());
40402 e.preventDefault();
40407 if(!this.preventDefault){
40411 e.preventDefault();
40413 if (this.activeClass != '') {
40414 this.selectBrick();
40417 this.fireEvent('click', this, e);
40420 enter: function(e, el)
40422 e.preventDefault();
40424 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
40428 if(this.bgimage.length && this.html.length){
40429 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
40433 leave: function(e, el)
40435 e.preventDefault();
40437 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
40441 if(this.bgimage.length && this.html.length){
40442 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
40446 onTouchStart: function(e, el)
40448 // e.preventDefault();
40450 this.touchmoved = false;
40452 if(!this.isFitContainer){
40456 if(!this.bgimage.length || !this.html.length){
40460 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
40462 this.timer = new Date().getTime();
40466 onTouchMove: function(e, el)
40468 this.touchmoved = true;
40471 onContextMenu : function(e,el)
40473 e.preventDefault();
40474 e.stopPropagation();
40478 onTouchEnd: function(e, el)
40480 // e.preventDefault();
40482 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
40489 if(!this.bgimage.length || !this.html.length){
40491 if(this.href.length){
40492 window.location.href = this.href;
40498 if(!this.isFitContainer){
40502 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
40504 window.location.href = this.href;
40507 //selection on single brick only
40508 selectBrick : function() {
40510 if (!this.parentId) {
40514 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
40515 var index = m.selectedBrick.indexOf(this.id);
40518 m.selectedBrick.splice(index,1);
40519 this.el.removeClass(this.activeClass);
40523 for(var i = 0; i < m.selectedBrick.length; i++) {
40524 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
40525 b.el.removeClass(b.activeClass);
40528 m.selectedBrick = [];
40530 m.selectedBrick.push(this.id);
40531 this.el.addClass(this.activeClass);
40535 isSelected : function(){
40536 return this.el.hasClass(this.activeClass);
40541 Roo.apply(Roo.bootstrap.MasonryBrick, {
40544 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
40546 * register a Masonry Brick
40547 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
40550 register : function(brick)
40552 //this.groups[brick.id] = brick;
40553 this.groups.add(brick.id, brick);
40556 * fetch a masonry brick based on the masonry brick ID
40557 * @param {string} the masonry brick to add
40558 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
40561 get: function(brick_id)
40563 // if (typeof(this.groups[brick_id]) == 'undefined') {
40566 // return this.groups[brick_id] ;
40568 if(this.groups.key(brick_id)) {
40569 return this.groups.key(brick_id);
40587 * @class Roo.bootstrap.Brick
40588 * @extends Roo.bootstrap.Component
40589 * Bootstrap Brick class
40592 * Create a new Brick
40593 * @param {Object} config The config object
40596 Roo.bootstrap.Brick = function(config){
40597 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
40603 * When a Brick is click
40604 * @param {Roo.bootstrap.Brick} this
40605 * @param {Roo.EventObject} e
40611 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
40614 * @cfg {String} title
40618 * @cfg {String} html
40622 * @cfg {String} bgimage
40626 * @cfg {String} cls
40630 * @cfg {String} href
40634 * @cfg {String} video
40638 * @cfg {Boolean} square
40642 getAutoCreate : function()
40644 var cls = 'roo-brick';
40646 if(this.href.length){
40647 cls += ' roo-brick-link';
40650 if(this.bgimage.length){
40651 cls += ' roo-brick-image';
40654 if(!this.html.length && !this.bgimage.length){
40655 cls += ' roo-brick-center-title';
40658 if(!this.html.length && this.bgimage.length){
40659 cls += ' roo-brick-bottom-title';
40663 cls += ' ' + this.cls;
40667 tag: (this.href.length) ? 'a' : 'div',
40672 cls: 'roo-brick-paragraph',
40678 if(this.href.length){
40679 cfg.href = this.href;
40682 var cn = cfg.cn[0].cn;
40684 if(this.title.length){
40687 cls: 'roo-brick-title',
40692 if(this.html.length){
40695 cls: 'roo-brick-text',
40702 if(this.bgimage.length){
40705 cls: 'roo-brick-image-view',
40713 initEvents: function()
40715 if(this.title.length || this.html.length){
40716 this.el.on('mouseenter' ,this.enter, this);
40717 this.el.on('mouseleave', this.leave, this);
40720 Roo.EventManager.onWindowResize(this.resize, this);
40722 if(this.bgimage.length){
40723 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
40724 this.imageEl.on('load', this.onImageLoad, this);
40731 onImageLoad : function()
40736 resize : function()
40738 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
40740 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
40742 if(this.bgimage.length){
40743 var image = this.el.select('.roo-brick-image-view', true).first();
40745 image.setWidth(paragraph.getWidth());
40748 image.setHeight(paragraph.getWidth());
40751 this.el.setHeight(image.getHeight());
40752 paragraph.setHeight(image.getHeight());
40758 enter: function(e, el)
40760 e.preventDefault();
40762 if(this.bgimage.length){
40763 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
40764 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
40768 leave: function(e, el)
40770 e.preventDefault();
40772 if(this.bgimage.length){
40773 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
40774 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
40789 * @class Roo.bootstrap.form.NumberField
40790 * @extends Roo.bootstrap.form.Input
40791 * Bootstrap NumberField class
40797 * Create a new NumberField
40798 * @param {Object} config The config object
40801 Roo.bootstrap.form.NumberField = function(config){
40802 Roo.bootstrap.form.NumberField.superclass.constructor.call(this, config);
40805 Roo.extend(Roo.bootstrap.form.NumberField, Roo.bootstrap.form.Input, {
40808 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40810 allowDecimals : true,
40812 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40814 decimalSeparator : ".",
40816 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40818 decimalPrecision : 2,
40820 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40822 allowNegative : true,
40825 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40829 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40831 minValue : Number.NEGATIVE_INFINITY,
40833 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40835 maxValue : Number.MAX_VALUE,
40837 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40839 minText : "The minimum value for this field is {0}",
40841 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40843 maxText : "The maximum value for this field is {0}",
40845 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40846 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40848 nanText : "{0} is not a valid number",
40850 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40852 thousandsDelimiter : false,
40854 * @cfg {String} valueAlign alignment of value
40856 valueAlign : "left",
40858 getAutoCreate : function()
40860 var hiddenInput = {
40864 cls: 'hidden-number-input'
40868 hiddenInput.name = this.name;
40873 var cfg = Roo.bootstrap.form.NumberField.superclass.getAutoCreate.call(this);
40875 this.name = hiddenInput.name;
40877 if(cfg.cn.length > 0) {
40878 cfg.cn.push(hiddenInput);
40885 initEvents : function()
40887 Roo.bootstrap.form.NumberField.superclass.initEvents.call(this);
40889 var allowed = "0123456789";
40891 if(this.allowDecimals){
40892 allowed += this.decimalSeparator;
40895 if(this.allowNegative){
40899 if(this.thousandsDelimiter) {
40903 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40905 var keyPress = function(e){
40907 var k = e.getKey();
40909 var c = e.getCharCode();
40912 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40913 allowed.indexOf(String.fromCharCode(c)) === -1
40919 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40923 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40928 this.el.on("keypress", keyPress, this);
40931 validateValue : function(value)
40934 if(!Roo.bootstrap.form.NumberField.superclass.validateValue.call(this, value)){
40938 var num = this.parseValue(value);
40941 this.markInvalid(String.format(this.nanText, value));
40945 if(num < this.minValue){
40946 this.markInvalid(String.format(this.minText, this.minValue));
40950 if(num > this.maxValue){
40951 this.markInvalid(String.format(this.maxText, this.maxValue));
40958 getValue : function()
40960 var v = this.hiddenEl().getValue();
40962 return this.fixPrecision(this.parseValue(v));
40965 parseValue : function(value)
40967 if(this.thousandsDelimiter) {
40969 r = new RegExp(",", "g");
40970 value = value.replace(r, "");
40973 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
40974 return isNaN(value) ? '' : value;
40977 fixPrecision : function(value)
40979 if(this.thousandsDelimiter) {
40981 r = new RegExp(",", "g");
40982 value = value.replace(r, "");
40985 var nan = isNaN(value);
40987 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
40988 return nan ? '' : value;
40990 return parseFloat(value).toFixed(this.decimalPrecision);
40993 setValue : function(v)
40995 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
41001 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
41003 this.inputEl().dom.value = (v == '') ? '' :
41004 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
41006 if(!this.allowZero && v === '0') {
41007 this.hiddenEl().dom.value = '';
41008 this.inputEl().dom.value = '';
41015 decimalPrecisionFcn : function(v)
41017 return Math.floor(v);
41020 beforeBlur : function()
41022 var v = this.parseValue(this.getRawValue());
41024 if(v || v === 0 || v === ''){
41029 hiddenEl : function()
41031 return this.el.select('input.hidden-number-input',true).first();
41043 * @class Roo.bootstrap.DocumentSlider
41044 * @extends Roo.bootstrap.Component
41045 * Bootstrap DocumentSlider class
41048 * Create a new DocumentViewer
41049 * @param {Object} config The config object
41052 Roo.bootstrap.DocumentSlider = function(config){
41053 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
41060 * Fire after initEvent
41061 * @param {Roo.bootstrap.DocumentSlider} this
41066 * Fire after update
41067 * @param {Roo.bootstrap.DocumentSlider} this
41073 * @param {Roo.bootstrap.DocumentSlider} this
41079 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
41085 getAutoCreate : function()
41089 cls : 'roo-document-slider',
41093 cls : 'roo-document-slider-header',
41097 cls : 'roo-document-slider-header-title'
41103 cls : 'roo-document-slider-body',
41107 cls : 'roo-document-slider-prev',
41111 cls : 'fa fa-chevron-left'
41117 cls : 'roo-document-slider-thumb',
41121 cls : 'roo-document-slider-image'
41127 cls : 'roo-document-slider-next',
41131 cls : 'fa fa-chevron-right'
41143 initEvents : function()
41145 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
41146 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
41148 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
41149 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
41151 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
41152 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
41154 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
41155 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
41157 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
41158 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
41160 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
41161 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
41163 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
41164 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
41166 this.thumbEl.on('click', this.onClick, this);
41168 this.prevIndicator.on('click', this.prev, this);
41170 this.nextIndicator.on('click', this.next, this);
41174 initial : function()
41176 if(this.files.length){
41177 this.indicator = 1;
41181 this.fireEvent('initial', this);
41184 update : function()
41186 this.imageEl.attr('src', this.files[this.indicator - 1]);
41188 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
41190 this.prevIndicator.show();
41192 if(this.indicator == 1){
41193 this.prevIndicator.hide();
41196 this.nextIndicator.show();
41198 if(this.indicator == this.files.length){
41199 this.nextIndicator.hide();
41202 this.thumbEl.scrollTo('top');
41204 this.fireEvent('update', this);
41207 onClick : function(e)
41209 e.preventDefault();
41211 this.fireEvent('click', this);
41216 e.preventDefault();
41218 this.indicator = Math.max(1, this.indicator - 1);
41225 e.preventDefault();
41227 this.indicator = Math.min(this.files.length, this.indicator + 1);
41241 * @class Roo.bootstrap.form.RadioSet
41242 * @extends Roo.bootstrap.form.Input
41243 * @children Roo.bootstrap.form.Radio
41244 * Bootstrap RadioSet class
41245 * @cfg {String} indicatorpos (left|right) default left
41246 * @cfg {Boolean} inline (true|false) inline the element (default true)
41247 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
41249 * Create a new RadioSet
41250 * @param {Object} config The config object
41253 Roo.bootstrap.form.RadioSet = function(config){
41255 Roo.bootstrap.form.RadioSet.superclass.constructor.call(this, config);
41259 Roo.bootstrap.form.RadioSet.register(this);
41264 * Fires when the element is checked or unchecked.
41265 * @param {Roo.bootstrap.form.RadioSet} this This radio
41266 * @param {Roo.bootstrap.form.Radio} item The checked item
41271 * Fires when the element is click.
41272 * @param {Roo.bootstrap.form.RadioSet} this This radio set
41273 * @param {Roo.bootstrap.form.Radio} item The checked item
41274 * @param {Roo.EventObject} e The event object
41281 Roo.extend(Roo.bootstrap.form.RadioSet, Roo.bootstrap.form.Input, {
41289 indicatorpos : 'left',
41291 getAutoCreate : function()
41295 cls : 'roo-radio-set-label',
41299 html : this.fieldLabel
41303 if (Roo.bootstrap.version == 3) {
41306 if(this.indicatorpos == 'left'){
41309 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
41310 tooltip : 'This field is required'
41315 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
41316 tooltip : 'This field is required'
41322 cls : 'roo-radio-set-items'
41325 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
41327 if (align === 'left' && this.fieldLabel.length) {
41330 cls : "roo-radio-set-right",
41336 if(this.labelWidth > 12){
41337 label.style = "width: " + this.labelWidth + 'px';
41340 if(this.labelWidth < 13 && this.labelmd == 0){
41341 this.labelmd = this.labelWidth;
41344 if(this.labellg > 0){
41345 label.cls += ' col-lg-' + this.labellg;
41346 items.cls += ' col-lg-' + (12 - this.labellg);
41349 if(this.labelmd > 0){
41350 label.cls += ' col-md-' + this.labelmd;
41351 items.cls += ' col-md-' + (12 - this.labelmd);
41354 if(this.labelsm > 0){
41355 label.cls += ' col-sm-' + this.labelsm;
41356 items.cls += ' col-sm-' + (12 - this.labelsm);
41359 if(this.labelxs > 0){
41360 label.cls += ' col-xs-' + this.labelxs;
41361 items.cls += ' col-xs-' + (12 - this.labelxs);
41367 cls : 'roo-radio-set',
41371 cls : 'roo-radio-set-input',
41374 value : this.value ? this.value : ''
41381 if(this.weight.length){
41382 cfg.cls += ' roo-radio-' + this.weight;
41386 cfg.cls += ' roo-radio-set-inline';
41390 ['xs','sm','md','lg'].map(function(size){
41391 if (settings[size]) {
41392 cfg.cls += ' col-' + size + '-' + settings[size];
41400 initEvents : function()
41402 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
41403 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
41405 if(!this.fieldLabel.length){
41406 this.labelEl.hide();
41409 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
41410 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
41412 this.indicator = this.indicatorEl();
41414 if(this.indicator){
41415 this.indicator.addClass('invisible');
41418 this.originalValue = this.getValue();
41422 inputEl: function ()
41424 return this.el.select('.roo-radio-set-input', true).first();
41427 getChildContainer : function()
41429 return this.itemsEl;
41432 register : function(item)
41434 this.radioes.push(item);
41438 validate : function()
41440 if(this.getVisibilityEl().hasClass('hidden')){
41446 Roo.each(this.radioes, function(i){
41455 if(this.allowBlank) {
41459 if(this.disabled || valid){
41464 this.markInvalid();
41469 markValid : function()
41471 if(this.labelEl.isVisible(true) && this.indicatorEl()){
41472 this.indicatorEl().removeClass('visible');
41473 this.indicatorEl().addClass('invisible');
41477 if (Roo.bootstrap.version == 3) {
41478 this.el.removeClass([this.invalidClass, this.validClass]);
41479 this.el.addClass(this.validClass);
41481 this.el.removeClass(['is-invalid','is-valid']);
41482 this.el.addClass(['is-valid']);
41484 this.fireEvent('valid', this);
41487 markInvalid : function(msg)
41489 if(this.allowBlank || this.disabled){
41493 if(this.labelEl.isVisible(true) && this.indicatorEl()){
41494 this.indicatorEl().removeClass('invisible');
41495 this.indicatorEl().addClass('visible');
41497 if (Roo.bootstrap.version == 3) {
41498 this.el.removeClass([this.invalidClass, this.validClass]);
41499 this.el.addClass(this.invalidClass);
41501 this.el.removeClass(['is-invalid','is-valid']);
41502 this.el.addClass(['is-invalid']);
41505 this.fireEvent('invalid', this, msg);
41509 setValue : function(v, suppressEvent)
41511 if(this.value === v){
41518 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
41521 Roo.each(this.radioes, function(i){
41523 i.el.removeClass('checked');
41526 Roo.each(this.radioes, function(i){
41528 if(i.value === v || i.value.toString() === v.toString()){
41530 i.el.addClass('checked');
41532 if(suppressEvent !== true){
41533 this.fireEvent('check', this, i);
41544 clearInvalid : function(){
41546 if(!this.el || this.preventMark){
41550 this.el.removeClass([this.invalidClass]);
41552 this.fireEvent('valid', this);
41557 Roo.apply(Roo.bootstrap.form.RadioSet, {
41561 register : function(set)
41563 this.groups[set.name] = set;
41566 get: function(name)
41568 if (typeof(this.groups[name]) == 'undefined') {
41572 return this.groups[name] ;
41578 * Ext JS Library 1.1.1
41579 * Copyright(c) 2006-2007, Ext JS, LLC.
41581 * Originally Released Under LGPL - original licence link has changed is not relivant.
41584 * <script type="text/javascript">
41589 * @class Roo.bootstrap.SplitBar
41590 * @extends Roo.util.Observable
41591 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
41595 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
41596 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
41597 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
41598 split.minSize = 100;
41599 split.maxSize = 600;
41600 split.animate = true;
41601 split.on('moved', splitterMoved);
41604 * Create a new SplitBar
41605 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
41606 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
41607 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
41608 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
41609 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
41610 position of the SplitBar).
41612 Roo.bootstrap.SplitBar = function(cfg){
41617 // dragElement : elm
41618 // resizingElement: el,
41620 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
41621 // placement : Roo.bootstrap.SplitBar.LEFT ,
41622 // existingProxy ???
41625 this.el = Roo.get(cfg.dragElement, true);
41626 this.el.dom.unselectable = "on";
41628 this.resizingEl = Roo.get(cfg.resizingElement, true);
41632 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
41633 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
41636 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
41639 * The minimum size of the resizing element. (Defaults to 0)
41645 * The maximum size of the resizing element. (Defaults to 2000)
41648 this.maxSize = 2000;
41651 * Whether to animate the transition to the new size
41654 this.animate = false;
41657 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
41660 this.useShim = false;
41665 if(!cfg.existingProxy){
41667 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
41669 this.proxy = Roo.get(cfg.existingProxy).dom;
41672 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
41675 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
41678 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
41681 this.dragSpecs = {};
41684 * @private The adapter to use to positon and resize elements
41686 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
41687 this.adapter.init(this);
41689 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41691 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
41692 this.el.addClass("roo-splitbar-h");
41695 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
41696 this.el.addClass("roo-splitbar-v");
41702 * Fires when the splitter is moved (alias for {@link #event-moved})
41703 * @param {Roo.bootstrap.SplitBar} this
41704 * @param {Number} newSize the new width or height
41709 * Fires when the splitter is moved
41710 * @param {Roo.bootstrap.SplitBar} this
41711 * @param {Number} newSize the new width or height
41715 * @event beforeresize
41716 * Fires before the splitter is dragged
41717 * @param {Roo.bootstrap.SplitBar} this
41719 "beforeresize" : true,
41721 "beforeapply" : true
41724 Roo.util.Observable.call(this);
41727 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
41728 onStartProxyDrag : function(x, y){
41729 this.fireEvent("beforeresize", this);
41731 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
41733 o.enableDisplayMode("block");
41734 // all splitbars share the same overlay
41735 Roo.bootstrap.SplitBar.prototype.overlay = o;
41737 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
41738 this.overlay.show();
41739 Roo.get(this.proxy).setDisplayed("block");
41740 var size = this.adapter.getElementSize(this);
41741 this.activeMinSize = this.getMinimumSize();;
41742 this.activeMaxSize = this.getMaximumSize();;
41743 var c1 = size - this.activeMinSize;
41744 var c2 = Math.max(this.activeMaxSize - size, 0);
41745 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41746 this.dd.resetConstraints();
41747 this.dd.setXConstraint(
41748 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
41749 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
41751 this.dd.setYConstraint(0, 0);
41753 this.dd.resetConstraints();
41754 this.dd.setXConstraint(0, 0);
41755 this.dd.setYConstraint(
41756 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
41757 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
41760 this.dragSpecs.startSize = size;
41761 this.dragSpecs.startPoint = [x, y];
41762 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
41766 * @private Called after the drag operation by the DDProxy
41768 onEndProxyDrag : function(e){
41769 Roo.get(this.proxy).setDisplayed(false);
41770 var endPoint = Roo.lib.Event.getXY(e);
41772 this.overlay.hide();
41775 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41776 newSize = this.dragSpecs.startSize +
41777 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
41778 endPoint[0] - this.dragSpecs.startPoint[0] :
41779 this.dragSpecs.startPoint[0] - endPoint[0]
41782 newSize = this.dragSpecs.startSize +
41783 (this.placement == Roo.bootstrap.SplitBar.TOP ?
41784 endPoint[1] - this.dragSpecs.startPoint[1] :
41785 this.dragSpecs.startPoint[1] - endPoint[1]
41788 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
41789 if(newSize != this.dragSpecs.startSize){
41790 if(this.fireEvent('beforeapply', this, newSize) !== false){
41791 this.adapter.setElementSize(this, newSize);
41792 this.fireEvent("moved", this, newSize);
41793 this.fireEvent("resize", this, newSize);
41799 * Get the adapter this SplitBar uses
41800 * @return The adapter object
41802 getAdapter : function(){
41803 return this.adapter;
41807 * Set the adapter this SplitBar uses
41808 * @param {Object} adapter A SplitBar adapter object
41810 setAdapter : function(adapter){
41811 this.adapter = adapter;
41812 this.adapter.init(this);
41816 * Gets the minimum size for the resizing element
41817 * @return {Number} The minimum size
41819 getMinimumSize : function(){
41820 return this.minSize;
41824 * Sets the minimum size for the resizing element
41825 * @param {Number} minSize The minimum size
41827 setMinimumSize : function(minSize){
41828 this.minSize = minSize;
41832 * Gets the maximum size for the resizing element
41833 * @return {Number} The maximum size
41835 getMaximumSize : function(){
41836 return this.maxSize;
41840 * Sets the maximum size for the resizing element
41841 * @param {Number} maxSize The maximum size
41843 setMaximumSize : function(maxSize){
41844 this.maxSize = maxSize;
41848 * Sets the initialize size for the resizing element
41849 * @param {Number} size The initial size
41851 setCurrentSize : function(size){
41852 var oldAnimate = this.animate;
41853 this.animate = false;
41854 this.adapter.setElementSize(this, size);
41855 this.animate = oldAnimate;
41859 * Destroy this splitbar.
41860 * @param {Boolean} removeEl True to remove the element
41862 destroy : function(removeEl){
41864 this.shim.remove();
41867 this.proxy.parentNode.removeChild(this.proxy);
41875 * @private static Create our own proxy element element. So it will be the same same size on all browsers, we won't use borders. Instead we use a background color.
41877 Roo.bootstrap.SplitBar.createProxy = function(dir){
41878 var proxy = new Roo.Element(document.createElement("div"));
41879 proxy.unselectable();
41880 var cls = 'roo-splitbar-proxy';
41881 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
41882 document.body.appendChild(proxy.dom);
41887 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
41888 * Default Adapter. It assumes the splitter and resizing element are not positioned
41889 * elements and only gets/sets the width of the element. Generally used for table based layouts.
41891 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
41894 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
41895 // do nothing for now
41896 init : function(s){
41900 * Called before drag operations to get the current size of the resizing element.
41901 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
41903 getElementSize : function(s){
41904 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41905 return s.resizingEl.getWidth();
41907 return s.resizingEl.getHeight();
41912 * Called after drag operations to set the size of the resizing element.
41913 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
41914 * @param {Number} newSize The new size to set
41915 * @param {Function} onComplete A function to be invoked when resizing is complete
41917 setElementSize : function(s, newSize, onComplete){
41918 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41920 s.resizingEl.setWidth(newSize);
41922 onComplete(s, newSize);
41925 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
41930 s.resizingEl.setHeight(newSize);
41932 onComplete(s, newSize);
41935 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
41942 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
41943 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
41944 * Adapter that moves the splitter element to align with the resized sizing element.
41945 * Used with an absolute positioned SplitBar.
41946 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
41947 * document.body, make sure you assign an id to the body element.
41949 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
41950 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
41951 this.container = Roo.get(container);
41954 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
41955 init : function(s){
41956 this.basic.init(s);
41959 getElementSize : function(s){
41960 return this.basic.getElementSize(s);
41963 setElementSize : function(s, newSize, onComplete){
41964 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
41967 moveSplitter : function(s){
41968 var yes = Roo.bootstrap.SplitBar;
41969 switch(s.placement){
41971 s.el.setX(s.resizingEl.getRight());
41974 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
41977 s.el.setY(s.resizingEl.getBottom());
41980 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
41987 * Orientation constant - Create a vertical SplitBar
41991 Roo.bootstrap.SplitBar.VERTICAL = 1;
41994 * Orientation constant - Create a horizontal SplitBar
41998 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
42001 * Placement constant - The resizing element is to the left of the splitter element
42005 Roo.bootstrap.SplitBar.LEFT = 1;
42008 * Placement constant - The resizing element is to the right of the splitter element
42012 Roo.bootstrap.SplitBar.RIGHT = 2;
42015 * Placement constant - The resizing element is positioned above the splitter element
42019 Roo.bootstrap.SplitBar.TOP = 3;
42022 * Placement constant - The resizing element is positioned under splitter element
42026 Roo.bootstrap.SplitBar.BOTTOM = 4;
42029 * Ext JS Library 1.1.1
42030 * Copyright(c) 2006-2007, Ext JS, LLC.
42032 * Originally Released Under LGPL - original licence link has changed is not relivant.
42035 * <script type="text/javascript">
42039 * @class Roo.bootstrap.layout.Manager
42040 * @extends Roo.bootstrap.Component
42042 * Base class for layout managers.
42044 Roo.bootstrap.layout.Manager = function(config)
42046 this.monitorWindowResize = true; // do this before we apply configuration.
42048 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
42054 /** false to disable window resize monitoring @type Boolean */
42060 * Fires when a layout is performed.
42061 * @param {Roo.LayoutManager} this
42065 * @event regionresized
42066 * Fires when the user resizes a region.
42067 * @param {Roo.LayoutRegion} region The resized region
42068 * @param {Number} newSize The new size (width for east/west, height for north/south)
42070 "regionresized" : true,
42072 * @event regioncollapsed
42073 * Fires when a region is collapsed.
42074 * @param {Roo.LayoutRegion} region The collapsed region
42076 "regioncollapsed" : true,
42078 * @event regionexpanded
42079 * Fires when a region is expanded.
42080 * @param {Roo.LayoutRegion} region The expanded region
42082 "regionexpanded" : true
42084 this.updating = false;
42087 this.el = Roo.get(config.el);
42093 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
42098 monitorWindowResize : true,
42104 onRender : function(ct, position)
42107 this.el = Roo.get(ct);
42110 //this.fireEvent('render',this);
42114 initEvents: function()
42118 // ie scrollbar fix
42119 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
42120 document.body.scroll = "no";
42121 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
42122 this.el.position('relative');
42124 this.id = this.el.id;
42125 this.el.addClass("roo-layout-container");
42126 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
42127 if(this.el.dom != document.body ) {
42128 this.el.on('resize', this.layout,this);
42129 this.el.on('show', this.layout,this);
42135 * Returns true if this layout is currently being updated
42136 * @return {Boolean}
42138 isUpdating : function(){
42139 return this.updating;
42143 * Suspend the LayoutManager from doing auto-layouts while
42144 * making multiple add or remove calls
42146 beginUpdate : function(){
42147 this.updating = true;
42151 * Restore auto-layouts and optionally disable the manager from performing a layout
42152 * @param {Boolean} noLayout true to disable a layout update
42154 endUpdate : function(noLayout){
42155 this.updating = false;
42161 layout: function(){
42165 onRegionResized : function(region, newSize){
42166 this.fireEvent("regionresized", region, newSize);
42170 onRegionCollapsed : function(region){
42171 this.fireEvent("regioncollapsed", region);
42174 onRegionExpanded : function(region){
42175 this.fireEvent("regionexpanded", region);
42179 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
42180 * performs box-model adjustments.
42181 * @return {Object} The size as an object {width: (the width), height: (the height)}
42183 getViewSize : function()
42186 if(this.el.dom != document.body){
42187 size = this.el.getSize();
42189 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
42191 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
42192 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
42197 * Returns the Element this layout is bound to.
42198 * @return {Roo.Element}
42200 getEl : function(){
42205 * Returns the specified region.
42206 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
42207 * @return {Roo.LayoutRegion}
42209 getRegion : function(target){
42210 return this.regions[target.toLowerCase()];
42213 onWindowResize : function(){
42214 if(this.monitorWindowResize){
42221 * Ext JS Library 1.1.1
42222 * Copyright(c) 2006-2007, Ext JS, LLC.
42224 * Originally Released Under LGPL - original licence link has changed is not relivant.
42227 * <script type="text/javascript">
42230 * @class Roo.bootstrap.layout.Border
42231 * @extends Roo.bootstrap.layout.Manager
42232 * @children Roo.bootstrap.panel.Content Roo.bootstrap.panel.Nest Roo.bootstrap.panel.Grid
42233 * @parent builder Roo.bootstrap.panel.Nest Roo.bootstrap.panel.Nest Roo.bootstrap.Modal
42234 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
42235 * please see: examples/bootstrap/nested.html<br><br>
42237 <b>The container the layout is rendered into can be either the body element or any other element.
42238 If it is not the body element, the container needs to either be an absolute positioned element,
42239 or you will need to add "position:relative" to the css of the container. You will also need to specify
42240 the container size if it is not the body element.</b>
42243 * Create a new Border
42244 * @param {Object} config Configuration options
42246 Roo.bootstrap.layout.Border = function(config){
42247 config = config || {};
42248 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
42252 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
42253 if(config[region]){
42254 config[region].region = region;
42255 this.addRegion(config[region]);
42261 Roo.bootstrap.layout.Border.regions = ["center", "north","south","east","west"];
42263 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
42266 * @cfg {Roo.bootstrap.layout.Region} center region to go in center
42269 * @cfg {Roo.bootstrap.layout.Region} west region to go in west
42272 * @cfg {Roo.bootstrap.layout.Region} east region to go in east
42275 * @cfg {Roo.bootstrap.layout.Region} south region to go in south
42278 * @cfg {Roo.bootstrap.layout.Region} north region to go in north
42284 parent : false, // this might point to a 'nest' or a ???
42287 * Creates and adds a new region if it doesn't already exist.
42288 * @param {String} target The target region key (north, south, east, west or center).
42289 * @param {Object} config The regions config object
42290 * @return {BorderLayoutRegion} The new region
42292 addRegion : function(config)
42294 if(!this.regions[config.region]){
42295 var r = this.factory(config);
42296 this.bindRegion(r);
42298 return this.regions[config.region];
42302 bindRegion : function(r){
42303 this.regions[r.config.region] = r;
42305 r.on("visibilitychange", this.layout, this);
42306 r.on("paneladded", this.layout, this);
42307 r.on("panelremoved", this.layout, this);
42308 r.on("invalidated", this.layout, this);
42309 r.on("resized", this.onRegionResized, this);
42310 r.on("collapsed", this.onRegionCollapsed, this);
42311 r.on("expanded", this.onRegionExpanded, this);
42315 * Performs a layout update.
42317 layout : function()
42319 if(this.updating) {
42323 // render all the rebions if they have not been done alreayd?
42324 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
42325 if(this.regions[region] && !this.regions[region].bodyEl){
42326 this.regions[region].onRender(this.el)
42330 var size = this.getViewSize();
42331 var w = size.width;
42332 var h = size.height;
42337 //var x = 0, y = 0;
42339 var rs = this.regions;
42340 var north = rs["north"];
42341 var south = rs["south"];
42342 var west = rs["west"];
42343 var east = rs["east"];
42344 var center = rs["center"];
42345 //if(this.hideOnLayout){ // not supported anymore
42346 //c.el.setStyle("display", "none");
42348 if(north && north.isVisible()){
42349 var b = north.getBox();
42350 var m = north.getMargins();
42351 b.width = w - (m.left+m.right);
42354 centerY = b.height + b.y + m.bottom;
42355 centerH -= centerY;
42356 north.updateBox(this.safeBox(b));
42358 if(south && south.isVisible()){
42359 var b = south.getBox();
42360 var m = south.getMargins();
42361 b.width = w - (m.left+m.right);
42363 var totalHeight = (b.height + m.top + m.bottom);
42364 b.y = h - totalHeight + m.top;
42365 centerH -= totalHeight;
42366 south.updateBox(this.safeBox(b));
42368 if(west && west.isVisible()){
42369 var b = west.getBox();
42370 var m = west.getMargins();
42371 b.height = centerH - (m.top+m.bottom);
42373 b.y = centerY + m.top;
42374 var totalWidth = (b.width + m.left + m.right);
42375 centerX += totalWidth;
42376 centerW -= totalWidth;
42377 west.updateBox(this.safeBox(b));
42379 if(east && east.isVisible()){
42380 var b = east.getBox();
42381 var m = east.getMargins();
42382 b.height = centerH - (m.top+m.bottom);
42383 var totalWidth = (b.width + m.left + m.right);
42384 b.x = w - totalWidth + m.left;
42385 b.y = centerY + m.top;
42386 centerW -= totalWidth;
42387 east.updateBox(this.safeBox(b));
42390 var m = center.getMargins();
42392 x: centerX + m.left,
42393 y: centerY + m.top,
42394 width: centerW - (m.left+m.right),
42395 height: centerH - (m.top+m.bottom)
42397 //if(this.hideOnLayout){
42398 //center.el.setStyle("display", "block");
42400 center.updateBox(this.safeBox(centerBox));
42403 this.fireEvent("layout", this);
42407 safeBox : function(box){
42408 box.width = Math.max(0, box.width);
42409 box.height = Math.max(0, box.height);
42414 * Adds a ContentPanel (or subclass) to this layout.
42415 * @param {String} target The target region key (north, south, east, west or center).
42416 * @param {Roo.ContentPanel} panel The panel to add
42417 * @return {Roo.ContentPanel} The added panel
42419 add : function(target, panel){
42421 target = target.toLowerCase();
42422 return this.regions[target].add(panel);
42426 * Remove a ContentPanel (or subclass) to this layout.
42427 * @param {String} target The target region key (north, south, east, west or center).
42428 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
42429 * @return {Roo.ContentPanel} The removed panel
42431 remove : function(target, panel){
42432 target = target.toLowerCase();
42433 return this.regions[target].remove(panel);
42437 * Searches all regions for a panel with the specified id
42438 * @param {String} panelId
42439 * @return {Roo.ContentPanel} The panel or null if it wasn't found
42441 findPanel : function(panelId){
42442 var rs = this.regions;
42443 for(var target in rs){
42444 if(typeof rs[target] != "function"){
42445 var p = rs[target].getPanel(panelId);
42455 * Searches all regions for a panel with the specified id and activates (shows) it.
42456 * @param {String/ContentPanel} panelId The panels id or the panel itself
42457 * @return {Roo.ContentPanel} The shown panel or null
42459 showPanel : function(panelId) {
42460 var rs = this.regions;
42461 for(var target in rs){
42462 var r = rs[target];
42463 if(typeof r != "function"){
42464 if(r.hasPanel(panelId)){
42465 return r.showPanel(panelId);
42473 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
42474 * @param {Roo.state.Provider} provider (optional) An alternate state provider
42477 restoreState : function(provider){
42479 provider = Roo.state.Manager;
42481 var sm = new Roo.LayoutStateManager();
42482 sm.init(this, provider);
42488 * Adds a xtype elements to the layout.
42492 xtype : 'ContentPanel',
42499 xtype : 'NestedLayoutPanel',
42505 items : [ ... list of content panels or nested layout panels.. ]
42509 * @param {Object} cfg Xtype definition of item to add.
42511 addxtype : function(cfg)
42513 // basically accepts a pannel...
42514 // can accept a layout region..!?!?
42515 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
42518 // theory? children can only be panels??
42520 //if (!cfg.xtype.match(/Panel$/)) {
42525 if (typeof(cfg.region) == 'undefined') {
42526 Roo.log("Failed to add Panel, region was not set");
42530 var region = cfg.region;
42536 xitems = cfg.items;
42541 if ( region == 'center') {
42542 Roo.log("Center: " + cfg.title);
42548 case 'Content': // ContentPanel (el, cfg)
42549 case 'Scroll': // ContentPanel (el, cfg)
42551 cfg.autoCreate = cfg.autoCreate || true;
42552 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
42554 // var el = this.el.createChild();
42555 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
42558 this.add(region, ret);
42562 case 'TreePanel': // our new panel!
42563 cfg.el = this.el.createChild();
42564 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
42565 this.add(region, ret);
42570 // create a new Layout (which is a Border Layout...
42572 var clayout = cfg.layout;
42573 clayout.el = this.el.createChild();
42574 clayout.items = clayout.items || [];
42578 // replace this exitems with the clayout ones..
42579 xitems = clayout.items;
42581 // force background off if it's in center...
42582 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
42583 cfg.background = false;
42585 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
42588 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
42589 //console.log('adding nested layout panel ' + cfg.toSource());
42590 this.add(region, ret);
42591 nb = {}; /// find first...
42596 // needs grid and region
42598 //var el = this.getRegion(region).el.createChild();
42600 *var el = this.el.createChild();
42601 // create the grid first...
42602 cfg.grid.container = el;
42603 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
42606 if (region == 'center' && this.active ) {
42607 cfg.background = false;
42610 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
42612 this.add(region, ret);
42614 if (cfg.background) {
42615 // render grid on panel activation (if panel background)
42616 ret.on('activate', function(gp) {
42617 if (!gp.grid.rendered) {
42618 // gp.grid.render(el);
42622 // cfg.grid.render(el);
42628 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
42629 // it was the old xcomponent building that caused this before.
42630 // espeically if border is the top element in the tree.
42640 if (typeof(Roo[cfg.xtype]) != 'undefined') {
42642 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
42643 this.add(region, ret);
42647 throw "Can not add '" + cfg.xtype + "' to Border";
42653 this.beginUpdate();
42657 Roo.each(xitems, function(i) {
42658 region = nb && i.region ? i.region : false;
42660 var add = ret.addxtype(i);
42663 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
42664 if (!i.background) {
42665 abn[region] = nb[region] ;
42672 // make the last non-background panel active..
42673 //if (nb) { Roo.log(abn); }
42676 for(var r in abn) {
42677 region = this.getRegion(r);
42679 // tried using nb[r], but it does not work..
42681 region.showPanel(abn[r]);
42692 factory : function(cfg)
42695 var validRegions = Roo.bootstrap.layout.Border.regions;
42697 var target = cfg.region;
42700 var r = Roo.bootstrap.layout;
42704 return new r.North(cfg);
42706 return new r.South(cfg);
42708 return new r.East(cfg);
42710 return new r.West(cfg);
42712 return new r.Center(cfg);
42714 throw 'Layout region "'+target+'" not supported.';
42721 * Ext JS Library 1.1.1
42722 * Copyright(c) 2006-2007, Ext JS, LLC.
42724 * Originally Released Under LGPL - original licence link has changed is not relivant.
42727 * <script type="text/javascript">
42731 * @class Roo.bootstrap.layout.Basic
42732 * @extends Roo.util.Observable
42733 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
42734 * and does not have a titlebar, tabs or any other features. All it does is size and position
42735 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
42736 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
42737 * @cfg {string} region the region that it inhabits..
42738 * @cfg {bool} skipConfig skip config?
42742 Roo.bootstrap.layout.Basic = function(config){
42744 this.mgr = config.mgr;
42746 this.position = config.region;
42748 var skipConfig = config.skipConfig;
42752 * @scope Roo.BasicLayoutRegion
42756 * @event beforeremove
42757 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
42758 * @param {Roo.LayoutRegion} this
42759 * @param {Roo.ContentPanel} panel The panel
42760 * @param {Object} e The cancel event object
42762 "beforeremove" : true,
42764 * @event invalidated
42765 * Fires when the layout for this region is changed.
42766 * @param {Roo.LayoutRegion} this
42768 "invalidated" : true,
42770 * @event visibilitychange
42771 * Fires when this region is shown or hidden
42772 * @param {Roo.LayoutRegion} this
42773 * @param {Boolean} visibility true or false
42775 "visibilitychange" : true,
42777 * @event paneladded
42778 * Fires when a panel is added.
42779 * @param {Roo.LayoutRegion} this
42780 * @param {Roo.ContentPanel} panel The panel
42782 "paneladded" : true,
42784 * @event panelremoved
42785 * Fires when a panel is removed.
42786 * @param {Roo.LayoutRegion} this
42787 * @param {Roo.ContentPanel} panel The panel
42789 "panelremoved" : true,
42791 * @event beforecollapse
42792 * Fires when this region before collapse.
42793 * @param {Roo.LayoutRegion} this
42795 "beforecollapse" : true,
42798 * Fires when this region is collapsed.
42799 * @param {Roo.LayoutRegion} this
42801 "collapsed" : true,
42804 * Fires when this region is expanded.
42805 * @param {Roo.LayoutRegion} this
42810 * Fires when this region is slid into view.
42811 * @param {Roo.LayoutRegion} this
42813 "slideshow" : true,
42816 * Fires when this region slides out of view.
42817 * @param {Roo.LayoutRegion} this
42819 "slidehide" : true,
42821 * @event panelactivated
42822 * Fires when a panel is activated.
42823 * @param {Roo.LayoutRegion} this
42824 * @param {Roo.ContentPanel} panel The activated panel
42826 "panelactivated" : true,
42829 * Fires when the user resizes this region.
42830 * @param {Roo.LayoutRegion} this
42831 * @param {Number} newSize The new size (width for east/west, height for north/south)
42835 /** A collection of panels in this region. @type Roo.util.MixedCollection */
42836 this.panels = new Roo.util.MixedCollection();
42837 this.panels.getKey = this.getPanelId.createDelegate(this);
42839 this.activePanel = null;
42840 // ensure listeners are added...
42842 if (config.listeners || config.events) {
42843 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
42844 listeners : config.listeners || {},
42845 events : config.events || {}
42849 if(skipConfig !== true){
42850 this.applyConfig(config);
42854 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
42856 getPanelId : function(p){
42860 applyConfig : function(config){
42861 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
42862 this.config = config;
42867 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
42868 * the width, for horizontal (north, south) the height.
42869 * @param {Number} newSize The new width or height
42871 resizeTo : function(newSize){
42872 var el = this.el ? this.el :
42873 (this.activePanel ? this.activePanel.getEl() : null);
42875 switch(this.position){
42878 el.setWidth(newSize);
42879 this.fireEvent("resized", this, newSize);
42883 el.setHeight(newSize);
42884 this.fireEvent("resized", this, newSize);
42890 getBox : function(){
42891 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
42894 getMargins : function(){
42895 return this.margins;
42898 updateBox : function(box){
42900 var el = this.activePanel.getEl();
42901 el.dom.style.left = box.x + "px";
42902 el.dom.style.top = box.y + "px";
42903 this.activePanel.setSize(box.width, box.height);
42907 * Returns the container element for this region.
42908 * @return {Roo.Element}
42910 getEl : function(){
42911 return this.activePanel;
42915 * Returns true if this region is currently visible.
42916 * @return {Boolean}
42918 isVisible : function(){
42919 return this.activePanel ? true : false;
42922 setActivePanel : function(panel){
42923 panel = this.getPanel(panel);
42924 if(this.activePanel && this.activePanel != panel){
42925 this.activePanel.setActiveState(false);
42926 this.activePanel.getEl().setLeftTop(-10000,-10000);
42928 this.activePanel = panel;
42929 panel.setActiveState(true);
42931 panel.setSize(this.box.width, this.box.height);
42933 this.fireEvent("panelactivated", this, panel);
42934 this.fireEvent("invalidated");
42938 * Show the specified panel.
42939 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
42940 * @return {Roo.ContentPanel} The shown panel or null
42942 showPanel : function(panel){
42943 panel = this.getPanel(panel);
42945 this.setActivePanel(panel);
42951 * Get the active panel for this region.
42952 * @return {Roo.ContentPanel} The active panel or null
42954 getActivePanel : function(){
42955 return this.activePanel;
42959 * Add the passed ContentPanel(s)
42960 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
42961 * @return {Roo.ContentPanel} The panel added (if only one was added)
42963 add : function(panel){
42964 if(arguments.length > 1){
42965 for(var i = 0, len = arguments.length; i < len; i++) {
42966 this.add(arguments[i]);
42970 if(this.hasPanel(panel)){
42971 this.showPanel(panel);
42974 var el = panel.getEl();
42975 if(el.dom.parentNode != this.mgr.el.dom){
42976 this.mgr.el.dom.appendChild(el.dom);
42978 if(panel.setRegion){
42979 panel.setRegion(this);
42981 this.panels.add(panel);
42982 el.setStyle("position", "absolute");
42983 if(!panel.background){
42984 this.setActivePanel(panel);
42985 if(this.config.initialSize && this.panels.getCount()==1){
42986 this.resizeTo(this.config.initialSize);
42989 this.fireEvent("paneladded", this, panel);
42994 * Returns true if the panel is in this region.
42995 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
42996 * @return {Boolean}
42998 hasPanel : function(panel){
42999 if(typeof panel == "object"){ // must be panel obj
43000 panel = panel.getId();
43002 return this.getPanel(panel) ? true : false;
43006 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
43007 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43008 * @param {Boolean} preservePanel Overrides the config preservePanel option
43009 * @return {Roo.ContentPanel} The panel that was removed
43011 remove : function(panel, preservePanel){
43012 panel = this.getPanel(panel);
43017 this.fireEvent("beforeremove", this, panel, e);
43018 if(e.cancel === true){
43021 var panelId = panel.getId();
43022 this.panels.removeKey(panelId);
43027 * Returns the panel specified or null if it's not in this region.
43028 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43029 * @return {Roo.ContentPanel}
43031 getPanel : function(id){
43032 if(typeof id == "object"){ // must be panel obj
43035 return this.panels.get(id);
43039 * Returns this regions position (north/south/east/west/center).
43042 getPosition: function(){
43043 return this.position;
43047 * Ext JS Library 1.1.1
43048 * Copyright(c) 2006-2007, Ext JS, LLC.
43050 * Originally Released Under LGPL - original licence link has changed is not relivant.
43053 * <script type="text/javascript">
43057 * @class Roo.bootstrap.layout.Region
43058 * @extends Roo.bootstrap.layout.Basic
43059 * This class represents a region in a layout manager.
43061 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
43062 * @cfg {Object} cmargins Margins for the element when collapsed (defaults to: north/south {top: 2, left: 0, right:0, bottom: 2} or east/west {top: 0, left: 2, right:2, bottom: 0})
43063 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
43064 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
43065 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
43066 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
43067 * @cfg {String} title The title for the region (overrides panel titles)
43068 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
43069 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
43070 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
43071 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
43072 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
43073 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
43074 * the space available, similar to FireFox 1.5 tabs (defaults to false)
43075 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
43076 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
43077 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
43079 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
43080 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
43081 * @cfg {Boolean} disableTabTips True to disable tab tooltips
43082 * @cfg {Number} width For East/West panels
43083 * @cfg {Number} height For North/South panels
43084 * @cfg {Boolean} split To show the splitter
43085 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
43087 * @cfg {string} cls Extra CSS classes to add to region
43089 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
43090 * @cfg {string} region the region that it inhabits..
43093 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
43094 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
43096 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
43097 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
43098 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
43100 Roo.bootstrap.layout.Region = function(config)
43102 this.applyConfig(config);
43104 var mgr = config.mgr;
43105 var pos = config.region;
43106 config.skipConfig = true;
43107 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
43110 this.onRender(mgr.el);
43113 this.visible = true;
43114 this.collapsed = false;
43115 this.unrendered_panels = [];
43118 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
43120 position: '', // set by wrapper (eg. north/south etc..)
43121 unrendered_panels : null, // unrendered panels.
43123 tabPosition : false,
43125 mgr: false, // points to 'Border'
43128 createBody : function(){
43129 /** This region's body element
43130 * @type Roo.Element */
43131 this.bodyEl = this.el.createChild({
43133 cls: "roo-layout-panel-body tab-content" // bootstrap added...
43137 onRender: function(ctr, pos)
43139 var dh = Roo.DomHelper;
43140 /** This region's container element
43141 * @type Roo.Element */
43142 this.el = dh.append(ctr.dom, {
43144 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
43146 /** This region's title element
43147 * @type Roo.Element */
43149 this.titleEl = dh.append(this.el.dom, {
43151 unselectable: "on",
43152 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
43154 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
43155 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
43159 this.titleEl.enableDisplayMode();
43160 /** This region's title text element
43161 * @type HTMLElement */
43162 this.titleTextEl = this.titleEl.dom.firstChild;
43163 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
43165 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
43166 this.closeBtn.enableDisplayMode();
43167 this.closeBtn.on("click", this.closeClicked, this);
43168 this.closeBtn.hide();
43170 this.createBody(this.config);
43171 if(this.config.hideWhenEmpty){
43173 this.on("paneladded", this.validateVisibility, this);
43174 this.on("panelremoved", this.validateVisibility, this);
43176 if(this.autoScroll){
43177 this.bodyEl.setStyle("overflow", "auto");
43179 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
43181 //if(c.titlebar !== false){
43182 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
43183 this.titleEl.hide();
43185 this.titleEl.show();
43186 if(this.config.title){
43187 this.titleTextEl.innerHTML = this.config.title;
43191 if(this.config.collapsed){
43192 this.collapse(true);
43194 if(this.config.hidden){
43198 if (this.unrendered_panels && this.unrendered_panels.length) {
43199 for (var i =0;i< this.unrendered_panels.length; i++) {
43200 this.add(this.unrendered_panels[i]);
43202 this.unrendered_panels = null;
43208 applyConfig : function(c)
43211 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
43212 var dh = Roo.DomHelper;
43213 if(c.titlebar !== false){
43214 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
43215 this.collapseBtn.on("click", this.collapse, this);
43216 this.collapseBtn.enableDisplayMode();
43218 if(c.showPin === true || this.showPin){
43219 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
43220 this.stickBtn.enableDisplayMode();
43221 this.stickBtn.on("click", this.expand, this);
43222 this.stickBtn.hide();
43227 /** This region's collapsed element
43228 * @type Roo.Element */
43231 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
43232 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
43235 if(c.floatable !== false){
43236 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
43237 this.collapsedEl.on("click", this.collapseClick, this);
43240 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
43241 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
43242 id: "message", unselectable: "on", style:{"float":"left"}});
43243 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
43245 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
43246 this.expandBtn.on("click", this.expand, this);
43250 if(this.collapseBtn){
43251 this.collapseBtn.setVisible(c.collapsible == true);
43254 this.cmargins = c.cmargins || this.cmargins ||
43255 (this.position == "west" || this.position == "east" ?
43256 {top: 0, left: 2, right:2, bottom: 0} :
43257 {top: 2, left: 0, right:0, bottom: 2});
43259 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
43262 this.tabPosition = [ 'top','bottom', 'west'].indexOf(c.tabPosition) > -1 ? c.tabPosition : "top";
43264 this.autoScroll = c.autoScroll || false;
43269 this.duration = c.duration || .30;
43270 this.slideDuration = c.slideDuration || .45;
43275 * Returns true if this region is currently visible.
43276 * @return {Boolean}
43278 isVisible : function(){
43279 return this.visible;
43283 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
43284 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
43286 //setCollapsedTitle : function(title){
43287 // title = title || " ";
43288 // if(this.collapsedTitleTextEl){
43289 // this.collapsedTitleTextEl.innerHTML = title;
43293 getBox : function(){
43295 // if(!this.collapsed){
43296 b = this.el.getBox(false, true);
43298 // b = this.collapsedEl.getBox(false, true);
43303 getMargins : function(){
43304 return this.margins;
43305 //return this.collapsed ? this.cmargins : this.margins;
43308 highlight : function(){
43309 this.el.addClass("x-layout-panel-dragover");
43312 unhighlight : function(){
43313 this.el.removeClass("x-layout-panel-dragover");
43316 updateBox : function(box)
43318 if (!this.bodyEl) {
43319 return; // not rendered yet..
43323 if(!this.collapsed){
43324 this.el.dom.style.left = box.x + "px";
43325 this.el.dom.style.top = box.y + "px";
43326 this.updateBody(box.width, box.height);
43328 this.collapsedEl.dom.style.left = box.x + "px";
43329 this.collapsedEl.dom.style.top = box.y + "px";
43330 this.collapsedEl.setSize(box.width, box.height);
43333 this.tabs.autoSizeTabs();
43337 updateBody : function(w, h)
43340 this.el.setWidth(w);
43341 w -= this.el.getBorderWidth("rl");
43342 if(this.config.adjustments){
43343 w += this.config.adjustments[0];
43346 if(h !== null && h > 0){
43347 this.el.setHeight(h);
43348 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
43349 h -= this.el.getBorderWidth("tb");
43350 if(this.config.adjustments){
43351 h += this.config.adjustments[1];
43353 this.bodyEl.setHeight(h);
43355 h = this.tabs.syncHeight(h);
43358 if(this.panelSize){
43359 w = w !== null ? w : this.panelSize.width;
43360 h = h !== null ? h : this.panelSize.height;
43362 if(this.activePanel){
43363 var el = this.activePanel.getEl();
43364 w = w !== null ? w : el.getWidth();
43365 h = h !== null ? h : el.getHeight();
43366 this.panelSize = {width: w, height: h};
43367 this.activePanel.setSize(w, h);
43369 if(Roo.isIE && this.tabs){
43370 this.tabs.el.repaint();
43375 * Returns the container element for this region.
43376 * @return {Roo.Element}
43378 getEl : function(){
43383 * Hides this region.
43386 //if(!this.collapsed){
43387 this.el.dom.style.left = "-2000px";
43390 // this.collapsedEl.dom.style.left = "-2000px";
43391 // this.collapsedEl.hide();
43393 this.visible = false;
43394 this.fireEvent("visibilitychange", this, false);
43398 * Shows this region if it was previously hidden.
43401 //if(!this.collapsed){
43404 // this.collapsedEl.show();
43406 this.visible = true;
43407 this.fireEvent("visibilitychange", this, true);
43410 closeClicked : function(){
43411 if(this.activePanel){
43412 this.remove(this.activePanel);
43416 collapseClick : function(e){
43418 e.stopPropagation();
43421 e.stopPropagation();
43427 * Collapses this region.
43428 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
43431 collapse : function(skipAnim, skipCheck = false){
43432 if(this.collapsed) {
43436 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
43438 this.collapsed = true;
43440 this.split.el.hide();
43442 if(this.config.animate && skipAnim !== true){
43443 this.fireEvent("invalidated", this);
43444 this.animateCollapse();
43446 this.el.setLocation(-20000,-20000);
43448 this.collapsedEl.show();
43449 this.fireEvent("collapsed", this);
43450 this.fireEvent("invalidated", this);
43456 animateCollapse : function(){
43461 * Expands this region if it was previously collapsed.
43462 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
43463 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
43466 expand : function(e, skipAnim){
43468 e.stopPropagation();
43470 if(!this.collapsed || this.el.hasActiveFx()) {
43474 this.afterSlideIn();
43477 this.collapsed = false;
43478 if(this.config.animate && skipAnim !== true){
43479 this.animateExpand();
43483 this.split.el.show();
43485 this.collapsedEl.setLocation(-2000,-2000);
43486 this.collapsedEl.hide();
43487 this.fireEvent("invalidated", this);
43488 this.fireEvent("expanded", this);
43492 animateExpand : function(){
43496 initTabs : function()
43498 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
43500 var ts = new Roo.bootstrap.panel.Tabs({
43501 el: this.bodyEl.dom,
43503 tabPosition: this.tabPosition ? this.tabPosition : 'top',
43504 disableTooltips: this.config.disableTabTips,
43505 toolbar : this.config.toolbar
43508 if(this.config.hideTabs){
43509 ts.stripWrap.setDisplayed(false);
43512 ts.resizeTabs = this.config.resizeTabs === true;
43513 ts.minTabWidth = this.config.minTabWidth || 40;
43514 ts.maxTabWidth = this.config.maxTabWidth || 250;
43515 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
43516 ts.monitorResize = false;
43517 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
43518 ts.bodyEl.addClass('roo-layout-tabs-body');
43519 this.panels.each(this.initPanelAsTab, this);
43522 initPanelAsTab : function(panel){
43523 var ti = this.tabs.addTab(
43527 this.config.closeOnTab && panel.isClosable(),
43530 if(panel.tabTip !== undefined){
43531 ti.setTooltip(panel.tabTip);
43533 ti.on("activate", function(){
43534 this.setActivePanel(panel);
43537 if(this.config.closeOnTab){
43538 ti.on("beforeclose", function(t, e){
43540 this.remove(panel);
43544 panel.tabItem = ti;
43549 updatePanelTitle : function(panel, title)
43551 if(this.activePanel == panel){
43552 this.updateTitle(title);
43555 var ti = this.tabs.getTab(panel.getEl().id);
43557 if(panel.tabTip !== undefined){
43558 ti.setTooltip(panel.tabTip);
43563 updateTitle : function(title){
43564 if(this.titleTextEl && !this.config.title){
43565 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
43569 setActivePanel : function(panel)
43571 panel = this.getPanel(panel);
43572 if(this.activePanel && this.activePanel != panel){
43573 if(this.activePanel.setActiveState(false) === false){
43577 this.activePanel = panel;
43578 panel.setActiveState(true);
43579 if(this.panelSize){
43580 panel.setSize(this.panelSize.width, this.panelSize.height);
43583 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
43585 this.updateTitle(panel.getTitle());
43587 this.fireEvent("invalidated", this);
43589 this.fireEvent("panelactivated", this, panel);
43593 * Shows the specified panel.
43594 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
43595 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
43597 showPanel : function(panel)
43599 panel = this.getPanel(panel);
43602 var tab = this.tabs.getTab(panel.getEl().id);
43603 if(tab.isHidden()){
43604 this.tabs.unhideTab(tab.id);
43608 this.setActivePanel(panel);
43615 * Get the active panel for this region.
43616 * @return {Roo.ContentPanel} The active panel or null
43618 getActivePanel : function(){
43619 return this.activePanel;
43622 validateVisibility : function(){
43623 if(this.panels.getCount() < 1){
43624 this.updateTitle(" ");
43625 this.closeBtn.hide();
43628 if(!this.isVisible()){
43635 * Adds the passed ContentPanel(s) to this region.
43636 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
43637 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
43639 add : function(panel)
43641 if(arguments.length > 1){
43642 for(var i = 0, len = arguments.length; i < len; i++) {
43643 this.add(arguments[i]);
43648 // if we have not been rendered yet, then we can not really do much of this..
43649 if (!this.bodyEl) {
43650 this.unrendered_panels.push(panel);
43657 if(this.hasPanel(panel)){
43658 this.showPanel(panel);
43661 panel.setRegion(this);
43662 this.panels.add(panel);
43663 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
43664 // sinle panel - no tab...?? would it not be better to render it with the tabs,
43665 // and hide them... ???
43666 this.bodyEl.dom.appendChild(panel.getEl().dom);
43667 if(panel.background !== true){
43668 this.setActivePanel(panel);
43670 this.fireEvent("paneladded", this, panel);
43677 this.initPanelAsTab(panel);
43681 if(panel.background !== true){
43682 this.tabs.activate(panel.getEl().id);
43684 this.fireEvent("paneladded", this, panel);
43689 * Hides the tab for the specified panel.
43690 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
43692 hidePanel : function(panel){
43693 if(this.tabs && (panel = this.getPanel(panel))){
43694 this.tabs.hideTab(panel.getEl().id);
43699 * Unhides the tab for a previously hidden panel.
43700 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
43702 unhidePanel : function(panel){
43703 if(this.tabs && (panel = this.getPanel(panel))){
43704 this.tabs.unhideTab(panel.getEl().id);
43708 clearPanels : function(){
43709 while(this.panels.getCount() > 0){
43710 this.remove(this.panels.first());
43715 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
43716 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
43717 * @param {Boolean} preservePanel Overrides the config preservePanel option
43718 * @return {Roo.ContentPanel} The panel that was removed
43720 remove : function(panel, preservePanel)
43722 panel = this.getPanel(panel);
43727 this.fireEvent("beforeremove", this, panel, e);
43728 if(e.cancel === true){
43731 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
43732 var panelId = panel.getId();
43733 this.panels.removeKey(panelId);
43735 document.body.appendChild(panel.getEl().dom);
43738 this.tabs.removeTab(panel.getEl().id);
43739 }else if (!preservePanel){
43740 this.bodyEl.dom.removeChild(panel.getEl().dom);
43742 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
43743 var p = this.panels.first();
43744 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
43745 tempEl.appendChild(p.getEl().dom);
43746 this.bodyEl.update("");
43747 this.bodyEl.dom.appendChild(p.getEl().dom);
43749 this.updateTitle(p.getTitle());
43751 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
43752 this.setActivePanel(p);
43754 panel.setRegion(null);
43755 if(this.activePanel == panel){
43756 this.activePanel = null;
43758 if(this.config.autoDestroy !== false && preservePanel !== true){
43759 try{panel.destroy();}catch(e){}
43761 this.fireEvent("panelremoved", this, panel);
43766 * Returns the TabPanel component used by this region
43767 * @return {Roo.TabPanel}
43769 getTabs : function(){
43773 createTool : function(parentEl, className){
43774 var btn = Roo.DomHelper.append(parentEl, {
43776 cls: "x-layout-tools-button",
43779 cls: "roo-layout-tools-button-inner " + className,
43783 btn.addClassOnOver("roo-layout-tools-button-over");
43788 * Ext JS Library 1.1.1
43789 * Copyright(c) 2006-2007, Ext JS, LLC.
43791 * Originally Released Under LGPL - original licence link has changed is not relivant.
43794 * <script type="text/javascript">
43800 * @class Roo.SplitLayoutRegion
43801 * @extends Roo.LayoutRegion
43802 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
43804 Roo.bootstrap.layout.Split = function(config){
43805 this.cursor = config.cursor;
43806 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
43809 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
43811 splitTip : "Drag to resize.",
43812 collapsibleSplitTip : "Drag to resize. Double click to hide.",
43813 useSplitTips : false,
43815 applyConfig : function(config){
43816 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
43819 onRender : function(ctr,pos) {
43821 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
43822 if(!this.config.split){
43827 var splitEl = Roo.DomHelper.append(ctr.dom, {
43829 id: this.el.id + "-split",
43830 cls: "roo-layout-split roo-layout-split-"+this.position,
43833 /** The SplitBar for this region
43834 * @type Roo.SplitBar */
43835 // does not exist yet...
43836 Roo.log([this.position, this.orientation]);
43838 this.split = new Roo.bootstrap.SplitBar({
43839 dragElement : splitEl,
43840 resizingElement: this.el,
43841 orientation : this.orientation
43844 this.split.on("moved", this.onSplitMove, this);
43845 this.split.useShim = this.config.useShim === true;
43846 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
43847 if(this.useSplitTips){
43848 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
43850 //if(config.collapsible){
43851 // this.split.el.on("dblclick", this.collapse, this);
43854 if(typeof this.config.minSize != "undefined"){
43855 this.split.minSize = this.config.minSize;
43857 if(typeof this.config.maxSize != "undefined"){
43858 this.split.maxSize = this.config.maxSize;
43860 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
43861 this.hideSplitter();
43866 getHMaxSize : function(){
43867 var cmax = this.config.maxSize || 10000;
43868 var center = this.mgr.getRegion("center");
43869 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
43872 getVMaxSize : function(){
43873 var cmax = this.config.maxSize || 10000;
43874 var center = this.mgr.getRegion("center");
43875 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
43878 onSplitMove : function(split, newSize){
43879 this.fireEvent("resized", this, newSize);
43883 * Returns the {@link Roo.SplitBar} for this region.
43884 * @return {Roo.SplitBar}
43886 getSplitBar : function(){
43891 this.hideSplitter();
43892 Roo.bootstrap.layout.Split.superclass.hide.call(this);
43895 hideSplitter : function(){
43897 this.split.el.setLocation(-2000,-2000);
43898 this.split.el.hide();
43904 this.split.el.show();
43906 Roo.bootstrap.layout.Split.superclass.show.call(this);
43909 beforeSlide: function(){
43910 if(Roo.isGecko){// firefox overflow auto bug workaround
43911 this.bodyEl.clip();
43913 this.tabs.bodyEl.clip();
43915 if(this.activePanel){
43916 this.activePanel.getEl().clip();
43918 if(this.activePanel.beforeSlide){
43919 this.activePanel.beforeSlide();
43925 afterSlide : function(){
43926 if(Roo.isGecko){// firefox overflow auto bug workaround
43927 this.bodyEl.unclip();
43929 this.tabs.bodyEl.unclip();
43931 if(this.activePanel){
43932 this.activePanel.getEl().unclip();
43933 if(this.activePanel.afterSlide){
43934 this.activePanel.afterSlide();
43940 initAutoHide : function(){
43941 if(this.autoHide !== false){
43942 if(!this.autoHideHd){
43943 var st = new Roo.util.DelayedTask(this.slideIn, this);
43944 this.autoHideHd = {
43945 "mouseout": function(e){
43946 if(!e.within(this.el, true)){
43950 "mouseover" : function(e){
43956 this.el.on(this.autoHideHd);
43960 clearAutoHide : function(){
43961 if(this.autoHide !== false){
43962 this.el.un("mouseout", this.autoHideHd.mouseout);
43963 this.el.un("mouseover", this.autoHideHd.mouseover);
43967 clearMonitor : function(){
43968 Roo.get(document).un("click", this.slideInIf, this);
43971 // these names are backwards but not changed for compat
43972 slideOut : function(){
43973 if(this.isSlid || this.el.hasActiveFx()){
43976 this.isSlid = true;
43977 if(this.collapseBtn){
43978 this.collapseBtn.hide();
43980 this.closeBtnState = this.closeBtn.getStyle('display');
43981 this.closeBtn.hide();
43983 this.stickBtn.show();
43986 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
43987 this.beforeSlide();
43988 this.el.setStyle("z-index", 10001);
43989 this.el.slideIn(this.getSlideAnchor(), {
43990 callback: function(){
43992 this.initAutoHide();
43993 Roo.get(document).on("click", this.slideInIf, this);
43994 this.fireEvent("slideshow", this);
44001 afterSlideIn : function(){
44002 this.clearAutoHide();
44003 this.isSlid = false;
44004 this.clearMonitor();
44005 this.el.setStyle("z-index", "");
44006 if(this.collapseBtn){
44007 this.collapseBtn.show();
44009 this.closeBtn.setStyle('display', this.closeBtnState);
44011 this.stickBtn.hide();
44013 this.fireEvent("slidehide", this);
44016 slideIn : function(cb){
44017 if(!this.isSlid || this.el.hasActiveFx()){
44021 this.isSlid = false;
44022 this.beforeSlide();
44023 this.el.slideOut(this.getSlideAnchor(), {
44024 callback: function(){
44025 this.el.setLeftTop(-10000, -10000);
44027 this.afterSlideIn();
44035 slideInIf : function(e){
44036 if(!e.within(this.el)){
44041 animateCollapse : function(){
44042 this.beforeSlide();
44043 this.el.setStyle("z-index", 20000);
44044 var anchor = this.getSlideAnchor();
44045 this.el.slideOut(anchor, {
44046 callback : function(){
44047 this.el.setStyle("z-index", "");
44048 this.collapsedEl.slideIn(anchor, {duration:.3});
44050 this.el.setLocation(-10000,-10000);
44052 this.fireEvent("collapsed", this);
44059 animateExpand : function(){
44060 this.beforeSlide();
44061 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
44062 this.el.setStyle("z-index", 20000);
44063 this.collapsedEl.hide({
44066 this.el.slideIn(this.getSlideAnchor(), {
44067 callback : function(){
44068 this.el.setStyle("z-index", "");
44071 this.split.el.show();
44073 this.fireEvent("invalidated", this);
44074 this.fireEvent("expanded", this);
44102 getAnchor : function(){
44103 return this.anchors[this.position];
44106 getCollapseAnchor : function(){
44107 return this.canchors[this.position];
44110 getSlideAnchor : function(){
44111 return this.sanchors[this.position];
44114 getAlignAdj : function(){
44115 var cm = this.cmargins;
44116 switch(this.position){
44132 getExpandAdj : function(){
44133 var c = this.collapsedEl, cm = this.cmargins;
44134 switch(this.position){
44136 return [-(cm.right+c.getWidth()+cm.left), 0];
44139 return [cm.right+c.getWidth()+cm.left, 0];
44142 return [0, -(cm.top+cm.bottom+c.getHeight())];
44145 return [0, cm.top+cm.bottom+c.getHeight()];
44151 * Ext JS Library 1.1.1
44152 * Copyright(c) 2006-2007, Ext JS, LLC.
44154 * Originally Released Under LGPL - original licence link has changed is not relivant.
44157 * <script type="text/javascript">
44160 * These classes are private internal classes
44162 Roo.bootstrap.layout.Center = function(config){
44163 config.region = "center";
44164 Roo.bootstrap.layout.Region.call(this, config);
44165 this.visible = true;
44166 this.minWidth = config.minWidth || 20;
44167 this.minHeight = config.minHeight || 20;
44170 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
44172 // center panel can't be hidden
44176 // center panel can't be hidden
44179 getMinWidth: function(){
44180 return this.minWidth;
44183 getMinHeight: function(){
44184 return this.minHeight;
44198 Roo.bootstrap.layout.North = function(config)
44200 config.region = 'north';
44201 config.cursor = 'n-resize';
44203 Roo.bootstrap.layout.Split.call(this, config);
44207 this.split.placement = Roo.bootstrap.SplitBar.TOP;
44208 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
44209 this.split.el.addClass("roo-layout-split-v");
44211 //var size = config.initialSize || config.height;
44212 //if(this.el && typeof size != "undefined"){
44213 // this.el.setHeight(size);
44216 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
44218 orientation: Roo.bootstrap.SplitBar.VERTICAL,
44221 onRender : function(ctr, pos)
44223 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
44224 var size = this.config.initialSize || this.config.height;
44225 if(this.el && typeof size != "undefined"){
44226 this.el.setHeight(size);
44231 getBox : function(){
44232 if(this.collapsed){
44233 return this.collapsedEl.getBox();
44235 var box = this.el.getBox();
44237 box.height += this.split.el.getHeight();
44242 updateBox : function(box){
44243 if(this.split && !this.collapsed){
44244 box.height -= this.split.el.getHeight();
44245 this.split.el.setLeft(box.x);
44246 this.split.el.setTop(box.y+box.height);
44247 this.split.el.setWidth(box.width);
44249 if(this.collapsed){
44250 this.updateBody(box.width, null);
44252 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44260 Roo.bootstrap.layout.South = function(config){
44261 config.region = 'south';
44262 config.cursor = 's-resize';
44263 Roo.bootstrap.layout.Split.call(this, config);
44265 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
44266 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
44267 this.split.el.addClass("roo-layout-split-v");
44272 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
44273 orientation: Roo.bootstrap.SplitBar.VERTICAL,
44275 onRender : function(ctr, pos)
44277 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
44278 var size = this.config.initialSize || this.config.height;
44279 if(this.el && typeof size != "undefined"){
44280 this.el.setHeight(size);
44285 getBox : function(){
44286 if(this.collapsed){
44287 return this.collapsedEl.getBox();
44289 var box = this.el.getBox();
44291 var sh = this.split.el.getHeight();
44298 updateBox : function(box){
44299 if(this.split && !this.collapsed){
44300 var sh = this.split.el.getHeight();
44303 this.split.el.setLeft(box.x);
44304 this.split.el.setTop(box.y-sh);
44305 this.split.el.setWidth(box.width);
44307 if(this.collapsed){
44308 this.updateBody(box.width, null);
44310 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44314 Roo.bootstrap.layout.East = function(config){
44315 config.region = "east";
44316 config.cursor = "e-resize";
44317 Roo.bootstrap.layout.Split.call(this, config);
44319 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
44320 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
44321 this.split.el.addClass("roo-layout-split-h");
44325 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
44326 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
44328 onRender : function(ctr, pos)
44330 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
44331 var size = this.config.initialSize || this.config.width;
44332 if(this.el && typeof size != "undefined"){
44333 this.el.setWidth(size);
44338 getBox : function(){
44339 if(this.collapsed){
44340 return this.collapsedEl.getBox();
44342 var box = this.el.getBox();
44344 var sw = this.split.el.getWidth();
44351 updateBox : function(box){
44352 if(this.split && !this.collapsed){
44353 var sw = this.split.el.getWidth();
44355 this.split.el.setLeft(box.x);
44356 this.split.el.setTop(box.y);
44357 this.split.el.setHeight(box.height);
44360 if(this.collapsed){
44361 this.updateBody(null, box.height);
44363 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44367 Roo.bootstrap.layout.West = function(config){
44368 config.region = "west";
44369 config.cursor = "w-resize";
44371 Roo.bootstrap.layout.Split.call(this, config);
44373 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
44374 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
44375 this.split.el.addClass("roo-layout-split-h");
44379 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
44380 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
44382 onRender: function(ctr, pos)
44384 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
44385 var size = this.config.initialSize || this.config.width;
44386 if(typeof size != "undefined"){
44387 this.el.setWidth(size);
44391 getBox : function(){
44392 if(this.collapsed){
44393 return this.collapsedEl.getBox();
44395 var box = this.el.getBox();
44396 if (box.width == 0) {
44397 box.width = this.config.width; // kludge?
44400 box.width += this.split.el.getWidth();
44405 updateBox : function(box){
44406 if(this.split && !this.collapsed){
44407 var sw = this.split.el.getWidth();
44409 this.split.el.setLeft(box.x+box.width);
44410 this.split.el.setTop(box.y);
44411 this.split.el.setHeight(box.height);
44413 if(this.collapsed){
44414 this.updateBody(null, box.height);
44416 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44420 * Ext JS Library 1.1.1
44421 * Copyright(c) 2006-2007, Ext JS, LLC.
44423 * Originally Released Under LGPL - original licence link has changed is not relivant.
44426 * <script type="text/javascript">
44429 * @class Roo.bootstrap.paenl.Content
44430 * @extends Roo.util.Observable
44431 * @children Roo.bootstrap.Component
44432 * @parent builder Roo.bootstrap.layout.Border
44433 * A basic ContentPanel element. - a panel that contain any content (eg. forms etc.)
44434 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
44435 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
44436 * @cfg {Boolean/Object} autoCreate True to auto generate the DOM element for this panel, or a {@link Roo.DomHelper} config of the element to create
44437 * @cfg {Boolean} closable True if the panel can be closed/removed
44438 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
44439 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
44440 * @cfg {Toolbar} toolbar A toolbar for this panel
44441 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
44442 * @cfg {String} title The title for this panel
44443 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
44444 * @cfg {String} url Calls {@link #setUrl} with this value
44445 * @cfg {String} region [required] (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
44446 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
44447 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
44448 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
44449 * @cfg {Boolean} iframe contents are an iframe - makes showing remote sources/CSS feasible..
44450 * @cfg {Boolean} badges render the badges
44451 * @cfg {String} cls extra classes to use
44452 * @cfg {String} background (primary|secondary|success|info|warning|danger|light|dark)
44455 * Create a new ContentPanel.
44456 * @param {String/Object} config A string to set only the title or a config object
44459 Roo.bootstrap.panel.Content = function( config){
44461 this.tpl = config.tpl || false;
44463 var el = config.el;
44464 var content = config.content;
44466 if(config.autoCreate){ // xtype is available if this is called from factory
44469 this.el = Roo.get(el);
44470 if(!this.el && config && config.autoCreate){
44471 if(typeof config.autoCreate == "object"){
44472 if(!config.autoCreate.id){
44473 config.autoCreate.id = config.id||el;
44475 this.el = Roo.DomHelper.append(document.body,
44476 config.autoCreate, true);
44480 cls: (config.cls || '') +
44481 (config.background ? ' bg-' + config.background : '') +
44482 " roo-layout-inactive-content",
44485 if (config.iframe) {
44489 style : 'border: 0px',
44490 src : 'about:blank'
44496 elcfg.html = config.html;
44500 this.el = Roo.DomHelper.append(document.body, elcfg , true);
44501 if (config.iframe) {
44502 this.iframeEl = this.el.select('iframe',true).first();
44507 this.closable = false;
44508 this.loaded = false;
44509 this.active = false;
44512 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
44514 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
44516 this.wrapEl = this.el; //this.el.wrap();
44518 if (config.toolbar.items) {
44519 ti = config.toolbar.items ;
44520 delete config.toolbar.items ;
44524 this.toolbar.render(this.wrapEl, 'before');
44525 for(var i =0;i < ti.length;i++) {
44526 // Roo.log(['add child', items[i]]);
44527 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
44529 this.toolbar.items = nitems;
44530 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
44531 delete config.toolbar;
44535 // xtype created footer. - not sure if will work as we normally have to render first..
44536 if (this.footer && !this.footer.el && this.footer.xtype) {
44537 if (!this.wrapEl) {
44538 this.wrapEl = this.el.wrap();
44541 this.footer.container = this.wrapEl.createChild();
44543 this.footer = Roo.factory(this.footer, Roo);
44548 if(typeof config == "string"){
44549 this.title = config;
44551 Roo.apply(this, config);
44555 this.resizeEl = Roo.get(this.resizeEl, true);
44557 this.resizeEl = this.el;
44559 // handle view.xtype
44567 * Fires when this panel is activated.
44568 * @param {Roo.ContentPanel} this
44572 * @event deactivate
44573 * Fires when this panel is activated.
44574 * @param {Roo.ContentPanel} this
44576 "deactivate" : true,
44580 * Fires when this panel is resized if fitToFrame is true.
44581 * @param {Roo.ContentPanel} this
44582 * @param {Number} width The width after any component adjustments
44583 * @param {Number} height The height after any component adjustments
44589 * Fires when this tab is created
44590 * @param {Roo.ContentPanel} this
44596 * Fires when this content is scrolled
44597 * @param {Roo.ContentPanel} this
44598 * @param {Event} scrollEvent
44609 if(this.autoScroll && !this.iframe){
44610 this.resizeEl.setStyle("overflow", "auto");
44611 this.resizeEl.on('scroll', this.onScroll, this);
44613 // fix randome scrolling
44614 //this.el.on('scroll', function() {
44615 // Roo.log('fix random scolling');
44616 // this.scrollTo('top',0);
44619 content = content || this.content;
44621 this.setContent(content);
44623 if(config && config.url){
44624 this.setUrl(this.url, this.params, this.loadOnce);
44629 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
44631 if (this.view && typeof(this.view.xtype) != 'undefined') {
44632 this.view.el = this.el.appendChild(document.createElement("div"));
44633 this.view = Roo.factory(this.view);
44634 this.view.render && this.view.render(false, '');
44638 this.fireEvent('render', this);
44641 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
44651 /* Resize Element - use this to work out scroll etc. */
44654 setRegion : function(region){
44655 this.region = region;
44656 this.setActiveClass(region && !this.background);
44660 setActiveClass: function(state)
44663 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
44664 this.el.setStyle('position','relative');
44666 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
44667 this.el.setStyle('position', 'absolute');
44672 * Returns the toolbar for this Panel if one was configured.
44673 * @return {Roo.Toolbar}
44675 getToolbar : function(){
44676 return this.toolbar;
44679 setActiveState : function(active)
44681 this.active = active;
44682 this.setActiveClass(active);
44684 if(this.fireEvent("deactivate", this) === false){
44689 this.fireEvent("activate", this);
44693 * Updates this panel's element (not for iframe)
44694 * @param {String} content The new content
44695 * @param {Boolean} loadScripts (optional) true to look for and process scripts
44697 setContent : function(content, loadScripts){
44702 this.el.update(content, loadScripts);
44705 ignoreResize : function(w, h)
44707 //return false; // always resize?
44708 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
44711 this.lastSize = {width: w, height: h};
44716 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
44717 * @return {Roo.UpdateManager} The UpdateManager
44719 getUpdateManager : function(){
44723 return this.el.getUpdateManager();
44726 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
44727 * Does not work with IFRAME contents
44728 * @param {Object/String/Function} url The url for this request or a function to call to get the url or a config object containing any of the following options:
44731 url: "your-url.php",
44732 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
44733 callback: yourFunction,
44734 scope: yourObject, //(optional scope)
44737 text: "Loading...",
44743 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
44744 * are shorthand for <i>disableCaching</i>, <i>indicatorText</i> and <i>loadScripts</i> and are used to set their associated property on this panel UpdateManager instance.
44745 * @param {String/Object} params (optional) The parameters to pass as either a URL encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
44746 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
44747 * @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used URL. If true, it will not store the URL.
44748 * @return {Roo.ContentPanel} this
44756 var um = this.el.getUpdateManager();
44757 um.update.apply(um, arguments);
44763 * Set a URL to be used to load the content for this panel. When this panel is activated, the content will be loaded from that URL.
44764 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
44765 * @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Roo.UpdateManager#update} for more details. (Defaults to null)
44766 * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this panel is activated. (Defaults to false)
44767 * @return {Roo.UpdateManager|Boolean} The UpdateManager or false if IFRAME
44769 setUrl : function(url, params, loadOnce){
44771 this.iframeEl.dom.src = url;
44775 if(this.refreshDelegate){
44776 this.removeListener("activate", this.refreshDelegate);
44778 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
44779 this.on("activate", this.refreshDelegate);
44780 return this.el.getUpdateManager();
44783 _handleRefresh : function(url, params, loadOnce){
44784 if(!loadOnce || !this.loaded){
44785 var updater = this.el.getUpdateManager();
44786 updater.update(url, params, this._setLoaded.createDelegate(this));
44790 _setLoaded : function(){
44791 this.loaded = true;
44795 * Returns this panel's id
44798 getId : function(){
44803 * Returns this panel's element - used by regiosn to add.
44804 * @return {Roo.Element}
44806 getEl : function(){
44807 return this.wrapEl || this.el;
44812 adjustForComponents : function(width, height)
44814 //Roo.log('adjustForComponents ');
44815 if(this.resizeEl != this.el){
44816 width -= this.el.getFrameWidth('lr');
44817 height -= this.el.getFrameWidth('tb');
44820 var te = this.toolbar.getEl();
44821 te.setWidth(width);
44822 height -= te.getHeight();
44825 var te = this.footer.getEl();
44826 te.setWidth(width);
44827 height -= te.getHeight();
44831 if(this.adjustments){
44832 width += this.adjustments[0];
44833 height += this.adjustments[1];
44835 return {"width": width, "height": height};
44838 setSize : function(width, height){
44839 if(this.fitToFrame && !this.ignoreResize(width, height)){
44840 if(this.fitContainer && this.resizeEl != this.el){
44841 this.el.setSize(width, height);
44843 var size = this.adjustForComponents(width, height);
44845 this.iframeEl.setSize(width,height);
44848 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
44849 this.fireEvent('resize', this, size.width, size.height);
44856 * Returns this panel's title
44859 getTitle : function(){
44861 if (typeof(this.title) != 'object') {
44866 for (var k in this.title) {
44867 if (!this.title.hasOwnProperty(k)) {
44871 if (k.indexOf('-') >= 0) {
44872 var s = k.split('-');
44873 for (var i = 0; i<s.length; i++) {
44874 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
44877 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
44884 * Set this panel's title
44885 * @param {String} title
44887 setTitle : function(title){
44888 this.title = title;
44890 this.region.updatePanelTitle(this, title);
44895 * Returns true is this panel was configured to be closable
44896 * @return {Boolean}
44898 isClosable : function(){
44899 return this.closable;
44902 beforeSlide : function(){
44904 this.resizeEl.clip();
44907 afterSlide : function(){
44909 this.resizeEl.unclip();
44913 * Force a content refresh from the URL specified in the {@link #setUrl} method.
44914 * Will fail silently if the {@link #setUrl} method has not been called.
44915 * This does not activate the panel, just updates its content.
44917 refresh : function(){
44918 if(this.refreshDelegate){
44919 this.loaded = false;
44920 this.refreshDelegate();
44925 * Destroys this panel
44927 destroy : function(){
44928 this.el.removeAllListeners();
44929 var tempEl = document.createElement("span");
44930 tempEl.appendChild(this.el.dom);
44931 tempEl.innerHTML = "";
44937 * form - if the content panel contains a form - this is a reference to it.
44938 * @type {Roo.form.Form}
44942 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
44943 * This contains a reference to it.
44949 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
44959 * @param {Object} cfg Xtype definition of item to add.
44963 getChildContainer: function () {
44964 return this.getEl();
44968 onScroll : function(e)
44970 this.fireEvent('scroll', this, e);
44975 var ret = new Roo.factory(cfg);
44980 if (cfg.xtype.match(/^Form$/)) {
44983 //if (this.footer) {
44984 // el = this.footer.container.insertSibling(false, 'before');
44986 el = this.el.createChild();
44989 this.form = new Roo.form.Form(cfg);
44992 if ( this.form.allItems.length) {
44993 this.form.render(el.dom);
44997 // should only have one of theses..
44998 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
44999 // views.. should not be just added - used named prop 'view''
45001 cfg.el = this.el.appendChild(document.createElement("div"));
45004 var ret = new Roo.factory(cfg);
45006 ret.render && ret.render(false, ''); // render blank..
45016 * @class Roo.bootstrap.panel.Grid
45017 * @extends Roo.bootstrap.panel.Content
45019 * Create a new GridPanel.
45020 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
45021 * @cfg {Roo.bootstrap.nav.Simplebar} toolbar the toolbar at the top of the grid.
45022 * @param {Object} config A the config object
45028 Roo.bootstrap.panel.Grid = function(config)
45032 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
45033 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
45035 config.el = this.wrapper;
45036 //this.el = this.wrapper;
45038 if (config.container) {
45039 // ctor'ed from a Border/panel.grid
45042 this.wrapper.setStyle("overflow", "hidden");
45043 this.wrapper.addClass('roo-grid-container');
45048 if(config.toolbar){
45049 var tool_el = this.wrapper.createChild();
45050 this.toolbar = Roo.factory(config.toolbar);
45052 if (config.toolbar.items) {
45053 ti = config.toolbar.items ;
45054 delete config.toolbar.items ;
45058 this.toolbar.render(tool_el);
45059 for(var i =0;i < ti.length;i++) {
45060 // Roo.log(['add child', items[i]]);
45061 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
45063 this.toolbar.items = nitems;
45065 delete config.toolbar;
45068 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
45069 config.grid.scrollBody = true;;
45070 config.grid.monitorWindowResize = false; // turn off autosizing
45071 config.grid.autoHeight = false;
45072 config.grid.autoWidth = false;
45074 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
45076 if (config.background) {
45077 // render grid on panel activation (if panel background)
45078 this.on('activate', function(gp) {
45079 if (!gp.grid.rendered) {
45080 gp.grid.render(this.wrapper);
45081 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
45086 this.grid.render(this.wrapper);
45087 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
45090 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
45091 // ??? needed ??? config.el = this.wrapper;
45096 // xtype created footer. - not sure if will work as we normally have to render first..
45097 if (this.footer && !this.footer.el && this.footer.xtype) {
45099 var ctr = this.grid.getView().getFooterPanel(true);
45100 this.footer.dataSource = this.grid.dataSource;
45101 this.footer = Roo.factory(this.footer, Roo);
45102 this.footer.render(ctr);
45112 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content,
45115 getId : function(){
45116 return this.grid.id;
45120 * Returns the grid for this panel
45121 * @return {Roo.bootstrap.Table}
45123 getGrid : function(){
45127 setSize : function(width, height)
45130 //if(!this.ignoreResize(width, height)){
45131 var grid = this.grid;
45132 var size = this.adjustForComponents(width, height);
45133 // tfoot is not a footer?
45136 var gridel = grid.getGridEl();
45137 gridel.setSize(size.width, size.height);
45139 var tbd = grid.getGridEl().select('tbody', true).first();
45140 var thd = grid.getGridEl().select('thead',true).first();
45141 var tbf= grid.getGridEl().select('tfoot', true).first();
45144 size.height -= tbf.getHeight();
45147 size.height -= thd.getHeight();
45150 tbd.setSize(size.width, size.height );
45151 // this is for the account management tab -seems to work there.
45152 var thd = grid.getGridEl().select('thead',true).first();
45154 // tbd.setSize(size.width, size.height - thd.getHeight());
45164 beforeSlide : function(){
45165 this.grid.getView().scroller.clip();
45168 afterSlide : function(){
45169 this.grid.getView().scroller.unclip();
45172 destroy : function(){
45173 this.grid.destroy();
45175 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
45180 * @class Roo.bootstrap.panel.Nest
45181 * @extends Roo.bootstrap.panel.Content
45183 * Create a new Panel, that can contain a layout.Border.
45186 * @param {String/Object} config A string to set only the title or a config object
45188 Roo.bootstrap.panel.Nest = function(config)
45190 // construct with only one argument..
45191 /* FIXME - implement nicer consturctors
45192 if (layout.layout) {
45194 layout = config.layout;
45195 delete config.layout;
45197 if (layout.xtype && !layout.getEl) {
45198 // then layout needs constructing..
45199 layout = Roo.factory(layout, Roo);
45203 config.el = config.layout.getEl();
45205 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
45207 config.layout.monitorWindowResize = false; // turn off autosizing
45208 this.layout = config.layout;
45209 this.layout.getEl().addClass("roo-layout-nested-layout");
45210 this.layout.parent = this;
45217 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
45219 * @cfg {Roo.BorderLayout} layout The layout for this panel
45223 setSize : function(width, height){
45224 if(!this.ignoreResize(width, height)){
45225 var size = this.adjustForComponents(width, height);
45226 var el = this.layout.getEl();
45227 if (size.height < 1) {
45228 el.setWidth(size.width);
45230 el.setSize(size.width, size.height);
45232 var touch = el.dom.offsetWidth;
45233 this.layout.layout();
45234 // ie requires a double layout on the first pass
45235 if(Roo.isIE && !this.initialized){
45236 this.initialized = true;
45237 this.layout.layout();
45242 // activate all subpanels if not currently active..
45244 setActiveState : function(active){
45245 this.active = active;
45246 this.setActiveClass(active);
45249 this.fireEvent("deactivate", this);
45253 this.fireEvent("activate", this);
45254 // not sure if this should happen before or after..
45255 if (!this.layout) {
45256 return; // should not happen..
45259 for (var r in this.layout.regions) {
45260 reg = this.layout.getRegion(r);
45261 if (reg.getActivePanel()) {
45262 //reg.showPanel(reg.getActivePanel()); // force it to activate..
45263 reg.setActivePanel(reg.getActivePanel());
45266 if (!reg.panels.length) {
45269 reg.showPanel(reg.getPanel(0));
45278 * Returns the nested BorderLayout for this panel
45279 * @return {Roo.BorderLayout}
45281 getLayout : function(){
45282 return this.layout;
45286 * Adds a xtype elements to the layout of the nested panel
45290 xtype : 'ContentPanel',
45297 xtype : 'NestedLayoutPanel',
45303 items : [ ... list of content panels or nested layout panels.. ]
45307 * @param {Object} cfg Xtype definition of item to add.
45309 addxtype : function(cfg) {
45310 return this.layout.addxtype(cfg);
45315 * Ext JS Library 1.1.1
45316 * Copyright(c) 2006-2007, Ext JS, LLC.
45318 * Originally Released Under LGPL - original licence link has changed is not relivant.
45321 * <script type="text/javascript">
45324 * @class Roo.TabPanel
45325 * @extends Roo.util.Observable
45326 * A lightweight tab container.
45330 // basic tabs 1, built from existing content
45331 var tabs = new Roo.TabPanel("tabs1");
45332 tabs.addTab("script", "View Script");
45333 tabs.addTab("markup", "View Markup");
45334 tabs.activate("script");
45336 // more advanced tabs, built from javascript
45337 var jtabs = new Roo.TabPanel("jtabs");
45338 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
45340 // set up the UpdateManager
45341 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
45342 var updater = tab2.getUpdateManager();
45343 updater.setDefaultUrl("ajax1.htm");
45344 tab2.on('activate', updater.refresh, updater, true);
45346 // Use setUrl for Ajax loading
45347 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
45348 tab3.setUrl("ajax2.htm", null, true);
45351 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
45354 jtabs.activate("jtabs-1");
45357 * Create a new TabPanel.
45358 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
45359 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
45361 Roo.bootstrap.panel.Tabs = function(config){
45363 * The container element for this TabPanel.
45364 * @type Roo.Element
45366 this.el = Roo.get(config.el);
45369 if(typeof config == "boolean"){
45370 this.tabPosition = config ? "bottom" : "top";
45372 Roo.apply(this, config);
45376 if(this.tabPosition == "bottom"){
45377 // if tabs are at the bottom = create the body first.
45378 this.bodyEl = Roo.get(this.createBody(this.el.dom));
45379 this.el.addClass("roo-tabs-bottom");
45381 // next create the tabs holders
45383 if (this.tabPosition == "west"){
45385 var reg = this.region; // fake it..
45387 if (!reg.mgr.parent) {
45390 reg = reg.mgr.parent.region;
45392 Roo.log("got nest?");
45394 if (reg.mgr.getRegion('west')) {
45395 var ctrdom = reg.mgr.getRegion('west').bodyEl.dom;
45396 this.stripWrap = Roo.get(this.createStrip(ctrdom ), true);
45397 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
45398 this.stripEl.setVisibilityMode(Roo.Element.DISPLAY);
45399 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
45407 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
45408 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
45409 this.stripEl.setVisibilityMode(Roo.Element.DISPLAY);
45410 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
45415 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
45418 // finally - if tabs are at the top, then create the body last..
45419 if(this.tabPosition != "bottom"){
45420 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
45421 * @type Roo.Element
45423 this.bodyEl = Roo.get(this.createBody(this.el.dom));
45424 this.el.addClass("roo-tabs-top");
45428 this.bodyEl.setStyle("position", "relative");
45430 this.active = null;
45431 this.activateDelegate = this.activate.createDelegate(this);
45436 * Fires when the active tab changes
45437 * @param {Roo.TabPanel} this
45438 * @param {Roo.TabPanelItem} activePanel The new active tab
45442 * @event beforetabchange
45443 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
45444 * @param {Roo.TabPanel} this
45445 * @param {Object} e Set cancel to true on this object to cancel the tab change
45446 * @param {Roo.TabPanelItem} tab The tab being changed to
45448 "beforetabchange" : true
45451 Roo.EventManager.onWindowResize(this.onResize, this);
45452 this.cpad = this.el.getPadding("lr");
45453 this.hiddenCount = 0;
45456 // toolbar on the tabbar support...
45457 if (this.toolbar) {
45458 alert("no toolbar support yet");
45459 this.toolbar = false;
45461 var tcfg = this.toolbar;
45462 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
45463 this.toolbar = new Roo.Toolbar(tcfg);
45464 if (Roo.isSafari) {
45465 var tbl = tcfg.container.child('table', true);
45466 tbl.setAttribute('width', '100%');
45474 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
45477 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
45479 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
45481 tabPosition : "top",
45483 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
45485 currentTabWidth : 0,
45487 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
45491 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
45495 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
45497 preferredTabWidth : 175,
45499 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
45501 resizeTabs : false,
45503 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
45505 monitorResize : true,
45507 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
45509 toolbar : false, // set by caller..
45511 region : false, /// set by caller
45513 disableTooltips : true, // not used yet...
45516 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
45517 * @param {String} id The id of the div to use <b>or create</b>
45518 * @param {String} text The text for the tab
45519 * @param {String} content (optional) Content to put in the TabPanelItem body
45520 * @param {Boolean} closable (optional) True to create a close icon on the tab
45521 * @return {Roo.TabPanelItem} The created TabPanelItem
45523 addTab : function(id, text, content, closable, tpl)
45525 var item = new Roo.bootstrap.panel.TabItem({
45529 closable : closable,
45532 this.addTabItem(item);
45534 item.setContent(content);
45540 * Returns the {@link Roo.TabPanelItem} with the specified id/index
45541 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
45542 * @return {Roo.TabPanelItem}
45544 getTab : function(id){
45545 return this.items[id];
45549 * Hides the {@link Roo.TabPanelItem} with the specified id/index
45550 * @param {String/Number} id The id or index of the TabPanelItem to hide.
45552 hideTab : function(id){
45553 var t = this.items[id];
45556 this.hiddenCount++;
45557 this.autoSizeTabs();
45562 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
45563 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
45565 unhideTab : function(id){
45566 var t = this.items[id];
45568 t.setHidden(false);
45569 this.hiddenCount--;
45570 this.autoSizeTabs();
45575 * Adds an existing {@link Roo.TabPanelItem}.
45576 * @param {Roo.TabPanelItem} item The TabPanelItem to add
45578 addTabItem : function(item)
45580 this.items[item.id] = item;
45581 this.items.push(item);
45582 this.autoSizeTabs();
45583 // if(this.resizeTabs){
45584 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
45585 // this.autoSizeTabs();
45587 // item.autoSize();
45592 * Removes a {@link Roo.TabPanelItem}.
45593 * @param {String/Number} id The id or index of the TabPanelItem to remove.
45595 removeTab : function(id){
45596 var items = this.items;
45597 var tab = items[id];
45598 if(!tab) { return; }
45599 var index = items.indexOf(tab);
45600 if(this.active == tab && items.length > 1){
45601 var newTab = this.getNextAvailable(index);
45606 this.stripEl.dom.removeChild(tab.pnode.dom);
45607 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
45608 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
45610 items.splice(index, 1);
45611 delete this.items[tab.id];
45612 tab.fireEvent("close", tab);
45613 tab.purgeListeners();
45614 this.autoSizeTabs();
45617 getNextAvailable : function(start){
45618 var items = this.items;
45620 // look for a next tab that will slide over to
45621 // replace the one being removed
45622 while(index < items.length){
45623 var item = items[++index];
45624 if(item && !item.isHidden()){
45628 // if one isn't found select the previous tab (on the left)
45631 var item = items[--index];
45632 if(item && !item.isHidden()){
45640 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
45641 * @param {String/Number} id The id or index of the TabPanelItem to disable.
45643 disableTab : function(id){
45644 var tab = this.items[id];
45645 if(tab && this.active != tab){
45651 * Enables a {@link Roo.TabPanelItem} that is disabled.
45652 * @param {String/Number} id The id or index of the TabPanelItem to enable.
45654 enableTab : function(id){
45655 var tab = this.items[id];
45660 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
45661 * @param {String/Number} id The id or index of the TabPanelItem to activate.
45662 * @return {Roo.TabPanelItem} The TabPanelItem.
45664 activate : function(id)
45666 //Roo.log('activite:' + id);
45668 var tab = this.items[id];
45672 if(tab == this.active || tab.disabled){
45676 this.fireEvent("beforetabchange", this, e, tab);
45677 if(e.cancel !== true && !tab.disabled){
45679 this.active.hide();
45681 this.active = this.items[id];
45682 this.active.show();
45683 this.fireEvent("tabchange", this, this.active);
45689 * Gets the active {@link Roo.TabPanelItem}.
45690 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
45692 getActiveTab : function(){
45693 return this.active;
45697 * Updates the tab body element to fit the height of the container element
45698 * for overflow scrolling
45699 * @param {Number} targetHeight (optional) Override the starting height from the elements height
45701 syncHeight : function(targetHeight){
45702 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
45703 var bm = this.bodyEl.getMargins();
45704 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
45705 this.bodyEl.setHeight(newHeight);
45709 onResize : function(){
45710 if(this.monitorResize){
45711 this.autoSizeTabs();
45716 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
45718 beginUpdate : function(){
45719 this.updating = true;
45723 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
45725 endUpdate : function(){
45726 this.updating = false;
45727 this.autoSizeTabs();
45731 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
45733 autoSizeTabs : function()
45735 var count = this.items.length;
45736 var vcount = count - this.hiddenCount;
45739 this.stripEl.hide();
45741 this.stripEl.show();
45744 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
45749 var w = Math.max(this.el.getWidth() - this.cpad, 10);
45750 var availWidth = Math.floor(w / vcount);
45751 var b = this.stripBody;
45752 if(b.getWidth() > w){
45753 var tabs = this.items;
45754 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
45755 if(availWidth < this.minTabWidth){
45756 /*if(!this.sleft){ // incomplete scrolling code
45757 this.createScrollButtons();
45760 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
45763 if(this.currentTabWidth < this.preferredTabWidth){
45764 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
45770 * Returns the number of tabs in this TabPanel.
45773 getCount : function(){
45774 return this.items.length;
45778 * Resizes all the tabs to the passed width
45779 * @param {Number} The new width
45781 setTabWidth : function(width){
45782 this.currentTabWidth = width;
45783 for(var i = 0, len = this.items.length; i < len; i++) {
45784 if(!this.items[i].isHidden()) {
45785 this.items[i].setWidth(width);
45791 * Destroys this TabPanel
45792 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
45794 destroy : function(removeEl){
45795 Roo.EventManager.removeResizeListener(this.onResize, this);
45796 for(var i = 0, len = this.items.length; i < len; i++){
45797 this.items[i].purgeListeners();
45799 if(removeEl === true){
45800 this.el.update("");
45805 createStrip : function(container)
45807 var strip = document.createElement("nav");
45808 strip.className = Roo.bootstrap.version == 4 ?
45809 "navbar-light bg-light" :
45810 "navbar navbar-default"; //"x-tabs-wrap";
45811 container.appendChild(strip);
45815 createStripList : function(strip)
45817 // div wrapper for retard IE
45818 // returns the "tr" element.
45819 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
45820 //'<div class="x-tabs-strip-wrap">'+
45821 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
45822 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
45823 return strip.firstChild; //.firstChild.firstChild.firstChild;
45825 createBody : function(container)
45827 var body = document.createElement("div");
45828 Roo.id(body, "tab-body");
45829 //Roo.fly(body).addClass("x-tabs-body");
45830 Roo.fly(body).addClass("tab-content");
45831 container.appendChild(body);
45834 createItemBody :function(bodyEl, id){
45835 var body = Roo.getDom(id);
45837 body = document.createElement("div");
45840 //Roo.fly(body).addClass("x-tabs-item-body");
45841 Roo.fly(body).addClass("tab-pane");
45842 bodyEl.insertBefore(body, bodyEl.firstChild);
45846 createStripElements : function(stripEl, text, closable, tpl)
45848 var td = document.createElement("li"); // was td..
45849 td.className = 'nav-item';
45851 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
45854 stripEl.appendChild(td);
45856 td.className = "x-tabs-closable";
45857 if(!this.closeTpl){
45858 this.closeTpl = new Roo.Template(
45859 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
45860 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
45861 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
45864 var el = this.closeTpl.overwrite(td, {"text": text});
45865 var close = el.getElementsByTagName("div")[0];
45866 var inner = el.getElementsByTagName("em")[0];
45867 return {"el": el, "close": close, "inner": inner};
45870 // not sure what this is..
45871 // if(!this.tabTpl){
45872 //this.tabTpl = new Roo.Template(
45873 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
45874 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
45876 // this.tabTpl = new Roo.Template(
45877 // '<a href="#">' +
45878 // '<span unselectable="on"' +
45879 // (this.disableTooltips ? '' : ' title="{text}"') +
45880 // ' >{text}</span></a>'
45886 var template = tpl || this.tabTpl || false;
45889 template = new Roo.Template(
45890 Roo.bootstrap.version == 4 ?
45892 '<a class="nav-link" href="#" unselectable="on"' +
45893 (this.disableTooltips ? '' : ' title="{text}"') +
45896 '<a class="nav-link" href="#">' +
45897 '<span unselectable="on"' +
45898 (this.disableTooltips ? '' : ' title="{text}"') +
45899 ' >{text}</span></a>'
45904 switch (typeof(template)) {
45908 template = new Roo.Template(template);
45914 var el = template.overwrite(td, {"text": text});
45916 var inner = el.getElementsByTagName("span")[0];
45918 return {"el": el, "inner": inner};
45926 * @class Roo.TabPanelItem
45927 * @extends Roo.util.Observable
45928 * Represents an individual item (tab plus body) in a TabPanel.
45929 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
45930 * @param {String} id The id of this TabPanelItem
45931 * @param {String} text The text for the tab of this TabPanelItem
45932 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
45934 Roo.bootstrap.panel.TabItem = function(config){
45936 * The {@link Roo.TabPanel} this TabPanelItem belongs to
45937 * @type Roo.TabPanel
45939 this.tabPanel = config.panel;
45941 * The id for this TabPanelItem
45944 this.id = config.id;
45946 this.disabled = false;
45948 this.text = config.text;
45950 this.loaded = false;
45951 this.closable = config.closable;
45954 * The body element for this TabPanelItem.
45955 * @type Roo.Element
45957 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
45958 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
45959 this.bodyEl.setStyle("display", "block");
45960 this.bodyEl.setStyle("zoom", "1");
45961 //this.hideAction();
45963 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
45965 this.el = Roo.get(els.el);
45966 this.inner = Roo.get(els.inner, true);
45967 this.textEl = Roo.bootstrap.version == 4 ?
45968 this.el : Roo.get(this.el.dom.firstChild, true);
45970 this.pnode = this.linode = Roo.get(els.el.parentNode, true);
45971 this.status_node = Roo.bootstrap.version == 4 ? this.el : this.linode;
45974 // this.el.on("mousedown", this.onTabMouseDown, this);
45975 this.el.on("click", this.onTabClick, this);
45977 if(config.closable){
45978 var c = Roo.get(els.close, true);
45979 c.dom.title = this.closeText;
45980 c.addClassOnOver("close-over");
45981 c.on("click", this.closeClick, this);
45987 * Fires when this tab becomes the active tab.
45988 * @param {Roo.TabPanel} tabPanel The parent TabPanel
45989 * @param {Roo.TabPanelItem} this
45993 * @event beforeclose
45994 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
45995 * @param {Roo.TabPanelItem} this
45996 * @param {Object} e Set cancel to true on this object to cancel the close.
45998 "beforeclose": true,
46001 * Fires when this tab is closed.
46002 * @param {Roo.TabPanelItem} this
46006 * @event deactivate
46007 * Fires when this tab is no longer the active tab.
46008 * @param {Roo.TabPanel} tabPanel The parent TabPanel
46009 * @param {Roo.TabPanelItem} this
46011 "deactivate" : true
46013 this.hidden = false;
46015 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
46018 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
46020 purgeListeners : function(){
46021 Roo.util.Observable.prototype.purgeListeners.call(this);
46022 this.el.removeAllListeners();
46025 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
46028 this.status_node.addClass("active");
46031 this.tabPanel.stripWrap.repaint();
46033 this.fireEvent("activate", this.tabPanel, this);
46037 * Returns true if this tab is the active tab.
46038 * @return {Boolean}
46040 isActive : function(){
46041 return this.tabPanel.getActiveTab() == this;
46045 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
46048 this.status_node.removeClass("active");
46050 this.fireEvent("deactivate", this.tabPanel, this);
46053 hideAction : function(){
46054 this.bodyEl.hide();
46055 this.bodyEl.setStyle("position", "absolute");
46056 this.bodyEl.setLeft("-20000px");
46057 this.bodyEl.setTop("-20000px");
46060 showAction : function(){
46061 this.bodyEl.setStyle("position", "relative");
46062 this.bodyEl.setTop("");
46063 this.bodyEl.setLeft("");
46064 this.bodyEl.show();
46068 * Set the tooltip for the tab.
46069 * @param {String} tooltip The tab's tooltip
46071 setTooltip : function(text){
46072 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
46073 this.textEl.dom.qtip = text;
46074 this.textEl.dom.removeAttribute('title');
46076 this.textEl.dom.title = text;
46080 onTabClick : function(e){
46081 e.preventDefault();
46082 this.tabPanel.activate(this.id);
46085 onTabMouseDown : function(e){
46086 e.preventDefault();
46087 this.tabPanel.activate(this.id);
46090 getWidth : function(){
46091 return this.inner.getWidth();
46094 setWidth : function(width){
46095 var iwidth = width - this.linode.getPadding("lr");
46096 this.inner.setWidth(iwidth);
46097 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
46098 this.linode.setWidth(width);
46102 * Show or hide the tab
46103 * @param {Boolean} hidden True to hide or false to show.
46105 setHidden : function(hidden){
46106 this.hidden = hidden;
46107 this.linode.setStyle("display", hidden ? "none" : "");
46111 * Returns true if this tab is "hidden"
46112 * @return {Boolean}
46114 isHidden : function(){
46115 return this.hidden;
46119 * Returns the text for this tab
46122 getText : function(){
46126 autoSize : function(){
46127 //this.el.beginMeasure();
46128 this.textEl.setWidth(1);
46130 * #2804 [new] Tabs in Roojs
46131 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
46133 //this.setWidth(this.textEl.dom.scrollWidth+this.linode.getPadding("lr")+this.inner.getPadding("lr") + 2);
46134 //this.el.endMeasure();
46138 * Sets the text for the tab (Note: this also sets the tooltip text)
46139 * @param {String} text The tab's text and tooltip
46141 setText : function(text){
46143 this.textEl.update(text);
46144 this.setTooltip(text);
46145 //if(!this.tabPanel.resizeTabs){
46146 // this.autoSize();
46150 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
46152 activate : function(){
46153 this.tabPanel.activate(this.id);
46157 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
46159 disable : function(){
46160 if(this.tabPanel.active != this){
46161 this.disabled = true;
46162 this.status_node.addClass("disabled");
46167 * Enables this TabPanelItem if it was previously disabled.
46169 enable : function(){
46170 this.disabled = false;
46171 this.status_node.removeClass("disabled");
46175 * Sets the content for this TabPanelItem.
46176 * @param {String} content The content
46177 * @param {Boolean} loadScripts true to look for and load scripts
46179 setContent : function(content, loadScripts){
46180 this.bodyEl.update(content, loadScripts);
46184 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
46185 * @return {Roo.UpdateManager} The UpdateManager
46187 getUpdateManager : function(){
46188 return this.bodyEl.getUpdateManager();
46192 * Set a URL to be used to load the content for this TabPanelItem.
46193 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
46194 * @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Roo.UpdateManager#update} for more details. (Defaults to null)
46195 * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this TabPanelItem is activated. (Defaults to false)
46196 * @return {Roo.UpdateManager} The UpdateManager
46198 setUrl : function(url, params, loadOnce){
46199 if(this.refreshDelegate){
46200 this.un('activate', this.refreshDelegate);
46202 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
46203 this.on("activate", this.refreshDelegate);
46204 return this.bodyEl.getUpdateManager();
46208 _handleRefresh : function(url, params, loadOnce){
46209 if(!loadOnce || !this.loaded){
46210 var updater = this.bodyEl.getUpdateManager();
46211 updater.update(url, params, this._setLoaded.createDelegate(this));
46216 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
46217 * Will fail silently if the setUrl method has not been called.
46218 * This does not activate the panel, just updates its content.
46220 refresh : function(){
46221 if(this.refreshDelegate){
46222 this.loaded = false;
46223 this.refreshDelegate();
46228 _setLoaded : function(){
46229 this.loaded = true;
46233 closeClick : function(e){
46236 this.fireEvent("beforeclose", this, o);
46237 if(o.cancel !== true){
46238 this.tabPanel.removeTab(this.id);
46242 * The text displayed in the tooltip for the close icon.
46245 closeText : "Close this tab"
46248 * This script refer to:
46249 * Title: International Telephone Input
46250 * Author: Jack O'Connor
46251 * Code version: v12.1.12
46252 * Availability: https://github.com/jackocnr/intl-tel-input.git
46255 Roo.bootstrap.form.PhoneInputData = function() {
46258 "Afghanistan (افغانستان)",
46263 "Albania (Shqipëri)",
46268 "Algeria (الجزائر)",
46293 "Antigua and Barbuda",
46303 "Armenia (Հայաստան)",
46319 "Austria (Österreich)",
46324 "Azerbaijan (Azərbaycan)",
46334 "Bahrain (البحرين)",
46339 "Bangladesh (বাংলাদেশ)",
46349 "Belarus (Беларусь)",
46354 "Belgium (België)",
46384 "Bosnia and Herzegovina (Босна и Херцеговина)",
46399 "British Indian Ocean Territory",
46404 "British Virgin Islands",
46414 "Bulgaria (България)",
46424 "Burundi (Uburundi)",
46429 "Cambodia (កម្ពុជា)",
46434 "Cameroon (Cameroun)",
46443 ["204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905"]
46446 "Cape Verde (Kabu Verdi)",
46451 "Caribbean Netherlands",
46462 "Central African Republic (République centrafricaine)",
46482 "Christmas Island",
46488 "Cocos (Keeling) Islands",
46499 "Comoros (جزر القمر)",
46504 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
46509 "Congo (Republic) (Congo-Brazzaville)",
46529 "Croatia (Hrvatska)",
46550 "Czech Republic (Česká republika)",
46555 "Denmark (Danmark)",
46570 "Dominican Republic (República Dominicana)",
46574 ["809", "829", "849"]
46592 "Equatorial Guinea (Guinea Ecuatorial)",
46612 "Falkland Islands (Islas Malvinas)",
46617 "Faroe Islands (Føroyar)",
46638 "French Guiana (Guyane française)",
46643 "French Polynesia (Polynésie française)",
46658 "Georgia (საქართველო)",
46663 "Germany (Deutschland)",
46683 "Greenland (Kalaallit Nunaat)",
46720 "Guinea-Bissau (Guiné Bissau)",
46745 "Hungary (Magyarország)",
46750 "Iceland (Ísland)",
46770 "Iraq (العراق)",
46786 "Israel (ישראל)",
46813 "Jordan (الأردن)",
46818 "Kazakhstan (Казахстан)",
46839 "Kuwait (الكويت)",
46844 "Kyrgyzstan (Кыргызстан)",
46854 "Latvia (Latvija)",
46859 "Lebanon (لبنان)",
46874 "Libya (ليبيا)",
46884 "Lithuania (Lietuva)",
46899 "Macedonia (FYROM) (Македонија)",
46904 "Madagascar (Madagasikara)",
46934 "Marshall Islands",
46944 "Mauritania (موريتانيا)",
46949 "Mauritius (Moris)",
46970 "Moldova (Republica Moldova)",
46980 "Mongolia (Монгол)",
46985 "Montenegro (Crna Gora)",
46995 "Morocco (المغرب)",
47001 "Mozambique (Moçambique)",
47006 "Myanmar (Burma) (မြန်မာ)",
47011 "Namibia (Namibië)",
47026 "Netherlands (Nederland)",
47031 "New Caledonia (Nouvelle-Calédonie)",
47066 "North Korea (조선 민주주의 인민 공화국)",
47071 "Northern Mariana Islands",
47087 "Pakistan (پاکستان)",
47097 "Palestine (فلسطين)",
47107 "Papua New Guinea",
47149 "Réunion (La Réunion)",
47155 "Romania (România)",
47171 "Saint Barthélemy",
47182 "Saint Kitts and Nevis",
47192 "Saint Martin (Saint-Martin (partie française))",
47198 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
47203 "Saint Vincent and the Grenadines",
47218 "São Tomé and Príncipe (São Tomé e Príncipe)",
47223 "Saudi Arabia (المملكة العربية السعودية)",
47228 "Senegal (Sénégal)",
47258 "Slovakia (Slovensko)",
47263 "Slovenia (Slovenija)",
47273 "Somalia (Soomaaliya)",
47283 "South Korea (대한민국)",
47288 "South Sudan (جنوب السودان)",
47298 "Sri Lanka (ශ්රී ලංකාව)",
47303 "Sudan (السودان)",
47313 "Svalbard and Jan Mayen",
47324 "Sweden (Sverige)",
47329 "Switzerland (Schweiz)",
47334 "Syria (سوريا)",
47379 "Trinidad and Tobago",
47384 "Tunisia (تونس)",
47389 "Turkey (Türkiye)",
47399 "Turks and Caicos Islands",
47409 "U.S. Virgin Islands",
47419 "Ukraine (Україна)",
47424 "United Arab Emirates (الإمارات العربية المتحدة)",
47446 "Uzbekistan (Oʻzbekiston)",
47456 "Vatican City (Città del Vaticano)",
47467 "Vietnam (Việt Nam)",
47472 "Wallis and Futuna (Wallis-et-Futuna)",
47477 "Western Sahara (الصحراء الغربية)",
47483 "Yemen (اليمن)",
47507 * This script refer to:
47508 * Title: International Telephone Input
47509 * Author: Jack O'Connor
47510 * Code version: v12.1.12
47511 * Availability: https://github.com/jackocnr/intl-tel-input.git
47515 * @class Roo.bootstrap.form.PhoneInput
47516 * @extends Roo.bootstrap.form.TriggerField
47517 * An input with International dial-code selection
47519 * @cfg {String} defaultDialCode default '+852'
47520 * @cfg {Array} preferedCountries default []
47523 * Create a new PhoneInput.
47524 * @param {Object} config Configuration options
47527 Roo.bootstrap.form.PhoneInput = function(config) {
47528 Roo.bootstrap.form.PhoneInput.superclass.constructor.call(this, config);
47531 Roo.extend(Roo.bootstrap.form.PhoneInput, Roo.bootstrap.form.TriggerField, {
47533 * @cfg {Roo.data.Store} store [required] The data store to which this combo is bound (defaults to undefined)
47535 listWidth: undefined,
47537 selectedClass: 'active',
47539 invalidClass : "has-warning",
47541 validClass: 'has-success',
47543 allowed: '0123456789',
47548 * @cfg {String} defaultDialCode The default dial code when initializing the input
47550 defaultDialCode: '+852',
47553 * @cfg {Array} preferedCountries A list of iso2 in array (e.g. ['hk','us']). Those related countries will show at the top of the input's choices
47555 preferedCountries: false,
47557 getAutoCreate : function()
47559 var data = Roo.bootstrap.form.PhoneInputData();
47560 var align = this.labelAlign || this.parentLabelAlign();
47563 this.allCountries = [];
47564 this.dialCodeMapping = [];
47566 for (var i = 0; i < data.length; i++) {
47568 this.allCountries[i] = {
47572 priority: c[3] || 0,
47573 areaCodes: c[4] || null
47575 this.dialCodeMapping[c[2]] = {
47578 priority: c[3] || 0,
47579 areaCodes: c[4] || null
47591 // type: 'number', -- do not use number - we get the flaky up/down arrows.
47592 maxlength: this.max_length,
47593 cls : 'form-control tel-input',
47594 autocomplete: 'new-password'
47597 var hiddenInput = {
47600 cls: 'hidden-tel-input'
47604 hiddenInput.name = this.name;
47607 if (this.disabled) {
47608 input.disabled = true;
47611 var flag_container = {
47628 cls: this.hasFeedback ? 'has-feedback' : '',
47634 cls: 'dial-code-holder',
47641 cls: 'roo-select2-container input-group',
47648 if (this.fieldLabel.length) {
47651 tooltip: 'This field is required'
47657 cls: 'control-label',
47663 html: this.fieldLabel
47666 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
47672 if(this.indicatorpos == 'right') {
47673 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
47680 if(align == 'left') {
47688 if(this.labelWidth > 12){
47689 label.style = "width: " + this.labelWidth + 'px';
47691 if(this.labelWidth < 13 && this.labelmd == 0){
47692 this.labelmd = this.labelWidth;
47694 if(this.labellg > 0){
47695 label.cls += ' col-lg-' + this.labellg;
47696 input.cls += ' col-lg-' + (12 - this.labellg);
47698 if(this.labelmd > 0){
47699 label.cls += ' col-md-' + this.labelmd;
47700 container.cls += ' col-md-' + (12 - this.labelmd);
47702 if(this.labelsm > 0){
47703 label.cls += ' col-sm-' + this.labelsm;
47704 container.cls += ' col-sm-' + (12 - this.labelsm);
47706 if(this.labelxs > 0){
47707 label.cls += ' col-xs-' + this.labelxs;
47708 container.cls += ' col-xs-' + (12 - this.labelxs);
47718 var settings = this;
47720 ['xs','sm','md','lg'].map(function(size){
47721 if (settings[size]) {
47722 cfg.cls += ' col-' + size + '-' + settings[size];
47726 this.store = new Roo.data.Store({
47727 proxy : new Roo.data.MemoryProxy({}),
47728 reader : new Roo.data.JsonReader({
47739 'name' : 'dialCode',
47743 'name' : 'priority',
47747 'name' : 'areaCodes',
47754 if(!this.preferedCountries) {
47755 this.preferedCountries = [
47762 var p = this.preferedCountries.reverse();
47765 for (var i = 0; i < p.length; i++) {
47766 for (var j = 0; j < this.allCountries.length; j++) {
47767 if(this.allCountries[j].iso2 == p[i]) {
47768 var t = this.allCountries[j];
47769 this.allCountries.splice(j,1);
47770 this.allCountries.unshift(t);
47776 this.store.proxy.data = {
47778 data: this.allCountries
47784 initEvents : function()
47787 Roo.bootstrap.form.PhoneInput.superclass.initEvents.call(this);
47789 this.indicator = this.indicatorEl();
47790 this.flag = this.flagEl();
47791 this.dialCodeHolder = this.dialCodeHolderEl();
47793 this.trigger = this.el.select('div.flag-box',true).first();
47794 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
47799 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
47800 _this.list.setWidth(lw);
47803 this.list.on('mouseover', this.onViewOver, this);
47804 this.list.on('mousemove', this.onViewMove, this);
47805 this.inputEl().on("keyup", this.onKeyUp, this);
47806 this.inputEl().on("keypress", this.onKeyPress, this);
47808 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
47810 this.view = new Roo.View(this.list, this.tpl, {
47811 singleSelect:true, store: this.store, selectedClass: this.selectedClass
47814 this.view.on('click', this.onViewClick, this);
47815 this.setValue(this.defaultDialCode);
47818 onTriggerClick : function(e)
47820 Roo.log('trigger click');
47825 if(this.isExpanded()){
47827 this.hasFocus = false;
47829 this.store.load({});
47830 this.hasFocus = true;
47835 isExpanded : function()
47837 return this.list.isVisible();
47840 collapse : function()
47842 if(!this.isExpanded()){
47846 Roo.get(document).un('mousedown', this.collapseIf, this);
47847 Roo.get(document).un('mousewheel', this.collapseIf, this);
47848 this.fireEvent('collapse', this);
47852 expand : function()
47856 if(this.isExpanded() || !this.hasFocus){
47860 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
47861 this.list.setWidth(lw);
47864 this.restrictHeight();
47866 Roo.get(document).on('mousedown', this.collapseIf, this);
47867 Roo.get(document).on('mousewheel', this.collapseIf, this);
47869 this.fireEvent('expand', this);
47872 restrictHeight : function()
47874 this.list.alignTo(this.inputEl(), this.listAlign);
47875 this.list.alignTo(this.inputEl(), this.listAlign);
47878 onViewOver : function(e, t)
47880 if(this.inKeyMode){
47883 var item = this.view.findItemFromChild(t);
47886 var index = this.view.indexOf(item);
47887 this.select(index, false);
47892 onViewClick : function(view, doFocus, el, e)
47894 var index = this.view.getSelectedIndexes()[0];
47896 var r = this.store.getAt(index);
47899 this.onSelect(r, index);
47901 if(doFocus !== false && !this.blockFocus){
47902 this.inputEl().focus();
47906 onViewMove : function(e, t)
47908 this.inKeyMode = false;
47911 select : function(index, scrollIntoView)
47913 this.selectedIndex = index;
47914 this.view.select(index);
47915 if(scrollIntoView !== false){
47916 var el = this.view.getNode(index);
47918 this.list.scrollChildIntoView(el, false);
47923 createList : function()
47925 this.list = Roo.get(document.body).createChild({
47927 cls: 'typeahead typeahead-long dropdown-menu tel-list',
47928 style: 'display:none'
47931 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
47934 collapseIf : function(e)
47936 var in_combo = e.within(this.el);
47937 var in_list = e.within(this.list);
47938 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
47940 if (in_combo || in_list || is_list) {
47946 onSelect : function(record, index)
47948 if(this.fireEvent('beforeselect', this, record, index) !== false){
47950 this.setFlagClass(record.data.iso2);
47951 this.setDialCode(record.data.dialCode);
47952 this.hasFocus = false;
47954 this.fireEvent('select', this, record, index);
47958 flagEl : function()
47960 var flag = this.el.select('div.flag',true).first();
47967 dialCodeHolderEl : function()
47969 var d = this.el.select('input.dial-code-holder',true).first();
47976 setDialCode : function(v)
47978 this.dialCodeHolder.dom.value = '+'+v;
47981 setFlagClass : function(n)
47983 this.flag.dom.className = 'flag '+n;
47986 getValue : function()
47988 var v = this.inputEl().getValue();
47989 if(this.dialCodeHolder) {
47990 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
47995 setValue : function(v)
47997 var d = this.getDialCode(v);
47999 //invalid dial code
48000 if(v.length == 0 || !d || d.length == 0) {
48002 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
48003 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
48009 this.setFlagClass(this.dialCodeMapping[d].iso2);
48010 this.setDialCode(d);
48011 this.inputEl().dom.value = v.replace('+'+d,'');
48012 this.hiddenEl().dom.value = this.getValue();
48017 getDialCode : function(v)
48021 if (v.length == 0) {
48022 return this.dialCodeHolder.dom.value;
48026 if (v.charAt(0) != "+") {
48029 var numericChars = "";
48030 for (var i = 1; i < v.length; i++) {
48031 var c = v.charAt(i);
48034 if (this.dialCodeMapping[numericChars]) {
48035 dialCode = v.substr(1, i);
48037 if (numericChars.length == 4) {
48047 this.setValue(this.defaultDialCode);
48051 hiddenEl : function()
48053 return this.el.select('input.hidden-tel-input',true).first();
48056 // after setting val
48057 onKeyUp : function(e){
48058 this.setValue(this.getValue());
48061 onKeyPress : function(e){
48062 if(this.allowed.indexOf(String.fromCharCode(e.getCharCode())) === -1){
48069 * @class Roo.bootstrap.form.MoneyField
48070 * @extends Roo.bootstrap.form.ComboBox
48071 * Bootstrap MoneyField class
48074 * Create a new MoneyField.
48075 * @param {Object} config Configuration options
48078 Roo.bootstrap.form.MoneyField = function(config) {
48080 Roo.bootstrap.form.MoneyField.superclass.constructor.call(this, config);
48084 Roo.extend(Roo.bootstrap.form.MoneyField, Roo.bootstrap.form.ComboBox, {
48087 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
48089 allowDecimals : true,
48091 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
48093 decimalSeparator : ".",
48095 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
48097 decimalPrecision : 0,
48099 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
48101 allowNegative : true,
48103 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
48107 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
48109 minValue : Number.NEGATIVE_INFINITY,
48111 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
48113 maxValue : Number.MAX_VALUE,
48115 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
48117 minText : "The minimum value for this field is {0}",
48119 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
48121 maxText : "The maximum value for this field is {0}",
48123 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
48124 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
48126 nanText : "{0} is not a valid number",
48128 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
48132 * @cfg {String} defaults currency of the MoneyField
48133 * value should be in lkey
48135 defaultCurrency : false,
48137 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
48139 thousandsDelimiter : false,
48141 * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
48150 * @cfg {Roo.data.Store} store Store to lookup currency??
48154 getAutoCreate : function()
48156 var align = this.labelAlign || this.parentLabelAlign();
48168 cls : 'form-control roo-money-amount-input',
48169 autocomplete: 'new-password'
48172 var hiddenInput = {
48176 cls: 'hidden-number-input'
48179 if(this.max_length) {
48180 input.maxlength = this.max_length;
48184 hiddenInput.name = this.name;
48187 if (this.disabled) {
48188 input.disabled = true;
48191 var clg = 12 - this.inputlg;
48192 var cmd = 12 - this.inputmd;
48193 var csm = 12 - this.inputsm;
48194 var cxs = 12 - this.inputxs;
48198 cls : 'row roo-money-field',
48202 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
48206 cls: 'roo-select2-container input-group',
48210 cls : 'form-control roo-money-currency-input',
48211 autocomplete: 'new-password',
48213 name : this.currencyName
48217 cls : 'input-group-addon',
48231 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
48235 cls: this.hasFeedback ? 'has-feedback' : '',
48246 if (this.fieldLabel.length) {
48249 tooltip: 'This field is required'
48255 cls: 'control-label',
48261 html: this.fieldLabel
48264 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
48270 if(this.indicatorpos == 'right') {
48271 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
48278 if(align == 'left') {
48286 if(this.labelWidth > 12){
48287 label.style = "width: " + this.labelWidth + 'px';
48289 if(this.labelWidth < 13 && this.labelmd == 0){
48290 this.labelmd = this.labelWidth;
48292 if(this.labellg > 0){
48293 label.cls += ' col-lg-' + this.labellg;
48294 input.cls += ' col-lg-' + (12 - this.labellg);
48296 if(this.labelmd > 0){
48297 label.cls += ' col-md-' + this.labelmd;
48298 container.cls += ' col-md-' + (12 - this.labelmd);
48300 if(this.labelsm > 0){
48301 label.cls += ' col-sm-' + this.labelsm;
48302 container.cls += ' col-sm-' + (12 - this.labelsm);
48304 if(this.labelxs > 0){
48305 label.cls += ' col-xs-' + this.labelxs;
48306 container.cls += ' col-xs-' + (12 - this.labelxs);
48317 var settings = this;
48319 ['xs','sm','md','lg'].map(function(size){
48320 if (settings[size]) {
48321 cfg.cls += ' col-' + size + '-' + settings[size];
48328 initEvents : function()
48330 this.indicator = this.indicatorEl();
48332 this.initCurrencyEvent();
48334 this.initNumberEvent();
48337 initCurrencyEvent : function()
48340 throw "can not find store for combo";
48343 this.store = Roo.factory(this.store, Roo.data);
48344 this.store.parent = this;
48348 this.triggerEl = this.el.select('.input-group-addon', true).first();
48350 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
48355 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
48356 _this.list.setWidth(lw);
48359 this.list.on('mouseover', this.onViewOver, this);
48360 this.list.on('mousemove', this.onViewMove, this);
48361 this.list.on('scroll', this.onViewScroll, this);
48364 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
48367 this.view = new Roo.View(this.list, this.tpl, {
48368 singleSelect:true, store: this.store, selectedClass: this.selectedClass
48371 this.view.on('click', this.onViewClick, this);
48373 this.store.on('beforeload', this.onBeforeLoad, this);
48374 this.store.on('load', this.onLoad, this);
48375 this.store.on('loadexception', this.onLoadException, this);
48377 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
48378 "up" : function(e){
48379 this.inKeyMode = true;
48383 "down" : function(e){
48384 if(!this.isExpanded()){
48385 this.onTriggerClick();
48387 this.inKeyMode = true;
48392 "enter" : function(e){
48395 if(this.fireEvent("specialkey", this, e)){
48396 this.onViewClick(false);
48402 "esc" : function(e){
48406 "tab" : function(e){
48409 if(this.fireEvent("specialkey", this, e)){
48410 this.onViewClick(false);
48418 doRelay : function(foo, bar, hname){
48419 if(hname == 'down' || this.scope.isExpanded()){
48420 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
48428 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
48432 initNumberEvent : function(e)
48434 this.inputEl().on("keydown" , this.fireKey, this);
48435 this.inputEl().on("focus", this.onFocus, this);
48436 this.inputEl().on("blur", this.onBlur, this);
48438 this.inputEl().relayEvent('keyup', this);
48440 if(this.indicator){
48441 this.indicator.addClass('invisible');
48444 this.originalValue = this.getValue();
48446 if(this.validationEvent == 'keyup'){
48447 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
48448 this.inputEl().on('keyup', this.filterValidation, this);
48450 else if(this.validationEvent !== false){
48451 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
48454 if(this.selectOnFocus){
48455 this.on("focus", this.preFocus, this);
48458 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
48459 this.inputEl().on("keypress", this.filterKeys, this);
48461 this.inputEl().relayEvent('keypress', this);
48464 var allowed = "0123456789";
48466 if(this.allowDecimals){
48467 allowed += this.decimalSeparator;
48470 if(this.allowNegative){
48474 if(this.thousandsDelimiter) {
48478 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
48480 var keyPress = function(e){
48482 var k = e.getKey();
48484 var c = e.getCharCode();
48487 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
48488 allowed.indexOf(String.fromCharCode(c)) === -1
48494 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
48498 if(allowed.indexOf(String.fromCharCode(c)) === -1){
48503 this.inputEl().on("keypress", keyPress, this);
48507 onTriggerClick : function(e)
48514 this.loadNext = false;
48516 if(this.isExpanded()){
48521 this.hasFocus = true;
48523 if(this.triggerAction == 'all') {
48524 this.doQuery(this.allQuery, true);
48528 this.doQuery(this.getRawValue());
48531 getCurrency : function()
48533 var v = this.currencyEl().getValue();
48538 restrictHeight : function()
48540 this.list.alignTo(this.currencyEl(), this.listAlign);
48541 this.list.alignTo(this.currencyEl(), this.listAlign);
48544 onViewClick : function(view, doFocus, el, e)
48546 var index = this.view.getSelectedIndexes()[0];
48548 var r = this.store.getAt(index);
48551 this.onSelect(r, index);
48555 onSelect : function(record, index){
48557 if(this.fireEvent('beforeselect', this, record, index) !== false){
48559 this.setFromCurrencyData(index > -1 ? record.data : false);
48563 this.fireEvent('select', this, record, index);
48567 setFromCurrencyData : function(o)
48571 this.lastCurrency = o;
48573 if (this.currencyField) {
48574 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
48576 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
48579 this.lastSelectionText = currency;
48581 //setting default currency
48582 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
48583 this.setCurrency(this.defaultCurrency);
48587 this.setCurrency(currency);
48590 setFromData : function(o)
48594 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
48596 this.setFromCurrencyData(c);
48601 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
48603 Roo.log('no value set for '+ (this.name ? this.name : this.id));
48606 this.setValue(value);
48610 setCurrency : function(v)
48612 this.currencyValue = v;
48615 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
48620 setValue : function(v)
48622 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
48628 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
48630 this.inputEl().dom.value = (v == '') ? '' :
48631 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
48633 if(!this.allowZero && v === '0') {
48634 this.hiddenEl().dom.value = '';
48635 this.inputEl().dom.value = '';
48642 getRawValue : function()
48644 var v = this.inputEl().getValue();
48649 getValue : function()
48651 return this.fixPrecision(this.parseValue(this.getRawValue()));
48654 parseValue : function(value)
48656 if(this.thousandsDelimiter) {
48658 r = new RegExp(",", "g");
48659 value = value.replace(r, "");
48662 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
48663 return isNaN(value) ? '' : value;
48667 fixPrecision : function(value)
48669 if(this.thousandsDelimiter) {
48671 r = new RegExp(",", "g");
48672 value = value.replace(r, "");
48675 var nan = isNaN(value);
48677 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
48678 return nan ? '' : value;
48680 return parseFloat(value).toFixed(this.decimalPrecision);
48683 decimalPrecisionFcn : function(v)
48685 return Math.floor(v);
48688 validateValue : function(value)
48690 if(!Roo.bootstrap.form.MoneyField.superclass.validateValue.call(this, value)){
48694 var num = this.parseValue(value);
48697 this.markInvalid(String.format(this.nanText, value));
48701 if(num < this.minValue){
48702 this.markInvalid(String.format(this.minText, this.minValue));
48706 if(num > this.maxValue){
48707 this.markInvalid(String.format(this.maxText, this.maxValue));
48714 validate : function()
48716 if(this.disabled || this.allowBlank){
48721 var currency = this.getCurrency();
48723 if(this.validateValue(this.getRawValue()) && currency.length){
48728 this.markInvalid();
48732 getName: function()
48737 beforeBlur : function()
48743 var v = this.parseValue(this.getRawValue());
48750 onBlur : function()
48754 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
48755 //this.el.removeClass(this.focusClass);
48758 this.hasFocus = false;
48760 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
48764 var v = this.getValue();
48766 if(String(v) !== String(this.startValue)){
48767 this.fireEvent('change', this, v, this.startValue);
48770 this.fireEvent("blur", this);
48773 inputEl : function()
48775 return this.el.select('.roo-money-amount-input', true).first();
48778 currencyEl : function()
48780 return this.el.select('.roo-money-currency-input', true).first();
48783 hiddenEl : function()
48785 return this.el.select('input.hidden-number-input',true).first();
48789 * @class Roo.bootstrap.BezierSignature
48790 * @extends Roo.bootstrap.Component
48791 * Bootstrap BezierSignature class
48792 * This script refer to:
48793 * Title: Signature Pad
48795 * Availability: https://github.com/szimek/signature_pad
48798 * Create a new BezierSignature
48799 * @param {Object} config The config object
48802 Roo.bootstrap.BezierSignature = function(config){
48803 Roo.bootstrap.BezierSignature.superclass.constructor.call(this, config);
48809 Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component,
48816 mouse_btn_down: true,
48819 * @cfg {int} canvas height
48821 canvas_height: '200px',
48824 * @cfg {float|function} Radius of a single dot.
48829 * @cfg {float} Minimum width of a line. Defaults to 0.5.
48834 * @cfg {float} Maximum width of a line. Defaults to 2.5.
48839 * @cfg {integer} Draw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling. Defaults to 16.
48844 * @cfg {integer} Add the next point only if the previous one is farther than x pixels. Defaults to 5.
48849 * @cfg {string} Color used to clear the background. Can be any color format accepted by context.fillStyle. Defaults to "rgba(0,0,0,0)" (transparent black). Use a non-transparent color e.g. "rgb(255,255,255)" (opaque white) if you'd like to save signatures as JPEG images.
48851 bg_color: 'rgba(0, 0, 0, 0)',
48854 * @cfg {string} Color used to draw the lines. Can be any color format accepted by context.fillStyle. Defaults to "black".
48856 dot_color: 'black',
48859 * @cfg {float} Weight used to modify new velocity based on the previous velocity. Defaults to 0.7.
48861 velocity_filter_weight: 0.7,
48864 * @cfg {function} Callback when stroke begin.
48869 * @cfg {function} Callback when stroke end.
48873 getAutoCreate : function()
48875 var cls = 'roo-signature column';
48878 cls += ' ' + this.cls;
48888 for(var i = 0; i < col_sizes.length; i++) {
48889 if(this[col_sizes[i]]) {
48890 cls += " col-"+col_sizes[i]+"-"+this[col_sizes[i]];
48900 cls: 'roo-signature-body',
48904 cls: 'roo-signature-body-canvas',
48905 height: this.canvas_height,
48906 width: this.canvas_width
48913 style: 'display: none'
48921 initEvents: function()
48923 Roo.bootstrap.BezierSignature.superclass.initEvents.call(this);
48925 var canvas = this.canvasEl();
48927 // mouse && touch event swapping...
48928 canvas.dom.style.touchAction = 'none';
48929 canvas.dom.style.msTouchAction = 'none';
48931 this.mouse_btn_down = false;
48932 canvas.on('mousedown', this._handleMouseDown, this);
48933 canvas.on('mousemove', this._handleMouseMove, this);
48934 Roo.select('html').first().on('mouseup', this._handleMouseUp, this);
48936 if (window.PointerEvent) {
48937 canvas.on('pointerdown', this._handleMouseDown, this);
48938 canvas.on('pointermove', this._handleMouseMove, this);
48939 Roo.select('html').first().on('pointerup', this._handleMouseUp, this);
48942 if ('ontouchstart' in window) {
48943 canvas.on('touchstart', this._handleTouchStart, this);
48944 canvas.on('touchmove', this._handleTouchMove, this);
48945 canvas.on('touchend', this._handleTouchEnd, this);
48948 Roo.EventManager.onWindowResize(this.resize, this, true);
48950 // file input event
48951 this.fileEl().on('change', this.uploadImage, this);
48958 resize: function(){
48960 var canvas = this.canvasEl().dom;
48961 var ctx = this.canvasElCtx();
48962 var img_data = false;
48964 if(canvas.width > 0) {
48965 var img_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
48967 // setting canvas width will clean img data
48970 var style = window.getComputedStyle ?
48971 getComputedStyle(this.el.dom, null) : this.el.dom.currentStyle;
48973 var padding_left = parseInt(style.paddingLeft) || 0;
48974 var padding_right = parseInt(style.paddingRight) || 0;
48976 canvas.width = this.el.dom.clientWidth - padding_left - padding_right;
48979 ctx.putImageData(img_data, 0, 0);
48983 _handleMouseDown: function(e)
48985 if (e.browserEvent.which === 1) {
48986 this.mouse_btn_down = true;
48987 this.strokeBegin(e);
48991 _handleMouseMove: function (e)
48993 if (this.mouse_btn_down) {
48994 this.strokeMoveUpdate(e);
48998 _handleMouseUp: function (e)
49000 if (e.browserEvent.which === 1 && this.mouse_btn_down) {
49001 this.mouse_btn_down = false;
49006 _handleTouchStart: function (e) {
49008 e.preventDefault();
49009 if (e.browserEvent.targetTouches.length === 1) {
49010 // var touch = e.browserEvent.changedTouches[0];
49011 // this.strokeBegin(touch);
49013 this.strokeBegin(e); // assume e catching the correct xy...
49017 _handleTouchMove: function (e) {
49018 e.preventDefault();
49019 // var touch = event.targetTouches[0];
49020 // _this._strokeMoveUpdate(touch);
49021 this.strokeMoveUpdate(e);
49024 _handleTouchEnd: function (e) {
49025 var wasCanvasTouched = e.target === this.canvasEl().dom;
49026 if (wasCanvasTouched) {
49027 e.preventDefault();
49028 // var touch = event.changedTouches[0];
49029 // _this._strokeEnd(touch);
49034 reset: function () {
49035 this._lastPoints = [];
49036 this._lastVelocity = 0;
49037 this._lastWidth = (this.min_width + this.max_width) / 2;
49038 this.canvasElCtx().fillStyle = this.dot_color;
49041 strokeMoveUpdate: function(e)
49043 this.strokeUpdate(e);
49045 if (this.throttle) {
49046 this.throttleStroke(this.strokeUpdate, this.throttle);
49049 this.strokeUpdate(e);
49053 strokeBegin: function(e)
49055 var newPointGroup = {
49056 color: this.dot_color,
49060 if (typeof this.onBegin === 'function') {
49064 this.curve_data.push(newPointGroup);
49066 this.strokeUpdate(e);
49069 strokeUpdate: function(e)
49071 var rect = this.canvasEl().dom.getBoundingClientRect();
49072 var point = new this.Point(e.xy[0] - rect.left, e.xy[1] - rect.top, new Date().getTime());
49073 var lastPointGroup = this.curve_data[this.curve_data.length - 1];
49074 var lastPoints = lastPointGroup.points;
49075 var lastPoint = lastPoints.length > 0 && lastPoints[lastPoints.length - 1];
49076 var isLastPointTooClose = lastPoint
49077 ? point.distanceTo(lastPoint) <= this.min_distance
49079 var color = lastPointGroup.color;
49080 if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
49081 var curve = this.addPoint(point);
49083 this.drawDot({color: color, point: point});
49086 this.drawCurve({color: color, curve: curve});
49096 strokeEnd: function(e)
49098 this.strokeUpdate(e);
49099 if (typeof this.onEnd === 'function') {
49104 addPoint: function (point) {
49105 var _lastPoints = this._lastPoints;
49106 _lastPoints.push(point);
49107 if (_lastPoints.length > 2) {
49108 if (_lastPoints.length === 3) {
49109 _lastPoints.unshift(_lastPoints[0]);
49111 var widths = this.calculateCurveWidths(_lastPoints[1], _lastPoints[2]);
49112 var curve = this.Bezier.fromPoints(_lastPoints, widths, this);
49113 _lastPoints.shift();
49119 calculateCurveWidths: function (startPoint, endPoint) {
49120 var velocity = this.velocity_filter_weight * endPoint.velocityFrom(startPoint) +
49121 (1 - this.velocity_filter_weight) * this._lastVelocity;
49123 var newWidth = Math.max(this.max_width / (velocity + 1), this.min_width);
49126 start: this._lastWidth
49129 this._lastVelocity = velocity;
49130 this._lastWidth = newWidth;
49134 drawDot: function (_a) {
49135 var color = _a.color, point = _a.point;
49136 var ctx = this.canvasElCtx();
49137 var width = typeof this.dot_size === 'function' ? this.dot_size() : this.dot_size;
49139 this.drawCurveSegment(point.x, point.y, width);
49141 ctx.fillStyle = color;
49145 drawCurve: function (_a) {
49146 var color = _a.color, curve = _a.curve;
49147 var ctx = this.canvasElCtx();
49148 var widthDelta = curve.endWidth - curve.startWidth;
49149 var drawSteps = Math.floor(curve.length()) * 2;
49151 ctx.fillStyle = color;
49152 for (var i = 0; i < drawSteps; i += 1) {
49153 var t = i / drawSteps;
49159 var x = uuu * curve.startPoint.x;
49160 x += 3 * uu * t * curve.control1.x;
49161 x += 3 * u * tt * curve.control2.x;
49162 x += ttt * curve.endPoint.x;
49163 var y = uuu * curve.startPoint.y;
49164 y += 3 * uu * t * curve.control1.y;
49165 y += 3 * u * tt * curve.control2.y;
49166 y += ttt * curve.endPoint.y;
49167 var width = curve.startWidth + ttt * widthDelta;
49168 this.drawCurveSegment(x, y, width);
49174 drawCurveSegment: function (x, y, width) {
49175 var ctx = this.canvasElCtx();
49177 ctx.arc(x, y, width, 0, 2 * Math.PI, false);
49178 this.is_empty = false;
49183 var ctx = this.canvasElCtx();
49184 var canvas = this.canvasEl().dom;
49185 ctx.fillStyle = this.bg_color;
49186 ctx.clearRect(0, 0, canvas.width, canvas.height);
49187 ctx.fillRect(0, 0, canvas.width, canvas.height);
49188 this.curve_data = [];
49190 this.is_empty = true;
49195 return this.el.select('input',true).first();
49198 canvasEl: function()
49200 return this.el.select('canvas',true).first();
49203 canvasElCtx: function()
49205 return this.el.select('canvas',true).first().dom.getContext('2d');
49208 getImage: function(type)
49210 if(this.is_empty) {
49215 return this.canvasEl().dom.toDataURL('image/'+type, 1);
49218 drawFromImage: function(img_src)
49220 var img = new Image();
49222 img.onload = function(){
49223 this.canvasElCtx().drawImage(img, 0, 0);
49228 this.is_empty = false;
49231 selectImage: function()
49233 this.fileEl().dom.click();
49236 uploadImage: function(e)
49238 var reader = new FileReader();
49240 reader.onload = function(e){
49241 var img = new Image();
49242 img.onload = function(){
49244 this.canvasElCtx().drawImage(img, 0, 0);
49246 img.src = e.target.result;
49249 reader.readAsDataURL(e.target.files[0]);
49252 // Bezier Point Constructor
49253 Point: (function () {
49254 function Point(x, y, time) {
49257 this.time = time || Date.now();
49259 Point.prototype.distanceTo = function (start) {
49260 return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
49262 Point.prototype.equals = function (other) {
49263 return this.x === other.x && this.y === other.y && this.time === other.time;
49265 Point.prototype.velocityFrom = function (start) {
49266 return this.time !== start.time
49267 ? this.distanceTo(start) / (this.time - start.time)
49274 // Bezier Constructor
49275 Bezier: (function () {
49276 function Bezier(startPoint, control2, control1, endPoint, startWidth, endWidth) {
49277 this.startPoint = startPoint;
49278 this.control2 = control2;
49279 this.control1 = control1;
49280 this.endPoint = endPoint;
49281 this.startWidth = startWidth;
49282 this.endWidth = endWidth;
49284 Bezier.fromPoints = function (points, widths, scope) {
49285 var c2 = this.calculateControlPoints(points[0], points[1], points[2], scope).c2;
49286 var c3 = this.calculateControlPoints(points[1], points[2], points[3], scope).c1;
49287 return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
49289 Bezier.calculateControlPoints = function (s1, s2, s3, scope) {
49290 var dx1 = s1.x - s2.x;
49291 var dy1 = s1.y - s2.y;
49292 var dx2 = s2.x - s3.x;
49293 var dy2 = s2.y - s3.y;
49294 var m1 = { x: (s1.x + s2.x) / 2.0, y: (s1.y + s2.y) / 2.0 };
49295 var m2 = { x: (s2.x + s3.x) / 2.0, y: (s2.y + s3.y) / 2.0 };
49296 var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
49297 var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
49298 var dxm = m1.x - m2.x;
49299 var dym = m1.y - m2.y;
49300 var k = l2 / (l1 + l2);
49301 var cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
49302 var tx = s2.x - cm.x;
49303 var ty = s2.y - cm.y;
49305 c1: new scope.Point(m1.x + tx, m1.y + ty),
49306 c2: new scope.Point(m2.x + tx, m2.y + ty)
49309 Bezier.prototype.length = function () {
49314 for (var i = 0; i <= steps; i += 1) {
49316 var cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
49317 var cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
49319 var xdiff = cx - px;
49320 var ydiff = cy - py;
49321 length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
49328 Bezier.prototype.point = function (t, start, c1, c2, end) {
49329 return (start * (1.0 - t) * (1.0 - t) * (1.0 - t))
49330 + (3.0 * c1 * (1.0 - t) * (1.0 - t) * t)
49331 + (3.0 * c2 * (1.0 - t) * t * t)
49332 + (end * t * t * t);
49337 throttleStroke: function(fn, wait) {
49338 if (wait === void 0) { wait = 250; }
49340 var timeout = null;
49344 var later = function () {
49345 previous = Date.now();
49347 result = fn.apply(storedContext, storedArgs);
49349 storedContext = null;
49353 return function wrapper() {
49355 for (var _i = 0; _i < arguments.length; _i++) {
49356 args[_i] = arguments[_i];
49358 var now = Date.now();
49359 var remaining = wait - (now - previous);
49360 storedContext = this;
49362 if (remaining <= 0 || remaining > wait) {
49364 clearTimeout(timeout);
49368 result = fn.apply(storedContext, storedArgs);
49370 storedContext = null;
49374 else if (!timeout) {
49375 timeout = window.setTimeout(later, remaining);
49385 // old names for form elements
49386 Roo.bootstrap.Form = Roo.bootstrap.form.Form;
49387 Roo.bootstrap.Input = Roo.bootstrap.form.Input;
49388 Roo.bootstrap.TextArea = Roo.bootstrap.form.TextArea;
49389 Roo.bootstrap.TriggerField = Roo.bootstrap.form.TriggerField;
49390 Roo.bootstrap.ComboBox = Roo.bootstrap.form.ComboBox;
49391 Roo.bootstrap.DateField = Roo.bootstrap.form.DateField;
49392 Roo.bootstrap.TimeField = Roo.bootstrap.form.TimeField;
49393 Roo.bootstrap.MonthField = Roo.bootstrap.form.MonthField;
49394 Roo.bootstrap.CheckBox = Roo.bootstrap.form.CheckBox;
49395 Roo.bootstrap.Radio = Roo.bootstrap.form.Radio;
49396 Roo.bootstrap.RadioSet = Roo.bootstrap.form.RadioSet;
49397 Roo.bootstrap.SecurePass = Roo.bootstrap.form.SecurePass;
49398 Roo.bootstrap.FieldLabel = Roo.bootstrap.form.FieldLabel;
49399 Roo.bootstrap.DateSplitField= Roo.bootstrap.form.DateSplitField;
49400 Roo.bootstrap.NumberField = Roo.bootstrap.form.NumberField;
49401 Roo.bootstrap.PhoneInput = Roo.bootstrap.form.PhoneInput;
49402 Roo.bootstrap.PhoneInputData= Roo.bootstrap.form.PhoneInputData;
49403 Roo.bootstrap.MoneyField = Roo.bootstrap.form.MoneyField;
49404 Roo.bootstrap.HtmlEditor = Roo.bootstrap.form.HtmlEditor;
49405 Roo.bootstrap.HtmlEditor.ToolbarStandard = Roo.bootstrap.form.HtmlEditorToolbarStandard;
49406 Roo.bootstrap.Markdown = Roo.bootstrap.form.Markdown;
49407 Roo.bootstrap.CardUploader = Roo.bootstrap.form.CardUploader;// depricated.
49408 Roo.bootstrap.Navbar = Roo.bootstrap.nav.Bar;
49409 Roo.bootstrap.NavGroup = Roo.bootstrap.nav.Group;
49410 Roo.bootstrap.NavHeaderbar = Roo.bootstrap.nav.Headerbar;
49411 Roo.bootstrap.NavItem = Roo.bootstrap.nav.Item;
49413 Roo.bootstrap.NavProgressBar = Roo.bootstrap.nav.ProgressBar;
49414 Roo.bootstrap.NavProgressBarItem = Roo.bootstrap.nav.ProgressBarItem;
49416 Roo.bootstrap.NavSidebar = Roo.bootstrap.nav.Sidebar;
49417 Roo.bootstrap.NavSidebarItem = Roo.bootstrap.nav.SidebarItem;
49419 Roo.bootstrap.NavSimplebar = Roo.bootstrap.nav.Simplebar;// deprciated
49420 Roo.bootstrap.Menu = Roo.bootstrap.menu.Menu;
49421 Roo.bootstrap.MenuItem = Roo.bootstrap.menu.Item;
49422 Roo.bootstrap.MenuSeparator = Roo.bootstrap.menu.Separator