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){
9422 cfg.cn.push(this.renderFooter());
9425 if(!this.footerShow && this.summaryFooterShow) {
9426 cfg.cn.push(this.renderSummaryFooter());
9429 // where does this come from?
9430 //cfg.cls+= ' TableGrid';
9433 return { cn : [ cfg ] };
9436 initEvents : function()
9438 if(!this.store || !this.cm){
9441 if (this.selModel) {
9442 this.selModel.initEvents();
9446 //Roo.log('initEvents with ds!!!!');
9448 this.bodyEl = this.el.select('tbody', true).first();
9449 this.headEl = this.el.select('thead', true).first();
9450 this.mainFoot = this.el.select('tfoot', true).first();
9455 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
9456 e.on('click', this.sort, this);
9460 // why is this done????? = it breaks dialogs??
9461 //this.parent().el.setStyle('position', 'relative');
9465 this.footer.parentId = this.id;
9466 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
9469 this.el.select('tfoot tr td').first().addClass('hide');
9474 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
9477 this.store.on('load', this.onLoad, this);
9478 this.store.on('beforeload', this.onBeforeLoad, this);
9479 this.store.on('update', this.onUpdate, this);
9480 this.store.on('add', this.onAdd, this);
9481 this.store.on("clear", this.clear, this);
9483 this.el.on("contextmenu", this.onContextMenu, this);
9486 this.cm.on("headerchange", this.onHeaderChange, this);
9487 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
9489 //?? does bodyEl get replaced on render?
9490 this.bodyEl.on("click", this.onClick, this);
9491 this.bodyEl.on("dblclick", this.onDblClick, this);
9492 this.bodyEl.on('scroll', this.onBodyScroll, this);
9494 // guessing mainbody will work - this relays usually caught by selmodel at present.
9495 this.relayEvents(this.bodyEl, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
9498 this.resizeProxy = Roo.get(document.body).createChild({ cls:"x-grid-resize-proxy", html: ' ' });
9501 if(this.headEl && this.enableColumnResize !== false && Roo.grid.SplitDragZone){
9502 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
9507 // Compatibility with grid - we implement all the view features at present.
9508 getView : function()
9513 initCSS : function()
9515 if(this.disableAutoSize) {
9519 var cm = this.cm, styles = [];
9520 this.CSS.removeStyleSheet(this.id + '-cssrules');
9521 var headHeight = this.headEl ? this.headEl.dom.clientHeight : 0;
9522 // we can honour xs/sm/md/xl as widths...
9523 // we first have to decide what widht we are currently at...
9524 var sz = Roo.getGridSize();
9528 var cols = []; // visable cols.
9530 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
9531 var w = cm.getColumnWidth(i, false);
9533 cols.push( { rel : false, abs : 0 });
9537 cols.push( { rel : false, abs : w });
9539 last = i; // not really..
9542 var w = cm.getColumnWidth(i, sz);
9547 cols.push( { rel : w, abs : false });
9550 var avail = this.bodyEl.dom.clientWidth - total_abs;
9552 var unitWidth = Math.floor(avail / total);
9553 var rem = avail - (unitWidth * total);
9555 var hidden, width, pos = 0 , splithide , left;
9556 for(var i = 0, len = cm.getColumnCount(); i < len; i++) {
9558 hidden = 'display:none;';
9560 width = 'width:0px;';
9562 if(!cm.isHidden(i)){
9566 // we can honour xs/sm/md/xl ?
9567 var w = cols[i].rel == false ? cols[i].abs : (cols[i].rel * unitWidth);
9569 hidden = 'display:none;';
9571 // width should return a small number...
9573 w+=rem; // add the remaining with..
9576 left = "left:" + (pos -4) + "px;";
9577 width = "width:" + w+ "px;";
9580 if (this.responsive) {
9583 hidden = cm.isHidden(i) ? 'display:none;' : '';
9584 splithide = 'display: none;';
9587 styles.push( '#' , this.id , ' .x-col-' , i, " {", cm.config[i].css, width, hidden, "}\n" );
9590 splithide = 'display:none;';
9593 styles.push('#' , this.id , ' .x-hcol-' , i, " { ", width, hidden," }\n",
9594 '#' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', (headHeight - 4), "px;}\n",
9595 // this is the popover version..
9596 '.popover-inner #' , this.id , ' .x-grid-split-' , i, " { ", left, splithide, 'height:', 100, "%;}\n"
9601 //Roo.log(styles.join(''));
9602 this.CSS.createStyleSheet( styles.join(''), this.id + '-cssrules');
9608 onContextMenu : function(e, t)
9610 this.processEvent("contextmenu", e);
9613 processEvent : function(name, e)
9615 if (name != 'touchstart' ) {
9616 this.fireEvent(name, e);
9619 var t = e.getTarget();
9621 var cell = Roo.get(t);
9627 if(cell.findParent('tfoot', false, true)){
9631 if(cell.findParent('thead', false, true)){
9633 if(e.getTarget().nodeName.toLowerCase() != 'th'){
9634 cell = Roo.get(t).findParent('th', false, true);
9636 Roo.log("failed to find th in thead?");
9637 Roo.log(e.getTarget());
9642 var cellIndex = cell.dom.cellIndex;
9644 var ename = name == 'touchstart' ? 'click' : name;
9645 this.fireEvent("header" + ename, this, cellIndex, e);
9650 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9651 cell = Roo.get(t).findParent('td', false, true);
9653 Roo.log("failed to find th in tbody?");
9654 Roo.log(e.getTarget());
9659 var row = cell.findParent('tr', false, true);
9660 var cellIndex = cell.dom.cellIndex;
9661 var rowIndex = row.dom.rowIndex - 1;
9665 this.fireEvent("row" + name, this, rowIndex, e);
9669 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
9675 onMouseover : function(e, el)
9677 var cell = Roo.get(el);
9683 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9684 cell = cell.findParent('td', false, true);
9687 var row = cell.findParent('tr', false, true);
9688 var cellIndex = cell.dom.cellIndex;
9689 var rowIndex = row.dom.rowIndex - 1; // start from 0
9691 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
9695 onMouseout : function(e, el)
9697 var cell = Roo.get(el);
9703 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9704 cell = cell.findParent('td', false, true);
9707 var row = cell.findParent('tr', false, true);
9708 var cellIndex = cell.dom.cellIndex;
9709 var rowIndex = row.dom.rowIndex - 1; // start from 0
9711 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
9715 onClick : function(e, el)
9717 var cell = Roo.get(el);
9719 if(!cell || (!this.cellSelection && !this.rowSelection)){
9723 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9724 cell = cell.findParent('td', false, true);
9727 if(!cell || typeof(cell) == 'undefined'){
9731 var row = cell.findParent('tr', false, true);
9733 if(!row || typeof(row) == 'undefined'){
9737 var cellIndex = cell.dom.cellIndex;
9738 var rowIndex = this.getRowIndex(row);
9740 // why??? - should these not be based on SelectionModel?
9741 //if(this.cellSelection){
9742 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
9745 //if(this.rowSelection){
9746 this.fireEvent('rowclick', this, row, rowIndex, e);
9751 onDblClick : function(e,el)
9753 var cell = Roo.get(el);
9755 if(!cell || (!this.cellSelection && !this.rowSelection)){
9759 if(e.getTarget().nodeName.toLowerCase() != 'td'){
9760 cell = cell.findParent('td', false, true);
9763 if(!cell || typeof(cell) == 'undefined'){
9767 var row = cell.findParent('tr', false, true);
9769 if(!row || typeof(row) == 'undefined'){
9773 var cellIndex = cell.dom.cellIndex;
9774 var rowIndex = this.getRowIndex(row);
9776 if(this.cellSelection){
9777 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
9780 if(this.rowSelection){
9781 this.fireEvent('rowdblclick', this, row, rowIndex, e);
9784 findRowIndex : function(el)
9786 var cell = Roo.get(el);
9790 var row = cell.findParent('tr', false, true);
9792 if(!row || typeof(row) == 'undefined'){
9795 return this.getRowIndex(row);
9797 sort : function(e,el)
9799 var col = Roo.get(el);
9801 if(!col.hasClass('sortable')){
9805 var sort = col.attr('sort');
9808 if(col.select('i', true).first().hasClass('fa-arrow-up')){
9812 this.store.sortInfo = {field : sort, direction : dir};
9815 Roo.log("calling footer first");
9816 this.footer.onClick('first');
9819 this.store.load({ params : { start : 0 } });
9823 renderHeader : function()
9831 this.totalWidth = 0;
9833 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
9835 var config = cm.config[i];
9839 cls : 'x-hcol-' + i,
9842 html: cm.getColumnHeader(i)
9845 var tooltip = cm.getColumnTooltip(i);
9847 c.tooltip = tooltip;
9853 if(typeof(config.sortable) != 'undefined' && config.sortable){
9854 c.cls += ' sortable';
9855 c.html = '<i class="fa"></i>' + c.html;
9858 // could use BS4 hidden-..-down
9860 if(typeof(config.lgHeader) != 'undefined'){
9861 hh += '<span class="hidden-xs hidden-sm hidden-md ">' + config.lgHeader + '</span>';
9864 if(typeof(config.mdHeader) != 'undefined'){
9865 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
9868 if(typeof(config.smHeader) != 'undefined'){
9869 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
9872 if(typeof(config.xsHeader) != 'undefined'){
9873 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
9880 if(typeof(config.tooltip) != 'undefined'){
9881 c.tooltip = config.tooltip;
9884 if(typeof(config.colspan) != 'undefined'){
9885 c.colspan = config.colspan;
9888 // hidden is handled by CSS now
9890 if(typeof(config.dataIndex) != 'undefined'){
9891 c.sort = config.dataIndex;
9896 if(typeof(config.align) != 'undefined' && config.align.length){
9897 c.style += ' text-align:' + config.align + ';';
9900 /* width is done in CSS
9901 *if(typeof(config.width) != 'undefined'){
9902 c.style += ' width:' + config.width + 'px;';
9903 this.totalWidth += config.width;
9905 this.totalWidth += 100; // assume minimum of 100 per column?
9909 if(typeof(config.cls) != 'undefined'){
9910 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
9912 // this is the bit that doesnt reall work at all...
9914 if (this.responsive) {
9917 ['xs','sm','md','lg'].map(function(size){
9919 if(typeof(config[size]) == 'undefined'){
9923 if (!config[size]) { // 0 = hidden
9924 // BS 4 '0' is treated as hide that column and below.
9925 c.cls += ' hidden-' + size + ' hidden' + size + '-down';
9929 c.cls += ' col-' + size + '-' + config[size] + (
9930 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
9938 c.html +=' <span class="x-grid-split x-grid-split-' + i + '"></span>';
9949 renderBody : function()
9959 colspan : this.cm.getColumnCount()
9969 renderFooter : function()
9979 colspan : this.cm.getColumnCount()
9989 renderSummaryFooter : function()
9998 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
10002 cls : 'x-fcol-' + i,
10015 onLoad : function()
10017 // Roo.log('ds onload');
10022 var ds = this.store;
10024 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
10025 e.select('i', true).removeClass(['fa-arrow-up', 'fa-arrow-down']);
10026 if (_this.store.sortInfo) {
10028 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
10029 e.select('i', true).addClass(['fa-arrow-up']);
10032 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
10033 e.select('i', true).addClass(['fa-arrow-down']);
10038 var tbody = this.bodyEl;
10040 if(ds.getCount() > 0){
10041 ds.data.each(function(d,rowIndex){
10042 var row = this.renderRow(cm, ds, rowIndex);
10044 tbody.createChild(row);
10048 if(row.cellObjects.length){
10049 Roo.each(row.cellObjects, function(r){
10050 _this.renderCellObject(r);
10055 } else if (this.empty_results.length) {
10056 this.el.mask(this.empty_results, 'no-spinner');
10059 var tfoot = this.el.select('tfoot', true).first();
10061 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
10063 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
10065 var total = this.ds.getTotalCount();
10067 if(this.footer.pageSize < total){
10068 this.mainFoot.show();
10072 if(!this.footerShow && this.summaryFooterShow) {
10074 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
10076 var value = cm.config[i].summaryFooter;
10078 Roo.log('value [' + i + '] : ' + value);
10082 Roo.each(this.el.select('tbody td', true).elements, function(e){
10083 e.on('mouseover', _this.onMouseover, _this);
10086 Roo.each(this.el.select('tbody td', true).elements, function(e){
10087 e.on('mouseout', _this.onMouseout, _this);
10089 this.fireEvent('rowsrendered', this);
10093 this.initCSS(); /// resize cols
10099 onUpdate : function(ds,record)
10101 this.refreshRow(record);
10105 onRemove : function(ds, record, index, isUpdate){
10106 if(isUpdate !== true){
10107 this.fireEvent("beforerowremoved", this, index, record);
10109 var bt = this.bodyEl.dom;
10111 var rows = this.el.select('tbody > tr', true).elements;
10113 if(typeof(rows[index]) != 'undefined'){
10114 bt.removeChild(rows[index].dom);
10117 // if(bt.rows[index]){
10118 // bt.removeChild(bt.rows[index]);
10121 if(isUpdate !== true){
10122 //this.stripeRows(index);
10123 //this.syncRowHeights(index, index);
10125 this.fireEvent("rowremoved", this, index, record);
10129 onAdd : function(ds, records, rowIndex)
10131 //Roo.log('on Add called');
10132 // - note this does not handle multiple adding very well..
10133 var bt = this.bodyEl.dom;
10134 for (var i =0 ; i < records.length;i++) {
10135 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
10136 //Roo.log(records[i]);
10137 //Roo.log(this.store.getAt(rowIndex+i));
10138 this.insertRow(this.store, rowIndex + i, false);
10145 refreshRow : function(record){
10146 var ds = this.store, index;
10147 if(typeof record == 'number'){
10149 record = ds.getAt(index);
10151 index = ds.indexOf(record);
10153 return; // should not happen - but seems to
10156 this.insertRow(ds, index, true);
10158 this.onRemove(ds, record, index+1, true);
10160 //this.syncRowHeights(index, index);
10162 this.fireEvent("rowupdated", this, index, record);
10164 // private - called by RowSelection
10165 onRowSelect : function(rowIndex){
10166 var row = this.getRowDom(rowIndex);
10167 row.addClass(['bg-info','info']);
10169 // private - called by RowSelection
10170 onRowDeselect : function(rowIndex)
10172 if (rowIndex < 0) {
10175 var row = this.getRowDom(rowIndex);
10176 row.removeClass(['bg-info','info']);
10179 * Focuses the specified row.
10180 * @param {Number} row The row index
10182 focusRow : function(row)
10184 //Roo.log('GridView.focusRow');
10185 var x = this.bodyEl.dom.scrollLeft;
10186 this.focusCell(row, 0, false);
10187 this.bodyEl.dom.scrollLeft = x;
10191 * Focuses the specified cell.
10192 * @param {Number} row The row index
10193 * @param {Number} col The column index
10194 * @param {Boolean} hscroll false to disable horizontal scrolling
10196 focusCell : function(row, col, hscroll)
10198 //Roo.log('GridView.focusCell');
10199 var el = this.ensureVisible(row, col, hscroll);
10200 // not sure what focusEL achives = it's a <a> pos relative
10201 //this.focusEl.alignTo(el, "tl-tl");
10203 // this.focusEl.focus();
10205 // this.focusEl.focus.defer(1, this.focusEl);
10210 * Scrolls the specified cell into view
10211 * @param {Number} row The row index
10212 * @param {Number} col The column index
10213 * @param {Boolean} hscroll false to disable horizontal scrolling
10215 ensureVisible : function(row, col, hscroll)
10217 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
10218 //return null; //disable for testing.
10219 if(typeof row != "number"){
10220 row = row.rowIndex;
10222 if(row < 0 && row >= this.ds.getCount()){
10225 col = (col !== undefined ? col : 0);
10227 while(cm.isHidden(col)){
10231 var el = this.getCellDom(row, col);
10235 var c = this.bodyEl.dom;
10237 var ctop = parseInt(el.offsetTop, 10);
10238 var cleft = parseInt(el.offsetLeft, 10);
10239 var cbot = ctop + el.offsetHeight;
10240 var cright = cleft + el.offsetWidth;
10242 //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
10243 var ch = 0; //?? header is not withing the area?
10244 var stop = parseInt(c.scrollTop, 10);
10245 var sleft = parseInt(c.scrollLeft, 10);
10246 var sbot = stop + ch;
10247 var sright = sleft + c.clientWidth;
10249 Roo.log('GridView.ensureVisible:' +
10251 ' c.clientHeight:' + c.clientHeight +
10252 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
10260 c.scrollTop = ctop;
10261 //Roo.log("set scrolltop to ctop DISABLE?");
10262 }else if(cbot > sbot){
10263 //Roo.log("set scrolltop to cbot-ch");
10264 c.scrollTop = cbot-ch;
10267 if(hscroll !== false){
10269 c.scrollLeft = cleft;
10270 }else if(cright > sright){
10271 c.scrollLeft = cright-c.clientWidth;
10279 insertRow : function(dm, rowIndex, isUpdate){
10282 this.fireEvent("beforerowsinserted", this, rowIndex);
10284 //var s = this.getScrollState();
10285 var row = this.renderRow(this.cm, this.store, rowIndex);
10286 // insert before rowIndex..
10287 var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
10291 if(row.cellObjects.length){
10292 Roo.each(row.cellObjects, function(r){
10293 _this.renderCellObject(r);
10298 this.fireEvent("rowsinserted", this, rowIndex);
10299 //this.syncRowHeights(firstRow, lastRow);
10300 //this.stripeRows(firstRow);
10307 getRowDom : function(rowIndex)
10309 var rows = this.el.select('tbody > tr', true).elements;
10311 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
10314 getCellDom : function(rowIndex, colIndex)
10316 var row = this.getRowDom(rowIndex);
10317 if (row === false) {
10320 var cols = row.select('td', true).elements;
10321 return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
10325 // returns the object tree for a tr..
10328 renderRow : function(cm, ds, rowIndex)
10330 var d = ds.getAt(rowIndex);
10334 cls : 'x-row-' + rowIndex,
10338 var cellObjects = [];
10340 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
10341 var config = cm.config[i];
10343 var renderer = cm.getRenderer(i);
10347 if(typeof(renderer) !== 'undefined'){
10348 value = renderer(d.data[cm.getDataIndex(i)], false, d);
10350 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
10351 // and are rendered into the cells after the row is rendered - using the id for the element.
10353 if(typeof(value) === 'object'){
10363 rowIndex : rowIndex,
10368 this.fireEvent('rowclass', this, rowcfg);
10372 // this might end up displaying HTML?
10373 // this is too messy... - better to only do it on columsn you know are going to be too long
10374 //tooltip : (typeof(value) === 'object') ? '' : value,
10375 cls : rowcfg.rowClass + ' x-col-' + i,
10377 html: (typeof(value) === 'object') ? '' : value
10384 if(typeof(config.colspan) != 'undefined'){
10385 td.colspan = config.colspan;
10390 if(typeof(config.align) != 'undefined' && config.align.length){
10391 td.style += ' text-align:' + config.align + ';';
10393 if(typeof(config.valign) != 'undefined' && config.valign.length){
10394 td.style += ' vertical-align:' + config.valign + ';';
10397 if(typeof(config.width) != 'undefined'){
10398 td.style += ' width:' + config.width + 'px;';
10402 if(typeof(config.cursor) != 'undefined'){
10403 td.style += ' cursor:' + config.cursor + ';';
10406 if(typeof(config.cls) != 'undefined'){
10407 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
10409 if (this.responsive) {
10410 ['xs','sm','md','lg'].map(function(size){
10412 if(typeof(config[size]) == 'undefined'){
10418 if (!config[size]) { // 0 = hidden
10419 // BS 4 '0' is treated as hide that column and below.
10420 td.cls += ' hidden-' + size + ' hidden' + size + '-down';
10424 td.cls += ' col-' + size + '-' + config[size] + (
10425 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
10435 row.cellObjects = cellObjects;
10443 onBeforeLoad : function()
10445 this.el.unmask(); // if needed.
10452 this.el.select('tbody', true).first().dom.innerHTML = '';
10455 * Show or hide a row.
10456 * @param {Number} rowIndex to show or hide
10457 * @param {Boolean} state hide
10459 setRowVisibility : function(rowIndex, state)
10461 var bt = this.bodyEl.dom;
10463 var rows = this.el.select('tbody > tr', true).elements;
10465 if(typeof(rows[rowIndex]) == 'undefined'){
10468 rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
10473 getSelectionModel : function(){
10474 if(!this.selModel){
10475 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
10477 return this.selModel;
10480 * Render the Roo.bootstrap object from renderder
10482 renderCellObject : function(r)
10486 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
10488 var t = r.cfg.render(r.container);
10491 Roo.each(r.cfg.cn, function(c){
10493 container: t.getChildContainer(),
10496 _this.renderCellObject(child);
10501 * get the Row Index from a dom element.
10502 * @param {Roo.Element} row The row to look for
10503 * @returns {Number} the row
10505 getRowIndex : function(row)
10509 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
10520 * get the header TH element for columnIndex
10521 * @param {Number} columnIndex
10522 * @returns {Roo.Element}
10524 getHeaderIndex: function(colIndex)
10526 var cols = this.headEl.select('th', true).elements;
10527 return cols[colIndex];
10530 * get the Column Index from a dom element. (using regex on x-hcol-{colid})
10531 * @param {domElement} cell to look for
10532 * @returns {Number} the column
10534 getCellIndex : function(cell)
10536 var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
10538 return parseInt(id[1], 10);
10543 * Returns the grid's underlying element = used by panel.Grid
10544 * @return {Element} The element
10546 getGridEl : function(){
10550 * Forces a resize - used by panel.Grid
10551 * @return {Element} The element
10553 autoSize : function()
10555 if(this.disableAutoSize) {
10558 //var ctr = Roo.get(this.container.dom.parentElement);
10559 var ctr = Roo.get(this.el.dom);
10561 var thd = this.getGridEl().select('thead',true).first();
10562 var tbd = this.getGridEl().select('tbody', true).first();
10563 var tfd = this.getGridEl().select('tfoot', true).first();
10565 var cw = ctr.getWidth();
10566 this.getGridEl().select('tfoot tr, tfoot td',true).setWidth(cw);
10570 tbd.setWidth(ctr.getWidth());
10571 // if the body has a max height - and then scrolls - we should perhaps set up the height here
10572 // this needs fixing for various usage - currently only hydra job advers I think..
10574 // ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
10576 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
10579 cw = Math.max(cw, this.totalWidth);
10580 this.getGridEl().select('tbody tr',true).setWidth(cw);
10583 // resize 'expandable coloumn?
10585 return; // we doe not have a view in this design..
10588 onBodyScroll: function()
10590 //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
10592 this.headEl.setStyle({
10593 'position' : 'relative',
10594 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
10600 var scrollHeight = this.bodyEl.dom.scrollHeight;
10602 var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
10604 var height = this.bodyEl.getHeight();
10606 if(scrollHeight - height == scrollTop) {
10608 var total = this.ds.getTotalCount();
10610 if(this.footer.cursor + this.footer.pageSize < total){
10612 this.footer.ds.load({
10614 start : this.footer.cursor + this.footer.pageSize,
10615 limit : this.footer.pageSize
10624 onColumnSplitterMoved : function(i, diff)
10626 this.userResized = true;
10628 var cm = this.colModel;
10630 var w = this.getHeaderIndex(i).getWidth() + diff;
10633 cm.setColumnWidth(i, w, true);
10635 //var cid = cm.getColumnId(i); << not used in this version?
10636 /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
10638 this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
10639 this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
10640 this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
10642 //this.updateSplitters();
10643 //this.layout(); << ??
10644 this.fireEvent("columnresize", i, w);
10646 onHeaderChange : function()
10648 var header = this.renderHeader();
10649 var table = this.el.select('table', true).first();
10651 this.headEl.remove();
10652 this.headEl = table.createChild(header, this.bodyEl, false);
10654 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
10655 e.on('click', this.sort, this);
10658 if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
10659 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
10664 onHiddenChange : function(colModel, colIndex, hidden)
10667 this.cm.setHidden()
10668 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
10669 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
10671 this.CSS.updateRule(thSelector, "display", "");
10672 this.CSS.updateRule(tdSelector, "display", "");
10675 this.CSS.updateRule(thSelector, "display", "none");
10676 this.CSS.updateRule(tdSelector, "display", "none");
10679 // onload calls initCSS()
10680 this.onHeaderChange();
10684 setColumnWidth: function(col_index, width)
10686 // width = "md-2 xs-2..."
10687 if(!this.colModel.config[col_index]) {
10691 var w = width.split(" ");
10693 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
10695 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
10698 for(var j = 0; j < w.length; j++) {
10704 var size_cls = w[j].split("-");
10706 if(!Number.isInteger(size_cls[1] * 1)) {
10710 if(!this.colModel.config[col_index][size_cls[0]]) {
10714 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
10718 h_row[0].classList.replace(
10719 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
10720 "col-"+size_cls[0]+"-"+size_cls[1]
10723 for(var i = 0; i < rows.length; i++) {
10725 var size_cls = w[j].split("-");
10727 if(!Number.isInteger(size_cls[1] * 1)) {
10731 if(!this.colModel.config[col_index][size_cls[0]]) {
10735 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
10739 rows[i].classList.replace(
10740 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
10741 "col-"+size_cls[0]+"-"+size_cls[1]
10745 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
10750 // currently only used to find the split on drag..
10751 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
10756 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
10757 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;
10766 * @class Roo.bootstrap.TableCell
10767 * @extends Roo.bootstrap.Component
10768 * @children Roo.bootstrap.Component
10769 * @parent Roo.bootstrap.TableRow
10770 * Bootstrap TableCell class
10772 * @cfg {String} html cell contain text
10773 * @cfg {String} cls cell class
10774 * @cfg {String} tag cell tag (td|th) default td
10775 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
10776 * @cfg {String} align Aligns the content in a cell
10777 * @cfg {String} axis Categorizes cells
10778 * @cfg {String} bgcolor Specifies the background color of a cell
10779 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
10780 * @cfg {Number} colspan Specifies the number of columns a cell should span
10781 * @cfg {String} headers Specifies one or more header cells a cell is related to
10782 * @cfg {Number} height Sets the height of a cell
10783 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
10784 * @cfg {Number} rowspan Sets the number of rows a cell should span
10785 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
10786 * @cfg {String} valign Vertical aligns the content in a cell
10787 * @cfg {Number} width Specifies the width of a cell
10790 * Create a new TableCell
10791 * @param {Object} config The config object
10794 Roo.bootstrap.TableCell = function(config){
10795 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
10798 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
10818 getAutoCreate : function(){
10819 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
10826 cfg.tag = this.tag;
10839 cfg.align=this.align
10844 if (this.bgcolor) {
10845 cfg.bgcolor=this.bgcolor
10847 if (this.charoff) {
10848 cfg.charoff=this.charoff
10850 if (this.colspan) {
10851 cfg.colspan=this.colspan
10853 if (this.headers) {
10854 cfg.headers=this.headers
10857 cfg.height=this.height
10860 cfg.nowrap=this.nowrap
10862 if (this.rowspan) {
10863 cfg.rowspan=this.rowspan
10866 cfg.scope=this.scope
10869 cfg.valign=this.valign
10872 cfg.width=this.width
10891 * @class Roo.bootstrap.TableRow
10892 * @extends Roo.bootstrap.Component
10893 * @children Roo.bootstrap.TableCell
10894 * @parent Roo.bootstrap.TableBody
10895 * Bootstrap TableRow class
10896 * @cfg {String} cls row class
10897 * @cfg {String} align Aligns the content in a table row
10898 * @cfg {String} bgcolor Specifies a background color for a table row
10899 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
10900 * @cfg {String} valign Vertical aligns the content in a table row
10903 * Create a new TableRow
10904 * @param {Object} config The config object
10907 Roo.bootstrap.TableRow = function(config){
10908 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
10911 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
10919 getAutoCreate : function(){
10920 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
10927 cfg.cls = this.cls;
10930 cfg.align = this.align;
10933 cfg.bgcolor = this.bgcolor;
10936 cfg.charoff = this.charoff;
10939 cfg.valign = this.valign;
10957 * @class Roo.bootstrap.TableBody
10958 * @extends Roo.bootstrap.Component
10959 * @children Roo.bootstrap.TableRow
10960 * @parent Roo.bootstrap.Table
10961 * Bootstrap TableBody class
10962 * @cfg {String} cls element class
10963 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
10964 * @cfg {String} align Aligns the content inside the element
10965 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
10966 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
10969 * Create a new TableBody
10970 * @param {Object} config The config object
10973 Roo.bootstrap.TableBody = function(config){
10974 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
10977 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
10985 getAutoCreate : function(){
10986 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
10996 cfg.tag = this.tag;
11000 cfg.align = this.align;
11003 cfg.charoff = this.charoff;
11006 cfg.valign = this.valign;
11013 // initEvents : function()
11016 // if(!this.store){
11020 // this.store = Roo.factory(this.store, Roo.data);
11021 // this.store.on('load', this.onLoad, this);
11023 // this.store.load();
11027 // onLoad: function ()
11029 // this.fireEvent('load', this);
11039 * Ext JS Library 1.1.1
11040 * Copyright(c) 2006-2007, Ext JS, LLC.
11042 * Originally Released Under LGPL - original licence link has changed is not relivant.
11045 * <script type="text/javascript">
11048 // as we use this in bootstrap.
11049 Roo.namespace('Roo.form');
11051 * @class Roo.form.Action
11052 * Internal Class used to handle form actions
11054 * @param {Roo.form.BasicForm} el The form element or its id
11055 * @param {Object} config Configuration options
11060 // define the action interface
11061 Roo.form.Action = function(form, options){
11063 this.options = options || {};
11066 * Client Validation Failed
11069 Roo.form.Action.CLIENT_INVALID = 'client';
11071 * Server Validation Failed
11074 Roo.form.Action.SERVER_INVALID = 'server';
11076 * Connect to Server Failed
11079 Roo.form.Action.CONNECT_FAILURE = 'connect';
11081 * Reading Data from Server Failed
11084 Roo.form.Action.LOAD_FAILURE = 'load';
11086 Roo.form.Action.prototype = {
11088 failureType : undefined,
11089 response : undefined,
11090 result : undefined,
11092 // interface method
11093 run : function(options){
11097 // interface method
11098 success : function(response){
11102 // interface method
11103 handleResponse : function(response){
11107 // default connection failure
11108 failure : function(response){
11110 this.response = response;
11111 this.failureType = Roo.form.Action.CONNECT_FAILURE;
11112 this.form.afterAction(this, false);
11115 processResponse : function(response){
11116 this.response = response;
11117 if(!response.responseText){
11120 this.result = this.handleResponse(response);
11121 return this.result;
11124 // utility functions used internally
11125 getUrl : function(appendParams){
11126 var url = this.options.url || this.form.url || this.form.el.dom.action;
11128 var p = this.getParams();
11130 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11136 getMethod : function(){
11137 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
11140 getParams : function(){
11141 var bp = this.form.baseParams;
11142 var p = this.options.params;
11144 if(typeof p == "object"){
11145 p = Roo.urlEncode(Roo.applyIf(p, bp));
11146 }else if(typeof p == 'string' && bp){
11147 p += '&' + Roo.urlEncode(bp);
11150 p = Roo.urlEncode(bp);
11155 createCallback : function(){
11157 success: this.success,
11158 failure: this.failure,
11160 timeout: (this.form.timeout*1000),
11161 upload: this.form.fileUpload ? this.success : undefined
11166 Roo.form.Action.Submit = function(form, options){
11167 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
11170 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
11173 haveProgress : false,
11174 uploadComplete : false,
11176 // uploadProgress indicator.
11177 uploadProgress : function()
11179 if (!this.form.progressUrl) {
11183 if (!this.haveProgress) {
11184 Roo.MessageBox.progress("Uploading", "Uploading");
11186 if (this.uploadComplete) {
11187 Roo.MessageBox.hide();
11191 this.haveProgress = true;
11193 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
11195 var c = new Roo.data.Connection();
11197 url : this.form.progressUrl,
11202 success : function(req){
11203 //console.log(data);
11207 rdata = Roo.decode(req.responseText)
11209 Roo.log("Invalid data from server..");
11213 if (!rdata || !rdata.success) {
11215 Roo.MessageBox.alert(Roo.encode(rdata));
11218 var data = rdata.data;
11220 if (this.uploadComplete) {
11221 Roo.MessageBox.hide();
11226 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
11227 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
11230 this.uploadProgress.defer(2000,this);
11233 failure: function(data) {
11234 Roo.log('progress url failed ');
11245 // run get Values on the form, so it syncs any secondary forms.
11246 this.form.getValues();
11248 var o = this.options;
11249 var method = this.getMethod();
11250 var isPost = method == 'POST';
11251 if(o.clientValidation === false || this.form.isValid()){
11253 if (this.form.progressUrl) {
11254 this.form.findField('UPLOAD_IDENTIFIER').setValue(
11255 (new Date() * 1) + '' + Math.random());
11260 Roo.Ajax.request(Roo.apply(this.createCallback(), {
11261 form:this.form.el.dom,
11262 url:this.getUrl(!isPost),
11264 params:isPost ? this.getParams() : null,
11265 isUpload: this.form.fileUpload,
11266 formData : this.form.formData
11269 this.uploadProgress();
11271 }else if (o.clientValidation !== false){ // client validation failed
11272 this.failureType = Roo.form.Action.CLIENT_INVALID;
11273 this.form.afterAction(this, false);
11277 success : function(response)
11279 this.uploadComplete= true;
11280 if (this.haveProgress) {
11281 Roo.MessageBox.hide();
11285 var result = this.processResponse(response);
11286 if(result === true || result.success){
11287 this.form.afterAction(this, true);
11291 this.form.markInvalid(result.errors);
11292 this.failureType = Roo.form.Action.SERVER_INVALID;
11294 this.form.afterAction(this, false);
11296 failure : function(response)
11298 this.uploadComplete= true;
11299 if (this.haveProgress) {
11300 Roo.MessageBox.hide();
11303 this.response = response;
11304 this.failureType = Roo.form.Action.CONNECT_FAILURE;
11305 this.form.afterAction(this, false);
11308 handleResponse : function(response){
11309 if(this.form.errorReader){
11310 var rs = this.form.errorReader.read(response);
11313 for(var i = 0, len = rs.records.length; i < len; i++) {
11314 var r = rs.records[i];
11315 errors[i] = r.data;
11318 if(errors.length < 1){
11322 success : rs.success,
11328 ret = Roo.decode(response.responseText);
11332 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
11342 Roo.form.Action.Load = function(form, options){
11343 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
11344 this.reader = this.form.reader;
11347 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
11352 Roo.Ajax.request(Roo.apply(
11353 this.createCallback(), {
11354 method:this.getMethod(),
11355 url:this.getUrl(false),
11356 params:this.getParams()
11360 success : function(response){
11362 var result = this.processResponse(response);
11363 if(result === true || !result.success || !result.data){
11364 this.failureType = Roo.form.Action.LOAD_FAILURE;
11365 this.form.afterAction(this, false);
11368 this.form.clearInvalid();
11369 this.form.setValues(result.data);
11370 this.form.afterAction(this, true);
11373 handleResponse : function(response){
11374 if(this.form.reader){
11375 var rs = this.form.reader.read(response);
11376 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
11378 success : rs.success,
11382 return Roo.decode(response.responseText);
11386 Roo.form.Action.ACTION_TYPES = {
11387 'load' : Roo.form.Action.Load,
11388 'submit' : Roo.form.Action.Submit
11397 * @class Roo.bootstrap.form.Form
11398 * @extends Roo.bootstrap.Component
11399 * @children Roo.bootstrap.Component
11400 * Bootstrap Form class
11401 * @cfg {String} method GET | POST (default POST)
11402 * @cfg {String} labelAlign top | left (default top)
11403 * @cfg {String} align left | right - for navbars
11404 * @cfg {Boolean} loadMask load mask when submit (default true)
11408 * Create a new Form
11409 * @param {Object} config The config object
11413 Roo.bootstrap.form.Form = function(config){
11415 Roo.bootstrap.form.Form.superclass.constructor.call(this, config);
11417 Roo.bootstrap.form.Form.popover.apply();
11421 * @event clientvalidation
11422 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
11423 * @param {Form} this
11424 * @param {Boolean} valid true if the form has passed client-side validation
11426 clientvalidation: true,
11428 * @event beforeaction
11429 * Fires before any action is performed. Return false to cancel the action.
11430 * @param {Form} this
11431 * @param {Action} action The action to be performed
11433 beforeaction: true,
11435 * @event actionfailed
11436 * Fires when an action fails.
11437 * @param {Form} this
11438 * @param {Action} action The action that failed
11440 actionfailed : true,
11442 * @event actioncomplete
11443 * Fires when an action is completed.
11444 * @param {Form} this
11445 * @param {Action} action The action that completed
11447 actioncomplete : true
11451 Roo.extend(Roo.bootstrap.form.Form, Roo.bootstrap.Component, {
11454 * @cfg {String} method
11455 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
11459 * @cfg {String} url
11460 * The URL to use for form actions if one isn't supplied in the action options.
11463 * @cfg {Boolean} fileUpload
11464 * Set to true if this form is a file upload.
11468 * @cfg {Object} baseParams
11469 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
11473 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
11477 * @cfg {Sting} align (left|right) for navbar forms
11482 activeAction : null,
11485 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
11486 * element by passing it or its id or mask the form itself by passing in true.
11489 waitMsgTarget : false,
11494 * @cfg {Boolean} errorMask (true|false) default false
11499 * @cfg {Number} maskOffset Default 100
11504 * @cfg {Boolean} maskBody
11508 getAutoCreate : function(){
11512 method : this.method || 'POST',
11513 id : this.id || Roo.id(),
11516 if (this.parent().xtype.match(/^Nav/)) {
11517 cfg.cls = 'navbar-form form-inline navbar-' + this.align;
11521 if (this.labelAlign == 'left' ) {
11522 cfg.cls += ' form-horizontal';
11528 initEvents : function()
11530 this.el.on('submit', this.onSubmit, this);
11531 // this was added as random key presses on the form where triggering form submit.
11532 this.el.on('keypress', function(e) {
11533 if (e.getCharCode() != 13) {
11536 // we might need to allow it for textareas.. and some other items.
11537 // check e.getTarget().
11539 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
11543 Roo.log("keypress blocked");
11545 e.preventDefault();
11551 onSubmit : function(e){
11556 * Returns true if client-side validation on the form is successful.
11559 isValid : function(){
11560 var items = this.getItems();
11562 var target = false;
11564 items.each(function(f){
11570 Roo.log('invalid field: ' + f.name);
11574 if(!target && f.el.isVisible(true)){
11580 if(this.errorMask && !valid){
11581 Roo.bootstrap.form.Form.popover.mask(this, target);
11588 * Returns true if any fields in this form have changed since their original load.
11591 isDirty : function(){
11593 var items = this.getItems();
11594 items.each(function(f){
11604 * Performs a predefined action (submit or load) or custom actions you define on this form.
11605 * @param {String} actionName The name of the action type
11606 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
11607 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
11608 * accept other config options):
11610 Property Type Description
11611 ---------------- --------------- ----------------------------------------------------------------------------------
11612 url String The url for the action (defaults to the form's url)
11613 method String The form method to use (defaults to the form's method, or POST if not defined)
11614 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
11615 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
11616 validate the form on the client (defaults to false)
11618 * @return {BasicForm} this
11620 doAction : function(action, options){
11621 if(typeof action == 'string'){
11622 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
11624 if(this.fireEvent('beforeaction', this, action) !== false){
11625 this.beforeAction(action);
11626 action.run.defer(100, action);
11632 beforeAction : function(action){
11633 var o = action.options;
11638 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
11640 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
11643 // not really supported yet.. ??
11645 //if(this.waitMsgTarget === true){
11646 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
11647 //}else if(this.waitMsgTarget){
11648 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
11649 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
11651 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
11657 afterAction : function(action, success){
11658 this.activeAction = null;
11659 var o = action.options;
11664 Roo.get(document.body).unmask();
11670 //if(this.waitMsgTarget === true){
11671 // this.el.unmask();
11672 //}else if(this.waitMsgTarget){
11673 // this.waitMsgTarget.unmask();
11675 // Roo.MessageBox.updateProgress(1);
11676 // Roo.MessageBox.hide();
11683 Roo.callback(o.success, o.scope, [this, action]);
11684 this.fireEvent('actioncomplete', this, action);
11688 // failure condition..
11689 // we have a scenario where updates need confirming.
11690 // eg. if a locking scenario exists..
11691 // we look for { errors : { needs_confirm : true }} in the response.
11693 (typeof(action.result) != 'undefined') &&
11694 (typeof(action.result.errors) != 'undefined') &&
11695 (typeof(action.result.errors.needs_confirm) != 'undefined')
11698 Roo.log("not supported yet");
11701 Roo.MessageBox.confirm(
11702 "Change requires confirmation",
11703 action.result.errorMsg,
11708 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
11718 Roo.callback(o.failure, o.scope, [this, action]);
11719 // show an error message if no failed handler is set..
11720 if (!this.hasListener('actionfailed')) {
11721 Roo.log("need to add dialog support");
11723 Roo.MessageBox.alert("Error",
11724 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
11725 action.result.errorMsg :
11726 "Saving Failed, please check your entries or try again"
11731 this.fireEvent('actionfailed', this, action);
11736 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
11737 * @param {String} id The value to search for
11740 findField : function(id){
11741 var items = this.getItems();
11742 var field = items.get(id);
11744 items.each(function(f){
11745 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
11752 return field || null;
11755 * Mark fields in this form invalid in bulk.
11756 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
11757 * @return {BasicForm} this
11759 markInvalid : function(errors){
11760 if(errors instanceof Array){
11761 for(var i = 0, len = errors.length; i < len; i++){
11762 var fieldError = errors[i];
11763 var f = this.findField(fieldError.id);
11765 f.markInvalid(fieldError.msg);
11771 if(typeof errors[id] != 'function' && (field = this.findField(id))){
11772 field.markInvalid(errors[id]);
11776 //Roo.each(this.childForms || [], function (f) {
11777 // f.markInvalid(errors);
11784 * Set values for fields in this form in bulk.
11785 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
11786 * @return {BasicForm} this
11788 setValues : function(values){
11789 if(values instanceof Array){ // array of objects
11790 for(var i = 0, len = values.length; i < len; i++){
11792 var f = this.findField(v.id);
11794 f.setValue(v.value);
11795 if(this.trackResetOnLoad){
11796 f.originalValue = f.getValue();
11800 }else{ // object hash
11803 if(typeof values[id] != 'function' && (field = this.findField(id))){
11805 if (field.setFromData &&
11806 field.valueField &&
11807 field.displayField &&
11808 // combos' with local stores can
11809 // be queried via setValue()
11810 // to set their value..
11811 (field.store && !field.store.isLocal)
11815 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
11816 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
11817 field.setFromData(sd);
11819 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
11821 field.setFromData(values);
11824 field.setValue(values[id]);
11828 if(this.trackResetOnLoad){
11829 field.originalValue = field.getValue();
11835 //Roo.each(this.childForms || [], function (f) {
11836 // f.setValues(values);
11843 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
11844 * they are returned as an array.
11845 * @param {Boolean} asString
11848 getValues : function(asString){
11849 //if (this.childForms) {
11850 // copy values from the child forms
11851 // Roo.each(this.childForms, function (f) {
11852 // this.setValues(f.getValues());
11858 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
11859 if(asString === true){
11862 return Roo.urlDecode(fs);
11866 * Returns the fields in this form as an object with key/value pairs.
11867 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
11870 getFieldValues : function(with_hidden)
11872 var items = this.getItems();
11874 items.each(function(f){
11876 if (!f.getName()) {
11880 var v = f.getValue();
11882 if (f.inputType =='radio') {
11883 if (typeof(ret[f.getName()]) == 'undefined') {
11884 ret[f.getName()] = ''; // empty..
11887 if (!f.el.dom.checked) {
11891 v = f.el.dom.value;
11895 if(f.xtype == 'MoneyField'){
11896 ret[f.currencyName] = f.getCurrency();
11899 // not sure if this supported any more..
11900 if ((typeof(v) == 'object') && f.getRawValue) {
11901 v = f.getRawValue() ; // dates..
11903 // combo boxes where name != hiddenName...
11904 if (f.name !== false && f.name != '' && f.name != f.getName()) {
11905 ret[f.name] = f.getRawValue();
11907 ret[f.getName()] = v;
11914 * Clears all invalid messages in this form.
11915 * @return {BasicForm} this
11917 clearInvalid : function(){
11918 var items = this.getItems();
11920 items.each(function(f){
11928 * Resets this form.
11929 * @return {BasicForm} this
11931 reset : function(){
11932 var items = this.getItems();
11933 items.each(function(f){
11937 Roo.each(this.childForms || [], function (f) {
11945 getItems : function()
11947 var r=new Roo.util.MixedCollection(false, function(o){
11948 return o.id || (o.id = Roo.id());
11950 var iter = function(el) {
11957 Roo.each(el.items,function(e) {
11966 hideFields : function(items)
11968 Roo.each(items, function(i){
11970 var f = this.findField(i);
11981 showFields : function(items)
11983 Roo.each(items, function(i){
11985 var f = this.findField(i);
11998 Roo.apply(Roo.bootstrap.form.Form, {
12014 intervalID : false,
12020 if(this.isApplied){
12025 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
12026 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
12027 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
12028 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
12031 this.maskEl.top.enableDisplayMode("block");
12032 this.maskEl.left.enableDisplayMode("block");
12033 this.maskEl.bottom.enableDisplayMode("block");
12034 this.maskEl.right.enableDisplayMode("block");
12036 this.toolTip = new Roo.bootstrap.Tooltip({
12037 cls : 'roo-form-error-popover',
12039 'left' : ['r-l', [-2,0], 'right'],
12040 'right' : ['l-r', [2,0], 'left'],
12041 'bottom' : ['tl-bl', [0,2], 'top'],
12042 'top' : [ 'bl-tl', [0,-2], 'bottom']
12046 this.toolTip.render(Roo.get(document.body));
12048 this.toolTip.el.enableDisplayMode("block");
12050 Roo.get(document.body).on('click', function(){
12054 Roo.get(document.body).on('touchstart', function(){
12058 this.isApplied = true
12061 mask : function(form, target)
12065 this.target = target;
12067 if(!this.form.errorMask || !target.el){
12071 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
12073 Roo.log(scrollable);
12075 var ot = this.target.el.calcOffsetsTo(scrollable);
12077 var scrollTo = ot[1] - this.form.maskOffset;
12079 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
12081 scrollable.scrollTo('top', scrollTo);
12083 var box = this.target.el.getBox();
12085 var zIndex = Roo.bootstrap.Modal.zIndex++;
12088 this.maskEl.top.setStyle('position', 'absolute');
12089 this.maskEl.top.setStyle('z-index', zIndex);
12090 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
12091 this.maskEl.top.setLeft(0);
12092 this.maskEl.top.setTop(0);
12093 this.maskEl.top.show();
12095 this.maskEl.left.setStyle('position', 'absolute');
12096 this.maskEl.left.setStyle('z-index', zIndex);
12097 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
12098 this.maskEl.left.setLeft(0);
12099 this.maskEl.left.setTop(box.y - this.padding);
12100 this.maskEl.left.show();
12102 this.maskEl.bottom.setStyle('position', 'absolute');
12103 this.maskEl.bottom.setStyle('z-index', zIndex);
12104 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
12105 this.maskEl.bottom.setLeft(0);
12106 this.maskEl.bottom.setTop(box.bottom + this.padding);
12107 this.maskEl.bottom.show();
12109 this.maskEl.right.setStyle('position', 'absolute');
12110 this.maskEl.right.setStyle('z-index', zIndex);
12111 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
12112 this.maskEl.right.setLeft(box.right + this.padding);
12113 this.maskEl.right.setTop(box.y - this.padding);
12114 this.maskEl.right.show();
12116 this.toolTip.bindEl = this.target.el;
12118 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
12120 var tip = this.target.blankText;
12122 if(this.target.getValue() !== '' ) {
12124 if (this.target.invalidText.length) {
12125 tip = this.target.invalidText;
12126 } else if (this.target.regexText.length){
12127 tip = this.target.regexText;
12131 this.toolTip.show(tip);
12133 this.intervalID = window.setInterval(function() {
12134 Roo.bootstrap.form.Form.popover.unmask();
12137 window.onwheel = function(){ return false;};
12139 (function(){ this.isMasked = true; }).defer(500, this);
12143 unmask : function()
12145 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
12149 this.maskEl.top.setStyle('position', 'absolute');
12150 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
12151 this.maskEl.top.hide();
12153 this.maskEl.left.setStyle('position', 'absolute');
12154 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
12155 this.maskEl.left.hide();
12157 this.maskEl.bottom.setStyle('position', 'absolute');
12158 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
12159 this.maskEl.bottom.hide();
12161 this.maskEl.right.setStyle('position', 'absolute');
12162 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
12163 this.maskEl.right.hide();
12165 this.toolTip.hide();
12167 this.toolTip.el.hide();
12169 window.onwheel = function(){ return true;};
12171 if(this.intervalID){
12172 window.clearInterval(this.intervalID);
12173 this.intervalID = false;
12176 this.isMasked = false;
12186 * Ext JS Library 1.1.1
12187 * Copyright(c) 2006-2007, Ext JS, LLC.
12189 * Originally Released Under LGPL - original licence link has changed is not relivant.
12192 * <script type="text/javascript">
12195 * @class Roo.form.VTypes
12196 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
12199 Roo.form.VTypes = function(){
12200 // closure these in so they are only created once.
12201 var alpha = /^[a-zA-Z_]+$/;
12202 var alphanum = /^[a-zA-Z0-9_]+$/;
12203 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
12204 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
12206 // All these messages and functions are configurable
12209 * The function used to validate email addresses
12210 * @param {String} value The email address
12212 email : function(v){
12213 return email.test(v);
12216 * The error text to display when the email validation function returns false
12219 emailText : 'This field should be an e-mail address in the format "user@domain.com"',
12221 * The keystroke filter mask to be applied on email input
12224 emailMask : /[a-z0-9_\.\-@]/i,
12227 * The function used to validate URLs
12228 * @param {String} value The URL
12231 return url.test(v);
12234 * The error text to display when the url validation function returns false
12237 urlText : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
12240 * The function used to validate alpha values
12241 * @param {String} value The value
12243 alpha : function(v){
12244 return alpha.test(v);
12247 * The error text to display when the alpha validation function returns false
12250 alphaText : 'This field should only contain letters and _',
12252 * The keystroke filter mask to be applied on alpha input
12255 alphaMask : /[a-z_]/i,
12258 * The function used to validate alphanumeric values
12259 * @param {String} value The value
12261 alphanum : function(v){
12262 return alphanum.test(v);
12265 * The error text to display when the alphanumeric validation function returns false
12268 alphanumText : 'This field should only contain letters, numbers and _',
12270 * The keystroke filter mask to be applied on alphanumeric input
12273 alphanumMask : /[a-z0-9_]/i
12283 * @class Roo.bootstrap.form.Input
12284 * @extends Roo.bootstrap.Component
12285 * Bootstrap Input class
12286 * @cfg {Boolean} disabled is it disabled
12287 * @cfg {String} inputType (button|checkbox|email|file|hidden|image|number|password|radio|range|reset|search|submit|text)
12288 * @cfg {String} name name of the input
12289 * @cfg {string} fieldLabel - the label associated
12290 * @cfg {string} placeholder - placeholder to put in text.
12291 * @cfg {string} before - input group add on before
12292 * @cfg {string} after - input group add on after
12293 * @cfg {string} size - (lg|sm) or leave empty..
12294 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
12295 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
12296 * @cfg {Number} md colspan out of 12 for computer-sized screens
12297 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
12298 * @cfg {string} value default value of the input
12299 * @cfg {Number} labelWidth set the width of label
12300 * @cfg {Number} labellg set the width of label (1-12)
12301 * @cfg {Number} labelmd set the width of label (1-12)
12302 * @cfg {Number} labelsm set the width of label (1-12)
12303 * @cfg {Number} labelxs set the width of label (1-12)
12304 * @cfg {String} labelAlign (top|left)
12305 * @cfg {Boolean} readOnly Specifies that the field should be read-only
12306 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
12307 * @cfg {String} indicatorpos (left|right) default left
12308 * @cfg {String} capture (user|camera) use for file input only. (default empty)
12309 * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
12310 * @cfg {Boolean} preventMark Do not show tick or cross if error/success
12311 * @cfg {Roo.bootstrap.Button} before Button to show before
12312 * @cfg {Roo.bootstrap.Button} afterButton to show before
12313 * @cfg {String} align (left|center|right) Default left
12314 * @cfg {Boolean} forceFeedback (true|false) Default false
12317 * Create a new Input
12318 * @param {Object} config The config object
12321 Roo.bootstrap.form.Input = function(config){
12323 Roo.bootstrap.form.Input.superclass.constructor.call(this, config);
12328 * Fires when this field receives input focus.
12329 * @param {Roo.form.Field} this
12334 * Fires when this field loses input focus.
12335 * @param {Roo.form.Field} this
12339 * @event specialkey
12340 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
12341 * {@link Roo.EventObject#getKey} to determine which key was pressed.
12342 * @param {Roo.form.Field} this
12343 * @param {Roo.EventObject} e The event object
12348 * Fires just before the field blurs if the field value has changed.
12349 * @param {Roo.form.Field} this
12350 * @param {Mixed} newValue The new value
12351 * @param {Mixed} oldValue The original value
12356 * Fires after the field has been marked as invalid.
12357 * @param {Roo.form.Field} this
12358 * @param {String} msg The validation message
12363 * Fires after the field has been validated with no errors.
12364 * @param {Roo.form.Field} this
12369 * Fires after the key up
12370 * @param {Roo.form.Field} this
12371 * @param {Roo.EventObject} e The event Object
12376 * Fires after the user pastes into input
12377 * @param {Roo.form.Field} this
12378 * @param {Roo.EventObject} e The event Object
12384 Roo.extend(Roo.bootstrap.form.Input, Roo.bootstrap.Component, {
12386 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
12387 automatic validation (defaults to "keyup").
12389 validationEvent : "keyup",
12391 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
12393 validateOnBlur : true,
12395 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
12397 validationDelay : 250,
12399 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
12401 focusClass : "x-form-focus", // not needed???
12405 * @cfg {String} invalidClass DEPRICATED - code uses BS4 - is-valid / is-invalid
12407 invalidClass : "has-warning",
12410 * @cfg {String} validClass DEPRICATED - code uses BS4 - is-valid / is-invalid
12412 validClass : "has-success",
12415 * @cfg {Boolean} hasFeedback (true|false) default true
12417 hasFeedback : true,
12420 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
12422 invalidFeedbackClass : "glyphicon-warning-sign",
12425 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
12427 validFeedbackClass : "glyphicon-ok",
12430 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
12432 selectOnFocus : false,
12435 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
12439 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
12444 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
12446 disableKeyFilter : false,
12449 * @cfg {Boolean} disabled True to disable the field (defaults to false).
12453 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
12457 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
12459 blankText : "Please complete this mandatory field",
12462 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
12466 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
12468 maxLength : Number.MAX_VALUE,
12470 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
12472 minLengthText : "The minimum length for this field is {0}",
12474 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
12476 maxLengthText : "The maximum length for this field is {0}",
12480 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
12481 * If available, this function will be called only after the basic validators all return true, and will be passed the
12482 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
12486 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
12487 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
12488 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
12492 * @cfg {String} regexText -- Depricated - use Invalid Text
12497 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
12503 autocomplete: false,
12507 inputType : 'text',
12510 placeholder: false,
12515 preventMark: false,
12516 isFormField : true,
12519 labelAlign : false,
12522 formatedValue : false,
12523 forceFeedback : false,
12525 indicatorpos : 'left',
12535 parentLabelAlign : function()
12538 while (parent.parent()) {
12539 parent = parent.parent();
12540 if (typeof(parent.labelAlign) !='undefined') {
12541 return parent.labelAlign;
12548 getAutoCreate : function()
12550 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
12556 if(this.inputType != 'hidden'){
12557 cfg.cls = 'form-group' //input-group
12563 type : this.inputType,
12564 value : this.value,
12565 cls : 'form-control',
12566 placeholder : this.placeholder || '',
12567 autocomplete : this.autocomplete || 'new-password'
12569 if (this.inputType == 'file') {
12570 input.style = 'overflow:hidden'; // why not in CSS?
12573 if(this.capture.length){
12574 input.capture = this.capture;
12577 if(this.accept.length){
12578 input.accept = this.accept + "/*";
12582 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
12585 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
12586 input.maxLength = this.maxLength;
12589 if (this.disabled) {
12590 input.disabled=true;
12593 if (this.readOnly) {
12594 input.readonly=true;
12598 input.name = this.name;
12602 input.cls += ' input-' + this.size;
12606 ['xs','sm','md','lg'].map(function(size){
12607 if (settings[size]) {
12608 cfg.cls += ' col-' + size + '-' + settings[size];
12612 var inputblock = input;
12616 cls: 'glyphicon form-control-feedback'
12619 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
12622 cls : 'has-feedback',
12630 if (this.before || this.after) {
12633 cls : 'input-group',
12637 if (this.before && typeof(this.before) == 'string') {
12639 inputblock.cn.push({
12641 cls : 'roo-input-before input-group-addon input-group-prepend input-group-text',
12645 if (this.before && typeof(this.before) == 'object') {
12646 this.before = Roo.factory(this.before);
12648 inputblock.cn.push({
12650 cls : 'roo-input-before input-group-prepend input-group-' +
12651 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
12655 inputblock.cn.push(input);
12657 if (this.after && typeof(this.after) == 'string') {
12658 inputblock.cn.push({
12660 cls : 'roo-input-after input-group-append input-group-text input-group-addon',
12664 if (this.after && typeof(this.after) == 'object') {
12665 this.after = Roo.factory(this.after);
12667 inputblock.cn.push({
12669 cls : 'roo-input-after input-group-append input-group-' +
12670 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
12674 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
12675 inputblock.cls += ' has-feedback';
12676 inputblock.cn.push(feedback);
12681 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
12682 tooltip : 'This field is required'
12684 if (this.allowBlank ) {
12685 indicator.style = this.allowBlank ? ' display:none' : '';
12687 if (align ==='left' && this.fieldLabel.length) {
12689 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
12696 cls : 'control-label col-form-label',
12697 html : this.fieldLabel
12708 var labelCfg = cfg.cn[1];
12709 var contentCfg = cfg.cn[2];
12711 if(this.indicatorpos == 'right'){
12716 cls : 'control-label col-form-label',
12720 html : this.fieldLabel
12734 labelCfg = cfg.cn[0];
12735 contentCfg = cfg.cn[1];
12739 if(this.labelWidth > 12){
12740 labelCfg.style = "width: " + this.labelWidth + 'px';
12743 if(this.labelWidth < 13 && this.labelmd == 0){
12744 this.labellg = this.labellg > 0 ? this.labellg : this.labelWidth;
12747 if(this.labellg > 0){
12748 labelCfg.cls += ' col-lg-' + this.labellg;
12749 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
12752 if(this.labelmd > 0){
12753 labelCfg.cls += ' col-md-' + this.labelmd;
12754 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
12757 if(this.labelsm > 0){
12758 labelCfg.cls += ' col-sm-' + this.labelsm;
12759 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
12762 if(this.labelxs > 0){
12763 labelCfg.cls += ' col-xs-' + this.labelxs;
12764 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
12768 } else if ( this.fieldLabel.length) {
12775 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12776 tooltip : 'This field is required',
12777 style : this.allowBlank ? ' display:none' : ''
12781 //cls : 'input-group-addon',
12782 html : this.fieldLabel
12790 if(this.indicatorpos == 'right'){
12795 //cls : 'input-group-addon',
12796 html : this.fieldLabel
12801 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12802 tooltip : 'This field is required',
12803 style : this.allowBlank ? ' display:none' : ''
12823 if (this.parentType === 'Navbar' && this.parent().bar) {
12824 cfg.cls += ' navbar-form';
12827 if (this.parentType === 'NavGroup' && !(Roo.bootstrap.version == 4 && this.parent().form)) {
12828 // on BS4 we do this only if not form
12829 cfg.cls += ' navbar-form';
12837 * return the real input element.
12839 inputEl: function ()
12841 return this.el.select('input.form-control',true).first();
12844 tooltipEl : function()
12846 return this.inputEl();
12849 indicatorEl : function()
12851 if (Roo.bootstrap.version == 4) {
12852 return false; // not enabled in v4 yet.
12855 var indicator = this.el.select('i.roo-required-indicator',true).first();
12865 setDisabled : function(v)
12867 var i = this.inputEl().dom;
12869 i.removeAttribute('disabled');
12873 i.setAttribute('disabled','true');
12875 initEvents : function()
12878 this.inputEl().on("keydown" , this.fireKey, this);
12879 this.inputEl().on("focus", this.onFocus, this);
12880 this.inputEl().on("blur", this.onBlur, this);
12882 this.inputEl().relayEvent('keyup', this);
12883 this.inputEl().relayEvent('paste', this);
12885 this.indicator = this.indicatorEl();
12887 if(this.indicator){
12888 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? -
12891 // reference to original value for reset
12892 this.originalValue = this.getValue();
12893 //Roo.form.TextField.superclass.initEvents.call(this);
12894 if(this.validationEvent == 'keyup'){
12895 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
12896 this.inputEl().on('keyup', this.filterValidation, this);
12898 else if(this.validationEvent !== false){
12899 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
12902 if(this.selectOnFocus){
12903 this.on("focus", this.preFocus, this);
12906 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
12907 this.inputEl().on("keypress", this.filterKeys, this);
12909 this.inputEl().relayEvent('keypress', this);
12912 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
12913 this.el.on("click", this.autoSize, this);
12916 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
12917 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
12920 if (typeof(this.before) == 'object') {
12921 this.before.render(this.el.select('.roo-input-before',true).first());
12923 if (typeof(this.after) == 'object') {
12924 this.after.render(this.el.select('.roo-input-after',true).first());
12927 this.inputEl().on('change', this.onChange, this);
12930 filterValidation : function(e){
12931 if(!e.isNavKeyPress()){
12932 this.validationTask.delay(this.validationDelay);
12936 * Validates the field value
12937 * @return {Boolean} True if the value is valid, else false
12939 validate : function(){
12940 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
12941 if(this.disabled || this.validateValue(this.getRawValue())){
12946 this.markInvalid();
12952 * Validates a value according to the field's validation rules and marks the field as invalid
12953 * if the validation fails
12954 * @param {Mixed} value The value to validate
12955 * @return {Boolean} True if the value is valid, else false
12957 validateValue : function(value)
12959 if(this.getVisibilityEl().hasClass('hidden')){
12963 if(value.length < 1) { // if it's blank
12964 if(this.allowBlank){
12970 if(value.length < this.minLength){
12973 if(value.length > this.maxLength){
12977 var vt = Roo.form.VTypes;
12978 if(!vt[this.vtype](value, this)){
12982 if(typeof this.validator == "function"){
12983 var msg = this.validator(value);
12984 if (typeof(msg) == 'string') {
12985 this.invalidText = msg;
12992 if(this.regex && !this.regex.test(value)){
13000 fireKey : function(e){
13001 //Roo.log('field ' + e.getKey());
13002 if(e.isNavKeyPress()){
13003 this.fireEvent("specialkey", this, e);
13006 focus : function (selectText){
13008 this.inputEl().focus();
13009 if(selectText === true){
13010 this.inputEl().dom.select();
13016 onFocus : function(){
13017 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
13018 // this.el.addClass(this.focusClass);
13020 if(!this.hasFocus){
13021 this.hasFocus = true;
13022 this.startValue = this.getValue();
13023 this.fireEvent("focus", this);
13027 beforeBlur : Roo.emptyFn,
13031 onBlur : function(){
13033 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
13034 //this.el.removeClass(this.focusClass);
13036 this.hasFocus = false;
13037 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
13040 var v = this.getValue();
13041 if(String(v) !== String(this.startValue)){
13042 this.fireEvent('change', this, v, this.startValue);
13044 this.fireEvent("blur", this);
13047 onChange : function(e)
13049 var v = this.getValue();
13050 if(String(v) !== String(this.startValue)){
13051 this.fireEvent('change', this, v, this.startValue);
13057 * Resets the current field value to the originally loaded value and clears any validation messages
13059 reset : function(){
13060 this.setValue(this.originalValue);
13064 * Returns the name of the field
13065 * @return {Mixed} name The name field
13067 getName: function(){
13071 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
13072 * @return {Mixed} value The field value
13074 getValue : function(){
13076 var v = this.inputEl().getValue();
13081 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
13082 * @return {Mixed} value The field value
13084 getRawValue : function(){
13085 var v = this.inputEl().getValue();
13091 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
13092 * @param {Mixed} value The value to set
13094 setRawValue : function(v){
13095 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
13098 selectText : function(start, end){
13099 var v = this.getRawValue();
13101 start = start === undefined ? 0 : start;
13102 end = end === undefined ? v.length : end;
13103 var d = this.inputEl().dom;
13104 if(d.setSelectionRange){
13105 d.setSelectionRange(start, end);
13106 }else if(d.createTextRange){
13107 var range = d.createTextRange();
13108 range.moveStart("character", start);
13109 range.moveEnd("character", v.length-end);
13116 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
13117 * @param {Mixed} value The value to set
13119 setValue : function(v){
13122 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
13128 processValue : function(value){
13129 if(this.stripCharsRe){
13130 var newValue = value.replace(this.stripCharsRe, '');
13131 if(newValue !== value){
13132 this.setRawValue(newValue);
13139 preFocus : function(){
13141 if(this.selectOnFocus){
13142 this.inputEl().dom.select();
13145 filterKeys : function(e){
13146 var k = e.getKey();
13147 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
13150 var c = e.getCharCode(), cc = String.fromCharCode(c);
13151 if(Roo.isIE && (e.isSpecialKey() || !cc)){
13154 if(!this.maskRe.test(cc)){
13159 * Clear any invalid styles/messages for this field
13161 clearInvalid : function(){
13163 if(!this.el || this.preventMark){ // not rendered
13168 this.el.removeClass([this.invalidClass, 'is-invalid']);
13170 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13172 var feedback = this.el.select('.form-control-feedback', true).first();
13175 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
13180 if(this.indicator){
13181 this.indicator.removeClass('visible');
13182 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13185 this.fireEvent('valid', this);
13189 * Mark this field as valid
13191 markValid : function()
13193 if(!this.el || this.preventMark){ // not rendered...
13197 this.el.removeClass([this.invalidClass, this.validClass]);
13198 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13200 var feedback = this.el.select('.form-control-feedback', true).first();
13203 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13206 if(this.indicator){
13207 this.indicator.removeClass('visible');
13208 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13216 if(this.allowBlank && !this.getRawValue().length){
13219 if (Roo.bootstrap.version == 3) {
13220 this.el.addClass(this.validClass);
13222 this.inputEl().addClass('is-valid');
13225 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
13227 var feedback = this.el.select('.form-control-feedback', true).first();
13230 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13231 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
13236 this.fireEvent('valid', this);
13240 * Mark this field as invalid
13241 * @param {String} msg The validation message
13243 markInvalid : function(msg)
13245 if(!this.el || this.preventMark){ // not rendered
13249 this.el.removeClass([this.invalidClass, this.validClass]);
13250 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13252 var feedback = this.el.select('.form-control-feedback', true).first();
13255 this.el.select('.form-control-feedback', true).first().removeClass(
13256 [this.invalidFeedbackClass, this.validFeedbackClass]);
13263 if(this.allowBlank && !this.getRawValue().length){
13267 if(this.indicator){
13268 this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13269 this.indicator.addClass('visible');
13271 if (Roo.bootstrap.version == 3) {
13272 this.el.addClass(this.invalidClass);
13274 this.inputEl().addClass('is-invalid');
13279 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13281 var feedback = this.el.select('.form-control-feedback', true).first();
13284 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13286 if(this.getValue().length || this.forceFeedback){
13287 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
13294 this.fireEvent('invalid', this, msg);
13297 SafariOnKeyDown : function(event)
13299 // this is a workaround for a password hang bug on chrome/ webkit.
13300 if (this.inputEl().dom.type != 'password') {
13304 var isSelectAll = false;
13306 if(this.inputEl().dom.selectionEnd > 0){
13307 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
13309 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
13310 event.preventDefault();
13315 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
13317 event.preventDefault();
13318 // this is very hacky as keydown always get's upper case.
13320 var cc = String.fromCharCode(event.getCharCode());
13321 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
13325 adjustWidth : function(tag, w){
13326 tag = tag.toLowerCase();
13327 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
13328 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
13329 if(tag == 'input'){
13332 if(tag == 'textarea'){
13335 }else if(Roo.isOpera){
13336 if(tag == 'input'){
13339 if(tag == 'textarea'){
13347 setFieldLabel : function(v)
13349 if(!this.rendered){
13353 if(this.indicatorEl()){
13354 var ar = this.el.select('label > span',true);
13356 if (ar.elements.length) {
13357 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13358 this.fieldLabel = v;
13362 var br = this.el.select('label',true);
13364 if(br.elements.length) {
13365 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13366 this.fieldLabel = v;
13370 Roo.log('Cannot Found any of label > span || label in input');
13374 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13375 this.fieldLabel = v;
13390 * @class Roo.bootstrap.form.TextArea
13391 * @extends Roo.bootstrap.form.Input
13392 * Bootstrap TextArea class
13393 * @cfg {Number} cols Specifies the visible width of a text area
13394 * @cfg {Number} rows Specifies the visible number of lines in a text area
13395 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
13396 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
13397 * @cfg {string} html text
13400 * Create a new TextArea
13401 * @param {Object} config The config object
13404 Roo.bootstrap.form.TextArea = function(config){
13405 Roo.bootstrap.form.TextArea.superclass.constructor.call(this, config);
13409 Roo.extend(Roo.bootstrap.form.TextArea, Roo.bootstrap.form.Input, {
13419 getAutoCreate : function(){
13421 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
13427 if(this.inputType != 'hidden'){
13428 cfg.cls = 'form-group' //input-group
13436 value : this.value || '',
13437 html: this.html || '',
13438 cls : 'form-control',
13439 placeholder : this.placeholder || ''
13443 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
13444 input.maxLength = this.maxLength;
13448 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
13452 input.cols = this.cols;
13455 if (this.readOnly) {
13456 input.readonly = true;
13460 input.name = this.name;
13464 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
13468 ['xs','sm','md','lg'].map(function(size){
13469 if (settings[size]) {
13470 cfg.cls += ' col-' + size + '-' + settings[size];
13474 var inputblock = input;
13476 if(this.hasFeedback && !this.allowBlank){
13480 cls: 'glyphicon form-control-feedback'
13484 cls : 'has-feedback',
13493 if (this.before || this.after) {
13496 cls : 'input-group',
13500 inputblock.cn.push({
13502 cls : 'input-group-addon',
13507 inputblock.cn.push(input);
13509 if(this.hasFeedback && !this.allowBlank){
13510 inputblock.cls += ' has-feedback';
13511 inputblock.cn.push(feedback);
13515 inputblock.cn.push({
13517 cls : 'input-group-addon',
13524 if (align ==='left' && this.fieldLabel.length) {
13529 cls : 'control-label',
13530 html : this.fieldLabel
13541 if(this.labelWidth > 12){
13542 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
13545 if(this.labelWidth < 13 && this.labelmd == 0){
13546 this.labelmd = this.labelWidth;
13549 if(this.labellg > 0){
13550 cfg.cn[0].cls += ' col-lg-' + this.labellg;
13551 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
13554 if(this.labelmd > 0){
13555 cfg.cn[0].cls += ' col-md-' + this.labelmd;
13556 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
13559 if(this.labelsm > 0){
13560 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
13561 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
13564 if(this.labelxs > 0){
13565 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
13566 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
13569 } else if ( this.fieldLabel.length) {
13574 //cls : 'input-group-addon',
13575 html : this.fieldLabel
13593 if (this.disabled) {
13594 input.disabled=true;
13601 * return the real textarea element.
13603 inputEl: function ()
13605 return this.el.select('textarea.form-control',true).first();
13609 * Clear any invalid styles/messages for this field
13611 clearInvalid : function()
13614 if(!this.el || this.preventMark){ // not rendered
13618 var label = this.el.select('label', true).first();
13619 var icon = this.el.select('i.fa-star', true).first();
13624 this.el.removeClass( this.validClass);
13625 this.inputEl().removeClass('is-invalid');
13627 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13629 var feedback = this.el.select('.form-control-feedback', true).first();
13632 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
13637 this.fireEvent('valid', this);
13641 * Mark this field as valid
13643 markValid : function()
13645 if(!this.el || this.preventMark){ // not rendered
13649 this.el.removeClass([this.invalidClass, this.validClass]);
13650 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13652 var feedback = this.el.select('.form-control-feedback', true).first();
13655 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13658 if(this.disabled || this.allowBlank){
13662 var label = this.el.select('label', true).first();
13663 var icon = this.el.select('i.fa-star', true).first();
13668 if (Roo.bootstrap.version == 3) {
13669 this.el.addClass(this.validClass);
13671 this.inputEl().addClass('is-valid');
13675 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
13677 var feedback = this.el.select('.form-control-feedback', true).first();
13680 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13681 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
13686 this.fireEvent('valid', this);
13690 * Mark this field as invalid
13691 * @param {String} msg The validation message
13693 markInvalid : function(msg)
13695 if(!this.el || this.preventMark){ // not rendered
13699 this.el.removeClass([this.invalidClass, this.validClass]);
13700 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13702 var feedback = this.el.select('.form-control-feedback', true).first();
13705 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13708 if(this.disabled || this.allowBlank){
13712 var label = this.el.select('label', true).first();
13713 var icon = this.el.select('i.fa-star', true).first();
13715 if(!this.getValue().length && label && !icon){
13716 this.el.createChild({
13718 cls : 'text-danger fa fa-lg fa-star',
13719 tooltip : 'This field is required',
13720 style : 'margin-right:5px;'
13724 if (Roo.bootstrap.version == 3) {
13725 this.el.addClass(this.invalidClass);
13727 this.inputEl().addClass('is-invalid');
13730 // fixme ... this may be depricated need to test..
13731 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13733 var feedback = this.el.select('.form-control-feedback', true).first();
13736 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13738 if(this.getValue().length || this.forceFeedback){
13739 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
13746 this.fireEvent('invalid', this, msg);
13754 * trigger field - base class for combo..
13759 * @class Roo.bootstrap.form.TriggerField
13760 * @extends Roo.bootstrap.form.Input
13761 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
13762 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
13763 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
13764 * for which you can provide a custom implementation. For example:
13766 var trigger = new Roo.bootstrap.form.TriggerField();
13767 trigger.onTriggerClick = myTriggerFn;
13768 trigger.applyTo('my-field');
13771 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
13772 * {@link Roo.bootstrap.form.DateField} and {@link Roo.bootstrap.form.ComboBox} are perfect examples of this.
13773 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
13774 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
13775 * @cfg {String} caret (search|calendar) BS3 only - carat fa name
13778 * Create a new TriggerField.
13779 * @param {Object} config Configuration options (valid {@Roo.bootstrap.form.Input} config options will also be applied
13780 * to the base TextField)
13782 Roo.bootstrap.form.TriggerField = function(config){
13783 this.mimicing = false;
13784 Roo.bootstrap.form.TriggerField.superclass.constructor.call(this, config);
13787 Roo.extend(Roo.bootstrap.form.TriggerField, Roo.bootstrap.form.Input, {
13789 * @cfg {String} triggerClass A CSS class to apply to the trigger
13792 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
13797 * @cfg {Boolean} removable (true|false) special filter default false
13801 /** @cfg {Boolean} grow @hide */
13802 /** @cfg {Number} growMin @hide */
13803 /** @cfg {Number} growMax @hide */
13809 autoSize: Roo.emptyFn,
13813 deferHeight : true,
13816 actionMode : 'wrap',
13821 getAutoCreate : function(){
13823 var align = this.labelAlign || this.parentLabelAlign();
13828 cls: 'form-group' //input-group
13835 type : this.inputType,
13836 cls : 'form-control',
13837 autocomplete: 'new-password',
13838 placeholder : this.placeholder || ''
13842 input.name = this.name;
13845 input.cls += ' input-' + this.size;
13848 if (this.disabled) {
13849 input.disabled=true;
13852 var inputblock = input;
13854 if(this.hasFeedback && !this.allowBlank){
13858 cls: 'glyphicon form-control-feedback'
13861 if(this.removable && !this.editable ){
13863 cls : 'has-feedback',
13869 cls : 'roo-combo-removable-btn close'
13876 cls : 'has-feedback',
13885 if(this.removable && !this.editable ){
13887 cls : 'roo-removable',
13893 cls : 'roo-combo-removable-btn close'
13900 if (this.before || this.after) {
13903 cls : 'input-group',
13907 inputblock.cn.push({
13909 cls : 'input-group-addon input-group-prepend input-group-text',
13914 inputblock.cn.push(input);
13916 if(this.hasFeedback && !this.allowBlank){
13917 inputblock.cls += ' has-feedback';
13918 inputblock.cn.push(feedback);
13922 inputblock.cn.push({
13924 cls : 'input-group-addon input-group-append input-group-text',
13933 var ibwrap = inputblock;
13938 cls: 'roo-select2-choices',
13942 cls: 'roo-select2-search-field',
13954 cls: 'roo-select2-container input-group',
13959 cls: 'form-hidden-field'
13965 if(!this.multiple && this.showToggleBtn){
13971 if (this.caret != false) {
13974 cls: 'fa fa-' + this.caret
13981 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
13983 Roo.bootstrap.version == 3 ? caret : '',
13986 cls: 'combobox-clear',
14000 combobox.cls += ' roo-select2-container-multi';
14004 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
14005 tooltip : 'This field is required'
14007 if (Roo.bootstrap.version == 4) {
14010 style : 'display:none'
14015 if (align ==='left' && this.fieldLabel.length) {
14017 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
14024 cls : 'control-label',
14025 html : this.fieldLabel
14037 var labelCfg = cfg.cn[1];
14038 var contentCfg = cfg.cn[2];
14040 if(this.indicatorpos == 'right'){
14045 cls : 'control-label',
14049 html : this.fieldLabel
14063 labelCfg = cfg.cn[0];
14064 contentCfg = cfg.cn[1];
14067 if(this.labelWidth > 12){
14068 labelCfg.style = "width: " + this.labelWidth + 'px';
14071 if(this.labelWidth < 13 && this.labelmd == 0){
14072 this.labelmd = this.labelWidth;
14075 if(this.labellg > 0){
14076 labelCfg.cls += ' col-lg-' + this.labellg;
14077 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
14080 if(this.labelmd > 0){
14081 labelCfg.cls += ' col-md-' + this.labelmd;
14082 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
14085 if(this.labelsm > 0){
14086 labelCfg.cls += ' col-sm-' + this.labelsm;
14087 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
14090 if(this.labelxs > 0){
14091 labelCfg.cls += ' col-xs-' + this.labelxs;
14092 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
14095 } else if ( this.fieldLabel.length) {
14096 // Roo.log(" label");
14101 //cls : 'input-group-addon',
14102 html : this.fieldLabel
14110 if(this.indicatorpos == 'right'){
14118 html : this.fieldLabel
14132 // Roo.log(" no label && no align");
14139 ['xs','sm','md','lg'].map(function(size){
14140 if (settings[size]) {
14141 cfg.cls += ' col-' + size + '-' + settings[size];
14152 onResize : function(w, h){
14153 // Roo.bootstrap.form.TriggerField.superclass.onResize.apply(this, arguments);
14154 // if(typeof w == 'number'){
14155 // var x = w - this.trigger.getWidth();
14156 // this.inputEl().setWidth(this.adjustWidth('input', x));
14157 // this.trigger.setStyle('left', x+'px');
14162 adjustSize : Roo.BoxComponent.prototype.adjustSize,
14165 getResizeEl : function(){
14166 return this.inputEl();
14170 getPositionEl : function(){
14171 return this.inputEl();
14175 alignErrorIcon : function(){
14176 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
14180 initEvents : function(){
14184 Roo.bootstrap.form.TriggerField.superclass.initEvents.call(this);
14185 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
14186 if(!this.multiple && this.showToggleBtn){
14187 this.trigger = this.el.select('span.dropdown-toggle',true).first();
14188 if(this.hideTrigger){
14189 this.trigger.setDisplayed(false);
14191 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
14195 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
14198 if(this.removable && !this.editable && !this.tickable){
14199 var close = this.closeTriggerEl();
14202 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
14203 close.on('click', this.removeBtnClick, this, close);
14207 //this.trigger.addClassOnOver('x-form-trigger-over');
14208 //this.trigger.addClassOnClick('x-form-trigger-click');
14211 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
14215 closeTriggerEl : function()
14217 var close = this.el.select('.roo-combo-removable-btn', true).first();
14218 return close ? close : false;
14221 removeBtnClick : function(e, h, el)
14223 e.preventDefault();
14225 if(this.fireEvent("remove", this) !== false){
14227 this.fireEvent("afterremove", this)
14231 createList : function()
14233 this.list = Roo.get(document.body).createChild({
14234 tag: Roo.bootstrap.version == 4 ? 'div' : 'ul',
14235 cls: 'typeahead typeahead-long dropdown-menu shadow',
14236 style: 'display:none'
14239 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
14244 initTrigger : function(){
14249 onDestroy : function(){
14251 this.trigger.removeAllListeners();
14252 // this.trigger.remove();
14255 // this.wrap.remove();
14257 Roo.bootstrap.form.TriggerField.superclass.onDestroy.call(this);
14261 onFocus : function(){
14262 Roo.bootstrap.form.TriggerField.superclass.onFocus.call(this);
14264 if(!this.mimicing){
14265 this.wrap.addClass('x-trigger-wrap-focus');
14266 this.mimicing = true;
14267 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
14268 if(this.monitorTab){
14269 this.el.on("keydown", this.checkTab, this);
14276 checkTab : function(e){
14277 if(e.getKey() == e.TAB){
14278 this.triggerBlur();
14283 onBlur : function(){
14288 mimicBlur : function(e, t){
14290 if(!this.wrap.contains(t) && this.validateBlur()){
14291 this.triggerBlur();
14297 triggerBlur : function(){
14298 this.mimicing = false;
14299 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
14300 if(this.monitorTab){
14301 this.el.un("keydown", this.checkTab, this);
14303 //this.wrap.removeClass('x-trigger-wrap-focus');
14304 Roo.bootstrap.form.TriggerField.superclass.onBlur.call(this);
14308 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
14309 validateBlur : function(e, t){
14314 onDisable : function(){
14315 this.inputEl().dom.disabled = true;
14316 //Roo.bootstrap.form.TriggerField.superclass.onDisable.call(this);
14318 // this.wrap.addClass('x-item-disabled');
14323 onEnable : function(){
14324 this.inputEl().dom.disabled = false;
14325 //Roo.bootstrap.form.TriggerField.superclass.onEnable.call(this);
14327 // this.el.removeClass('x-item-disabled');
14332 onShow : function(){
14333 var ae = this.getActionEl();
14336 ae.dom.style.display = '';
14337 ae.dom.style.visibility = 'visible';
14343 onHide : function(){
14344 var ae = this.getActionEl();
14345 ae.dom.style.display = 'none';
14349 * The function that should handle the trigger's click event. This method does nothing by default until overridden
14350 * by an implementing function.
14352 * @param {EventObject} e
14354 onTriggerClick : Roo.emptyFn
14362 * @class Roo.bootstrap.form.CardUploader
14363 * @extends Roo.bootstrap.Button
14364 * Bootstrap Card Uploader class - it's a button which when you add files to it, adds cards below with preview and the name...
14365 * @cfg {Number} errorTimeout default 3000
14366 * @cfg {Array} images an array of ?? Img objects ??? when loading existing files..
14367 * @cfg {Array} html The button text.
14371 * Create a new CardUploader
14372 * @param {Object} config The config object
14375 Roo.bootstrap.form.CardUploader = function(config){
14379 Roo.bootstrap.form.CardUploader.superclass.constructor.call(this, config);
14382 this.fileCollection = new Roo.util.MixedCollection(false,function(r) {
14390 * When a image is clicked on - and needs to display a slideshow or similar..
14391 * @param {Roo.bootstrap.Card} this
14392 * @param {Object} The image information data
14398 * When a the download link is clicked
14399 * @param {Roo.bootstrap.Card} this
14400 * @param {Object} The image information data contains
14407 Roo.extend(Roo.bootstrap.form.CardUploader, Roo.bootstrap.form.Input, {
14410 errorTimeout : 3000,
14414 fileCollection : false,
14417 getAutoCreate : function()
14421 cls :'form-group' ,
14426 //cls : 'input-group-addon',
14427 html : this.fieldLabel
14435 value : this.value,
14436 cls : 'd-none form-control'
14441 multiple : 'multiple',
14443 cls : 'd-none roo-card-upload-selector'
14447 cls : 'roo-card-uploader-button-container w-100 mb-2'
14450 cls : 'card-columns roo-card-uploader-container'
14460 getChildContainer : function() /// what children are added to.
14462 return this.containerEl;
14465 getButtonContainer : function() /// what children are added to.
14467 return this.el.select(".roo-card-uploader-button-container").first();
14470 initEvents : function()
14473 Roo.bootstrap.form.Input.prototype.initEvents.call(this);
14477 xns: Roo.bootstrap,
14480 container_method : 'getButtonContainer' ,
14481 html : this.html, // fix changable?
14484 'click' : function(btn, e) {
14493 this.urlAPI = (window.createObjectURL && window) ||
14494 (window.URL && URL.revokeObjectURL && URL) ||
14495 (window.webkitURL && webkitURL);
14500 this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
14502 this.selectorEl.on('change', this.onFileSelected, this);
14505 this.images.forEach(function(img) {
14508 this.images = false;
14510 this.containerEl = this.el.select('.roo-card-uploader-container', true).first();
14516 onClick : function(e)
14518 e.preventDefault();
14520 this.selectorEl.dom.click();
14524 onFileSelected : function(e)
14526 e.preventDefault();
14528 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
14532 Roo.each(this.selectorEl.dom.files, function(file){
14533 this.addFile(file);
14542 addFile : function(file)
14545 if(typeof(file) === 'string'){
14546 throw "Add file by name?"; // should not happen
14550 if(!file || !this.urlAPI){
14560 var url = _this.urlAPI.createObjectURL( file);
14563 id : Roo.bootstrap.form.CardUploader.ID--,
14564 is_uploaded : false,
14568 mimetype : file.type,
14576 * addCard - add an Attachment to the uploader
14577 * @param data - the data about the image to upload
14581 title : "Title of file",
14582 is_uploaded : false,
14583 src : "http://.....",
14584 srcfile : { the File upload object },
14585 mimetype : file.type,
14588 .. any other data...
14594 addCard : function (data)
14596 // hidden input element?
14597 // if the file is not an image...
14598 //then we need to use something other that and header_image
14603 xns : Roo.bootstrap,
14604 xtype : 'CardFooter',
14607 xns : Roo.bootstrap,
14613 xns : Roo.bootstrap,
14615 html : String.format("<small>{0}</small>", data.title),
14616 cls : 'col-10 text-left',
14621 click : function() {
14623 t.fireEvent( "download", t, data );
14629 xns : Roo.bootstrap,
14631 style: 'max-height: 28px; ',
14637 click : function() {
14638 t.removeCard(data.id)
14650 var cn = this.addxtype(
14653 xns : Roo.bootstrap,
14656 header : !data.mimetype.match(/image/) && !data.preview ? "Document": false,
14657 header_image : data.mimetype.match(/image/) ? data.src : data.preview,
14658 header_image_fit_square: true, // fixme - we probably need to use the 'Img' element to do stuff like this.
14663 initEvents : function() {
14664 Roo.bootstrap.Card.prototype.initEvents.call(this);
14666 this.imgEl = this.el.select('.card-img-top').first();
14668 this.imgEl.on('click', function() { t.fireEvent( "preview", t, data ); }, this);
14669 this.imgEl.set({ 'pointer' : 'cursor' });
14672 this.getCardFooter().addClass('p-1');
14679 // dont' really need ot update items.
14680 // this.items.push(cn);
14681 this.fileCollection.add(cn);
14683 if (!data.srcfile) {
14684 this.updateInput();
14689 var reader = new FileReader();
14690 reader.addEventListener("load", function() {
14691 data.srcdata = reader.result;
14694 reader.readAsDataURL(data.srcfile);
14699 removeCard : function(id)
14702 var card = this.fileCollection.get(id);
14703 card.data.is_deleted = 1;
14704 card.data.src = ''; /// delete the source - so it reduces size of not uploaded images etc.
14705 //this.fileCollection.remove(card);
14706 //this.items = this.items.filter(function(e) { return e != card });
14707 // dont' really need ot update items.
14708 card.el.dom.parentNode.removeChild(card.el.dom);
14709 this.updateInput();
14715 this.fileCollection.each(function(card) {
14716 if (card.el.dom && card.el.dom.parentNode) {
14717 card.el.dom.parentNode.removeChild(card.el.dom);
14720 this.fileCollection.clear();
14721 this.updateInput();
14724 updateInput : function()
14727 this.fileCollection.each(function(e) {
14731 this.inputEl().dom.value = JSON.stringify(data);
14741 Roo.bootstrap.form.CardUploader.ID = -1;/*
14743 * Ext JS Library 1.1.1
14744 * Copyright(c) 2006-2007, Ext JS, LLC.
14746 * Originally Released Under LGPL - original licence link has changed is not relivant.
14749 * <script type="text/javascript">
14754 * @class Roo.data.SortTypes
14756 * Defines the default sorting (casting?) comparison functions used when sorting data.
14758 Roo.data.SortTypes = {
14760 * Default sort that does nothing
14761 * @param {Mixed} s The value being converted
14762 * @return {Mixed} The comparison value
14764 none : function(s){
14769 * The regular expression used to strip tags
14773 stripTagsRE : /<\/?[^>]+>/gi,
14776 * Strips all HTML tags to sort on text only
14777 * @param {Mixed} s The value being converted
14778 * @return {String} The comparison value
14780 asText : function(s){
14781 return String(s).replace(this.stripTagsRE, "");
14785 * Strips all HTML tags to sort on text only - Case insensitive
14786 * @param {Mixed} s The value being converted
14787 * @return {String} The comparison value
14789 asUCText : function(s){
14790 return String(s).toUpperCase().replace(this.stripTagsRE, "");
14794 * Case insensitive string
14795 * @param {Mixed} s The value being converted
14796 * @return {String} The comparison value
14798 asUCString : function(s) {
14799 return String(s).toUpperCase();
14804 * @param {Mixed} s The value being converted
14805 * @return {Number} The comparison value
14807 asDate : function(s) {
14811 if(s instanceof Date){
14812 return s.getTime();
14814 return Date.parse(String(s));
14819 * @param {Mixed} s The value being converted
14820 * @return {Float} The comparison value
14822 asFloat : function(s) {
14823 var val = parseFloat(String(s).replace(/,/g, ""));
14832 * @param {Mixed} s The value being converted
14833 * @return {Number} The comparison value
14835 asInt : function(s) {
14836 var val = parseInt(String(s).replace(/,/g, ""));
14844 * Ext JS Library 1.1.1
14845 * Copyright(c) 2006-2007, Ext JS, LLC.
14847 * Originally Released Under LGPL - original licence link has changed is not relivant.
14850 * <script type="text/javascript">
14854 * @class Roo.data.Record
14855 * Instances of this class encapsulate both record <em>definition</em> information, and record
14856 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
14857 * to access Records cached in an {@link Roo.data.Store} object.<br>
14859 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
14860 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
14863 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
14865 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
14866 * {@link #create}. The parameters are the same.
14867 * @param {Array} data An associative Array of data values keyed by the field name.
14868 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
14869 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
14870 * not specified an integer id is generated.
14872 Roo.data.Record = function(data, id){
14873 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
14878 * Generate a constructor for a specific record layout.
14879 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
14880 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
14881 * Each field definition object may contain the following properties: <ul>
14882 * <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,
14883 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
14884 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
14885 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
14886 * is being used, then this is a string containing the javascript expression to reference the data relative to
14887 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
14888 * to the data item relative to the record element. If the mapping expression is the same as the field name,
14889 * this may be omitted.</p></li>
14890 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
14891 * <ul><li>auto (Default, implies no conversion)</li>
14896 * <li>date</li></ul></p></li>
14897 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
14898 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
14899 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
14900 * by the Reader into an object that will be stored in the Record. It is passed the
14901 * following parameters:<ul>
14902 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
14904 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
14906 * <br>usage:<br><pre><code>
14907 var TopicRecord = Roo.data.Record.create(
14908 {name: 'title', mapping: 'topic_title'},
14909 {name: 'author', mapping: 'username'},
14910 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
14911 {name: 'lastPost', mapping: 'post_time', type: 'date'},
14912 {name: 'lastPoster', mapping: 'user2'},
14913 {name: 'excerpt', mapping: 'post_text'}
14916 var myNewRecord = new TopicRecord({
14917 title: 'Do my job please',
14920 lastPost: new Date(),
14921 lastPoster: 'Animal',
14922 excerpt: 'No way dude!'
14924 myStore.add(myNewRecord);
14929 Roo.data.Record.create = function(o){
14930 var f = function(){
14931 f.superclass.constructor.apply(this, arguments);
14933 Roo.extend(f, Roo.data.Record);
14934 var p = f.prototype;
14935 p.fields = new Roo.util.MixedCollection(false, function(field){
14938 for(var i = 0, len = o.length; i < len; i++){
14939 p.fields.add(new Roo.data.Field(o[i]));
14941 f.getField = function(name){
14942 return p.fields.get(name);
14947 Roo.data.Record.AUTO_ID = 1000;
14948 Roo.data.Record.EDIT = 'edit';
14949 Roo.data.Record.REJECT = 'reject';
14950 Roo.data.Record.COMMIT = 'commit';
14952 Roo.data.Record.prototype = {
14954 * Readonly flag - true if this record has been modified.
14963 join : function(store){
14964 this.store = store;
14968 * Set the named field to the specified value.
14969 * @param {String} name The name of the field to set.
14970 * @param {Object} value The value to set the field to.
14972 set : function(name, value){
14973 if(this.data[name] == value){
14977 if(!this.modified){
14978 this.modified = {};
14980 if(typeof this.modified[name] == 'undefined'){
14981 this.modified[name] = this.data[name];
14983 this.data[name] = value;
14984 if(!this.editing && this.store){
14985 this.store.afterEdit(this);
14990 * Get the value of the named field.
14991 * @param {String} name The name of the field to get the value of.
14992 * @return {Object} The value of the field.
14994 get : function(name){
14995 return this.data[name];
14999 beginEdit : function(){
15000 this.editing = true;
15001 this.modified = {};
15005 cancelEdit : function(){
15006 this.editing = false;
15007 delete this.modified;
15011 endEdit : function(){
15012 this.editing = false;
15013 if(this.dirty && this.store){
15014 this.store.afterEdit(this);
15019 * Usually called by the {@link Roo.data.Store} which owns the Record.
15020 * Rejects all changes made to the Record since either creation, or the last commit operation.
15021 * Modified fields are reverted to their original values.
15023 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
15024 * of reject operations.
15026 reject : function(){
15027 var m = this.modified;
15029 if(typeof m[n] != "function"){
15030 this.data[n] = m[n];
15033 this.dirty = false;
15034 delete this.modified;
15035 this.editing = false;
15037 this.store.afterReject(this);
15042 * Usually called by the {@link Roo.data.Store} which owns the Record.
15043 * Commits all changes made to the Record since either creation, or the last commit operation.
15045 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
15046 * of commit operations.
15048 commit : function(){
15049 this.dirty = false;
15050 delete this.modified;
15051 this.editing = false;
15053 this.store.afterCommit(this);
15058 hasError : function(){
15059 return this.error != null;
15063 clearError : function(){
15068 * Creates a copy of this record.
15069 * @param {String} id (optional) A new record id if you don't want to use this record's id
15072 copy : function(newId) {
15073 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
15077 * Ext JS Library 1.1.1
15078 * Copyright(c) 2006-2007, Ext JS, LLC.
15080 * Originally Released Under LGPL - original licence link has changed is not relivant.
15083 * <script type="text/javascript">
15089 * @class Roo.data.Store
15090 * @extends Roo.util.Observable
15091 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
15092 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
15094 * 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
15095 * has no knowledge of the format of the data returned by the Proxy.<br>
15097 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
15098 * instances from the data object. These records are cached and made available through accessor functions.
15100 * Creates a new Store.
15101 * @param {Object} config A config object containing the objects needed for the Store to access data,
15102 * and read the data into Records.
15104 Roo.data.Store = function(config){
15105 this.data = new Roo.util.MixedCollection(false);
15106 this.data.getKey = function(o){
15109 this.baseParams = {};
15111 this.paramNames = {
15116 "multisort" : "_multisort"
15119 if(config && config.data){
15120 this.inlineData = config.data;
15121 delete config.data;
15124 Roo.apply(this, config);
15126 if(this.reader){ // reader passed
15127 this.reader = Roo.factory(this.reader, Roo.data);
15128 this.reader.xmodule = this.xmodule || false;
15129 if(!this.recordType){
15130 this.recordType = this.reader.recordType;
15132 if(this.reader.onMetaChange){
15133 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
15137 if(this.recordType){
15138 this.fields = this.recordType.prototype.fields;
15140 this.modified = [];
15144 * @event datachanged
15145 * Fires when the data cache has changed, and a widget which is using this Store
15146 * as a Record cache should refresh its view.
15147 * @param {Store} this
15149 datachanged : true,
15151 * @event metachange
15152 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
15153 * @param {Store} this
15154 * @param {Object} meta The JSON metadata
15159 * Fires when Records have been added to the Store
15160 * @param {Store} this
15161 * @param {Roo.data.Record[]} records The array of Records added
15162 * @param {Number} index The index at which the record(s) were added
15167 * Fires when a Record has been removed from the Store
15168 * @param {Store} this
15169 * @param {Roo.data.Record} record The Record that was removed
15170 * @param {Number} index The index at which the record was removed
15175 * Fires when a Record has been updated
15176 * @param {Store} this
15177 * @param {Roo.data.Record} record The Record that was updated
15178 * @param {String} operation The update operation being performed. Value may be one of:
15180 Roo.data.Record.EDIT
15181 Roo.data.Record.REJECT
15182 Roo.data.Record.COMMIT
15188 * Fires when the data cache has been cleared.
15189 * @param {Store} this
15193 * @event beforeload
15194 * Fires before a request is made for a new data object. If the beforeload handler returns false
15195 * the load action will be canceled.
15196 * @param {Store} this
15197 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15201 * @event beforeloadadd
15202 * Fires after a new set of Records has been loaded.
15203 * @param {Store} this
15204 * @param {Roo.data.Record[]} records The Records that were loaded
15205 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15207 beforeloadadd : true,
15210 * Fires after a new set of Records has been loaded, before they are added to the store.
15211 * @param {Store} this
15212 * @param {Roo.data.Record[]} records The Records that were loaded
15213 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15214 * @params {Object} return from reader
15218 * @event loadexception
15219 * Fires if an exception occurs in the Proxy during loading.
15220 * Called with the signature of the Proxy's "loadexception" event.
15221 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
15224 * @param {Object} return from JsonData.reader() - success, totalRecords, records
15225 * @param {Object} load options
15226 * @param {Object} jsonData from your request (normally this contains the Exception)
15228 loadexception : true
15232 this.proxy = Roo.factory(this.proxy, Roo.data);
15233 this.proxy.xmodule = this.xmodule || false;
15234 this.relayEvents(this.proxy, ["loadexception"]);
15236 this.sortToggle = {};
15237 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
15239 Roo.data.Store.superclass.constructor.call(this);
15241 if(this.inlineData){
15242 this.loadData(this.inlineData);
15243 delete this.inlineData;
15247 Roo.extend(Roo.data.Store, Roo.util.Observable, {
15249 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
15250 * without a remote query - used by combo/forms at present.
15254 * @cfg {Roo.data.DataProxy} proxy [required] The Proxy object which provides access to a data object.
15257 * @cfg {Array} data Inline data to be loaded when the store is initialized.
15260 * @cfg {Roo.data.DataReader} reader [required] The Reader object which processes the data object and returns
15261 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
15264 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
15265 * on any HTTP request
15268 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
15271 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
15275 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
15276 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
15278 remoteSort : false,
15281 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
15282 * loaded or when a record is removed. (defaults to false).
15284 pruneModifiedRecords : false,
15287 lastOptions : null,
15290 * Add Records to the Store and fires the add event.
15291 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
15293 add : function(records){
15294 records = [].concat(records);
15295 for(var i = 0, len = records.length; i < len; i++){
15296 records[i].join(this);
15298 var index = this.data.length;
15299 this.data.addAll(records);
15300 this.fireEvent("add", this, records, index);
15304 * Remove a Record from the Store and fires the remove event.
15305 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
15307 remove : function(record){
15308 var index = this.data.indexOf(record);
15309 this.data.removeAt(index);
15311 if(this.pruneModifiedRecords){
15312 this.modified.remove(record);
15314 this.fireEvent("remove", this, record, index);
15318 * Remove all Records from the Store and fires the clear event.
15320 removeAll : function(){
15322 if(this.pruneModifiedRecords){
15323 this.modified = [];
15325 this.fireEvent("clear", this);
15329 * Inserts Records to the Store at the given index and fires the add event.
15330 * @param {Number} index The start index at which to insert the passed Records.
15331 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
15333 insert : function(index, records){
15334 records = [].concat(records);
15335 for(var i = 0, len = records.length; i < len; i++){
15336 this.data.insert(index, records[i]);
15337 records[i].join(this);
15339 this.fireEvent("add", this, records, index);
15343 * Get the index within the cache of the passed Record.
15344 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
15345 * @return {Number} The index of the passed Record. Returns -1 if not found.
15347 indexOf : function(record){
15348 return this.data.indexOf(record);
15352 * Get the index within the cache of the Record with the passed id.
15353 * @param {String} id The id of the Record to find.
15354 * @return {Number} The index of the Record. Returns -1 if not found.
15356 indexOfId : function(id){
15357 return this.data.indexOfKey(id);
15361 * Get the Record with the specified id.
15362 * @param {String} id The id of the Record to find.
15363 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
15365 getById : function(id){
15366 return this.data.key(id);
15370 * Get the Record at the specified index.
15371 * @param {Number} index The index of the Record to find.
15372 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
15374 getAt : function(index){
15375 return this.data.itemAt(index);
15379 * Returns a range of Records between specified indices.
15380 * @param {Number} startIndex (optional) The starting index (defaults to 0)
15381 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
15382 * @return {Roo.data.Record[]} An array of Records
15384 getRange : function(start, end){
15385 return this.data.getRange(start, end);
15389 storeOptions : function(o){
15390 o = Roo.apply({}, o);
15393 this.lastOptions = o;
15397 * Loads the Record cache from the configured Proxy using the configured Reader.
15399 * If using remote paging, then the first load call must specify the <em>start</em>
15400 * and <em>limit</em> properties in the options.params property to establish the initial
15401 * position within the dataset, and the number of Records to cache on each read from the Proxy.
15403 * <strong>It is important to note that for remote data sources, loading is asynchronous,
15404 * and this call will return before the new data has been loaded. Perform any post-processing
15405 * in a callback function, or in a "load" event handler.</strong>
15407 * @param {Object} options An object containing properties which control loading options:<ul>
15408 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
15409 * <li>params.data {Object} if you are using a MemoryProxy / JsonReader, use this as the data to load stuff..
15412 data : data, // array of key=>value data like JsonReader
15413 total : data.length,
15419 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
15420 * passed the following arguments:<ul>
15421 * <li>r : Roo.data.Record[]</li>
15422 * <li>options: Options object from the load call</li>
15423 * <li>success: Boolean success indicator</li></ul></li>
15424 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
15425 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
15428 load : function(options){
15429 options = options || {};
15430 if(this.fireEvent("beforeload", this, options) !== false){
15431 this.storeOptions(options);
15432 var p = Roo.apply(options.params || {}, this.baseParams);
15433 // if meta was not loaded from remote source.. try requesting it.
15434 if (!this.reader.metaFromRemote) {
15435 p._requestMeta = 1;
15437 if(this.sortInfo && this.remoteSort){
15438 var pn = this.paramNames;
15439 p[pn["sort"]] = this.sortInfo.field;
15440 p[pn["dir"]] = this.sortInfo.direction;
15442 if (this.multiSort) {
15443 var pn = this.paramNames;
15444 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
15447 this.proxy.load(p, this.reader, this.loadRecords, this, options);
15452 * Reloads the Record cache from the configured Proxy using the configured Reader and
15453 * the options from the last load operation performed.
15454 * @param {Object} options (optional) An object containing properties which may override the options
15455 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
15456 * the most recently used options are reused).
15458 reload : function(options){
15459 this.load(Roo.applyIf(options||{}, this.lastOptions));
15463 // Called as a callback by the Reader during a load operation.
15464 loadRecords : function(o, options, success){
15467 if(success !== false){
15468 this.fireEvent("load", this, [], options, o);
15470 if(options.callback){
15471 options.callback.call(options.scope || this, [], options, false);
15475 // if data returned failure - throw an exception.
15476 if (o.success === false) {
15477 // show a message if no listener is registered.
15478 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
15479 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
15481 // loadmask wil be hooked into this..
15482 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
15485 var r = o.records, t = o.totalRecords || r.length;
15487 this.fireEvent("beforeloadadd", this, r, options, o);
15489 if(!options || options.add !== true){
15490 if(this.pruneModifiedRecords){
15491 this.modified = [];
15493 for(var i = 0, len = r.length; i < len; i++){
15497 this.data = this.snapshot;
15498 delete this.snapshot;
15501 this.data.addAll(r);
15502 this.totalLength = t;
15504 this.fireEvent("datachanged", this);
15506 this.totalLength = Math.max(t, this.data.length+r.length);
15510 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
15512 var e = new Roo.data.Record({});
15514 e.set(this.parent.displayField, this.parent.emptyTitle);
15515 e.set(this.parent.valueField, '');
15520 this.fireEvent("load", this, r, options, o);
15521 if(options.callback){
15522 options.callback.call(options.scope || this, r, options, true);
15528 * Loads data from a passed data block. A Reader which understands the format of the data
15529 * must have been configured in the constructor.
15530 * @param {Object} data The data block from which to read the Records. The format of the data expected
15531 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
15532 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
15534 loadData : function(o, append){
15535 var r = this.reader.readRecords(o);
15536 this.loadRecords(r, {add: append}, true);
15540 * using 'cn' the nested child reader read the child array into it's child stores.
15541 * @param {Object} rec The record with a 'children array
15543 loadDataFromChildren : function(rec)
15545 this.loadData(this.reader.toLoadData(rec));
15550 * Gets the number of cached records.
15552 * <em>If using paging, this may not be the total size of the dataset. If the data object
15553 * used by the Reader contains the dataset size, then the getTotalCount() function returns
15554 * the data set size</em>
15556 getCount : function(){
15557 return this.data.length || 0;
15561 * Gets the total number of records in the dataset as returned by the server.
15563 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
15564 * the dataset size</em>
15566 getTotalCount : function(){
15567 return this.totalLength || 0;
15571 * Returns the sort state of the Store as an object with two properties:
15573 field {String} The name of the field by which the Records are sorted
15574 direction {String} The sort order, "ASC" or "DESC"
15577 getSortState : function(){
15578 return this.sortInfo;
15582 applySort : function(){
15583 if(this.sortInfo && !this.remoteSort){
15584 var s = this.sortInfo, f = s.field;
15585 var st = this.fields.get(f).sortType;
15586 var fn = function(r1, r2){
15587 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
15588 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
15590 this.data.sort(s.direction, fn);
15591 if(this.snapshot && this.snapshot != this.data){
15592 this.snapshot.sort(s.direction, fn);
15598 * Sets the default sort column and order to be used by the next load operation.
15599 * @param {String} fieldName The name of the field to sort by.
15600 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
15602 setDefaultSort : function(field, dir){
15603 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
15607 * Sort the Records.
15608 * If remote sorting is used, the sort is performed on the server, and the cache is
15609 * reloaded. If local sorting is used, the cache is sorted internally.
15610 * @param {String} fieldName The name of the field to sort by.
15611 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
15613 sort : function(fieldName, dir){
15614 var f = this.fields.get(fieldName);
15616 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
15618 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
15619 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
15624 this.sortToggle[f.name] = dir;
15625 this.sortInfo = {field: f.name, direction: dir};
15626 if(!this.remoteSort){
15628 this.fireEvent("datachanged", this);
15630 this.load(this.lastOptions);
15635 * Calls the specified function for each of the Records in the cache.
15636 * @param {Function} fn The function to call. The Record is passed as the first parameter.
15637 * Returning <em>false</em> aborts and exits the iteration.
15638 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
15640 each : function(fn, scope){
15641 this.data.each(fn, scope);
15645 * Gets all records modified since the last commit. Modified records are persisted across load operations
15646 * (e.g., during paging).
15647 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
15649 getModifiedRecords : function(){
15650 return this.modified;
15654 createFilterFn : function(property, value, anyMatch){
15655 if(!value.exec){ // not a regex
15656 value = String(value);
15657 if(value.length == 0){
15660 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
15662 return function(r){
15663 return value.test(r.data[property]);
15668 * Sums the value of <i>property</i> for each record between start and end and returns the result.
15669 * @param {String} property A field on your records
15670 * @param {Number} start The record index to start at (defaults to 0)
15671 * @param {Number} end The last record index to include (defaults to length - 1)
15672 * @return {Number} The sum
15674 sum : function(property, start, end){
15675 var rs = this.data.items, v = 0;
15676 start = start || 0;
15677 end = (end || end === 0) ? end : rs.length-1;
15679 for(var i = start; i <= end; i++){
15680 v += (rs[i].data[property] || 0);
15686 * Filter the records by a specified property.
15687 * @param {String} field A field on your records
15688 * @param {String/RegExp} value Either a string that the field
15689 * should start with or a RegExp to test against the field
15690 * @param {Boolean} anyMatch True to match any part not just the beginning
15692 filter : function(property, value, anyMatch){
15693 var fn = this.createFilterFn(property, value, anyMatch);
15694 return fn ? this.filterBy(fn) : this.clearFilter();
15698 * Filter by a function. The specified function will be called with each
15699 * record in this data source. If the function returns true the record is included,
15700 * otherwise it is filtered.
15701 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
15702 * @param {Object} scope (optional) The scope of the function (defaults to this)
15704 filterBy : function(fn, scope){
15705 this.snapshot = this.snapshot || this.data;
15706 this.data = this.queryBy(fn, scope||this);
15707 this.fireEvent("datachanged", this);
15711 * Query the records by a specified property.
15712 * @param {String} field A field on your records
15713 * @param {String/RegExp} value Either a string that the field
15714 * should start with or a RegExp to test against the field
15715 * @param {Boolean} anyMatch True to match any part not just the beginning
15716 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
15718 query : function(property, value, anyMatch){
15719 var fn = this.createFilterFn(property, value, anyMatch);
15720 return fn ? this.queryBy(fn) : this.data.clone();
15724 * Query by a function. The specified function will be called with each
15725 * record in this data source. If the function returns true the record is included
15727 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
15728 * @param {Object} scope (optional) The scope of the function (defaults to this)
15729 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
15731 queryBy : function(fn, scope){
15732 var data = this.snapshot || this.data;
15733 return data.filterBy(fn, scope||this);
15737 * Collects unique values for a particular dataIndex from this store.
15738 * @param {String} dataIndex The property to collect
15739 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
15740 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
15741 * @return {Array} An array of the unique values
15743 collect : function(dataIndex, allowNull, bypassFilter){
15744 var d = (bypassFilter === true && this.snapshot) ?
15745 this.snapshot.items : this.data.items;
15746 var v, sv, r = [], l = {};
15747 for(var i = 0, len = d.length; i < len; i++){
15748 v = d[i].data[dataIndex];
15750 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
15759 * Revert to a view of the Record cache with no filtering applied.
15760 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
15762 clearFilter : function(suppressEvent){
15763 if(this.snapshot && this.snapshot != this.data){
15764 this.data = this.snapshot;
15765 delete this.snapshot;
15766 if(suppressEvent !== true){
15767 this.fireEvent("datachanged", this);
15773 afterEdit : function(record){
15774 if(this.modified.indexOf(record) == -1){
15775 this.modified.push(record);
15777 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
15781 afterReject : function(record){
15782 this.modified.remove(record);
15783 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
15787 afterCommit : function(record){
15788 this.modified.remove(record);
15789 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
15793 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
15794 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
15796 commitChanges : function(){
15797 var m = this.modified.slice(0);
15798 this.modified = [];
15799 for(var i = 0, len = m.length; i < len; i++){
15805 * Cancel outstanding changes on all changed records.
15807 rejectChanges : function(){
15808 var m = this.modified.slice(0);
15809 this.modified = [];
15810 for(var i = 0, len = m.length; i < len; i++){
15815 onMetaChange : function(meta, rtype, o){
15816 this.recordType = rtype;
15817 this.fields = rtype.prototype.fields;
15818 delete this.snapshot;
15819 this.sortInfo = meta.sortInfo || this.sortInfo;
15820 this.modified = [];
15821 this.fireEvent('metachange', this, this.reader.meta);
15824 moveIndex : function(data, type)
15826 var index = this.indexOf(data);
15828 var newIndex = index + type;
15832 this.insert(newIndex, data);
15837 * Ext JS Library 1.1.1
15838 * Copyright(c) 2006-2007, Ext JS, LLC.
15840 * Originally Released Under LGPL - original licence link has changed is not relivant.
15843 * <script type="text/javascript">
15847 * @class Roo.data.SimpleStore
15848 * @extends Roo.data.Store
15849 * Small helper class to make creating Stores from Array data easier.
15850 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
15851 * @cfg {Array} fields An array of field definition objects, or field name strings.
15852 * @cfg {Object} an existing reader (eg. copied from another store)
15853 * @cfg {Array} data The multi-dimensional array of data
15854 * @cfg {Roo.data.DataProxy} proxy [not-required]
15855 * @cfg {Roo.data.Reader} reader [not-required]
15857 * @param {Object} config
15859 Roo.data.SimpleStore = function(config)
15861 Roo.data.SimpleStore.superclass.constructor.call(this, {
15863 reader: typeof(config.reader) != 'undefined' ? config.reader : new Roo.data.ArrayReader({
15866 Roo.data.Record.create(config.fields)
15868 proxy : new Roo.data.MemoryProxy(config.data)
15872 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
15874 * Ext JS Library 1.1.1
15875 * Copyright(c) 2006-2007, Ext JS, LLC.
15877 * Originally Released Under LGPL - original licence link has changed is not relivant.
15880 * <script type="text/javascript">
15885 * @extends Roo.data.Store
15886 * @class Roo.data.JsonStore
15887 * Small helper class to make creating Stores for JSON data easier. <br/>
15889 var store = new Roo.data.JsonStore({
15890 url: 'get-images.php',
15892 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
15895 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
15896 * JsonReader and HttpProxy (unless inline data is provided).</b>
15897 * @cfg {Array} fields An array of field definition objects, or field name strings.
15899 * @param {Object} config
15901 Roo.data.JsonStore = function(c){
15902 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
15903 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
15904 reader: new Roo.data.JsonReader(c, c.fields)
15907 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
15909 * Ext JS Library 1.1.1
15910 * Copyright(c) 2006-2007, Ext JS, LLC.
15912 * Originally Released Under LGPL - original licence link has changed is not relivant.
15915 * <script type="text/javascript">
15919 Roo.data.Field = function(config){
15920 if(typeof config == "string"){
15921 config = {name: config};
15923 Roo.apply(this, config);
15926 this.type = "auto";
15929 var st = Roo.data.SortTypes;
15930 // named sortTypes are supported, here we look them up
15931 if(typeof this.sortType == "string"){
15932 this.sortType = st[this.sortType];
15935 // set default sortType for strings and dates
15936 if(!this.sortType){
15939 this.sortType = st.asUCString;
15942 this.sortType = st.asDate;
15945 this.sortType = st.none;
15950 var stripRe = /[\$,%]/g;
15952 // prebuilt conversion function for this field, instead of
15953 // switching every time we're reading a value
15955 var cv, dateFormat = this.dateFormat;
15960 cv = function(v){ return v; };
15963 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
15967 return v !== undefined && v !== null && v !== '' ?
15968 parseInt(String(v).replace(stripRe, ""), 10) : '';
15973 return v !== undefined && v !== null && v !== '' ?
15974 parseFloat(String(v).replace(stripRe, ""), 10) : '';
15979 cv = function(v){ return v === true || v === "true" || v == 1; };
15986 if(v instanceof Date){
15990 if(dateFormat == "timestamp"){
15991 return new Date(v*1000);
15993 return Date.parseDate(v, dateFormat);
15995 var parsed = Date.parse(v);
15996 return parsed ? new Date(parsed) : null;
16005 Roo.data.Field.prototype = {
16013 * Ext JS Library 1.1.1
16014 * Copyright(c) 2006-2007, Ext JS, LLC.
16016 * Originally Released Under LGPL - original licence link has changed is not relivant.
16019 * <script type="text/javascript">
16022 // Base class for reading structured data from a data source. This class is intended to be
16023 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
16026 * @class Roo.data.DataReader
16028 * Base class for reading structured data from a data source. This class is intended to be
16029 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
16032 Roo.data.DataReader = function(meta, recordType){
16036 this.recordType = recordType instanceof Array ?
16037 Roo.data.Record.create(recordType) : recordType;
16040 Roo.data.DataReader.prototype = {
16043 readerType : 'Data',
16045 * Create an empty record
16046 * @param {Object} data (optional) - overlay some values
16047 * @return {Roo.data.Record} record created.
16049 newRow : function(d) {
16051 this.recordType.prototype.fields.each(function(c) {
16053 case 'int' : da[c.name] = 0; break;
16054 case 'date' : da[c.name] = new Date(); break;
16055 case 'float' : da[c.name] = 0.0; break;
16056 case 'boolean' : da[c.name] = false; break;
16057 default : da[c.name] = ""; break;
16061 return new this.recordType(Roo.apply(da, d));
16067 * Ext JS Library 1.1.1
16068 * Copyright(c) 2006-2007, Ext JS, LLC.
16070 * Originally Released Under LGPL - original licence link has changed is not relivant.
16073 * <script type="text/javascript">
16077 * @class Roo.data.DataProxy
16078 * @extends Roo.util.Observable
16080 * This class is an abstract base class for implementations which provide retrieval of
16081 * unformatted data objects.<br>
16083 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
16084 * (of the appropriate type which knows how to parse the data object) to provide a block of
16085 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
16087 * Custom implementations must implement the load method as described in
16088 * {@link Roo.data.HttpProxy#load}.
16090 Roo.data.DataProxy = function(){
16093 * @event beforeload
16094 * Fires before a network request is made to retrieve a data object.
16095 * @param {Object} This DataProxy object.
16096 * @param {Object} params The params parameter to the load function.
16101 * Fires before the load method's callback is called.
16102 * @param {Object} This DataProxy object.
16103 * @param {Object} o The data object.
16104 * @param {Object} arg The callback argument object passed to the load function.
16108 * @event loadexception
16109 * Fires if an Exception occurs during data retrieval.
16110 * @param {Object} This DataProxy object.
16111 * @param {Object} o The data object.
16112 * @param {Object} arg The callback argument object passed to the load function.
16113 * @param {Object} e The Exception.
16115 loadexception : true
16117 Roo.data.DataProxy.superclass.constructor.call(this);
16120 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
16123 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
16127 * Ext JS Library 1.1.1
16128 * Copyright(c) 2006-2007, Ext JS, LLC.
16130 * Originally Released Under LGPL - original licence link has changed is not relivant.
16133 * <script type="text/javascript">
16136 * @class Roo.data.MemoryProxy
16137 * @extends Roo.data.DataProxy
16138 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
16139 * to the Reader when its load method is called.
16141 * @param {Object} config A config object containing the objects needed for the Store to access data,
16143 Roo.data.MemoryProxy = function(config){
16145 if (typeof(config) != 'undefined' && typeof(config.data) != 'undefined') {
16146 data = config.data;
16148 Roo.data.MemoryProxy.superclass.constructor.call(this);
16152 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
16155 * @cfg {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
16158 * Load data from the requested source (in this case an in-memory
16159 * data object passed to the constructor), read the data object into
16160 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
16161 * process that block using the passed callback.
16162 * @param {Object} params This parameter is not used by the MemoryProxy class.
16163 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16164 * object into a block of Roo.data.Records.
16165 * @param {Function} callback The function into which to pass the block of Roo.data.records.
16166 * The function must be passed <ul>
16167 * <li>The Record block object</li>
16168 * <li>The "arg" argument from the load function</li>
16169 * <li>A boolean success indicator</li>
16171 * @param {Object} scope The scope in which to call the callback
16172 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16174 load : function(params, reader, callback, scope, arg){
16175 params = params || {};
16178 result = reader.readRecords(params.data ? params.data :this.data);
16180 this.fireEvent("loadexception", this, arg, null, e);
16181 callback.call(scope, null, arg, false);
16184 callback.call(scope, result, arg, true);
16188 update : function(params, records){
16193 * Ext JS Library 1.1.1
16194 * Copyright(c) 2006-2007, Ext JS, LLC.
16196 * Originally Released Under LGPL - original licence link has changed is not relivant.
16199 * <script type="text/javascript">
16202 * @class Roo.data.HttpProxy
16203 * @extends Roo.data.DataProxy
16204 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
16205 * configured to reference a certain URL.<br><br>
16207 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
16208 * from which the running page was served.<br><br>
16210 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
16212 * Be aware that to enable the browser to parse an XML document, the server must set
16213 * the Content-Type header in the HTTP response to "text/xml".
16215 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
16216 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
16217 * will be used to make the request.
16219 Roo.data.HttpProxy = function(conn){
16220 Roo.data.HttpProxy.superclass.constructor.call(this);
16221 // is conn a conn config or a real conn?
16223 this.useAjax = !conn || !conn.events;
16227 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
16228 // thse are take from connection...
16231 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
16234 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
16235 * extra parameters to each request made by this object. (defaults to undefined)
16238 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
16239 * to each request made by this object. (defaults to undefined)
16242 * @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)
16245 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
16248 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
16254 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
16258 * Return the {@link Roo.data.Connection} object being used by this Proxy.
16259 * @return {Connection} The Connection object. This object may be used to subscribe to events on
16260 * a finer-grained basis than the DataProxy events.
16262 getConnection : function(){
16263 return this.useAjax ? Roo.Ajax : this.conn;
16267 * Load data from the configured {@link Roo.data.Connection}, read the data object into
16268 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
16269 * process that block using the passed callback.
16270 * @param {Object} params An object containing properties which are to be used as HTTP parameters
16271 * for the request to the remote server.
16272 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16273 * object into a block of Roo.data.Records.
16274 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
16275 * The function must be passed <ul>
16276 * <li>The Record block object</li>
16277 * <li>The "arg" argument from the load function</li>
16278 * <li>A boolean success indicator</li>
16280 * @param {Object} scope The scope in which to call the callback
16281 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16283 load : function(params, reader, callback, scope, arg){
16284 if(this.fireEvent("beforeload", this, params) !== false){
16286 params : params || {},
16288 callback : callback,
16293 callback : this.loadResponse,
16297 Roo.applyIf(o, this.conn);
16298 if(this.activeRequest){
16299 Roo.Ajax.abort(this.activeRequest);
16301 this.activeRequest = Roo.Ajax.request(o);
16303 this.conn.request(o);
16306 callback.call(scope||this, null, arg, false);
16311 loadResponse : function(o, success, response){
16312 delete this.activeRequest;
16314 this.fireEvent("loadexception", this, o, response);
16315 o.request.callback.call(o.request.scope, null, o.request.arg, false);
16320 result = o.reader.read(response);
16323 o.raw = { errorMsg : response.responseText };
16324 this.fireEvent("loadexception", this, o, response, e);
16325 o.request.callback.call(o.request.scope, o, o.request.arg, false);
16329 this.fireEvent("load", this, o, o.request.arg);
16330 o.request.callback.call(o.request.scope, result, o.request.arg, true);
16334 update : function(dataSet){
16339 updateResponse : function(dataSet){
16344 * Ext JS Library 1.1.1
16345 * Copyright(c) 2006-2007, Ext JS, LLC.
16347 * Originally Released Under LGPL - original licence link has changed is not relivant.
16350 * <script type="text/javascript">
16354 * @class Roo.data.ScriptTagProxy
16355 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
16356 * other than the originating domain of the running page.<br><br>
16358 * <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
16359 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
16361 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
16362 * source code that is used as the source inside a <script> tag.<br><br>
16364 * In order for the browser to process the returned data, the server must wrap the data object
16365 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
16366 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
16367 * depending on whether the callback name was passed:
16370 boolean scriptTag = false;
16371 String cb = request.getParameter("callback");
16374 response.setContentType("text/javascript");
16376 response.setContentType("application/x-json");
16378 Writer out = response.getWriter();
16380 out.write(cb + "(");
16382 out.print(dataBlock.toJsonString());
16389 * @param {Object} config A configuration object.
16391 Roo.data.ScriptTagProxy = function(config){
16392 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
16393 Roo.apply(this, config);
16394 this.head = document.getElementsByTagName("head")[0];
16397 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
16399 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
16401 * @cfg {String} url The URL from which to request the data object.
16404 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
16408 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
16409 * the server the name of the callback function set up by the load call to process the returned data object.
16410 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
16411 * javascript output which calls this named function passing the data object as its only parameter.
16413 callbackParam : "callback",
16415 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
16416 * name to the request.
16421 * Load data from the configured URL, read the data object into
16422 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
16423 * process that block using the passed callback.
16424 * @param {Object} params An object containing properties which are to be used as HTTP parameters
16425 * for the request to the remote server.
16426 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16427 * object into a block of Roo.data.Records.
16428 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
16429 * The function must be passed <ul>
16430 * <li>The Record block object</li>
16431 * <li>The "arg" argument from the load function</li>
16432 * <li>A boolean success indicator</li>
16434 * @param {Object} scope The scope in which to call the callback
16435 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16437 load : function(params, reader, callback, scope, arg){
16438 if(this.fireEvent("beforeload", this, params) !== false){
16440 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
16442 var url = this.url;
16443 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
16445 url += "&_dc=" + (new Date().getTime());
16447 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
16450 cb : "stcCallback"+transId,
16451 scriptId : "stcScript"+transId,
16455 callback : callback,
16461 window[trans.cb] = function(o){
16462 conn.handleResponse(o, trans);
16465 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
16467 if(this.autoAbort !== false){
16471 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
16473 var script = document.createElement("script");
16474 script.setAttribute("src", url);
16475 script.setAttribute("type", "text/javascript");
16476 script.setAttribute("id", trans.scriptId);
16477 this.head.appendChild(script);
16479 this.trans = trans;
16481 callback.call(scope||this, null, arg, false);
16486 isLoading : function(){
16487 return this.trans ? true : false;
16491 * Abort the current server request.
16493 abort : function(){
16494 if(this.isLoading()){
16495 this.destroyTrans(this.trans);
16500 destroyTrans : function(trans, isLoaded){
16501 this.head.removeChild(document.getElementById(trans.scriptId));
16502 clearTimeout(trans.timeoutId);
16504 window[trans.cb] = undefined;
16506 delete window[trans.cb];
16509 // if hasn't been loaded, wait for load to remove it to prevent script error
16510 window[trans.cb] = function(){
16511 window[trans.cb] = undefined;
16513 delete window[trans.cb];
16520 handleResponse : function(o, trans){
16521 this.trans = false;
16522 this.destroyTrans(trans, true);
16525 result = trans.reader.readRecords(o);
16527 this.fireEvent("loadexception", this, o, trans.arg, e);
16528 trans.callback.call(trans.scope||window, null, trans.arg, false);
16531 this.fireEvent("load", this, o, trans.arg);
16532 trans.callback.call(trans.scope||window, result, trans.arg, true);
16536 handleFailure : function(trans){
16537 this.trans = false;
16538 this.destroyTrans(trans, false);
16539 this.fireEvent("loadexception", this, null, trans.arg);
16540 trans.callback.call(trans.scope||window, null, trans.arg, false);
16544 * Ext JS Library 1.1.1
16545 * Copyright(c) 2006-2007, Ext JS, LLC.
16547 * Originally Released Under LGPL - original licence link has changed is not relivant.
16550 * <script type="text/javascript">
16554 * @class Roo.data.JsonReader
16555 * @extends Roo.data.DataReader
16556 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
16557 * based on mappings in a provided Roo.data.Record constructor.
16559 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
16560 * in the reply previously.
16565 var RecordDef = Roo.data.Record.create([
16566 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
16567 {name: 'occupation'} // This field will use "occupation" as the mapping.
16569 var myReader = new Roo.data.JsonReader({
16570 totalProperty: "results", // The property which contains the total dataset size (optional)
16571 root: "rows", // The property which contains an Array of row objects
16572 id: "id" // The property within each row object that provides an ID for the record (optional)
16576 * This would consume a JSON file like this:
16578 { 'results': 2, 'rows': [
16579 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
16580 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
16583 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
16584 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
16585 * paged from the remote server.
16586 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
16587 * @cfg {String} root name of the property which contains the Array of row objects.
16588 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
16589 * @cfg {Array} fields Array of field definition objects
16591 * Create a new JsonReader
16592 * @param {Object} meta Metadata configuration options
16593 * @param {Object} recordType Either an Array of field definition objects,
16594 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
16596 Roo.data.JsonReader = function(meta, recordType){
16599 // set some defaults:
16600 Roo.applyIf(meta, {
16601 totalProperty: 'total',
16602 successProperty : 'success',
16607 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
16609 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
16611 readerType : 'Json',
16614 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
16615 * Used by Store query builder to append _requestMeta to params.
16618 metaFromRemote : false,
16620 * This method is only used by a DataProxy which has retrieved data from a remote server.
16621 * @param {Object} response The XHR object which contains the JSON data in its responseText.
16622 * @return {Object} data A data block which is used by an Roo.data.Store object as
16623 * a cache of Roo.data.Records.
16625 read : function(response){
16626 var json = response.responseText;
16628 var o = /* eval:var:o */ eval("("+json+")");
16630 throw {message: "JsonReader.read: Json object not found"};
16636 this.metaFromRemote = true;
16637 this.meta = o.metaData;
16638 this.recordType = Roo.data.Record.create(o.metaData.fields);
16639 this.onMetaChange(this.meta, this.recordType, o);
16641 return this.readRecords(o);
16644 // private function a store will implement
16645 onMetaChange : function(meta, recordType, o){
16652 simpleAccess: function(obj, subsc) {
16659 getJsonAccessor: function(){
16661 return function(expr) {
16663 return(re.test(expr))
16664 ? new Function("obj", "return obj." + expr)
16669 return Roo.emptyFn;
16674 * Create a data block containing Roo.data.Records from an XML document.
16675 * @param {Object} o An object which contains an Array of row objects in the property specified
16676 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
16677 * which contains the total size of the dataset.
16678 * @return {Object} data A data block which is used by an Roo.data.Store object as
16679 * a cache of Roo.data.Records.
16681 readRecords : function(o){
16683 * After any data loads, the raw JSON data is available for further custom processing.
16687 var s = this.meta, Record = this.recordType,
16688 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
16690 // Generate extraction functions for the totalProperty, the root, the id, and for each field
16692 if(s.totalProperty) {
16693 this.getTotal = this.getJsonAccessor(s.totalProperty);
16695 if(s.successProperty) {
16696 this.getSuccess = this.getJsonAccessor(s.successProperty);
16698 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
16700 var g = this.getJsonAccessor(s.id);
16701 this.getId = function(rec) {
16703 return (r === undefined || r === "") ? null : r;
16706 this.getId = function(){return null;};
16709 for(var jj = 0; jj < fl; jj++){
16711 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
16712 this.ef[jj] = this.getJsonAccessor(map);
16716 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
16717 if(s.totalProperty){
16718 var vt = parseInt(this.getTotal(o), 10);
16723 if(s.successProperty){
16724 var vs = this.getSuccess(o);
16725 if(vs === false || vs === 'false'){
16730 for(var i = 0; i < c; i++){
16733 var id = this.getId(n);
16734 for(var j = 0; j < fl; j++){
16736 var v = this.ef[j](n);
16738 Roo.log('missing convert for ' + f.name);
16742 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
16746 raw : { errorMsg : "JSON Reader Error: fields or metadata not available to create Record" },
16752 var record = new Record(values, id);
16754 records[i] = record;
16760 totalRecords : totalRecords
16763 // used when loading children.. @see loadDataFromChildren
16764 toLoadData: function(rec)
16766 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
16767 var data = typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
16768 return { data : data, total : data.length };
16773 * Ext JS Library 1.1.1
16774 * Copyright(c) 2006-2007, Ext JS, LLC.
16776 * Originally Released Under LGPL - original licence link has changed is not relivant.
16779 * <script type="text/javascript">
16783 * @class Roo.data.ArrayReader
16784 * @extends Roo.data.DataReader
16785 * Data reader class to create an Array of Roo.data.Record objects from an Array.
16786 * Each element of that Array represents a row of data fields. The
16787 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
16788 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
16792 var RecordDef = Roo.data.Record.create([
16793 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
16794 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
16796 var myReader = new Roo.data.ArrayReader({
16797 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
16801 * This would consume an Array like this:
16803 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
16807 * Create a new JsonReader
16808 * @param {Object} meta Metadata configuration options.
16809 * @param {Object|Array} recordType Either an Array of field definition objects
16811 * @cfg {Array} fields Array of field definition objects
16812 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
16813 * as specified to {@link Roo.data.Record#create},
16814 * or an {@link Roo.data.Record} object
16817 * created using {@link Roo.data.Record#create}.
16819 Roo.data.ArrayReader = function(meta, recordType)
16821 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType||meta.fields);
16824 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
16827 * Create a data block containing Roo.data.Records from an XML document.
16828 * @param {Object} o An Array of row objects which represents the dataset.
16829 * @return {Object} A data block which is used by an {@link Roo.data.Store} object as
16830 * a cache of Roo.data.Records.
16832 readRecords : function(o)
16834 var sid = this.meta ? this.meta.id : null;
16835 var recordType = this.recordType, fields = recordType.prototype.fields;
16838 for(var i = 0; i < root.length; i++){
16841 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
16842 for(var j = 0, jlen = fields.length; j < jlen; j++){
16843 var f = fields.items[j];
16844 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
16845 var v = n[k] !== undefined ? n[k] : f.defaultValue;
16847 values[f.name] = v;
16849 var record = new recordType(values, id);
16851 records[records.length] = record;
16855 totalRecords : records.length
16858 // used when loading children.. @see loadDataFromChildren
16859 toLoadData: function(rec)
16861 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
16862 return typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
16873 * @class Roo.bootstrap.form.ComboBox
16874 * @extends Roo.bootstrap.form.TriggerField
16875 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
16876 * @cfg {Boolean} append (true|false) default false
16877 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
16878 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
16879 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
16880 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
16881 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16882 * @cfg {Boolean} animate default true
16883 * @cfg {Boolean} emptyResultText only for touch device
16884 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
16885 * @cfg {String} emptyTitle default ''
16886 * @cfg {Number} width fixed with? experimental
16888 * Create a new ComboBox.
16889 * @param {Object} config Configuration options
16891 Roo.bootstrap.form.ComboBox = function(config){
16892 Roo.bootstrap.form.ComboBox.superclass.constructor.call(this, config);
16896 * Fires when the dropdown list is expanded
16897 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16902 * Fires when the dropdown list is collapsed
16903 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16907 * @event beforeselect
16908 * Fires before a list item is selected. Return false to cancel the selection.
16909 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16910 * @param {Roo.data.Record} record The data record returned from the underlying store
16911 * @param {Number} index The index of the selected item in the dropdown list
16913 'beforeselect' : true,
16916 * Fires when a list item is selected
16917 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16918 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
16919 * @param {Number} index The index of the selected item in the dropdown list
16923 * @event beforequery
16924 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
16925 * The event object passed has these properties:
16926 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16927 * @param {String} query The query
16928 * @param {Boolean} forceAll true to force "all" query
16929 * @param {Boolean} cancel true to cancel the query
16930 * @param {Object} e The query event object
16932 'beforequery': true,
16935 * Fires when the 'add' icon is pressed (add a listener to enable add button)
16936 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16941 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
16942 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16943 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
16948 * Fires when the remove value from the combobox array
16949 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16953 * @event afterremove
16954 * Fires when the remove value from the combobox array
16955 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16957 'afterremove' : true,
16959 * @event specialfilter
16960 * Fires when specialfilter
16961 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16963 'specialfilter' : true,
16966 * Fires when tick the element
16967 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16971 * @event touchviewdisplay
16972 * Fires when touch view require special display (default is using displayField)
16973 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16974 * @param {Object} cfg set html .
16976 'touchviewdisplay' : true
16981 this.tickItems = [];
16983 this.selectedIndex = -1;
16984 if(this.mode == 'local'){
16985 if(config.queryDelay === undefined){
16986 this.queryDelay = 10;
16988 if(config.minChars === undefined){
16994 Roo.extend(Roo.bootstrap.form.ComboBox, Roo.bootstrap.form.TriggerField, {
16997 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
16998 * rendering into an Roo.Editor, defaults to false)
17001 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
17002 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
17005 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
17008 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
17009 * the dropdown list (defaults to undefined, with no header element)
17013 * @cfg {String/Roo.Template} tpl The template to use to render the output default is '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>'
17017 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
17019 listWidth: undefined,
17021 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
17022 * mode = 'remote' or 'text' if mode = 'local')
17024 displayField: undefined,
17027 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
17028 * mode = 'remote' or 'value' if mode = 'local').
17029 * Note: use of a valueField requires the user make a selection
17030 * in order for a value to be mapped.
17032 valueField: undefined,
17034 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
17039 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
17040 * field's data value (defaults to the underlying DOM element's name)
17042 hiddenName: undefined,
17044 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
17048 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
17050 selectedClass: 'active',
17053 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
17057 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
17058 * anchor positions (defaults to 'tl-bl')
17060 listAlign: 'tl-bl?',
17062 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
17066 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
17067 * query specified by the allQuery config option (defaults to 'query')
17069 triggerAction: 'query',
17071 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
17072 * (defaults to 4, does not apply if editable = false)
17076 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
17077 * delay (typeAheadDelay) if it matches a known value (defaults to false)
17081 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
17082 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
17086 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
17087 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
17091 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
17092 * when editable = true (defaults to false)
17094 selectOnFocus:false,
17096 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
17098 queryParam: 'query',
17100 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
17101 * when mode = 'remote' (defaults to 'Loading...')
17103 loadingText: 'Loading...',
17105 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
17109 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
17113 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
17114 * traditional select (defaults to true)
17118 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
17122 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
17126 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
17127 * listWidth has a higher value)
17131 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
17132 * allow the user to set arbitrary text into the field (defaults to false)
17134 forceSelection:false,
17136 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
17137 * if typeAhead = true (defaults to 250)
17139 typeAheadDelay : 250,
17141 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
17142 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
17144 valueNotFoundText : undefined,
17146 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
17148 blockFocus : false,
17151 * @cfg {Boolean} disableClear Disable showing of clear button.
17153 disableClear : false,
17155 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
17157 alwaysQuery : false,
17160 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
17165 * @cfg {String} invalidClass DEPRICATED - uses BS4 is-valid now
17167 invalidClass : "has-warning",
17170 * @cfg {String} validClass DEPRICATED - uses BS4 is-valid now
17172 validClass : "has-success",
17175 * @cfg {Boolean} specialFilter (true|false) special filter default false
17177 specialFilter : false,
17180 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
17182 mobileTouchView : true,
17185 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
17187 useNativeIOS : false,
17190 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
17192 mobile_restrict_height : false,
17194 ios_options : false,
17206 btnPosition : 'right',
17207 triggerList : true,
17208 showToggleBtn : true,
17210 emptyResultText: 'Empty',
17211 triggerText : 'Select',
17215 // element that contains real text value.. (when hidden is used..)
17217 getAutoCreate : function()
17222 * Render classic select for iso
17225 if(Roo.isIOS && this.useNativeIOS){
17226 cfg = this.getAutoCreateNativeIOS();
17234 if(Roo.isTouch && this.mobileTouchView){
17235 cfg = this.getAutoCreateTouchView();
17242 if(!this.tickable){
17243 cfg = Roo.bootstrap.form.ComboBox.superclass.getAutoCreate.call(this);
17248 * ComboBox with tickable selections
17251 var align = this.labelAlign || this.parentLabelAlign();
17254 cls : 'form-group roo-combobox-tickable' //input-group
17257 var btn_text_select = '';
17258 var btn_text_done = '';
17259 var btn_text_cancel = '';
17261 if (this.btn_text_show) {
17262 btn_text_select = 'Select';
17263 btn_text_done = 'Done';
17264 btn_text_cancel = 'Cancel';
17269 cls : 'tickable-buttons',
17274 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
17275 //html : this.triggerText
17276 html: btn_text_select
17282 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
17284 html: btn_text_done
17290 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
17292 html: btn_text_cancel
17298 buttons.cn.unshift({
17300 cls: 'roo-select2-search-field-input'
17306 Roo.each(buttons.cn, function(c){
17308 c.cls += ' btn-' + _this.size;
17311 if (_this.disabled) {
17318 style : 'display: contents',
17323 cls: 'form-hidden-field'
17327 cls: 'roo-select2-choices',
17331 cls: 'roo-select2-search-field',
17342 cls: 'roo-select2-container input-group roo-select2-container-multi',
17348 // cls: 'typeahead typeahead-long dropdown-menu',
17349 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
17354 if(this.hasFeedback && !this.allowBlank){
17358 cls: 'glyphicon form-control-feedback'
17361 combobox.cn.push(feedback);
17368 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
17369 tooltip : 'This field is required'
17371 if (Roo.bootstrap.version == 4) {
17374 style : 'display:none'
17377 if (align ==='left' && this.fieldLabel.length) {
17379 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
17386 cls : 'control-label col-form-label',
17387 html : this.fieldLabel
17399 var labelCfg = cfg.cn[1];
17400 var contentCfg = cfg.cn[2];
17403 if(this.indicatorpos == 'right'){
17409 cls : 'control-label col-form-label',
17413 html : this.fieldLabel
17429 labelCfg = cfg.cn[0];
17430 contentCfg = cfg.cn[1];
17434 if(this.labelWidth > 12){
17435 labelCfg.style = "width: " + this.labelWidth + 'px';
17437 if(this.width * 1 > 0){
17438 contentCfg.style = "width: " + this.width + 'px';
17440 if(this.labelWidth < 13 && this.labelmd == 0){
17441 this.labelmd = this.labelWidth;
17444 if(this.labellg > 0){
17445 labelCfg.cls += ' col-lg-' + this.labellg;
17446 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
17449 if(this.labelmd > 0){
17450 labelCfg.cls += ' col-md-' + this.labelmd;
17451 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
17454 if(this.labelsm > 0){
17455 labelCfg.cls += ' col-sm-' + this.labelsm;
17456 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
17459 if(this.labelxs > 0){
17460 labelCfg.cls += ' col-xs-' + this.labelxs;
17461 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
17465 } else if ( this.fieldLabel.length) {
17466 // Roo.log(" label");
17471 //cls : 'input-group-addon',
17472 html : this.fieldLabel
17477 if(this.indicatorpos == 'right'){
17481 //cls : 'input-group-addon',
17482 html : this.fieldLabel
17492 // Roo.log(" no label && no align");
17499 ['xs','sm','md','lg'].map(function(size){
17500 if (settings[size]) {
17501 cfg.cls += ' col-' + size + '-' + settings[size];
17509 _initEventsCalled : false,
17512 initEvents: function()
17514 if (this._initEventsCalled) { // as we call render... prevent looping...
17517 this._initEventsCalled = true;
17520 throw "can not find store for combo";
17523 this.indicator = this.indicatorEl();
17525 this.store = Roo.factory(this.store, Roo.data);
17526 this.store.parent = this;
17528 // if we are building from html. then this element is so complex, that we can not really
17529 // use the rendered HTML.
17530 // so we have to trash and replace the previous code.
17531 if (Roo.XComponent.build_from_html) {
17532 // remove this element....
17533 var e = this.el.dom, k=0;
17534 while (e ) { e = e.previousSibling; ++k;}
17539 this.rendered = false;
17541 this.render(this.parent().getChildContainer(true), k);
17544 if(Roo.isIOS && this.useNativeIOS){
17545 this.initIOSView();
17553 if(Roo.isTouch && this.mobileTouchView){
17554 this.initTouchView();
17559 this.initTickableEvents();
17563 Roo.bootstrap.form.ComboBox.superclass.initEvents.call(this);
17565 if(this.hiddenName){
17567 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
17569 this.hiddenField.dom.value =
17570 this.hiddenValue !== undefined ? this.hiddenValue :
17571 this.value !== undefined ? this.value : '';
17573 // prevent input submission
17574 this.el.dom.removeAttribute('name');
17575 this.hiddenField.dom.setAttribute('name', this.hiddenName);
17580 // this.el.dom.setAttribute('autocomplete', 'off');
17583 var cls = 'x-combo-list';
17585 //this.list = new Roo.Layer({
17586 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
17592 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
17593 _this.list.setWidth(lw);
17596 this.list.on('mouseover', this.onViewOver, this);
17597 this.list.on('mousemove', this.onViewMove, this);
17598 this.list.on('scroll', this.onViewScroll, this);
17601 this.list.swallowEvent('mousewheel');
17602 this.assetHeight = 0;
17605 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
17606 this.assetHeight += this.header.getHeight();
17609 this.innerList = this.list.createChild({cls:cls+'-inner'});
17610 this.innerList.on('mouseover', this.onViewOver, this);
17611 this.innerList.on('mousemove', this.onViewMove, this);
17612 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
17614 if(this.allowBlank && !this.pageSize && !this.disableClear){
17615 this.footer = this.list.createChild({cls:cls+'-ft'});
17616 this.pageTb = new Roo.Toolbar(this.footer);
17620 this.footer = this.list.createChild({cls:cls+'-ft'});
17621 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
17622 {pageSize: this.pageSize});
17626 if (this.pageTb && this.allowBlank && !this.disableClear) {
17628 this.pageTb.add(new Roo.Toolbar.Fill(), {
17629 cls: 'x-btn-icon x-btn-clear',
17631 handler: function()
17634 _this.clearValue();
17635 _this.onSelect(false, -1);
17640 this.assetHeight += this.footer.getHeight();
17645 this.tpl = Roo.bootstrap.version == 4 ?
17646 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
17647 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
17650 this.view = new Roo.View(this.list, this.tpl, {
17651 singleSelect:true, store: this.store, selectedClass: this.selectedClass
17653 //this.view.wrapEl.setDisplayed(false);
17654 this.view.on('click', this.onViewClick, this);
17657 this.store.on('beforeload', this.onBeforeLoad, this);
17658 this.store.on('load', this.onLoad, this);
17659 this.store.on('loadexception', this.onLoadException, this);
17661 if(this.resizable){
17662 this.resizer = new Roo.Resizable(this.list, {
17663 pinned:true, handles:'se'
17665 this.resizer.on('resize', function(r, w, h){
17666 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
17667 this.listWidth = w;
17668 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
17669 this.restrictHeight();
17671 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
17674 if(!this.editable){
17675 this.editable = true;
17676 this.setEditable(false);
17681 if (typeof(this.events.add.listeners) != 'undefined') {
17683 this.addicon = this.wrap.createChild(
17684 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
17686 this.addicon.on('click', function(e) {
17687 this.fireEvent('add', this);
17690 if (typeof(this.events.edit.listeners) != 'undefined') {
17692 this.editicon = this.wrap.createChild(
17693 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
17694 if (this.addicon) {
17695 this.editicon.setStyle('margin-left', '40px');
17697 this.editicon.on('click', function(e) {
17699 // we fire even if inothing is selected..
17700 this.fireEvent('edit', this, this.lastData );
17706 this.keyNav = new Roo.KeyNav(this.inputEl(), {
17707 "up" : function(e){
17708 this.inKeyMode = true;
17712 "down" : function(e){
17713 if(!this.isExpanded()){
17714 this.onTriggerClick();
17716 this.inKeyMode = true;
17721 "enter" : function(e){
17722 // this.onViewClick();
17726 if(this.fireEvent("specialkey", this, e)){
17727 this.onViewClick(false);
17733 "esc" : function(e){
17737 "tab" : function(e){
17740 if(this.fireEvent("specialkey", this, e)){
17741 this.onViewClick(false);
17749 doRelay : function(foo, bar, hname){
17750 if(hname == 'down' || this.scope.isExpanded()){
17751 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
17760 this.queryDelay = Math.max(this.queryDelay || 10,
17761 this.mode == 'local' ? 10 : 250);
17764 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
17766 if(this.typeAhead){
17767 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
17769 if(this.editable !== false){
17770 this.inputEl().on("keyup", this.onKeyUp, this);
17772 if(this.forceSelection){
17773 this.inputEl().on('blur', this.doForce, this);
17777 this.choices = this.el.select('ul.roo-select2-choices', true).first();
17778 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
17782 initTickableEvents: function()
17786 if(this.hiddenName){
17788 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
17790 this.hiddenField.dom.value =
17791 this.hiddenValue !== undefined ? this.hiddenValue :
17792 this.value !== undefined ? this.value : '';
17794 // prevent input submission
17795 this.el.dom.removeAttribute('name');
17796 this.hiddenField.dom.setAttribute('name', this.hiddenName);
17801 // this.list = this.el.select('ul.dropdown-menu',true).first();
17803 this.choices = this.el.select('ul.roo-select2-choices', true).first();
17804 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
17805 if(this.triggerList){
17806 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
17809 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
17810 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
17812 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
17813 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
17815 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
17816 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
17818 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
17819 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
17820 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
17823 this.cancelBtn.hide();
17828 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
17829 _this.list.setWidth(lw);
17832 this.list.on('mouseover', this.onViewOver, this);
17833 this.list.on('mousemove', this.onViewMove, this);
17835 this.list.on('scroll', this.onViewScroll, this);
17838 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
17839 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
17842 this.view = new Roo.View(this.list, this.tpl, {
17847 selectedClass: this.selectedClass
17850 //this.view.wrapEl.setDisplayed(false);
17851 this.view.on('click', this.onViewClick, this);
17855 this.store.on('beforeload', this.onBeforeLoad, this);
17856 this.store.on('load', this.onLoad, this);
17857 this.store.on('loadexception', this.onLoadException, this);
17860 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
17861 "up" : function(e){
17862 this.inKeyMode = true;
17866 "down" : function(e){
17867 this.inKeyMode = true;
17871 "enter" : function(e){
17872 if(this.fireEvent("specialkey", this, e)){
17873 this.onViewClick(false);
17879 "esc" : function(e){
17880 this.onTickableFooterButtonClick(e, false, false);
17883 "tab" : function(e){
17884 this.fireEvent("specialkey", this, e);
17886 this.onTickableFooterButtonClick(e, false, false);
17893 doRelay : function(e, fn, key){
17894 if(this.scope.isExpanded()){
17895 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
17904 this.queryDelay = Math.max(this.queryDelay || 10,
17905 this.mode == 'local' ? 10 : 250);
17908 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
17910 if(this.typeAhead){
17911 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
17914 if(this.editable !== false){
17915 this.tickableInputEl().on("keyup", this.onKeyUp, this);
17918 this.indicator = this.indicatorEl();
17920 if(this.indicator){
17921 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
17922 this.indicator.hide();
17927 onDestroy : function(){
17929 this.view.setStore(null);
17930 this.view.el.removeAllListeners();
17931 this.view.el.remove();
17932 this.view.purgeListeners();
17935 this.list.dom.innerHTML = '';
17939 this.store.un('beforeload', this.onBeforeLoad, this);
17940 this.store.un('load', this.onLoad, this);
17941 this.store.un('loadexception', this.onLoadException, this);
17943 Roo.bootstrap.form.ComboBox.superclass.onDestroy.call(this);
17947 fireKey : function(e){
17948 if(e.isNavKeyPress() && !this.list.isVisible()){
17949 this.fireEvent("specialkey", this, e);
17954 onResize: function(w, h)
17958 // Roo.bootstrap.form.ComboBox.superclass.onResize.apply(this, arguments);
17960 // if(typeof w != 'number'){
17961 // // we do not handle it!?!?
17964 // var tw = this.trigger.getWidth();
17965 // // tw += this.addicon ? this.addicon.getWidth() : 0;
17966 // // tw += this.editicon ? this.editicon.getWidth() : 0;
17968 // this.inputEl().setWidth( this.adjustWidth('input', x));
17970 // //this.trigger.setStyle('left', x+'px');
17972 // if(this.list && this.listWidth === undefined){
17973 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
17974 // this.list.setWidth(lw);
17975 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
17983 * Allow or prevent the user from directly editing the field text. If false is passed,
17984 * the user will only be able to select from the items defined in the dropdown list. This method
17985 * is the runtime equivalent of setting the 'editable' config option at config time.
17986 * @param {Boolean} value True to allow the user to directly edit the field text
17988 setEditable : function(value){
17989 if(value == this.editable){
17992 this.editable = value;
17994 this.inputEl().dom.setAttribute('readOnly', true);
17995 this.inputEl().on('mousedown', this.onTriggerClick, this);
17996 this.inputEl().addClass('x-combo-noedit');
17998 this.inputEl().dom.removeAttribute('readOnly');
17999 this.inputEl().un('mousedown', this.onTriggerClick, this);
18000 this.inputEl().removeClass('x-combo-noedit');
18006 onBeforeLoad : function(combo,opts){
18007 if(!this.hasFocus){
18011 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
18013 this.restrictHeight();
18014 this.selectedIndex = -1;
18018 onLoad : function(){
18020 this.hasQuery = false;
18022 if(!this.hasFocus){
18026 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
18027 this.loading.hide();
18030 if(this.store.getCount() > 0){
18033 this.restrictHeight();
18034 if(this.lastQuery == this.allQuery){
18035 if(this.editable && !this.tickable){
18036 this.inputEl().dom.select();
18040 !this.selectByValue(this.value, true) &&
18043 !this.store.lastOptions ||
18044 typeof(this.store.lastOptions.add) == 'undefined' ||
18045 this.store.lastOptions.add != true
18048 this.select(0, true);
18051 if(this.autoFocus){
18054 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
18055 this.taTask.delay(this.typeAheadDelay);
18059 this.onEmptyResults();
18065 onLoadException : function()
18067 this.hasQuery = false;
18069 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
18070 this.loading.hide();
18073 if(this.tickable && this.editable){
18078 // only causes errors at present
18079 //Roo.log(this.store.reader.jsonData);
18080 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
18082 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
18088 onTypeAhead : function(){
18089 if(this.store.getCount() > 0){
18090 var r = this.store.getAt(0);
18091 var newValue = r.data[this.displayField];
18092 var len = newValue.length;
18093 var selStart = this.getRawValue().length;
18095 if(selStart != len){
18096 this.setRawValue(newValue);
18097 this.selectText(selStart, newValue.length);
18103 onSelect : function(record, index){
18105 if(this.fireEvent('beforeselect', this, record, index) !== false){
18107 this.setFromData(index > -1 ? record.data : false);
18110 this.fireEvent('select', this, record, index);
18115 * Returns the currently selected field value or empty string if no value is set.
18116 * @return {String} value The selected value
18118 getValue : function()
18120 if(Roo.isIOS && this.useNativeIOS){
18121 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
18125 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
18128 if(this.valueField){
18129 return typeof this.value != 'undefined' ? this.value : '';
18131 return Roo.bootstrap.form.ComboBox.superclass.getValue.call(this);
18135 getRawValue : function()
18137 if(Roo.isIOS && this.useNativeIOS){
18138 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
18141 var v = this.inputEl().getValue();
18147 * Clears any text/value currently set in the field
18149 clearValue : function(){
18151 if(this.hiddenField){
18152 this.hiddenField.dom.value = '';
18155 this.setRawValue('');
18156 this.lastSelectionText = '';
18157 this.lastData = false;
18159 var close = this.closeTriggerEl();
18170 * Sets the specified value into the field. If the value finds a match, the corresponding record text
18171 * will be displayed in the field. If the value does not match the data value of an existing item,
18172 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
18173 * Otherwise the field will be blank (although the value will still be set).
18174 * @param {String} value The value to match
18176 setValue : function(v)
18178 if(Roo.isIOS && this.useNativeIOS){
18179 this.setIOSValue(v);
18189 if(this.valueField){
18190 var r = this.findRecord(this.valueField, v);
18192 text = r.data[this.displayField];
18193 }else if(this.valueNotFoundText !== undefined){
18194 text = this.valueNotFoundText;
18197 this.lastSelectionText = text;
18198 if(this.hiddenField){
18199 this.hiddenField.dom.value = v;
18201 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, text);
18204 var close = this.closeTriggerEl();
18207 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
18213 * @property {Object} the last set data for the element
18218 * Sets the value of the field based on a object which is related to the record format for the store.
18219 * @param {Object} value the value to set as. or false on reset?
18221 setFromData : function(o){
18228 var dv = ''; // display value
18229 var vv = ''; // value value..
18231 if (this.displayField) {
18232 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
18234 // this is an error condition!!!
18235 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
18238 if(this.valueField){
18239 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
18242 var close = this.closeTriggerEl();
18245 if(dv.length || vv * 1 > 0){
18247 this.blockFocus=true;
18253 if(this.hiddenField){
18254 this.hiddenField.dom.value = vv;
18256 this.lastSelectionText = dv;
18257 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
18261 // no hidden field.. - we store the value in 'value', but still display
18262 // display field!!!!
18263 this.lastSelectionText = dv;
18264 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
18271 reset : function(){
18272 // overridden so that last data is reset..
18279 this.setValue(this.originalValue);
18280 //this.clearInvalid();
18281 this.lastData = false;
18283 this.view.clearSelections();
18289 findRecord : function(prop, value){
18291 if(this.store.getCount() > 0){
18292 this.store.each(function(r){
18293 if(r.data[prop] == value){
18303 getName: function()
18305 // returns hidden if it's set..
18306 if (!this.rendered) {return ''};
18307 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
18311 onViewMove : function(e, t){
18312 this.inKeyMode = false;
18316 onViewOver : function(e, t){
18317 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
18320 var item = this.view.findItemFromChild(t);
18323 var index = this.view.indexOf(item);
18324 this.select(index, false);
18329 onViewClick : function(view, doFocus, el, e)
18331 var index = this.view.getSelectedIndexes()[0];
18333 var r = this.store.getAt(index);
18337 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
18344 Roo.each(this.tickItems, function(v,k){
18346 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
18348 _this.tickItems.splice(k, 1);
18350 if(typeof(e) == 'undefined' && view == false){
18351 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
18363 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
18364 this.tickItems.push(r.data);
18367 if(typeof(e) == 'undefined' && view == false){
18368 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
18375 this.onSelect(r, index);
18377 if(doFocus !== false && !this.blockFocus){
18378 this.inputEl().focus();
18383 restrictHeight : function(){
18384 //this.innerList.dom.style.height = '';
18385 //var inner = this.innerList.dom;
18386 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
18387 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
18388 //this.list.beginUpdate();
18389 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
18390 this.list.alignTo(this.inputEl(), this.listAlign);
18391 this.list.alignTo(this.inputEl(), this.listAlign);
18392 //this.list.endUpdate();
18396 onEmptyResults : function(){
18398 if(this.tickable && this.editable){
18399 this.hasFocus = false;
18400 this.restrictHeight();
18408 * Returns true if the dropdown list is expanded, else false.
18410 isExpanded : function(){
18411 return this.list.isVisible();
18415 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
18416 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
18417 * @param {String} value The data value of the item to select
18418 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
18419 * selected item if it is not currently in view (defaults to true)
18420 * @return {Boolean} True if the value matched an item in the list, else false
18422 selectByValue : function(v, scrollIntoView){
18423 if(v !== undefined && v !== null){
18424 var r = this.findRecord(this.valueField || this.displayField, v);
18426 this.select(this.store.indexOf(r), scrollIntoView);
18434 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
18435 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
18436 * @param {Number} index The zero-based index of the list item to select
18437 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
18438 * selected item if it is not currently in view (defaults to true)
18440 select : function(index, scrollIntoView){
18441 this.selectedIndex = index;
18442 this.view.select(index);
18443 if(scrollIntoView !== false){
18444 var el = this.view.getNode(index);
18446 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
18449 this.list.scrollChildIntoView(el, false);
18455 selectNext : function(){
18456 var ct = this.store.getCount();
18458 if(this.selectedIndex == -1){
18460 }else if(this.selectedIndex < ct-1){
18461 this.select(this.selectedIndex+1);
18467 selectPrev : function(){
18468 var ct = this.store.getCount();
18470 if(this.selectedIndex == -1){
18472 }else if(this.selectedIndex != 0){
18473 this.select(this.selectedIndex-1);
18479 onKeyUp : function(e){
18480 if(this.editable !== false && !e.isSpecialKey()){
18481 this.lastKey = e.getKey();
18482 this.dqTask.delay(this.queryDelay);
18487 validateBlur : function(){
18488 return !this.list || !this.list.isVisible();
18492 initQuery : function(){
18494 var v = this.getRawValue();
18496 if(this.tickable && this.editable){
18497 v = this.tickableInputEl().getValue();
18504 doForce : function(){
18505 if(this.inputEl().dom.value.length > 0){
18506 this.inputEl().dom.value =
18507 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
18513 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
18514 * query allowing the query action to be canceled if needed.
18515 * @param {String} query The SQL query to execute
18516 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
18517 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
18518 * saved in the current store (defaults to false)
18520 doQuery : function(q, forceAll){
18522 if(q === undefined || q === null){
18527 forceAll: forceAll,
18531 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
18536 forceAll = qe.forceAll;
18537 if(forceAll === true || (q.length >= this.minChars)){
18539 this.hasQuery = true;
18541 if(this.lastQuery != q || this.alwaysQuery){
18542 this.lastQuery = q;
18543 if(this.mode == 'local'){
18544 this.selectedIndex = -1;
18546 this.store.clearFilter();
18549 if(this.specialFilter){
18550 this.fireEvent('specialfilter', this);
18555 this.store.filter(this.displayField, q);
18558 this.store.fireEvent("datachanged", this.store);
18565 this.store.baseParams[this.queryParam] = q;
18567 var options = {params : this.getParams(q)};
18570 options.add = true;
18571 options.params.start = this.page * this.pageSize;
18574 this.store.load(options);
18577 * this code will make the page width larger, at the beginning, the list not align correctly,
18578 * we should expand the list on onLoad
18579 * so command out it
18584 this.selectedIndex = -1;
18589 this.loadNext = false;
18593 getParams : function(q){
18595 //p[this.queryParam] = q;
18599 p.limit = this.pageSize;
18605 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
18607 collapse : function(){
18608 if(!this.isExpanded()){
18614 this.hasFocus = false;
18618 this.cancelBtn.hide();
18619 this.trigger.show();
18622 this.tickableInputEl().dom.value = '';
18623 this.tickableInputEl().blur();
18628 Roo.get(document).un('mousedown', this.collapseIf, this);
18629 Roo.get(document).un('mousewheel', this.collapseIf, this);
18630 if (!this.editable) {
18631 Roo.get(document).un('keydown', this.listKeyPress, this);
18633 this.fireEvent('collapse', this);
18639 collapseIf : function(e){
18640 var in_combo = e.within(this.el);
18641 var in_list = e.within(this.list);
18642 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
18644 if (in_combo || in_list || is_list) {
18645 //e.stopPropagation();
18650 this.onTickableFooterButtonClick(e, false, false);
18658 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
18660 expand : function(){
18662 if(this.isExpanded() || !this.hasFocus){
18666 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
18667 this.list.setWidth(lw);
18673 this.restrictHeight();
18677 this.tickItems = Roo.apply([], this.item);
18680 this.cancelBtn.show();
18681 this.trigger.hide();
18684 this.tickableInputEl().focus();
18689 Roo.get(document).on('mousedown', this.collapseIf, this);
18690 Roo.get(document).on('mousewheel', this.collapseIf, this);
18691 if (!this.editable) {
18692 Roo.get(document).on('keydown', this.listKeyPress, this);
18695 this.fireEvent('expand', this);
18699 // Implements the default empty TriggerField.onTriggerClick function
18700 onTriggerClick : function(e)
18702 Roo.log('trigger click');
18704 if(this.disabled || !this.triggerList){
18709 this.loadNext = false;
18711 if(this.isExpanded()){
18713 if (!this.blockFocus) {
18714 this.inputEl().focus();
18718 this.hasFocus = true;
18719 if(this.triggerAction == 'all') {
18720 this.doQuery(this.allQuery, true);
18722 this.doQuery(this.getRawValue());
18724 if (!this.blockFocus) {
18725 this.inputEl().focus();
18730 onTickableTriggerClick : function(e)
18737 this.loadNext = false;
18738 this.hasFocus = true;
18740 if(this.triggerAction == 'all') {
18741 this.doQuery(this.allQuery, true);
18743 this.doQuery(this.getRawValue());
18747 onSearchFieldClick : function(e)
18749 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
18750 this.onTickableFooterButtonClick(e, false, false);
18754 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
18759 this.loadNext = false;
18760 this.hasFocus = true;
18762 if(this.triggerAction == 'all') {
18763 this.doQuery(this.allQuery, true);
18765 this.doQuery(this.getRawValue());
18769 listKeyPress : function(e)
18771 //Roo.log('listkeypress');
18772 // scroll to first matching element based on key pres..
18773 if (e.isSpecialKey()) {
18776 var k = String.fromCharCode(e.getKey()).toUpperCase();
18779 var csel = this.view.getSelectedNodes();
18780 var cselitem = false;
18782 var ix = this.view.indexOf(csel[0]);
18783 cselitem = this.store.getAt(ix);
18784 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
18790 this.store.each(function(v) {
18792 // start at existing selection.
18793 if (cselitem.id == v.id) {
18799 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
18800 match = this.store.indexOf(v);
18806 if (match === false) {
18807 return true; // no more action?
18810 this.view.select(match);
18811 var sn = Roo.get(this.view.getSelectedNodes()[0]);
18812 sn.scrollIntoView(sn.dom.parentNode, false);
18815 onViewScroll : function(e, t){
18817 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){
18821 this.hasQuery = true;
18823 this.loading = this.list.select('.loading', true).first();
18825 if(this.loading === null){
18826 this.list.createChild({
18828 cls: 'loading roo-select2-more-results roo-select2-active',
18829 html: 'Loading more results...'
18832 this.loading = this.list.select('.loading', true).first();
18834 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
18836 this.loading.hide();
18839 this.loading.show();
18844 this.loadNext = true;
18846 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
18851 addItem : function(o)
18853 var dv = ''; // display value
18855 if (this.displayField) {
18856 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
18858 // this is an error condition!!!
18859 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
18866 var choice = this.choices.createChild({
18868 cls: 'roo-select2-search-choice',
18877 cls: 'roo-select2-search-choice-close fa fa-times',
18882 }, this.searchField);
18884 var close = choice.select('a.roo-select2-search-choice-close', true).first();
18886 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
18894 this.inputEl().dom.value = '';
18899 onRemoveItem : function(e, _self, o)
18901 e.preventDefault();
18903 this.lastItem = Roo.apply([], this.item);
18905 var index = this.item.indexOf(o.data) * 1;
18908 Roo.log('not this item?!');
18912 this.item.splice(index, 1);
18917 this.fireEvent('remove', this, e);
18923 syncValue : function()
18925 if(!this.item.length){
18932 Roo.each(this.item, function(i){
18933 if(_this.valueField){
18934 value.push(i[_this.valueField]);
18941 this.value = value.join(',');
18943 if(this.hiddenField){
18944 this.hiddenField.dom.value = this.value;
18947 this.store.fireEvent("datachanged", this.store);
18952 clearItem : function()
18954 if(!this.multiple){
18960 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
18968 if(this.tickable && !Roo.isTouch){
18969 this.view.refresh();
18973 inputEl: function ()
18975 if(Roo.isIOS && this.useNativeIOS){
18976 return this.el.select('select.roo-ios-select', true).first();
18979 if(Roo.isTouch && this.mobileTouchView){
18980 return this.el.select('input.form-control',true).first();
18984 return this.searchField;
18987 return this.el.select('input.form-control',true).first();
18990 onTickableFooterButtonClick : function(e, btn, el)
18992 e.preventDefault();
18994 this.lastItem = Roo.apply([], this.item);
18996 if(btn && btn.name == 'cancel'){
18997 this.tickItems = Roo.apply([], this.item);
19006 Roo.each(this.tickItems, function(o){
19014 validate : function()
19016 if(this.getVisibilityEl().hasClass('hidden')){
19020 var v = this.getRawValue();
19023 v = this.getValue();
19026 if(this.disabled || this.allowBlank || v.length){
19031 this.markInvalid();
19035 tickableInputEl : function()
19037 if(!this.tickable || !this.editable){
19038 return this.inputEl();
19041 return this.inputEl().select('.roo-select2-search-field-input', true).first();
19045 getAutoCreateTouchView : function()
19050 cls: 'form-group' //input-group
19056 type : this.inputType,
19057 cls : 'form-control x-combo-noedit',
19058 autocomplete: 'new-password',
19059 placeholder : this.placeholder || '',
19064 input.name = this.name;
19068 input.cls += ' input-' + this.size;
19071 if (this.disabled) {
19072 input.disabled = true;
19076 cls : 'roo-combobox-wrap',
19083 inputblock.cls += ' input-group';
19085 inputblock.cn.unshift({
19087 cls : 'input-group-addon input-group-prepend input-group-text',
19092 if(this.removable && !this.multiple){
19093 inputblock.cls += ' roo-removable';
19095 inputblock.cn.push({
19098 cls : 'roo-combo-removable-btn close'
19102 if(this.hasFeedback && !this.allowBlank){
19104 inputblock.cls += ' has-feedback';
19106 inputblock.cn.push({
19108 cls: 'glyphicon form-control-feedback'
19115 inputblock.cls += (this.before) ? '' : ' input-group';
19117 inputblock.cn.push({
19119 cls : 'input-group-addon input-group-append input-group-text',
19125 var ibwrap = inputblock;
19130 cls: 'roo-select2-choices',
19134 cls: 'roo-select2-search-field',
19147 cls: 'roo-select2-container input-group roo-touchview-combobox ',
19152 cls: 'form-hidden-field'
19158 if(!this.multiple && this.showToggleBtn){
19164 if (this.caret != false) {
19167 cls: 'fa fa-' + this.caret
19174 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
19176 Roo.bootstrap.version == 3 ? caret : '',
19179 cls: 'combobox-clear',
19193 combobox.cls += ' roo-select2-container-multi';
19196 var required = this.allowBlank ? {
19198 style: 'display: none'
19201 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
19202 tooltip : 'This field is required'
19205 var align = this.labelAlign || this.parentLabelAlign();
19207 if (align ==='left' && this.fieldLabel.length) {
19213 cls : 'control-label col-form-label',
19214 html : this.fieldLabel
19218 cls : 'roo-combobox-wrap ',
19225 var labelCfg = cfg.cn[1];
19226 var contentCfg = cfg.cn[2];
19229 if(this.indicatorpos == 'right'){
19234 cls : 'control-label col-form-label',
19238 html : this.fieldLabel
19244 cls : "roo-combobox-wrap ",
19252 labelCfg = cfg.cn[0];
19253 contentCfg = cfg.cn[1];
19258 if(this.labelWidth > 12){
19259 labelCfg.style = "width: " + this.labelWidth + 'px';
19262 if(this.labelWidth < 13 && this.labelmd == 0){
19263 this.labelmd = this.labelWidth;
19266 if(this.labellg > 0){
19267 labelCfg.cls += ' col-lg-' + this.labellg;
19268 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
19271 if(this.labelmd > 0){
19272 labelCfg.cls += ' col-md-' + this.labelmd;
19273 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
19276 if(this.labelsm > 0){
19277 labelCfg.cls += ' col-sm-' + this.labelsm;
19278 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
19281 if(this.labelxs > 0){
19282 labelCfg.cls += ' col-xs-' + this.labelxs;
19283 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
19287 } else if ( this.fieldLabel.length) {
19292 cls : 'control-label',
19293 html : this.fieldLabel
19304 if(this.indicatorpos == 'right'){
19308 cls : 'control-label',
19309 html : this.fieldLabel,
19327 var settings = this;
19329 ['xs','sm','md','lg'].map(function(size){
19330 if (settings[size]) {
19331 cfg.cls += ' col-' + size + '-' + settings[size];
19338 initTouchView : function()
19340 this.renderTouchView();
19342 this.touchViewEl.on('scroll', function(){
19343 this.el.dom.scrollTop = 0;
19346 this.originalValue = this.getValue();
19348 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
19350 this.inputEl().on("click", this.showTouchView, this);
19351 if (this.triggerEl) {
19352 this.triggerEl.on("click", this.showTouchView, this);
19356 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
19357 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
19359 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
19361 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
19362 this.store.on('load', this.onTouchViewLoad, this);
19363 this.store.on('loadexception', this.onTouchViewLoadException, this);
19365 if(this.hiddenName){
19367 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
19369 this.hiddenField.dom.value =
19370 this.hiddenValue !== undefined ? this.hiddenValue :
19371 this.value !== undefined ? this.value : '';
19373 this.el.dom.removeAttribute('name');
19374 this.hiddenField.dom.setAttribute('name', this.hiddenName);
19378 this.choices = this.el.select('ul.roo-select2-choices', true).first();
19379 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
19382 if(this.removable && !this.multiple){
19383 var close = this.closeTriggerEl();
19385 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
19386 close.on('click', this.removeBtnClick, this, close);
19390 * fix the bug in Safari iOS8
19392 this.inputEl().on("focus", function(e){
19393 document.activeElement.blur();
19396 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
19403 renderTouchView : function()
19405 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.form.ComboBox.touchViewTemplate);
19406 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19408 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
19409 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19411 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
19412 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19413 this.touchViewBodyEl.setStyle('overflow', 'auto');
19415 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
19416 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19418 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
19419 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19423 showTouchView : function()
19429 this.touchViewHeaderEl.hide();
19431 if(this.modalTitle.length){
19432 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
19433 this.touchViewHeaderEl.show();
19436 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
19437 this.touchViewEl.show();
19439 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
19441 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
19442 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
19444 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
19446 if(this.modalTitle.length){
19447 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
19450 this.touchViewBodyEl.setHeight(bodyHeight);
19454 (function(){ _this.touchViewEl.addClass(['in','show']); }).defer(50);
19456 this.touchViewEl.addClass(['in','show']);
19459 if(this._touchViewMask){
19460 Roo.get(document.body).addClass("x-body-masked");
19461 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
19462 this._touchViewMask.setStyle('z-index', 10000);
19463 this._touchViewMask.addClass('show');
19466 this.doTouchViewQuery();
19470 hideTouchView : function()
19472 this.touchViewEl.removeClass(['in','show']);
19476 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
19478 this.touchViewEl.setStyle('display', 'none');
19481 if(this._touchViewMask){
19482 this._touchViewMask.removeClass('show');
19483 Roo.get(document.body).removeClass("x-body-masked");
19487 setTouchViewValue : function()
19494 Roo.each(this.tickItems, function(o){
19499 this.hideTouchView();
19502 doTouchViewQuery : function()
19511 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
19515 if(!this.alwaysQuery || this.mode == 'local'){
19516 this.onTouchViewLoad();
19523 onTouchViewBeforeLoad : function(combo,opts)
19529 onTouchViewLoad : function()
19531 if(this.store.getCount() < 1){
19532 this.onTouchViewEmptyResults();
19536 this.clearTouchView();
19538 var rawValue = this.getRawValue();
19540 var template = (this.multiple) ? Roo.bootstrap.form.ComboBox.listItemCheckbox : Roo.bootstrap.form.ComboBox.listItemRadio;
19542 this.tickItems = [];
19544 this.store.data.each(function(d, rowIndex){
19545 var row = this.touchViewListGroup.createChild(template);
19547 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
19548 row.addClass(d.data.cls);
19551 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
19554 html : d.data[this.displayField]
19557 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
19558 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
19561 row.removeClass('selected');
19562 if(!this.multiple && this.valueField &&
19563 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
19566 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19567 row.addClass('selected');
19570 if(this.multiple && this.valueField &&
19571 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
19575 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19576 this.tickItems.push(d.data);
19579 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
19583 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
19585 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
19587 if(this.modalTitle.length){
19588 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
19591 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
19593 if(this.mobile_restrict_height && listHeight < bodyHeight){
19594 this.touchViewBodyEl.setHeight(listHeight);
19599 if(firstChecked && listHeight > bodyHeight){
19600 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
19605 onTouchViewLoadException : function()
19607 this.hideTouchView();
19610 onTouchViewEmptyResults : function()
19612 this.clearTouchView();
19614 this.touchViewListGroup.createChild(Roo.bootstrap.form.ComboBox.emptyResult);
19616 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
19620 clearTouchView : function()
19622 this.touchViewListGroup.dom.innerHTML = '';
19625 onTouchViewClick : function(e, el, o)
19627 e.preventDefault();
19630 var rowIndex = o.rowIndex;
19632 var r = this.store.getAt(rowIndex);
19634 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
19636 if(!this.multiple){
19637 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
19638 c.dom.removeAttribute('checked');
19641 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19643 this.setFromData(r.data);
19645 var close = this.closeTriggerEl();
19651 this.hideTouchView();
19653 this.fireEvent('select', this, r, rowIndex);
19658 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
19659 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
19660 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
19664 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19665 this.addItem(r.data);
19666 this.tickItems.push(r.data);
19670 getAutoCreateNativeIOS : function()
19673 cls: 'form-group' //input-group,
19678 cls : 'roo-ios-select'
19682 combobox.name = this.name;
19685 if (this.disabled) {
19686 combobox.disabled = true;
19689 var settings = this;
19691 ['xs','sm','md','lg'].map(function(size){
19692 if (settings[size]) {
19693 cfg.cls += ' col-' + size + '-' + settings[size];
19703 initIOSView : function()
19705 this.store.on('load', this.onIOSViewLoad, this);
19710 onIOSViewLoad : function()
19712 if(this.store.getCount() < 1){
19716 this.clearIOSView();
19718 if(this.allowBlank) {
19720 var default_text = '-- SELECT --';
19722 if(this.placeholder.length){
19723 default_text = this.placeholder;
19726 if(this.emptyTitle.length){
19727 default_text += ' - ' + this.emptyTitle + ' -';
19730 var opt = this.inputEl().createChild({
19733 html : default_text
19737 o[this.valueField] = 0;
19738 o[this.displayField] = default_text;
19740 this.ios_options.push({
19747 this.store.data.each(function(d, rowIndex){
19751 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
19752 html = d.data[this.displayField];
19757 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
19758 value = d.data[this.valueField];
19767 if(this.value == d.data[this.valueField]){
19768 option['selected'] = true;
19771 var opt = this.inputEl().createChild(option);
19773 this.ios_options.push({
19780 this.inputEl().on('change', function(){
19781 this.fireEvent('select', this);
19786 clearIOSView: function()
19788 this.inputEl().dom.innerHTML = '';
19790 this.ios_options = [];
19793 setIOSValue: function(v)
19797 if(!this.ios_options){
19801 Roo.each(this.ios_options, function(opts){
19803 opts.el.dom.removeAttribute('selected');
19805 if(opts.data[this.valueField] != v){
19809 opts.el.dom.setAttribute('selected', true);
19815 * @cfg {Boolean} grow
19819 * @cfg {Number} growMin
19823 * @cfg {Number} growMax
19832 Roo.apply(Roo.bootstrap.form.ComboBox, {
19836 cls: 'modal-header',
19858 cls: 'list-group-item',
19862 cls: 'roo-combobox-list-group-item-value'
19866 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
19880 listItemCheckbox : {
19882 cls: 'list-group-item',
19886 cls: 'roo-combobox-list-group-item-value'
19890 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
19906 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
19911 cls: 'modal-footer',
19919 cls: 'col-xs-6 text-left',
19922 cls: 'btn btn-danger roo-touch-view-cancel',
19928 cls: 'col-xs-6 text-right',
19931 cls: 'btn btn-success roo-touch-view-ok',
19942 Roo.apply(Roo.bootstrap.form.ComboBox, {
19944 touchViewTemplate : {
19946 cls: 'modal fade roo-combobox-touch-view',
19950 cls: 'modal-dialog',
19951 style : 'position:fixed', // we have to fix position....
19955 cls: 'modal-content',
19957 Roo.bootstrap.form.ComboBox.header,
19958 Roo.bootstrap.form.ComboBox.body,
19959 Roo.bootstrap.form.ComboBox.footer
19968 * Ext JS Library 1.1.1
19969 * Copyright(c) 2006-2007, Ext JS, LLC.
19971 * Originally Released Under LGPL - original licence link has changed is not relivant.
19974 * <script type="text/javascript">
19979 * @extends Roo.util.Observable
19980 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
19981 * This class also supports single and multi selection modes. <br>
19982 * Create a data model bound view:
19984 var store = new Roo.data.Store(...);
19986 var view = new Roo.View({
19988 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
19990 singleSelect: true,
19991 selectedClass: "ydataview-selected",
19995 // listen for node click?
19996 view.on("click", function(vw, index, node, e){
19997 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
20001 dataModel.load("foobar.xml");
20003 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
20005 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
20006 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
20008 * Note: old style constructor is still suported (container, template, config)
20011 * Create a new View
20012 * @param {Object} config The config object
20015 Roo.View = function(config, depreciated_tpl, depreciated_config){
20017 this.parent = false;
20019 if (typeof(depreciated_tpl) == 'undefined') {
20020 // new way.. - universal constructor.
20021 Roo.apply(this, config);
20022 this.el = Roo.get(this.el);
20025 this.el = Roo.get(config);
20026 this.tpl = depreciated_tpl;
20027 Roo.apply(this, depreciated_config);
20029 this.wrapEl = this.el.wrap().wrap();
20030 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
20033 if(typeof(this.tpl) == "string"){
20034 this.tpl = new Roo.Template(this.tpl);
20036 // support xtype ctors..
20037 this.tpl = new Roo.factory(this.tpl, Roo);
20041 this.tpl.compile();
20046 * @event beforeclick
20047 * Fires before a click is processed. Returns false to cancel the default action.
20048 * @param {Roo.View} this
20049 * @param {Number} index The index of the target node
20050 * @param {HTMLElement} node The target node
20051 * @param {Roo.EventObject} e The raw event object
20053 "beforeclick" : true,
20056 * Fires when a template node is clicked.
20057 * @param {Roo.View} this
20058 * @param {Number} index The index of the target node
20059 * @param {HTMLElement} node The target node
20060 * @param {Roo.EventObject} e The raw event object
20065 * Fires when a template node is double clicked.
20066 * @param {Roo.View} this
20067 * @param {Number} index The index of the target node
20068 * @param {HTMLElement} node The target node
20069 * @param {Roo.EventObject} e The raw event object
20073 * @event contextmenu
20074 * Fires when a template node is right clicked.
20075 * @param {Roo.View} this
20076 * @param {Number} index The index of the target node
20077 * @param {HTMLElement} node The target node
20078 * @param {Roo.EventObject} e The raw event object
20080 "contextmenu" : true,
20082 * @event selectionchange
20083 * Fires when the selected nodes change.
20084 * @param {Roo.View} this
20085 * @param {Array} selections Array of the selected nodes
20087 "selectionchange" : true,
20090 * @event beforeselect
20091 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
20092 * @param {Roo.View} this
20093 * @param {HTMLElement} node The node to be selected
20094 * @param {Array} selections Array of currently selected nodes
20096 "beforeselect" : true,
20098 * @event preparedata
20099 * Fires on every row to render, to allow you to change the data.
20100 * @param {Roo.View} this
20101 * @param {Object} data to be rendered (change this)
20103 "preparedata" : true
20111 "click": this.onClick,
20112 "dblclick": this.onDblClick,
20113 "contextmenu": this.onContextMenu,
20117 this.selections = [];
20119 this.cmp = new Roo.CompositeElementLite([]);
20121 this.store = Roo.factory(this.store, Roo.data);
20122 this.setStore(this.store, true);
20125 if ( this.footer && this.footer.xtype) {
20127 var fctr = this.wrapEl.appendChild(document.createElement("div"));
20129 this.footer.dataSource = this.store;
20130 this.footer.container = fctr;
20131 this.footer = Roo.factory(this.footer, Roo);
20132 fctr.insertFirst(this.el);
20134 // this is a bit insane - as the paging toolbar seems to detach the el..
20135 // dom.parentNode.parentNode.parentNode
20136 // they get detached?
20140 Roo.View.superclass.constructor.call(this);
20145 Roo.extend(Roo.View, Roo.util.Observable, {
20148 * @cfg {Roo.data.Store} store Data store to load data from.
20153 * @cfg {String|Roo.Element} el The container element.
20158 * @cfg {String|Roo.Template} tpl The template used by this View
20162 * @cfg {String} dataName the named area of the template to use as the data area
20163 * Works with domtemplates roo-name="name"
20167 * @cfg {String} selectedClass The css class to add to selected nodes
20169 selectedClass : "x-view-selected",
20171 * @cfg {String} emptyText The empty text to show when nothing is loaded.
20176 * @cfg {String} text to display on mask (default Loading)
20180 * @cfg {Boolean} multiSelect Allow multiple selection
20182 multiSelect : false,
20184 * @cfg {Boolean} singleSelect Allow single selection
20186 singleSelect: false,
20189 * @cfg {Boolean} toggleSelect - selecting
20191 toggleSelect : false,
20194 * @cfg {Boolean} tickable - selecting
20199 * Returns the element this view is bound to.
20200 * @return {Roo.Element}
20202 getEl : function(){
20203 return this.wrapEl;
20209 * Refreshes the view. - called by datachanged on the store. - do not call directly.
20211 refresh : function(){
20212 //Roo.log('refresh');
20215 // if we are using something like 'domtemplate', then
20216 // the what gets used is:
20217 // t.applySubtemplate(NAME, data, wrapping data..)
20218 // the outer template then get' applied with
20219 // the store 'extra data'
20220 // and the body get's added to the
20221 // roo-name="data" node?
20222 // <span class='roo-tpl-{name}'></span> ?????
20226 this.clearSelections();
20227 this.el.update("");
20229 var records = this.store.getRange();
20230 if(records.length < 1) {
20232 // is this valid?? = should it render a template??
20234 this.el.update(this.emptyText);
20238 if (this.dataName) {
20239 this.el.update(t.apply(this.store.meta)); //????
20240 el = this.el.child('.roo-tpl-' + this.dataName);
20243 for(var i = 0, len = records.length; i < len; i++){
20244 var data = this.prepareData(records[i].data, i, records[i]);
20245 this.fireEvent("preparedata", this, data, i, records[i]);
20247 var d = Roo.apply({}, data);
20250 Roo.apply(d, {'roo-id' : Roo.id()});
20254 Roo.each(this.parent.item, function(item){
20255 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
20258 Roo.apply(d, {'roo-data-checked' : 'checked'});
20262 html[html.length] = Roo.util.Format.trim(
20264 t.applySubtemplate(this.dataName, d, this.store.meta) :
20271 el.update(html.join(""));
20272 this.nodes = el.dom.childNodes;
20273 this.updateIndexes(0);
20278 * Function to override to reformat the data that is sent to
20279 * the template for each node.
20280 * DEPRICATED - use the preparedata event handler.
20281 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
20282 * a JSON object for an UpdateManager bound view).
20284 prepareData : function(data, index, record)
20286 this.fireEvent("preparedata", this, data, index, record);
20290 onUpdate : function(ds, record){
20291 // Roo.log('on update');
20292 this.clearSelections();
20293 var index = this.store.indexOf(record);
20294 var n = this.nodes[index];
20295 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
20296 n.parentNode.removeChild(n);
20297 this.updateIndexes(index, index);
20303 onAdd : function(ds, records, index)
20305 //Roo.log(['on Add', ds, records, index] );
20306 this.clearSelections();
20307 if(this.nodes.length == 0){
20311 var n = this.nodes[index];
20312 for(var i = 0, len = records.length; i < len; i++){
20313 var d = this.prepareData(records[i].data, i, records[i]);
20315 this.tpl.insertBefore(n, d);
20318 this.tpl.append(this.el, d);
20321 this.updateIndexes(index);
20324 onRemove : function(ds, record, index){
20325 // Roo.log('onRemove');
20326 this.clearSelections();
20327 var el = this.dataName ?
20328 this.el.child('.roo-tpl-' + this.dataName) :
20331 el.dom.removeChild(this.nodes[index]);
20332 this.updateIndexes(index);
20336 * Refresh an individual node.
20337 * @param {Number} index
20339 refreshNode : function(index){
20340 this.onUpdate(this.store, this.store.getAt(index));
20343 updateIndexes : function(startIndex, endIndex){
20344 var ns = this.nodes;
20345 startIndex = startIndex || 0;
20346 endIndex = endIndex || ns.length - 1;
20347 for(var i = startIndex; i <= endIndex; i++){
20348 ns[i].nodeIndex = i;
20353 * Changes the data store this view uses and refresh the view.
20354 * @param {Store} store
20356 setStore : function(store, initial){
20357 if(!initial && this.store){
20358 this.store.un("datachanged", this.refresh);
20359 this.store.un("add", this.onAdd);
20360 this.store.un("remove", this.onRemove);
20361 this.store.un("update", this.onUpdate);
20362 this.store.un("clear", this.refresh);
20363 this.store.un("beforeload", this.onBeforeLoad);
20364 this.store.un("load", this.onLoad);
20365 this.store.un("loadexception", this.onLoad);
20369 store.on("datachanged", this.refresh, this);
20370 store.on("add", this.onAdd, this);
20371 store.on("remove", this.onRemove, this);
20372 store.on("update", this.onUpdate, this);
20373 store.on("clear", this.refresh, this);
20374 store.on("beforeload", this.onBeforeLoad, this);
20375 store.on("load", this.onLoad, this);
20376 store.on("loadexception", this.onLoad, this);
20384 * onbeforeLoad - masks the loading area.
20387 onBeforeLoad : function(store,opts)
20389 //Roo.log('onBeforeLoad');
20391 this.el.update("");
20393 this.el.mask(this.mask ? this.mask : "Loading" );
20395 onLoad : function ()
20402 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
20403 * @param {HTMLElement} node
20404 * @return {HTMLElement} The template node
20406 findItemFromChild : function(node){
20407 var el = this.dataName ?
20408 this.el.child('.roo-tpl-' + this.dataName,true) :
20411 if(!node || node.parentNode == el){
20414 var p = node.parentNode;
20415 while(p && p != el){
20416 if(p.parentNode == el){
20425 onClick : function(e){
20426 var item = this.findItemFromChild(e.getTarget());
20428 var index = this.indexOf(item);
20429 if(this.onItemClick(item, index, e) !== false){
20430 this.fireEvent("click", this, index, item, e);
20433 this.clearSelections();
20438 onContextMenu : function(e){
20439 var item = this.findItemFromChild(e.getTarget());
20441 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
20446 onDblClick : function(e){
20447 var item = this.findItemFromChild(e.getTarget());
20449 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
20453 onItemClick : function(item, index, e)
20455 if(this.fireEvent("beforeclick", this, index, item, e) === false){
20458 if (this.toggleSelect) {
20459 var m = this.isSelected(item) ? 'unselect' : 'select';
20462 _t[m](item, true, false);
20465 if(this.multiSelect || this.singleSelect){
20466 if(this.multiSelect && e.shiftKey && this.lastSelection){
20467 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
20469 this.select(item, this.multiSelect && e.ctrlKey);
20470 this.lastSelection = item;
20473 if(!this.tickable){
20474 e.preventDefault();
20482 * Get the number of selected nodes.
20485 getSelectionCount : function(){
20486 return this.selections.length;
20490 * Get the currently selected nodes.
20491 * @return {Array} An array of HTMLElements
20493 getSelectedNodes : function(){
20494 return this.selections;
20498 * Get the indexes of the selected nodes.
20501 getSelectedIndexes : function(){
20502 var indexes = [], s = this.selections;
20503 for(var i = 0, len = s.length; i < len; i++){
20504 indexes.push(s[i].nodeIndex);
20510 * Clear all selections
20511 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
20513 clearSelections : function(suppressEvent){
20514 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
20515 this.cmp.elements = this.selections;
20516 this.cmp.removeClass(this.selectedClass);
20517 this.selections = [];
20518 if(!suppressEvent){
20519 this.fireEvent("selectionchange", this, this.selections);
20525 * Returns true if the passed node is selected
20526 * @param {HTMLElement/Number} node The node or node index
20527 * @return {Boolean}
20529 isSelected : function(node){
20530 var s = this.selections;
20534 node = this.getNode(node);
20535 return s.indexOf(node) !== -1;
20540 * @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
20541 * @param {Boolean} keepExisting (optional) true to keep existing selections
20542 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
20544 select : function(nodeInfo, keepExisting, suppressEvent){
20545 if(nodeInfo instanceof Array){
20547 this.clearSelections(true);
20549 for(var i = 0, len = nodeInfo.length; i < len; i++){
20550 this.select(nodeInfo[i], true, true);
20554 var node = this.getNode(nodeInfo);
20555 if(!node || this.isSelected(node)){
20556 return; // already selected.
20559 this.clearSelections(true);
20562 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
20563 Roo.fly(node).addClass(this.selectedClass);
20564 this.selections.push(node);
20565 if(!suppressEvent){
20566 this.fireEvent("selectionchange", this, this.selections);
20574 * @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
20575 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
20576 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
20578 unselect : function(nodeInfo, keepExisting, suppressEvent)
20580 if(nodeInfo instanceof Array){
20581 Roo.each(this.selections, function(s) {
20582 this.unselect(s, nodeInfo);
20586 var node = this.getNode(nodeInfo);
20587 if(!node || !this.isSelected(node)){
20588 //Roo.log("not selected");
20589 return; // not selected.
20593 Roo.each(this.selections, function(s) {
20595 Roo.fly(node).removeClass(this.selectedClass);
20602 this.selections= ns;
20603 this.fireEvent("selectionchange", this, this.selections);
20607 * Gets a template node.
20608 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
20609 * @return {HTMLElement} The node or null if it wasn't found
20611 getNode : function(nodeInfo){
20612 if(typeof nodeInfo == "string"){
20613 return document.getElementById(nodeInfo);
20614 }else if(typeof nodeInfo == "number"){
20615 return this.nodes[nodeInfo];
20621 * Gets a range template nodes.
20622 * @param {Number} startIndex
20623 * @param {Number} endIndex
20624 * @return {Array} An array of nodes
20626 getNodes : function(start, end){
20627 var ns = this.nodes;
20628 start = start || 0;
20629 end = typeof end == "undefined" ? ns.length - 1 : end;
20632 for(var i = start; i <= end; i++){
20636 for(var i = start; i >= end; i--){
20644 * Finds the index of the passed node
20645 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
20646 * @return {Number} The index of the node or -1
20648 indexOf : function(node){
20649 node = this.getNode(node);
20650 if(typeof node.nodeIndex == "number"){
20651 return node.nodeIndex;
20653 var ns = this.nodes;
20654 for(var i = 0, len = ns.length; i < len; i++){
20665 * based on jquery fullcalendar
20669 Roo.bootstrap = Roo.bootstrap || {};
20671 * @class Roo.bootstrap.Calendar
20672 * @extends Roo.bootstrap.Component
20673 * Bootstrap Calendar class
20674 * @cfg {Boolean} loadMask (true|false) default false
20675 * @cfg {Object} header generate the user specific header of the calendar, default false
20678 * Create a new Container
20679 * @param {Object} config The config object
20684 Roo.bootstrap.Calendar = function(config){
20685 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
20689 * Fires when a date is selected
20690 * @param {DatePicker} this
20691 * @param {Date} date The selected date
20695 * @event monthchange
20696 * Fires when the displayed month changes
20697 * @param {DatePicker} this
20698 * @param {Date} date The selected month
20700 'monthchange': true,
20702 * @event evententer
20703 * Fires when mouse over an event
20704 * @param {Calendar} this
20705 * @param {event} Event
20707 'evententer': true,
20709 * @event eventleave
20710 * Fires when the mouse leaves an
20711 * @param {Calendar} this
20714 'eventleave': true,
20716 * @event eventclick
20717 * Fires when the mouse click an
20718 * @param {Calendar} this
20727 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
20730 * @cfg {Roo.data.Store} store
20731 * The data source for the calendar
20735 * @cfg {Number} startDay
20736 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
20744 getAutoCreate : function(){
20747 var fc_button = function(name, corner, style, content ) {
20748 return Roo.apply({},{
20750 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
20752 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
20755 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
20766 style : 'width:100%',
20773 cls : 'fc-header-left',
20775 fc_button('prev', 'left', 'arrow', '‹' ),
20776 fc_button('next', 'right', 'arrow', '›' ),
20777 { tag: 'span', cls: 'fc-header-space' },
20778 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
20786 cls : 'fc-header-center',
20790 cls: 'fc-header-title',
20793 html : 'month / year'
20801 cls : 'fc-header-right',
20803 /* fc_button('month', 'left', '', 'month' ),
20804 fc_button('week', '', '', 'week' ),
20805 fc_button('day', 'right', '', 'day' )
20817 header = this.header;
20820 var cal_heads = function() {
20822 // fixme - handle this.
20824 for (var i =0; i < Date.dayNames.length; i++) {
20825 var d = Date.dayNames[i];
20828 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
20829 html : d.substring(0,3)
20833 ret[0].cls += ' fc-first';
20834 ret[6].cls += ' fc-last';
20837 var cal_cell = function(n) {
20840 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
20845 cls: 'fc-day-number',
20849 cls: 'fc-day-content',
20853 style: 'position: relative;' // height: 17px;
20865 var cal_rows = function() {
20868 for (var r = 0; r < 6; r++) {
20875 for (var i =0; i < Date.dayNames.length; i++) {
20876 var d = Date.dayNames[i];
20877 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
20880 row.cn[0].cls+=' fc-first';
20881 row.cn[0].cn[0].style = 'min-height:90px';
20882 row.cn[6].cls+=' fc-last';
20886 ret[0].cls += ' fc-first';
20887 ret[4].cls += ' fc-prev-last';
20888 ret[5].cls += ' fc-last';
20895 cls: 'fc-border-separate',
20896 style : 'width:100%',
20904 cls : 'fc-first fc-last',
20922 cls : 'fc-content',
20923 style : "position: relative;",
20926 cls : 'fc-view fc-view-month fc-grid',
20927 style : 'position: relative',
20928 unselectable : 'on',
20931 cls : 'fc-event-container',
20932 style : 'position:absolute;z-index:8;top:0;left:0;'
20950 initEvents : function()
20953 throw "can not find store for calendar";
20959 style: "text-align:center",
20963 style: "background-color:white;width:50%;margin:250 auto",
20967 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
20978 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
20980 var size = this.el.select('.fc-content', true).first().getSize();
20981 this.maskEl.setSize(size.width, size.height);
20982 this.maskEl.enableDisplayMode("block");
20983 if(!this.loadMask){
20984 this.maskEl.hide();
20987 this.store = Roo.factory(this.store, Roo.data);
20988 this.store.on('load', this.onLoad, this);
20989 this.store.on('beforeload', this.onBeforeLoad, this);
20993 this.cells = this.el.select('.fc-day',true);
20994 //Roo.log(this.cells);
20995 this.textNodes = this.el.query('.fc-day-number');
20996 this.cells.addClassOnOver('fc-state-hover');
20998 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
20999 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
21000 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
21001 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
21003 this.on('monthchange', this.onMonthChange, this);
21005 this.update(new Date().clearTime());
21008 resize : function() {
21009 var sz = this.el.getSize();
21011 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
21012 this.el.select('.fc-day-content div',true).setHeight(34);
21017 showPrevMonth : function(e){
21018 this.update(this.activeDate.add("mo", -1));
21020 showToday : function(e){
21021 this.update(new Date().clearTime());
21024 showNextMonth : function(e){
21025 this.update(this.activeDate.add("mo", 1));
21029 showPrevYear : function(){
21030 this.update(this.activeDate.add("y", -1));
21034 showNextYear : function(){
21035 this.update(this.activeDate.add("y", 1));
21040 update : function(date)
21042 var vd = this.activeDate;
21043 this.activeDate = date;
21044 // if(vd && this.el){
21045 // var t = date.getTime();
21046 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
21047 // Roo.log('using add remove');
21049 // this.fireEvent('monthchange', this, date);
21051 // this.cells.removeClass("fc-state-highlight");
21052 // this.cells.each(function(c){
21053 // if(c.dateValue == t){
21054 // c.addClass("fc-state-highlight");
21055 // setTimeout(function(){
21056 // try{c.dom.firstChild.focus();}catch(e){}
21066 var days = date.getDaysInMonth();
21068 var firstOfMonth = date.getFirstDateOfMonth();
21069 var startingPos = firstOfMonth.getDay()-this.startDay;
21071 if(startingPos < this.startDay){
21075 var pm = date.add(Date.MONTH, -1);
21076 var prevStart = pm.getDaysInMonth()-startingPos;
21078 this.cells = this.el.select('.fc-day',true);
21079 this.textNodes = this.el.query('.fc-day-number');
21080 this.cells.addClassOnOver('fc-state-hover');
21082 var cells = this.cells.elements;
21083 var textEls = this.textNodes;
21085 Roo.each(cells, function(cell){
21086 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
21089 days += startingPos;
21091 // convert everything to numbers so it's fast
21092 var day = 86400000;
21093 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
21096 //Roo.log(prevStart);
21098 var today = new Date().clearTime().getTime();
21099 var sel = date.clearTime().getTime();
21100 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
21101 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
21102 var ddMatch = this.disabledDatesRE;
21103 var ddText = this.disabledDatesText;
21104 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
21105 var ddaysText = this.disabledDaysText;
21106 var format = this.format;
21108 var setCellClass = function(cal, cell){
21112 //Roo.log('set Cell Class');
21114 var t = d.getTime();
21118 cell.dateValue = t;
21120 cell.className += " fc-today";
21121 cell.className += " fc-state-highlight";
21122 cell.title = cal.todayText;
21125 // disable highlight in other month..
21126 //cell.className += " fc-state-highlight";
21131 cell.className = " fc-state-disabled";
21132 cell.title = cal.minText;
21136 cell.className = " fc-state-disabled";
21137 cell.title = cal.maxText;
21141 if(ddays.indexOf(d.getDay()) != -1){
21142 cell.title = ddaysText;
21143 cell.className = " fc-state-disabled";
21146 if(ddMatch && format){
21147 var fvalue = d.dateFormat(format);
21148 if(ddMatch.test(fvalue)){
21149 cell.title = ddText.replace("%0", fvalue);
21150 cell.className = " fc-state-disabled";
21154 if (!cell.initialClassName) {
21155 cell.initialClassName = cell.dom.className;
21158 cell.dom.className = cell.initialClassName + ' ' + cell.className;
21163 for(; i < startingPos; i++) {
21164 textEls[i].innerHTML = (++prevStart);
21165 d.setDate(d.getDate()+1);
21167 cells[i].className = "fc-past fc-other-month";
21168 setCellClass(this, cells[i]);
21173 for(; i < days; i++){
21174 intDay = i - startingPos + 1;
21175 textEls[i].innerHTML = (intDay);
21176 d.setDate(d.getDate()+1);
21178 cells[i].className = ''; // "x-date-active";
21179 setCellClass(this, cells[i]);
21183 for(; i < 42; i++) {
21184 textEls[i].innerHTML = (++extraDays);
21185 d.setDate(d.getDate()+1);
21187 cells[i].className = "fc-future fc-other-month";
21188 setCellClass(this, cells[i]);
21191 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
21193 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
21195 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
21196 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
21198 if(totalRows != 6){
21199 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
21200 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
21203 this.fireEvent('monthchange', this, date);
21207 if(!this.internalRender){
21208 var main = this.el.dom.firstChild;
21209 var w = main.offsetWidth;
21210 this.el.setWidth(w + this.el.getBorderWidth("lr"));
21211 Roo.fly(main).setWidth(w);
21212 this.internalRender = true;
21213 // opera does not respect the auto grow header center column
21214 // then, after it gets a width opera refuses to recalculate
21215 // without a second pass
21216 if(Roo.isOpera && !this.secondPass){
21217 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
21218 this.secondPass = true;
21219 this.update.defer(10, this, [date]);
21226 findCell : function(dt) {
21227 dt = dt.clearTime().getTime();
21229 this.cells.each(function(c){
21230 //Roo.log("check " +c.dateValue + '?=' + dt);
21231 if(c.dateValue == dt){
21241 findCells : function(ev) {
21242 var s = ev.start.clone().clearTime().getTime();
21244 var e= ev.end.clone().clearTime().getTime();
21247 this.cells.each(function(c){
21248 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
21250 if(c.dateValue > e){
21253 if(c.dateValue < s){
21262 // findBestRow: function(cells)
21266 // for (var i =0 ; i < cells.length;i++) {
21267 // ret = Math.max(cells[i].rows || 0,ret);
21274 addItem : function(ev)
21276 // look for vertical location slot in
21277 var cells = this.findCells(ev);
21279 // ev.row = this.findBestRow(cells);
21281 // work out the location.
21285 for(var i =0; i < cells.length; i++) {
21287 cells[i].row = cells[0].row;
21290 cells[i].row = cells[i].row + 1;
21300 if (crow.start.getY() == cells[i].getY()) {
21302 crow.end = cells[i];
21319 cells[0].events.push(ev);
21321 this.calevents.push(ev);
21324 clearEvents: function() {
21326 if(!this.calevents){
21330 Roo.each(this.cells.elements, function(c){
21336 Roo.each(this.calevents, function(e) {
21337 Roo.each(e.els, function(el) {
21338 el.un('mouseenter' ,this.onEventEnter, this);
21339 el.un('mouseleave' ,this.onEventLeave, this);
21344 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
21350 renderEvents: function()
21354 this.cells.each(function(c) {
21363 if(c.row != c.events.length){
21364 r = 4 - (4 - (c.row - c.events.length));
21367 c.events = ev.slice(0, r);
21368 c.more = ev.slice(r);
21370 if(c.more.length && c.more.length == 1){
21371 c.events.push(c.more.pop());
21374 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
21378 this.cells.each(function(c) {
21380 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
21383 for (var e = 0; e < c.events.length; e++){
21384 var ev = c.events[e];
21385 var rows = ev.rows;
21387 for(var i = 0; i < rows.length; i++) {
21389 // how many rows should it span..
21392 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
21393 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
21395 unselectable : "on",
21398 cls: 'fc-event-inner',
21402 // cls: 'fc-event-time',
21403 // html : cells.length > 1 ? '' : ev.time
21407 cls: 'fc-event-title',
21408 html : String.format('{0}', ev.title)
21415 cls: 'ui-resizable-handle ui-resizable-e',
21416 html : '  '
21423 cfg.cls += ' fc-event-start';
21425 if ((i+1) == rows.length) {
21426 cfg.cls += ' fc-event-end';
21429 var ctr = _this.el.select('.fc-event-container',true).first();
21430 var cg = ctr.createChild(cfg);
21432 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
21433 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
21435 var r = (c.more.length) ? 1 : 0;
21436 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
21437 cg.setWidth(ebox.right - sbox.x -2);
21439 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
21440 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
21441 cg.on('click', _this.onEventClick, _this, ev);
21452 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
21453 style : 'position: absolute',
21454 unselectable : "on",
21457 cls: 'fc-event-inner',
21461 cls: 'fc-event-title',
21469 cls: 'ui-resizable-handle ui-resizable-e',
21470 html : '  '
21476 var ctr = _this.el.select('.fc-event-container',true).first();
21477 var cg = ctr.createChild(cfg);
21479 var sbox = c.select('.fc-day-content',true).first().getBox();
21480 var ebox = c.select('.fc-day-content',true).first().getBox();
21482 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
21483 cg.setWidth(ebox.right - sbox.x -2);
21485 cg.on('click', _this.onMoreEventClick, _this, c.more);
21495 onEventEnter: function (e, el,event,d) {
21496 this.fireEvent('evententer', this, el, event);
21499 onEventLeave: function (e, el,event,d) {
21500 this.fireEvent('eventleave', this, el, event);
21503 onEventClick: function (e, el,event,d) {
21504 this.fireEvent('eventclick', this, el, event);
21507 onMonthChange: function () {
21511 onMoreEventClick: function(e, el, more)
21515 this.calpopover.placement = 'right';
21516 this.calpopover.setTitle('More');
21518 this.calpopover.setContent('');
21520 var ctr = this.calpopover.el.select('.popover-content', true).first();
21522 Roo.each(more, function(m){
21524 cls : 'fc-event-hori fc-event-draggable',
21527 var cg = ctr.createChild(cfg);
21529 cg.on('click', _this.onEventClick, _this, m);
21532 this.calpopover.show(el);
21537 onLoad: function ()
21539 this.calevents = [];
21542 if(this.store.getCount() > 0){
21543 this.store.data.each(function(d){
21546 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
21547 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
21548 time : d.data.start_time,
21549 title : d.data.title,
21550 description : d.data.description,
21551 venue : d.data.venue
21556 this.renderEvents();
21558 if(this.calevents.length && this.loadMask){
21559 this.maskEl.hide();
21563 onBeforeLoad: function()
21565 this.clearEvents();
21567 this.maskEl.show();
21581 * @class Roo.bootstrap.Popover
21582 * @extends Roo.bootstrap.Component
21583 * @parent none builder
21584 * @children Roo.bootstrap.Component
21585 * Bootstrap Popover class
21586 * @cfg {String} html contents of the popover (or false to use children..)
21587 * @cfg {String} title of popover (or false to hide)
21588 * @cfg {String|function} (right|top|bottom|left|auto) placement how it is placed
21589 * @cfg {String} trigger click || hover (or false to trigger manually)
21590 * @cfg {Boolean} modal - popovers that are modal will mask the screen, and must be closed with another event.
21591 * @cfg {String|Boolean|Roo.Element} add click hander to trigger show over what element
21592 * - if false and it has a 'parent' then it will be automatically added to that element
21593 * - if string - Roo.get will be called
21594 * @cfg {Number} delay - delay before showing
21597 * Create a new Popover
21598 * @param {Object} config The config object
21601 Roo.bootstrap.Popover = function(config){
21602 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
21608 * After the popover show
21610 * @param {Roo.bootstrap.Popover} this
21615 * After the popover hide
21617 * @param {Roo.bootstrap.Popover} this
21623 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
21628 placement : 'right',
21629 trigger : 'hover', // hover
21635 can_build_overlaid : false,
21637 maskEl : false, // the mask element
21640 alignEl : false, // when show is called with an element - this get's stored.
21642 getChildContainer : function()
21644 return this.contentEl;
21647 getPopoverHeader : function()
21649 this.title = true; // flag not to hide it..
21650 this.headerEl.addClass('p-0');
21651 return this.headerEl
21655 getAutoCreate : function(){
21658 cls : 'popover roo-dynamic shadow roo-popover' + (this.modal ? '-modal' : ''),
21659 style: 'display:block',
21665 cls : 'popover-inner ',
21669 cls: 'popover-title popover-header',
21670 html : this.title === false ? '' : this.title
21673 cls : 'popover-content popover-body ' + (this.cls || ''),
21674 html : this.html || ''
21685 * @param {string} the title
21687 setTitle: function(str)
21691 this.headerEl.dom.innerHTML = str;
21696 * @param {string} the body content
21698 setContent: function(str)
21701 if (this.contentEl) {
21702 this.contentEl.dom.innerHTML = str;
21706 // as it get's added to the bottom of the page.
21707 onRender : function(ct, position)
21709 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
21714 var cfg = Roo.apply({}, this.getAutoCreate());
21718 cfg.cls += ' ' + this.cls;
21721 cfg.style = this.style;
21723 //Roo.log("adding to ");
21724 this.el = Roo.get(document.body).createChild(cfg, position);
21725 // Roo.log(this.el);
21728 this.contentEl = this.el.select('.popover-content',true).first();
21729 this.headerEl = this.el.select('.popover-title',true).first();
21732 if(typeof(this.items) != 'undefined'){
21733 var items = this.items;
21736 for(var i =0;i < items.length;i++) {
21737 nitems.push(this.addxtype(Roo.apply({}, items[i])));
21741 this.items = nitems;
21743 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
21744 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
21751 resizeMask : function()
21753 this.maskEl.setSize(
21754 Roo.lib.Dom.getViewWidth(true),
21755 Roo.lib.Dom.getViewHeight(true)
21759 initEvents : function()
21763 Roo.bootstrap.Popover.register(this);
21766 this.arrowEl = this.el.select('.arrow',true).first();
21767 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY); // probably not needed as it's default in BS4
21768 this.el.enableDisplayMode('block');
21772 if (this.over === false && !this.parent()) {
21775 if (this.triggers === false) {
21780 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
21781 var triggers = this.trigger ? this.trigger.split(' ') : [];
21782 Roo.each(triggers, function(trigger) {
21784 if (trigger == 'click') {
21785 on_el.on('click', this.toggle, this);
21786 } else if (trigger != 'manual') {
21787 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
21788 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
21790 on_el.on(eventIn ,this.enter, this);
21791 on_el.on(eventOut, this.leave, this);
21801 toggle : function () {
21802 this.hoverState == 'in' ? this.leave() : this.enter();
21805 enter : function () {
21807 clearTimeout(this.timeout);
21809 this.hoverState = 'in';
21811 if (!this.delay || !this.delay.show) {
21816 this.timeout = setTimeout(function () {
21817 if (_t.hoverState == 'in') {
21820 }, this.delay.show)
21823 leave : function() {
21824 clearTimeout(this.timeout);
21826 this.hoverState = 'out';
21828 if (!this.delay || !this.delay.hide) {
21833 this.timeout = setTimeout(function () {
21834 if (_t.hoverState == 'out') {
21837 }, this.delay.hide)
21841 * update the position of the dialog
21842 * normally this is needed if the popover get's bigger - due to a Table reload etc..
21847 doAlign : function()
21850 if (this.alignEl) {
21851 this.updatePosition(this.placement, true);
21854 // this is usually just done by the builder = to show the popoup in the middle of the scren.
21855 var es = this.el.getSize();
21856 var x = Roo.lib.Dom.getViewWidth()/2;
21857 var y = Roo.lib.Dom.getViewHeight()/2;
21858 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
21870 * @param {Roo.Element|string|Boolean} - element to align and point to. (set align to [ pos, offset ])
21871 * @param {string} (left|right|top|bottom) position
21873 show : function (on_el, placement)
21875 this.placement = typeof(placement) == 'undefined' ? this.placement : placement;
21876 on_el = on_el || false; // default to false
21879 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
21880 on_el = this.parent().el;
21881 } else if (this.over) {
21882 on_el = Roo.get(this.over);
21887 this.alignEl = Roo.get( on_el );
21890 this.render(document.body);
21896 if (this.title === false) {
21897 this.headerEl.hide();
21902 this.el.dom.style.display = 'block';
21906 //var arrow = this.el.select('.arrow',true).first();
21907 //arrow.set(align[2],
21909 this.el.addClass('in');
21913 this.hoverState = 'in';
21916 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
21917 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
21918 this.maskEl.dom.style.display = 'block';
21919 this.maskEl.addClass('show');
21921 this.el.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
21923 this.fireEvent('show', this);
21927 * fire this manually after loading a grid in the table for example
21928 * @param {string} (left|right|top|bottom) where to try and put it (use false to use the last one)
21929 * @param {Boolean} try and move it if we cant get right position.
21931 updatePosition : function(placement, try_move)
21933 // allow for calling with no parameters
21934 placement = placement ? placement : this.placement;
21935 try_move = typeof(try_move) == 'undefined' ? true : try_move;
21937 this.el.removeClass([
21938 'fade','top','bottom', 'left', 'right','in',
21939 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
21941 this.el.addClass(placement + ' bs-popover-' + placement);
21943 if (!this.alignEl ) {
21947 switch (placement) {
21949 var exact = this.el.getAlignToXY(this.alignEl, 'tl-tr', [10,0]);
21950 var offset = this.el.getAlignToXY(this.alignEl, 'tl-tr?',[10,0]);
21951 if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
21952 //normal display... or moved up/down.
21953 this.el.setXY(offset);
21954 var xy = this.alignEl.getAnchorXY('tr', false);
21956 this.arrowEl.setXY(xy);
21959 // continue through...
21960 return this.updatePosition('left', false);
21964 var exact = this.el.getAlignToXY(this.alignEl, 'tr-tl', [-10,0]);
21965 var offset = this.el.getAlignToXY(this.alignEl, 'tr-tl?',[-10,0]);
21966 if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
21967 //normal display... or moved up/down.
21968 this.el.setXY(offset);
21969 var xy = this.alignEl.getAnchorXY('tl', false);
21970 xy[0]-=10;xy[1]+=5; // << fix me
21971 this.arrowEl.setXY(xy);
21975 return this.updatePosition('right', false);
21978 var exact = this.el.getAlignToXY(this.alignEl, 'b-t', [0,-10]);
21979 var offset = this.el.getAlignToXY(this.alignEl, 'b-t?',[0,-10]);
21980 if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
21981 //normal display... or moved up/down.
21982 this.el.setXY(offset);
21983 var xy = this.alignEl.getAnchorXY('t', false);
21984 xy[1]-=10; // << fix me
21985 this.arrowEl.setXY(xy);
21989 return this.updatePosition('bottom', false);
21992 var exact = this.el.getAlignToXY(this.alignEl, 't-b', [0,10]);
21993 var offset = this.el.getAlignToXY(this.alignEl, 't-b?',[0,10]);
21994 if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
21995 //normal display... or moved up/down.
21996 this.el.setXY(offset);
21997 var xy = this.alignEl.getAnchorXY('b', false);
21998 xy[1]+=2; // << fix me
21999 this.arrowEl.setXY(xy);
22003 return this.updatePosition('top', false);
22014 this.el.setXY([0,0]);
22015 this.el.removeClass('in');
22017 this.hoverState = null;
22018 this.maskEl.hide(); // always..
22019 this.fireEvent('hide', this);
22025 Roo.apply(Roo.bootstrap.Popover, {
22028 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
22029 'right' : ['l-br', [10,0], 'right bs-popover-right'],
22030 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
22031 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
22036 clickHander : false,
22040 onMouseDown : function(e)
22042 if (this.popups.length && !e.getTarget(".roo-popover")) {
22043 /// what is nothing is showing..
22052 register : function(popup)
22054 if (!Roo.bootstrap.Popover.clickHandler) {
22055 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
22057 // hide other popups.
22058 popup.on('show', Roo.bootstrap.Popover.onShow, popup);
22059 popup.on('hide', Roo.bootstrap.Popover.onHide, popup);
22060 this.hideAll(); //<< why?
22061 //this.popups.push(popup);
22063 hideAll : function()
22065 this.popups.forEach(function(p) {
22069 onShow : function() {
22070 Roo.bootstrap.Popover.popups.push(this);
22072 onHide : function() {
22073 Roo.bootstrap.Popover.popups.remove(this);
22078 * @class Roo.bootstrap.PopoverNav
22079 * @extends Roo.bootstrap.nav.Simplebar
22080 * @parent Roo.bootstrap.Popover
22081 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container
22083 * Bootstrap Popover header navigation class
22084 * FIXME? should this go under nav?
22088 * Create a new Popover Header Navigation
22089 * @param {Object} config The config object
22092 Roo.bootstrap.PopoverNav = function(config){
22093 Roo.bootstrap.PopoverNav.superclass.constructor.call(this, config);
22096 Roo.extend(Roo.bootstrap.PopoverNav, Roo.bootstrap.nav.Simplebar, {
22099 container_method : 'getPopoverHeader'
22117 * @class Roo.bootstrap.Progress
22118 * @extends Roo.bootstrap.Component
22119 * @children Roo.bootstrap.ProgressBar
22120 * Bootstrap Progress class
22121 * @cfg {Boolean} striped striped of the progress bar
22122 * @cfg {Boolean} active animated of the progress bar
22126 * Create a new Progress
22127 * @param {Object} config The config object
22130 Roo.bootstrap.Progress = function(config){
22131 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
22134 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
22139 getAutoCreate : function(){
22147 cfg.cls += ' progress-striped';
22151 cfg.cls += ' active';
22170 * @class Roo.bootstrap.ProgressBar
22171 * @extends Roo.bootstrap.Component
22172 * Bootstrap ProgressBar class
22173 * @cfg {Number} aria_valuenow aria-value now
22174 * @cfg {Number} aria_valuemin aria-value min
22175 * @cfg {Number} aria_valuemax aria-value max
22176 * @cfg {String} label label for the progress bar
22177 * @cfg {String} panel (success | info | warning | danger )
22178 * @cfg {String} role role of the progress bar
22179 * @cfg {String} sr_only text
22183 * Create a new ProgressBar
22184 * @param {Object} config The config object
22187 Roo.bootstrap.ProgressBar = function(config){
22188 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
22191 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
22195 aria_valuemax : 100,
22201 getAutoCreate : function()
22206 cls: 'progress-bar',
22207 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
22219 cfg.role = this.role;
22222 if(this.aria_valuenow){
22223 cfg['aria-valuenow'] = this.aria_valuenow;
22226 if(this.aria_valuemin){
22227 cfg['aria-valuemin'] = this.aria_valuemin;
22230 if(this.aria_valuemax){
22231 cfg['aria-valuemax'] = this.aria_valuemax;
22234 if(this.label && !this.sr_only){
22235 cfg.html = this.label;
22239 cfg.cls += ' progress-bar-' + this.panel;
22245 update : function(aria_valuenow)
22247 this.aria_valuenow = aria_valuenow;
22249 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
22257 * @class Roo.bootstrap.TabGroup
22258 * @extends Roo.bootstrap.Column
22259 * @children Roo.bootstrap.TabPanel
22260 * Bootstrap Column class
22261 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
22262 * @cfg {Boolean} carousel true to make the group behave like a carousel
22263 * @cfg {Boolean} bullets show bullets for the panels
22264 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
22265 * @cfg {Number} timer auto slide timer .. default 0 millisecond
22266 * @cfg {Boolean} showarrow (true|false) show arrow default true
22269 * Create a new TabGroup
22270 * @param {Object} config The config object
22273 Roo.bootstrap.TabGroup = function(config){
22274 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
22276 this.navId = Roo.id();
22279 Roo.bootstrap.TabGroup.register(this);
22283 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
22286 transition : false,
22291 slideOnTouch : false,
22294 getAutoCreate : function()
22296 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
22298 cfg.cls += ' tab-content';
22300 if (this.carousel) {
22301 cfg.cls += ' carousel slide';
22304 cls : 'carousel-inner',
22308 if(this.bullets && !Roo.isTouch){
22311 cls : 'carousel-bullets',
22315 if(this.bullets_cls){
22316 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
22323 cfg.cn[0].cn.push(bullets);
22326 if(this.showarrow){
22327 cfg.cn[0].cn.push({
22329 class : 'carousel-arrow',
22333 class : 'carousel-prev',
22337 class : 'fa fa-chevron-left'
22343 class : 'carousel-next',
22347 class : 'fa fa-chevron-right'
22360 initEvents: function()
22362 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
22363 // this.el.on("touchstart", this.onTouchStart, this);
22366 if(this.autoslide){
22369 this.slideFn = window.setInterval(function() {
22370 _this.showPanelNext();
22374 if(this.showarrow){
22375 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
22376 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
22382 // onTouchStart : function(e, el, o)
22384 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
22388 // this.showPanelNext();
22392 getChildContainer : function()
22394 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
22398 * register a Navigation item
22399 * @param {Roo.bootstrap.nav.Item} the navitem to add
22401 register : function(item)
22403 this.tabs.push( item);
22404 item.navId = this.navId; // not really needed..
22409 getActivePanel : function()
22412 Roo.each(this.tabs, function(t) {
22422 getPanelByName : function(n)
22425 Roo.each(this.tabs, function(t) {
22426 if (t.tabId == n) {
22434 indexOfPanel : function(p)
22437 Roo.each(this.tabs, function(t,i) {
22438 if (t.tabId == p.tabId) {
22447 * show a specific panel
22448 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
22449 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
22451 showPanel : function (pan)
22453 if(this.transition || typeof(pan) == 'undefined'){
22454 Roo.log("waiting for the transitionend");
22458 if (typeof(pan) == 'number') {
22459 pan = this.tabs[pan];
22462 if (typeof(pan) == 'string') {
22463 pan = this.getPanelByName(pan);
22466 var cur = this.getActivePanel();
22469 Roo.log('pan or acitve pan is undefined');
22473 if (pan.tabId == this.getActivePanel().tabId) {
22477 if (false === cur.fireEvent('beforedeactivate')) {
22481 if(this.bullets > 0 && !Roo.isTouch){
22482 this.setActiveBullet(this.indexOfPanel(pan));
22485 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
22487 //class="carousel-item carousel-item-next carousel-item-left"
22489 this.transition = true;
22490 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
22491 var lr = dir == 'next' ? 'left' : 'right';
22492 pan.el.addClass(dir); // or prev
22493 pan.el.addClass('carousel-item-' + dir); // or prev
22494 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
22495 cur.el.addClass(lr); // or right
22496 pan.el.addClass(lr);
22497 cur.el.addClass('carousel-item-' +lr); // or right
22498 pan.el.addClass('carousel-item-' +lr);
22502 cur.el.on('transitionend', function() {
22503 Roo.log("trans end?");
22505 pan.el.removeClass([lr,dir, 'carousel-item-' + lr, 'carousel-item-' + dir]);
22506 pan.setActive(true);
22508 cur.el.removeClass([lr, 'carousel-item-' + lr]);
22509 cur.setActive(false);
22511 _this.transition = false;
22513 }, this, { single: true } );
22518 cur.setActive(false);
22519 pan.setActive(true);
22524 showPanelNext : function()
22526 var i = this.indexOfPanel(this.getActivePanel());
22528 if (i >= this.tabs.length - 1 && !this.autoslide) {
22532 if (i >= this.tabs.length - 1 && this.autoslide) {
22536 this.showPanel(this.tabs[i+1]);
22539 showPanelPrev : function()
22541 var i = this.indexOfPanel(this.getActivePanel());
22543 if (i < 1 && !this.autoslide) {
22547 if (i < 1 && this.autoslide) {
22548 i = this.tabs.length;
22551 this.showPanel(this.tabs[i-1]);
22555 addBullet: function()
22557 if(!this.bullets || Roo.isTouch){
22560 var ctr = this.el.select('.carousel-bullets',true).first();
22561 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
22562 var bullet = ctr.createChild({
22563 cls : 'bullet bullet-' + i
22564 },ctr.dom.lastChild);
22569 bullet.on('click', (function(e, el, o, ii, t){
22571 e.preventDefault();
22573 this.showPanel(ii);
22575 if(this.autoslide && this.slideFn){
22576 clearInterval(this.slideFn);
22577 this.slideFn = window.setInterval(function() {
22578 _this.showPanelNext();
22582 }).createDelegate(this, [i, bullet], true));
22587 setActiveBullet : function(i)
22593 Roo.each(this.el.select('.bullet', true).elements, function(el){
22594 el.removeClass('selected');
22597 var bullet = this.el.select('.bullet-' + i, true).first();
22603 bullet.addClass('selected');
22614 Roo.apply(Roo.bootstrap.TabGroup, {
22618 * register a Navigation Group
22619 * @param {Roo.bootstrap.nav.Group} the navgroup to add
22621 register : function(navgrp)
22623 this.groups[navgrp.navId] = navgrp;
22627 * fetch a Navigation Group based on the navigation ID
22628 * if one does not exist , it will get created.
22629 * @param {string} the navgroup to add
22630 * @returns {Roo.bootstrap.nav.Group} the navgroup
22632 get: function(navId) {
22633 if (typeof(this.groups[navId]) == 'undefined') {
22634 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
22636 return this.groups[navId] ;
22651 * @class Roo.bootstrap.TabPanel
22652 * @extends Roo.bootstrap.Component
22653 * @children Roo.bootstrap.Component
22654 * Bootstrap TabPanel class
22655 * @cfg {Boolean} active panel active
22656 * @cfg {String} html panel content
22657 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
22658 * @cfg {String} navId The Roo.bootstrap.nav.Group which triggers show hide ()
22659 * @cfg {String} href click to link..
22660 * @cfg {Boolean} touchSlide if swiping slides tab to next panel (default off)
22664 * Create a new TabPanel
22665 * @param {Object} config The config object
22668 Roo.bootstrap.TabPanel = function(config){
22669 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
22673 * Fires when the active status changes
22674 * @param {Roo.bootstrap.TabPanel} this
22675 * @param {Boolean} state the new state
22680 * @event beforedeactivate
22681 * Fires before a tab is de-activated - can be used to do validation on a form.
22682 * @param {Roo.bootstrap.TabPanel} this
22683 * @return {Boolean} false if there is an error
22686 'beforedeactivate': true
22689 this.tabId = this.tabId || Roo.id();
22693 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
22700 touchSlide : false,
22701 getAutoCreate : function(){
22706 // item is needed for carousel - not sure if it has any effect otherwise
22707 cls: 'carousel-item tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
22708 html: this.html || ''
22712 cfg.cls += ' active';
22716 cfg.tabId = this.tabId;
22724 initEvents: function()
22726 var p = this.parent();
22728 this.navId = this.navId || p.navId;
22730 if (typeof(this.navId) != 'undefined') {
22731 // not really needed.. but just in case.. parent should be a NavGroup.
22732 var tg = Roo.bootstrap.TabGroup.get(this.navId);
22736 var i = tg.tabs.length - 1;
22738 if(this.active && tg.bullets > 0 && i < tg.bullets){
22739 tg.setActiveBullet(i);
22743 this.el.on('click', this.onClick, this);
22745 if(Roo.isTouch && this.touchSlide){
22746 this.el.on("touchstart", this.onTouchStart, this);
22747 this.el.on("touchmove", this.onTouchMove, this);
22748 this.el.on("touchend", this.onTouchEnd, this);
22753 onRender : function(ct, position)
22755 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
22758 setActive : function(state)
22760 Roo.log("panel - set active " + this.tabId + "=" + state);
22762 this.active = state;
22764 this.el.removeClass('active');
22766 } else if (!this.el.hasClass('active')) {
22767 this.el.addClass('active');
22770 this.fireEvent('changed', this, state);
22773 onClick : function(e)
22775 e.preventDefault();
22777 if(!this.href.length){
22781 window.location.href = this.href;
22790 onTouchStart : function(e)
22792 this.swiping = false;
22794 this.startX = e.browserEvent.touches[0].clientX;
22795 this.startY = e.browserEvent.touches[0].clientY;
22798 onTouchMove : function(e)
22800 this.swiping = true;
22802 this.endX = e.browserEvent.touches[0].clientX;
22803 this.endY = e.browserEvent.touches[0].clientY;
22806 onTouchEnd : function(e)
22813 var tabGroup = this.parent();
22815 if(this.endX > this.startX){ // swiping right
22816 tabGroup.showPanelPrev();
22820 if(this.startX > this.endX){ // swiping left
22821 tabGroup.showPanelNext();
22840 * @class Roo.bootstrap.form.DateField
22841 * @extends Roo.bootstrap.form.Input
22842 * Bootstrap DateField class
22843 * @cfg {Number} weekStart default 0
22844 * @cfg {String} viewMode default empty, (months|years)
22845 * @cfg {String} minViewMode default empty, (months|years)
22846 * @cfg {Number} startDate default -Infinity
22847 * @cfg {Number} endDate default Infinity
22848 * @cfg {Boolean} todayHighlight default false
22849 * @cfg {Boolean} todayBtn default false
22850 * @cfg {Boolean} calendarWeeks default false
22851 * @cfg {Object} daysOfWeekDisabled default empty
22852 * @cfg {Boolean} singleMode default false (true | false)
22854 * @cfg {Boolean} keyboardNavigation default true
22855 * @cfg {String} language default en
22858 * Create a new DateField
22859 * @param {Object} config The config object
22862 Roo.bootstrap.form.DateField = function(config){
22863 Roo.bootstrap.form.DateField.superclass.constructor.call(this, config);
22867 * Fires when this field show.
22868 * @param {Roo.bootstrap.form.DateField} this
22869 * @param {Mixed} date The date value
22874 * Fires when this field hide.
22875 * @param {Roo.bootstrap.form.DateField} this
22876 * @param {Mixed} date The date value
22881 * Fires when select a date.
22882 * @param {Roo.bootstrap.form.DateField} this
22883 * @param {Mixed} date The date value
22887 * @event beforeselect
22888 * Fires when before select a date.
22889 * @param {Roo.bootstrap.form.DateField} this
22890 * @param {Mixed} date The date value
22892 beforeselect : true
22896 Roo.extend(Roo.bootstrap.form.DateField, Roo.bootstrap.form.Input, {
22899 * @cfg {String} format
22900 * The default date format string which can be overriden for localization support. The format must be
22901 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
22905 * @cfg {String} altFormats
22906 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
22907 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
22909 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
22917 todayHighlight : false,
22923 keyboardNavigation: true,
22925 calendarWeeks: false,
22927 startDate: -Infinity,
22931 daysOfWeekDisabled: [],
22935 singleMode : false,
22937 UTCDate: function()
22939 return new Date(Date.UTC.apply(Date, arguments));
22942 UTCToday: function()
22944 var today = new Date();
22945 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
22948 getDate: function() {
22949 var d = this.getUTCDate();
22950 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
22953 getUTCDate: function() {
22957 setDate: function(d) {
22958 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
22961 setUTCDate: function(d) {
22963 this.setValue(this.formatDate(this.date));
22966 onRender: function(ct, position)
22969 Roo.bootstrap.form.DateField.superclass.onRender.call(this, ct, position);
22971 this.language = this.language || 'en';
22972 this.language = this.language in Roo.bootstrap.form.DateField.dates ? this.language : this.language.split('-')[0];
22973 this.language = this.language in Roo.bootstrap.form.DateField.dates ? this.language : "en";
22975 this.isRTL = Roo.bootstrap.form.DateField.dates[this.language].rtl || false;
22976 this.format = this.format || 'm/d/y';
22977 this.isInline = false;
22978 this.isInput = true;
22979 this.component = this.el.select('.add-on', true).first() || false;
22980 this.component = (this.component && this.component.length === 0) ? false : this.component;
22981 this.hasInput = this.component && this.inputEl().length;
22983 if (typeof(this.minViewMode === 'string')) {
22984 switch (this.minViewMode) {
22986 this.minViewMode = 1;
22989 this.minViewMode = 2;
22992 this.minViewMode = 0;
22997 if (typeof(this.viewMode === 'string')) {
22998 switch (this.viewMode) {
23011 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.DateField.template);
23013 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.form.DateField.template);
23015 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
23017 this.picker().on('mousedown', this.onMousedown, this);
23018 this.picker().on('click', this.onClick, this);
23020 this.picker().addClass('datepicker-dropdown');
23022 this.startViewMode = this.viewMode;
23024 if(this.singleMode){
23025 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
23026 v.setVisibilityMode(Roo.Element.DISPLAY);
23030 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
23031 v.setStyle('width', '189px');
23035 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
23036 if(!this.calendarWeeks){
23041 v.dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].today;
23042 v.attr('colspan', function(i, val){
23043 return parseInt(val) + 1;
23048 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
23050 this.setStartDate(this.startDate);
23051 this.setEndDate(this.endDate);
23053 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
23060 if(this.isInline) {
23065 picker : function()
23067 return this.pickerEl;
23068 // return this.el.select('.datepicker', true).first();
23071 fillDow: function()
23073 var dowCnt = this.weekStart;
23082 if(this.calendarWeeks){
23090 while (dowCnt < this.weekStart + 7) {
23094 html: Roo.bootstrap.form.DateField.dates[this.language].daysMin[(dowCnt++)%7]
23098 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
23101 fillMonths: function()
23104 var months = this.picker().select('>.datepicker-months td', true).first();
23106 months.dom.innerHTML = '';
23112 html: Roo.bootstrap.form.DateField.dates[this.language].monthsShort[i++]
23115 months.createChild(month);
23122 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;
23124 if (this.date < this.startDate) {
23125 this.viewDate = new Date(this.startDate);
23126 } else if (this.date > this.endDate) {
23127 this.viewDate = new Date(this.endDate);
23129 this.viewDate = new Date(this.date);
23137 var d = new Date(this.viewDate),
23138 year = d.getUTCFullYear(),
23139 month = d.getUTCMonth(),
23140 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
23141 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
23142 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
23143 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
23144 currentDate = this.date && this.date.valueOf(),
23145 today = this.UTCToday();
23147 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].months[month]+' '+year;
23149 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].today;
23151 // this.picker.select('>tfoot th.today').
23152 // .text(dates[this.language].today)
23153 // .toggle(this.todayBtn !== false);
23155 this.updateNavArrows();
23158 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
23160 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
23162 prevMonth.setUTCDate(day);
23164 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
23166 var nextMonth = new Date(prevMonth);
23168 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
23170 nextMonth = nextMonth.valueOf();
23172 var fillMonths = false;
23174 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
23176 while(prevMonth.valueOf() <= nextMonth) {
23179 if (prevMonth.getUTCDay() === this.weekStart) {
23181 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
23189 if(this.calendarWeeks){
23190 // ISO 8601: First week contains first thursday.
23191 // ISO also states week starts on Monday, but we can be more abstract here.
23193 // Start of current week: based on weekstart/current date
23194 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
23195 // Thursday of this week
23196 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
23197 // First Thursday of year, year from thursday
23198 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
23199 // Calendar week: ms between thursdays, div ms per day, div 7 days
23200 calWeek = (th - yth) / 864e5 / 7 + 1;
23202 fillMonths.cn.push({
23210 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
23212 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
23215 if (this.todayHighlight &&
23216 prevMonth.getUTCFullYear() == today.getFullYear() &&
23217 prevMonth.getUTCMonth() == today.getMonth() &&
23218 prevMonth.getUTCDate() == today.getDate()) {
23219 clsName += ' today';
23222 if (currentDate && prevMonth.valueOf() === currentDate) {
23223 clsName += ' active';
23226 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
23227 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
23228 clsName += ' disabled';
23231 fillMonths.cn.push({
23233 cls: 'day ' + clsName,
23234 html: prevMonth.getDate()
23237 prevMonth.setDate(prevMonth.getDate()+1);
23240 var currentYear = this.date && this.date.getUTCFullYear();
23241 var currentMonth = this.date && this.date.getUTCMonth();
23243 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
23245 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
23246 v.removeClass('active');
23248 if(currentYear === year && k === currentMonth){
23249 v.addClass('active');
23252 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
23253 v.addClass('disabled');
23259 year = parseInt(year/10, 10) * 10;
23261 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
23263 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
23266 for (var i = -1; i < 11; i++) {
23267 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
23269 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
23277 showMode: function(dir)
23280 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
23283 Roo.each(this.picker().select('>div',true).elements, function(v){
23284 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
23287 this.picker().select('>.datepicker-'+Roo.bootstrap.form.DateField.modes[this.viewMode].clsName, true).first().show();
23292 if(this.isInline) {
23296 this.picker().removeClass(['bottom', 'top']);
23298 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
23300 * place to the top of element!
23304 this.picker().addClass('top');
23305 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
23310 this.picker().addClass('bottom');
23312 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
23315 parseDate : function(value)
23317 if(!value || value instanceof Date){
23320 var v = Date.parseDate(value, this.format);
23321 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
23322 v = Date.parseDate(value, 'Y-m-d');
23324 if(!v && this.altFormats){
23325 if(!this.altFormatsArray){
23326 this.altFormatsArray = this.altFormats.split("|");
23328 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
23329 v = Date.parseDate(value, this.altFormatsArray[i]);
23335 formatDate : function(date, fmt)
23337 return (!date || !(date instanceof Date)) ?
23338 date : date.dateFormat(fmt || this.format);
23341 onFocus : function()
23343 Roo.bootstrap.form.DateField.superclass.onFocus.call(this);
23347 onBlur : function()
23349 Roo.bootstrap.form.DateField.superclass.onBlur.call(this);
23351 var d = this.inputEl().getValue();
23358 showPopup : function()
23360 this.picker().show();
23364 this.fireEvent('showpopup', this, this.date);
23367 hidePopup : function()
23369 if(this.isInline) {
23372 this.picker().hide();
23373 this.viewMode = this.startViewMode;
23376 this.fireEvent('hidepopup', this, this.date);
23380 onMousedown: function(e)
23382 e.stopPropagation();
23383 e.preventDefault();
23388 Roo.bootstrap.form.DateField.superclass.keyup.call(this);
23392 setValue: function(v)
23394 if(this.fireEvent('beforeselect', this, v) !== false){
23395 var d = new Date(this.parseDate(v) ).clearTime();
23397 if(isNaN(d.getTime())){
23398 this.date = this.viewDate = '';
23399 Roo.bootstrap.form.DateField.superclass.setValue.call(this, '');
23403 v = this.formatDate(d);
23405 Roo.bootstrap.form.DateField.superclass.setValue.call(this, v);
23407 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
23411 this.fireEvent('select', this, this.date);
23415 getValue: function()
23417 return this.formatDate(this.date);
23420 fireKey: function(e)
23422 if (!this.picker().isVisible()){
23423 if (e.keyCode == 27) { // allow escape to hide and re-show picker
23429 var dateChanged = false,
23431 newDate, newViewDate;
23436 e.preventDefault();
23440 if (!this.keyboardNavigation) {
23443 dir = e.keyCode == 37 ? -1 : 1;
23446 newDate = this.moveYear(this.date, dir);
23447 newViewDate = this.moveYear(this.viewDate, dir);
23448 } else if (e.shiftKey){
23449 newDate = this.moveMonth(this.date, dir);
23450 newViewDate = this.moveMonth(this.viewDate, dir);
23452 newDate = new Date(this.date);
23453 newDate.setUTCDate(this.date.getUTCDate() + dir);
23454 newViewDate = new Date(this.viewDate);
23455 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
23457 if (this.dateWithinRange(newDate)){
23458 this.date = newDate;
23459 this.viewDate = newViewDate;
23460 this.setValue(this.formatDate(this.date));
23462 e.preventDefault();
23463 dateChanged = true;
23468 if (!this.keyboardNavigation) {
23471 dir = e.keyCode == 38 ? -1 : 1;
23473 newDate = this.moveYear(this.date, dir);
23474 newViewDate = this.moveYear(this.viewDate, dir);
23475 } else if (e.shiftKey){
23476 newDate = this.moveMonth(this.date, dir);
23477 newViewDate = this.moveMonth(this.viewDate, dir);
23479 newDate = new Date(this.date);
23480 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
23481 newViewDate = new Date(this.viewDate);
23482 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
23484 if (this.dateWithinRange(newDate)){
23485 this.date = newDate;
23486 this.viewDate = newViewDate;
23487 this.setValue(this.formatDate(this.date));
23489 e.preventDefault();
23490 dateChanged = true;
23494 this.setValue(this.formatDate(this.date));
23496 e.preventDefault();
23499 this.setValue(this.formatDate(this.date));
23513 onClick: function(e)
23515 e.stopPropagation();
23516 e.preventDefault();
23518 var target = e.getTarget();
23520 if(target.nodeName.toLowerCase() === 'i'){
23521 target = Roo.get(target).dom.parentNode;
23524 var nodeName = target.nodeName;
23525 var className = target.className;
23526 var html = target.innerHTML;
23527 //Roo.log(nodeName);
23529 switch(nodeName.toLowerCase()) {
23531 switch(className) {
23537 var dir = Roo.bootstrap.form.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
23538 switch(this.viewMode){
23540 this.viewDate = this.moveMonth(this.viewDate, dir);
23544 this.viewDate = this.moveYear(this.viewDate, dir);
23550 var date = new Date();
23551 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
23553 this.setValue(this.formatDate(this.date));
23560 if (className.indexOf('disabled') < 0) {
23561 if (!this.viewDate) {
23562 this.viewDate = new Date();
23564 this.viewDate.setUTCDate(1);
23565 if (className.indexOf('month') > -1) {
23566 this.viewDate.setUTCMonth(Roo.bootstrap.form.DateField.dates[this.language].monthsShort.indexOf(html));
23568 var year = parseInt(html, 10) || 0;
23569 this.viewDate.setUTCFullYear(year);
23573 if(this.singleMode){
23574 this.setValue(this.formatDate(this.viewDate));
23585 //Roo.log(className);
23586 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
23587 var day = parseInt(html, 10) || 1;
23588 var year = (this.viewDate || new Date()).getUTCFullYear(),
23589 month = (this.viewDate || new Date()).getUTCMonth();
23591 if (className.indexOf('old') > -1) {
23598 } else if (className.indexOf('new') > -1) {
23606 //Roo.log([year,month,day]);
23607 this.date = this.UTCDate(year, month, day,0,0,0,0);
23608 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
23610 //Roo.log(this.formatDate(this.date));
23611 this.setValue(this.formatDate(this.date));
23618 setStartDate: function(startDate)
23620 this.startDate = startDate || -Infinity;
23621 if (this.startDate !== -Infinity) {
23622 this.startDate = this.parseDate(this.startDate);
23625 this.updateNavArrows();
23628 setEndDate: function(endDate)
23630 this.endDate = endDate || Infinity;
23631 if (this.endDate !== Infinity) {
23632 this.endDate = this.parseDate(this.endDate);
23635 this.updateNavArrows();
23638 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
23640 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
23641 if (typeof(this.daysOfWeekDisabled) !== 'object') {
23642 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
23644 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
23645 return parseInt(d, 10);
23648 this.updateNavArrows();
23651 updateNavArrows: function()
23653 if(this.singleMode){
23657 var d = new Date(this.viewDate),
23658 year = d.getUTCFullYear(),
23659 month = d.getUTCMonth();
23661 Roo.each(this.picker().select('.prev', true).elements, function(v){
23663 switch (this.viewMode) {
23666 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
23672 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
23679 Roo.each(this.picker().select('.next', true).elements, function(v){
23681 switch (this.viewMode) {
23684 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
23690 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
23698 moveMonth: function(date, dir)
23703 var new_date = new Date(date.valueOf()),
23704 day = new_date.getUTCDate(),
23705 month = new_date.getUTCMonth(),
23706 mag = Math.abs(dir),
23708 dir = dir > 0 ? 1 : -1;
23711 // If going back one month, make sure month is not current month
23712 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
23714 return new_date.getUTCMonth() == month;
23716 // If going forward one month, make sure month is as expected
23717 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
23719 return new_date.getUTCMonth() != new_month;
23721 new_month = month + dir;
23722 new_date.setUTCMonth(new_month);
23723 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
23724 if (new_month < 0 || new_month > 11) {
23725 new_month = (new_month + 12) % 12;
23728 // For magnitudes >1, move one month at a time...
23729 for (var i=0; i<mag; i++) {
23730 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
23731 new_date = this.moveMonth(new_date, dir);
23733 // ...then reset the day, keeping it in the new month
23734 new_month = new_date.getUTCMonth();
23735 new_date.setUTCDate(day);
23737 return new_month != new_date.getUTCMonth();
23740 // Common date-resetting loop -- if date is beyond end of month, make it
23743 new_date.setUTCDate(--day);
23744 new_date.setUTCMonth(new_month);
23749 moveYear: function(date, dir)
23751 return this.moveMonth(date, dir*12);
23754 dateWithinRange: function(date)
23756 return date >= this.startDate && date <= this.endDate;
23762 this.picker().remove();
23765 validateValue : function(value)
23767 if(this.getVisibilityEl().hasClass('hidden')){
23771 if(value.length < 1) {
23772 if(this.allowBlank){
23778 if(value.length < this.minLength){
23781 if(value.length > this.maxLength){
23785 var vt = Roo.form.VTypes;
23786 if(!vt[this.vtype](value, this)){
23790 if(typeof this.validator == "function"){
23791 var msg = this.validator(value);
23797 if(this.regex && !this.regex.test(value)){
23801 if(typeof(this.parseDate(value)) == 'undefined'){
23805 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
23809 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
23819 this.date = this.viewDate = '';
23821 Roo.bootstrap.form.DateField.superclass.setValue.call(this, '');
23826 Roo.apply(Roo.bootstrap.form.DateField, {
23837 html: '<i class="fa fa-arrow-left"/>'
23847 html: '<i class="fa fa-arrow-right"/>'
23889 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
23890 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
23891 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
23892 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
23893 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
23906 navFnc: 'FullYear',
23911 navFnc: 'FullYear',
23916 Roo.apply(Roo.bootstrap.form.DateField, {
23920 cls: 'datepicker dropdown-menu roo-dynamic shadow',
23924 cls: 'datepicker-days',
23928 cls: 'table-condensed',
23930 Roo.bootstrap.form.DateField.head,
23934 Roo.bootstrap.form.DateField.footer
23941 cls: 'datepicker-months',
23945 cls: 'table-condensed',
23947 Roo.bootstrap.form.DateField.head,
23948 Roo.bootstrap.form.DateField.content,
23949 Roo.bootstrap.form.DateField.footer
23956 cls: 'datepicker-years',
23960 cls: 'table-condensed',
23962 Roo.bootstrap.form.DateField.head,
23963 Roo.bootstrap.form.DateField.content,
23964 Roo.bootstrap.form.DateField.footer
23983 * @class Roo.bootstrap.form.TimeField
23984 * @extends Roo.bootstrap.form.Input
23985 * Bootstrap DateField class
23989 * Create a new TimeField
23990 * @param {Object} config The config object
23993 Roo.bootstrap.form.TimeField = function(config){
23994 Roo.bootstrap.form.TimeField.superclass.constructor.call(this, config);
23998 * Fires when this field show.
23999 * @param {Roo.bootstrap.form.DateField} thisthis
24000 * @param {Mixed} date The date value
24005 * Fires when this field hide.
24006 * @param {Roo.bootstrap.form.DateField} this
24007 * @param {Mixed} date The date value
24012 * Fires when select a date.
24013 * @param {Roo.bootstrap.form.DateField} this
24014 * @param {Mixed} date The date value
24020 Roo.extend(Roo.bootstrap.form.TimeField, Roo.bootstrap.form.Input, {
24023 * @cfg {String} format
24024 * The default time format string which can be overriden for localization support. The format must be
24025 * valid according to {@link Date#parseDate} (defaults to 'H:i').
24029 getAutoCreate : function()
24031 this.after = '<i class="fa far fa-clock"></i>';
24032 return Roo.bootstrap.form.TimeField.superclass.getAutoCreate.call(this);
24036 onRender: function(ct, position)
24039 Roo.bootstrap.form.TimeField.superclass.onRender.call(this, ct, position);
24041 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.TimeField.template);
24043 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24045 this.pop = this.picker().select('>.datepicker-time',true).first();
24046 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24048 this.picker().on('mousedown', this.onMousedown, this);
24049 this.picker().on('click', this.onClick, this);
24051 this.picker().addClass('datepicker-dropdown');
24056 this.pop.select('.hours-up', true).first().on('click', this.onIncrementHours, this);
24057 this.pop.select('.hours-down', true).first().on('click', this.onDecrementHours, this);
24058 this.pop.select('.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
24059 this.pop.select('.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
24060 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
24061 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
24065 fireKey: function(e){
24066 if (!this.picker().isVisible()){
24067 if (e.keyCode == 27) { // allow escape to hide and re-show picker
24073 e.preventDefault();
24081 this.onTogglePeriod();
24084 this.onIncrementMinutes();
24087 this.onDecrementMinutes();
24096 onClick: function(e) {
24097 e.stopPropagation();
24098 e.preventDefault();
24101 picker : function()
24103 return this.pickerEl;
24106 fillTime: function()
24108 var time = this.pop.select('tbody', true).first();
24110 time.dom.innerHTML = '';
24125 cls: 'hours-up fa fas fa-chevron-up'
24145 cls: 'minutes-up fa fas fa-chevron-up'
24166 cls: 'timepicker-hour',
24181 cls: 'timepicker-minute',
24196 cls: 'btn btn-primary period',
24218 cls: 'hours-down fa fas fa-chevron-down'
24238 cls: 'minutes-down fa fas fa-chevron-down'
24256 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
24263 var hours = this.time.getHours();
24264 var minutes = this.time.getMinutes();
24277 hours = hours - 12;
24281 hours = '0' + hours;
24285 minutes = '0' + minutes;
24288 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
24289 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
24290 this.pop.select('button', true).first().dom.innerHTML = period;
24296 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
24298 var cls = ['bottom'];
24300 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
24307 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
24311 //this.picker().setXY(20000,20000);
24312 this.picker().addClass(cls.join('-'));
24316 Roo.each(cls, function(c){
24321 _this.picker().alignTo(_this.inputEl(), "tr-br", [0, 10], false);
24322 //_this.picker().setTop(_this.inputEl().getHeight());
24326 _this.picker().alignTo(_this.inputEl(), "br-tr", [0, 10], false);
24328 //_this.picker().setTop(0 - _this.picker().getHeight());
24333 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
24337 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
24345 onFocus : function()
24347 Roo.bootstrap.form.TimeField.superclass.onFocus.call(this);
24351 onBlur : function()
24353 Roo.bootstrap.form.TimeField.superclass.onBlur.call(this);
24359 this.picker().show();
24364 this.fireEvent('show', this, this.date);
24369 this.picker().hide();
24372 this.fireEvent('hide', this, this.date);
24375 setTime : function()
24378 this.setValue(this.time.format(this.format));
24380 this.fireEvent('select', this, this.date);
24385 onMousedown: function(e){
24386 e.stopPropagation();
24387 e.preventDefault();
24390 onIncrementHours: function()
24392 Roo.log('onIncrementHours');
24393 this.time = this.time.add(Date.HOUR, 1);
24398 onDecrementHours: function()
24400 Roo.log('onDecrementHours');
24401 this.time = this.time.add(Date.HOUR, -1);
24405 onIncrementMinutes: function()
24407 Roo.log('onIncrementMinutes');
24408 this.time = this.time.add(Date.MINUTE, 1);
24412 onDecrementMinutes: function()
24414 Roo.log('onDecrementMinutes');
24415 this.time = this.time.add(Date.MINUTE, -1);
24419 onTogglePeriod: function()
24421 Roo.log('onTogglePeriod');
24422 this.time = this.time.add(Date.HOUR, 12);
24430 Roo.apply(Roo.bootstrap.form.TimeField, {
24434 cls: 'datepicker dropdown-menu',
24438 cls: 'datepicker-time',
24442 cls: 'table-condensed',
24471 cls: 'btn btn-info ok',
24499 * @class Roo.bootstrap.form.MonthField
24500 * @extends Roo.bootstrap.form.Input
24501 * Bootstrap MonthField class
24503 * @cfg {String} language default en
24506 * Create a new MonthField
24507 * @param {Object} config The config object
24510 Roo.bootstrap.form.MonthField = function(config){
24511 Roo.bootstrap.form.MonthField.superclass.constructor.call(this, config);
24516 * Fires when this field show.
24517 * @param {Roo.bootstrap.form.MonthField} this
24518 * @param {Mixed} date The date value
24523 * Fires when this field hide.
24524 * @param {Roo.bootstrap.form.MonthField} this
24525 * @param {Mixed} date The date value
24530 * Fires when select a date.
24531 * @param {Roo.bootstrap.form.MonthField} this
24532 * @param {String} oldvalue The old value
24533 * @param {String} newvalue The new value
24539 Roo.extend(Roo.bootstrap.form.MonthField, Roo.bootstrap.form.Input, {
24541 onRender: function(ct, position)
24544 Roo.bootstrap.form.MonthField.superclass.onRender.call(this, ct, position);
24546 this.language = this.language || 'en';
24547 this.language = this.language in Roo.bootstrap.form.MonthField.dates ? this.language : this.language.split('-')[0];
24548 this.language = this.language in Roo.bootstrap.form.MonthField.dates ? this.language : "en";
24550 this.isRTL = Roo.bootstrap.form.MonthField.dates[this.language].rtl || false;
24551 this.isInline = false;
24552 this.isInput = true;
24553 this.component = this.el.select('.add-on', true).first() || false;
24554 this.component = (this.component && this.component.length === 0) ? false : this.component;
24555 this.hasInput = this.component && this.inputEL().length;
24557 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.MonthField.template);
24559 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24561 this.picker().on('mousedown', this.onMousedown, this);
24562 this.picker().on('click', this.onClick, this);
24564 this.picker().addClass('datepicker-dropdown');
24566 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
24567 v.setStyle('width', '189px');
24574 if(this.isInline) {
24580 setValue: function(v, suppressEvent)
24582 var o = this.getValue();
24584 Roo.bootstrap.form.MonthField.superclass.setValue.call(this, v);
24588 if(suppressEvent !== true){
24589 this.fireEvent('select', this, o, v);
24594 getValue: function()
24599 onClick: function(e)
24601 e.stopPropagation();
24602 e.preventDefault();
24604 var target = e.getTarget();
24606 if(target.nodeName.toLowerCase() === 'i'){
24607 target = Roo.get(target).dom.parentNode;
24610 var nodeName = target.nodeName;
24611 var className = target.className;
24612 var html = target.innerHTML;
24614 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
24618 this.vIndex = Roo.bootstrap.form.MonthField.dates[this.language].monthsShort.indexOf(html);
24620 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24626 picker : function()
24628 return this.pickerEl;
24631 fillMonths: function()
24634 var months = this.picker().select('>.datepicker-months td', true).first();
24636 months.dom.innerHTML = '';
24642 html: Roo.bootstrap.form.MonthField.dates[this.language].monthsShort[i++]
24645 months.createChild(month);
24654 if(typeof(this.vIndex) == 'undefined' && this.value.length){
24655 this.vIndex = Roo.bootstrap.form.MonthField.dates[this.language].months.indexOf(this.value);
24658 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
24659 e.removeClass('active');
24661 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
24662 e.addClass('active');
24669 if(this.isInline) {
24673 this.picker().removeClass(['bottom', 'top']);
24675 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
24677 * place to the top of element!
24681 this.picker().addClass('top');
24682 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
24687 this.picker().addClass('bottom');
24689 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
24692 onFocus : function()
24694 Roo.bootstrap.form.MonthField.superclass.onFocus.call(this);
24698 onBlur : function()
24700 Roo.bootstrap.form.MonthField.superclass.onBlur.call(this);
24702 var d = this.inputEl().getValue();
24711 this.picker().show();
24712 this.picker().select('>.datepicker-months', true).first().show();
24716 this.fireEvent('show', this, this.date);
24721 if(this.isInline) {
24724 this.picker().hide();
24725 this.fireEvent('hide', this, this.date);
24729 onMousedown: function(e)
24731 e.stopPropagation();
24732 e.preventDefault();
24737 Roo.bootstrap.form.MonthField.superclass.keyup.call(this);
24741 fireKey: function(e)
24743 if (!this.picker().isVisible()){
24744 if (e.keyCode == 27) {// allow escape to hide and re-show picker
24755 e.preventDefault();
24759 dir = e.keyCode == 37 ? -1 : 1;
24761 this.vIndex = this.vIndex + dir;
24763 if(this.vIndex < 0){
24767 if(this.vIndex > 11){
24771 if(isNaN(this.vIndex)){
24775 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24781 dir = e.keyCode == 38 ? -1 : 1;
24783 this.vIndex = this.vIndex + dir * 4;
24785 if(this.vIndex < 0){
24789 if(this.vIndex > 11){
24793 if(isNaN(this.vIndex)){
24797 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24802 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
24803 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24807 e.preventDefault();
24810 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
24811 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24827 this.picker().remove();
24832 Roo.apply(Roo.bootstrap.form.MonthField, {
24851 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
24852 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
24857 Roo.apply(Roo.bootstrap.form.MonthField, {
24861 cls: 'datepicker dropdown-menu roo-dynamic',
24865 cls: 'datepicker-months',
24869 cls: 'table-condensed',
24871 Roo.bootstrap.form.DateField.content
24891 * @class Roo.bootstrap.form.CheckBox
24892 * @extends Roo.bootstrap.form.Input
24893 * Bootstrap CheckBox class
24895 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
24896 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
24897 * @cfg {String} boxLabel The text that appears beside the checkbox
24898 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
24899 * @cfg {Boolean} checked initnal the element
24900 * @cfg {Boolean} inline inline the element (default false)
24901 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
24902 * @cfg {String} tooltip label tooltip
24905 * Create a new CheckBox
24906 * @param {Object} config The config object
24909 Roo.bootstrap.form.CheckBox = function(config){
24910 Roo.bootstrap.form.CheckBox.superclass.constructor.call(this, config);
24915 * Fires when the element is checked or unchecked.
24916 * @param {Roo.bootstrap.form.CheckBox} this This input
24917 * @param {Boolean} checked The new checked value
24922 * Fires when the element is click.
24923 * @param {Roo.bootstrap.form.CheckBox} this This input
24930 Roo.extend(Roo.bootstrap.form.CheckBox, Roo.bootstrap.form.Input, {
24932 inputType: 'checkbox',
24941 // checkbox success does not make any sense really..
24946 getAutoCreate : function()
24948 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
24954 cfg.cls = 'form-group form-check ' + this.inputType; //input-group
24957 cfg.cls += ' ' + this.inputType + '-inline form-check-inline';
24963 type : this.inputType,
24964 value : this.inputValue,
24965 cls : 'roo-' + this.inputType, //'form-box',
24966 placeholder : this.placeholder || ''
24970 if(this.inputType != 'radio'){
24974 cls : 'roo-hidden-value',
24975 value : this.checked ? this.inputValue : this.valueOff
24980 if (this.weight) { // Validity check?
24981 cfg.cls += " " + this.inputType + "-" + this.weight;
24984 if (this.disabled) {
24985 input.disabled=true;
24989 input.checked = this.checked;
24994 input.name = this.name;
24996 if(this.inputType != 'radio'){
24997 hidden.name = this.name;
24998 input.name = '_hidden_' + this.name;
25003 input.cls += ' input-' + this.size;
25008 ['xs','sm','md','lg'].map(function(size){
25009 if (settings[size]) {
25010 cfg.cls += ' col-' + size + '-' + settings[size];
25014 var inputblock = input;
25016 if (this.before || this.after) {
25019 cls : 'input-group',
25024 inputblock.cn.push({
25026 cls : 'input-group-addon',
25031 inputblock.cn.push(input);
25033 if(this.inputType != 'radio'){
25034 inputblock.cn.push(hidden);
25038 inputblock.cn.push({
25040 cls : 'input-group-addon',
25046 var boxLabelCfg = false;
25052 //'for': id, // box label is handled by onclick - so no for...
25054 html: this.boxLabel
25057 boxLabelCfg.tooltip = this.tooltip;
25063 if (align ==='left' && this.fieldLabel.length) {
25064 // Roo.log("left and has label");
25069 cls : 'control-label',
25070 html : this.fieldLabel
25081 cfg.cn[1].cn.push(boxLabelCfg);
25084 if(this.labelWidth > 12){
25085 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
25088 if(this.labelWidth < 13 && this.labelmd == 0){
25089 this.labelmd = this.labelWidth;
25092 if(this.labellg > 0){
25093 cfg.cn[0].cls += ' col-lg-' + this.labellg;
25094 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
25097 if(this.labelmd > 0){
25098 cfg.cn[0].cls += ' col-md-' + this.labelmd;
25099 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
25102 if(this.labelsm > 0){
25103 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
25104 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
25107 if(this.labelxs > 0){
25108 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
25109 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
25112 } else if ( this.fieldLabel.length) {
25113 // Roo.log(" label");
25117 tag: this.boxLabel ? 'span' : 'label',
25119 cls: 'control-label box-input-label',
25120 //cls : 'input-group-addon',
25121 html : this.fieldLabel
25128 cfg.cn.push(boxLabelCfg);
25133 // Roo.log(" no label && no align");
25134 cfg.cn = [ inputblock ] ;
25136 cfg.cn.push(boxLabelCfg);
25144 if(this.inputType != 'radio'){
25145 cfg.cn.push(hidden);
25153 * return the real input element.
25155 inputEl: function ()
25157 return this.el.select('input.roo-' + this.inputType,true).first();
25159 hiddenEl: function ()
25161 return this.el.select('input.roo-hidden-value',true).first();
25164 labelEl: function()
25166 return this.el.select('label.control-label',true).first();
25168 /* depricated... */
25172 return this.labelEl();
25175 boxLabelEl: function()
25177 return this.el.select('label.box-label',true).first();
25180 initEvents : function()
25182 // Roo.bootstrap.form.CheckBox.superclass.initEvents.call(this);
25184 this.inputEl().on('click', this.onClick, this);
25186 if (this.boxLabel) {
25187 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
25190 this.startValue = this.getValue();
25193 Roo.bootstrap.form.CheckBox.register(this);
25197 onClick : function(e)
25199 if(this.fireEvent('click', this, e) !== false){
25200 this.setChecked(!this.checked);
25205 setChecked : function(state,suppressEvent)
25207 this.startValue = this.getValue();
25209 if(this.inputType == 'radio'){
25211 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25212 e.dom.checked = false;
25215 this.inputEl().dom.checked = true;
25217 this.inputEl().dom.value = this.inputValue;
25219 if(suppressEvent !== true){
25220 this.fireEvent('check', this, true);
25228 this.checked = state;
25230 this.inputEl().dom.checked = state;
25233 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
25235 if(suppressEvent !== true){
25236 this.fireEvent('check', this, state);
25242 getValue : function()
25244 if(this.inputType == 'radio'){
25245 return this.getGroupValue();
25248 return this.hiddenEl().dom.value;
25252 getGroupValue : function()
25254 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
25258 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
25261 setValue : function(v,suppressEvent)
25263 if(this.inputType == 'radio'){
25264 this.setGroupValue(v, suppressEvent);
25268 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
25273 setGroupValue : function(v, suppressEvent)
25275 this.startValue = this.getValue();
25277 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25278 e.dom.checked = false;
25280 if(e.dom.value == v){
25281 e.dom.checked = true;
25285 if(suppressEvent !== true){
25286 this.fireEvent('check', this, true);
25294 validate : function()
25296 if(this.getVisibilityEl().hasClass('hidden')){
25302 (this.inputType == 'radio' && this.validateRadio()) ||
25303 (this.inputType == 'checkbox' && this.validateCheckbox())
25309 this.markInvalid();
25313 validateRadio : function()
25315 if(this.getVisibilityEl().hasClass('hidden')){
25319 if(this.allowBlank){
25325 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25326 if(!e.dom.checked){
25338 validateCheckbox : function()
25341 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
25342 //return (this.getValue() == this.inputValue) ? true : false;
25345 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25353 for(var i in group){
25354 if(group[i].el.isVisible(true)){
25362 for(var i in group){
25367 r = (group[i].getValue() == group[i].inputValue) ? true : false;
25374 * Mark this field as valid
25376 markValid : function()
25380 this.fireEvent('valid', this);
25382 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25385 label = Roo.bootstrap.form.FieldLabel.get(this.groupId + '-group');
25392 if(this.inputType == 'radio'){
25393 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25394 var fg = e.findParent('.form-group', false, true);
25395 if (Roo.bootstrap.version == 3) {
25396 fg.removeClass([_this.invalidClass, _this.validClass]);
25397 fg.addClass(_this.validClass);
25399 fg.removeClass(['is-valid', 'is-invalid']);
25400 fg.addClass('is-valid');
25408 var fg = this.el.findParent('.form-group', false, true);
25409 if (Roo.bootstrap.version == 3) {
25410 fg.removeClass([this.invalidClass, this.validClass]);
25411 fg.addClass(this.validClass);
25413 fg.removeClass(['is-valid', 'is-invalid']);
25414 fg.addClass('is-valid');
25419 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25425 for(var i in group){
25426 var fg = group[i].el.findParent('.form-group', false, true);
25427 if (Roo.bootstrap.version == 3) {
25428 fg.removeClass([this.invalidClass, this.validClass]);
25429 fg.addClass(this.validClass);
25431 fg.removeClass(['is-valid', 'is-invalid']);
25432 fg.addClass('is-valid');
25438 * Mark this field as invalid
25439 * @param {String} msg The validation message
25441 markInvalid : function(msg)
25443 if(this.allowBlank){
25449 this.fireEvent('invalid', this, msg);
25451 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25454 label = Roo.bootstrap.form.FieldLabel.get(this.groupId + '-group');
25458 label.markInvalid();
25461 if(this.inputType == 'radio'){
25463 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25464 var fg = e.findParent('.form-group', false, true);
25465 if (Roo.bootstrap.version == 3) {
25466 fg.removeClass([_this.invalidClass, _this.validClass]);
25467 fg.addClass(_this.invalidClass);
25469 fg.removeClass(['is-invalid', 'is-valid']);
25470 fg.addClass('is-invalid');
25478 var fg = this.el.findParent('.form-group', false, true);
25479 if (Roo.bootstrap.version == 3) {
25480 fg.removeClass([_this.invalidClass, _this.validClass]);
25481 fg.addClass(_this.invalidClass);
25483 fg.removeClass(['is-invalid', 'is-valid']);
25484 fg.addClass('is-invalid');
25489 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25495 for(var i in group){
25496 var fg = group[i].el.findParent('.form-group', false, true);
25497 if (Roo.bootstrap.version == 3) {
25498 fg.removeClass([_this.invalidClass, _this.validClass]);
25499 fg.addClass(_this.invalidClass);
25501 fg.removeClass(['is-invalid', 'is-valid']);
25502 fg.addClass('is-invalid');
25508 clearInvalid : function()
25510 Roo.bootstrap.form.Input.prototype.clearInvalid.call(this);
25512 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
25514 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25516 if (label && label.iconEl) {
25517 label.iconEl.removeClass([ label.validClass, label.invalidClass ]);
25518 label.iconEl.removeClass(['is-invalid', 'is-valid']);
25522 disable : function()
25524 if(this.inputType != 'radio'){
25525 Roo.bootstrap.form.CheckBox.superclass.disable.call(this);
25532 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25533 _this.getActionEl().addClass(this.disabledClass);
25534 e.dom.disabled = true;
25538 this.disabled = true;
25539 this.fireEvent("disable", this);
25543 enable : function()
25545 if(this.inputType != 'radio'){
25546 Roo.bootstrap.form.CheckBox.superclass.enable.call(this);
25553 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25554 _this.getActionEl().removeClass(this.disabledClass);
25555 e.dom.disabled = false;
25559 this.disabled = false;
25560 this.fireEvent("enable", this);
25564 setBoxLabel : function(v)
25569 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
25575 Roo.apply(Roo.bootstrap.form.CheckBox, {
25580 * register a CheckBox Group
25581 * @param {Roo.bootstrap.form.CheckBox} the CheckBox to add
25583 register : function(checkbox)
25585 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
25586 this.groups[checkbox.groupId] = {};
25589 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
25593 this.groups[checkbox.groupId][checkbox.name] = checkbox;
25597 * fetch a CheckBox Group based on the group ID
25598 * @param {string} the group ID
25599 * @returns {Roo.bootstrap.form.CheckBox} the CheckBox group
25601 get: function(groupId) {
25602 if (typeof(this.groups[groupId]) == 'undefined') {
25606 return this.groups[groupId] ;
25619 * @class Roo.bootstrap.form.Radio
25620 * @extends Roo.bootstrap.Component
25621 * Bootstrap Radio class
25622 * @cfg {String} boxLabel - the label associated
25623 * @cfg {String} value - the value of radio
25626 * Create a new Radio
25627 * @param {Object} config The config object
25629 Roo.bootstrap.form.Radio = function(config){
25630 Roo.bootstrap.form.Radio.superclass.constructor.call(this, config);
25634 Roo.extend(Roo.bootstrap.form.Radio, Roo.bootstrap.Component, {
25640 getAutoCreate : function()
25644 cls : 'form-group radio',
25649 html : this.boxLabel
25657 initEvents : function()
25659 this.parent().register(this);
25661 this.el.on('click', this.onClick, this);
25665 onClick : function(e)
25667 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
25668 this.setChecked(true);
25672 setChecked : function(state, suppressEvent)
25674 this.parent().setValue(this.value, suppressEvent);
25678 setBoxLabel : function(v)
25683 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
25698 * @class Roo.bootstrap.form.SecurePass
25699 * @extends Roo.bootstrap.form.Input
25700 * Bootstrap SecurePass class
25704 * Create a new SecurePass
25705 * @param {Object} config The config object
25708 Roo.bootstrap.form.SecurePass = function (config) {
25709 // these go here, so the translation tool can replace them..
25711 PwdEmpty: "Please type a password, and then retype it to confirm.",
25712 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
25713 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
25714 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
25715 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
25716 FNInPwd: "Your password can't contain your first name. Please type a different password.",
25717 LNInPwd: "Your password can't contain your last name. Please type a different password.",
25718 TooWeak: "Your password is Too Weak."
25720 this.meterLabel = "Password strength:";
25721 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
25722 this.meterClass = [
25723 "roo-password-meter-tooweak",
25724 "roo-password-meter-weak",
25725 "roo-password-meter-medium",
25726 "roo-password-meter-strong",
25727 "roo-password-meter-grey"
25732 Roo.bootstrap.form.SecurePass.superclass.constructor.call(this, config);
25735 Roo.extend(Roo.bootstrap.form.SecurePass, Roo.bootstrap.form.Input, {
25737 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
25739 * PwdEmpty: "Please type a password, and then retype it to confirm.",
25740 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
25741 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
25742 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
25743 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
25744 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
25745 * LNInPwd: "Your password can't contain your last name. Please type a different password."
25755 * @cfg {String/Object} Label for the strength meter (defaults to
25756 * 'Password strength:')
25761 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
25762 * ['Weak', 'Medium', 'Strong'])
25765 pwdStrengths: false,
25778 initEvents: function ()
25780 Roo.bootstrap.form.SecurePass.superclass.initEvents.call(this);
25782 if (this.el.is('input[type=password]') && Roo.isSafari) {
25783 this.el.on('keydown', this.SafariOnKeyDown, this);
25786 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
25789 onRender: function (ct, position)
25791 Roo.bootstrap.form.SecurePass.superclass.onRender.call(this, ct, position);
25792 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
25793 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
25795 this.trigger.createChild({
25800 cls: 'roo-password-meter-grey col-xs-12',
25803 //width: this.meterWidth + 'px'
25807 cls: 'roo-password-meter-text'
25813 if (this.hideTrigger) {
25814 this.trigger.setDisplayed(false);
25816 this.setSize(this.width || '', this.height || '');
25819 onDestroy: function ()
25821 if (this.trigger) {
25822 this.trigger.removeAllListeners();
25823 this.trigger.remove();
25826 this.wrap.remove();
25828 Roo.bootstrap.form.TriggerField.superclass.onDestroy.call(this);
25831 checkStrength: function ()
25833 var pwd = this.inputEl().getValue();
25834 if (pwd == this._lastPwd) {
25839 if (this.ClientSideStrongPassword(pwd)) {
25841 } else if (this.ClientSideMediumPassword(pwd)) {
25843 } else if (this.ClientSideWeakPassword(pwd)) {
25849 Roo.log('strength1: ' + strength);
25851 //var pm = this.trigger.child('div/div/div').dom;
25852 var pm = this.trigger.child('div/div');
25853 pm.removeClass(this.meterClass);
25854 pm.addClass(this.meterClass[strength]);
25857 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25859 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
25861 this._lastPwd = pwd;
25865 Roo.bootstrap.form.SecurePass.superclass.reset.call(this);
25867 this._lastPwd = '';
25869 var pm = this.trigger.child('div/div');
25870 pm.removeClass(this.meterClass);
25871 pm.addClass('roo-password-meter-grey');
25874 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25877 this.inputEl().dom.type='password';
25880 validateValue: function (value)
25882 if (!Roo.bootstrap.form.SecurePass.superclass.validateValue.call(this, value)) {
25885 if (value.length == 0) {
25886 if (this.allowBlank) {
25887 this.clearInvalid();
25891 this.markInvalid(this.errors.PwdEmpty);
25892 this.errorMsg = this.errors.PwdEmpty;
25900 if (!value.match(/[\x21-\x7e]+/)) {
25901 this.markInvalid(this.errors.PwdBadChar);
25902 this.errorMsg = this.errors.PwdBadChar;
25905 if (value.length < 6) {
25906 this.markInvalid(this.errors.PwdShort);
25907 this.errorMsg = this.errors.PwdShort;
25910 if (value.length > 16) {
25911 this.markInvalid(this.errors.PwdLong);
25912 this.errorMsg = this.errors.PwdLong;
25916 if (this.ClientSideStrongPassword(value)) {
25918 } else if (this.ClientSideMediumPassword(value)) {
25920 } else if (this.ClientSideWeakPassword(value)) {
25927 if (strength < 2) {
25928 //this.markInvalid(this.errors.TooWeak);
25929 this.errorMsg = this.errors.TooWeak;
25934 console.log('strength2: ' + strength);
25936 //var pm = this.trigger.child('div/div/div').dom;
25938 var pm = this.trigger.child('div/div');
25939 pm.removeClass(this.meterClass);
25940 pm.addClass(this.meterClass[strength]);
25942 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25944 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
25946 this.errorMsg = '';
25950 CharacterSetChecks: function (type)
25953 this.fResult = false;
25956 isctype: function (character, type)
25959 case this.kCapitalLetter:
25960 if (character >= 'A' && character <= 'Z') {
25965 case this.kSmallLetter:
25966 if (character >= 'a' && character <= 'z') {
25972 if (character >= '0' && character <= '9') {
25977 case this.kPunctuation:
25978 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
25989 IsLongEnough: function (pwd, size)
25991 return !(pwd == null || isNaN(size) || pwd.length < size);
25994 SpansEnoughCharacterSets: function (word, nb)
25996 if (!this.IsLongEnough(word, nb))
26001 var characterSetChecks = new Array(
26002 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
26003 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
26006 for (var index = 0; index < word.length; ++index) {
26007 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
26008 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
26009 characterSetChecks[nCharSet].fResult = true;
26016 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
26017 if (characterSetChecks[nCharSet].fResult) {
26022 if (nCharSets < nb) {
26028 ClientSideStrongPassword: function (pwd)
26030 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
26033 ClientSideMediumPassword: function (pwd)
26035 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
26038 ClientSideWeakPassword: function (pwd)
26040 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
26044 Roo.htmleditor = {};
26047 * @class Roo.htmleditor.Filter
26048 * Base Class for filtering htmleditor stuff. - do not use this directly - extend it.
26049 * @cfg {DomElement} node The node to iterate and filter
26050 * @cfg {boolean|String|Array} tag Tags to replace
26052 * Create a new Filter.
26053 * @param {Object} config Configuration options
26058 Roo.htmleditor.Filter = function(cfg) {
26059 Roo.apply(this.cfg);
26060 // this does not actually call walk as it's really just a abstract class
26064 Roo.htmleditor.Filter.prototype = {
26070 // overrride to do replace comments.
26071 replaceComment : false,
26073 // overrride to do replace or do stuff with tags..
26074 replaceTag : false,
26076 walk : function(dom)
26078 Roo.each( Array.from(dom.childNodes), function( e ) {
26081 case e.nodeType == 8 && this.replaceComment !== false: // comment
26082 this.replaceComment(e);
26085 case e.nodeType != 1: //not a node.
26088 case this.tag === true: // everything
26089 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1:
26090 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":":
26091 case typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1: // array and it matches.
26092 case typeof(this.tag) == 'string' && this.tag == e.tagName: // array and it matches.
26093 if (this.replaceTag && false === this.replaceTag(e)) {
26096 if (e.hasChildNodes()) {
26101 default: // tags .. that do not match.
26102 if (e.hasChildNodes()) {
26112 removeNodeKeepChildren : function( node)
26115 ar = Array.from(node.childNodes);
26116 for (var i = 0; i < ar.length; i++) {
26118 node.removeChild(ar[i]);
26119 // what if we need to walk these???
26120 node.parentNode.insertBefore(ar[i], node);
26123 node.parentNode.removeChild(node);
26128 * @class Roo.htmleditor.FilterAttributes
26129 * clean attributes and styles including http:// etc.. in attribute
26131 * Run a new Attribute Filter
26132 * @param {Object} config Configuration options
26134 Roo.htmleditor.FilterAttributes = function(cfg)
26136 Roo.apply(this, cfg);
26137 this.attrib_black = this.attrib_black || [];
26138 this.attrib_white = this.attrib_white || [];
26140 this.attrib_clean = this.attrib_clean || [];
26141 this.style_white = this.style_white || [];
26142 this.style_black = this.style_black || [];
26143 this.walk(cfg.node);
26146 Roo.extend(Roo.htmleditor.FilterAttributes, Roo.htmleditor.Filter,
26148 tag: true, // all tags
26150 attrib_black : false, // array
26151 attrib_clean : false,
26152 attrib_white : false,
26154 style_white : false,
26155 style_black : false,
26158 replaceTag : function(node)
26160 if (!node.attributes || !node.attributes.length) {
26164 for (var i = node.attributes.length-1; i > -1 ; i--) {
26165 var a = node.attributes[i];
26167 if (this.attrib_white.length && this.attrib_white.indexOf(a.name.toLowerCase()) < 0) {
26168 node.removeAttribute(a.name);
26174 if (a.name.toLowerCase().substr(0,2)=='on') {
26175 node.removeAttribute(a.name);
26180 if (this.attrib_black.indexOf(a.name.toLowerCase()) > -1) {
26181 node.removeAttribute(a.name);
26184 if (this.attrib_clean.indexOf(a.name.toLowerCase()) > -1) {
26185 this.cleanAttr(node,a.name,a.value); // fixme..
26188 if (a.name == 'style') {
26189 this.cleanStyle(node,a.name,a.value);
26192 /// clean up MS crap..
26193 // tecnically this should be a list of valid class'es..
26196 if (a.name == 'class') {
26197 if (a.value.match(/^Mso/)) {
26198 node.removeAttribute('class');
26201 if (a.value.match(/^body$/)) {
26202 node.removeAttribute('class');
26212 return true; // clean children
26215 cleanAttr: function(node, n,v)
26218 if (v.match(/^\./) || v.match(/^\//)) {
26221 if (v.match(/^(http|https):\/\//)
26222 || v.match(/^mailto:/)
26223 || v.match(/^ftp:/)
26224 || v.match(/^data:/)
26228 if (v.match(/^#/)) {
26231 if (v.match(/^\{/)) { // allow template editing.
26234 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
26235 node.removeAttribute(n);
26238 cleanStyle : function(node, n,v)
26240 if (v.match(/expression/)) { //XSS?? should we even bother..
26241 node.removeAttribute(n);
26245 var parts = v.split(/;/);
26248 Roo.each(parts, function(p) {
26249 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
26253 var l = p.split(':').shift().replace(/\s+/g,'');
26254 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
26256 if ( this.style_black.length && (this.style_black.indexOf(l) > -1 || this.style_black.indexOf(l.toLowerCase()) > -1)) {
26260 // only allow 'c whitelisted system attributes'
26261 if ( this.style_white.length && style_white.indexOf(l) < 0 && style_white.indexOf(l.toLowerCase()) < 0 ) {
26269 if (clean.length) {
26270 node.setAttribute(n, clean.join(';'));
26272 node.removeAttribute(n);
26281 * @class Roo.htmleditor.FilterBlack
26282 * remove blacklisted elements.
26284 * Run a new Blacklisted Filter
26285 * @param {Object} config Configuration options
26288 Roo.htmleditor.FilterBlack = function(cfg)
26290 Roo.apply(this, cfg);
26291 this.walk(cfg.node);
26294 Roo.extend(Roo.htmleditor.FilterBlack, Roo.htmleditor.Filter,
26296 tag : true, // all elements.
26298 replaceTag : function(n)
26300 n.parentNode.removeChild(n);
26304 * @class Roo.htmleditor.FilterComment
26307 * Run a new Comments Filter
26308 * @param {Object} config Configuration options
26310 Roo.htmleditor.FilterComment = function(cfg)
26312 this.walk(cfg.node);
26315 Roo.extend(Roo.htmleditor.FilterComment, Roo.htmleditor.Filter,
26318 replaceComment : function(n)
26320 n.parentNode.removeChild(n);
26323 * @class Roo.htmleditor.FilterKeepChildren
26324 * remove tags but keep children
26326 * Run a new Keep Children Filter
26327 * @param {Object} config Configuration options
26330 Roo.htmleditor.FilterKeepChildren = function(cfg)
26332 Roo.apply(this, cfg);
26333 if (this.tag === false) {
26334 return; // dont walk.. (you can use this to use this just to do a child removal on a single tag )
26337 if ((typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)) {
26338 this.cleanNamespace = true;
26341 this.walk(cfg.node);
26344 Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack,
26346 cleanNamespace : false, // should really be an option, rather than using ':' inside of this tag.
26348 replaceTag : function(node)
26350 // walk children...
26351 //Roo.log(node.tagName);
26352 var ar = Array.from(node.childNodes);
26355 for (var i = 0; i < ar.length; i++) {
26357 if (e.nodeType == 1) {
26359 (typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1)
26360 || // array and it matches
26361 (typeof(this.tag) == 'string' && this.tag == e.tagName)
26363 (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)
26365 (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":")
26367 this.replaceTag(ar[i]); // child is blacklisted as well...
26372 ar = Array.from(node.childNodes);
26373 for (var i = 0; i < ar.length; i++) {
26375 node.removeChild(ar[i]);
26376 // what if we need to walk these???
26377 node.parentNode.insertBefore(ar[i], node);
26378 if (this.tag !== false) {
26383 //Roo.log("REMOVE:" + node.tagName);
26384 node.parentNode.removeChild(node);
26385 return false; // don't walk children
26390 * @class Roo.htmleditor.FilterParagraph
26391 * paragraphs cause a nightmare for shared content - this filter is designed to be called ? at various points when editing
26392 * like on 'push' to remove the <p> tags and replace them with line breaks.
26394 * Run a new Paragraph Filter
26395 * @param {Object} config Configuration options
26398 Roo.htmleditor.FilterParagraph = function(cfg)
26400 // no need to apply config.
26401 this.walk(cfg.node);
26404 Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter,
26411 replaceTag : function(node)
26414 if (node.childNodes.length == 1 &&
26415 node.childNodes[0].nodeType == 3 &&
26416 node.childNodes[0].textContent.trim().length < 1
26418 // remove and replace with '<BR>';
26419 node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node);
26420 return false; // no need to walk..
26422 var ar = Array.from(node.childNodes);
26423 for (var i = 0; i < ar.length; i++) {
26424 node.removeChild(ar[i]);
26425 // what if we need to walk these???
26426 node.parentNode.insertBefore(ar[i], node);
26428 // now what about this?
26432 node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
26433 node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
26434 node.parentNode.removeChild(node);
26441 * @class Roo.htmleditor.FilterSpan
26442 * filter span's with no attributes out..
26444 * Run a new Span Filter
26445 * @param {Object} config Configuration options
26448 Roo.htmleditor.FilterSpan = function(cfg)
26450 // no need to apply config.
26451 this.walk(cfg.node);
26454 Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterKeepChildren,
26460 replaceTag : function(node)
26462 if (node.attributes && node.attributes.length > 0) {
26463 return true; // walk if there are any.
26465 Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this, node);
26471 * @class Roo.htmleditor.FilterTableWidth
26472 try and remove table width data - as that frequently messes up other stuff.
26474 * was cleanTableWidths.
26476 * Quite often pasting from word etc.. results in tables with column and widths.
26477 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
26480 * Run a new Table Filter
26481 * @param {Object} config Configuration options
26484 Roo.htmleditor.FilterTableWidth = function(cfg)
26486 // no need to apply config.
26487 this.tag = ['TABLE', 'TD', 'TR', 'TH', 'THEAD', 'TBODY' ];
26488 this.walk(cfg.node);
26491 Roo.extend(Roo.htmleditor.FilterTableWidth, Roo.htmleditor.Filter,
26496 replaceTag: function(node) {
26500 if (node.hasAttribute('width')) {
26501 node.removeAttribute('width');
26505 if (node.hasAttribute("style")) {
26508 var styles = node.getAttribute("style").split(";");
26510 Roo.each(styles, function(s) {
26511 if (!s.match(/:/)) {
26514 var kv = s.split(":");
26515 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
26518 // what ever is left... we allow.
26521 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
26522 if (!nstyle.length) {
26523 node.removeAttribute('style');
26527 return true; // continue doing children..
26530 * @class Roo.htmleditor.FilterWord
26531 * try and clean up all the mess that Word generates.
26533 * This is the 'nice version' - see 'Heavy' that white lists a very short list of elements, and multi-filters
26536 * Run a new Span Filter
26537 * @param {Object} config Configuration options
26540 Roo.htmleditor.FilterWord = function(cfg)
26542 // no need to apply config.
26543 this.replaceDocBullets(cfg.node);
26545 this.replaceAname(cfg.node);
26546 // this is disabled as the removal is done by other filters;
26547 // this.walk(cfg.node);
26552 Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
26558 * Clean up MS wordisms...
26560 replaceTag : function(node)
26563 // no idea what this does - span with text, replaceds with just text.
26565 node.nodeName == 'SPAN' &&
26566 !node.hasAttributes() &&
26567 node.childNodes.length == 1 &&
26568 node.firstChild.nodeName == "#text"
26570 var textNode = node.firstChild;
26571 node.removeChild(textNode);
26572 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
26573 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node);
26575 node.parentNode.insertBefore(textNode, node);
26576 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
26577 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node);
26580 node.parentNode.removeChild(node);
26581 return false; // dont do chidren - we have remove our node - so no need to do chdhilren?
26586 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
26587 node.parentNode.removeChild(node);
26588 return false; // dont do chidlren
26590 //Roo.log(node.tagName);
26591 // remove - but keep children..
26592 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) {
26593 //Roo.log('-- removed');
26594 while (node.childNodes.length) {
26595 var cn = node.childNodes[0];
26596 node.removeChild(cn);
26597 node.parentNode.insertBefore(cn, node);
26598 // move node to parent - and clean it..
26599 if (cn.nodeType == 1) {
26600 this.replaceTag(cn);
26604 node.parentNode.removeChild(node);
26605 /// no need to iterate chidlren = it's got none..
26606 //this.iterateChildren(node, this.cleanWord);
26607 return false; // no need to iterate children.
26610 if (node.className.length) {
26612 var cn = node.className.split(/\W+/);
26614 Roo.each(cn, function(cls) {
26615 if (cls.match(/Mso[a-zA-Z]+/)) {
26620 node.className = cna.length ? cna.join(' ') : '';
26622 node.removeAttribute("class");
26626 if (node.hasAttribute("lang")) {
26627 node.removeAttribute("lang");
26630 if (node.hasAttribute("style")) {
26632 var styles = node.getAttribute("style").split(";");
26634 Roo.each(styles, function(s) {
26635 if (!s.match(/:/)) {
26638 var kv = s.split(":");
26639 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
26642 // what ever is left... we allow.
26645 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
26646 if (!nstyle.length) {
26647 node.removeAttribute('style');
26650 return true; // do children
26656 styleToObject: function(node)
26658 var styles = (node.getAttribute("style") || '').split(";");
26660 Roo.each(styles, function(s) {
26661 if (!s.match(/:/)) {
26664 var kv = s.split(":");
26666 // what ever is left... we allow.
26667 ret[kv[0].trim()] = kv[1];
26673 replaceAname : function (doc)
26675 // replace all the a/name without..
26676 var aa = Array.from(doc.getElementsByTagName('a'));
26677 for (var i = 0; i < aa.length; i++) {
26679 if (a.hasAttribute("name")) {
26680 a.removeAttribute("name");
26682 if (a.hasAttribute("href")) {
26685 // reparent children.
26686 this.removeNodeKeepChildren(a);
26696 replaceDocBullets : function(doc)
26698 // this is a bit odd - but it appears some indents use ql-indent-1
26699 //Roo.log(doc.innerHTML);
26701 var listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpFirst'));
26702 for( var i = 0; i < listpara.length; i ++) {
26703 listpara[i].className = "MsoListParagraph";
26706 listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpMiddle'));
26707 for( var i = 0; i < listpara.length; i ++) {
26708 listpara[i].className = "MsoListParagraph";
26710 listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpLast'));
26711 for( var i = 0; i < listpara.length; i ++) {
26712 listpara[i].className = "MsoListParagraph";
26714 listpara = Array.from(doc.getElementsByClassName('ql-indent-1'));
26715 for( var i = 0; i < listpara.length; i ++) {
26716 listpara[i].className = "MsoListParagraph";
26719 // this is a bit hacky - we had one word document where h2 had a miso-list attribute.
26720 var htwo = Array.from(doc.getElementsByTagName('h2'));
26721 for( var i = 0; i < htwo.length; i ++) {
26722 if (htwo[i].hasAttribute('style') && htwo[i].getAttribute('style').match(/mso-list:/)) {
26723 htwo[i].className = "MsoListParagraph";
26726 listpara = Array.from(doc.getElementsByClassName('MsoNormal'));
26727 for( var i = 0; i < listpara.length; i ++) {
26728 if (listpara[i].hasAttribute('style') && listpara[i].getAttribute('style').match(/mso-list:/)) {
26729 listpara[i].className = "MsoListParagraph";
26731 listpara[i].className = "MsoNormalx";
26735 listpara = doc.getElementsByClassName('MsoListParagraph');
26736 // Roo.log(doc.innerHTML);
26740 while(listpara.length) {
26742 this.replaceDocBullet(listpara.item(0));
26749 replaceDocBullet : function(p)
26751 // gather all the siblings.
26753 parent = p.parentNode,
26754 doc = parent.ownerDocument,
26757 var listtype = 'ul';
26759 if (ns.nodeType != 1) {
26760 ns = ns.nextSibling;
26763 if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) {
26766 var spans = ns.getElementsByTagName('span');
26767 if (ns.hasAttribute('style') && ns.getAttribute('style').match(/mso-list/)) {
26769 ns = ns.nextSibling;
26771 if (spans.length && spans[0].hasAttribute('style')) {
26772 var style = this.styleToObject(spans[0]);
26773 if (typeof(style['font-family']) != 'undefined' && !style['font-family'].match(/Symbol/)) {
26780 var spans = ns.getElementsByTagName('span');
26781 if (!spans.length) {
26784 var has_list = false;
26785 for(var i = 0; i < spans.length; i++) {
26786 if (spans[i].hasAttribute('style') && spans[i].getAttribute('style').match(/mso-list/)) {
26795 ns = ns.nextSibling;
26799 if (!items.length) {
26804 var ul = parent.ownerDocument.createElement(listtype); // what about number lists...
26805 parent.insertBefore(ul, p);
26807 var stack = [ ul ];
26808 var last_li = false;
26810 var margin_to_depth = {};
26813 items.forEach(function(n, ipos) {
26814 //Roo.log("got innertHMLT=" + n.innerHTML);
26816 var spans = n.getElementsByTagName('span');
26817 if (!spans.length) {
26818 //Roo.log("No spans found");
26820 parent.removeChild(n);
26823 return; // skip it...
26829 for(var i = 0; i < spans.length; i++) {
26831 style = this.styleToObject(spans[i]);
26832 if (typeof(style['mso-list']) == 'undefined') {
26835 if (listtype == 'ol') {
26836 num = spans[i].innerText.replace(/[^0-9]+]/g,'') * 1;
26838 spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet.
26841 //Roo.log("NOW GOT innertHMLT=" + n.innerHTML);
26842 style = this.styleToObject(n); // mo-list is from the parent node.
26843 if (typeof(style['mso-list']) == 'undefined') {
26844 //Roo.log("parent is missing level");
26846 parent.removeChild(n);
26851 var margin = style['margin-left'];
26852 if (typeof(margin_to_depth[margin]) == 'undefined') {
26854 margin_to_depth[margin] = max_margins;
26856 nlvl = margin_to_depth[margin] ;
26860 var nul = doc.createElement(listtype); // what about number lists...
26862 last_li = doc.createElement('li');
26863 stack[lvl].appendChild(last_li);
26865 last_li.appendChild(nul);
26871 // not starting at 1..
26872 if (!stack[nlvl].hasAttribute("start") && listtype == "ol") {
26873 stack[nlvl].setAttribute("start", num);
26876 var nli = stack[nlvl].appendChild(doc.createElement('li'));
26878 nli.innerHTML = n.innerHTML;
26879 //Roo.log("innerHTML = " + n.innerHTML);
26880 parent.removeChild(n);
26896 * @class Roo.htmleditor.FilterStyleToTag
26897 * part of the word stuff... - certain 'styles' should be converted to tags.
26899 * font-weight: bold -> bold
26900 * ?? super / subscrit etc..
26903 * Run a new style to tag filter.
26904 * @param {Object} config Configuration options
26906 Roo.htmleditor.FilterStyleToTag = function(cfg)
26910 B : [ 'fontWeight' , 'bold'],
26911 I : [ 'fontStyle' , 'italic'],
26912 //pre : [ 'font-style' , 'italic'],
26913 // h1.. h6 ?? font-size?
26914 SUP : [ 'verticalAlign' , 'super' ],
26915 SUB : [ 'verticalAlign' , 'sub' ]
26920 Roo.apply(this, cfg);
26923 this.walk(cfg.node);
26930 Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter,
26932 tag: true, // all tags
26937 replaceTag : function(node)
26941 if (node.getAttribute("style") === null) {
26945 for (var k in this.tags) {
26946 if (node.style[this.tags[k][0]] == this.tags[k][1]) {
26948 node.style.removeProperty(this.tags[k][0]);
26951 if (!inject.length) {
26954 var cn = Array.from(node.childNodes);
26956 Roo.each(inject, function(t) {
26957 var nc = node.ownerDocument.createElement(t);
26958 nn.appendChild(nc);
26961 for(var i = 0;i < cn.length;cn++) {
26962 node.removeChild(cn[i]);
26963 nn.appendChild(cn[i]);
26965 return true /// iterate thru
26969 * @class Roo.htmleditor.FilterLongBr
26970 * BR/BR/BR - keep a maximum of 2...
26972 * Run a new Long BR Filter
26973 * @param {Object} config Configuration options
26976 Roo.htmleditor.FilterLongBr = function(cfg)
26978 // no need to apply config.
26979 this.walk(cfg.node);
26982 Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter,
26989 replaceTag : function(node)
26992 var ps = node.nextSibling;
26993 while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
26994 ps = ps.nextSibling;
26997 if (!ps && [ 'TD', 'TH', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(node.parentNode.tagName) > -1) {
26998 node.parentNode.removeChild(node); // remove last BR inside one fo these tags
27002 if (!ps || ps.nodeType != 1) {
27006 if (!ps || ps.tagName != 'BR') {
27015 if (!node.previousSibling) {
27018 var ps = node.previousSibling;
27020 while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
27021 ps = ps.previousSibling;
27023 if (!ps || ps.nodeType != 1) {
27026 // if header or BR before.. then it's a candidate for removal.. - as we only want '2' of these..
27027 if (!ps || [ 'BR', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(ps.tagName) < 0) {
27031 node.parentNode.removeChild(node); // remove me...
27033 return false; // no need to do children
27040 * @class Roo.htmleditor.FilterBlock
27041 * removes id / data-block and contenteditable that are associated with blocks
27042 * usage should be done on a cloned copy of the dom
27044 * Run a new Attribute Filter { node : xxxx }}
27045 * @param {Object} config Configuration options
27047 Roo.htmleditor.FilterBlock = function(cfg)
27049 Roo.apply(this, cfg);
27050 var qa = cfg.node.querySelectorAll;
27051 this.removeAttributes('data-block');
27052 this.removeAttributes('contenteditable');
27053 this.removeAttributes('id');
27057 Roo.apply(Roo.htmleditor.FilterBlock.prototype,
27059 node: true, // all tags
27062 removeAttributes : function(attr)
27064 var ar = this.node.querySelectorAll('*[' + attr + ']');
27065 for (var i =0;i<ar.length;i++) {
27066 ar[i].removeAttribute(attr);
27075 * This is based loosely on tinymce
27076 * @class Roo.htmleditor.TidySerializer
27077 * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js
27079 * @method Serializer
27080 * @param {Object} settings Name/value settings object.
27084 Roo.htmleditor.TidySerializer = function(settings)
27086 Roo.apply(this, settings);
27088 this.writer = new Roo.htmleditor.TidyWriter(settings);
27093 Roo.htmleditor.TidySerializer.prototype = {
27096 * @param {boolean} inner do the inner of the node.
27103 * Serializes the specified node into a string.
27106 * new tinymce.html.Serializer().serialize(new tinymce.html.DomParser().parse('<p>text</p>'));
27107 * @method serialize
27108 * @param {DomElement} node Node instance to serialize.
27109 * @return {String} String with HTML based on DOM tree.
27111 serialize : function(node) {
27113 // = settings.validate;
27114 var writer = this.writer;
27118 3: function(node) {
27120 writer.text(node.nodeValue, node);
27123 8: function(node) {
27124 writer.comment(node.nodeValue);
27126 // Processing instruction
27127 7: function(node) {
27128 writer.pi(node.name, node.nodeValue);
27131 10: function(node) {
27132 writer.doctype(node.nodeValue);
27135 4: function(node) {
27136 writer.cdata(node.nodeValue);
27138 // Document fragment
27139 11: function(node) {
27140 node = node.firstChild;
27146 node = node.nextSibling
27151 1 != node.nodeType || this.inner ? this.handlers[11](node) : this.walk(node);
27152 return writer.getContent();
27155 walk: function(node)
27157 var attrName, attrValue, sortedAttrs, i, l, elementRule,
27158 handler = this.handlers[node.nodeType];
27165 var name = node.nodeName;
27166 var isEmpty = node.childNodes.length < 1;
27168 var writer = this.writer;
27169 var attrs = node.attributes;
27172 writer.start(node.nodeName, attrs, isEmpty, node);
27176 node = node.firstChild;
27183 node = node.nextSibling;
27189 // Serialize element and treat all non elements as fragments
27194 * This is based loosely on tinymce
27195 * @class Roo.htmleditor.TidyWriter
27196 * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js
27199 * - not tested much with 'PRE' formated elements.
27205 Roo.htmleditor.TidyWriter = function(settings)
27208 // indent, indentBefore, indentAfter, encode, htmlOutput, html = [];
27209 Roo.apply(this, settings);
27213 this.encode = Roo.htmleditor.TidyEntities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
27216 Roo.htmleditor.TidyWriter.prototype = {
27223 // part of state...
27227 last_inline : false,
27232 * Writes the a start element such as <p id="a">.
27235 * @param {String} name Name of the element.
27236 * @param {Array} attrs Optional attribute array or undefined if it hasn't any.
27237 * @param {Boolean} empty Optional empty state if the tag should end like <br />.
27239 start: function(name, attrs, empty, node)
27241 var i, l, attr, value;
27243 // there are some situations where adding line break && indentation will not work. will not work.
27244 // <span / b / i ... formating?
27246 var in_inline = this.in_inline || Roo.htmleditor.TidyWriter.inline_elements.indexOf(name) > -1;
27247 var in_pre = this.in_pre || Roo.htmleditor.TidyWriter.whitespace_elements.indexOf(name) > -1;
27249 var is_short = empty ? Roo.htmleditor.TidyWriter.shortend_elements.indexOf(name) > -1 : false;
27251 var add_lb = name == 'BR' ? false : in_inline;
27253 if (!add_lb && !this.in_pre && this.lastElementEndsWS()) {
27257 var indentstr = this.indentstr;
27259 // e_inline = elements that can be inline, but still allow \n before and after?
27260 // only 'BR' ??? any others?
27262 // ADD LINE BEFORE tage
27263 if (!this.in_pre) {
27266 if (name == 'BR') {
27268 } else if (this.lastElementEndsWS()) {
27271 // otherwise - no new line. (and dont indent.)
27282 this.html.push(indentstr + '<', name.toLowerCase());
27285 for (i = 0, l = attrs.length; i < l; i++) {
27287 this.html.push(' ', attr.name, '="', this.encode(attr.value, true), '"');
27293 this.html[this.html.length] = '/>';
27295 this.html[this.html.length] = '></' + name.toLowerCase() + '>';
27297 var e_inline = name == 'BR' ? false : this.in_inline;
27299 if (!e_inline && !this.in_pre) {
27306 this.html[this.html.length] = '>';
27308 // there is a special situation, where we need to turn on in_inline - if any of the imediate chidlren are one of these.
27310 if (!in_inline && !in_pre) {
27311 var cn = node.firstChild;
27313 if (Roo.htmleditor.TidyWriter.inline_elements.indexOf(cn.nodeName) > -1) {
27317 cn = cn.nextSibling;
27325 indentstr : in_pre ? '' : (this.indentstr + this.indent),
27327 in_inline : in_inline
27329 // add a line after if we are not in a
27331 if (!in_inline && !in_pre) {
27340 lastElementEndsWS : function()
27342 var value = this.html.length > 0 ? this.html[this.html.length-1] : false;
27343 if (value === false) {
27346 return value.match(/\s+$/);
27351 * Writes the a end element such as </p>.
27354 * @param {String} name Name of the element.
27356 end: function(name) {
27359 var indentstr = '';
27360 var in_inline = this.in_inline || Roo.htmleditor.TidyWriter.inline_elements.indexOf(name) > -1;
27362 if (!this.in_pre && !in_inline) {
27364 indentstr = this.indentstr;
27366 this.html.push(indentstr + '</', name.toLowerCase(), '>');
27367 this.last_inline = in_inline;
27369 // pop the indent state..
27372 * Writes a text node.
27374 * In pre - we should not mess with the contents.
27378 * @param {String} text String to write out.
27379 * @param {Boolean} raw Optional raw state if true the contents wont get encoded.
27381 text: function(in_text, node)
27383 // if not in whitespace critical
27384 if (in_text.length < 1) {
27387 var text = new XMLSerializer().serializeToString(document.createTextNode(in_text)); // escape it properly?
27390 this.html[this.html.length] = text;
27394 if (this.in_inline) {
27395 text = text.replace(/\s+/g,' '); // all white space inc line breaks to a slingle' '
27397 text = text.replace(/\s+/,' '); // all white space to single white space
27400 // if next tag is '<BR>', then we can trim right..
27401 if (node.nextSibling &&
27402 node.nextSibling.nodeType == 1 &&
27403 node.nextSibling.nodeName == 'BR' )
27405 text = text.replace(/\s+$/g,'');
27407 // if previous tag was a BR, we can also trim..
27408 if (node.previousSibling &&
27409 node.previousSibling.nodeType == 1 &&
27410 node.previousSibling.nodeName == 'BR' )
27412 text = this.indentstr + text.replace(/^\s+/g,'');
27414 if (text.match(/\n/)) {
27415 text = text.replace(
27416 /(?![^\n]{1,64}$)([^\n]{1,64})\s/g, '$1\n' + this.indentstr
27418 // remoeve the last whitespace / line break.
27419 text = text.replace(/\n\s+$/,'');
27421 // repace long lines
27425 this.html[this.html.length] = text;
27428 // see if previous element was a inline element.
27429 var indentstr = this.indentstr;
27431 text = text.replace(/\s+/g," "); // all whitespace into single white space.
27433 // should trim left?
27434 if (node.previousSibling &&
27435 node.previousSibling.nodeType == 1 &&
27436 Roo.htmleditor.TidyWriter.inline_elements.indexOf(node.previousSibling.nodeName) > -1)
27442 text = text.replace(/^\s+/,''); // trim left
27445 // should trim right?
27446 if (node.nextSibling &&
27447 node.nextSibling.nodeType == 1 &&
27448 Roo.htmleditor.TidyWriter.inline_elements.indexOf(node.nextSibling.nodeName) > -1)
27453 text = text.replace(/\s+$/,''); // trim right
27460 if (text.length < 1) {
27463 if (!text.match(/\n/)) {
27464 this.html.push(indentstr + text);
27468 text = this.indentstr + text.replace(
27469 /(?![^\n]{1,64}$)([^\n]{1,64})\s/g, '$1\n' + this.indentstr
27471 // remoeve the last whitespace / line break.
27472 text = text.replace(/\s+$/,'');
27474 this.html.push(text);
27476 // split and indent..
27481 * Writes a cdata node such as <![CDATA[data]]>.
27484 * @param {String} text String to write out inside the cdata.
27486 cdata: function(text) {
27487 this.html.push('<![CDATA[', text, ']]>');
27490 * Writes a comment node such as <!-- Comment -->.
27493 * @param {String} text String to write out inside the comment.
27495 comment: function(text) {
27496 this.html.push('<!--', text, '-->');
27499 * Writes a PI node such as <?xml attr="value" ?>.
27502 * @param {String} name Name of the pi.
27503 * @param {String} text String to write out inside the pi.
27505 pi: function(name, text) {
27506 text ? this.html.push('<?', name, ' ', this.encode(text), '?>') : this.html.push('<?', name, '?>');
27507 this.indent != '' && this.html.push('\n');
27510 * Writes a doctype node such as <!DOCTYPE data>.
27513 * @param {String} text String to write out inside the doctype.
27515 doctype: function(text) {
27516 this.html.push('<!DOCTYPE', text, '>', this.indent != '' ? '\n' : '');
27519 * Resets the internal buffer if one wants to reuse the writer.
27523 reset: function() {
27524 this.html.length = 0;
27533 * Returns the contents that got serialized.
27535 * @method getContent
27536 * @return {String} HTML contents that got written down.
27538 getContent: function() {
27539 return this.html.join('').replace(/\n$/, '');
27542 pushState : function(cfg)
27544 this.state.push(cfg);
27545 Roo.apply(this, cfg);
27548 popState : function()
27550 if (this.state.length < 1) {
27551 return; // nothing to push
27558 if (this.state.length > 0) {
27559 cfg = this.state[this.state.length-1];
27561 Roo.apply(this, cfg);
27564 addLine: function()
27566 if (this.html.length < 1) {
27571 var value = this.html[this.html.length - 1];
27572 if (value.length > 0 && '\n' !== value) {
27573 this.html.push('\n');
27578 //'pre script noscript style textarea video audio iframe object code'
27579 // shortended... 'area base basefont br col frame hr img input isindex link meta param embed source wbr track');
27583 Roo.htmleditor.TidyWriter.inline_elements = [
27584 'SPAN','STRONG','B','EM','I','FONT','STRIKE','U','VAR',
27585 'CITE','DFN','CODE','MARK','Q','SUP','SUB','SAMP', 'A'
27587 Roo.htmleditor.TidyWriter.shortend_elements = [
27588 'AREA','BASE','BASEFONT','BR','COL','FRAME','HR','IMG','INPUT',
27589 'ISINDEX','LINK','','META','PARAM','EMBED','SOURCE','WBR','TRACK'
27592 Roo.htmleditor.TidyWriter.whitespace_elements = [
27593 'PRE','SCRIPT','NOSCRIPT','STYLE','TEXTAREA','VIDEO','AUDIO','IFRAME','OBJECT','CODE'
27595 * This is based loosely on tinymce
27596 * @class Roo.htmleditor.TidyEntities
27598 * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js
27600 * Not 100% sure this is actually used or needed.
27603 Roo.htmleditor.TidyEntities = {
27606 * initialize data..
27608 init : function (){
27610 this.namedEntities = this.buildEntitiesLookup(this.namedEntitiesData, 32);
27615 buildEntitiesLookup: function(items, radix) {
27616 var i, chr, entity, lookup = {};
27620 items = typeof(items) == 'string' ? items.split(',') : items;
27621 radix = radix || 10;
27622 // Build entities lookup table
27623 for (i = 0; i < items.length; i += 2) {
27624 chr = String.fromCharCode(parseInt(items[i], radix));
27625 // Only add non base entities
27626 if (!this.baseEntities[chr]) {
27627 entity = '&' + items[i + 1] + ';';
27628 lookup[chr] = entity;
27629 lookup[entity] = chr;
27668 // Needs to be escaped since the YUI compressor would otherwise break the code
27675 // Reverse lookup table for raw entities
27676 reverseEntities : {
27684 attrsCharsRegExp : /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
27685 textCharsRegExp : /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
27686 rawCharsRegExp : /[<>&\"\']/g,
27687 entityRegExp : /&#([a-z0-9]+);?|&([a-z0-9]+);/gi,
27688 namedEntities : false,
27689 namedEntitiesData : [
28190 * Encodes the specified string using raw entities. This means only the required XML base entities will be encoded.
28192 * @method encodeRaw
28193 * @param {String} text Text to encode.
28194 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
28195 * @return {String} Entity encoded text.
28197 encodeRaw: function(text, attr)
28200 return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
28201 return t.baseEntities[chr] || chr;
28205 * Encoded the specified text with both the attributes and text entities. This function will produce larger text contents
28206 * since it doesn't know if the context is within a attribute or text node. This was added for compatibility
28207 * and is exposed as the DOMUtils.encode function.
28209 * @method encodeAllRaw
28210 * @param {String} text Text to encode.
28211 * @return {String} Entity encoded text.
28213 encodeAllRaw: function(text) {
28215 return ('' + text).replace(this.rawCharsRegExp, function(chr) {
28216 return t.baseEntities[chr] || chr;
28220 * Encodes the specified string using numeric entities. The core entities will be
28221 * encoded as named ones but all non lower ascii characters will be encoded into numeric entities.
28223 * @method encodeNumeric
28224 * @param {String} text Text to encode.
28225 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
28226 * @return {String} Entity encoded text.
28228 encodeNumeric: function(text, attr) {
28230 return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
28231 // Multi byte sequence convert it to a single entity
28232 if (chr.length > 1) {
28233 return '&#' + (1024 * (chr.charCodeAt(0) - 55296) + (chr.charCodeAt(1) - 56320) + 65536) + ';';
28235 return t.baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
28239 * Encodes the specified string using named entities. The core entities will be encoded
28240 * as named ones but all non lower ascii characters will be encoded into named entities.
28242 * @method encodeNamed
28243 * @param {String} text Text to encode.
28244 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
28245 * @param {Object} entities Optional parameter with entities to use.
28246 * @return {String} Entity encoded text.
28248 encodeNamed: function(text, attr, entities) {
28250 entities = entities || this.namedEntities;
28251 return text.replace(attr ? this.attrsCharsRegExp : this.textCharsRegExp, function(chr) {
28252 return t.baseEntities[chr] || entities[chr] || chr;
28256 * Returns an encode function based on the name(s) and it's optional entities.
28258 * @method getEncodeFunc
28259 * @param {String} name Comma separated list of encoders for example named,numeric.
28260 * @param {String} entities Optional parameter with entities to use instead of the built in set.
28261 * @return {function} Encode function to be used.
28263 getEncodeFunc: function(name, entities) {
28264 entities = this.buildEntitiesLookup(entities) || this.namedEntities;
28266 function encodeNamedAndNumeric(text, attr) {
28267 return text.replace(attr ? t.attrsCharsRegExp : t.textCharsRegExp, function(chr) {
28268 return t.baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
28272 function encodeCustomNamed(text, attr) {
28273 return t.encodeNamed(text, attr, entities);
28275 // Replace + with , to be compatible with previous TinyMCE versions
28276 name = this.makeMap(name.replace(/\+/g, ','));
28277 // Named and numeric encoder
28278 if (name.named && name.numeric) {
28279 return this.encodeNamedAndNumeric;
28285 return encodeCustomNamed;
28287 return this.encodeNamed;
28290 if (name.numeric) {
28291 return this.encodeNumeric;
28294 return this.encodeRaw;
28297 * Decodes the specified string, this will replace entities with raw UTF characters.
28300 * @param {String} text Text to entity decode.
28301 * @return {String} Entity decoded string.
28303 decode: function(text)
28306 return text.replace(this.entityRegExp, function(all, numeric) {
28308 numeric = 'x' === numeric.charAt(0).toLowerCase() ? parseInt(numeric.substr(1), 16) : parseInt(numeric, 10);
28309 // Support upper UTF
28310 if (numeric > 65535) {
28312 return String.fromCharCode(55296 + (numeric >> 10), 56320 + (1023 & numeric));
28314 return t.asciiMap[numeric] || String.fromCharCode(numeric);
28316 return t.reverseEntities[all] || t.namedEntities[all] || t.nativeDecode(all);
28319 nativeDecode : function (text) {
28322 makeMap : function (items, delim, map) {
28324 items = items || [];
28325 delim = delim || ',';
28326 if (typeof items == "string") {
28327 items = items.split(delim);
28332 map[items[i]] = {};
28340 Roo.htmleditor.TidyEntities.init();
28342 * @class Roo.htmleditor.KeyEnter
28343 * Handle Enter press..
28344 * @cfg {Roo.HtmlEditorCore} core the editor.
28346 * Create a new Filter.
28347 * @param {Object} config Configuration options
28354 Roo.htmleditor.KeyEnter = function(cfg) {
28355 Roo.apply(this, cfg);
28356 // this does not actually call walk as it's really just a abstract class
28358 Roo.get(this.core.doc.body).on('keypress', this.keypress, this);
28361 //Roo.htmleditor.KeyEnter.i = 0;
28364 Roo.htmleditor.KeyEnter.prototype = {
28368 keypress : function(e)
28370 if (e.charCode != 13 && e.charCode != 10) {
28371 Roo.log([e.charCode,e]);
28374 e.preventDefault();
28375 // https://stackoverflow.com/questions/18552336/prevent-contenteditable-adding-div-on-enter-chrome
28376 var doc = this.core.doc;
28380 var sel = this.core.getSelection();
28381 var range = sel.getRangeAt(0);
28382 var n = range.commonAncestorContainer;
28383 var pc = range.closest([ 'ol', 'ul']);
28384 var pli = range.closest('li');
28385 if (!pc || e.ctrlKey) {
28386 // on it list, or ctrl pressed.
28388 sel.insertNode('br', 'after');
28390 // only do this if we have ctrl key..
28391 var br = doc.createElement('br');
28392 br.className = 'clear';
28393 br.setAttribute('style', 'clear: both');
28394 sel.insertNode(br, 'after');
28398 this.core.undoManager.addEvent();
28399 this.core.fireEditorEvent(e);
28403 // deal with <li> insetion
28404 if (pli.innerText.trim() == '' &&
28405 pli.previousSibling &&
28406 pli.previousSibling.nodeName == 'LI' &&
28407 pli.previousSibling.innerText.trim() == '') {
28408 pli.parentNode.removeChild(pli.previousSibling);
28409 sel.cursorAfter(pc);
28410 this.core.undoManager.addEvent();
28411 this.core.fireEditorEvent(e);
28415 var li = doc.createElement('LI');
28416 li.innerHTML = ' ';
28417 if (!pli || !pli.firstSibling) {
28418 pc.appendChild(li);
28420 pli.parentNode.insertBefore(li, pli.firstSibling);
28422 sel.cursorText (li.firstChild);
28424 this.core.undoManager.addEvent();
28425 this.core.fireEditorEvent(e);
28437 * @class Roo.htmleditor.Block
28438 * Base class for html editor blocks - do not use it directly .. extend it..
28439 * @cfg {DomElement} node The node to apply stuff to.
28440 * @cfg {String} friendly_name the name that appears in the context bar about this block
28441 * @cfg {Object} Context menu - see Roo.form.HtmlEditor.ToolbarContext
28444 * Create a new Filter.
28445 * @param {Object} config Configuration options
28448 Roo.htmleditor.Block = function(cfg)
28450 // do nothing .. should not be called really.
28453 * factory method to get the block from an element (using cache if necessary)
28455 * @param {HtmlElement} the dom element
28457 Roo.htmleditor.Block.factory = function(node)
28459 var cc = Roo.htmleditor.Block.cache;
28460 var id = Roo.get(node).id;
28461 if (typeof(cc[id]) != 'undefined' && (!cc[id].node || cc[id].node.closest('body'))) {
28462 Roo.htmleditor.Block.cache[id].readElement(node);
28463 return Roo.htmleditor.Block.cache[id];
28465 var db = node.getAttribute('data-block');
28467 db = node.nodeName.toLowerCase().toUpperCaseFirst();
28469 var cls = Roo.htmleditor['Block' + db];
28470 if (typeof(cls) == 'undefined') {
28471 //Roo.log(node.getAttribute('data-block'));
28472 Roo.log("OOps missing block : " + 'Block' + db);
28475 Roo.htmleditor.Block.cache[id] = new cls({ node: node });
28476 return Roo.htmleditor.Block.cache[id]; /// should trigger update element
28480 * initalize all Elements from content that are 'blockable'
28482 * @param the body element
28484 Roo.htmleditor.Block.initAll = function(body, type)
28486 if (typeof(type) == 'undefined') {
28487 var ia = Roo.htmleditor.Block.initAll;
28493 Roo.each(Roo.get(body).query(type), function(e) {
28494 Roo.htmleditor.Block.factory(e);
28497 // question goes here... do we need to clear out this cache sometimes?
28498 // or show we make it relivant to the htmleditor.
28499 Roo.htmleditor.Block.cache = {};
28501 Roo.htmleditor.Block.prototype = {
28505 // used by context menu
28506 friendly_name : 'Based Block',
28508 // text for button to delete this element
28509 deleteTitle : false,
28513 * Update a node with values from this object
28514 * @param {DomElement} node
28516 updateElement : function(node)
28518 Roo.DomHelper.update(node === undefined ? this.node : node, this.toObject());
28521 * convert to plain HTML for calling insertAtCursor..
28523 toHTML : function()
28525 return Roo.DomHelper.markup(this.toObject());
28528 * used by readEleemnt to extract data from a node
28529 * may need improving as it's pretty basic
28531 * @param {DomElement} node
28532 * @param {String} tag - tag to find, eg. IMG ?? might be better to use DomQuery ?
28533 * @param {String} attribute (use html - for contents, style for using next param as style, or false to return the node)
28534 * @param {String} style the style property - eg. text-align
28536 getVal : function(node, tag, attr, style)
28539 if (tag !== true && n.tagName != tag.toUpperCase()) {
28540 // in theory we could do figure[3] << 3rd figure? or some more complex search..?
28541 // but kiss for now.
28542 n = node.getElementsByTagName(tag).item(0);
28547 if (attr === false) {
28550 if (attr == 'html') {
28551 return n.innerHTML;
28553 if (attr == 'style') {
28554 return n.style[style];
28557 return n.hasAttribute(attr) ? n.getAttribute(attr) : '';
28561 * create a DomHelper friendly object - for use with
28562 * Roo.DomHelper.markup / overwrite / etc..
28565 toObject : function()
28570 * Read a node that has a 'data-block' property - and extract the values from it.
28571 * @param {DomElement} node - the node
28573 readElement : function(node)
28584 * @class Roo.htmleditor.BlockFigure
28585 * Block that has an image and a figcaption
28586 * @cfg {String} image_src the url for the image
28587 * @cfg {String} align (left|right) alignment for the block default left
28588 * @cfg {String} caption the text to appear below (and in the alt tag)
28589 * @cfg {String} caption_display (block|none) display or not the caption
28590 * @cfg {String|number} image_width the width of the image number or %?
28591 * @cfg {String|number} image_height the height of the image number or %?
28594 * Create a new Filter.
28595 * @param {Object} config Configuration options
28598 Roo.htmleditor.BlockFigure = function(cfg)
28601 this.readElement(cfg.node);
28602 this.updateElement(cfg.node);
28604 Roo.apply(this, cfg);
28606 Roo.extend(Roo.htmleditor.BlockFigure, Roo.htmleditor.Block, {
28613 caption_display : 'block',
28619 // margin: '2%', not used
28621 text_align: 'left', // (left|right) alignment for the text caption default left. - not used at present
28624 // used by context menu
28625 friendly_name : 'Image with caption',
28626 deleteTitle : "Delete Image and Caption",
28628 contextMenu : function(toolbar)
28631 var block = function() {
28632 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
28636 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
28638 var syncValue = toolbar.editorcore.syncValue;
28644 xtype : 'TextItem',
28646 xns : rooui.Toolbar //Boostrap?
28650 text: 'Change Image URL',
28653 click: function (btn, state)
28657 Roo.MessageBox.show({
28658 title : "Image Source URL",
28659 msg : "Enter the url for the image",
28660 buttons: Roo.MessageBox.OKCANCEL,
28661 fn: function(btn, val){
28668 toolbar.editorcore.onEditorEvent();
28672 //multiline: multiline,
28674 value : b.image_src
28678 xns : rooui.Toolbar
28683 text: 'Change Link URL',
28686 click: function (btn, state)
28690 Roo.MessageBox.show({
28691 title : "Link URL",
28692 msg : "Enter the url for the link - leave blank to have no link",
28693 buttons: Roo.MessageBox.OKCANCEL,
28694 fn: function(btn, val){
28701 toolbar.editorcore.onEditorEvent();
28705 //multiline: multiline,
28711 xns : rooui.Toolbar
28715 text: 'Show Video URL',
28718 click: function (btn, state)
28720 Roo.MessageBox.alert("Video URL",
28721 block().video_url == '' ? 'This image is not linked ot a video' :
28722 'The image is linked to: <a target="_new" href="' + block().video_url + '">' + block().video_url + '</a>');
28725 xns : rooui.Toolbar
28730 xtype : 'TextItem',
28732 xns : rooui.Toolbar //Boostrap?
28735 xtype : 'ComboBox',
28736 allowBlank : false,
28737 displayField : 'val',
28740 triggerAction : 'all',
28742 valueField : 'val',
28746 select : function (combo, r, index)
28748 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28750 b.width = r.get('val');
28753 toolbar.editorcore.onEditorEvent();
28758 xtype : 'SimpleStore',
28771 xtype : 'TextItem',
28773 xns : rooui.Toolbar //Boostrap?
28776 xtype : 'ComboBox',
28777 allowBlank : false,
28778 displayField : 'val',
28781 triggerAction : 'all',
28783 valueField : 'val',
28787 select : function (combo, r, index)
28789 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28791 b.align = r.get('val');
28794 toolbar.editorcore.onEditorEvent();
28799 xtype : 'SimpleStore',
28813 text: 'Hide Caption',
28814 name : 'caption_display',
28816 enableToggle : true,
28817 setValue : function(v) {
28818 // this trigger toggle.
28820 this.setText(v ? "Hide Caption" : "Show Caption");
28821 this.setPressed(v != 'block');
28824 toggle: function (btn, state)
28827 b.caption_display = b.caption_display == 'block' ? 'none' : 'block';
28828 this.setText(b.caption_display == 'block' ? "Hide Caption" : "Show Caption");
28831 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28832 toolbar.editorcore.onEditorEvent();
28835 xns : rooui.Toolbar
28841 * create a DomHelper friendly object - for use with
28842 * Roo.DomHelper.markup / overwrite / etc..
28844 toObject : function()
28846 var d = document.createElement('div');
28847 d.innerHTML = this.caption;
28849 var m = this.width != '100%' && this.align == 'center' ? '0 auto' : 0;
28851 var iw = this.align == 'center' ? this.width : '100%';
28854 contenteditable : 'false',
28855 src : this.image_src,
28856 alt : d.innerText.replace(/\n/g, " ").replace(/\s+/g, ' ').trim(), // removeHTML and reduce spaces..
28859 maxWidth : iw + ' !important', // this is not getting rendered?
28865 '<div class="{0}" width="420" height="315" src="{1}" frameborder="0" allowfullscreen>' +
28867 '<img class="{0}-thumbnail" src="{3}/Images/{4}/{5}#image-{4}" />' +
28872 if (this.href.length > 0) {
28876 contenteditable : 'true',
28884 if (this.video_url.length > 0) {
28889 allowfullscreen : true,
28890 width : 420, // these are for video tricks - that we replace the outer
28892 src : this.video_url,
28898 // we remove caption totally if its hidden... - will delete data.. but otherwise we end up with fake caption
28899 var captionhtml = this.caption_display == 'none' ? '' : (this.caption.length ? this.caption : "Caption");
28904 'data-block' : 'Figure',
28905 'data-width' : this.width,
28906 contenteditable : 'false',
28910 float : this.align ,
28911 maxWidth : this.align == 'center' ? '100% !important' : (this.width + ' !important'),
28912 width : this.align == 'center' ? '100%' : this.width,
28914 padding: this.align == 'center' ? '0' : '0 10px' ,
28915 textAlign : this.align // seems to work for email..
28920 align : this.align,
28926 'data-display' : this.caption_display,
28928 textAlign : 'left',
28930 lineHeight : '24px',
28931 display : this.caption_display,
28932 maxWidth : (this.align == 'center' ? this.width : '100%' ) + ' !important',
28934 width: this.align == 'center' ? this.width : '100%'
28938 cls : this.cls.length > 0 ? (this.cls + '-thumbnail' ) : '',
28943 marginTop : '16px',
28949 // we can not rely on yahoo syndication to use CSS elements - so have to use '<i>' to encase stuff.
28951 contenteditable : true,
28967 readElement : function(node)
28969 // this should not really come from the link...
28970 this.video_url = this.getVal(node, 'div', 'src');
28971 this.cls = this.getVal(node, 'div', 'class');
28972 this.href = this.getVal(node, 'a', 'href');
28975 this.image_src = this.getVal(node, 'img', 'src');
28977 this.align = this.getVal(node, 'figure', 'align');
28978 var figcaption = this.getVal(node, 'figcaption', false);
28979 if (figcaption !== '') {
28980 this.caption = this.getVal(figcaption, 'i', 'html');
28984 this.caption_display = this.getVal(node, 'figcaption', 'data-display');
28985 //this.text_align = this.getVal(node, 'figcaption', 'style','text-align');
28986 this.width = this.getVal(node, true, 'data-width');
28987 //this.margin = this.getVal(node, 'figure', 'style', 'margin');
28990 removeNode : function()
29007 * @class Roo.htmleditor.BlockTable
29008 * Block that manages a table
29011 * Create a new Filter.
29012 * @param {Object} config Configuration options
29015 Roo.htmleditor.BlockTable = function(cfg)
29018 this.readElement(cfg.node);
29019 this.updateElement(cfg.node);
29021 Roo.apply(this, cfg);
29024 for(var r = 0; r < this.no_row; r++) {
29026 for(var c = 0; c < this.no_col; c++) {
29027 this.rows[r][c] = this.emptyCell();
29034 Roo.extend(Roo.htmleditor.BlockTable, Roo.htmleditor.Block, {
29043 // used by context menu
29044 friendly_name : 'Table',
29045 deleteTitle : 'Delete Table',
29046 // context menu is drawn once..
29048 contextMenu : function(toolbar)
29051 var block = function() {
29052 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
29056 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
29058 var syncValue = toolbar.editorcore.syncValue;
29064 xtype : 'TextItem',
29066 xns : rooui.Toolbar //Boostrap?
29069 xtype : 'ComboBox',
29070 allowBlank : false,
29071 displayField : 'val',
29074 triggerAction : 'all',
29076 valueField : 'val',
29080 select : function (combo, r, index)
29082 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29084 b.width = r.get('val');
29087 toolbar.editorcore.onEditorEvent();
29092 xtype : 'SimpleStore',
29104 xtype : 'TextItem',
29105 text : "Columns: ",
29106 xns : rooui.Toolbar //Boostrap?
29113 click : function (_self, e)
29115 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29116 block().removeColumn();
29118 toolbar.editorcore.onEditorEvent();
29121 xns : rooui.Toolbar
29127 click : function (_self, e)
29129 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29130 block().addColumn();
29132 toolbar.editorcore.onEditorEvent();
29135 xns : rooui.Toolbar
29139 xtype : 'TextItem',
29141 xns : rooui.Toolbar //Boostrap?
29148 click : function (_self, e)
29150 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29151 block().removeRow();
29153 toolbar.editorcore.onEditorEvent();
29156 xns : rooui.Toolbar
29162 click : function (_self, e)
29166 toolbar.editorcore.onEditorEvent();
29169 xns : rooui.Toolbar
29174 text: 'Reset Column Widths',
29177 click : function (_self, e)
29179 block().resetWidths();
29181 toolbar.editorcore.onEditorEvent();
29184 xns : rooui.Toolbar
29195 * create a DomHelper friendly object - for use with
29196 * Roo.DomHelper.markup / overwrite / etc..
29197 * ?? should it be called with option to hide all editing features?
29199 toObject : function()
29204 contenteditable : 'false', // this stops cell selection from picking the table.
29205 'data-block' : 'Table',
29208 border : 'solid 1px #000', // ??? hard coded?
29209 'border-collapse' : 'collapse'
29212 { tag : 'tbody' , cn : [] }
29216 // do we have a head = not really
29218 Roo.each(this.rows, function( row ) {
29223 border : 'solid 1px #000',
29229 ret.cn[0].cn.push(tr);
29230 // does the row have any properties? ?? height?
29232 Roo.each(row, function( cell ) {
29236 contenteditable : 'true',
29237 'data-block' : 'Td',
29241 if (cell.colspan > 1) {
29242 td.colspan = cell.colspan ;
29243 nc += cell.colspan;
29247 if (cell.rowspan > 1) {
29248 td.rowspan = cell.rowspan ;
29257 ncols = Math.max(nc, ncols);
29261 // add the header row..
29270 readElement : function(node)
29272 node = node ? node : this.node ;
29273 this.width = this.getVal(node, true, 'style', 'width') || '100%';
29277 var trs = Array.from(node.rows);
29278 trs.forEach(function(tr) {
29280 this.rows.push(row);
29284 Array.from(tr.cells).forEach(function(td) {
29287 colspan : td.hasAttribute('colspan') ? td.getAttribute('colspan')*1 : 1,
29288 rowspan : td.hasAttribute('rowspan') ? td.getAttribute('rowspan')*1 : 1,
29289 style : td.hasAttribute('style') ? td.getAttribute('style') : '',
29290 html : td.innerHTML
29292 no_column += add.colspan;
29299 this.no_col = Math.max(this.no_col, no_column);
29306 normalizeRows: function()
29310 this.rows.forEach(function(row) {
29313 row = this.normalizeRow(row);
29315 row.forEach(function(c) {
29316 while (typeof(ret[rid][cid]) != 'undefined') {
29319 if (typeof(ret[rid]) == 'undefined') {
29325 if (c.rowspan < 2) {
29329 for(var i = 1 ;i < c.rowspan; i++) {
29330 if (typeof(ret[rid+i]) == 'undefined') {
29333 ret[rid+i][cid] = c;
29341 normalizeRow: function(row)
29344 row.forEach(function(c) {
29345 if (c.colspan < 2) {
29349 for(var i =0 ;i < c.colspan; i++) {
29357 deleteColumn : function(sel)
29359 if (!sel || sel.type != 'col') {
29362 if (this.no_col < 2) {
29366 this.rows.forEach(function(row) {
29367 var cols = this.normalizeRow(row);
29368 var col = cols[sel.col];
29369 if (col.colspan > 1) {
29379 removeColumn : function()
29381 this.deleteColumn({
29383 col : this.no_col-1
29385 this.updateElement();
29389 addColumn : function()
29392 this.rows.forEach(function(row) {
29393 row.push(this.emptyCell());
29396 this.updateElement();
29399 deleteRow : function(sel)
29401 if (!sel || sel.type != 'row') {
29405 if (this.no_row < 2) {
29409 var rows = this.normalizeRows();
29412 rows[sel.row].forEach(function(col) {
29413 if (col.rowspan > 1) {
29416 col.remove = 1; // flage it as removed.
29421 this.rows.forEach(function(row) {
29423 row.forEach(function(c) {
29424 if (typeof(c.remove) == 'undefined') {
29429 if (newrow.length > 0) {
29433 this.rows = newrows;
29438 this.updateElement();
29441 removeRow : function()
29445 row : this.no_row-1
29451 addRow : function()
29455 for (var i = 0; i < this.no_col; i++ ) {
29457 row.push(this.emptyCell());
29460 this.rows.push(row);
29461 this.updateElement();
29465 // the default cell object... at present...
29466 emptyCell : function() {
29467 return (new Roo.htmleditor.BlockTd({})).toObject();
29472 removeNode : function()
29479 resetWidths : function()
29481 Array.from(this.node.getElementsByTagName('td')).forEach(function(n) {
29482 var nn = Roo.htmleditor.Block.factory(n);
29484 nn.updateElement(n);
29497 * since selections really work on the table cell, then editing really should work from there
29499 * The original plan was to support merging etc... - but that may not be needed yet..
29501 * So this simple version will support:
29503 * adjust the width +/-
29504 * reset the width...
29513 * @class Roo.htmleditor.BlockTable
29514 * Block that manages a table
29517 * Create a new Filter.
29518 * @param {Object} config Configuration options
29521 Roo.htmleditor.BlockTd = function(cfg)
29524 this.readElement(cfg.node);
29525 this.updateElement(cfg.node);
29527 Roo.apply(this, cfg);
29532 Roo.extend(Roo.htmleditor.BlockTd, Roo.htmleditor.Block, {
29537 textAlign : 'left',
29544 // used by context menu
29545 friendly_name : 'Table Cell',
29546 deleteTitle : false, // use our customer delete
29548 // context menu is drawn once..
29550 contextMenu : function(toolbar)
29553 var cell = function() {
29554 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
29557 var table = function() {
29558 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode.closest('table'));
29562 var saveSel = function()
29564 lr = toolbar.editorcore.getSelection().getRangeAt(0);
29566 var restoreSel = function()
29570 toolbar.editorcore.focus();
29571 var cr = toolbar.editorcore.getSelection();
29572 cr.removeAllRanges();
29574 toolbar.editorcore.onEditorEvent();
29575 }).defer(10, this);
29581 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
29583 var syncValue = toolbar.editorcore.syncValue;
29590 text : 'Edit Table',
29592 click : function() {
29593 var t = toolbar.tb.selectedNode.closest('table');
29594 toolbar.editorcore.selectNode(t);
29595 toolbar.editorcore.onEditorEvent();
29604 xtype : 'TextItem',
29605 text : "Column Width: ",
29606 xns : rooui.Toolbar
29613 click : function (_self, e)
29615 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29616 cell().shrinkColumn();
29618 toolbar.editorcore.onEditorEvent();
29621 xns : rooui.Toolbar
29627 click : function (_self, e)
29629 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29630 cell().growColumn();
29632 toolbar.editorcore.onEditorEvent();
29635 xns : rooui.Toolbar
29639 xtype : 'TextItem',
29640 text : "Vertical Align: ",
29641 xns : rooui.Toolbar //Boostrap?
29644 xtype : 'ComboBox',
29645 allowBlank : false,
29646 displayField : 'val',
29649 triggerAction : 'all',
29651 valueField : 'val',
29655 select : function (combo, r, index)
29657 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29659 b.valign = r.get('val');
29662 toolbar.editorcore.onEditorEvent();
29667 xtype : 'SimpleStore',
29671 ['bottom'] // there are afew more...
29679 xtype : 'TextItem',
29680 text : "Merge Cells: ",
29681 xns : rooui.Toolbar
29690 click : function (_self, e)
29692 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29693 cell().mergeRight();
29694 //block().growColumn();
29696 toolbar.editorcore.onEditorEvent();
29699 xns : rooui.Toolbar
29706 click : function (_self, e)
29708 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29709 cell().mergeBelow();
29710 //block().growColumn();
29712 toolbar.editorcore.onEditorEvent();
29715 xns : rooui.Toolbar
29718 xtype : 'TextItem',
29720 xns : rooui.Toolbar
29728 click : function (_self, e)
29730 //toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29733 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
29734 toolbar.editorcore.onEditorEvent();
29738 xns : rooui.Toolbar
29742 xns : rooui.Toolbar
29751 xns : rooui.Toolbar,
29760 click : function (_self, e)
29764 cell().deleteColumn();
29766 toolbar.editorcore.selectNode(t.node);
29767 toolbar.editorcore.onEditorEvent();
29776 click : function (_self, e)
29779 cell().deleteRow();
29782 toolbar.editorcore.selectNode(t.node);
29783 toolbar.editorcore.onEditorEvent();
29790 xtype : 'Separator',
29797 click : function (_self, e)
29800 var nn = t.node.nextSibling || t.node.previousSibling;
29801 t.node.parentNode.removeChild(t.node);
29803 toolbar.editorcore.selectNode(nn, true);
29805 toolbar.editorcore.onEditorEvent();
29815 // align... << fixme
29823 * create a DomHelper friendly object - for use with
29824 * Roo.DomHelper.markup / overwrite / etc..
29825 * ?? should it be called with option to hide all editing features?
29828 * create a DomHelper friendly object - for use with
29829 * Roo.DomHelper.markup / overwrite / etc..
29830 * ?? should it be called with option to hide all editing features?
29832 toObject : function()
29836 contenteditable : 'true', // this stops cell selection from picking the table.
29837 'data-block' : 'Td',
29838 valign : this.valign,
29840 'text-align' : this.textAlign,
29841 border : 'solid 1px rgb(0, 0, 0)', // ??? hard coded?
29842 'border-collapse' : 'collapse',
29843 padding : '6px', // 8 for desktop / 4 for mobile
29844 'vertical-align': this.valign
29848 if (this.width != '') {
29849 ret.width = this.width;
29850 ret.style.width = this.width;
29854 if (this.colspan > 1) {
29855 ret.colspan = this.colspan ;
29857 if (this.rowspan > 1) {
29858 ret.rowspan = this.rowspan ;
29867 readElement : function(node)
29869 node = node ? node : this.node ;
29870 this.width = node.style.width;
29871 this.colspan = Math.max(1,1*node.getAttribute('colspan'));
29872 this.rowspan = Math.max(1,1*node.getAttribute('rowspan'));
29873 this.html = node.innerHTML;
29874 if (node.style.textAlign != '') {
29875 this.textAlign = node.style.textAlign;
29881 // the default cell object... at present...
29882 emptyCell : function() {
29886 textAlign : 'left',
29887 html : " " // is this going to be editable now?
29892 removeNode : function()
29894 return this.node.closest('table');
29902 toTableArray : function()
29905 var tab = this.node.closest('tr').closest('table');
29906 Array.from(tab.rows).forEach(function(r, ri){
29910 this.colWidths = [];
29911 var all_auto = true;
29912 Array.from(tab.rows).forEach(function(r, ri){
29915 Array.from(r.cells).forEach(function(ce, ci){
29920 colspan : ce.colSpan,
29921 rowspan : ce.rowSpan
29923 if (ce.isEqualNode(this.node)) {
29926 // if we have been filled up by a row?
29927 if (typeof(ret[rn][cn]) != 'undefined') {
29928 while(typeof(ret[rn][cn]) != 'undefined') {
29934 if (typeof(this.colWidths[cn]) == 'undefined' && c.colspan < 2) {
29935 this.colWidths[cn] = ce.style.width;
29936 if (this.colWidths[cn] != '') {
29942 if (c.colspan < 2 && c.rowspan < 2 ) {
29947 for(var j = 0; j < c.rowspan; j++) {
29948 if (typeof(ret[rn+j]) == 'undefined') {
29949 continue; // we have a problem..
29952 for(var i = 0; i < c.colspan; i++) {
29953 ret[rn+j][cn+i] = c;
29962 // initalize widths.?
29963 // either all widths or no widths..
29965 this.colWidths[0] = false; // no widths flag.
29976 mergeRight: function()
29979 // get the contents of the next cell along..
29980 var tr = this.node.closest('tr');
29981 var i = Array.prototype.indexOf.call(tr.childNodes, this.node);
29982 if (i >= tr.childNodes.length - 1) {
29983 return; // no cells on right to merge with.
29985 var table = this.toTableArray();
29987 if (typeof(table[this.cellData.row][this.cellData.col+this.cellData.colspan]) == 'undefined') {
29988 return; // nothing right?
29990 var rc = table[this.cellData.row][this.cellData.col+this.cellData.colspan];
29991 // right cell - must be same rowspan and on the same row.
29992 if (rc.rowspan != this.cellData.rowspan || rc.row != this.cellData.row) {
29993 return; // right hand side is not same rowspan.
29998 this.node.innerHTML += ' ' + rc.cell.innerHTML;
29999 tr.removeChild(rc.cell);
30000 this.colspan += rc.colspan;
30001 this.node.setAttribute('colspan', this.colspan);
30003 var table = this.toTableArray();
30004 this.normalizeWidths(table);
30005 this.updateWidths(table);
30009 mergeBelow : function()
30011 var table = this.toTableArray();
30012 if (typeof(table[this.cellData.row+this.cellData.rowspan]) == 'undefined') {
30013 return; // no row below
30015 if (typeof(table[this.cellData.row+this.cellData.rowspan][this.cellData.col]) == 'undefined') {
30016 return; // nothing right?
30018 var rc = table[this.cellData.row+this.cellData.rowspan][this.cellData.col];
30020 if (rc.colspan != this.cellData.colspan || rc.col != this.cellData.col) {
30021 return; // right hand side is not same rowspan.
30023 this.node.innerHTML = this.node.innerHTML + rc.cell.innerHTML ;
30024 rc.cell.parentNode.removeChild(rc.cell);
30025 this.rowspan += rc.rowspan;
30026 this.node.setAttribute('rowspan', this.rowspan);
30031 if (this.node.rowSpan < 2 && this.node.colSpan < 2) {
30034 var table = this.toTableArray();
30035 var cd = this.cellData;
30039 for(var r = cd.row; r < cd.row + cd.rowspan; r++) {
30042 for(var c = cd.col; c < cd.col + cd.colspan; c++) {
30043 if (r == cd.row && c == cd.col) {
30044 this.node.removeAttribute('rowspan');
30045 this.node.removeAttribute('colspan');
30048 var ntd = this.node.cloneNode(); // which col/row should be 0..
30049 ntd.removeAttribute('id');
30050 ntd.style.width = this.colWidths[c];
30051 ntd.innerHTML = '';
30052 table[r][c] = { cell : ntd, col : c, row: r , colspan : 1 , rowspan : 1 };
30056 this.redrawAllCells(table);
30062 redrawAllCells: function(table)
30066 var tab = this.node.closest('tr').closest('table');
30067 var ctr = tab.rows[0].parentNode;
30068 Array.from(tab.rows).forEach(function(r, ri){
30070 Array.from(r.cells).forEach(function(ce, ci){
30071 ce.parentNode.removeChild(ce);
30073 r.parentNode.removeChild(r);
30075 for(var r = 0 ; r < table.length; r++) {
30076 var re = tab.rows[r];
30078 var re = tab.ownerDocument.createElement('tr');
30079 ctr.appendChild(re);
30080 for(var c = 0 ; c < table[r].length; c++) {
30081 if (table[r][c].cell === false) {
30085 re.appendChild(table[r][c].cell);
30087 table[r][c].cell = false;
30092 updateWidths : function(table)
30094 for(var r = 0 ; r < table.length; r++) {
30096 for(var c = 0 ; c < table[r].length; c++) {
30097 if (table[r][c].cell === false) {
30101 if (this.colWidths[0] != false && table[r][c].colspan < 2) {
30102 var el = Roo.htmleditor.Block.factory(table[r][c].cell);
30103 el.width = Math.floor(this.colWidths[c]) +'%';
30104 el.updateElement(el.node);
30106 if (this.colWidths[0] != false && table[r][c].colspan > 1) {
30107 var el = Roo.htmleditor.Block.factory(table[r][c].cell);
30109 for(var i = 0; i < table[r][c].colspan; i ++) {
30110 width += Math.floor(this.colWidths[c + i]);
30112 el.width = width +'%';
30113 el.updateElement(el.node);
30115 table[r][c].cell = false; // done
30119 normalizeWidths : function(table)
30121 if (this.colWidths[0] === false) {
30122 var nw = 100.0 / this.colWidths.length;
30123 this.colWidths.forEach(function(w,i) {
30124 this.colWidths[i] = nw;
30129 var t = 0, missing = [];
30131 this.colWidths.forEach(function(w,i) {
30133 this.colWidths[i] = this.colWidths[i] == '' ? 0 : (this.colWidths[i]+'').replace(/[^0-9]+/g,'')*1;
30134 var add = this.colWidths[i];
30143 var nc = this.colWidths.length;
30144 if (missing.length) {
30145 var mult = (nc - missing.length) / (1.0 * nc);
30147 var ew = (100 -t) / (1.0 * missing.length);
30148 this.colWidths.forEach(function(w,i) {
30150 this.colWidths[i] = w * mult;
30154 this.colWidths[i] = ew;
30156 // have to make up numbers..
30159 // now we should have all the widths..
30164 shrinkColumn : function()
30166 var table = this.toTableArray();
30167 this.normalizeWidths(table);
30168 var col = this.cellData.col;
30169 var nw = this.colWidths[col] * 0.8;
30173 var otherAdd = (this.colWidths[col] * 0.2) / (this.colWidths.length -1);
30174 this.colWidths.forEach(function(w,i) {
30176 this.colWidths[i] = nw;
30179 this.colWidths[i] += otherAdd
30181 this.updateWidths(table);
30184 growColumn : function()
30186 var table = this.toTableArray();
30187 this.normalizeWidths(table);
30188 var col = this.cellData.col;
30189 var nw = this.colWidths[col] * 1.2;
30193 var otherSub = (this.colWidths[col] * 0.2) / (this.colWidths.length -1);
30194 this.colWidths.forEach(function(w,i) {
30196 this.colWidths[i] = nw;
30199 this.colWidths[i] -= otherSub
30201 this.updateWidths(table);
30204 deleteRow : function()
30206 // delete this rows 'tr'
30207 // if any of the cells in this row have a rowspan > 1 && row!= this row..
30208 // then reduce the rowspan.
30209 var table = this.toTableArray();
30210 // this.cellData.row;
30211 for (var i =0;i< table[this.cellData.row].length ; i++) {
30212 var c = table[this.cellData.row][i];
30213 if (c.row != this.cellData.row) {
30216 c.cell.setAttribute('rowspan', c.rowspan);
30219 if (c.rowspan > 1) {
30221 c.cell.setAttribute('rowspan', c.rowspan);
30224 table.splice(this.cellData.row,1);
30225 this.redrawAllCells(table);
30228 deleteColumn : function()
30230 var table = this.toTableArray();
30232 for (var i =0;i< table.length ; i++) {
30233 var c = table[i][this.cellData.col];
30234 if (c.col != this.cellData.col) {
30235 table[i][this.cellData.col].colspan--;
30236 } else if (c.colspan > 1) {
30238 c.cell.setAttribute('colspan', c.colspan);
30240 table[i].splice(this.cellData.col,1);
30243 this.redrawAllCells(table);
30251 //<script type="text/javascript">
30254 * Based Ext JS Library 1.1.1
30255 * Copyright(c) 2006-2007, Ext JS, LLC.
30261 * @class Roo.HtmlEditorCore
30262 * @extends Roo.Component
30263 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
30265 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
30268 Roo.HtmlEditorCore = function(config){
30271 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
30276 * @event initialize
30277 * Fires when the editor is fully initialized (including the iframe)
30278 * @param {Roo.HtmlEditorCore} this
30283 * Fires when the editor is first receives the focus. Any insertion must wait
30284 * until after this event.
30285 * @param {Roo.HtmlEditorCore} this
30289 * @event beforesync
30290 * Fires before the textarea is updated with content from the editor iframe. Return false
30291 * to cancel the sync.
30292 * @param {Roo.HtmlEditorCore} this
30293 * @param {String} html
30297 * @event beforepush
30298 * Fires before the iframe editor is updated with content from the textarea. Return false
30299 * to cancel the push.
30300 * @param {Roo.HtmlEditorCore} this
30301 * @param {String} html
30306 * Fires when the textarea is updated with content from the editor iframe.
30307 * @param {Roo.HtmlEditorCore} this
30308 * @param {String} html
30313 * Fires when the iframe editor is updated with content from the textarea.
30314 * @param {Roo.HtmlEditorCore} this
30315 * @param {String} html
30320 * @event editorevent
30321 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
30322 * @param {Roo.HtmlEditorCore} this
30329 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
30331 // defaults : white / black...
30332 this.applyBlacklists();
30339 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
30343 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
30349 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
30354 * @cfg {Number} height (in pixels)
30358 * @cfg {Number} width (in pixels)
30362 * @cfg {boolean} autoClean - default true - loading and saving will remove quite a bit of formating,
30363 * if you are doing an email editor, this probably needs disabling, it's designed
30368 * @cfg {boolean} enableBlocks - default true - if the block editor (table and figure should be enabled)
30370 enableBlocks : true,
30372 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
30375 stylesheets: false,
30377 * @cfg {String} language default en - language of text (usefull for rtl languages)
30383 * @cfg {boolean} allowComments - default false - allow comments in HTML source
30384 * - by default they are stripped - if you are editing email you may need this.
30386 allowComments: false,
30390 // private properties
30391 validationEvent : false,
30393 initialized : false,
30395 sourceEditMode : false,
30396 onFocus : Roo.emptyFn,
30398 hideMode:'offsets',
30402 // blacklist + whitelisted elements..
30409 undoManager : false,
30411 * Protected method that will not generally be called directly. It
30412 * is called when the editor initializes the iframe with HTML contents. Override this method if you
30413 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
30415 getDocMarkup : function(){
30419 // inherit styels from page...??
30420 if (this.stylesheets === false) {
30422 Roo.get(document.head).select('style').each(function(node) {
30423 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
30426 Roo.get(document.head).select('link').each(function(node) {
30427 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
30430 } else if (!this.stylesheets.length) {
30432 st = '<style type="text/css">' +
30433 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
30436 for (var i in this.stylesheets) {
30437 if (typeof(this.stylesheets[i]) != 'string') {
30440 st += '<link rel="stylesheet" href="' + this.stylesheets[i] +'" type="text/css">';
30445 st += '<style type="text/css">' +
30446 'IMG { cursor: pointer } ' +
30449 st += '<meta name="google" content="notranslate">';
30451 var cls = 'notranslate roo-htmleditor-body';
30453 if(this.bodyCls.length){
30454 cls += ' ' + this.bodyCls;
30457 return '<html class="notranslate" translate="no"><head>' + st +
30458 //<style type="text/css">' +
30459 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
30461 ' </head><body contenteditable="true" data-enable-grammerly="true" class="' + cls + '"></body></html>';
30465 onRender : function(ct, position)
30468 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
30469 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
30472 this.el.dom.style.border = '0 none';
30473 this.el.dom.setAttribute('tabIndex', -1);
30474 this.el.addClass('x-hidden hide');
30478 if(Roo.isIE){ // fix IE 1px bogus margin
30479 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
30483 this.frameId = Roo.id();
30487 var iframe = this.owner.wrap.createChild({
30489 cls: 'form-control', // bootstrap..
30491 name: this.frameId,
30492 frameBorder : 'no',
30493 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
30498 this.iframe = iframe.dom;
30500 this.assignDocWin();
30502 this.doc.designMode = 'on';
30505 this.doc.write(this.getDocMarkup());
30509 var task = { // must defer to wait for browser to be ready
30511 //console.log("run task?" + this.doc.readyState);
30512 this.assignDocWin();
30513 if(this.doc.body || this.doc.readyState == 'complete'){
30515 this.doc.designMode="on";
30520 Roo.TaskMgr.stop(task);
30521 this.initEditor.defer(10, this);
30528 Roo.TaskMgr.start(task);
30533 onResize : function(w, h)
30535 Roo.log('resize: ' +w + ',' + h );
30536 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
30540 if(typeof w == 'number'){
30542 this.iframe.style.width = w + 'px';
30544 if(typeof h == 'number'){
30546 this.iframe.style.height = h + 'px';
30548 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
30555 * Toggles the editor between standard and source edit mode.
30556 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
30558 toggleSourceEdit : function(sourceEditMode){
30560 this.sourceEditMode = sourceEditMode === true;
30562 if(this.sourceEditMode){
30564 Roo.get(this.iframe).addClass(['x-hidden','hide', 'd-none']); //FIXME - what's the BS styles for these
30567 Roo.get(this.iframe).removeClass(['x-hidden','hide', 'd-none']);
30568 //this.iframe.className = '';
30571 //this.setSize(this.owner.wrap.getSize());
30572 //this.fireEvent('editmodechange', this, this.sourceEditMode);
30579 * Protected method that will not generally be called directly. If you need/want
30580 * custom HTML cleanup, this is the method you should override.
30581 * @param {String} html The HTML to be cleaned
30582 * return {String} The cleaned HTML
30584 cleanHtml : function(html)
30586 html = String(html);
30587 if(html.length > 5){
30588 if(Roo.isSafari){ // strip safari nonsense
30589 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
30592 if(html == ' '){
30599 * HTML Editor -> Textarea
30600 * Protected method that will not generally be called directly. Syncs the contents
30601 * of the editor iframe with the textarea.
30603 syncValue : function()
30605 //Roo.log("HtmlEditorCore:syncValue (EDITOR->TEXT)");
30606 if(this.initialized){
30608 if (this.undoManager) {
30609 this.undoManager.addEvent();
30613 var bd = (this.doc.body || this.doc.documentElement);
30616 var sel = this.win.getSelection();
30618 var div = document.createElement('div');
30619 div.innerHTML = bd.innerHTML;
30620 var gtx = div.getElementsByClassName('gtx-trans-icon'); // google translate - really annoying and difficult to get rid of.
30621 if (gtx.length > 0) {
30622 var rm = gtx.item(0).parentNode;
30623 rm.parentNode.removeChild(rm);
30627 if (this.enableBlocks) {
30628 new Roo.htmleditor.FilterBlock({ node : div });
30631 var html = div.innerHTML;
30634 if (this.autoClean) {
30636 new Roo.htmleditor.FilterAttributes({
30657 attrib_clean : ['href', 'src' ]
30660 var tidy = new Roo.htmleditor.TidySerializer({
30663 html = tidy.serialize(div);
30669 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
30670 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
30672 html = '<div style="'+m[0]+'">' + html + '</div>';
30675 html = this.cleanHtml(html);
30676 // fix up the special chars.. normaly like back quotes in word...
30677 // however we do not want to do this with chinese..
30678 html = html.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g, function(match) {
30680 var cc = match.charCodeAt();
30682 // Get the character value, handling surrogate pairs
30683 if (match.length == 2) {
30684 // It's a surrogate pair, calculate the Unicode code point
30685 var high = match.charCodeAt(0) - 0xD800;
30686 var low = match.charCodeAt(1) - 0xDC00;
30687 cc = (high * 0x400) + low + 0x10000;
30689 (cc >= 0x4E00 && cc < 0xA000 ) ||
30690 (cc >= 0x3400 && cc < 0x4E00 ) ||
30691 (cc >= 0xf900 && cc < 0xfb00 )
30696 // No, use a numeric entity. Here we brazenly (and possibly mistakenly)
30697 return "&#" + cc + ";";
30704 if(this.owner.fireEvent('beforesync', this, html) !== false){
30705 this.el.dom.value = html;
30706 this.owner.fireEvent('sync', this, html);
30712 * TEXTAREA -> EDITABLE
30713 * Protected method that will not generally be called directly. Pushes the value of the textarea
30714 * into the iframe editor.
30716 pushValue : function()
30718 //Roo.log("HtmlEditorCore:pushValue (TEXT->EDITOR)");
30719 if(this.initialized){
30720 var v = this.el.dom.value.trim();
30723 if(this.owner.fireEvent('beforepush', this, v) !== false){
30724 var d = (this.doc.body || this.doc.documentElement);
30727 this.el.dom.value = d.innerHTML;
30728 this.owner.fireEvent('push', this, v);
30730 if (this.autoClean) {
30731 new Roo.htmleditor.FilterParagraph({node : this.doc.body}); // paragraphs
30732 new Roo.htmleditor.FilterSpan({node : this.doc.body}); // empty spans
30734 if (this.enableBlocks) {
30735 Roo.htmleditor.Block.initAll(this.doc.body);
30738 this.updateLanguage();
30740 var lc = this.doc.body.lastChild;
30741 if (lc && lc.nodeType == 1 && lc.getAttribute("contenteditable") == "false") {
30742 // add an extra line at the end.
30743 this.doc.body.appendChild(this.doc.createElement('br'));
30751 deferFocus : function(){
30752 this.focus.defer(10, this);
30756 focus : function(){
30757 if(this.win && !this.sourceEditMode){
30764 assignDocWin: function()
30766 var iframe = this.iframe;
30769 this.doc = iframe.contentWindow.document;
30770 this.win = iframe.contentWindow;
30772 // if (!Roo.get(this.frameId)) {
30775 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
30776 // this.win = Roo.get(this.frameId).dom.contentWindow;
30778 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
30782 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
30783 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
30788 initEditor : function(){
30789 //console.log("INIT EDITOR");
30790 this.assignDocWin();
30794 this.doc.designMode="on";
30796 this.doc.write(this.getDocMarkup());
30799 var dbody = (this.doc.body || this.doc.documentElement);
30800 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
30801 // this copies styles from the containing element into thsi one..
30802 // not sure why we need all of this..
30803 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
30805 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
30806 //ss['background-attachment'] = 'fixed'; // w3c
30807 dbody.bgProperties = 'fixed'; // ie
30808 dbody.setAttribute("translate", "no");
30810 //Roo.DomHelper.applyStyles(dbody, ss);
30811 Roo.EventManager.on(this.doc, {
30813 'mouseup': this.onEditorEvent,
30814 'dblclick': this.onEditorEvent,
30815 'click': this.onEditorEvent,
30816 'keyup': this.onEditorEvent,
30821 Roo.EventManager.on(this.doc, {
30822 'paste': this.onPasteEvent,
30826 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
30829 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
30830 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
30832 this.initialized = true;
30835 // initialize special key events - enter
30836 new Roo.htmleditor.KeyEnter({core : this});
30840 this.owner.fireEvent('initialize', this);
30843 // this is to prevent a href clicks resulting in a redirect?
30845 onPasteEvent : function(e,v)
30847 // I think we better assume paste is going to be a dirty load of rubish from word..
30849 // even pasting into a 'email version' of this widget will have to clean up that mess.
30850 var cd = (e.browserEvent.clipboardData || window.clipboardData);
30852 // check what type of paste - if it's an image, then handle it differently.
30853 if (cd.files && cd.files.length > 0) {
30855 var urlAPI = (window.createObjectURL && window) ||
30856 (window.URL && URL.revokeObjectURL && URL) ||
30857 (window.webkitURL && webkitURL);
30859 var url = urlAPI.createObjectURL( cd.files[0]);
30860 this.insertAtCursor('<img src=" + url + ">');
30863 if (cd.types.indexOf('text/html') < 0 ) {
30867 var html = cd.getData('text/html'); // clipboard event
30868 if (cd.types.indexOf('text/rtf') > -1) {
30869 var parser = new Roo.rtf.Parser(cd.getData('text/rtf'));
30870 images = parser.doc ? parser.doc.getElementsByType('pict') : [];
30875 images = images.filter(function(g) { return !g.path.match(/^rtf\/(head|pgdsctbl|listtable|footerf)/); }) // ignore headers/footers etc.
30876 .map(function(g) { return g.toDataURL(); })
30877 .filter(function(g) { return g != 'about:blank'; });
30880 html = this.cleanWordChars(html);
30882 var d = (new DOMParser().parseFromString(html, 'text/html')).body;
30885 var sn = this.getParentElement();
30886 // check if d contains a table, and prevent nesting??
30887 //Roo.log(d.getElementsByTagName('table'));
30889 //Roo.log(sn.closest('table'));
30890 if (d.getElementsByTagName('table').length && sn && sn.closest('table')) {
30891 e.preventDefault();
30892 this.insertAtCursor("You can not nest tables");
30893 //Roo.log("prevent?"); // fixme -
30899 if (images.length > 0) {
30900 // replace all v:imagedata - with img.
30901 var ar = Array.from(d.getElementsByTagName('v:imagedata'));
30902 Roo.each(ar, function(node) {
30903 node.parentNode.insertBefore(d.ownerDocument.createElement('img'), node );
30904 node.parentNode.removeChild(node);
30908 Roo.each(d.getElementsByTagName('img'), function(img, i) {
30909 img.setAttribute('src', images[i]);
30912 if (this.autoClean) {
30913 new Roo.htmleditor.FilterWord({ node : d });
30915 new Roo.htmleditor.FilterStyleToTag({ node : d });
30916 new Roo.htmleditor.FilterAttributes({
30918 attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'],
30919 attrib_clean : ['href', 'src' ]
30921 new Roo.htmleditor.FilterBlack({ node : d, tag : this.black});
30922 // should be fonts..
30923 new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT', ':' ]} );
30924 new Roo.htmleditor.FilterParagraph({ node : d });
30925 new Roo.htmleditor.FilterSpan({ node : d });
30926 new Roo.htmleditor.FilterLongBr({ node : d });
30927 new Roo.htmleditor.FilterComment({ node : d });
30931 if (this.enableBlocks) {
30933 Array.from(d.getElementsByTagName('img')).forEach(function(img) {
30934 if (img.closest('figure')) { // assume!! that it's aready
30937 var fig = new Roo.htmleditor.BlockFigure({
30938 image_src : img.src
30940 fig.updateElement(img); // replace it..
30946 this.insertAtCursor(d.innerHTML.replace(/ /g,' '));
30947 if (this.enableBlocks) {
30948 Roo.htmleditor.Block.initAll(this.doc.body);
30952 e.preventDefault();
30954 // default behaveiour should be our local cleanup paste? (optional?)
30955 // for simple editor - we want to hammer the paste and get rid of everything... - so over-rideable..
30956 //this.owner.fireEvent('paste', e, v);
30959 onDestroy : function(){
30965 //for (var i =0; i < this.toolbars.length;i++) {
30966 // // fixme - ask toolbars for heights?
30967 // this.toolbars[i].onDestroy();
30970 //this.wrap.dom.innerHTML = '';
30971 //this.wrap.remove();
30976 onFirstFocus : function(){
30978 this.assignDocWin();
30979 this.undoManager = new Roo.lib.UndoManager(100,(this.doc.body || this.doc.documentElement));
30981 this.activated = true;
30984 if(Roo.isGecko){ // prevent silly gecko errors
30986 var s = this.win.getSelection();
30987 if(!s.focusNode || s.focusNode.nodeType != 3){
30988 var r = s.getRangeAt(0);
30989 r.selectNodeContents((this.doc.body || this.doc.documentElement));
30994 this.execCmd('useCSS', true);
30995 this.execCmd('styleWithCSS', false);
30998 this.owner.fireEvent('activate', this);
31002 adjustFont: function(btn){
31003 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
31004 //if(Roo.isSafari){ // safari
31007 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
31008 if(Roo.isSafari){ // safari
31009 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
31010 v = (v < 10) ? 10 : v;
31011 v = (v > 48) ? 48 : v;
31012 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
31017 v = Math.max(1, v+adjust);
31019 this.execCmd('FontSize', v );
31022 onEditorEvent : function(e)
31026 if (e && (e.ctrlKey || e.metaKey) && e.keyCode === 90) {
31027 return; // we do not handle this.. (undo manager does..)
31029 // in theory this detects if the last element is not a br, then we try and do that.
31030 // its so clicking in space at bottom triggers adding a br and moving the cursor.
31032 e.target.nodeName == 'BODY' &&
31033 e.type == "mouseup" &&
31034 this.doc.body.lastChild
31036 var lc = this.doc.body.lastChild;
31037 // gtx-trans is google translate plugin adding crap.
31038 while ((lc.nodeType == 3 && lc.nodeValue == '') || lc.id == 'gtx-trans') {
31039 lc = lc.previousSibling;
31041 if (lc.nodeType == 1 && lc.nodeName != 'BR') {
31042 // if last element is <BR> - then dont do anything.
31044 var ns = this.doc.createElement('br');
31045 this.doc.body.appendChild(ns);
31046 range = this.doc.createRange();
31047 range.setStartAfter(ns);
31048 range.collapse(true);
31049 var sel = this.win.getSelection();
31050 sel.removeAllRanges();
31051 sel.addRange(range);
31057 this.fireEditorEvent(e);
31058 // this.updateToolbar();
31059 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
31062 fireEditorEvent: function(e)
31064 this.owner.fireEvent('editorevent', this, e);
31067 insertTag : function(tg)
31069 // could be a bit smarter... -> wrap the current selected tRoo..
31070 if (tg.toLowerCase() == 'span' ||
31071 tg.toLowerCase() == 'code' ||
31072 tg.toLowerCase() == 'sup' ||
31073 tg.toLowerCase() == 'sub'
31076 range = this.createRange(this.getSelection());
31077 var wrappingNode = this.doc.createElement(tg.toLowerCase());
31078 wrappingNode.appendChild(range.extractContents());
31079 range.insertNode(wrappingNode);
31086 this.execCmd("formatblock", tg);
31087 this.undoManager.addEvent();
31090 insertText : function(txt)
31094 var range = this.createRange();
31095 range.deleteContents();
31096 //alert(Sender.getAttribute('label'));
31098 range.insertNode(this.doc.createTextNode(txt));
31099 this.undoManager.addEvent();
31105 * Executes a Midas editor command on the editor document and performs necessary focus and
31106 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
31107 * @param {String} cmd The Midas command
31108 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
31110 relayCmd : function(cmd, value)
31114 case 'justifyleft':
31115 case 'justifyright':
31116 case 'justifycenter':
31117 // if we are in a cell, then we will adjust the
31118 var n = this.getParentElement();
31119 var td = n.closest('td');
31121 var bl = Roo.htmleditor.Block.factory(td);
31122 bl.textAlign = cmd.replace('justify','');
31123 bl.updateElement();
31124 this.owner.fireEvent('editorevent', this);
31127 this.execCmd('styleWithCSS', true); //
31131 // if there is no selection, then we insert, and set the curson inside it..
31132 this.execCmd('styleWithCSS', false);
31142 this.execCmd(cmd, value);
31143 this.owner.fireEvent('editorevent', this);
31144 //this.updateToolbar();
31145 this.owner.deferFocus();
31149 * Executes a Midas editor command directly on the editor document.
31150 * For visual commands, you should use {@link #relayCmd} instead.
31151 * <b>This should only be called after the editor is initialized.</b>
31152 * @param {String} cmd The Midas command
31153 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
31155 execCmd : function(cmd, value){
31156 this.doc.execCommand(cmd, false, value === undefined ? null : value);
31163 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
31165 * @param {String} text | dom node..
31167 insertAtCursor : function(text)
31170 if(!this.activated){
31174 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
31178 // from jquery ui (MIT licenced)
31180 var win = this.win;
31182 if (win.getSelection && win.getSelection().getRangeAt) {
31184 // delete the existing?
31186 this.createRange(this.getSelection()).deleteContents();
31187 range = win.getSelection().getRangeAt(0);
31188 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
31189 range.insertNode(node);
31190 range = range.cloneRange();
31191 range.collapse(false);
31193 win.getSelection().removeAllRanges();
31194 win.getSelection().addRange(range);
31198 } else if (win.document.selection && win.document.selection.createRange) {
31199 // no firefox support
31200 var txt = typeof(text) == 'string' ? text : text.outerHTML;
31201 win.document.selection.createRange().pasteHTML(txt);
31204 // no firefox support
31205 var txt = typeof(text) == 'string' ? text : text.outerHTML;
31206 this.execCmd('InsertHTML', txt);
31214 mozKeyPress : function(e){
31216 var c = e.getCharCode(), cmd;
31219 c = String.fromCharCode(c).toLowerCase();
31233 // this.cleanUpPaste.defer(100, this);
31239 this.relayCmd(cmd);
31240 //this.win.focus();
31241 //this.execCmd(cmd);
31242 //this.deferFocus();
31243 e.preventDefault();
31251 fixKeys : function(){ // load time branching for fastest keydown performance
31255 return function(e){
31256 var k = e.getKey(), r;
31259 r = this.doc.selection.createRange();
31262 r.pasteHTML('    ');
31267 /// this is handled by Roo.htmleditor.KeyEnter
31270 r = this.doc.selection.createRange();
31272 var target = r.parentElement();
31273 if(!target || target.tagName.toLowerCase() != 'li'){
31275 r.pasteHTML('<br/>');
31282 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
31283 // this.cleanUpPaste.defer(100, this);
31289 }else if(Roo.isOpera){
31290 return function(e){
31291 var k = e.getKey();
31295 this.execCmd('InsertHTML','    ');
31299 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
31300 // this.cleanUpPaste.defer(100, this);
31305 }else if(Roo.isSafari){
31306 return function(e){
31307 var k = e.getKey();
31311 this.execCmd('InsertText','\t');
31315 this.mozKeyPress(e);
31317 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
31318 // this.cleanUpPaste.defer(100, this);
31326 getAllAncestors: function()
31328 var p = this.getSelectedNode();
31331 a.push(p); // push blank onto stack..
31332 p = this.getParentElement();
31336 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
31340 a.push(this.doc.body);
31344 lastSelNode : false,
31347 getSelection : function()
31349 this.assignDocWin();
31350 return Roo.lib.Selection.wrap(Roo.isIE ? this.doc.selection : this.win.getSelection(), this.doc);
31353 * Select a dom node
31354 * @param {DomElement} node the node to select
31356 selectNode : function(node, collapse)
31358 var nodeRange = node.ownerDocument.createRange();
31360 nodeRange.selectNode(node);
31362 nodeRange.selectNodeContents(node);
31364 if (collapse === true) {
31365 nodeRange.collapse(true);
31368 var s = this.win.getSelection();
31369 s.removeAllRanges();
31370 s.addRange(nodeRange);
31373 getSelectedNode: function()
31375 // this may only work on Gecko!!!
31377 // should we cache this!!!!
31381 var range = this.createRange(this.getSelection()).cloneRange();
31384 var parent = range.parentElement();
31386 var testRange = range.duplicate();
31387 testRange.moveToElementText(parent);
31388 if (testRange.inRange(range)) {
31391 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
31394 parent = parent.parentElement;
31399 // is ancestor a text element.
31400 var ac = range.commonAncestorContainer;
31401 if (ac.nodeType == 3) {
31402 ac = ac.parentNode;
31405 var ar = ac.childNodes;
31408 var other_nodes = [];
31409 var has_other_nodes = false;
31410 for (var i=0;i<ar.length;i++) {
31411 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
31414 // fullly contained node.
31416 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
31421 // probably selected..
31422 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
31423 other_nodes.push(ar[i]);
31427 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
31432 has_other_nodes = true;
31434 if (!nodes.length && other_nodes.length) {
31435 nodes= other_nodes;
31437 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
31445 createRange: function(sel)
31447 // this has strange effects when using with
31448 // top toolbar - not sure if it's a great idea.
31449 //this.editor.contentWindow.focus();
31450 if (typeof sel != "undefined") {
31452 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
31454 return this.doc.createRange();
31457 return this.doc.createRange();
31460 getParentElement: function()
31463 this.assignDocWin();
31464 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
31466 var range = this.createRange(sel);
31469 var p = range.commonAncestorContainer;
31470 while (p.nodeType == 3) { // text node
31481 * Range intersection.. the hard stuff...
31485 * [ -- selected range --- ]
31489 * if end is before start or hits it. fail.
31490 * if start is after end or hits it fail.
31492 * if either hits (but other is outside. - then it's not
31498 // @see http://www.thismuchiknow.co.uk/?p=64.
31499 rangeIntersectsNode : function(range, node)
31501 var nodeRange = node.ownerDocument.createRange();
31503 nodeRange.selectNode(node);
31505 nodeRange.selectNodeContents(node);
31508 var rangeStartRange = range.cloneRange();
31509 rangeStartRange.collapse(true);
31511 var rangeEndRange = range.cloneRange();
31512 rangeEndRange.collapse(false);
31514 var nodeStartRange = nodeRange.cloneRange();
31515 nodeStartRange.collapse(true);
31517 var nodeEndRange = nodeRange.cloneRange();
31518 nodeEndRange.collapse(false);
31520 return rangeStartRange.compareBoundaryPoints(
31521 Range.START_TO_START, nodeEndRange) == -1 &&
31522 rangeEndRange.compareBoundaryPoints(
31523 Range.START_TO_START, nodeStartRange) == 1;
31527 rangeCompareNode : function(range, node)
31529 var nodeRange = node.ownerDocument.createRange();
31531 nodeRange.selectNode(node);
31533 nodeRange.selectNodeContents(node);
31537 range.collapse(true);
31539 nodeRange.collapse(true);
31541 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
31542 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
31544 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
31546 var nodeIsBefore = ss == 1;
31547 var nodeIsAfter = ee == -1;
31549 if (nodeIsBefore && nodeIsAfter) {
31552 if (!nodeIsBefore && nodeIsAfter) {
31553 return 1; //right trailed.
31556 if (nodeIsBefore && !nodeIsAfter) {
31557 return 2; // left trailed.
31563 cleanWordChars : function(input) {// change the chars to hex code
31566 [ 8211, "–" ],
31567 [ 8212, "—" ],
31575 var output = input;
31576 Roo.each(swapCodes, function(sw) {
31577 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
31579 output = output.replace(swapper, sw[1]);
31589 cleanUpChild : function (node)
31592 new Roo.htmleditor.FilterComment({node : node});
31593 new Roo.htmleditor.FilterAttributes({
31595 attrib_black : this.ablack,
31596 attrib_clean : this.aclean,
31597 style_white : this.cwhite,
31598 style_black : this.cblack
31600 new Roo.htmleditor.FilterBlack({ node : node, tag : this.black});
31601 new Roo.htmleditor.FilterKeepChildren({node : node, tag : this.tag_remove} );
31607 * Clean up MS wordisms...
31608 * @deprecated - use filter directly
31610 cleanWord : function(node)
31612 new Roo.htmleditor.FilterWord({ node : node ? node : this.doc.body });
31613 new Roo.htmleditor.FilterKeepChildren({node : node ? node : this.doc.body, tag : [ 'FONT', ':' ]} );
31620 * @deprecated - use filters
31622 cleanTableWidths : function(node)
31624 new Roo.htmleditor.FilterTableWidth({ node : node ? node : this.doc.body});
31631 applyBlacklists : function()
31633 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
31634 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
31636 this.aclean = typeof(this.owner.aclean) != 'undefined' && this.owner.aclean ? this.owner.aclean : Roo.HtmlEditorCore.aclean;
31637 this.ablack = typeof(this.owner.ablack) != 'undefined' && this.owner.ablack ? this.owner.ablack : Roo.HtmlEditorCore.ablack;
31638 this.tag_remove = typeof(this.owner.tag_remove) != 'undefined' && this.owner.tag_remove ? this.owner.tag_remove : Roo.HtmlEditorCore.tag_remove;
31642 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
31643 if (b.indexOf(tag) > -1) {
31646 this.white.push(tag);
31650 Roo.each(w, function(tag) {
31651 if (b.indexOf(tag) > -1) {
31654 if (this.white.indexOf(tag) > -1) {
31657 this.white.push(tag);
31662 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
31663 if (w.indexOf(tag) > -1) {
31666 this.black.push(tag);
31670 Roo.each(b, function(tag) {
31671 if (w.indexOf(tag) > -1) {
31674 if (this.black.indexOf(tag) > -1) {
31677 this.black.push(tag);
31682 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
31683 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
31687 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
31688 if (b.indexOf(tag) > -1) {
31691 this.cwhite.push(tag);
31695 Roo.each(w, function(tag) {
31696 if (b.indexOf(tag) > -1) {
31699 if (this.cwhite.indexOf(tag) > -1) {
31702 this.cwhite.push(tag);
31707 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
31708 if (w.indexOf(tag) > -1) {
31711 this.cblack.push(tag);
31715 Roo.each(b, function(tag) {
31716 if (w.indexOf(tag) > -1) {
31719 if (this.cblack.indexOf(tag) > -1) {
31722 this.cblack.push(tag);
31727 setStylesheets : function(stylesheets)
31729 if(typeof(stylesheets) == 'string'){
31730 Roo.get(this.iframe.contentDocument.head).createChild({
31732 rel : 'stylesheet',
31741 Roo.each(stylesheets, function(s) {
31746 Roo.get(_this.iframe.contentDocument.head).createChild({
31748 rel : 'stylesheet',
31758 updateLanguage : function()
31760 if (!this.iframe || !this.iframe.contentDocument) {
31763 Roo.get(this.iframe.contentDocument.body).attr("lang", this.language);
31767 removeStylesheets : function()
31771 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
31776 setStyle : function(style)
31778 Roo.get(this.iframe.contentDocument.head).createChild({
31787 // hide stuff that is not compatible
31801 * @event specialkey
31805 * @cfg {String} fieldClass @hide
31808 * @cfg {String} focusClass @hide
31811 * @cfg {String} autoCreate @hide
31814 * @cfg {String} inputType @hide
31817 * @cfg {String} invalidClass @hide
31820 * @cfg {String} invalidText @hide
31823 * @cfg {String} msgFx @hide
31826 * @cfg {String} validateOnBlur @hide
31830 Roo.HtmlEditorCore.white = [
31831 'AREA', 'BR', 'IMG', 'INPUT', 'HR', 'WBR',
31833 'ADDRESS', 'BLOCKQUOTE', 'CENTER', 'DD', 'DIR', 'DIV',
31834 'DL', 'DT', 'H1', 'H2', 'H3', 'H4',
31835 'H5', 'H6', 'HR', 'ISINDEX', 'LISTING', 'MARQUEE',
31836 'MENU', 'MULTICOL', 'OL', 'P', 'PLAINTEXT', 'PRE',
31837 'TABLE', 'UL', 'XMP',
31839 'CAPTION', 'COL', 'COLGROUP', 'TBODY', 'TD', 'TFOOT', 'TH',
31842 'DIR', 'MENU', 'OL', 'UL', 'DL',
31848 Roo.HtmlEditorCore.black = [
31849 // 'embed', 'object', // enable - backend responsiblity to clean thiese
31851 'BASE', 'BASEFONT', 'BGSOUND', 'BLINK', 'BODY',
31852 'FRAME', 'FRAMESET', 'HEAD', 'HTML', 'ILAYER',
31853 'IFRAME', 'LAYER', 'LINK', 'META', 'OBJECT',
31854 'SCRIPT', 'STYLE' ,'TITLE', 'XML',
31855 //'FONT' // CLEAN LATER..
31856 'COLGROUP', 'COL' // messy tables.
31860 Roo.HtmlEditorCore.clean = [ // ?? needed???
31861 'SCRIPT', 'STYLE', 'TITLE', 'XML'
31863 Roo.HtmlEditorCore.tag_remove = [
31868 Roo.HtmlEditorCore.ablack = [
31872 Roo.HtmlEditorCore.aclean = [
31873 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
31877 Roo.HtmlEditorCore.pwhite= [
31878 'http', 'https', 'mailto'
31881 // white listed style attributes.
31882 Roo.HtmlEditorCore.cwhite= [
31883 // 'text-align', /// default is to allow most things..
31889 // black listed style attributes.
31890 Roo.HtmlEditorCore.cblack= [
31891 // 'font-size' -- this can be set by the project
31905 * @class Roo.bootstrap.form.HtmlEditor
31906 * @extends Roo.bootstrap.form.TextArea
31907 * Bootstrap HtmlEditor class
31910 * Create a new HtmlEditor
31911 * @param {Object} config The config object
31914 Roo.bootstrap.form.HtmlEditor = function(config){
31915 Roo.bootstrap.form.HtmlEditor.superclass.constructor.call(this, config);
31916 if (!this.toolbars) {
31917 this.toolbars = [];
31920 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
31923 * @event initialize
31924 * Fires when the editor is fully initialized (including the iframe)
31925 * @param {HtmlEditor} this
31930 * Fires when the editor is first receives the focus. Any insertion must wait
31931 * until after this event.
31932 * @param {HtmlEditor} this
31936 * @event beforesync
31937 * Fires before the textarea is updated with content from the editor iframe. Return false
31938 * to cancel the sync.
31939 * @param {HtmlEditor} this
31940 * @param {String} html
31944 * @event beforepush
31945 * Fires before the iframe editor is updated with content from the textarea. Return false
31946 * to cancel the push.
31947 * @param {HtmlEditor} this
31948 * @param {String} html
31953 * Fires when the textarea is updated with content from the editor iframe.
31954 * @param {HtmlEditor} this
31955 * @param {String} html
31960 * Fires when the iframe editor is updated with content from the textarea.
31961 * @param {HtmlEditor} this
31962 * @param {String} html
31966 * @event editmodechange
31967 * Fires when the editor switches edit modes
31968 * @param {HtmlEditor} this
31969 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
31971 editmodechange: true,
31973 * @event editorevent
31974 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
31975 * @param {HtmlEditor} this
31979 * @event firstfocus
31980 * Fires when on first focus - needed by toolbars..
31981 * @param {HtmlEditor} this
31986 * Auto save the htmlEditor value as a file into Events
31987 * @param {HtmlEditor} this
31991 * @event savedpreview
31992 * preview the saved version of htmlEditor
31993 * @param {HtmlEditor} this
32000 Roo.extend(Roo.bootstrap.form.HtmlEditor, Roo.bootstrap.form.TextArea, {
32004 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
32009 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
32014 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
32019 * @cfg {Number} height (in pixels)
32023 * @cfg {Number} width (in pixels)
32028 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
32031 stylesheets: false,
32036 // private properties
32037 validationEvent : false,
32039 initialized : false,
32042 onFocus : Roo.emptyFn,
32044 hideMode:'offsets',
32046 tbContainer : false,
32050 toolbarContainer :function() {
32051 return this.wrap.select('.x-html-editor-tb',true).first();
32055 * Protected method that will not generally be called directly. It
32056 * is called when the editor creates its toolbar. Override this method if you need to
32057 * add custom toolbar buttons.
32058 * @param {HtmlEditor} editor
32060 createToolbar : function(){
32061 Roo.log('renewing');
32062 Roo.log("create toolbars");
32064 this.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard({editor: this} ) ];
32065 this.toolbars[0].render(this.toolbarContainer());
32069 // if (!editor.toolbars || !editor.toolbars.length) {
32070 // editor.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard() ]; // can be empty?
32073 // for (var i =0 ; i < editor.toolbars.length;i++) {
32074 // editor.toolbars[i] = Roo.factory(
32075 // typeof(editor.toolbars[i]) == 'string' ?
32076 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
32077 // Roo.bootstrap.form.HtmlEditor);
32078 // editor.toolbars[i].init(editor);
32084 onRender : function(ct, position)
32086 // Roo.log("Call onRender: " + this.xtype);
32088 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
32090 this.wrap = this.inputEl().wrap({
32091 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
32094 this.editorcore.onRender(ct, position);
32096 if (this.resizable) {
32097 this.resizeEl = new Roo.Resizable(this.wrap, {
32101 minHeight : this.height,
32102 height: this.height,
32103 handles : this.resizable,
32106 resize : function(r, w, h) {
32107 _t.onResize(w,h); // -something
32113 this.createToolbar(this);
32116 if(!this.width && this.resizable){
32117 this.setSize(this.wrap.getSize());
32119 if (this.resizeEl) {
32120 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
32121 // should trigger onReize..
32127 onResize : function(w, h)
32129 Roo.log('resize: ' +w + ',' + h );
32130 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
32134 if(this.inputEl() ){
32135 if(typeof w == 'number'){
32136 var aw = w - this.wrap.getFrameWidth('lr');
32137 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
32140 if(typeof h == 'number'){
32141 var tbh = -11; // fixme it needs to tool bar size!
32142 for (var i =0; i < this.toolbars.length;i++) {
32143 // fixme - ask toolbars for heights?
32144 tbh += this.toolbars[i].el.getHeight();
32145 //if (this.toolbars[i].footer) {
32146 // tbh += this.toolbars[i].footer.el.getHeight();
32154 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
32155 ah -= 5; // knock a few pixes off for look..
32156 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
32160 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
32161 this.editorcore.onResize(ew,eh);
32166 * Toggles the editor between standard and source edit mode.
32167 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
32169 toggleSourceEdit : function(sourceEditMode)
32171 this.editorcore.toggleSourceEdit(sourceEditMode);
32173 if(this.editorcore.sourceEditMode){
32174 Roo.log('editor - showing textarea');
32177 // Roo.log(this.syncValue());
32179 this.inputEl().removeClass(['hide', 'x-hidden']);
32180 this.inputEl().dom.removeAttribute('tabIndex');
32181 this.inputEl().focus();
32183 Roo.log('editor - hiding textarea');
32185 // Roo.log(this.pushValue());
32188 this.inputEl().addClass(['hide', 'x-hidden']);
32189 this.inputEl().dom.setAttribute('tabIndex', -1);
32190 //this.deferFocus();
32193 if(this.resizable){
32194 this.setSize(this.wrap.getSize());
32197 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
32200 // private (for BoxComponent)
32201 adjustSize : Roo.BoxComponent.prototype.adjustSize,
32203 // private (for BoxComponent)
32204 getResizeEl : function(){
32208 // private (for BoxComponent)
32209 getPositionEl : function(){
32214 initEvents : function(){
32215 this.originalValue = this.getValue();
32219 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
32222 // markInvalid : Roo.emptyFn,
32224 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
32227 // clearInvalid : Roo.emptyFn,
32229 setValue : function(v){
32230 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
32231 this.editorcore.pushValue();
32236 deferFocus : function(){
32237 this.focus.defer(10, this);
32241 focus : function(){
32242 this.editorcore.focus();
32248 onDestroy : function(){
32254 for (var i =0; i < this.toolbars.length;i++) {
32255 // fixme - ask toolbars for heights?
32256 this.toolbars[i].onDestroy();
32259 this.wrap.dom.innerHTML = '';
32260 this.wrap.remove();
32265 onFirstFocus : function(){
32266 //Roo.log("onFirstFocus");
32267 this.editorcore.onFirstFocus();
32268 for (var i =0; i < this.toolbars.length;i++) {
32269 this.toolbars[i].onFirstFocus();
32275 syncValue : function()
32277 this.editorcore.syncValue();
32280 pushValue : function()
32282 this.editorcore.pushValue();
32286 // hide stuff that is not compatible
32300 * @event specialkey
32304 * @cfg {String} fieldClass @hide
32307 * @cfg {String} focusClass @hide
32310 * @cfg {String} autoCreate @hide
32313 * @cfg {String} inputType @hide
32317 * @cfg {String} invalidText @hide
32320 * @cfg {String} msgFx @hide
32323 * @cfg {String} validateOnBlur @hide
32332 Roo.namespace('Roo.bootstrap.form.HtmlEditor');
32334 * @class Roo.bootstrap.form.HtmlEditorToolbarStandard
32335 * @parent Roo.bootstrap.form.HtmlEditor
32336 * @extends Roo.bootstrap.nav.Simplebar
32342 new Roo.bootstrap.form.HtmlEditor({
32345 new Roo.bootstrap.form.HtmlEditorToolbarStandard({
32346 disable : { fonts: 1 , format: 1, ..., ... , ...],
32352 * @cfg {Object} disable List of elements to disable..
32353 * @cfg {Array} btns List of additional buttons.
32357 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
32360 Roo.bootstrap.form.HtmlEditorToolbarStandard = function(config)
32363 Roo.apply(this, config);
32365 // default disabled, based on 'good practice'..
32366 this.disable = this.disable || {};
32367 Roo.applyIf(this.disable, {
32370 specialElements : true
32372 Roo.bootstrap.form.HtmlEditorToolbarStandard.superclass.constructor.call(this, config);
32374 this.editor = config.editor;
32375 this.editorcore = config.editor.editorcore;
32377 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
32379 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
32380 // dont call parent... till later.
32382 Roo.extend(Roo.bootstrap.form.HtmlEditorToolbarStandard, Roo.bootstrap.nav.Simplebar, {
32387 editorcore : false,
32392 "h1","h2","h3","h4","h5","h6",
32394 "abbr", "acronym", "address", "cite", "samp", "var",
32398 onRender : function(ct, position)
32400 // Roo.log("Call onRender: " + this.xtype);
32402 Roo.bootstrap.form.HtmlEditorToolbarStandard.superclass.onRender.call(this, ct, position);
32404 this.el.dom.style.marginBottom = '0';
32406 var editorcore = this.editorcore;
32407 var editor= this.editor;
32410 var btn = function(id,cmd , toggle, handler, html){
32412 var event = toggle ? 'toggle' : 'click';
32417 xns: Roo.bootstrap,
32421 enableToggle:toggle !== false,
32423 pressed : toggle ? false : null,
32426 a.listeners[toggle ? 'toggle' : 'click'] = function() {
32427 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
32433 // var cb_box = function...
32438 xns: Roo.bootstrap,
32443 xns: Roo.bootstrap,
32447 Roo.each(this.formats, function(f) {
32448 style.menu.items.push({
32450 xns: Roo.bootstrap,
32451 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
32456 editorcore.insertTag(this.tagname);
32463 children.push(style);
32465 btn('bold',false,true);
32466 btn('italic',false,true);
32467 btn('align-left', 'justifyleft',true);
32468 btn('align-center', 'justifycenter',true);
32469 btn('align-right' , 'justifyright',true);
32470 btn('link', false, false, function(btn) {
32471 //Roo.log("create link?");
32472 var url = prompt(this.createLinkText, this.defaultLinkValue);
32473 if(url && url != 'http:/'+'/'){
32474 this.editorcore.relayCmd('createlink', url);
32477 btn('list','insertunorderedlist',true);
32478 btn('pencil', false,true, function(btn){
32480 this.toggleSourceEdit(btn.pressed);
32483 if (this.editor.btns.length > 0) {
32484 for (var i = 0; i<this.editor.btns.length; i++) {
32485 children.push(this.editor.btns[i]);
32493 xns: Roo.bootstrap,
32498 xns: Roo.bootstrap,
32503 cog.menu.items.push({
32505 xns: Roo.bootstrap,
32506 html : Clean styles,
32511 editorcore.insertTag(this.tagname);
32520 this.xtype = 'NavSimplebar';
32522 for(var i=0;i< children.length;i++) {
32524 this.buttons.add(this.addxtypeChild(children[i]));
32528 editor.on('editorevent', this.updateToolbar, this);
32530 onBtnClick : function(id)
32532 this.editorcore.relayCmd(id);
32533 this.editorcore.focus();
32537 * Protected method that will not generally be called directly. It triggers
32538 * a toolbar update by reading the markup state of the current selection in the editor.
32540 updateToolbar: function(){
32542 if(!this.editorcore.activated){
32543 this.editor.onFirstFocus(); // is this neeed?
32547 var btns = this.buttons;
32548 var doc = this.editorcore.doc;
32549 btns.get('bold').setActive(doc.queryCommandState('bold'));
32550 btns.get('italic').setActive(doc.queryCommandState('italic'));
32551 //btns.get('underline').setActive(doc.queryCommandState('underline'));
32553 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
32554 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
32555 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
32557 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
32558 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
32561 var ans = this.editorcore.getAllAncestors();
32562 if (this.formatCombo) {
32565 var store = this.formatCombo.store;
32566 this.formatCombo.setValue("");
32567 for (var i =0; i < ans.length;i++) {
32568 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
32570 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
32578 // hides menus... - so this cant be on a menu...
32579 Roo.bootstrap.MenuMgr.hideAll();
32581 Roo.bootstrap.menu.Manager.hideAll();
32582 //this.editorsyncValue();
32584 onFirstFocus: function() {
32585 this.buttons.each(function(item){
32589 toggleSourceEdit : function(sourceEditMode){
32592 if(sourceEditMode){
32593 Roo.log("disabling buttons");
32594 this.buttons.each( function(item){
32595 if(item.cmd != 'pencil'){
32601 Roo.log("enabling buttons");
32602 if(this.editorcore.initialized){
32603 this.buttons.each( function(item){
32609 Roo.log("calling toggole on editor");
32610 // tell the editor that it's been pressed..
32611 this.editor.toggleSourceEdit(sourceEditMode);
32625 * @class Roo.bootstrap.form.Markdown
32626 * @extends Roo.bootstrap.form.TextArea
32627 * Bootstrap Showdown editable area
32628 * @cfg {string} content
32631 * Create a new Showdown
32634 Roo.bootstrap.form.Markdown = function(config){
32635 Roo.bootstrap.form.Markdown.superclass.constructor.call(this, config);
32639 Roo.extend(Roo.bootstrap.form.Markdown, Roo.bootstrap.form.TextArea, {
32643 initEvents : function()
32646 Roo.bootstrap.form.TextArea.prototype.initEvents.call(this);
32647 this.markdownEl = this.el.createChild({
32648 cls : 'roo-markdown-area'
32650 this.inputEl().addClass('d-none');
32651 if (this.getValue() == '') {
32652 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
32655 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
32657 this.markdownEl.on('click', this.toggleTextEdit, this);
32658 this.on('blur', this.toggleTextEdit, this);
32659 this.on('specialkey', this.resizeTextArea, this);
32662 toggleTextEdit : function()
32664 var sh = this.markdownEl.getHeight();
32665 this.inputEl().addClass('d-none');
32666 this.markdownEl.addClass('d-none');
32667 if (!this.editing) {
32669 this.inputEl().setHeight(Math.min(500, Math.max(sh,(this.getValue().split("\n").length+1) * 30)));
32670 this.inputEl().removeClass('d-none');
32671 this.inputEl().focus();
32672 this.editing = true;
32675 // show showdown...
32676 this.updateMarkdown();
32677 this.markdownEl.removeClass('d-none');
32678 this.editing = false;
32681 updateMarkdown : function()
32683 if (this.getValue() == '') {
32684 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
32688 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
32691 resizeTextArea: function () {
32694 Roo.log([sh, this.getValue().split("\n").length * 30]);
32695 this.inputEl().setHeight(Math.min(500, Math.max(sh, (this.getValue().split("\n").length +1) * 30)));
32697 setValue : function(val)
32699 Roo.bootstrap.form.TextArea.prototype.setValue.call(this,val);
32700 if (!this.editing) {
32701 this.updateMarkdown();
32707 if (!this.editing) {
32708 this.toggleTextEdit();
32716 * Ext JS Library 1.1.1
32717 * Copyright(c) 2006-2007, Ext JS, LLC.
32719 * Originally Released Under LGPL - original licence link has changed is not relivant.
32722 * <script type="text/javascript">
32726 * @class Roo.bootstrap.PagingToolbar
32727 * @extends Roo.bootstrap.nav.Simplebar
32728 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
32730 * Create a new PagingToolbar
32731 * @param {Object} config The config object
32732 * @param {Roo.data.Store} store
32734 Roo.bootstrap.PagingToolbar = function(config)
32736 // old args format still supported... - xtype is prefered..
32737 // created from xtype...
32739 this.ds = config.dataSource;
32741 if (config.store && !this.ds) {
32742 this.store= Roo.factory(config.store, Roo.data);
32743 this.ds = this.store;
32744 this.ds.xmodule = this.xmodule || false;
32747 this.toolbarItems = [];
32748 if (config.items) {
32749 this.toolbarItems = config.items;
32752 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
32757 this.bind(this.ds);
32760 if (Roo.bootstrap.version == 4) {
32761 this.navgroup = new Roo.bootstrap.ButtonGroup({ cls: 'pagination' });
32763 this.navgroup = new Roo.bootstrap.nav.Group({ cls: 'pagination' });
32768 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.nav.Simplebar, {
32770 * @cfg {Roo.bootstrap.Button} buttons[]
32771 * Buttons for the toolbar
32774 * @cfg {Roo.data.Store} store
32775 * The underlying data store providing the paged data
32778 * @cfg {String/HTMLElement/Element} container
32779 * container The id or element that will contain the toolbar
32782 * @cfg {Boolean} displayInfo
32783 * True to display the displayMsg (defaults to false)
32786 * @cfg {Number} pageSize
32787 * The number of records to display per page (defaults to 20)
32791 * @cfg {String} displayMsg
32792 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
32794 displayMsg : 'Displaying {0} - {1} of {2}',
32796 * @cfg {String} emptyMsg
32797 * The message to display when no records are found (defaults to "No data to display")
32799 emptyMsg : 'No data to display',
32801 * Customizable piece of the default paging text (defaults to "Page")
32804 beforePageText : "Page",
32806 * Customizable piece of the default paging text (defaults to "of %0")
32809 afterPageText : "of {0}",
32811 * Customizable piece of the default paging text (defaults to "First Page")
32814 firstText : "First Page",
32816 * Customizable piece of the default paging text (defaults to "Previous Page")
32819 prevText : "Previous Page",
32821 * Customizable piece of the default paging text (defaults to "Next Page")
32824 nextText : "Next Page",
32826 * Customizable piece of the default paging text (defaults to "Last Page")
32829 lastText : "Last Page",
32831 * Customizable piece of the default paging text (defaults to "Refresh")
32834 refreshText : "Refresh",
32838 onRender : function(ct, position)
32840 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
32841 this.navgroup.parentId = this.id;
32842 this.navgroup.onRender(this.el, null);
32843 // add the buttons to the navgroup
32845 if(this.displayInfo){
32846 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
32847 this.displayEl = this.el.select('.x-paging-info', true).first();
32848 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
32849 // this.displayEl = navel.el.select('span',true).first();
32855 Roo.each(_this.buttons, function(e){ // this might need to use render????
32856 Roo.factory(e).render(_this.el);
32860 Roo.each(_this.toolbarItems, function(e) {
32861 _this.navgroup.addItem(e);
32865 this.first = this.navgroup.addItem({
32866 tooltip: this.firstText,
32867 cls: "prev btn-outline-secondary",
32868 html : ' <i class="fa fa-step-backward"></i>',
32870 preventDefault: true,
32871 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
32874 this.prev = this.navgroup.addItem({
32875 tooltip: this.prevText,
32876 cls: "prev btn-outline-secondary",
32877 html : ' <i class="fa fa-backward"></i>',
32879 preventDefault: true,
32880 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
32882 //this.addSeparator();
32885 var field = this.navgroup.addItem( {
32887 cls : 'x-paging-position btn-outline-secondary',
32889 html : this.beforePageText +
32890 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
32891 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
32894 this.field = field.el.select('input', true).first();
32895 this.field.on("keydown", this.onPagingKeydown, this);
32896 this.field.on("focus", function(){this.dom.select();});
32899 this.afterTextEl = field.el.select('.x-paging-after',true).first();
32900 //this.field.setHeight(18);
32901 //this.addSeparator();
32902 this.next = this.navgroup.addItem({
32903 tooltip: this.nextText,
32904 cls: "next btn-outline-secondary",
32905 html : ' <i class="fa fa-forward"></i>',
32907 preventDefault: true,
32908 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
32910 this.last = this.navgroup.addItem({
32911 tooltip: this.lastText,
32912 html : ' <i class="fa fa-step-forward"></i>',
32913 cls: "next btn-outline-secondary",
32915 preventDefault: true,
32916 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
32918 //this.addSeparator();
32919 this.loading = this.navgroup.addItem({
32920 tooltip: this.refreshText,
32921 cls: "btn-outline-secondary",
32922 html : ' <i class="fa fa-refresh"></i>',
32923 preventDefault: true,
32924 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
32930 updateInfo : function(){
32931 if(this.displayEl){
32932 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
32933 var msg = count == 0 ?
32937 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
32939 this.displayEl.update(msg);
32944 onLoad : function(ds, r, o)
32946 this.cursor = o.params && o.params.start ? o.params.start : 0;
32948 var d = this.getPageData(),
32953 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
32954 this.field.dom.value = ap;
32955 this.first.setDisabled(ap == 1);
32956 this.prev.setDisabled(ap == 1);
32957 this.next.setDisabled(ap == ps);
32958 this.last.setDisabled(ap == ps);
32959 this.loading.enable();
32964 getPageData : function(){
32965 var total = this.ds.getTotalCount();
32968 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
32969 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
32974 onLoadError : function(proxy, o){
32975 this.loading.enable();
32976 if (this.ds.events.loadexception.listeners.length < 2) {
32977 // nothing has been assigned to loadexception except this...
32979 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
32985 onPagingKeydown : function(e){
32986 var k = e.getKey();
32987 var d = this.getPageData();
32989 var v = this.field.dom.value, pageNum;
32990 if(!v || isNaN(pageNum = parseInt(v, 10))){
32991 this.field.dom.value = d.activePage;
32994 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
32995 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
32998 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))
33000 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
33001 this.field.dom.value = pageNum;
33002 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
33005 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
33007 var v = this.field.dom.value, pageNum;
33008 var increment = (e.shiftKey) ? 10 : 1;
33009 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
33012 if(!v || isNaN(pageNum = parseInt(v, 10))) {
33013 this.field.dom.value = d.activePage;
33016 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
33018 this.field.dom.value = parseInt(v, 10) + increment;
33019 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
33020 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
33027 beforeLoad : function(){
33029 this.loading.disable();
33034 onClick : function(which){
33043 ds.load({params:{start: 0, limit: this.pageSize}});
33046 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
33049 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
33052 var total = ds.getTotalCount();
33053 var extra = total % this.pageSize;
33054 var lastStart = extra ? (total - extra) : total-this.pageSize;
33055 ds.load({params:{start: lastStart, limit: this.pageSize}});
33058 ds.load({params:{start: this.cursor, limit: this.pageSize}});
33064 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
33065 * @param {Roo.data.Store} store The data store to unbind
33067 unbind : function(ds){
33068 ds.un("beforeload", this.beforeLoad, this);
33069 ds.un("load", this.onLoad, this);
33070 ds.un("loadexception", this.onLoadError, this);
33071 ds.un("remove", this.updateInfo, this);
33072 ds.un("add", this.updateInfo, this);
33073 this.ds = undefined;
33077 * Binds the paging toolbar to the specified {@link Roo.data.Store}
33078 * @param {Roo.data.Store} store The data store to bind
33080 bind : function(ds){
33081 ds.on("beforeload", this.beforeLoad, this);
33082 ds.on("load", this.onLoad, this);
33083 ds.on("loadexception", this.onLoadError, this);
33084 ds.on("remove", this.updateInfo, this);
33085 ds.on("add", this.updateInfo, this);
33096 * @class Roo.bootstrap.MessageBar
33097 * @extends Roo.bootstrap.Component
33098 * Bootstrap MessageBar class
33099 * @cfg {String} html contents of the MessageBar
33100 * @cfg {String} weight (info | success | warning | danger) default info
33101 * @cfg {String} beforeClass insert the bar before the given class
33102 * @cfg {Boolean} closable (true | false) default false
33103 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
33106 * Create a new Element
33107 * @param {Object} config The config object
33110 Roo.bootstrap.MessageBar = function(config){
33111 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
33114 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
33120 beforeClass: 'bootstrap-sticky-wrap',
33122 getAutoCreate : function(){
33126 cls: 'alert alert-dismissable alert-' + this.weight,
33131 html: this.html || ''
33137 cfg.cls += ' alert-messages-fixed';
33151 onRender : function(ct, position)
33153 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
33156 var cfg = Roo.apply({}, this.getAutoCreate());
33160 cfg.cls += ' ' + this.cls;
33163 cfg.style = this.style;
33165 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
33167 this.el.setVisibilityMode(Roo.Element.DISPLAY);
33170 this.el.select('>button.close').on('click', this.hide, this);
33176 if (!this.rendered) {
33182 this.fireEvent('show', this);
33188 if (!this.rendered) {
33194 this.fireEvent('hide', this);
33197 update : function()
33199 // var e = this.el.dom.firstChild;
33201 // if(this.closable){
33202 // e = e.nextSibling;
33205 // e.data = this.html || '';
33207 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
33223 * @class Roo.bootstrap.Graph
33224 * @extends Roo.bootstrap.Component
33225 * Bootstrap Graph class
33229 @cfg {String} graphtype bar | vbar | pie
33230 @cfg {number} g_x coodinator | centre x (pie)
33231 @cfg {number} g_y coodinator | centre y (pie)
33232 @cfg {number} g_r radius (pie)
33233 @cfg {number} g_height height of the chart (respected by all elements in the set)
33234 @cfg {number} g_width width of the chart (respected by all elements in the set)
33235 @cfg {Object} title The title of the chart
33238 -opts (object) options for the chart
33240 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
33241 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
33243 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.
33244 o stacked (boolean) whether or not to tread values as in a stacked bar chart
33246 o stretch (boolean)
33248 -opts (object) options for the pie
33251 o startAngle (number)
33252 o endAngle (number)
33256 * Create a new Input
33257 * @param {Object} config The config object
33260 Roo.bootstrap.Graph = function(config){
33261 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
33267 * The img click event for the img.
33268 * @param {Roo.EventObject} e
33274 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
33285 //g_colors: this.colors,
33292 getAutoCreate : function(){
33303 onRender : function(ct,position){
33306 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
33308 if (typeof(Raphael) == 'undefined') {
33309 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
33313 this.raphael = Raphael(this.el.dom);
33315 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
33316 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
33317 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
33318 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
33320 r.text(160, 10, "Single Series Chart").attr(txtattr);
33321 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
33322 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
33323 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
33325 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
33326 r.barchart(330, 10, 300, 220, data1);
33327 r.barchart(10, 250, 300, 220, data2, {stacked: true});
33328 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
33331 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
33332 // r.barchart(30, 30, 560, 250, xdata, {
33333 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
33334 // axis : "0 0 1 1",
33335 // axisxlabels : xdata
33336 // //yvalues : cols,
33339 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
33341 // this.load(null,xdata,{
33342 // axis : "0 0 1 1",
33343 // axisxlabels : xdata
33348 load : function(graphtype,xdata,opts)
33350 this.raphael.clear();
33352 graphtype = this.graphtype;
33357 var r = this.raphael,
33358 fin = function () {
33359 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
33361 fout = function () {
33362 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
33364 pfin = function() {
33365 this.sector.stop();
33366 this.sector.scale(1.1, 1.1, this.cx, this.cy);
33369 this.label[0].stop();
33370 this.label[0].attr({ r: 7.5 });
33371 this.label[1].attr({ "font-weight": 800 });
33374 pfout = function() {
33375 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
33378 this.label[0].animate({ r: 5 }, 500, "bounce");
33379 this.label[1].attr({ "font-weight": 400 });
33385 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
33388 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
33391 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
33392 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
33394 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
33401 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
33406 setTitle: function(o)
33411 initEvents: function() {
33414 this.el.on('click', this.onClick, this);
33418 onClick : function(e)
33420 Roo.log('img onclick');
33421 this.fireEvent('click', this, e);
33427 Roo.bootstrap.dash = {};/*
33433 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
33436 * @class Roo.bootstrap.dash.NumberBox
33437 * @extends Roo.bootstrap.Component
33438 * Bootstrap NumberBox class
33439 * @cfg {String} headline Box headline
33440 * @cfg {String} content Box content
33441 * @cfg {String} icon Box icon
33442 * @cfg {String} footer Footer text
33443 * @cfg {String} fhref Footer href
33446 * Create a new NumberBox
33447 * @param {Object} config The config object
33451 Roo.bootstrap.dash.NumberBox = function(config){
33452 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
33456 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
33465 getAutoCreate : function(){
33469 cls : 'small-box ',
33477 cls : 'roo-headline',
33478 html : this.headline
33482 cls : 'roo-content',
33483 html : this.content
33497 cls : 'ion ' + this.icon
33506 cls : 'small-box-footer',
33507 href : this.fhref || '#',
33511 cfg.cn.push(footer);
33518 onRender : function(ct,position){
33519 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
33526 setHeadline: function (value)
33528 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
33531 setFooter: function (value, href)
33533 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
33536 this.el.select('a.small-box-footer',true).first().attr('href', href);
33541 setContent: function (value)
33543 this.el.select('.roo-content',true).first().dom.innerHTML = value;
33546 initEvents: function()
33560 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
33563 * @class Roo.bootstrap.dash.TabBox
33564 * @extends Roo.bootstrap.Component
33565 * @children Roo.bootstrap.dash.TabPane
33566 * Bootstrap TabBox class
33567 * @cfg {String} title Title of the TabBox
33568 * @cfg {String} icon Icon of the TabBox
33569 * @cfg {Boolean} showtabs (true|false) show the tabs default true
33570 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
33573 * Create a new TabBox
33574 * @param {Object} config The config object
33578 Roo.bootstrap.dash.TabBox = function(config){
33579 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
33584 * When a pane is added
33585 * @param {Roo.bootstrap.dash.TabPane} pane
33589 * @event activatepane
33590 * When a pane is activated
33591 * @param {Roo.bootstrap.dash.TabPane} pane
33593 "activatepane" : true
33601 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
33606 tabScrollable : false,
33608 getChildContainer : function()
33610 return this.el.select('.tab-content', true).first();
33613 getAutoCreate : function(){
33617 cls: 'pull-left header',
33625 cls: 'fa ' + this.icon
33631 cls: 'nav nav-tabs pull-right',
33637 if(this.tabScrollable){
33644 cls: 'nav nav-tabs pull-right',
33655 cls: 'nav-tabs-custom',
33660 cls: 'tab-content no-padding',
33668 initEvents : function()
33670 //Roo.log('add add pane handler');
33671 this.on('addpane', this.onAddPane, this);
33674 * Updates the box title
33675 * @param {String} html to set the title to.
33677 setTitle : function(value)
33679 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
33681 onAddPane : function(pane)
33683 this.panes.push(pane);
33684 //Roo.log('addpane');
33686 // tabs are rendere left to right..
33687 if(!this.showtabs){
33691 var ctr = this.el.select('.nav-tabs', true).first();
33694 var existing = ctr.select('.nav-tab',true);
33695 var qty = existing.getCount();;
33698 var tab = ctr.createChild({
33700 cls : 'nav-tab' + (qty ? '' : ' active'),
33708 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
33711 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
33713 pane.el.addClass('active');
33718 onTabClick : function(ev,un,ob,pane)
33720 //Roo.log('tab - prev default');
33721 ev.preventDefault();
33724 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
33725 pane.tab.addClass('active');
33726 //Roo.log(pane.title);
33727 this.getChildContainer().select('.tab-pane',true).removeClass('active');
33728 // technically we should have a deactivate event.. but maybe add later.
33729 // and it should not de-activate the selected tab...
33730 this.fireEvent('activatepane', pane);
33731 pane.el.addClass('active');
33732 pane.fireEvent('activate');
33737 getActivePane : function()
33740 Roo.each(this.panes, function(p) {
33741 if(p.el.hasClass('active')){
33762 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
33764 * @class Roo.bootstrap.TabPane
33765 * @extends Roo.bootstrap.Component
33766 * @children Roo.bootstrap.Graph Roo.bootstrap.Column
33767 * Bootstrap TabPane class
33768 * @cfg {Boolean} active (false | true) Default false
33769 * @cfg {String} title title of panel
33773 * Create a new TabPane
33774 * @param {Object} config The config object
33777 Roo.bootstrap.dash.TabPane = function(config){
33778 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
33784 * When a pane is activated
33785 * @param {Roo.bootstrap.dash.TabPane} pane
33792 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
33797 // the tabBox that this is attached to.
33800 getAutoCreate : function()
33808 cfg.cls += ' active';
33813 initEvents : function()
33815 //Roo.log('trigger add pane handler');
33816 this.parent().fireEvent('addpane', this)
33820 * Updates the tab title
33821 * @param {String} html to set the title to.
33823 setTitle: function(str)
33829 this.tab.select('a', true).first().dom.innerHTML = str;
33848 * @class Roo.bootstrap.Tooltip
33849 * Bootstrap Tooltip class
33850 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
33851 * to determine which dom element triggers the tooltip.
33853 * It needs to add support for additional attributes like tooltip-position
33856 * Create a new Toolti
33857 * @param {Object} config The config object
33860 Roo.bootstrap.Tooltip = function(config){
33861 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
33863 this.alignment = Roo.bootstrap.Tooltip.alignment;
33865 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
33866 this.alignment = config.alignment;
33871 Roo.apply(Roo.bootstrap.Tooltip, {
33873 * @function init initialize tooltip monitoring.
33877 currentTip : false,
33878 currentRegion : false,
33884 Roo.get(document).on('mouseover', this.enter ,this);
33885 Roo.get(document).on('mouseout', this.leave, this);
33888 this.currentTip = new Roo.bootstrap.Tooltip();
33891 enter : function(ev)
33893 var dom = ev.getTarget();
33895 //Roo.log(['enter',dom]);
33896 var el = Roo.fly(dom);
33897 if (this.currentEl) {
33899 //Roo.log(this.currentEl);
33900 //Roo.log(this.currentEl.contains(dom));
33901 if (this.currentEl == el) {
33904 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
33910 if (this.currentTip.el) {
33911 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
33915 if(!el || el.dom == document){
33921 if (!el.attr('tooltip')) {
33922 pel = el.findParent("[tooltip]");
33924 bindEl = Roo.get(pel);
33930 // you can not look for children, as if el is the body.. then everythign is the child..
33931 if (!pel && !el.attr('tooltip')) { //
33932 if (!el.select("[tooltip]").elements.length) {
33935 // is the mouse over this child...?
33936 bindEl = el.select("[tooltip]").first();
33937 var xy = ev.getXY();
33938 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
33939 //Roo.log("not in region.");
33942 //Roo.log("child element over..");
33945 this.currentEl = el;
33946 this.currentTip.bind(bindEl);
33947 this.currentRegion = Roo.lib.Region.getRegion(dom);
33948 this.currentTip.enter();
33951 leave : function(ev)
33953 var dom = ev.getTarget();
33954 //Roo.log(['leave',dom]);
33955 if (!this.currentEl) {
33960 if (dom != this.currentEl.dom) {
33963 var xy = ev.getXY();
33964 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
33967 // only activate leave if mouse cursor is outside... bounding box..
33972 if (this.currentTip) {
33973 this.currentTip.leave();
33975 //Roo.log('clear currentEl');
33976 this.currentEl = false;
33981 'left' : ['r-l', [-2,0], 'right'],
33982 'right' : ['l-r', [2,0], 'left'],
33983 'bottom' : ['t-b', [0,2], 'top'],
33984 'top' : [ 'b-t', [0,-2], 'bottom']
33990 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
33995 delay : null, // can be { show : 300 , hide: 500}
33999 hoverState : null, //???
34001 placement : 'bottom',
34005 getAutoCreate : function(){
34012 cls : 'tooltip-arrow arrow'
34015 cls : 'tooltip-inner'
34022 bind : function(el)
34027 initEvents : function()
34029 this.arrowEl = this.el.select('.arrow', true).first();
34030 this.innerEl = this.el.select('.tooltip-inner', true).first();
34033 enter : function () {
34035 if (this.timeout != null) {
34036 clearTimeout(this.timeout);
34039 this.hoverState = 'in';
34040 //Roo.log("enter - show");
34041 if (!this.delay || !this.delay.show) {
34046 this.timeout = setTimeout(function () {
34047 if (_t.hoverState == 'in') {
34050 }, this.delay.show);
34054 clearTimeout(this.timeout);
34056 this.hoverState = 'out';
34057 if (!this.delay || !this.delay.hide) {
34063 this.timeout = setTimeout(function () {
34064 //Roo.log("leave - timeout");
34066 if (_t.hoverState == 'out') {
34068 Roo.bootstrap.Tooltip.currentEl = false;
34073 show : function (msg)
34076 this.render(document.body);
34079 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
34081 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
34083 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
34085 this.el.removeClass(['fade','top','bottom', 'left', 'right','in',
34086 'bs-tooltip-top','bs-tooltip-bottom', 'bs-tooltip-left', 'bs-tooltip-right']);
34088 if(this.bindEl.attr('tooltip-class')) {
34089 this.el.addClass(this.bindEl.attr('tooltip-class'));
34092 var placement = typeof this.placement == 'function' ?
34093 this.placement.call(this, this.el, on_el) :
34096 if(this.bindEl.attr('tooltip-placement')) {
34097 placement = this.bindEl.attr('tooltip-placement');
34100 var autoToken = /\s?auto?\s?/i;
34101 var autoPlace = autoToken.test(placement);
34103 placement = placement.replace(autoToken, '') || 'top';
34107 //this.el.setXY([0,0]);
34109 //this.el.dom.style.display='block';
34111 //this.el.appendTo(on_el);
34113 var p = this.getPosition();
34114 var box = this.el.getBox();
34120 var align = this.alignment[placement];
34122 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
34124 if(placement == 'top' || placement == 'bottom'){
34126 placement = 'right';
34129 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
34130 placement = 'left';
34133 var scroll = Roo.select('body', true).first().getScroll();
34135 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
34139 align = this.alignment[placement];
34141 this.arrowEl.setLeft((this.innerEl.getWidth()/2) - 5);
34145 var elems = document.getElementsByTagName('div');
34146 var highest = Number.MIN_SAFE_INTEGER || -(Math.pow(2, 53) - 1);
34147 for (var i = 0; i < elems.length; i++) {
34148 var zindex = Number.parseInt(
34149 document.defaultView.getComputedStyle(elems[i], null).getPropertyValue("z-index"),
34152 if (zindex > highest) {
34159 this.el.dom.style.zIndex = highest;
34161 this.el.alignTo(this.bindEl, align[0],align[1]);
34162 //var arrow = this.el.select('.arrow',true).first();
34163 //arrow.set(align[2],
34165 this.el.addClass(placement);
34166 this.el.addClass("bs-tooltip-"+ placement);
34168 this.el.addClass('in fade show');
34170 this.hoverState = null;
34172 if (this.el.hasClass('fade')) {
34187 //this.el.setXY([0,0]);
34188 if(this.bindEl.attr('tooltip-class')) {
34189 this.el.removeClass(this.bindEl.attr('tooltip-class'));
34191 this.el.removeClass(['show', 'in']);
34207 * @class Roo.bootstrap.LocationPicker
34208 * @extends Roo.bootstrap.Component
34209 * Bootstrap LocationPicker class
34210 * @cfg {Number} latitude Position when init default 0
34211 * @cfg {Number} longitude Position when init default 0
34212 * @cfg {Number} zoom default 15
34213 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
34214 * @cfg {Boolean} mapTypeControl default false
34215 * @cfg {Boolean} disableDoubleClickZoom default false
34216 * @cfg {Boolean} scrollwheel default true
34217 * @cfg {Boolean} streetViewControl default false
34218 * @cfg {Number} radius default 0
34219 * @cfg {String} locationName
34220 * @cfg {Boolean} draggable default true
34221 * @cfg {Boolean} enableAutocomplete default false
34222 * @cfg {Boolean} enableReverseGeocode default true
34223 * @cfg {String} markerTitle
34226 * Create a new LocationPicker
34227 * @param {Object} config The config object
34231 Roo.bootstrap.LocationPicker = function(config){
34233 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
34238 * Fires when the picker initialized.
34239 * @param {Roo.bootstrap.LocationPicker} this
34240 * @param {Google Location} location
34244 * @event positionchanged
34245 * Fires when the picker position changed.
34246 * @param {Roo.bootstrap.LocationPicker} this
34247 * @param {Google Location} location
34249 positionchanged : true,
34252 * Fires when the map resize.
34253 * @param {Roo.bootstrap.LocationPicker} this
34258 * Fires when the map show.
34259 * @param {Roo.bootstrap.LocationPicker} this
34264 * Fires when the map hide.
34265 * @param {Roo.bootstrap.LocationPicker} this
34270 * Fires when click the map.
34271 * @param {Roo.bootstrap.LocationPicker} this
34272 * @param {Map event} e
34276 * @event mapRightClick
34277 * Fires when right click the map.
34278 * @param {Roo.bootstrap.LocationPicker} this
34279 * @param {Map event} e
34281 mapRightClick : true,
34283 * @event markerClick
34284 * Fires when click the marker.
34285 * @param {Roo.bootstrap.LocationPicker} this
34286 * @param {Map event} e
34288 markerClick : true,
34290 * @event markerRightClick
34291 * Fires when right click the marker.
34292 * @param {Roo.bootstrap.LocationPicker} this
34293 * @param {Map event} e
34295 markerRightClick : true,
34297 * @event OverlayViewDraw
34298 * Fires when OverlayView Draw
34299 * @param {Roo.bootstrap.LocationPicker} this
34301 OverlayViewDraw : true,
34303 * @event OverlayViewOnAdd
34304 * Fires when OverlayView Draw
34305 * @param {Roo.bootstrap.LocationPicker} this
34307 OverlayViewOnAdd : true,
34309 * @event OverlayViewOnRemove
34310 * Fires when OverlayView Draw
34311 * @param {Roo.bootstrap.LocationPicker} this
34313 OverlayViewOnRemove : true,
34315 * @event OverlayViewShow
34316 * Fires when OverlayView Draw
34317 * @param {Roo.bootstrap.LocationPicker} this
34318 * @param {Pixel} cpx
34320 OverlayViewShow : true,
34322 * @event OverlayViewHide
34323 * Fires when OverlayView Draw
34324 * @param {Roo.bootstrap.LocationPicker} this
34326 OverlayViewHide : true,
34328 * @event loadexception
34329 * Fires when load google lib failed.
34330 * @param {Roo.bootstrap.LocationPicker} this
34332 loadexception : true
34337 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
34339 gMapContext: false,
34345 mapTypeControl: false,
34346 disableDoubleClickZoom: false,
34348 streetViewControl: false,
34352 enableAutocomplete: false,
34353 enableReverseGeocode: true,
34356 getAutoCreate: function()
34361 cls: 'roo-location-picker'
34367 initEvents: function(ct, position)
34369 if(!this.el.getWidth() || this.isApplied()){
34373 this.el.setVisibilityMode(Roo.Element.DISPLAY);
34378 initial: function()
34380 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
34381 this.fireEvent('loadexception', this);
34385 if(!this.mapTypeId){
34386 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
34389 this.gMapContext = this.GMapContext();
34391 this.initOverlayView();
34393 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
34397 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
34398 _this.setPosition(_this.gMapContext.marker.position);
34401 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
34402 _this.fireEvent('mapClick', this, event);
34406 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
34407 _this.fireEvent('mapRightClick', this, event);
34411 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
34412 _this.fireEvent('markerClick', this, event);
34416 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
34417 _this.fireEvent('markerRightClick', this, event);
34421 this.setPosition(this.gMapContext.location);
34423 this.fireEvent('initial', this, this.gMapContext.location);
34426 initOverlayView: function()
34430 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
34434 _this.fireEvent('OverlayViewDraw', _this);
34439 _this.fireEvent('OverlayViewOnAdd', _this);
34442 onRemove: function()
34444 _this.fireEvent('OverlayViewOnRemove', _this);
34447 show: function(cpx)
34449 _this.fireEvent('OverlayViewShow', _this, cpx);
34454 _this.fireEvent('OverlayViewHide', _this);
34460 fromLatLngToContainerPixel: function(event)
34462 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
34465 isApplied: function()
34467 return this.getGmapContext() == false ? false : true;
34470 getGmapContext: function()
34472 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
34475 GMapContext: function()
34477 var position = new google.maps.LatLng(this.latitude, this.longitude);
34479 var _map = new google.maps.Map(this.el.dom, {
34482 mapTypeId: this.mapTypeId,
34483 mapTypeControl: this.mapTypeControl,
34484 disableDoubleClickZoom: this.disableDoubleClickZoom,
34485 scrollwheel: this.scrollwheel,
34486 streetViewControl: this.streetViewControl,
34487 locationName: this.locationName,
34488 draggable: this.draggable,
34489 enableAutocomplete: this.enableAutocomplete,
34490 enableReverseGeocode: this.enableReverseGeocode
34493 var _marker = new google.maps.Marker({
34494 position: position,
34496 title: this.markerTitle,
34497 draggable: this.draggable
34504 location: position,
34505 radius: this.radius,
34506 locationName: this.locationName,
34507 addressComponents: {
34508 formatted_address: null,
34509 addressLine1: null,
34510 addressLine2: null,
34512 streetNumber: null,
34516 stateOrProvince: null
34519 domContainer: this.el.dom,
34520 geodecoder: new google.maps.Geocoder()
34524 drawCircle: function(center, radius, options)
34526 if (this.gMapContext.circle != null) {
34527 this.gMapContext.circle.setMap(null);
34531 options = Roo.apply({}, options, {
34532 strokeColor: "#0000FF",
34533 strokeOpacity: .35,
34535 fillColor: "#0000FF",
34539 options.map = this.gMapContext.map;
34540 options.radius = radius;
34541 options.center = center;
34542 this.gMapContext.circle = new google.maps.Circle(options);
34543 return this.gMapContext.circle;
34549 setPosition: function(location)
34551 this.gMapContext.location = location;
34552 this.gMapContext.marker.setPosition(location);
34553 this.gMapContext.map.panTo(location);
34554 this.drawCircle(location, this.gMapContext.radius, {});
34558 if (this.gMapContext.settings.enableReverseGeocode) {
34559 this.gMapContext.geodecoder.geocode({
34560 latLng: this.gMapContext.location
34561 }, function(results, status) {
34563 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
34564 _this.gMapContext.locationName = results[0].formatted_address;
34565 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
34567 _this.fireEvent('positionchanged', this, location);
34574 this.fireEvent('positionchanged', this, location);
34579 google.maps.event.trigger(this.gMapContext.map, "resize");
34581 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
34583 this.fireEvent('resize', this);
34586 setPositionByLatLng: function(latitude, longitude)
34588 this.setPosition(new google.maps.LatLng(latitude, longitude));
34591 getCurrentPosition: function()
34594 latitude: this.gMapContext.location.lat(),
34595 longitude: this.gMapContext.location.lng()
34599 getAddressName: function()
34601 return this.gMapContext.locationName;
34604 getAddressComponents: function()
34606 return this.gMapContext.addressComponents;
34609 address_component_from_google_geocode: function(address_components)
34613 for (var i = 0; i < address_components.length; i++) {
34614 var component = address_components[i];
34615 if (component.types.indexOf("postal_code") >= 0) {
34616 result.postalCode = component.short_name;
34617 } else if (component.types.indexOf("street_number") >= 0) {
34618 result.streetNumber = component.short_name;
34619 } else if (component.types.indexOf("route") >= 0) {
34620 result.streetName = component.short_name;
34621 } else if (component.types.indexOf("neighborhood") >= 0) {
34622 result.city = component.short_name;
34623 } else if (component.types.indexOf("locality") >= 0) {
34624 result.city = component.short_name;
34625 } else if (component.types.indexOf("sublocality") >= 0) {
34626 result.district = component.short_name;
34627 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
34628 result.stateOrProvince = component.short_name;
34629 } else if (component.types.indexOf("country") >= 0) {
34630 result.country = component.short_name;
34634 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
34635 result.addressLine2 = "";
34639 setZoomLevel: function(zoom)
34641 this.gMapContext.map.setZoom(zoom);
34654 this.fireEvent('show', this);
34665 this.fireEvent('hide', this);
34670 Roo.apply(Roo.bootstrap.LocationPicker, {
34672 OverlayView : function(map, options)
34674 options = options || {};
34681 * @class Roo.bootstrap.Alert
34682 * @extends Roo.bootstrap.Component
34683 * Bootstrap Alert class - shows an alert area box
34685 * <div class="alert alert-danger" role="alert"><span class="fa fa-exclamation-triangle"></span><span class="sr-only">Error:</span>
34686 Enter a valid email address
34689 * @cfg {String} title The title of alert
34690 * @cfg {String} html The content of alert
34691 * @cfg {String} weight (success|info|warning|danger) Weight of the message
34692 * @cfg {String} fa font-awesomeicon
34693 * @cfg {Number} seconds default:-1 Number of seconds until it disapears (-1 means never.)
34694 * @cfg {Boolean} close true to show a x closer
34698 * Create a new alert
34699 * @param {Object} config The config object
34703 Roo.bootstrap.Alert = function(config){
34704 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
34708 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
34714 faicon: false, // BC
34718 getAutoCreate : function()
34730 style : this.close ? '' : 'display:none'
34734 cls : 'roo-alert-icon'
34739 cls : 'roo-alert-title',
34744 cls : 'roo-alert-text',
34751 cfg.cn[0].cls += ' fa ' + this.faicon;
34754 cfg.cn[0].cls += ' fa ' + this.fa;
34758 cfg.cls += ' alert-' + this.weight;
34764 initEvents: function()
34766 this.el.setVisibilityMode(Roo.Element.DISPLAY);
34767 this.titleEl = this.el.select('.roo-alert-title',true).first();
34768 this.iconEl = this.el.select('.roo-alert-icon',true).first();
34769 this.htmlEl = this.el.select('.roo-alert-text',true).first();
34770 if (this.seconds > 0) {
34771 this.hide.defer(this.seconds, this);
34775 * Set the Title Message HTML
34776 * @param {String} html
34778 setTitle : function(str)
34780 this.titleEl.dom.innerHTML = str;
34784 * Set the Body Message HTML
34785 * @param {String} html
34787 setHtml : function(str)
34789 this.htmlEl.dom.innerHTML = str;
34792 * Set the Weight of the alert
34793 * @param {String} (success|info|warning|danger) weight
34796 setWeight : function(weight)
34799 this.el.removeClass('alert-' + this.weight);
34802 this.weight = weight;
34804 this.el.addClass('alert-' + this.weight);
34807 * Set the Icon of the alert
34808 * @param {String} see fontawsome names (name without the 'fa-' bit)
34810 setIcon : function(icon)
34813 this.alertEl.removeClass(['fa', 'fa-' + this.faicon]);
34816 this.faicon = icon;
34818 this.alertEl.addClass(['fa', 'fa-' + this.faicon]);
34843 * @class Roo.bootstrap.UploadCropbox
34844 * @extends Roo.bootstrap.Component
34845 * Bootstrap UploadCropbox class
34846 * @cfg {String} emptyText show when image has been loaded
34847 * @cfg {String} rotateNotify show when image too small to rotate
34848 * @cfg {Number} errorTimeout default 3000
34849 * @cfg {Number} minWidth default 300
34850 * @cfg {Number} minHeight default 300
34851 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
34852 * @cfg {Boolean} isDocument (true|false) default false
34853 * @cfg {String} url action url
34854 * @cfg {String} paramName default 'imageUpload'
34855 * @cfg {String} method default POST
34856 * @cfg {Boolean} loadMask (true|false) default true
34857 * @cfg {Boolean} loadingText default 'Loading...'
34860 * Create a new UploadCropbox
34861 * @param {Object} config The config object
34864 Roo.bootstrap.UploadCropbox = function(config){
34865 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
34869 * @event beforeselectfile
34870 * Fire before select file
34871 * @param {Roo.bootstrap.UploadCropbox} this
34873 "beforeselectfile" : true,
34876 * Fire after initEvent
34877 * @param {Roo.bootstrap.UploadCropbox} this
34882 * Fire after initEvent
34883 * @param {Roo.bootstrap.UploadCropbox} this
34884 * @param {String} data
34889 * Fire when preparing the file data
34890 * @param {Roo.bootstrap.UploadCropbox} this
34891 * @param {Object} file
34896 * Fire when get exception
34897 * @param {Roo.bootstrap.UploadCropbox} this
34898 * @param {XMLHttpRequest} xhr
34900 "exception" : true,
34902 * @event beforeloadcanvas
34903 * Fire before load the canvas
34904 * @param {Roo.bootstrap.UploadCropbox} this
34905 * @param {String} src
34907 "beforeloadcanvas" : true,
34910 * Fire when trash image
34911 * @param {Roo.bootstrap.UploadCropbox} this
34916 * Fire when download the image
34917 * @param {Roo.bootstrap.UploadCropbox} this
34921 * @event footerbuttonclick
34922 * Fire when footerbuttonclick
34923 * @param {Roo.bootstrap.UploadCropbox} this
34924 * @param {String} type
34926 "footerbuttonclick" : true,
34930 * @param {Roo.bootstrap.UploadCropbox} this
34935 * Fire when rotate the image
34936 * @param {Roo.bootstrap.UploadCropbox} this
34937 * @param {String} pos
34942 * Fire when inspect the file
34943 * @param {Roo.bootstrap.UploadCropbox} this
34944 * @param {Object} file
34949 * Fire when xhr upload the file
34950 * @param {Roo.bootstrap.UploadCropbox} this
34951 * @param {Object} data
34956 * Fire when arrange the file data
34957 * @param {Roo.bootstrap.UploadCropbox} this
34958 * @param {Object} formData
34963 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
34966 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
34968 emptyText : 'Click to upload image',
34969 rotateNotify : 'Image is too small to rotate',
34970 errorTimeout : 3000,
34984 cropType : 'image/jpeg',
34986 canvasLoaded : false,
34987 isDocument : false,
34989 paramName : 'imageUpload',
34991 loadingText : 'Loading...',
34994 getAutoCreate : function()
34998 cls : 'roo-upload-cropbox',
35002 cls : 'roo-upload-cropbox-selector',
35007 cls : 'roo-upload-cropbox-body',
35008 style : 'cursor:pointer',
35012 cls : 'roo-upload-cropbox-preview'
35016 cls : 'roo-upload-cropbox-thumb'
35020 cls : 'roo-upload-cropbox-empty-notify',
35021 html : this.emptyText
35025 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
35026 html : this.rotateNotify
35032 cls : 'roo-upload-cropbox-footer',
35035 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
35045 onRender : function(ct, position)
35047 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
35049 if (this.buttons.length) {
35051 Roo.each(this.buttons, function(bb) {
35053 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
35055 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
35061 this.maskEl = this.el;
35065 initEvents : function()
35067 this.urlAPI = (window.createObjectURL && window) ||
35068 (window.URL && URL.revokeObjectURL && URL) ||
35069 (window.webkitURL && webkitURL);
35071 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
35072 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35074 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
35075 this.selectorEl.hide();
35077 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
35078 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35080 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
35081 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35082 this.thumbEl.hide();
35084 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
35085 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35087 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
35088 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35089 this.errorEl.hide();
35091 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
35092 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35093 this.footerEl.hide();
35095 this.setThumbBoxSize();
35101 this.fireEvent('initial', this);
35108 window.addEventListener("resize", function() { _this.resize(); } );
35110 this.bodyEl.on('click', this.beforeSelectFile, this);
35113 this.bodyEl.on('touchstart', this.onTouchStart, this);
35114 this.bodyEl.on('touchmove', this.onTouchMove, this);
35115 this.bodyEl.on('touchend', this.onTouchEnd, this);
35119 this.bodyEl.on('mousedown', this.onMouseDown, this);
35120 this.bodyEl.on('mousemove', this.onMouseMove, this);
35121 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
35122 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
35123 Roo.get(document).on('mouseup', this.onMouseUp, this);
35126 this.selectorEl.on('change', this.onFileSelected, this);
35132 this.baseScale = 1;
35134 this.baseRotate = 1;
35135 this.dragable = false;
35136 this.pinching = false;
35139 this.cropData = false;
35140 this.notifyEl.dom.innerHTML = this.emptyText;
35142 this.selectorEl.dom.value = '';
35146 resize : function()
35148 if(this.fireEvent('resize', this) != false){
35149 this.setThumbBoxPosition();
35150 this.setCanvasPosition();
35154 onFooterButtonClick : function(e, el, o, type)
35157 case 'rotate-left' :
35158 this.onRotateLeft(e);
35160 case 'rotate-right' :
35161 this.onRotateRight(e);
35164 this.beforeSelectFile(e);
35179 this.fireEvent('footerbuttonclick', this, type);
35182 beforeSelectFile : function(e)
35184 e.preventDefault();
35186 if(this.fireEvent('beforeselectfile', this) != false){
35187 this.selectorEl.dom.click();
35191 onFileSelected : function(e)
35193 e.preventDefault();
35195 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
35199 var file = this.selectorEl.dom.files[0];
35201 if(this.fireEvent('inspect', this, file) != false){
35202 this.prepare(file);
35207 trash : function(e)
35209 this.fireEvent('trash', this);
35212 download : function(e)
35214 this.fireEvent('download', this);
35217 loadCanvas : function(src)
35219 if(this.fireEvent('beforeloadcanvas', this, src) != false){
35223 this.imageEl = document.createElement('img');
35227 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
35229 this.imageEl.src = src;
35233 onLoadCanvas : function()
35235 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
35236 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
35238 this.bodyEl.un('click', this.beforeSelectFile, this);
35240 this.notifyEl.hide();
35241 this.thumbEl.show();
35242 this.footerEl.show();
35244 this.baseRotateLevel();
35246 if(this.isDocument){
35247 this.setThumbBoxSize();
35250 this.setThumbBoxPosition();
35252 this.baseScaleLevel();
35258 this.canvasLoaded = true;
35261 this.maskEl.unmask();
35266 setCanvasPosition : function()
35268 if(!this.canvasEl){
35272 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
35273 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
35275 this.previewEl.setLeft(pw);
35276 this.previewEl.setTop(ph);
35280 onMouseDown : function(e)
35284 this.dragable = true;
35285 this.pinching = false;
35287 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
35288 this.dragable = false;
35292 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
35293 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
35297 onMouseMove : function(e)
35301 if(!this.canvasLoaded){
35305 if (!this.dragable){
35309 var minX = Math.ceil(this.thumbEl.getLeft(true));
35310 var minY = Math.ceil(this.thumbEl.getTop(true));
35312 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
35313 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
35315 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
35316 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
35318 x = x - this.mouseX;
35319 y = y - this.mouseY;
35321 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
35322 var bgY = Math.ceil(y + this.previewEl.getTop(true));
35324 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
35325 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
35327 this.previewEl.setLeft(bgX);
35328 this.previewEl.setTop(bgY);
35330 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
35331 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
35334 onMouseUp : function(e)
35338 this.dragable = false;
35341 onMouseWheel : function(e)
35345 this.startScale = this.scale;
35347 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
35349 if(!this.zoomable()){
35350 this.scale = this.startScale;
35359 zoomable : function()
35361 var minScale = this.thumbEl.getWidth() / this.minWidth;
35363 if(this.minWidth < this.minHeight){
35364 minScale = this.thumbEl.getHeight() / this.minHeight;
35367 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
35368 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
35372 (this.rotate == 0 || this.rotate == 180) &&
35374 width > this.imageEl.OriginWidth ||
35375 height > this.imageEl.OriginHeight ||
35376 (width < this.minWidth && height < this.minHeight)
35384 (this.rotate == 90 || this.rotate == 270) &&
35386 width > this.imageEl.OriginWidth ||
35387 height > this.imageEl.OriginHeight ||
35388 (width < this.minHeight && height < this.minWidth)
35395 !this.isDocument &&
35396 (this.rotate == 0 || this.rotate == 180) &&
35398 width < this.minWidth ||
35399 width > this.imageEl.OriginWidth ||
35400 height < this.minHeight ||
35401 height > this.imageEl.OriginHeight
35408 !this.isDocument &&
35409 (this.rotate == 90 || this.rotate == 270) &&
35411 width < this.minHeight ||
35412 width > this.imageEl.OriginWidth ||
35413 height < this.minWidth ||
35414 height > this.imageEl.OriginHeight
35424 onRotateLeft : function(e)
35426 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
35428 var minScale = this.thumbEl.getWidth() / this.minWidth;
35430 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
35431 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
35433 this.startScale = this.scale;
35435 while (this.getScaleLevel() < minScale){
35437 this.scale = this.scale + 1;
35439 if(!this.zoomable()){
35444 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
35445 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
35450 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
35457 this.scale = this.startScale;
35459 this.onRotateFail();
35464 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
35466 if(this.isDocument){
35467 this.setThumbBoxSize();
35468 this.setThumbBoxPosition();
35469 this.setCanvasPosition();
35474 this.fireEvent('rotate', this, 'left');
35478 onRotateRight : function(e)
35480 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
35482 var minScale = this.thumbEl.getWidth() / this.minWidth;
35484 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
35485 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
35487 this.startScale = this.scale;
35489 while (this.getScaleLevel() < minScale){
35491 this.scale = this.scale + 1;
35493 if(!this.zoomable()){
35498 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
35499 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
35504 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
35511 this.scale = this.startScale;
35513 this.onRotateFail();
35518 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
35520 if(this.isDocument){
35521 this.setThumbBoxSize();
35522 this.setThumbBoxPosition();
35523 this.setCanvasPosition();
35528 this.fireEvent('rotate', this, 'right');
35531 onRotateFail : function()
35533 this.errorEl.show(true);
35537 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
35542 this.previewEl.dom.innerHTML = '';
35544 var canvasEl = document.createElement("canvas");
35546 var contextEl = canvasEl.getContext("2d");
35548 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
35549 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
35550 var center = this.imageEl.OriginWidth / 2;
35552 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
35553 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
35554 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
35555 center = this.imageEl.OriginHeight / 2;
35558 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
35560 contextEl.translate(center, center);
35561 contextEl.rotate(this.rotate * Math.PI / 180);
35563 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
35565 this.canvasEl = document.createElement("canvas");
35567 this.contextEl = this.canvasEl.getContext("2d");
35569 switch (this.rotate) {
35572 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
35573 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
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.OriginHeight * this.getScaleLevel();
35581 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
35583 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35584 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);
35588 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35593 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
35594 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
35596 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35597 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);
35601 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);
35606 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
35607 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
35609 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35610 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
35614 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);
35621 this.previewEl.appendChild(this.canvasEl);
35623 this.setCanvasPosition();
35628 if(!this.canvasLoaded){
35632 var imageCanvas = document.createElement("canvas");
35634 var imageContext = imageCanvas.getContext("2d");
35636 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
35637 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
35639 var center = imageCanvas.width / 2;
35641 imageContext.translate(center, center);
35643 imageContext.rotate(this.rotate * Math.PI / 180);
35645 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
35647 var canvas = document.createElement("canvas");
35649 var context = canvas.getContext("2d");
35651 canvas.width = this.minWidth;
35652 canvas.height = this.minHeight;
35654 switch (this.rotate) {
35657 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
35658 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
35660 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35661 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35663 var targetWidth = this.minWidth - 2 * x;
35664 var targetHeight = this.minHeight - 2 * y;
35668 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35669 scale = targetWidth / width;
35672 if(x > 0 && y == 0){
35673 scale = targetHeight / height;
35676 if(x > 0 && y > 0){
35677 scale = targetWidth / width;
35679 if(width < height){
35680 scale = targetHeight / height;
35684 context.scale(scale, scale);
35686 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35687 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35689 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35690 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35692 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35697 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
35698 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
35700 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35701 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35703 var targetWidth = this.minWidth - 2 * x;
35704 var targetHeight = this.minHeight - 2 * y;
35708 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35709 scale = targetWidth / width;
35712 if(x > 0 && y == 0){
35713 scale = targetHeight / height;
35716 if(x > 0 && y > 0){
35717 scale = targetWidth / width;
35719 if(width < height){
35720 scale = targetHeight / height;
35724 context.scale(scale, scale);
35726 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35727 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35729 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35730 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35732 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
35734 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35739 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
35740 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
35742 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35743 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35745 var targetWidth = this.minWidth - 2 * x;
35746 var targetHeight = this.minHeight - 2 * y;
35750 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35751 scale = targetWidth / width;
35754 if(x > 0 && y == 0){
35755 scale = targetHeight / height;
35758 if(x > 0 && y > 0){
35759 scale = targetWidth / width;
35761 if(width < height){
35762 scale = targetHeight / height;
35766 context.scale(scale, scale);
35768 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35769 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35771 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35772 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35774 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
35775 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
35777 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35782 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
35783 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
35785 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
35786 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
35788 var targetWidth = this.minWidth - 2 * x;
35789 var targetHeight = this.minHeight - 2 * y;
35793 if((x == 0 && y == 0) || (x == 0 && y > 0)){
35794 scale = targetWidth / width;
35797 if(x > 0 && y == 0){
35798 scale = targetHeight / height;
35801 if(x > 0 && y > 0){
35802 scale = targetWidth / width;
35804 if(width < height){
35805 scale = targetHeight / height;
35809 context.scale(scale, scale);
35811 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
35812 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
35814 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
35815 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
35817 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
35819 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
35826 this.cropData = canvas.toDataURL(this.cropType);
35828 if(this.fireEvent('crop', this, this.cropData) !== false){
35829 this.process(this.file, this.cropData);
35836 setThumbBoxSize : function()
35840 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
35841 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
35842 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
35844 this.minWidth = width;
35845 this.minHeight = height;
35847 if(this.rotate == 90 || this.rotate == 270){
35848 this.minWidth = height;
35849 this.minHeight = width;
35854 width = Math.ceil(this.minWidth * height / this.minHeight);
35856 if(this.minWidth > this.minHeight){
35858 height = Math.ceil(this.minHeight * width / this.minWidth);
35861 this.thumbEl.setStyle({
35862 width : width + 'px',
35863 height : height + 'px'
35870 setThumbBoxPosition : function()
35872 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
35873 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
35875 this.thumbEl.setLeft(x);
35876 this.thumbEl.setTop(y);
35880 baseRotateLevel : function()
35882 this.baseRotate = 1;
35885 typeof(this.exif) != 'undefined' &&
35886 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
35887 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
35889 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
35892 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
35896 baseScaleLevel : function()
35900 if(this.isDocument){
35902 if(this.baseRotate == 6 || this.baseRotate == 8){
35904 height = this.thumbEl.getHeight();
35905 this.baseScale = height / this.imageEl.OriginWidth;
35907 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
35908 width = this.thumbEl.getWidth();
35909 this.baseScale = width / this.imageEl.OriginHeight;
35915 height = this.thumbEl.getHeight();
35916 this.baseScale = height / this.imageEl.OriginHeight;
35918 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
35919 width = this.thumbEl.getWidth();
35920 this.baseScale = width / this.imageEl.OriginWidth;
35926 if(this.baseRotate == 6 || this.baseRotate == 8){
35928 width = this.thumbEl.getHeight();
35929 this.baseScale = width / this.imageEl.OriginHeight;
35931 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
35932 height = this.thumbEl.getWidth();
35933 this.baseScale = height / this.imageEl.OriginHeight;
35936 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35937 height = this.thumbEl.getWidth();
35938 this.baseScale = height / this.imageEl.OriginHeight;
35940 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
35941 width = this.thumbEl.getHeight();
35942 this.baseScale = width / this.imageEl.OriginWidth;
35949 width = this.thumbEl.getWidth();
35950 this.baseScale = width / this.imageEl.OriginWidth;
35952 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
35953 height = this.thumbEl.getHeight();
35954 this.baseScale = height / this.imageEl.OriginHeight;
35957 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
35959 height = this.thumbEl.getHeight();
35960 this.baseScale = height / this.imageEl.OriginHeight;
35962 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
35963 width = this.thumbEl.getWidth();
35964 this.baseScale = width / this.imageEl.OriginWidth;
35972 getScaleLevel : function()
35974 return this.baseScale * Math.pow(1.1, this.scale);
35977 onTouchStart : function(e)
35979 if(!this.canvasLoaded){
35980 this.beforeSelectFile(e);
35984 var touches = e.browserEvent.touches;
35990 if(touches.length == 1){
35991 this.onMouseDown(e);
35995 if(touches.length != 2){
36001 for(var i = 0, finger; finger = touches[i]; i++){
36002 coords.push(finger.pageX, finger.pageY);
36005 var x = Math.pow(coords[0] - coords[2], 2);
36006 var y = Math.pow(coords[1] - coords[3], 2);
36008 this.startDistance = Math.sqrt(x + y);
36010 this.startScale = this.scale;
36012 this.pinching = true;
36013 this.dragable = false;
36017 onTouchMove : function(e)
36019 if(!this.pinching && !this.dragable){
36023 var touches = e.browserEvent.touches;
36030 this.onMouseMove(e);
36036 for(var i = 0, finger; finger = touches[i]; i++){
36037 coords.push(finger.pageX, finger.pageY);
36040 var x = Math.pow(coords[0] - coords[2], 2);
36041 var y = Math.pow(coords[1] - coords[3], 2);
36043 this.endDistance = Math.sqrt(x + y);
36045 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
36047 if(!this.zoomable()){
36048 this.scale = this.startScale;
36056 onTouchEnd : function(e)
36058 this.pinching = false;
36059 this.dragable = false;
36063 process : function(file, crop)
36066 this.maskEl.mask(this.loadingText);
36069 this.xhr = new XMLHttpRequest();
36071 file.xhr = this.xhr;
36073 this.xhr.open(this.method, this.url, true);
36076 "Accept": "application/json",
36077 "Cache-Control": "no-cache",
36078 "X-Requested-With": "XMLHttpRequest"
36081 for (var headerName in headers) {
36082 var headerValue = headers[headerName];
36084 this.xhr.setRequestHeader(headerName, headerValue);
36090 this.xhr.onload = function()
36092 _this.xhrOnLoad(_this.xhr);
36095 this.xhr.onerror = function()
36097 _this.xhrOnError(_this.xhr);
36100 var formData = new FormData();
36102 formData.append('returnHTML', 'NO');
36105 formData.append('crop', crop);
36108 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
36109 formData.append(this.paramName, file, file.name);
36112 if(typeof(file.filename) != 'undefined'){
36113 formData.append('filename', file.filename);
36116 if(typeof(file.mimetype) != 'undefined'){
36117 formData.append('mimetype', file.mimetype);
36120 if(this.fireEvent('arrange', this, formData) != false){
36121 this.xhr.send(formData);
36125 xhrOnLoad : function(xhr)
36128 this.maskEl.unmask();
36131 if (xhr.readyState !== 4) {
36132 this.fireEvent('exception', this, xhr);
36136 var response = Roo.decode(xhr.responseText);
36138 if(!response.success){
36139 this.fireEvent('exception', this, xhr);
36143 var response = Roo.decode(xhr.responseText);
36145 this.fireEvent('upload', this, response);
36149 xhrOnError : function()
36152 this.maskEl.unmask();
36155 Roo.log('xhr on error');
36157 var response = Roo.decode(xhr.responseText);
36163 prepare : function(file)
36166 this.maskEl.mask(this.loadingText);
36172 if(typeof(file) === 'string'){
36173 this.loadCanvas(file);
36177 if(!file || !this.urlAPI){
36182 this.cropType = file.type;
36186 if(this.fireEvent('prepare', this, this.file) != false){
36188 var reader = new FileReader();
36190 reader.onload = function (e) {
36191 if (e.target.error) {
36192 Roo.log(e.target.error);
36196 var buffer = e.target.result,
36197 dataView = new DataView(buffer),
36199 maxOffset = dataView.byteLength - 4,
36203 if (dataView.getUint16(0) === 0xffd8) {
36204 while (offset < maxOffset) {
36205 markerBytes = dataView.getUint16(offset);
36207 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
36208 markerLength = dataView.getUint16(offset + 2) + 2;
36209 if (offset + markerLength > dataView.byteLength) {
36210 Roo.log('Invalid meta data: Invalid segment size.');
36214 if(markerBytes == 0xffe1){
36215 _this.parseExifData(
36222 offset += markerLength;
36232 var url = _this.urlAPI.createObjectURL(_this.file);
36234 _this.loadCanvas(url);
36239 reader.readAsArrayBuffer(this.file);
36245 parseExifData : function(dataView, offset, length)
36247 var tiffOffset = offset + 10,
36251 if (dataView.getUint32(offset + 4) !== 0x45786966) {
36252 // No Exif data, might be XMP data instead
36256 // Check for the ASCII code for "Exif" (0x45786966):
36257 if (dataView.getUint32(offset + 4) !== 0x45786966) {
36258 // No Exif data, might be XMP data instead
36261 if (tiffOffset + 8 > dataView.byteLength) {
36262 Roo.log('Invalid Exif data: Invalid segment size.');
36265 // Check for the two null bytes:
36266 if (dataView.getUint16(offset + 8) !== 0x0000) {
36267 Roo.log('Invalid Exif data: Missing byte alignment offset.');
36270 // Check the byte alignment:
36271 switch (dataView.getUint16(tiffOffset)) {
36273 littleEndian = true;
36276 littleEndian = false;
36279 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
36282 // Check for the TIFF tag marker (0x002A):
36283 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
36284 Roo.log('Invalid Exif data: Missing TIFF marker.');
36287 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
36288 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
36290 this.parseExifTags(
36293 tiffOffset + dirOffset,
36298 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
36303 if (dirOffset + 6 > dataView.byteLength) {
36304 Roo.log('Invalid Exif data: Invalid directory offset.');
36307 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
36308 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
36309 if (dirEndOffset + 4 > dataView.byteLength) {
36310 Roo.log('Invalid Exif data: Invalid directory size.');
36313 for (i = 0; i < tagsNumber; i += 1) {
36317 dirOffset + 2 + 12 * i, // tag offset
36321 // Return the offset to the next directory:
36322 return dataView.getUint32(dirEndOffset, littleEndian);
36325 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
36327 var tag = dataView.getUint16(offset, littleEndian);
36329 this.exif[tag] = this.getExifValue(
36333 dataView.getUint16(offset + 2, littleEndian), // tag type
36334 dataView.getUint32(offset + 4, littleEndian), // tag length
36339 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
36341 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
36350 Roo.log('Invalid Exif data: Invalid tag type.');
36354 tagSize = tagType.size * length;
36355 // Determine if the value is contained in the dataOffset bytes,
36356 // or if the value at the dataOffset is a pointer to the actual data:
36357 dataOffset = tagSize > 4 ?
36358 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
36359 if (dataOffset + tagSize > dataView.byteLength) {
36360 Roo.log('Invalid Exif data: Invalid data offset.');
36363 if (length === 1) {
36364 return tagType.getValue(dataView, dataOffset, littleEndian);
36367 for (i = 0; i < length; i += 1) {
36368 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
36371 if (tagType.ascii) {
36373 // Concatenate the chars:
36374 for (i = 0; i < values.length; i += 1) {
36376 // Ignore the terminating NULL byte(s):
36377 if (c === '\u0000') {
36389 Roo.apply(Roo.bootstrap.UploadCropbox, {
36391 'Orientation': 0x0112
36395 1: 0, //'top-left',
36397 3: 180, //'bottom-right',
36398 // 4: 'bottom-left',
36400 6: 90, //'right-top',
36401 // 7: 'right-bottom',
36402 8: 270 //'left-bottom'
36406 // byte, 8-bit unsigned int:
36408 getValue: function (dataView, dataOffset) {
36409 return dataView.getUint8(dataOffset);
36413 // ascii, 8-bit byte:
36415 getValue: function (dataView, dataOffset) {
36416 return String.fromCharCode(dataView.getUint8(dataOffset));
36421 // short, 16 bit int:
36423 getValue: function (dataView, dataOffset, littleEndian) {
36424 return dataView.getUint16(dataOffset, littleEndian);
36428 // long, 32 bit int:
36430 getValue: function (dataView, dataOffset, littleEndian) {
36431 return dataView.getUint32(dataOffset, littleEndian);
36435 // rational = two long values, first is numerator, second is denominator:
36437 getValue: function (dataView, dataOffset, littleEndian) {
36438 return dataView.getUint32(dataOffset, littleEndian) /
36439 dataView.getUint32(dataOffset + 4, littleEndian);
36443 // slong, 32 bit signed int:
36445 getValue: function (dataView, dataOffset, littleEndian) {
36446 return dataView.getInt32(dataOffset, littleEndian);
36450 // srational, two slongs, first is numerator, second is denominator:
36452 getValue: function (dataView, dataOffset, littleEndian) {
36453 return dataView.getInt32(dataOffset, littleEndian) /
36454 dataView.getInt32(dataOffset + 4, littleEndian);
36464 cls : 'btn-group roo-upload-cropbox-rotate-left',
36465 action : 'rotate-left',
36469 cls : 'btn btn-default',
36470 html : '<i class="fa fa-undo"></i>'
36476 cls : 'btn-group roo-upload-cropbox-picture',
36477 action : 'picture',
36481 cls : 'btn btn-default',
36482 html : '<i class="fa fa-picture-o"></i>'
36488 cls : 'btn-group roo-upload-cropbox-rotate-right',
36489 action : 'rotate-right',
36493 cls : 'btn btn-default',
36494 html : '<i class="fa fa-repeat"></i>'
36502 cls : 'btn-group roo-upload-cropbox-rotate-left',
36503 action : 'rotate-left',
36507 cls : 'btn btn-default',
36508 html : '<i class="fa fa-undo"></i>'
36514 cls : 'btn-group roo-upload-cropbox-download',
36515 action : 'download',
36519 cls : 'btn btn-default',
36520 html : '<i class="fa fa-download"></i>'
36526 cls : 'btn-group roo-upload-cropbox-crop',
36531 cls : 'btn btn-default',
36532 html : '<i class="fa fa-crop"></i>'
36538 cls : 'btn-group roo-upload-cropbox-trash',
36543 cls : 'btn btn-default',
36544 html : '<i class="fa fa-trash"></i>'
36550 cls : 'btn-group roo-upload-cropbox-rotate-right',
36551 action : 'rotate-right',
36555 cls : 'btn btn-default',
36556 html : '<i class="fa fa-repeat"></i>'
36564 cls : 'btn-group roo-upload-cropbox-rotate-left',
36565 action : 'rotate-left',
36569 cls : 'btn btn-default',
36570 html : '<i class="fa fa-undo"></i>'
36576 cls : 'btn-group roo-upload-cropbox-rotate-right',
36577 action : 'rotate-right',
36581 cls : 'btn btn-default',
36582 html : '<i class="fa fa-repeat"></i>'
36595 * @class Roo.bootstrap.DocumentManager
36596 * @extends Roo.bootstrap.Component
36597 * Bootstrap DocumentManager class
36598 * @cfg {String} paramName default 'imageUpload'
36599 * @cfg {String} toolTipName default 'filename'
36600 * @cfg {String} method default POST
36601 * @cfg {String} url action url
36602 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
36603 * @cfg {Boolean} multiple multiple upload default true
36604 * @cfg {Number} thumbSize default 300
36605 * @cfg {String} fieldLabel
36606 * @cfg {Number} labelWidth default 4
36607 * @cfg {String} labelAlign (left|top) default left
36608 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
36609 * @cfg {Number} labellg set the width of label (1-12)
36610 * @cfg {Number} labelmd set the width of label (1-12)
36611 * @cfg {Number} labelsm set the width of label (1-12)
36612 * @cfg {Number} labelxs set the width of label (1-12)
36615 * Create a new DocumentManager
36616 * @param {Object} config The config object
36619 Roo.bootstrap.DocumentManager = function(config){
36620 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
36623 this.delegates = [];
36628 * Fire when initial the DocumentManager
36629 * @param {Roo.bootstrap.DocumentManager} this
36634 * inspect selected file
36635 * @param {Roo.bootstrap.DocumentManager} this
36636 * @param {File} file
36641 * Fire when xhr load exception
36642 * @param {Roo.bootstrap.DocumentManager} this
36643 * @param {XMLHttpRequest} xhr
36645 "exception" : true,
36647 * @event afterupload
36648 * Fire when xhr load exception
36649 * @param {Roo.bootstrap.DocumentManager} this
36650 * @param {XMLHttpRequest} xhr
36652 "afterupload" : true,
36655 * prepare the form data
36656 * @param {Roo.bootstrap.DocumentManager} this
36657 * @param {Object} formData
36662 * Fire when remove the file
36663 * @param {Roo.bootstrap.DocumentManager} this
36664 * @param {Object} file
36669 * Fire after refresh the file
36670 * @param {Roo.bootstrap.DocumentManager} this
36675 * Fire after click the image
36676 * @param {Roo.bootstrap.DocumentManager} this
36677 * @param {Object} file
36682 * Fire when upload a image and editable set to true
36683 * @param {Roo.bootstrap.DocumentManager} this
36684 * @param {Object} file
36688 * @event beforeselectfile
36689 * Fire before select file
36690 * @param {Roo.bootstrap.DocumentManager} this
36692 "beforeselectfile" : true,
36695 * Fire before process file
36696 * @param {Roo.bootstrap.DocumentManager} this
36697 * @param {Object} file
36701 * @event previewrendered
36702 * Fire when preview rendered
36703 * @param {Roo.bootstrap.DocumentManager} this
36704 * @param {Object} file
36706 "previewrendered" : true,
36709 "previewResize" : true
36714 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
36723 paramName : 'imageUpload',
36724 toolTipName : 'filename',
36727 labelAlign : 'left',
36737 getAutoCreate : function()
36739 var managerWidget = {
36741 cls : 'roo-document-manager',
36745 cls : 'roo-document-manager-selector',
36750 cls : 'roo-document-manager-uploader',
36754 cls : 'roo-document-manager-upload-btn',
36755 html : '<i class="fa fa-plus"></i>'
36766 cls : 'column col-md-12',
36771 if(this.fieldLabel.length){
36776 cls : 'column col-md-12',
36777 html : this.fieldLabel
36781 cls : 'column col-md-12',
36786 if(this.labelAlign == 'left'){
36791 html : this.fieldLabel
36800 if(this.labelWidth > 12){
36801 content[0].style = "width: " + this.labelWidth + 'px';
36804 if(this.labelWidth < 13 && this.labelmd == 0){
36805 this.labelmd = this.labelWidth;
36808 if(this.labellg > 0){
36809 content[0].cls += ' col-lg-' + this.labellg;
36810 content[1].cls += ' col-lg-' + (12 - this.labellg);
36813 if(this.labelmd > 0){
36814 content[0].cls += ' col-md-' + this.labelmd;
36815 content[1].cls += ' col-md-' + (12 - this.labelmd);
36818 if(this.labelsm > 0){
36819 content[0].cls += ' col-sm-' + this.labelsm;
36820 content[1].cls += ' col-sm-' + (12 - this.labelsm);
36823 if(this.labelxs > 0){
36824 content[0].cls += ' col-xs-' + this.labelxs;
36825 content[1].cls += ' col-xs-' + (12 - this.labelxs);
36833 cls : 'row clearfix',
36841 initEvents : function()
36843 this.managerEl = this.el.select('.roo-document-manager', true).first();
36844 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
36846 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
36847 this.selectorEl.hide();
36850 this.selectorEl.attr('multiple', 'multiple');
36853 this.selectorEl.on('change', this.onFileSelected, this);
36855 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
36856 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
36858 this.uploader.on('click', this.onUploaderClick, this);
36860 this.renderProgressDialog();
36864 window.addEventListener("resize", function() { _this.refresh(); } );
36866 this.fireEvent('initial', this);
36869 renderProgressDialog : function()
36873 this.progressDialog = new Roo.bootstrap.Modal({
36874 cls : 'roo-document-manager-progress-dialog',
36875 allow_close : false,
36886 btnclick : function() {
36887 _this.uploadCancel();
36893 this.progressDialog.render(Roo.get(document.body));
36895 this.progress = new Roo.bootstrap.Progress({
36896 cls : 'roo-document-manager-progress',
36901 this.progress.render(this.progressDialog.getChildContainer());
36903 this.progressBar = new Roo.bootstrap.ProgressBar({
36904 cls : 'roo-document-manager-progress-bar',
36907 aria_valuemax : 12,
36911 this.progressBar.render(this.progress.getChildContainer());
36914 onUploaderClick : function(e)
36916 e.preventDefault();
36918 if(this.fireEvent('beforeselectfile', this) != false){
36919 this.selectorEl.dom.click();
36924 onFileSelected : function(e)
36926 e.preventDefault();
36928 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
36932 Roo.each(this.selectorEl.dom.files, function(file){
36933 if(this.fireEvent('inspect', this, file) != false){
36934 this.files.push(file);
36944 this.selectorEl.dom.value = '';
36946 if(!this.files || !this.files.length){
36950 if(this.boxes > 0 && this.files.length > this.boxes){
36951 this.files = this.files.slice(0, this.boxes);
36954 this.uploader.show();
36956 if(this.boxes > 0 && this.files.length > this.boxes - 1){
36957 this.uploader.hide();
36966 Roo.each(this.files, function(file){
36968 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
36969 var f = this.renderPreview(file);
36974 if(file.type.indexOf('image') != -1){
36975 this.delegates.push(
36977 _this.process(file);
36978 }).createDelegate(this)
36986 _this.process(file);
36987 }).createDelegate(this)
36992 this.files = files;
36994 this.delegates = this.delegates.concat(docs);
36996 if(!this.delegates.length){
37001 this.progressBar.aria_valuemax = this.delegates.length;
37008 arrange : function()
37010 if(!this.delegates.length){
37011 this.progressDialog.hide();
37016 var delegate = this.delegates.shift();
37018 this.progressDialog.show();
37020 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
37022 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
37027 refresh : function()
37029 this.uploader.show();
37031 if(this.boxes > 0 && this.files.length > this.boxes - 1){
37032 this.uploader.hide();
37035 Roo.isTouch ? this.closable(false) : this.closable(true);
37037 this.fireEvent('refresh', this);
37040 onRemove : function(e, el, o)
37042 e.preventDefault();
37044 this.fireEvent('remove', this, o);
37048 remove : function(o)
37052 Roo.each(this.files, function(file){
37053 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
37062 this.files = files;
37069 Roo.each(this.files, function(file){
37074 file.target.remove();
37083 onClick : function(e, el, o)
37085 e.preventDefault();
37087 this.fireEvent('click', this, o);
37091 closable : function(closable)
37093 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
37095 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
37107 xhrOnLoad : function(xhr)
37109 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
37113 if (xhr.readyState !== 4) {
37115 this.fireEvent('exception', this, xhr);
37119 var response = Roo.decode(xhr.responseText);
37121 if(!response.success){
37123 this.fireEvent('exception', this, xhr);
37127 var file = this.renderPreview(response.data);
37129 this.files.push(file);
37133 this.fireEvent('afterupload', this, xhr);
37137 xhrOnError : function(xhr)
37139 Roo.log('xhr on error');
37141 var response = Roo.decode(xhr.responseText);
37148 process : function(file)
37150 if(this.fireEvent('process', this, file) !== false){
37151 if(this.editable && file.type.indexOf('image') != -1){
37152 this.fireEvent('edit', this, file);
37156 this.uploadStart(file, false);
37163 uploadStart : function(file, crop)
37165 this.xhr = new XMLHttpRequest();
37167 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
37172 file.xhr = this.xhr;
37174 this.managerEl.createChild({
37176 cls : 'roo-document-manager-loading',
37180 tooltip : file.name,
37181 cls : 'roo-document-manager-thumb',
37182 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
37188 this.xhr.open(this.method, this.url, true);
37191 "Accept": "application/json",
37192 "Cache-Control": "no-cache",
37193 "X-Requested-With": "XMLHttpRequest"
37196 for (var headerName in headers) {
37197 var headerValue = headers[headerName];
37199 this.xhr.setRequestHeader(headerName, headerValue);
37205 this.xhr.onload = function()
37207 _this.xhrOnLoad(_this.xhr);
37210 this.xhr.onerror = function()
37212 _this.xhrOnError(_this.xhr);
37215 var formData = new FormData();
37217 formData.append('returnHTML', 'NO');
37220 formData.append('crop', crop);
37223 formData.append(this.paramName, file, file.name);
37230 if(this.fireEvent('prepare', this, formData, options) != false){
37232 if(options.manually){
37236 this.xhr.send(formData);
37240 this.uploadCancel();
37243 uploadCancel : function()
37249 this.delegates = [];
37251 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
37258 renderPreview : function(file)
37260 if(typeof(file.target) != 'undefined' && file.target){
37264 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
37266 var previewEl = this.managerEl.createChild({
37268 cls : 'roo-document-manager-preview',
37272 tooltip : file[this.toolTipName],
37273 cls : 'roo-document-manager-thumb',
37274 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
37279 html : '<i class="fa fa-times-circle"></i>'
37284 var close = previewEl.select('button.close', true).first();
37286 close.on('click', this.onRemove, this, file);
37288 file.target = previewEl;
37290 var image = previewEl.select('img', true).first();
37294 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
37296 image.on('click', this.onClick, this, file);
37298 this.fireEvent('previewrendered', this, file);
37304 onPreviewLoad : function(file, image)
37306 if(typeof(file.target) == 'undefined' || !file.target){
37310 var width = image.dom.naturalWidth || image.dom.width;
37311 var height = image.dom.naturalHeight || image.dom.height;
37313 if(!this.previewResize) {
37317 if(width > height){
37318 file.target.addClass('wide');
37322 file.target.addClass('tall');
37327 uploadFromSource : function(file, crop)
37329 this.xhr = new XMLHttpRequest();
37331 this.managerEl.createChild({
37333 cls : 'roo-document-manager-loading',
37337 tooltip : file.name,
37338 cls : 'roo-document-manager-thumb',
37339 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
37345 this.xhr.open(this.method, this.url, true);
37348 "Accept": "application/json",
37349 "Cache-Control": "no-cache",
37350 "X-Requested-With": "XMLHttpRequest"
37353 for (var headerName in headers) {
37354 var headerValue = headers[headerName];
37356 this.xhr.setRequestHeader(headerName, headerValue);
37362 this.xhr.onload = function()
37364 _this.xhrOnLoad(_this.xhr);
37367 this.xhr.onerror = function()
37369 _this.xhrOnError(_this.xhr);
37372 var formData = new FormData();
37374 formData.append('returnHTML', 'NO');
37376 formData.append('crop', crop);
37378 if(typeof(file.filename) != 'undefined'){
37379 formData.append('filename', file.filename);
37382 if(typeof(file.mimetype) != 'undefined'){
37383 formData.append('mimetype', file.mimetype);
37388 if(this.fireEvent('prepare', this, formData) != false){
37389 this.xhr.send(formData);
37399 * @class Roo.bootstrap.DocumentViewer
37400 * @extends Roo.bootstrap.Component
37401 * Bootstrap DocumentViewer class
37402 * @cfg {Boolean} showDownload (true|false) show download button (default true)
37403 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
37406 * Create a new DocumentViewer
37407 * @param {Object} config The config object
37410 Roo.bootstrap.DocumentViewer = function(config){
37411 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
37416 * Fire after initEvent
37417 * @param {Roo.bootstrap.DocumentViewer} this
37423 * @param {Roo.bootstrap.DocumentViewer} this
37428 * Fire after download button
37429 * @param {Roo.bootstrap.DocumentViewer} this
37434 * Fire after trash button
37435 * @param {Roo.bootstrap.DocumentViewer} this
37442 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
37444 showDownload : true,
37448 getAutoCreate : function()
37452 cls : 'roo-document-viewer',
37456 cls : 'roo-document-viewer-body',
37460 cls : 'roo-document-viewer-thumb',
37464 cls : 'roo-document-viewer-image'
37472 cls : 'roo-document-viewer-footer',
37475 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
37479 cls : 'btn-group roo-document-viewer-download',
37483 cls : 'btn btn-default',
37484 html : '<i class="fa fa-download"></i>'
37490 cls : 'btn-group roo-document-viewer-trash',
37494 cls : 'btn btn-default',
37495 html : '<i class="fa fa-trash"></i>'
37508 initEvents : function()
37510 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
37511 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
37513 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
37514 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
37516 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
37517 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
37519 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
37520 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
37522 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
37523 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
37525 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
37526 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
37528 this.bodyEl.on('click', this.onClick, this);
37529 this.downloadBtn.on('click', this.onDownload, this);
37530 this.trashBtn.on('click', this.onTrash, this);
37532 this.downloadBtn.hide();
37533 this.trashBtn.hide();
37535 if(this.showDownload){
37536 this.downloadBtn.show();
37539 if(this.showTrash){
37540 this.trashBtn.show();
37543 if(!this.showDownload && !this.showTrash) {
37544 this.footerEl.hide();
37549 initial : function()
37551 this.fireEvent('initial', this);
37555 onClick : function(e)
37557 e.preventDefault();
37559 this.fireEvent('click', this);
37562 onDownload : function(e)
37564 e.preventDefault();
37566 this.fireEvent('download', this);
37569 onTrash : function(e)
37571 e.preventDefault();
37573 this.fireEvent('trash', this);
37585 * @class Roo.bootstrap.form.FieldLabel
37586 * @extends Roo.bootstrap.Component
37587 * Bootstrap FieldLabel class
37588 * @cfg {String} html contents of the element
37589 * @cfg {String} tag tag of the element default label
37590 * @cfg {String} cls class of the element
37591 * @cfg {String} target label target
37592 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
37593 * @cfg {String} invalidClass DEPRICATED - BS4 uses is-invalid
37594 * @cfg {String} validClass DEPRICATED - BS4 uses is-valid
37595 * @cfg {String} iconTooltip default "This field is required"
37596 * @cfg {String} indicatorpos (left|right) default left
37599 * Create a new FieldLabel
37600 * @param {Object} config The config object
37603 Roo.bootstrap.form.FieldLabel = function(config){
37604 Roo.bootstrap.Element.superclass.constructor.call(this, config);
37609 * Fires after the field has been marked as invalid.
37610 * @param {Roo.form.FieldLabel} this
37611 * @param {String} msg The validation message
37616 * Fires after the field has been validated with no errors.
37617 * @param {Roo.form.FieldLabel} this
37623 Roo.extend(Roo.bootstrap.form.FieldLabel, Roo.bootstrap.Component, {
37630 invalidClass : 'has-warning',
37631 validClass : 'has-success',
37632 iconTooltip : 'This field is required',
37633 indicatorpos : 'left',
37635 getAutoCreate : function(){
37638 if (!this.allowBlank) {
37644 cls : 'roo-bootstrap-field-label ' + this.cls,
37649 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
37650 tooltip : this.iconTooltip
37659 if(this.indicatorpos == 'right'){
37662 cls : 'roo-bootstrap-field-label ' + this.cls,
37671 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
37672 tooltip : this.iconTooltip
37681 initEvents: function()
37683 Roo.bootstrap.Element.superclass.initEvents.call(this);
37685 this.indicator = this.indicatorEl();
37687 if(this.indicator){
37688 this.indicator.removeClass('visible');
37689 this.indicator.addClass('invisible');
37692 Roo.bootstrap.form.FieldLabel.register(this);
37695 indicatorEl : function()
37697 var indicator = this.el.select('i.roo-required-indicator',true).first();
37708 * Mark this field as valid
37710 markValid : function()
37712 if(this.indicator){
37713 this.indicator.removeClass('visible');
37714 this.indicator.addClass('invisible');
37716 if (Roo.bootstrap.version == 3) {
37717 this.el.removeClass(this.invalidClass);
37718 this.el.addClass(this.validClass);
37720 this.el.removeClass('is-invalid');
37721 this.el.addClass('is-valid');
37725 this.fireEvent('valid', this);
37729 * Mark this field as invalid
37730 * @param {String} msg The validation message
37732 markInvalid : function(msg)
37734 if(this.indicator){
37735 this.indicator.removeClass('invisible');
37736 this.indicator.addClass('visible');
37738 if (Roo.bootstrap.version == 3) {
37739 this.el.removeClass(this.validClass);
37740 this.el.addClass(this.invalidClass);
37742 this.el.removeClass('is-valid');
37743 this.el.addClass('is-invalid');
37747 this.fireEvent('invalid', this, msg);
37753 Roo.apply(Roo.bootstrap.form.FieldLabel, {
37758 * register a FieldLabel Group
37759 * @param {Roo.bootstrap.form.FieldLabel} the FieldLabel to add
37761 register : function(label)
37763 if(this.groups.hasOwnProperty(label.target)){
37767 this.groups[label.target] = label;
37771 * fetch a FieldLabel Group based on the target
37772 * @param {string} target
37773 * @returns {Roo.bootstrap.form.FieldLabel} the CheckBox group
37775 get: function(target) {
37776 if (typeof(this.groups[target]) == 'undefined') {
37780 return this.groups[target] ;
37789 * page DateSplitField.
37795 * @class Roo.bootstrap.form.DateSplitField
37796 * @extends Roo.bootstrap.Component
37797 * Bootstrap DateSplitField class
37798 * @cfg {string} fieldLabel - the label associated
37799 * @cfg {Number} labelWidth set the width of label (0-12)
37800 * @cfg {String} labelAlign (top|left)
37801 * @cfg {Boolean} dayAllowBlank (true|false) default false
37802 * @cfg {Boolean} monthAllowBlank (true|false) default false
37803 * @cfg {Boolean} yearAllowBlank (true|false) default false
37804 * @cfg {string} dayPlaceholder
37805 * @cfg {string} monthPlaceholder
37806 * @cfg {string} yearPlaceholder
37807 * @cfg {string} dayFormat default 'd'
37808 * @cfg {string} monthFormat default 'm'
37809 * @cfg {string} yearFormat default 'Y'
37810 * @cfg {Number} labellg set the width of label (1-12)
37811 * @cfg {Number} labelmd set the width of label (1-12)
37812 * @cfg {Number} labelsm set the width of label (1-12)
37813 * @cfg {Number} labelxs set the width of label (1-12)
37817 * Create a new DateSplitField
37818 * @param {Object} config The config object
37821 Roo.bootstrap.form.DateSplitField = function(config){
37822 Roo.bootstrap.form.DateSplitField.superclass.constructor.call(this, config);
37828 * getting the data of years
37829 * @param {Roo.bootstrap.form.DateSplitField} this
37830 * @param {Object} years
37835 * getting the data of days
37836 * @param {Roo.bootstrap.form.DateSplitField} this
37837 * @param {Object} days
37842 * Fires after the field has been marked as invalid.
37843 * @param {Roo.form.Field} this
37844 * @param {String} msg The validation message
37849 * Fires after the field has been validated with no errors.
37850 * @param {Roo.form.Field} this
37856 Roo.extend(Roo.bootstrap.form.DateSplitField, Roo.bootstrap.Component, {
37859 labelAlign : 'top',
37861 dayAllowBlank : false,
37862 monthAllowBlank : false,
37863 yearAllowBlank : false,
37864 dayPlaceholder : '',
37865 monthPlaceholder : '',
37866 yearPlaceholder : '',
37870 isFormField : true,
37876 getAutoCreate : function()
37880 cls : 'row roo-date-split-field-group',
37885 cls : 'form-hidden-field roo-date-split-field-group-value',
37891 var labelCls = 'col-md-12';
37892 var contentCls = 'col-md-4';
37894 if(this.fieldLabel){
37898 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
37902 html : this.fieldLabel
37907 if(this.labelAlign == 'left'){
37909 if(this.labelWidth > 12){
37910 label.style = "width: " + this.labelWidth + 'px';
37913 if(this.labelWidth < 13 && this.labelmd == 0){
37914 this.labelmd = this.labelWidth;
37917 if(this.labellg > 0){
37918 labelCls = ' col-lg-' + this.labellg;
37919 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
37922 if(this.labelmd > 0){
37923 labelCls = ' col-md-' + this.labelmd;
37924 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
37927 if(this.labelsm > 0){
37928 labelCls = ' col-sm-' + this.labelsm;
37929 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
37932 if(this.labelxs > 0){
37933 labelCls = ' col-xs-' + this.labelxs;
37934 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
37938 label.cls += ' ' + labelCls;
37940 cfg.cn.push(label);
37943 Roo.each(['day', 'month', 'year'], function(t){
37946 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
37953 inputEl: function ()
37955 return this.el.select('.roo-date-split-field-group-value', true).first();
37958 onRender : function(ct, position)
37962 Roo.bootstrap.DateSplitFiel.superclass.onRender.call(this, ct, position);
37964 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
37966 this.dayField = new Roo.bootstrap.form.ComboBox({
37967 allowBlank : this.dayAllowBlank,
37968 alwaysQuery : true,
37969 displayField : 'value',
37972 forceSelection : true,
37974 placeholder : this.dayPlaceholder,
37975 selectOnFocus : true,
37976 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
37977 triggerAction : 'all',
37979 valueField : 'value',
37980 store : new Roo.data.SimpleStore({
37981 data : (function() {
37983 _this.fireEvent('days', _this, days);
37986 fields : [ 'value' ]
37989 select : function (_self, record, index)
37991 _this.setValue(_this.getValue());
37996 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
37998 this.monthField = new Roo.bootstrap.form.MonthField({
37999 after : '<i class=\"fa fa-calendar\"></i>',
38000 allowBlank : this.monthAllowBlank,
38001 placeholder : this.monthPlaceholder,
38004 render : function (_self)
38006 this.el.select('span.input-group-addon', true).first().on('click', function(e){
38007 e.preventDefault();
38011 select : function (_self, oldvalue, newvalue)
38013 _this.setValue(_this.getValue());
38018 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
38020 this.yearField = new Roo.bootstrap.form.ComboBox({
38021 allowBlank : this.yearAllowBlank,
38022 alwaysQuery : true,
38023 displayField : 'value',
38026 forceSelection : true,
38028 placeholder : this.yearPlaceholder,
38029 selectOnFocus : true,
38030 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
38031 triggerAction : 'all',
38033 valueField : 'value',
38034 store : new Roo.data.SimpleStore({
38035 data : (function() {
38037 _this.fireEvent('years', _this, years);
38040 fields : [ 'value' ]
38043 select : function (_self, record, index)
38045 _this.setValue(_this.getValue());
38050 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
38053 setValue : function(v, format)
38055 this.inputEl.dom.value = v;
38057 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
38059 var d = Date.parseDate(v, f);
38066 this.setDay(d.format(this.dayFormat));
38067 this.setMonth(d.format(this.monthFormat));
38068 this.setYear(d.format(this.yearFormat));
38075 setDay : function(v)
38077 this.dayField.setValue(v);
38078 this.inputEl.dom.value = this.getValue();
38083 setMonth : function(v)
38085 this.monthField.setValue(v, true);
38086 this.inputEl.dom.value = this.getValue();
38091 setYear : function(v)
38093 this.yearField.setValue(v);
38094 this.inputEl.dom.value = this.getValue();
38099 getDay : function()
38101 return this.dayField.getValue();
38104 getMonth : function()
38106 return this.monthField.getValue();
38109 getYear : function()
38111 return this.yearField.getValue();
38114 getValue : function()
38116 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
38118 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
38128 this.inputEl.dom.value = '';
38133 validate : function()
38135 var d = this.dayField.validate();
38136 var m = this.monthField.validate();
38137 var y = this.yearField.validate();
38142 (!this.dayAllowBlank && !d) ||
38143 (!this.monthAllowBlank && !m) ||
38144 (!this.yearAllowBlank && !y)
38149 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
38158 this.markInvalid();
38163 markValid : function()
38166 var label = this.el.select('label', true).first();
38167 var icon = this.el.select('i.fa-star', true).first();
38173 this.fireEvent('valid', this);
38177 * Mark this field as invalid
38178 * @param {String} msg The validation message
38180 markInvalid : function(msg)
38183 var label = this.el.select('label', true).first();
38184 var icon = this.el.select('i.fa-star', true).first();
38186 if(label && !icon){
38187 this.el.select('.roo-date-split-field-label', true).createChild({
38189 cls : 'text-danger fa fa-lg fa-star',
38190 tooltip : 'This field is required',
38191 style : 'margin-right:5px;'
38195 this.fireEvent('invalid', this, msg);
38198 clearInvalid : function()
38200 var label = this.el.select('label', true).first();
38201 var icon = this.el.select('i.fa-star', true).first();
38207 this.fireEvent('valid', this);
38210 getName: function()
38220 * @class Roo.bootstrap.LayoutMasonry
38221 * @extends Roo.bootstrap.Component
38222 * @children Roo.bootstrap.Element Roo.bootstrap.Img Roo.bootstrap.MasonryBrick
38223 * Bootstrap Layout Masonry class
38226 * http://masonry.desandro.com
38228 * The idea is to render all the bricks based on vertical width...
38230 * The original code extends 'outlayer' - we might need to use that....
38233 * Create a new Element
38234 * @param {Object} config The config object
38237 Roo.bootstrap.LayoutMasonry = function(config){
38239 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
38243 Roo.bootstrap.LayoutMasonry.register(this);
38249 * Fire after layout the items
38250 * @param {Roo.bootstrap.LayoutMasonry} this
38251 * @param {Roo.EventObject} e
38258 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
38261 * @cfg {Boolean} isLayoutInstant = no animation?
38263 isLayoutInstant : false, // needed?
38266 * @cfg {Number} boxWidth width of the columns
38271 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
38276 * @cfg {Number} padWidth padding below box..
38281 * @cfg {Number} gutter gutter width..
38286 * @cfg {Number} maxCols maximum number of columns
38292 * @cfg {Boolean} isAutoInitial defalut true
38294 isAutoInitial : true,
38299 * @cfg {Boolean} isHorizontal defalut false
38301 isHorizontal : false,
38303 currentSize : null,
38309 bricks: null, //CompositeElement
38313 _isLayoutInited : false,
38315 // isAlternative : false, // only use for vertical layout...
38318 * @cfg {Number} alternativePadWidth padding below box..
38320 alternativePadWidth : 50,
38322 selectedBrick : [],
38324 getAutoCreate : function(){
38326 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
38330 cls: 'blog-masonary-wrapper ' + this.cls,
38332 cls : 'mas-boxes masonary'
38339 getChildContainer: function( )
38341 if (this.boxesEl) {
38342 return this.boxesEl;
38345 this.boxesEl = this.el.select('.mas-boxes').first();
38347 return this.boxesEl;
38351 initEvents : function()
38355 if(this.isAutoInitial){
38356 Roo.log('hook children rendered');
38357 this.on('childrenrendered', function() {
38358 Roo.log('children rendered');
38364 initial : function()
38366 this.selectedBrick = [];
38368 this.currentSize = this.el.getBox(true);
38370 Roo.EventManager.onWindowResize(this.resize, this);
38372 if(!this.isAutoInitial){
38380 //this.layout.defer(500,this);
38384 resize : function()
38386 var cs = this.el.getBox(true);
38389 this.currentSize.width == cs.width &&
38390 this.currentSize.x == cs.x &&
38391 this.currentSize.height == cs.height &&
38392 this.currentSize.y == cs.y
38394 Roo.log("no change in with or X or Y");
38398 this.currentSize = cs;
38404 layout : function()
38406 this._resetLayout();
38408 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
38410 this.layoutItems( isInstant );
38412 this._isLayoutInited = true;
38414 this.fireEvent('layout', this);
38418 _resetLayout : function()
38420 if(this.isHorizontal){
38421 this.horizontalMeasureColumns();
38425 this.verticalMeasureColumns();
38429 verticalMeasureColumns : function()
38431 this.getContainerWidth();
38433 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
38434 // this.colWidth = Math.floor(this.containerWidth * 0.8);
38438 var boxWidth = this.boxWidth + this.padWidth;
38440 if(this.containerWidth < this.boxWidth){
38441 boxWidth = this.containerWidth
38444 var containerWidth = this.containerWidth;
38446 var cols = Math.floor(containerWidth / boxWidth);
38448 this.cols = Math.max( cols, 1 );
38450 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
38452 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
38454 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
38456 this.colWidth = boxWidth + avail - this.padWidth;
38458 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
38459 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
38462 horizontalMeasureColumns : function()
38464 this.getContainerWidth();
38466 var boxWidth = this.boxWidth;
38468 if(this.containerWidth < boxWidth){
38469 boxWidth = this.containerWidth;
38472 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
38474 this.el.setHeight(boxWidth);
38478 getContainerWidth : function()
38480 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
38483 layoutItems : function( isInstant )
38485 Roo.log(this.bricks);
38487 var items = Roo.apply([], this.bricks);
38489 if(this.isHorizontal){
38490 this._horizontalLayoutItems( items , isInstant );
38494 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
38495 // this._verticalAlternativeLayoutItems( items , isInstant );
38499 this._verticalLayoutItems( items , isInstant );
38503 _verticalLayoutItems : function ( items , isInstant)
38505 if ( !items || !items.length ) {
38510 ['xs', 'xs', 'xs', 'tall'],
38511 ['xs', 'xs', 'tall'],
38512 ['xs', 'xs', 'sm'],
38513 ['xs', 'xs', 'xs'],
38519 ['sm', 'xs', 'xs'],
38523 ['tall', 'xs', 'xs', 'xs'],
38524 ['tall', 'xs', 'xs'],
38536 Roo.each(items, function(item, k){
38538 switch (item.size) {
38539 // these layouts take up a full box,
38550 boxes.push([item]);
38573 var filterPattern = function(box, length)
38581 var pattern = box.slice(0, length);
38585 Roo.each(pattern, function(i){
38586 format.push(i.size);
38589 Roo.each(standard, function(s){
38591 if(String(s) != String(format)){
38600 if(!match && length == 1){
38605 filterPattern(box, length - 1);
38609 queue.push(pattern);
38611 box = box.slice(length, box.length);
38613 filterPattern(box, 4);
38619 Roo.each(boxes, function(box, k){
38625 if(box.length == 1){
38630 filterPattern(box, 4);
38634 this._processVerticalLayoutQueue( queue, isInstant );
38638 // _verticalAlternativeLayoutItems : function( items , isInstant )
38640 // if ( !items || !items.length ) {
38644 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
38648 _horizontalLayoutItems : function ( items , isInstant)
38650 if ( !items || !items.length || items.length < 3) {
38656 var eItems = items.slice(0, 3);
38658 items = items.slice(3, items.length);
38661 ['xs', 'xs', 'xs', 'wide'],
38662 ['xs', 'xs', 'wide'],
38663 ['xs', 'xs', 'sm'],
38664 ['xs', 'xs', 'xs'],
38670 ['sm', 'xs', 'xs'],
38674 ['wide', 'xs', 'xs', 'xs'],
38675 ['wide', 'xs', 'xs'],
38688 Roo.each(items, function(item, k){
38690 switch (item.size) {
38701 boxes.push([item]);
38725 var filterPattern = function(box, length)
38733 var pattern = box.slice(0, length);
38737 Roo.each(pattern, function(i){
38738 format.push(i.size);
38741 Roo.each(standard, function(s){
38743 if(String(s) != String(format)){
38752 if(!match && length == 1){
38757 filterPattern(box, length - 1);
38761 queue.push(pattern);
38763 box = box.slice(length, box.length);
38765 filterPattern(box, 4);
38771 Roo.each(boxes, function(box, k){
38777 if(box.length == 1){
38782 filterPattern(box, 4);
38789 var pos = this.el.getBox(true);
38793 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
38795 var hit_end = false;
38797 Roo.each(queue, function(box){
38801 Roo.each(box, function(b){
38803 b.el.setVisibilityMode(Roo.Element.DISPLAY);
38813 Roo.each(box, function(b){
38815 b.el.setVisibilityMode(Roo.Element.DISPLAY);
38818 mx = Math.max(mx, b.x);
38822 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
38826 Roo.each(box, function(b){
38828 b.el.setVisibilityMode(Roo.Element.DISPLAY);
38842 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
38845 /** Sets position of item in DOM
38846 * @param {Element} item
38847 * @param {Number} x - horizontal position
38848 * @param {Number} y - vertical position
38849 * @param {Boolean} isInstant - disables transitions
38851 _processVerticalLayoutQueue : function( queue, isInstant )
38853 var pos = this.el.getBox(true);
38858 for (var i = 0; i < this.cols; i++){
38862 Roo.each(queue, function(box, k){
38864 var col = k % this.cols;
38866 Roo.each(box, function(b,kk){
38868 b.el.position('absolute');
38870 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
38871 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
38873 if(b.size == 'md-left' || b.size == 'md-right'){
38874 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
38875 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
38878 b.el.setWidth(width);
38879 b.el.setHeight(height);
38881 b.el.select('iframe',true).setSize(width,height);
38885 for (var i = 0; i < this.cols; i++){
38887 if(maxY[i] < maxY[col]){
38892 col = Math.min(col, i);
38896 x = pos.x + col * (this.colWidth + this.padWidth);
38900 var positions = [];
38902 switch (box.length){
38904 positions = this.getVerticalOneBoxColPositions(x, y, box);
38907 positions = this.getVerticalTwoBoxColPositions(x, y, box);
38910 positions = this.getVerticalThreeBoxColPositions(x, y, box);
38913 positions = this.getVerticalFourBoxColPositions(x, y, box);
38919 Roo.each(box, function(b,kk){
38921 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
38923 var sz = b.el.getSize();
38925 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
38933 for (var i = 0; i < this.cols; i++){
38934 mY = Math.max(mY, maxY[i]);
38937 this.el.setHeight(mY - pos.y);
38941 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
38943 // var pos = this.el.getBox(true);
38946 // var maxX = pos.right;
38948 // var maxHeight = 0;
38950 // Roo.each(items, function(item, k){
38954 // item.el.position('absolute');
38956 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
38958 // item.el.setWidth(width);
38960 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
38962 // item.el.setHeight(height);
38965 // item.el.setXY([x, y], isInstant ? false : true);
38967 // item.el.setXY([maxX - width, y], isInstant ? false : true);
38970 // y = y + height + this.alternativePadWidth;
38972 // maxHeight = maxHeight + height + this.alternativePadWidth;
38976 // this.el.setHeight(maxHeight);
38980 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
38982 var pos = this.el.getBox(true);
38987 var maxX = pos.right;
38989 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
38991 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
38993 Roo.each(queue, function(box, k){
38995 Roo.each(box, function(b, kk){
38997 b.el.position('absolute');
38999 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
39000 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
39002 if(b.size == 'md-left' || b.size == 'md-right'){
39003 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
39004 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
39007 b.el.setWidth(width);
39008 b.el.setHeight(height);
39016 var positions = [];
39018 switch (box.length){
39020 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
39023 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
39026 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
39029 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
39035 Roo.each(box, function(b,kk){
39037 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
39039 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
39047 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
39049 Roo.each(eItems, function(b,k){
39051 b.size = (k == 0) ? 'sm' : 'xs';
39052 b.x = (k == 0) ? 2 : 1;
39053 b.y = (k == 0) ? 2 : 1;
39055 b.el.position('absolute');
39057 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
39059 b.el.setWidth(width);
39061 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
39063 b.el.setHeight(height);
39067 var positions = [];
39070 x : maxX - this.unitWidth * 2 - this.gutter,
39075 x : maxX - this.unitWidth,
39076 y : minY + (this.unitWidth + this.gutter) * 2
39080 x : maxX - this.unitWidth * 3 - this.gutter * 2,
39084 Roo.each(eItems, function(b,k){
39086 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
39092 getVerticalOneBoxColPositions : function(x, y, box)
39096 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
39098 if(box[0].size == 'md-left'){
39102 if(box[0].size == 'md-right'){
39107 x : x + (this.unitWidth + this.gutter) * rand,
39114 getVerticalTwoBoxColPositions : function(x, y, box)
39118 if(box[0].size == 'xs'){
39122 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
39126 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
39140 x : x + (this.unitWidth + this.gutter) * 2,
39141 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
39148 getVerticalThreeBoxColPositions : function(x, y, box)
39152 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
39160 x : x + (this.unitWidth + this.gutter) * 1,
39165 x : x + (this.unitWidth + this.gutter) * 2,
39173 if(box[0].size == 'xs' && box[1].size == 'xs'){
39182 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
39186 x : x + (this.unitWidth + this.gutter) * 1,
39200 x : x + (this.unitWidth + this.gutter) * 2,
39205 x : x + (this.unitWidth + this.gutter) * 2,
39206 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
39213 getVerticalFourBoxColPositions : function(x, y, box)
39217 if(box[0].size == 'xs'){
39226 y : y + (this.unitHeight + this.gutter) * 1
39231 y : y + (this.unitHeight + this.gutter) * 2
39235 x : x + (this.unitWidth + this.gutter) * 1,
39249 x : x + (this.unitWidth + this.gutter) * 2,
39254 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
39255 y : y + (this.unitHeight + this.gutter) * 1
39259 x : x + (this.unitWidth + this.gutter) * 2,
39260 y : y + (this.unitWidth + this.gutter) * 2
39267 getHorizontalOneBoxColPositions : function(maxX, minY, box)
39271 if(box[0].size == 'md-left'){
39273 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
39280 if(box[0].size == 'md-right'){
39282 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
39283 y : minY + (this.unitWidth + this.gutter) * 1
39289 var rand = Math.floor(Math.random() * (4 - box[0].y));
39292 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39293 y : minY + (this.unitWidth + this.gutter) * rand
39300 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
39304 if(box[0].size == 'xs'){
39307 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39312 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39313 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
39321 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39326 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39327 y : minY + (this.unitWidth + this.gutter) * 2
39334 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
39338 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
39341 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39346 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39347 y : minY + (this.unitWidth + this.gutter) * 1
39351 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39352 y : minY + (this.unitWidth + this.gutter) * 2
39359 if(box[0].size == 'xs' && box[1].size == 'xs'){
39362 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39367 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39372 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39373 y : minY + (this.unitWidth + this.gutter) * 1
39381 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39386 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39387 y : minY + (this.unitWidth + this.gutter) * 2
39391 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39392 y : minY + (this.unitWidth + this.gutter) * 2
39399 getHorizontalFourBoxColPositions : function(maxX, minY, box)
39403 if(box[0].size == 'xs'){
39406 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39411 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39416 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),
39421 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
39422 y : minY + (this.unitWidth + this.gutter) * 1
39430 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
39435 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
39436 y : minY + (this.unitWidth + this.gutter) * 2
39440 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
39441 y : minY + (this.unitWidth + this.gutter) * 2
39445 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),
39446 y : minY + (this.unitWidth + this.gutter) * 2
39454 * remove a Masonry Brick
39455 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
39457 removeBrick : function(brick_id)
39463 for (var i = 0; i<this.bricks.length; i++) {
39464 if (this.bricks[i].id == brick_id) {
39465 this.bricks.splice(i,1);
39466 this.el.dom.removeChild(Roo.get(brick_id).dom);
39473 * adds a Masonry Brick
39474 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
39476 addBrick : function(cfg)
39478 var cn = new Roo.bootstrap.MasonryBrick(cfg);
39479 //this.register(cn);
39480 cn.parentId = this.id;
39481 cn.render(this.el);
39486 * register a Masonry Brick
39487 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
39490 register : function(brick)
39492 this.bricks.push(brick);
39493 brick.masonryId = this.id;
39497 * clear all the Masonry Brick
39499 clearAll : function()
39502 //this.getChildContainer().dom.innerHTML = "";
39503 this.el.dom.innerHTML = '';
39506 getSelected : function()
39508 if (!this.selectedBrick) {
39512 return this.selectedBrick;
39516 Roo.apply(Roo.bootstrap.LayoutMasonry, {
39520 * register a Masonry Layout
39521 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
39524 register : function(layout)
39526 this.groups[layout.id] = layout;
39529 * fetch a Masonry Layout based on the masonry layout ID
39530 * @param {string} the masonry layout to add
39531 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
39534 get: function(layout_id) {
39535 if (typeof(this.groups[layout_id]) == 'undefined') {
39538 return this.groups[layout_id] ;
39550 * http://masonry.desandro.com
39552 * The idea is to render all the bricks based on vertical width...
39554 * The original code extends 'outlayer' - we might need to use that....
39560 * @class Roo.bootstrap.LayoutMasonryAuto
39561 * @extends Roo.bootstrap.Component
39562 * Bootstrap Layout Masonry class
39565 * Create a new Element
39566 * @param {Object} config The config object
39569 Roo.bootstrap.LayoutMasonryAuto = function(config){
39570 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
39573 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
39576 * @cfg {Boolean} isFitWidth - resize the width..
39578 isFitWidth : false, // options..
39580 * @cfg {Boolean} isOriginLeft = left align?
39582 isOriginLeft : true,
39584 * @cfg {Boolean} isOriginTop = top align?
39586 isOriginTop : false,
39588 * @cfg {Boolean} isLayoutInstant = no animation?
39590 isLayoutInstant : false, // needed?
39592 * @cfg {Boolean} isResizingContainer = not sure if this is used..
39594 isResizingContainer : true,
39596 * @cfg {Number} columnWidth width of the columns
39602 * @cfg {Number} maxCols maximum number of columns
39607 * @cfg {Number} padHeight padding below box..
39613 * @cfg {Boolean} isAutoInitial defalut true
39616 isAutoInitial : true,
39622 initialColumnWidth : 0,
39623 currentSize : null,
39625 colYs : null, // array.
39632 bricks: null, //CompositeElement
39633 cols : 0, // array?
39634 // element : null, // wrapped now this.el
39635 _isLayoutInited : null,
39638 getAutoCreate : function(){
39642 cls: 'blog-masonary-wrapper ' + this.cls,
39644 cls : 'mas-boxes masonary'
39651 getChildContainer: function( )
39653 if (this.boxesEl) {
39654 return this.boxesEl;
39657 this.boxesEl = this.el.select('.mas-boxes').first();
39659 return this.boxesEl;
39663 initEvents : function()
39667 if(this.isAutoInitial){
39668 Roo.log('hook children rendered');
39669 this.on('childrenrendered', function() {
39670 Roo.log('children rendered');
39677 initial : function()
39679 this.reloadItems();
39681 this.currentSize = this.el.getBox(true);
39683 /// was window resize... - let's see if this works..
39684 Roo.EventManager.onWindowResize(this.resize, this);
39686 if(!this.isAutoInitial){
39691 this.layout.defer(500,this);
39694 reloadItems: function()
39696 this.bricks = this.el.select('.masonry-brick', true);
39698 this.bricks.each(function(b) {
39699 //Roo.log(b.getSize());
39700 if (!b.attr('originalwidth')) {
39701 b.attr('originalwidth', b.getSize().width);
39706 Roo.log(this.bricks.elements.length);
39709 resize : function()
39712 var cs = this.el.getBox(true);
39714 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
39715 Roo.log("no change in with or X");
39718 this.currentSize = cs;
39722 layout : function()
39725 this._resetLayout();
39726 //this._manageStamps();
39728 // don't animate first layout
39729 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
39730 this.layoutItems( isInstant );
39732 // flag for initalized
39733 this._isLayoutInited = true;
39736 layoutItems : function( isInstant )
39738 //var items = this._getItemsForLayout( this.items );
39739 // original code supports filtering layout items.. we just ignore it..
39741 this._layoutItems( this.bricks , isInstant );
39743 this._postLayout();
39745 _layoutItems : function ( items , isInstant)
39747 //this.fireEvent( 'layout', this, items );
39750 if ( !items || !items.elements.length ) {
39751 // no items, emit event with empty array
39756 items.each(function(item) {
39757 Roo.log("layout item");
39759 // get x/y object from method
39760 var position = this._getItemLayoutPosition( item );
39762 position.item = item;
39763 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
39764 queue.push( position );
39767 this._processLayoutQueue( queue );
39769 /** Sets position of item in DOM
39770 * @param {Element} item
39771 * @param {Number} x - horizontal position
39772 * @param {Number} y - vertical position
39773 * @param {Boolean} isInstant - disables transitions
39775 _processLayoutQueue : function( queue )
39777 for ( var i=0, len = queue.length; i < len; i++ ) {
39778 var obj = queue[i];
39779 obj.item.position('absolute');
39780 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
39786 * Any logic you want to do after each layout,
39787 * i.e. size the container
39789 _postLayout : function()
39791 this.resizeContainer();
39794 resizeContainer : function()
39796 if ( !this.isResizingContainer ) {
39799 var size = this._getContainerSize();
39801 this.el.setSize(size.width,size.height);
39802 this.boxesEl.setSize(size.width,size.height);
39808 _resetLayout : function()
39810 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
39811 this.colWidth = this.el.getWidth();
39812 //this.gutter = this.el.getWidth();
39814 this.measureColumns();
39820 this.colYs.push( 0 );
39826 measureColumns : function()
39828 this.getContainerWidth();
39829 // if columnWidth is 0, default to outerWidth of first item
39830 if ( !this.columnWidth ) {
39831 var firstItem = this.bricks.first();
39832 Roo.log(firstItem);
39833 this.columnWidth = this.containerWidth;
39834 if (firstItem && firstItem.attr('originalwidth') ) {
39835 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
39837 // columnWidth fall back to item of first element
39838 Roo.log("set column width?");
39839 this.initialColumnWidth = this.columnWidth ;
39841 // if first elem has no width, default to size of container
39846 if (this.initialColumnWidth) {
39847 this.columnWidth = this.initialColumnWidth;
39852 // column width is fixed at the top - however if container width get's smaller we should
39855 // this bit calcs how man columns..
39857 var columnWidth = this.columnWidth += this.gutter;
39859 // calculate columns
39860 var containerWidth = this.containerWidth + this.gutter;
39862 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
39863 // fix rounding errors, typically with gutters
39864 var excess = columnWidth - containerWidth % columnWidth;
39867 // if overshoot is less than a pixel, round up, otherwise floor it
39868 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
39869 cols = Math[ mathMethod ]( cols );
39870 this.cols = Math.max( cols, 1 );
39871 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
39873 // padding positioning..
39874 var totalColWidth = this.cols * this.columnWidth;
39875 var padavail = this.containerWidth - totalColWidth;
39876 // so for 2 columns - we need 3 'pads'
39878 var padNeeded = (1+this.cols) * this.padWidth;
39880 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
39882 this.columnWidth += padExtra
39883 //this.padWidth = Math.floor(padavail / ( this.cols));
39885 // adjust colum width so that padding is fixed??
39887 // we have 3 columns ... total = width * 3
39888 // we have X left over... that should be used by
39890 //if (this.expandC) {
39898 getContainerWidth : function()
39900 /* // container is parent if fit width
39901 var container = this.isFitWidth ? this.element.parentNode : this.element;
39902 // check that this.size and size are there
39903 // IE8 triggers resize on body size change, so they might not be
39905 var size = getSize( container ); //FIXME
39906 this.containerWidth = size && size.innerWidth; //FIXME
39909 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
39913 _getItemLayoutPosition : function( item ) // what is item?
39915 // we resize the item to our columnWidth..
39917 item.setWidth(this.columnWidth);
39918 item.autoBoxAdjust = false;
39920 var sz = item.getSize();
39922 // how many columns does this brick span
39923 var remainder = this.containerWidth % this.columnWidth;
39925 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
39926 // round if off by 1 pixel, otherwise use ceil
39927 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
39928 colSpan = Math.min( colSpan, this.cols );
39930 // normally this should be '1' as we dont' currently allow multi width columns..
39932 var colGroup = this._getColGroup( colSpan );
39933 // get the minimum Y value from the columns
39934 var minimumY = Math.min.apply( Math, colGroup );
39935 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
39937 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
39939 // position the brick
39941 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
39942 y: this.currentSize.y + minimumY + this.padHeight
39946 // apply setHeight to necessary columns
39947 var setHeight = minimumY + sz.height + this.padHeight;
39948 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
39950 var setSpan = this.cols + 1 - colGroup.length;
39951 for ( var i = 0; i < setSpan; i++ ) {
39952 this.colYs[ shortColIndex + i ] = setHeight ;
39959 * @param {Number} colSpan - number of columns the element spans
39960 * @returns {Array} colGroup
39962 _getColGroup : function( colSpan )
39964 if ( colSpan < 2 ) {
39965 // if brick spans only one column, use all the column Ys
39970 // how many different places could this brick fit horizontally
39971 var groupCount = this.cols + 1 - colSpan;
39972 // for each group potential horizontal position
39973 for ( var i = 0; i < groupCount; i++ ) {
39974 // make an array of colY values for that one group
39975 var groupColYs = this.colYs.slice( i, i + colSpan );
39976 // and get the max value of the array
39977 colGroup[i] = Math.max.apply( Math, groupColYs );
39982 _manageStamp : function( stamp )
39984 var stampSize = stamp.getSize();
39985 var offset = stamp.getBox();
39986 // get the columns that this stamp affects
39987 var firstX = this.isOriginLeft ? offset.x : offset.right;
39988 var lastX = firstX + stampSize.width;
39989 var firstCol = Math.floor( firstX / this.columnWidth );
39990 firstCol = Math.max( 0, firstCol );
39992 var lastCol = Math.floor( lastX / this.columnWidth );
39993 // lastCol should not go over if multiple of columnWidth #425
39994 lastCol -= lastX % this.columnWidth ? 0 : 1;
39995 lastCol = Math.min( this.cols - 1, lastCol );
39997 // set colYs to bottom of the stamp
39998 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
40001 for ( var i = firstCol; i <= lastCol; i++ ) {
40002 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
40007 _getContainerSize : function()
40009 this.maxY = Math.max.apply( Math, this.colYs );
40014 if ( this.isFitWidth ) {
40015 size.width = this._getContainerFitWidth();
40021 _getContainerFitWidth : function()
40023 var unusedCols = 0;
40024 // count unused columns
40027 if ( this.colYs[i] !== 0 ) {
40032 // fit container to columns that have been used
40033 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
40036 needsResizeLayout : function()
40038 var previousWidth = this.containerWidth;
40039 this.getContainerWidth();
40040 return previousWidth !== this.containerWidth;
40055 * @class Roo.bootstrap.MasonryBrick
40056 * @extends Roo.bootstrap.Component
40057 * Bootstrap MasonryBrick class
40060 * Create a new MasonryBrick
40061 * @param {Object} config The config object
40064 Roo.bootstrap.MasonryBrick = function(config){
40066 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
40068 Roo.bootstrap.MasonryBrick.register(this);
40074 * When a MasonryBrick is clcik
40075 * @param {Roo.bootstrap.MasonryBrick} this
40076 * @param {Roo.EventObject} e
40082 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
40085 * @cfg {String} title
40089 * @cfg {String} html
40093 * @cfg {String} bgimage
40097 * @cfg {String} videourl
40101 * @cfg {String} cls
40105 * @cfg {String} href
40109 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
40114 * @cfg {String} placetitle (center|bottom)
40119 * @cfg {Boolean} isFitContainer defalut true
40121 isFitContainer : true,
40124 * @cfg {Boolean} preventDefault defalut false
40126 preventDefault : false,
40129 * @cfg {Boolean} inverse defalut false
40131 maskInverse : false,
40133 getAutoCreate : function()
40135 if(!this.isFitContainer){
40136 return this.getSplitAutoCreate();
40139 var cls = 'masonry-brick masonry-brick-full';
40141 if(this.href.length){
40142 cls += ' masonry-brick-link';
40145 if(this.bgimage.length){
40146 cls += ' masonry-brick-image';
40149 if(this.maskInverse){
40150 cls += ' mask-inverse';
40153 if(!this.html.length && !this.maskInverse && !this.videourl.length){
40154 cls += ' enable-mask';
40158 cls += ' masonry-' + this.size + '-brick';
40161 if(this.placetitle.length){
40163 switch (this.placetitle) {
40165 cls += ' masonry-center-title';
40168 cls += ' masonry-bottom-title';
40175 if(!this.html.length && !this.bgimage.length){
40176 cls += ' masonry-center-title';
40179 if(!this.html.length && this.bgimage.length){
40180 cls += ' masonry-bottom-title';
40185 cls += ' ' + this.cls;
40189 tag: (this.href.length) ? 'a' : 'div',
40194 cls: 'masonry-brick-mask'
40198 cls: 'masonry-brick-paragraph',
40204 if(this.href.length){
40205 cfg.href = this.href;
40208 var cn = cfg.cn[1].cn;
40210 if(this.title.length){
40213 cls: 'masonry-brick-title',
40218 if(this.html.length){
40221 cls: 'masonry-brick-text',
40226 if (!this.title.length && !this.html.length) {
40227 cfg.cn[1].cls += ' hide';
40230 if(this.bgimage.length){
40233 cls: 'masonry-brick-image-view',
40238 if(this.videourl.length){
40239 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
40240 // youtube support only?
40243 cls: 'masonry-brick-image-view',
40246 allowfullscreen : true
40254 getSplitAutoCreate : function()
40256 var cls = 'masonry-brick masonry-brick-split';
40258 if(this.href.length){
40259 cls += ' masonry-brick-link';
40262 if(this.bgimage.length){
40263 cls += ' masonry-brick-image';
40267 cls += ' masonry-' + this.size + '-brick';
40270 switch (this.placetitle) {
40272 cls += ' masonry-center-title';
40275 cls += ' masonry-bottom-title';
40278 if(!this.bgimage.length){
40279 cls += ' masonry-center-title';
40282 if(this.bgimage.length){
40283 cls += ' masonry-bottom-title';
40289 cls += ' ' + this.cls;
40293 tag: (this.href.length) ? 'a' : 'div',
40298 cls: 'masonry-brick-split-head',
40302 cls: 'masonry-brick-paragraph',
40309 cls: 'masonry-brick-split-body',
40315 if(this.href.length){
40316 cfg.href = this.href;
40319 if(this.title.length){
40320 cfg.cn[0].cn[0].cn.push({
40322 cls: 'masonry-brick-title',
40327 if(this.html.length){
40328 cfg.cn[1].cn.push({
40330 cls: 'masonry-brick-text',
40335 if(this.bgimage.length){
40336 cfg.cn[0].cn.push({
40338 cls: 'masonry-brick-image-view',
40343 if(this.videourl.length){
40344 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
40345 // youtube support only?
40346 cfg.cn[0].cn.cn.push({
40348 cls: 'masonry-brick-image-view',
40351 allowfullscreen : true
40358 initEvents: function()
40360 switch (this.size) {
40393 this.el.on('touchstart', this.onTouchStart, this);
40394 this.el.on('touchmove', this.onTouchMove, this);
40395 this.el.on('touchend', this.onTouchEnd, this);
40396 this.el.on('contextmenu', this.onContextMenu, this);
40398 this.el.on('mouseenter' ,this.enter, this);
40399 this.el.on('mouseleave', this.leave, this);
40400 this.el.on('click', this.onClick, this);
40403 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
40404 this.parent().bricks.push(this);
40409 onClick: function(e, el)
40411 var time = this.endTimer - this.startTimer;
40412 // Roo.log(e.preventDefault());
40415 e.preventDefault();
40420 if(!this.preventDefault){
40424 e.preventDefault();
40426 if (this.activeClass != '') {
40427 this.selectBrick();
40430 this.fireEvent('click', this, e);
40433 enter: 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.9, true);
40446 leave: function(e, el)
40448 e.preventDefault();
40450 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
40454 if(this.bgimage.length && this.html.length){
40455 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
40459 onTouchStart: function(e, el)
40461 // e.preventDefault();
40463 this.touchmoved = false;
40465 if(!this.isFitContainer){
40469 if(!this.bgimage.length || !this.html.length){
40473 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
40475 this.timer = new Date().getTime();
40479 onTouchMove: function(e, el)
40481 this.touchmoved = true;
40484 onContextMenu : function(e,el)
40486 e.preventDefault();
40487 e.stopPropagation();
40491 onTouchEnd: function(e, el)
40493 // e.preventDefault();
40495 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
40502 if(!this.bgimage.length || !this.html.length){
40504 if(this.href.length){
40505 window.location.href = this.href;
40511 if(!this.isFitContainer){
40515 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
40517 window.location.href = this.href;
40520 //selection on single brick only
40521 selectBrick : function() {
40523 if (!this.parentId) {
40527 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
40528 var index = m.selectedBrick.indexOf(this.id);
40531 m.selectedBrick.splice(index,1);
40532 this.el.removeClass(this.activeClass);
40536 for(var i = 0; i < m.selectedBrick.length; i++) {
40537 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
40538 b.el.removeClass(b.activeClass);
40541 m.selectedBrick = [];
40543 m.selectedBrick.push(this.id);
40544 this.el.addClass(this.activeClass);
40548 isSelected : function(){
40549 return this.el.hasClass(this.activeClass);
40554 Roo.apply(Roo.bootstrap.MasonryBrick, {
40557 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
40559 * register a Masonry Brick
40560 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
40563 register : function(brick)
40565 //this.groups[brick.id] = brick;
40566 this.groups.add(brick.id, brick);
40569 * fetch a masonry brick based on the masonry brick ID
40570 * @param {string} the masonry brick to add
40571 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
40574 get: function(brick_id)
40576 // if (typeof(this.groups[brick_id]) == 'undefined') {
40579 // return this.groups[brick_id] ;
40581 if(this.groups.key(brick_id)) {
40582 return this.groups.key(brick_id);
40600 * @class Roo.bootstrap.Brick
40601 * @extends Roo.bootstrap.Component
40602 * Bootstrap Brick class
40605 * Create a new Brick
40606 * @param {Object} config The config object
40609 Roo.bootstrap.Brick = function(config){
40610 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
40616 * When a Brick is click
40617 * @param {Roo.bootstrap.Brick} this
40618 * @param {Roo.EventObject} e
40624 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
40627 * @cfg {String} title
40631 * @cfg {String} html
40635 * @cfg {String} bgimage
40639 * @cfg {String} cls
40643 * @cfg {String} href
40647 * @cfg {String} video
40651 * @cfg {Boolean} square
40655 getAutoCreate : function()
40657 var cls = 'roo-brick';
40659 if(this.href.length){
40660 cls += ' roo-brick-link';
40663 if(this.bgimage.length){
40664 cls += ' roo-brick-image';
40667 if(!this.html.length && !this.bgimage.length){
40668 cls += ' roo-brick-center-title';
40671 if(!this.html.length && this.bgimage.length){
40672 cls += ' roo-brick-bottom-title';
40676 cls += ' ' + this.cls;
40680 tag: (this.href.length) ? 'a' : 'div',
40685 cls: 'roo-brick-paragraph',
40691 if(this.href.length){
40692 cfg.href = this.href;
40695 var cn = cfg.cn[0].cn;
40697 if(this.title.length){
40700 cls: 'roo-brick-title',
40705 if(this.html.length){
40708 cls: 'roo-brick-text',
40715 if(this.bgimage.length){
40718 cls: 'roo-brick-image-view',
40726 initEvents: function()
40728 if(this.title.length || this.html.length){
40729 this.el.on('mouseenter' ,this.enter, this);
40730 this.el.on('mouseleave', this.leave, this);
40733 Roo.EventManager.onWindowResize(this.resize, this);
40735 if(this.bgimage.length){
40736 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
40737 this.imageEl.on('load', this.onImageLoad, this);
40744 onImageLoad : function()
40749 resize : function()
40751 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
40753 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
40755 if(this.bgimage.length){
40756 var image = this.el.select('.roo-brick-image-view', true).first();
40758 image.setWidth(paragraph.getWidth());
40761 image.setHeight(paragraph.getWidth());
40764 this.el.setHeight(image.getHeight());
40765 paragraph.setHeight(image.getHeight());
40771 enter: function(e, el)
40773 e.preventDefault();
40775 if(this.bgimage.length){
40776 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
40777 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
40781 leave: function(e, el)
40783 e.preventDefault();
40785 if(this.bgimage.length){
40786 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
40787 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
40802 * @class Roo.bootstrap.form.NumberField
40803 * @extends Roo.bootstrap.form.Input
40804 * Bootstrap NumberField class
40810 * Create a new NumberField
40811 * @param {Object} config The config object
40814 Roo.bootstrap.form.NumberField = function(config){
40815 Roo.bootstrap.form.NumberField.superclass.constructor.call(this, config);
40818 Roo.extend(Roo.bootstrap.form.NumberField, Roo.bootstrap.form.Input, {
40821 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40823 allowDecimals : true,
40825 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40827 decimalSeparator : ".",
40829 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40831 decimalPrecision : 2,
40833 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40835 allowNegative : true,
40838 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40842 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40844 minValue : Number.NEGATIVE_INFINITY,
40846 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40848 maxValue : Number.MAX_VALUE,
40850 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40852 minText : "The minimum value for this field is {0}",
40854 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40856 maxText : "The maximum value for this field is {0}",
40858 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40859 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40861 nanText : "{0} is not a valid number",
40863 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40865 thousandsDelimiter : false,
40867 * @cfg {String} valueAlign alignment of value
40869 valueAlign : "left",
40871 getAutoCreate : function()
40873 var hiddenInput = {
40877 cls: 'hidden-number-input'
40881 hiddenInput.name = this.name;
40886 var cfg = Roo.bootstrap.form.NumberField.superclass.getAutoCreate.call(this);
40888 this.name = hiddenInput.name;
40890 if(cfg.cn.length > 0) {
40891 cfg.cn.push(hiddenInput);
40898 initEvents : function()
40900 Roo.bootstrap.form.NumberField.superclass.initEvents.call(this);
40902 var allowed = "0123456789";
40904 if(this.allowDecimals){
40905 allowed += this.decimalSeparator;
40908 if(this.allowNegative){
40912 if(this.thousandsDelimiter) {
40916 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40918 var keyPress = function(e){
40920 var k = e.getKey();
40922 var c = e.getCharCode();
40925 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40926 allowed.indexOf(String.fromCharCode(c)) === -1
40932 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40936 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40941 this.el.on("keypress", keyPress, this);
40944 validateValue : function(value)
40947 if(!Roo.bootstrap.form.NumberField.superclass.validateValue.call(this, value)){
40951 var num = this.parseValue(value);
40954 this.markInvalid(String.format(this.nanText, value));
40958 if(num < this.minValue){
40959 this.markInvalid(String.format(this.minText, this.minValue));
40963 if(num > this.maxValue){
40964 this.markInvalid(String.format(this.maxText, this.maxValue));
40971 getValue : function()
40973 var v = this.hiddenEl().getValue();
40975 return this.fixPrecision(this.parseValue(v));
40978 parseValue : function(value)
40980 if(this.thousandsDelimiter) {
40982 r = new RegExp(",", "g");
40983 value = value.replace(r, "");
40986 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
40987 return isNaN(value) ? '' : value;
40990 fixPrecision : function(value)
40992 if(this.thousandsDelimiter) {
40994 r = new RegExp(",", "g");
40995 value = value.replace(r, "");
40998 var nan = isNaN(value);
41000 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
41001 return nan ? '' : value;
41003 return parseFloat(value).toFixed(this.decimalPrecision);
41006 setValue : function(v)
41008 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
41014 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
41016 this.inputEl().dom.value = (v == '') ? '' :
41017 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
41019 if(!this.allowZero && v === '0') {
41020 this.hiddenEl().dom.value = '';
41021 this.inputEl().dom.value = '';
41028 decimalPrecisionFcn : function(v)
41030 return Math.floor(v);
41033 beforeBlur : function()
41035 var v = this.parseValue(this.getRawValue());
41037 if(v || v === 0 || v === ''){
41042 hiddenEl : function()
41044 return this.el.select('input.hidden-number-input',true).first();
41056 * @class Roo.bootstrap.DocumentSlider
41057 * @extends Roo.bootstrap.Component
41058 * Bootstrap DocumentSlider class
41061 * Create a new DocumentViewer
41062 * @param {Object} config The config object
41065 Roo.bootstrap.DocumentSlider = function(config){
41066 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
41073 * Fire after initEvent
41074 * @param {Roo.bootstrap.DocumentSlider} this
41079 * Fire after update
41080 * @param {Roo.bootstrap.DocumentSlider} this
41086 * @param {Roo.bootstrap.DocumentSlider} this
41092 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
41098 getAutoCreate : function()
41102 cls : 'roo-document-slider',
41106 cls : 'roo-document-slider-header',
41110 cls : 'roo-document-slider-header-title'
41116 cls : 'roo-document-slider-body',
41120 cls : 'roo-document-slider-prev',
41124 cls : 'fa fa-chevron-left'
41130 cls : 'roo-document-slider-thumb',
41134 cls : 'roo-document-slider-image'
41140 cls : 'roo-document-slider-next',
41144 cls : 'fa fa-chevron-right'
41156 initEvents : function()
41158 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
41159 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
41161 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
41162 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
41164 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
41165 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
41167 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
41168 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
41170 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
41171 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
41173 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
41174 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
41176 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
41177 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
41179 this.thumbEl.on('click', this.onClick, this);
41181 this.prevIndicator.on('click', this.prev, this);
41183 this.nextIndicator.on('click', this.next, this);
41187 initial : function()
41189 if(this.files.length){
41190 this.indicator = 1;
41194 this.fireEvent('initial', this);
41197 update : function()
41199 this.imageEl.attr('src', this.files[this.indicator - 1]);
41201 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
41203 this.prevIndicator.show();
41205 if(this.indicator == 1){
41206 this.prevIndicator.hide();
41209 this.nextIndicator.show();
41211 if(this.indicator == this.files.length){
41212 this.nextIndicator.hide();
41215 this.thumbEl.scrollTo('top');
41217 this.fireEvent('update', this);
41220 onClick : function(e)
41222 e.preventDefault();
41224 this.fireEvent('click', this);
41229 e.preventDefault();
41231 this.indicator = Math.max(1, this.indicator - 1);
41238 e.preventDefault();
41240 this.indicator = Math.min(this.files.length, this.indicator + 1);
41254 * @class Roo.bootstrap.form.RadioSet
41255 * @extends Roo.bootstrap.form.Input
41256 * @children Roo.bootstrap.form.Radio
41257 * Bootstrap RadioSet class
41258 * @cfg {String} indicatorpos (left|right) default left
41259 * @cfg {Boolean} inline (true|false) inline the element (default true)
41260 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
41262 * Create a new RadioSet
41263 * @param {Object} config The config object
41266 Roo.bootstrap.form.RadioSet = function(config){
41268 Roo.bootstrap.form.RadioSet.superclass.constructor.call(this, config);
41272 Roo.bootstrap.form.RadioSet.register(this);
41277 * Fires when the element is checked or unchecked.
41278 * @param {Roo.bootstrap.form.RadioSet} this This radio
41279 * @param {Roo.bootstrap.form.Radio} item The checked item
41284 * Fires when the element is click.
41285 * @param {Roo.bootstrap.form.RadioSet} this This radio set
41286 * @param {Roo.bootstrap.form.Radio} item The checked item
41287 * @param {Roo.EventObject} e The event object
41294 Roo.extend(Roo.bootstrap.form.RadioSet, Roo.bootstrap.form.Input, {
41302 indicatorpos : 'left',
41304 getAutoCreate : function()
41308 cls : 'roo-radio-set-label',
41312 html : this.fieldLabel
41316 if (Roo.bootstrap.version == 3) {
41319 if(this.indicatorpos == 'left'){
41322 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
41323 tooltip : 'This field is required'
41328 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
41329 tooltip : 'This field is required'
41335 cls : 'roo-radio-set-items'
41338 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
41340 if (align === 'left' && this.fieldLabel.length) {
41343 cls : "roo-radio-set-right",
41349 if(this.labelWidth > 12){
41350 label.style = "width: " + this.labelWidth + 'px';
41353 if(this.labelWidth < 13 && this.labelmd == 0){
41354 this.labelmd = this.labelWidth;
41357 if(this.labellg > 0){
41358 label.cls += ' col-lg-' + this.labellg;
41359 items.cls += ' col-lg-' + (12 - this.labellg);
41362 if(this.labelmd > 0){
41363 label.cls += ' col-md-' + this.labelmd;
41364 items.cls += ' col-md-' + (12 - this.labelmd);
41367 if(this.labelsm > 0){
41368 label.cls += ' col-sm-' + this.labelsm;
41369 items.cls += ' col-sm-' + (12 - this.labelsm);
41372 if(this.labelxs > 0){
41373 label.cls += ' col-xs-' + this.labelxs;
41374 items.cls += ' col-xs-' + (12 - this.labelxs);
41380 cls : 'roo-radio-set',
41384 cls : 'roo-radio-set-input',
41387 value : this.value ? this.value : ''
41394 if(this.weight.length){
41395 cfg.cls += ' roo-radio-' + this.weight;
41399 cfg.cls += ' roo-radio-set-inline';
41403 ['xs','sm','md','lg'].map(function(size){
41404 if (settings[size]) {
41405 cfg.cls += ' col-' + size + '-' + settings[size];
41413 initEvents : function()
41415 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
41416 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
41418 if(!this.fieldLabel.length){
41419 this.labelEl.hide();
41422 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
41423 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
41425 this.indicator = this.indicatorEl();
41427 if(this.indicator){
41428 this.indicator.addClass('invisible');
41431 this.originalValue = this.getValue();
41435 inputEl: function ()
41437 return this.el.select('.roo-radio-set-input', true).first();
41440 getChildContainer : function()
41442 return this.itemsEl;
41445 register : function(item)
41447 this.radioes.push(item);
41451 validate : function()
41453 if(this.getVisibilityEl().hasClass('hidden')){
41459 Roo.each(this.radioes, function(i){
41468 if(this.allowBlank) {
41472 if(this.disabled || valid){
41477 this.markInvalid();
41482 markValid : function()
41484 if(this.labelEl.isVisible(true) && this.indicatorEl()){
41485 this.indicatorEl().removeClass('visible');
41486 this.indicatorEl().addClass('invisible');
41490 if (Roo.bootstrap.version == 3) {
41491 this.el.removeClass([this.invalidClass, this.validClass]);
41492 this.el.addClass(this.validClass);
41494 this.el.removeClass(['is-invalid','is-valid']);
41495 this.el.addClass(['is-valid']);
41497 this.fireEvent('valid', this);
41500 markInvalid : function(msg)
41502 if(this.allowBlank || this.disabled){
41506 if(this.labelEl.isVisible(true) && this.indicatorEl()){
41507 this.indicatorEl().removeClass('invisible');
41508 this.indicatorEl().addClass('visible');
41510 if (Roo.bootstrap.version == 3) {
41511 this.el.removeClass([this.invalidClass, this.validClass]);
41512 this.el.addClass(this.invalidClass);
41514 this.el.removeClass(['is-invalid','is-valid']);
41515 this.el.addClass(['is-invalid']);
41518 this.fireEvent('invalid', this, msg);
41522 setValue : function(v, suppressEvent)
41524 if(this.value === v){
41531 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
41534 Roo.each(this.radioes, function(i){
41536 i.el.removeClass('checked');
41539 Roo.each(this.radioes, function(i){
41541 if(i.value === v || i.value.toString() === v.toString()){
41543 i.el.addClass('checked');
41545 if(suppressEvent !== true){
41546 this.fireEvent('check', this, i);
41557 clearInvalid : function(){
41559 if(!this.el || this.preventMark){
41563 this.el.removeClass([this.invalidClass]);
41565 this.fireEvent('valid', this);
41570 Roo.apply(Roo.bootstrap.form.RadioSet, {
41574 register : function(set)
41576 this.groups[set.name] = set;
41579 get: function(name)
41581 if (typeof(this.groups[name]) == 'undefined') {
41585 return this.groups[name] ;
41591 * Ext JS Library 1.1.1
41592 * Copyright(c) 2006-2007, Ext JS, LLC.
41594 * Originally Released Under LGPL - original licence link has changed is not relivant.
41597 * <script type="text/javascript">
41602 * @class Roo.bootstrap.SplitBar
41603 * @extends Roo.util.Observable
41604 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
41608 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
41609 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
41610 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
41611 split.minSize = 100;
41612 split.maxSize = 600;
41613 split.animate = true;
41614 split.on('moved', splitterMoved);
41617 * Create a new SplitBar
41618 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
41619 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
41620 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
41621 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
41622 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
41623 position of the SplitBar).
41625 Roo.bootstrap.SplitBar = function(cfg){
41630 // dragElement : elm
41631 // resizingElement: el,
41633 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
41634 // placement : Roo.bootstrap.SplitBar.LEFT ,
41635 // existingProxy ???
41638 this.el = Roo.get(cfg.dragElement, true);
41639 this.el.dom.unselectable = "on";
41641 this.resizingEl = Roo.get(cfg.resizingElement, true);
41645 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
41646 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
41649 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
41652 * The minimum size of the resizing element. (Defaults to 0)
41658 * The maximum size of the resizing element. (Defaults to 2000)
41661 this.maxSize = 2000;
41664 * Whether to animate the transition to the new size
41667 this.animate = false;
41670 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
41673 this.useShim = false;
41678 if(!cfg.existingProxy){
41680 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
41682 this.proxy = Roo.get(cfg.existingProxy).dom;
41685 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
41688 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
41691 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
41694 this.dragSpecs = {};
41697 * @private The adapter to use to positon and resize elements
41699 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
41700 this.adapter.init(this);
41702 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41704 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
41705 this.el.addClass("roo-splitbar-h");
41708 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
41709 this.el.addClass("roo-splitbar-v");
41715 * Fires when the splitter is moved (alias for {@link #event-moved})
41716 * @param {Roo.bootstrap.SplitBar} this
41717 * @param {Number} newSize the new width or height
41722 * Fires when the splitter is moved
41723 * @param {Roo.bootstrap.SplitBar} this
41724 * @param {Number} newSize the new width or height
41728 * @event beforeresize
41729 * Fires before the splitter is dragged
41730 * @param {Roo.bootstrap.SplitBar} this
41732 "beforeresize" : true,
41734 "beforeapply" : true
41737 Roo.util.Observable.call(this);
41740 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
41741 onStartProxyDrag : function(x, y){
41742 this.fireEvent("beforeresize", this);
41744 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
41746 o.enableDisplayMode("block");
41747 // all splitbars share the same overlay
41748 Roo.bootstrap.SplitBar.prototype.overlay = o;
41750 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
41751 this.overlay.show();
41752 Roo.get(this.proxy).setDisplayed("block");
41753 var size = this.adapter.getElementSize(this);
41754 this.activeMinSize = this.getMinimumSize();;
41755 this.activeMaxSize = this.getMaximumSize();;
41756 var c1 = size - this.activeMinSize;
41757 var c2 = Math.max(this.activeMaxSize - size, 0);
41758 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41759 this.dd.resetConstraints();
41760 this.dd.setXConstraint(
41761 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
41762 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
41764 this.dd.setYConstraint(0, 0);
41766 this.dd.resetConstraints();
41767 this.dd.setXConstraint(0, 0);
41768 this.dd.setYConstraint(
41769 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
41770 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
41773 this.dragSpecs.startSize = size;
41774 this.dragSpecs.startPoint = [x, y];
41775 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
41779 * @private Called after the drag operation by the DDProxy
41781 onEndProxyDrag : function(e){
41782 Roo.get(this.proxy).setDisplayed(false);
41783 var endPoint = Roo.lib.Event.getXY(e);
41785 this.overlay.hide();
41788 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41789 newSize = this.dragSpecs.startSize +
41790 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
41791 endPoint[0] - this.dragSpecs.startPoint[0] :
41792 this.dragSpecs.startPoint[0] - endPoint[0]
41795 newSize = this.dragSpecs.startSize +
41796 (this.placement == Roo.bootstrap.SplitBar.TOP ?
41797 endPoint[1] - this.dragSpecs.startPoint[1] :
41798 this.dragSpecs.startPoint[1] - endPoint[1]
41801 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
41802 if(newSize != this.dragSpecs.startSize){
41803 if(this.fireEvent('beforeapply', this, newSize) !== false){
41804 this.adapter.setElementSize(this, newSize);
41805 this.fireEvent("moved", this, newSize);
41806 this.fireEvent("resize", this, newSize);
41812 * Get the adapter this SplitBar uses
41813 * @return The adapter object
41815 getAdapter : function(){
41816 return this.adapter;
41820 * Set the adapter this SplitBar uses
41821 * @param {Object} adapter A SplitBar adapter object
41823 setAdapter : function(adapter){
41824 this.adapter = adapter;
41825 this.adapter.init(this);
41829 * Gets the minimum size for the resizing element
41830 * @return {Number} The minimum size
41832 getMinimumSize : function(){
41833 return this.minSize;
41837 * Sets the minimum size for the resizing element
41838 * @param {Number} minSize The minimum size
41840 setMinimumSize : function(minSize){
41841 this.minSize = minSize;
41845 * Gets the maximum size for the resizing element
41846 * @return {Number} The maximum size
41848 getMaximumSize : function(){
41849 return this.maxSize;
41853 * Sets the maximum size for the resizing element
41854 * @param {Number} maxSize The maximum size
41856 setMaximumSize : function(maxSize){
41857 this.maxSize = maxSize;
41861 * Sets the initialize size for the resizing element
41862 * @param {Number} size The initial size
41864 setCurrentSize : function(size){
41865 var oldAnimate = this.animate;
41866 this.animate = false;
41867 this.adapter.setElementSize(this, size);
41868 this.animate = oldAnimate;
41872 * Destroy this splitbar.
41873 * @param {Boolean} removeEl True to remove the element
41875 destroy : function(removeEl){
41877 this.shim.remove();
41880 this.proxy.parentNode.removeChild(this.proxy);
41888 * @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.
41890 Roo.bootstrap.SplitBar.createProxy = function(dir){
41891 var proxy = new Roo.Element(document.createElement("div"));
41892 proxy.unselectable();
41893 var cls = 'roo-splitbar-proxy';
41894 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
41895 document.body.appendChild(proxy.dom);
41900 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
41901 * Default Adapter. It assumes the splitter and resizing element are not positioned
41902 * elements and only gets/sets the width of the element. Generally used for table based layouts.
41904 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
41907 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
41908 // do nothing for now
41909 init : function(s){
41913 * Called before drag operations to get the current size of the resizing element.
41914 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
41916 getElementSize : function(s){
41917 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41918 return s.resizingEl.getWidth();
41920 return s.resizingEl.getHeight();
41925 * Called after drag operations to set the size of the resizing element.
41926 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
41927 * @param {Number} newSize The new size to set
41928 * @param {Function} onComplete A function to be invoked when resizing is complete
41930 setElementSize : function(s, newSize, onComplete){
41931 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
41933 s.resizingEl.setWidth(newSize);
41935 onComplete(s, newSize);
41938 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
41943 s.resizingEl.setHeight(newSize);
41945 onComplete(s, newSize);
41948 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
41955 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
41956 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
41957 * Adapter that moves the splitter element to align with the resized sizing element.
41958 * Used with an absolute positioned SplitBar.
41959 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
41960 * document.body, make sure you assign an id to the body element.
41962 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
41963 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
41964 this.container = Roo.get(container);
41967 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
41968 init : function(s){
41969 this.basic.init(s);
41972 getElementSize : function(s){
41973 return this.basic.getElementSize(s);
41976 setElementSize : function(s, newSize, onComplete){
41977 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
41980 moveSplitter : function(s){
41981 var yes = Roo.bootstrap.SplitBar;
41982 switch(s.placement){
41984 s.el.setX(s.resizingEl.getRight());
41987 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
41990 s.el.setY(s.resizingEl.getBottom());
41993 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
42000 * Orientation constant - Create a vertical SplitBar
42004 Roo.bootstrap.SplitBar.VERTICAL = 1;
42007 * Orientation constant - Create a horizontal SplitBar
42011 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
42014 * Placement constant - The resizing element is to the left of the splitter element
42018 Roo.bootstrap.SplitBar.LEFT = 1;
42021 * Placement constant - The resizing element is to the right of the splitter element
42025 Roo.bootstrap.SplitBar.RIGHT = 2;
42028 * Placement constant - The resizing element is positioned above the splitter element
42032 Roo.bootstrap.SplitBar.TOP = 3;
42035 * Placement constant - The resizing element is positioned under splitter element
42039 Roo.bootstrap.SplitBar.BOTTOM = 4;
42042 * Ext JS Library 1.1.1
42043 * Copyright(c) 2006-2007, Ext JS, LLC.
42045 * Originally Released Under LGPL - original licence link has changed is not relivant.
42048 * <script type="text/javascript">
42052 * @class Roo.bootstrap.layout.Manager
42053 * @extends Roo.bootstrap.Component
42055 * Base class for layout managers.
42057 Roo.bootstrap.layout.Manager = function(config)
42059 this.monitorWindowResize = true; // do this before we apply configuration.
42061 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
42067 /** false to disable window resize monitoring @type Boolean */
42073 * Fires when a layout is performed.
42074 * @param {Roo.LayoutManager} this
42078 * @event regionresized
42079 * Fires when the user resizes a region.
42080 * @param {Roo.LayoutRegion} region The resized region
42081 * @param {Number} newSize The new size (width for east/west, height for north/south)
42083 "regionresized" : true,
42085 * @event regioncollapsed
42086 * Fires when a region is collapsed.
42087 * @param {Roo.LayoutRegion} region The collapsed region
42089 "regioncollapsed" : true,
42091 * @event regionexpanded
42092 * Fires when a region is expanded.
42093 * @param {Roo.LayoutRegion} region The expanded region
42095 "regionexpanded" : true
42097 this.updating = false;
42100 this.el = Roo.get(config.el);
42106 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
42111 monitorWindowResize : true,
42117 onRender : function(ct, position)
42120 this.el = Roo.get(ct);
42123 //this.fireEvent('render',this);
42127 initEvents: function()
42131 // ie scrollbar fix
42132 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
42133 document.body.scroll = "no";
42134 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
42135 this.el.position('relative');
42137 this.id = this.el.id;
42138 this.el.addClass("roo-layout-container");
42139 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
42140 if(this.el.dom != document.body ) {
42141 this.el.on('resize', this.layout,this);
42142 this.el.on('show', this.layout,this);
42148 * Returns true if this layout is currently being updated
42149 * @return {Boolean}
42151 isUpdating : function(){
42152 return this.updating;
42156 * Suspend the LayoutManager from doing auto-layouts while
42157 * making multiple add or remove calls
42159 beginUpdate : function(){
42160 this.updating = true;
42164 * Restore auto-layouts and optionally disable the manager from performing a layout
42165 * @param {Boolean} noLayout true to disable a layout update
42167 endUpdate : function(noLayout){
42168 this.updating = false;
42174 layout: function(){
42178 onRegionResized : function(region, newSize){
42179 this.fireEvent("regionresized", region, newSize);
42183 onRegionCollapsed : function(region){
42184 this.fireEvent("regioncollapsed", region);
42187 onRegionExpanded : function(region){
42188 this.fireEvent("regionexpanded", region);
42192 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
42193 * performs box-model adjustments.
42194 * @return {Object} The size as an object {width: (the width), height: (the height)}
42196 getViewSize : function()
42199 if(this.el.dom != document.body){
42200 size = this.el.getSize();
42202 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
42204 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
42205 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
42210 * Returns the Element this layout is bound to.
42211 * @return {Roo.Element}
42213 getEl : function(){
42218 * Returns the specified region.
42219 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
42220 * @return {Roo.LayoutRegion}
42222 getRegion : function(target){
42223 return this.regions[target.toLowerCase()];
42226 onWindowResize : function(){
42227 if(this.monitorWindowResize){
42234 * Ext JS Library 1.1.1
42235 * Copyright(c) 2006-2007, Ext JS, LLC.
42237 * Originally Released Under LGPL - original licence link has changed is not relivant.
42240 * <script type="text/javascript">
42243 * @class Roo.bootstrap.layout.Border
42244 * @extends Roo.bootstrap.layout.Manager
42245 * @children Roo.bootstrap.panel.Content Roo.bootstrap.panel.Nest Roo.bootstrap.panel.Grid
42246 * @parent builder Roo.bootstrap.panel.Nest Roo.bootstrap.panel.Nest Roo.bootstrap.Modal
42247 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
42248 * please see: examples/bootstrap/nested.html<br><br>
42250 <b>The container the layout is rendered into can be either the body element or any other element.
42251 If it is not the body element, the container needs to either be an absolute positioned element,
42252 or you will need to add "position:relative" to the css of the container. You will also need to specify
42253 the container size if it is not the body element.</b>
42256 * Create a new Border
42257 * @param {Object} config Configuration options
42259 Roo.bootstrap.layout.Border = function(config){
42260 config = config || {};
42261 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
42265 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
42266 if(config[region]){
42267 config[region].region = region;
42268 this.addRegion(config[region]);
42274 Roo.bootstrap.layout.Border.regions = ["center", "north","south","east","west"];
42276 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
42279 * @cfg {Roo.bootstrap.layout.Region} center region to go in center
42282 * @cfg {Roo.bootstrap.layout.Region} west region to go in west
42285 * @cfg {Roo.bootstrap.layout.Region} east region to go in east
42288 * @cfg {Roo.bootstrap.layout.Region} south region to go in south
42291 * @cfg {Roo.bootstrap.layout.Region} north region to go in north
42297 parent : false, // this might point to a 'nest' or a ???
42300 * Creates and adds a new region if it doesn't already exist.
42301 * @param {String} target The target region key (north, south, east, west or center).
42302 * @param {Object} config The regions config object
42303 * @return {BorderLayoutRegion} The new region
42305 addRegion : function(config)
42307 if(!this.regions[config.region]){
42308 var r = this.factory(config);
42309 this.bindRegion(r);
42311 return this.regions[config.region];
42315 bindRegion : function(r){
42316 this.regions[r.config.region] = r;
42318 r.on("visibilitychange", this.layout, this);
42319 r.on("paneladded", this.layout, this);
42320 r.on("panelremoved", this.layout, this);
42321 r.on("invalidated", this.layout, this);
42322 r.on("resized", this.onRegionResized, this);
42323 r.on("collapsed", this.onRegionCollapsed, this);
42324 r.on("expanded", this.onRegionExpanded, this);
42328 * Performs a layout update.
42330 layout : function()
42332 if(this.updating) {
42336 // render all the rebions if they have not been done alreayd?
42337 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
42338 if(this.regions[region] && !this.regions[region].bodyEl){
42339 this.regions[region].onRender(this.el)
42343 var size = this.getViewSize();
42344 var w = size.width;
42345 var h = size.height;
42350 //var x = 0, y = 0;
42352 var rs = this.regions;
42353 var north = rs["north"];
42354 var south = rs["south"];
42355 var west = rs["west"];
42356 var east = rs["east"];
42357 var center = rs["center"];
42358 //if(this.hideOnLayout){ // not supported anymore
42359 //c.el.setStyle("display", "none");
42361 if(north && north.isVisible()){
42362 var b = north.getBox();
42363 var m = north.getMargins();
42364 b.width = w - (m.left+m.right);
42367 centerY = b.height + b.y + m.bottom;
42368 centerH -= centerY;
42369 north.updateBox(this.safeBox(b));
42371 if(south && south.isVisible()){
42372 var b = south.getBox();
42373 var m = south.getMargins();
42374 b.width = w - (m.left+m.right);
42376 var totalHeight = (b.height + m.top + m.bottom);
42377 b.y = h - totalHeight + m.top;
42378 centerH -= totalHeight;
42379 south.updateBox(this.safeBox(b));
42381 if(west && west.isVisible()){
42382 var b = west.getBox();
42383 var m = west.getMargins();
42384 b.height = centerH - (m.top+m.bottom);
42386 b.y = centerY + m.top;
42387 var totalWidth = (b.width + m.left + m.right);
42388 centerX += totalWidth;
42389 centerW -= totalWidth;
42390 west.updateBox(this.safeBox(b));
42392 if(east && east.isVisible()){
42393 var b = east.getBox();
42394 var m = east.getMargins();
42395 b.height = centerH - (m.top+m.bottom);
42396 var totalWidth = (b.width + m.left + m.right);
42397 b.x = w - totalWidth + m.left;
42398 b.y = centerY + m.top;
42399 centerW -= totalWidth;
42400 east.updateBox(this.safeBox(b));
42403 var m = center.getMargins();
42405 x: centerX + m.left,
42406 y: centerY + m.top,
42407 width: centerW - (m.left+m.right),
42408 height: centerH - (m.top+m.bottom)
42410 //if(this.hideOnLayout){
42411 //center.el.setStyle("display", "block");
42413 center.updateBox(this.safeBox(centerBox));
42416 this.fireEvent("layout", this);
42420 safeBox : function(box){
42421 box.width = Math.max(0, box.width);
42422 box.height = Math.max(0, box.height);
42427 * Adds a ContentPanel (or subclass) to this layout.
42428 * @param {String} target The target region key (north, south, east, west or center).
42429 * @param {Roo.ContentPanel} panel The panel to add
42430 * @return {Roo.ContentPanel} The added panel
42432 add : function(target, panel){
42434 target = target.toLowerCase();
42435 return this.regions[target].add(panel);
42439 * Remove a ContentPanel (or subclass) to this layout.
42440 * @param {String} target The target region key (north, south, east, west or center).
42441 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
42442 * @return {Roo.ContentPanel} The removed panel
42444 remove : function(target, panel){
42445 target = target.toLowerCase();
42446 return this.regions[target].remove(panel);
42450 * Searches all regions for a panel with the specified id
42451 * @param {String} panelId
42452 * @return {Roo.ContentPanel} The panel or null if it wasn't found
42454 findPanel : function(panelId){
42455 var rs = this.regions;
42456 for(var target in rs){
42457 if(typeof rs[target] != "function"){
42458 var p = rs[target].getPanel(panelId);
42468 * Searches all regions for a panel with the specified id and activates (shows) it.
42469 * @param {String/ContentPanel} panelId The panels id or the panel itself
42470 * @return {Roo.ContentPanel} The shown panel or null
42472 showPanel : function(panelId) {
42473 var rs = this.regions;
42474 for(var target in rs){
42475 var r = rs[target];
42476 if(typeof r != "function"){
42477 if(r.hasPanel(panelId)){
42478 return r.showPanel(panelId);
42486 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
42487 * @param {Roo.state.Provider} provider (optional) An alternate state provider
42490 restoreState : function(provider){
42492 provider = Roo.state.Manager;
42494 var sm = new Roo.LayoutStateManager();
42495 sm.init(this, provider);
42501 * Adds a xtype elements to the layout.
42505 xtype : 'ContentPanel',
42512 xtype : 'NestedLayoutPanel',
42518 items : [ ... list of content panels or nested layout panels.. ]
42522 * @param {Object} cfg Xtype definition of item to add.
42524 addxtype : function(cfg)
42526 // basically accepts a pannel...
42527 // can accept a layout region..!?!?
42528 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
42531 // theory? children can only be panels??
42533 //if (!cfg.xtype.match(/Panel$/)) {
42538 if (typeof(cfg.region) == 'undefined') {
42539 Roo.log("Failed to add Panel, region was not set");
42543 var region = cfg.region;
42549 xitems = cfg.items;
42554 if ( region == 'center') {
42555 Roo.log("Center: " + cfg.title);
42561 case 'Content': // ContentPanel (el, cfg)
42562 case 'Scroll': // ContentPanel (el, cfg)
42564 cfg.autoCreate = cfg.autoCreate || true;
42565 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
42567 // var el = this.el.createChild();
42568 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
42571 this.add(region, ret);
42575 case 'TreePanel': // our new panel!
42576 cfg.el = this.el.createChild();
42577 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
42578 this.add(region, ret);
42583 // create a new Layout (which is a Border Layout...
42585 var clayout = cfg.layout;
42586 clayout.el = this.el.createChild();
42587 clayout.items = clayout.items || [];
42591 // replace this exitems with the clayout ones..
42592 xitems = clayout.items;
42594 // force background off if it's in center...
42595 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
42596 cfg.background = false;
42598 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
42601 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
42602 //console.log('adding nested layout panel ' + cfg.toSource());
42603 this.add(region, ret);
42604 nb = {}; /// find first...
42609 // needs grid and region
42611 //var el = this.getRegion(region).el.createChild();
42613 *var el = this.el.createChild();
42614 // create the grid first...
42615 cfg.grid.container = el;
42616 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
42619 if (region == 'center' && this.active ) {
42620 cfg.background = false;
42623 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
42625 this.add(region, ret);
42627 if (cfg.background) {
42628 // render grid on panel activation (if panel background)
42629 ret.on('activate', function(gp) {
42630 if (!gp.grid.rendered) {
42631 // gp.grid.render(el);
42635 // cfg.grid.render(el);
42641 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
42642 // it was the old xcomponent building that caused this before.
42643 // espeically if border is the top element in the tree.
42653 if (typeof(Roo[cfg.xtype]) != 'undefined') {
42655 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
42656 this.add(region, ret);
42660 throw "Can not add '" + cfg.xtype + "' to Border";
42666 this.beginUpdate();
42670 Roo.each(xitems, function(i) {
42671 region = nb && i.region ? i.region : false;
42673 var add = ret.addxtype(i);
42676 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
42677 if (!i.background) {
42678 abn[region] = nb[region] ;
42685 // make the last non-background panel active..
42686 //if (nb) { Roo.log(abn); }
42689 for(var r in abn) {
42690 region = this.getRegion(r);
42692 // tried using nb[r], but it does not work..
42694 region.showPanel(abn[r]);
42705 factory : function(cfg)
42708 var validRegions = Roo.bootstrap.layout.Border.regions;
42710 var target = cfg.region;
42713 var r = Roo.bootstrap.layout;
42717 return new r.North(cfg);
42719 return new r.South(cfg);
42721 return new r.East(cfg);
42723 return new r.West(cfg);
42725 return new r.Center(cfg);
42727 throw 'Layout region "'+target+'" not supported.';
42734 * Ext JS Library 1.1.1
42735 * Copyright(c) 2006-2007, Ext JS, LLC.
42737 * Originally Released Under LGPL - original licence link has changed is not relivant.
42740 * <script type="text/javascript">
42744 * @class Roo.bootstrap.layout.Basic
42745 * @extends Roo.util.Observable
42746 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
42747 * and does not have a titlebar, tabs or any other features. All it does is size and position
42748 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
42749 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
42750 * @cfg {string} region the region that it inhabits..
42751 * @cfg {bool} skipConfig skip config?
42755 Roo.bootstrap.layout.Basic = function(config){
42757 this.mgr = config.mgr;
42759 this.position = config.region;
42761 var skipConfig = config.skipConfig;
42765 * @scope Roo.BasicLayoutRegion
42769 * @event beforeremove
42770 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
42771 * @param {Roo.LayoutRegion} this
42772 * @param {Roo.ContentPanel} panel The panel
42773 * @param {Object} e The cancel event object
42775 "beforeremove" : true,
42777 * @event invalidated
42778 * Fires when the layout for this region is changed.
42779 * @param {Roo.LayoutRegion} this
42781 "invalidated" : true,
42783 * @event visibilitychange
42784 * Fires when this region is shown or hidden
42785 * @param {Roo.LayoutRegion} this
42786 * @param {Boolean} visibility true or false
42788 "visibilitychange" : true,
42790 * @event paneladded
42791 * Fires when a panel is added.
42792 * @param {Roo.LayoutRegion} this
42793 * @param {Roo.ContentPanel} panel The panel
42795 "paneladded" : true,
42797 * @event panelremoved
42798 * Fires when a panel is removed.
42799 * @param {Roo.LayoutRegion} this
42800 * @param {Roo.ContentPanel} panel The panel
42802 "panelremoved" : true,
42804 * @event beforecollapse
42805 * Fires when this region before collapse.
42806 * @param {Roo.LayoutRegion} this
42808 "beforecollapse" : true,
42811 * Fires when this region is collapsed.
42812 * @param {Roo.LayoutRegion} this
42814 "collapsed" : true,
42817 * Fires when this region is expanded.
42818 * @param {Roo.LayoutRegion} this
42823 * Fires when this region is slid into view.
42824 * @param {Roo.LayoutRegion} this
42826 "slideshow" : true,
42829 * Fires when this region slides out of view.
42830 * @param {Roo.LayoutRegion} this
42832 "slidehide" : true,
42834 * @event panelactivated
42835 * Fires when a panel is activated.
42836 * @param {Roo.LayoutRegion} this
42837 * @param {Roo.ContentPanel} panel The activated panel
42839 "panelactivated" : true,
42842 * Fires when the user resizes this region.
42843 * @param {Roo.LayoutRegion} this
42844 * @param {Number} newSize The new size (width for east/west, height for north/south)
42848 /** A collection of panels in this region. @type Roo.util.MixedCollection */
42849 this.panels = new Roo.util.MixedCollection();
42850 this.panels.getKey = this.getPanelId.createDelegate(this);
42852 this.activePanel = null;
42853 // ensure listeners are added...
42855 if (config.listeners || config.events) {
42856 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
42857 listeners : config.listeners || {},
42858 events : config.events || {}
42862 if(skipConfig !== true){
42863 this.applyConfig(config);
42867 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
42869 getPanelId : function(p){
42873 applyConfig : function(config){
42874 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
42875 this.config = config;
42880 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
42881 * the width, for horizontal (north, south) the height.
42882 * @param {Number} newSize The new width or height
42884 resizeTo : function(newSize){
42885 var el = this.el ? this.el :
42886 (this.activePanel ? this.activePanel.getEl() : null);
42888 switch(this.position){
42891 el.setWidth(newSize);
42892 this.fireEvent("resized", this, newSize);
42896 el.setHeight(newSize);
42897 this.fireEvent("resized", this, newSize);
42903 getBox : function(){
42904 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
42907 getMargins : function(){
42908 return this.margins;
42911 updateBox : function(box){
42913 var el = this.activePanel.getEl();
42914 el.dom.style.left = box.x + "px";
42915 el.dom.style.top = box.y + "px";
42916 this.activePanel.setSize(box.width, box.height);
42920 * Returns the container element for this region.
42921 * @return {Roo.Element}
42923 getEl : function(){
42924 return this.activePanel;
42928 * Returns true if this region is currently visible.
42929 * @return {Boolean}
42931 isVisible : function(){
42932 return this.activePanel ? true : false;
42935 setActivePanel : function(panel){
42936 panel = this.getPanel(panel);
42937 if(this.activePanel && this.activePanel != panel){
42938 this.activePanel.setActiveState(false);
42939 this.activePanel.getEl().setLeftTop(-10000,-10000);
42941 this.activePanel = panel;
42942 panel.setActiveState(true);
42944 panel.setSize(this.box.width, this.box.height);
42946 this.fireEvent("panelactivated", this, panel);
42947 this.fireEvent("invalidated");
42951 * Show the specified panel.
42952 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
42953 * @return {Roo.ContentPanel} The shown panel or null
42955 showPanel : function(panel){
42956 panel = this.getPanel(panel);
42958 this.setActivePanel(panel);
42964 * Get the active panel for this region.
42965 * @return {Roo.ContentPanel} The active panel or null
42967 getActivePanel : function(){
42968 return this.activePanel;
42972 * Add the passed ContentPanel(s)
42973 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
42974 * @return {Roo.ContentPanel} The panel added (if only one was added)
42976 add : function(panel){
42977 if(arguments.length > 1){
42978 for(var i = 0, len = arguments.length; i < len; i++) {
42979 this.add(arguments[i]);
42983 if(this.hasPanel(panel)){
42984 this.showPanel(panel);
42987 var el = panel.getEl();
42988 if(el.dom.parentNode != this.mgr.el.dom){
42989 this.mgr.el.dom.appendChild(el.dom);
42991 if(panel.setRegion){
42992 panel.setRegion(this);
42994 this.panels.add(panel);
42995 el.setStyle("position", "absolute");
42996 if(!panel.background){
42997 this.setActivePanel(panel);
42998 if(this.config.initialSize && this.panels.getCount()==1){
42999 this.resizeTo(this.config.initialSize);
43002 this.fireEvent("paneladded", this, panel);
43007 * Returns true if the panel is in this region.
43008 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43009 * @return {Boolean}
43011 hasPanel : function(panel){
43012 if(typeof panel == "object"){ // must be panel obj
43013 panel = panel.getId();
43015 return this.getPanel(panel) ? true : false;
43019 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
43020 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43021 * @param {Boolean} preservePanel Overrides the config preservePanel option
43022 * @return {Roo.ContentPanel} The panel that was removed
43024 remove : function(panel, preservePanel){
43025 panel = this.getPanel(panel);
43030 this.fireEvent("beforeremove", this, panel, e);
43031 if(e.cancel === true){
43034 var panelId = panel.getId();
43035 this.panels.removeKey(panelId);
43040 * Returns the panel specified or null if it's not in this region.
43041 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
43042 * @return {Roo.ContentPanel}
43044 getPanel : function(id){
43045 if(typeof id == "object"){ // must be panel obj
43048 return this.panels.get(id);
43052 * Returns this regions position (north/south/east/west/center).
43055 getPosition: function(){
43056 return this.position;
43060 * Ext JS Library 1.1.1
43061 * Copyright(c) 2006-2007, Ext JS, LLC.
43063 * Originally Released Under LGPL - original licence link has changed is not relivant.
43066 * <script type="text/javascript">
43070 * @class Roo.bootstrap.layout.Region
43071 * @extends Roo.bootstrap.layout.Basic
43072 * This class represents a region in a layout manager.
43074 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
43075 * @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})
43076 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
43077 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
43078 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
43079 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
43080 * @cfg {String} title The title for the region (overrides panel titles)
43081 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
43082 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
43083 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
43084 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
43085 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
43086 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
43087 * the space available, similar to FireFox 1.5 tabs (defaults to false)
43088 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
43089 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
43090 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
43092 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
43093 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
43094 * @cfg {Boolean} disableTabTips True to disable tab tooltips
43095 * @cfg {Number} width For East/West panels
43096 * @cfg {Number} height For North/South panels
43097 * @cfg {Boolean} split To show the splitter
43098 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
43100 * @cfg {string} cls Extra CSS classes to add to region
43102 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
43103 * @cfg {string} region the region that it inhabits..
43106 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
43107 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
43109 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
43110 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
43111 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
43113 Roo.bootstrap.layout.Region = function(config)
43115 this.applyConfig(config);
43117 var mgr = config.mgr;
43118 var pos = config.region;
43119 config.skipConfig = true;
43120 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
43123 this.onRender(mgr.el);
43126 this.visible = true;
43127 this.collapsed = false;
43128 this.unrendered_panels = [];
43131 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
43133 position: '', // set by wrapper (eg. north/south etc..)
43134 unrendered_panels : null, // unrendered panels.
43136 tabPosition : false,
43138 mgr: false, // points to 'Border'
43141 createBody : function(){
43142 /** This region's body element
43143 * @type Roo.Element */
43144 this.bodyEl = this.el.createChild({
43146 cls: "roo-layout-panel-body tab-content" // bootstrap added...
43150 onRender: function(ctr, pos)
43152 var dh = Roo.DomHelper;
43153 /** This region's container element
43154 * @type Roo.Element */
43155 this.el = dh.append(ctr.dom, {
43157 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
43159 /** This region's title element
43160 * @type Roo.Element */
43162 this.titleEl = dh.append(this.el.dom, {
43164 unselectable: "on",
43165 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
43167 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
43168 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
43172 this.titleEl.enableDisplayMode();
43173 /** This region's title text element
43174 * @type HTMLElement */
43175 this.titleTextEl = this.titleEl.dom.firstChild;
43176 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
43178 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
43179 this.closeBtn.enableDisplayMode();
43180 this.closeBtn.on("click", this.closeClicked, this);
43181 this.closeBtn.hide();
43183 this.createBody(this.config);
43184 if(this.config.hideWhenEmpty){
43186 this.on("paneladded", this.validateVisibility, this);
43187 this.on("panelremoved", this.validateVisibility, this);
43189 if(this.autoScroll){
43190 this.bodyEl.setStyle("overflow", "auto");
43192 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
43194 //if(c.titlebar !== false){
43195 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
43196 this.titleEl.hide();
43198 this.titleEl.show();
43199 if(this.config.title){
43200 this.titleTextEl.innerHTML = this.config.title;
43204 if(this.config.collapsed){
43205 this.collapse(true);
43207 if(this.config.hidden){
43211 if (this.unrendered_panels && this.unrendered_panels.length) {
43212 for (var i =0;i< this.unrendered_panels.length; i++) {
43213 this.add(this.unrendered_panels[i]);
43215 this.unrendered_panels = null;
43221 applyConfig : function(c)
43224 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
43225 var dh = Roo.DomHelper;
43226 if(c.titlebar !== false){
43227 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
43228 this.collapseBtn.on("click", this.collapse, this);
43229 this.collapseBtn.enableDisplayMode();
43231 if(c.showPin === true || this.showPin){
43232 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
43233 this.stickBtn.enableDisplayMode();
43234 this.stickBtn.on("click", this.expand, this);
43235 this.stickBtn.hide();
43240 /** This region's collapsed element
43241 * @type Roo.Element */
43244 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
43245 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
43248 if(c.floatable !== false){
43249 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
43250 this.collapsedEl.on("click", this.collapseClick, this);
43253 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
43254 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
43255 id: "message", unselectable: "on", style:{"float":"left"}});
43256 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
43258 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
43259 this.expandBtn.on("click", this.expand, this);
43263 if(this.collapseBtn){
43264 this.collapseBtn.setVisible(c.collapsible == true);
43267 this.cmargins = c.cmargins || this.cmargins ||
43268 (this.position == "west" || this.position == "east" ?
43269 {top: 0, left: 2, right:2, bottom: 0} :
43270 {top: 2, left: 0, right:0, bottom: 2});
43272 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
43275 this.tabPosition = [ 'top','bottom', 'west'].indexOf(c.tabPosition) > -1 ? c.tabPosition : "top";
43277 this.autoScroll = c.autoScroll || false;
43282 this.duration = c.duration || .30;
43283 this.slideDuration = c.slideDuration || .45;
43288 * Returns true if this region is currently visible.
43289 * @return {Boolean}
43291 isVisible : function(){
43292 return this.visible;
43296 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
43297 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
43299 //setCollapsedTitle : function(title){
43300 // title = title || " ";
43301 // if(this.collapsedTitleTextEl){
43302 // this.collapsedTitleTextEl.innerHTML = title;
43306 getBox : function(){
43308 // if(!this.collapsed){
43309 b = this.el.getBox(false, true);
43311 // b = this.collapsedEl.getBox(false, true);
43316 getMargins : function(){
43317 return this.margins;
43318 //return this.collapsed ? this.cmargins : this.margins;
43321 highlight : function(){
43322 this.el.addClass("x-layout-panel-dragover");
43325 unhighlight : function(){
43326 this.el.removeClass("x-layout-panel-dragover");
43329 updateBox : function(box)
43331 if (!this.bodyEl) {
43332 return; // not rendered yet..
43336 if(!this.collapsed){
43337 this.el.dom.style.left = box.x + "px";
43338 this.el.dom.style.top = box.y + "px";
43339 this.updateBody(box.width, box.height);
43341 this.collapsedEl.dom.style.left = box.x + "px";
43342 this.collapsedEl.dom.style.top = box.y + "px";
43343 this.collapsedEl.setSize(box.width, box.height);
43346 this.tabs.autoSizeTabs();
43350 updateBody : function(w, h)
43353 this.el.setWidth(w);
43354 w -= this.el.getBorderWidth("rl");
43355 if(this.config.adjustments){
43356 w += this.config.adjustments[0];
43359 if(h !== null && h > 0){
43360 this.el.setHeight(h);
43361 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
43362 h -= this.el.getBorderWidth("tb");
43363 if(this.config.adjustments){
43364 h += this.config.adjustments[1];
43366 this.bodyEl.setHeight(h);
43368 h = this.tabs.syncHeight(h);
43371 if(this.panelSize){
43372 w = w !== null ? w : this.panelSize.width;
43373 h = h !== null ? h : this.panelSize.height;
43375 if(this.activePanel){
43376 var el = this.activePanel.getEl();
43377 w = w !== null ? w : el.getWidth();
43378 h = h !== null ? h : el.getHeight();
43379 this.panelSize = {width: w, height: h};
43380 this.activePanel.setSize(w, h);
43382 if(Roo.isIE && this.tabs){
43383 this.tabs.el.repaint();
43388 * Returns the container element for this region.
43389 * @return {Roo.Element}
43391 getEl : function(){
43396 * Hides this region.
43399 //if(!this.collapsed){
43400 this.el.dom.style.left = "-2000px";
43403 // this.collapsedEl.dom.style.left = "-2000px";
43404 // this.collapsedEl.hide();
43406 this.visible = false;
43407 this.fireEvent("visibilitychange", this, false);
43411 * Shows this region if it was previously hidden.
43414 //if(!this.collapsed){
43417 // this.collapsedEl.show();
43419 this.visible = true;
43420 this.fireEvent("visibilitychange", this, true);
43423 closeClicked : function(){
43424 if(this.activePanel){
43425 this.remove(this.activePanel);
43429 collapseClick : function(e){
43431 e.stopPropagation();
43434 e.stopPropagation();
43440 * Collapses this region.
43441 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
43444 collapse : function(skipAnim, skipCheck = false){
43445 if(this.collapsed) {
43449 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
43451 this.collapsed = true;
43453 this.split.el.hide();
43455 if(this.config.animate && skipAnim !== true){
43456 this.fireEvent("invalidated", this);
43457 this.animateCollapse();
43459 this.el.setLocation(-20000,-20000);
43461 this.collapsedEl.show();
43462 this.fireEvent("collapsed", this);
43463 this.fireEvent("invalidated", this);
43469 animateCollapse : function(){
43474 * Expands this region if it was previously collapsed.
43475 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
43476 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
43479 expand : function(e, skipAnim){
43481 e.stopPropagation();
43483 if(!this.collapsed || this.el.hasActiveFx()) {
43487 this.afterSlideIn();
43490 this.collapsed = false;
43491 if(this.config.animate && skipAnim !== true){
43492 this.animateExpand();
43496 this.split.el.show();
43498 this.collapsedEl.setLocation(-2000,-2000);
43499 this.collapsedEl.hide();
43500 this.fireEvent("invalidated", this);
43501 this.fireEvent("expanded", this);
43505 animateExpand : function(){
43509 initTabs : function()
43511 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
43513 var ts = new Roo.bootstrap.panel.Tabs({
43514 el: this.bodyEl.dom,
43516 tabPosition: this.tabPosition ? this.tabPosition : 'top',
43517 disableTooltips: this.config.disableTabTips,
43518 toolbar : this.config.toolbar
43521 if(this.config.hideTabs){
43522 ts.stripWrap.setDisplayed(false);
43525 ts.resizeTabs = this.config.resizeTabs === true;
43526 ts.minTabWidth = this.config.minTabWidth || 40;
43527 ts.maxTabWidth = this.config.maxTabWidth || 250;
43528 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
43529 ts.monitorResize = false;
43530 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
43531 ts.bodyEl.addClass('roo-layout-tabs-body');
43532 this.panels.each(this.initPanelAsTab, this);
43535 initPanelAsTab : function(panel){
43536 var ti = this.tabs.addTab(
43540 this.config.closeOnTab && panel.isClosable(),
43543 if(panel.tabTip !== undefined){
43544 ti.setTooltip(panel.tabTip);
43546 ti.on("activate", function(){
43547 this.setActivePanel(panel);
43550 if(this.config.closeOnTab){
43551 ti.on("beforeclose", function(t, e){
43553 this.remove(panel);
43557 panel.tabItem = ti;
43562 updatePanelTitle : function(panel, title)
43564 if(this.activePanel == panel){
43565 this.updateTitle(title);
43568 var ti = this.tabs.getTab(panel.getEl().id);
43570 if(panel.tabTip !== undefined){
43571 ti.setTooltip(panel.tabTip);
43576 updateTitle : function(title){
43577 if(this.titleTextEl && !this.config.title){
43578 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
43582 setActivePanel : function(panel)
43584 panel = this.getPanel(panel);
43585 if(this.activePanel && this.activePanel != panel){
43586 if(this.activePanel.setActiveState(false) === false){
43590 this.activePanel = panel;
43591 panel.setActiveState(true);
43592 if(this.panelSize){
43593 panel.setSize(this.panelSize.width, this.panelSize.height);
43596 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
43598 this.updateTitle(panel.getTitle());
43600 this.fireEvent("invalidated", this);
43602 this.fireEvent("panelactivated", this, panel);
43606 * Shows the specified panel.
43607 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
43608 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
43610 showPanel : function(panel)
43612 panel = this.getPanel(panel);
43615 var tab = this.tabs.getTab(panel.getEl().id);
43616 if(tab.isHidden()){
43617 this.tabs.unhideTab(tab.id);
43621 this.setActivePanel(panel);
43628 * Get the active panel for this region.
43629 * @return {Roo.ContentPanel} The active panel or null
43631 getActivePanel : function(){
43632 return this.activePanel;
43635 validateVisibility : function(){
43636 if(this.panels.getCount() < 1){
43637 this.updateTitle(" ");
43638 this.closeBtn.hide();
43641 if(!this.isVisible()){
43648 * Adds the passed ContentPanel(s) to this region.
43649 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
43650 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
43652 add : function(panel)
43654 if(arguments.length > 1){
43655 for(var i = 0, len = arguments.length; i < len; i++) {
43656 this.add(arguments[i]);
43661 // if we have not been rendered yet, then we can not really do much of this..
43662 if (!this.bodyEl) {
43663 this.unrendered_panels.push(panel);
43670 if(this.hasPanel(panel)){
43671 this.showPanel(panel);
43674 panel.setRegion(this);
43675 this.panels.add(panel);
43676 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
43677 // sinle panel - no tab...?? would it not be better to render it with the tabs,
43678 // and hide them... ???
43679 this.bodyEl.dom.appendChild(panel.getEl().dom);
43680 if(panel.background !== true){
43681 this.setActivePanel(panel);
43683 this.fireEvent("paneladded", this, panel);
43690 this.initPanelAsTab(panel);
43694 if(panel.background !== true){
43695 this.tabs.activate(panel.getEl().id);
43697 this.fireEvent("paneladded", this, panel);
43702 * Hides the tab for the specified panel.
43703 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
43705 hidePanel : function(panel){
43706 if(this.tabs && (panel = this.getPanel(panel))){
43707 this.tabs.hideTab(panel.getEl().id);
43712 * Unhides the tab for a previously hidden panel.
43713 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
43715 unhidePanel : function(panel){
43716 if(this.tabs && (panel = this.getPanel(panel))){
43717 this.tabs.unhideTab(panel.getEl().id);
43721 clearPanels : function(){
43722 while(this.panels.getCount() > 0){
43723 this.remove(this.panels.first());
43728 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
43729 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
43730 * @param {Boolean} preservePanel Overrides the config preservePanel option
43731 * @return {Roo.ContentPanel} The panel that was removed
43733 remove : function(panel, preservePanel)
43735 panel = this.getPanel(panel);
43740 this.fireEvent("beforeremove", this, panel, e);
43741 if(e.cancel === true){
43744 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
43745 var panelId = panel.getId();
43746 this.panels.removeKey(panelId);
43748 document.body.appendChild(panel.getEl().dom);
43751 this.tabs.removeTab(panel.getEl().id);
43752 }else if (!preservePanel){
43753 this.bodyEl.dom.removeChild(panel.getEl().dom);
43755 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
43756 var p = this.panels.first();
43757 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
43758 tempEl.appendChild(p.getEl().dom);
43759 this.bodyEl.update("");
43760 this.bodyEl.dom.appendChild(p.getEl().dom);
43762 this.updateTitle(p.getTitle());
43764 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
43765 this.setActivePanel(p);
43767 panel.setRegion(null);
43768 if(this.activePanel == panel){
43769 this.activePanel = null;
43771 if(this.config.autoDestroy !== false && preservePanel !== true){
43772 try{panel.destroy();}catch(e){}
43774 this.fireEvent("panelremoved", this, panel);
43779 * Returns the TabPanel component used by this region
43780 * @return {Roo.TabPanel}
43782 getTabs : function(){
43786 createTool : function(parentEl, className){
43787 var btn = Roo.DomHelper.append(parentEl, {
43789 cls: "x-layout-tools-button",
43792 cls: "roo-layout-tools-button-inner " + className,
43796 btn.addClassOnOver("roo-layout-tools-button-over");
43801 * Ext JS Library 1.1.1
43802 * Copyright(c) 2006-2007, Ext JS, LLC.
43804 * Originally Released Under LGPL - original licence link has changed is not relivant.
43807 * <script type="text/javascript">
43813 * @class Roo.SplitLayoutRegion
43814 * @extends Roo.LayoutRegion
43815 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
43817 Roo.bootstrap.layout.Split = function(config){
43818 this.cursor = config.cursor;
43819 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
43822 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
43824 splitTip : "Drag to resize.",
43825 collapsibleSplitTip : "Drag to resize. Double click to hide.",
43826 useSplitTips : false,
43828 applyConfig : function(config){
43829 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
43832 onRender : function(ctr,pos) {
43834 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
43835 if(!this.config.split){
43840 var splitEl = Roo.DomHelper.append(ctr.dom, {
43842 id: this.el.id + "-split",
43843 cls: "roo-layout-split roo-layout-split-"+this.position,
43846 /** The SplitBar for this region
43847 * @type Roo.SplitBar */
43848 // does not exist yet...
43849 Roo.log([this.position, this.orientation]);
43851 this.split = new Roo.bootstrap.SplitBar({
43852 dragElement : splitEl,
43853 resizingElement: this.el,
43854 orientation : this.orientation
43857 this.split.on("moved", this.onSplitMove, this);
43858 this.split.useShim = this.config.useShim === true;
43859 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
43860 if(this.useSplitTips){
43861 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
43863 //if(config.collapsible){
43864 // this.split.el.on("dblclick", this.collapse, this);
43867 if(typeof this.config.minSize != "undefined"){
43868 this.split.minSize = this.config.minSize;
43870 if(typeof this.config.maxSize != "undefined"){
43871 this.split.maxSize = this.config.maxSize;
43873 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
43874 this.hideSplitter();
43879 getHMaxSize : function(){
43880 var cmax = this.config.maxSize || 10000;
43881 var center = this.mgr.getRegion("center");
43882 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
43885 getVMaxSize : function(){
43886 var cmax = this.config.maxSize || 10000;
43887 var center = this.mgr.getRegion("center");
43888 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
43891 onSplitMove : function(split, newSize){
43892 this.fireEvent("resized", this, newSize);
43896 * Returns the {@link Roo.SplitBar} for this region.
43897 * @return {Roo.SplitBar}
43899 getSplitBar : function(){
43904 this.hideSplitter();
43905 Roo.bootstrap.layout.Split.superclass.hide.call(this);
43908 hideSplitter : function(){
43910 this.split.el.setLocation(-2000,-2000);
43911 this.split.el.hide();
43917 this.split.el.show();
43919 Roo.bootstrap.layout.Split.superclass.show.call(this);
43922 beforeSlide: function(){
43923 if(Roo.isGecko){// firefox overflow auto bug workaround
43924 this.bodyEl.clip();
43926 this.tabs.bodyEl.clip();
43928 if(this.activePanel){
43929 this.activePanel.getEl().clip();
43931 if(this.activePanel.beforeSlide){
43932 this.activePanel.beforeSlide();
43938 afterSlide : function(){
43939 if(Roo.isGecko){// firefox overflow auto bug workaround
43940 this.bodyEl.unclip();
43942 this.tabs.bodyEl.unclip();
43944 if(this.activePanel){
43945 this.activePanel.getEl().unclip();
43946 if(this.activePanel.afterSlide){
43947 this.activePanel.afterSlide();
43953 initAutoHide : function(){
43954 if(this.autoHide !== false){
43955 if(!this.autoHideHd){
43956 var st = new Roo.util.DelayedTask(this.slideIn, this);
43957 this.autoHideHd = {
43958 "mouseout": function(e){
43959 if(!e.within(this.el, true)){
43963 "mouseover" : function(e){
43969 this.el.on(this.autoHideHd);
43973 clearAutoHide : function(){
43974 if(this.autoHide !== false){
43975 this.el.un("mouseout", this.autoHideHd.mouseout);
43976 this.el.un("mouseover", this.autoHideHd.mouseover);
43980 clearMonitor : function(){
43981 Roo.get(document).un("click", this.slideInIf, this);
43984 // these names are backwards but not changed for compat
43985 slideOut : function(){
43986 if(this.isSlid || this.el.hasActiveFx()){
43989 this.isSlid = true;
43990 if(this.collapseBtn){
43991 this.collapseBtn.hide();
43993 this.closeBtnState = this.closeBtn.getStyle('display');
43994 this.closeBtn.hide();
43996 this.stickBtn.show();
43999 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
44000 this.beforeSlide();
44001 this.el.setStyle("z-index", 10001);
44002 this.el.slideIn(this.getSlideAnchor(), {
44003 callback: function(){
44005 this.initAutoHide();
44006 Roo.get(document).on("click", this.slideInIf, this);
44007 this.fireEvent("slideshow", this);
44014 afterSlideIn : function(){
44015 this.clearAutoHide();
44016 this.isSlid = false;
44017 this.clearMonitor();
44018 this.el.setStyle("z-index", "");
44019 if(this.collapseBtn){
44020 this.collapseBtn.show();
44022 this.closeBtn.setStyle('display', this.closeBtnState);
44024 this.stickBtn.hide();
44026 this.fireEvent("slidehide", this);
44029 slideIn : function(cb){
44030 if(!this.isSlid || this.el.hasActiveFx()){
44034 this.isSlid = false;
44035 this.beforeSlide();
44036 this.el.slideOut(this.getSlideAnchor(), {
44037 callback: function(){
44038 this.el.setLeftTop(-10000, -10000);
44040 this.afterSlideIn();
44048 slideInIf : function(e){
44049 if(!e.within(this.el)){
44054 animateCollapse : function(){
44055 this.beforeSlide();
44056 this.el.setStyle("z-index", 20000);
44057 var anchor = this.getSlideAnchor();
44058 this.el.slideOut(anchor, {
44059 callback : function(){
44060 this.el.setStyle("z-index", "");
44061 this.collapsedEl.slideIn(anchor, {duration:.3});
44063 this.el.setLocation(-10000,-10000);
44065 this.fireEvent("collapsed", this);
44072 animateExpand : function(){
44073 this.beforeSlide();
44074 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
44075 this.el.setStyle("z-index", 20000);
44076 this.collapsedEl.hide({
44079 this.el.slideIn(this.getSlideAnchor(), {
44080 callback : function(){
44081 this.el.setStyle("z-index", "");
44084 this.split.el.show();
44086 this.fireEvent("invalidated", this);
44087 this.fireEvent("expanded", this);
44115 getAnchor : function(){
44116 return this.anchors[this.position];
44119 getCollapseAnchor : function(){
44120 return this.canchors[this.position];
44123 getSlideAnchor : function(){
44124 return this.sanchors[this.position];
44127 getAlignAdj : function(){
44128 var cm = this.cmargins;
44129 switch(this.position){
44145 getExpandAdj : function(){
44146 var c = this.collapsedEl, cm = this.cmargins;
44147 switch(this.position){
44149 return [-(cm.right+c.getWidth()+cm.left), 0];
44152 return [cm.right+c.getWidth()+cm.left, 0];
44155 return [0, -(cm.top+cm.bottom+c.getHeight())];
44158 return [0, cm.top+cm.bottom+c.getHeight()];
44164 * Ext JS Library 1.1.1
44165 * Copyright(c) 2006-2007, Ext JS, LLC.
44167 * Originally Released Under LGPL - original licence link has changed is not relivant.
44170 * <script type="text/javascript">
44173 * These classes are private internal classes
44175 Roo.bootstrap.layout.Center = function(config){
44176 config.region = "center";
44177 Roo.bootstrap.layout.Region.call(this, config);
44178 this.visible = true;
44179 this.minWidth = config.minWidth || 20;
44180 this.minHeight = config.minHeight || 20;
44183 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
44185 // center panel can't be hidden
44189 // center panel can't be hidden
44192 getMinWidth: function(){
44193 return this.minWidth;
44196 getMinHeight: function(){
44197 return this.minHeight;
44211 Roo.bootstrap.layout.North = function(config)
44213 config.region = 'north';
44214 config.cursor = 'n-resize';
44216 Roo.bootstrap.layout.Split.call(this, config);
44220 this.split.placement = Roo.bootstrap.SplitBar.TOP;
44221 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
44222 this.split.el.addClass("roo-layout-split-v");
44224 //var size = config.initialSize || config.height;
44225 //if(this.el && typeof size != "undefined"){
44226 // this.el.setHeight(size);
44229 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
44231 orientation: Roo.bootstrap.SplitBar.VERTICAL,
44234 onRender : function(ctr, pos)
44236 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
44237 var size = this.config.initialSize || this.config.height;
44238 if(this.el && typeof size != "undefined"){
44239 this.el.setHeight(size);
44244 getBox : function(){
44245 if(this.collapsed){
44246 return this.collapsedEl.getBox();
44248 var box = this.el.getBox();
44250 box.height += this.split.el.getHeight();
44255 updateBox : function(box){
44256 if(this.split && !this.collapsed){
44257 box.height -= this.split.el.getHeight();
44258 this.split.el.setLeft(box.x);
44259 this.split.el.setTop(box.y+box.height);
44260 this.split.el.setWidth(box.width);
44262 if(this.collapsed){
44263 this.updateBody(box.width, null);
44265 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44273 Roo.bootstrap.layout.South = function(config){
44274 config.region = 'south';
44275 config.cursor = 's-resize';
44276 Roo.bootstrap.layout.Split.call(this, config);
44278 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
44279 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
44280 this.split.el.addClass("roo-layout-split-v");
44285 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
44286 orientation: Roo.bootstrap.SplitBar.VERTICAL,
44288 onRender : function(ctr, pos)
44290 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
44291 var size = this.config.initialSize || this.config.height;
44292 if(this.el && typeof size != "undefined"){
44293 this.el.setHeight(size);
44298 getBox : function(){
44299 if(this.collapsed){
44300 return this.collapsedEl.getBox();
44302 var box = this.el.getBox();
44304 var sh = this.split.el.getHeight();
44311 updateBox : function(box){
44312 if(this.split && !this.collapsed){
44313 var sh = this.split.el.getHeight();
44316 this.split.el.setLeft(box.x);
44317 this.split.el.setTop(box.y-sh);
44318 this.split.el.setWidth(box.width);
44320 if(this.collapsed){
44321 this.updateBody(box.width, null);
44323 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44327 Roo.bootstrap.layout.East = function(config){
44328 config.region = "east";
44329 config.cursor = "e-resize";
44330 Roo.bootstrap.layout.Split.call(this, config);
44332 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
44333 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
44334 this.split.el.addClass("roo-layout-split-h");
44338 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
44339 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
44341 onRender : function(ctr, pos)
44343 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
44344 var size = this.config.initialSize || this.config.width;
44345 if(this.el && typeof size != "undefined"){
44346 this.el.setWidth(size);
44351 getBox : function(){
44352 if(this.collapsed){
44353 return this.collapsedEl.getBox();
44355 var box = this.el.getBox();
44357 var sw = this.split.el.getWidth();
44364 updateBox : function(box){
44365 if(this.split && !this.collapsed){
44366 var sw = this.split.el.getWidth();
44368 this.split.el.setLeft(box.x);
44369 this.split.el.setTop(box.y);
44370 this.split.el.setHeight(box.height);
44373 if(this.collapsed){
44374 this.updateBody(null, box.height);
44376 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44380 Roo.bootstrap.layout.West = function(config){
44381 config.region = "west";
44382 config.cursor = "w-resize";
44384 Roo.bootstrap.layout.Split.call(this, config);
44386 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
44387 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
44388 this.split.el.addClass("roo-layout-split-h");
44392 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
44393 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
44395 onRender: function(ctr, pos)
44397 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
44398 var size = this.config.initialSize || this.config.width;
44399 if(typeof size != "undefined"){
44400 this.el.setWidth(size);
44404 getBox : function(){
44405 if(this.collapsed){
44406 return this.collapsedEl.getBox();
44408 var box = this.el.getBox();
44409 if (box.width == 0) {
44410 box.width = this.config.width; // kludge?
44413 box.width += this.split.el.getWidth();
44418 updateBox : function(box){
44419 if(this.split && !this.collapsed){
44420 var sw = this.split.el.getWidth();
44422 this.split.el.setLeft(box.x+box.width);
44423 this.split.el.setTop(box.y);
44424 this.split.el.setHeight(box.height);
44426 if(this.collapsed){
44427 this.updateBody(null, box.height);
44429 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
44433 * Ext JS Library 1.1.1
44434 * Copyright(c) 2006-2007, Ext JS, LLC.
44436 * Originally Released Under LGPL - original licence link has changed is not relivant.
44439 * <script type="text/javascript">
44442 * @class Roo.bootstrap.paenl.Content
44443 * @extends Roo.util.Observable
44444 * @children Roo.bootstrap.Component
44445 * @parent builder Roo.bootstrap.layout.Border
44446 * A basic ContentPanel element. - a panel that contain any content (eg. forms etc.)
44447 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
44448 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
44449 * @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
44450 * @cfg {Boolean} closable True if the panel can be closed/removed
44451 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
44452 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
44453 * @cfg {Toolbar} toolbar A toolbar for this panel
44454 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
44455 * @cfg {String} title The title for this panel
44456 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
44457 * @cfg {String} url Calls {@link #setUrl} with this value
44458 * @cfg {String} region [required] (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
44459 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
44460 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
44461 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
44462 * @cfg {Boolean} iframe contents are an iframe - makes showing remote sources/CSS feasible..
44463 * @cfg {Boolean} badges render the badges
44464 * @cfg {String} cls extra classes to use
44465 * @cfg {String} background (primary|secondary|success|info|warning|danger|light|dark)
44468 * Create a new ContentPanel.
44469 * @param {String/Object} config A string to set only the title or a config object
44472 Roo.bootstrap.panel.Content = function( config){
44474 this.tpl = config.tpl || false;
44476 var el = config.el;
44477 var content = config.content;
44479 if(config.autoCreate){ // xtype is available if this is called from factory
44482 this.el = Roo.get(el);
44483 if(!this.el && config && config.autoCreate){
44484 if(typeof config.autoCreate == "object"){
44485 if(!config.autoCreate.id){
44486 config.autoCreate.id = config.id||el;
44488 this.el = Roo.DomHelper.append(document.body,
44489 config.autoCreate, true);
44493 cls: (config.cls || '') +
44494 (config.background ? ' bg-' + config.background : '') +
44495 " roo-layout-inactive-content",
44498 if (config.iframe) {
44502 style : 'border: 0px',
44503 src : 'about:blank'
44509 elcfg.html = config.html;
44513 this.el = Roo.DomHelper.append(document.body, elcfg , true);
44514 if (config.iframe) {
44515 this.iframeEl = this.el.select('iframe',true).first();
44520 this.closable = false;
44521 this.loaded = false;
44522 this.active = false;
44525 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
44527 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
44529 this.wrapEl = this.el; //this.el.wrap();
44531 if (config.toolbar.items) {
44532 ti = config.toolbar.items ;
44533 delete config.toolbar.items ;
44537 this.toolbar.render(this.wrapEl, 'before');
44538 for(var i =0;i < ti.length;i++) {
44539 // Roo.log(['add child', items[i]]);
44540 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
44542 this.toolbar.items = nitems;
44543 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
44544 delete config.toolbar;
44548 // xtype created footer. - not sure if will work as we normally have to render first..
44549 if (this.footer && !this.footer.el && this.footer.xtype) {
44550 if (!this.wrapEl) {
44551 this.wrapEl = this.el.wrap();
44554 this.footer.container = this.wrapEl.createChild();
44556 this.footer = Roo.factory(this.footer, Roo);
44561 if(typeof config == "string"){
44562 this.title = config;
44564 Roo.apply(this, config);
44568 this.resizeEl = Roo.get(this.resizeEl, true);
44570 this.resizeEl = this.el;
44572 // handle view.xtype
44580 * Fires when this panel is activated.
44581 * @param {Roo.ContentPanel} this
44585 * @event deactivate
44586 * Fires when this panel is activated.
44587 * @param {Roo.ContentPanel} this
44589 "deactivate" : true,
44593 * Fires when this panel is resized if fitToFrame is true.
44594 * @param {Roo.ContentPanel} this
44595 * @param {Number} width The width after any component adjustments
44596 * @param {Number} height The height after any component adjustments
44602 * Fires when this tab is created
44603 * @param {Roo.ContentPanel} this
44609 * Fires when this content is scrolled
44610 * @param {Roo.ContentPanel} this
44611 * @param {Event} scrollEvent
44622 if(this.autoScroll && !this.iframe){
44623 this.resizeEl.setStyle("overflow", "auto");
44624 this.resizeEl.on('scroll', this.onScroll, this);
44626 // fix randome scrolling
44627 //this.el.on('scroll', function() {
44628 // Roo.log('fix random scolling');
44629 // this.scrollTo('top',0);
44632 content = content || this.content;
44634 this.setContent(content);
44636 if(config && config.url){
44637 this.setUrl(this.url, this.params, this.loadOnce);
44642 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
44644 if (this.view && typeof(this.view.xtype) != 'undefined') {
44645 this.view.el = this.el.appendChild(document.createElement("div"));
44646 this.view = Roo.factory(this.view);
44647 this.view.render && this.view.render(false, '');
44651 this.fireEvent('render', this);
44654 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
44664 /* Resize Element - use this to work out scroll etc. */
44667 setRegion : function(region){
44668 this.region = region;
44669 this.setActiveClass(region && !this.background);
44673 setActiveClass: function(state)
44676 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
44677 this.el.setStyle('position','relative');
44679 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
44680 this.el.setStyle('position', 'absolute');
44685 * Returns the toolbar for this Panel if one was configured.
44686 * @return {Roo.Toolbar}
44688 getToolbar : function(){
44689 return this.toolbar;
44692 setActiveState : function(active)
44694 this.active = active;
44695 this.setActiveClass(active);
44697 if(this.fireEvent("deactivate", this) === false){
44702 this.fireEvent("activate", this);
44706 * Updates this panel's element (not for iframe)
44707 * @param {String} content The new content
44708 * @param {Boolean} loadScripts (optional) true to look for and process scripts
44710 setContent : function(content, loadScripts){
44715 this.el.update(content, loadScripts);
44718 ignoreResize : function(w, h)
44720 //return false; // always resize?
44721 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
44724 this.lastSize = {width: w, height: h};
44729 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
44730 * @return {Roo.UpdateManager} The UpdateManager
44732 getUpdateManager : function(){
44736 return this.el.getUpdateManager();
44739 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
44740 * Does not work with IFRAME contents
44741 * @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:
44744 url: "your-url.php",
44745 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
44746 callback: yourFunction,
44747 scope: yourObject, //(optional scope)
44750 text: "Loading...",
44756 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
44757 * 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.
44758 * @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}
44759 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
44760 * @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.
44761 * @return {Roo.ContentPanel} this
44769 var um = this.el.getUpdateManager();
44770 um.update.apply(um, arguments);
44776 * 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.
44777 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
44778 * @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)
44779 * @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)
44780 * @return {Roo.UpdateManager|Boolean} The UpdateManager or false if IFRAME
44782 setUrl : function(url, params, loadOnce){
44784 this.iframeEl.dom.src = url;
44788 if(this.refreshDelegate){
44789 this.removeListener("activate", this.refreshDelegate);
44791 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
44792 this.on("activate", this.refreshDelegate);
44793 return this.el.getUpdateManager();
44796 _handleRefresh : function(url, params, loadOnce){
44797 if(!loadOnce || !this.loaded){
44798 var updater = this.el.getUpdateManager();
44799 updater.update(url, params, this._setLoaded.createDelegate(this));
44803 _setLoaded : function(){
44804 this.loaded = true;
44808 * Returns this panel's id
44811 getId : function(){
44816 * Returns this panel's element - used by regiosn to add.
44817 * @return {Roo.Element}
44819 getEl : function(){
44820 return this.wrapEl || this.el;
44825 adjustForComponents : function(width, height)
44827 //Roo.log('adjustForComponents ');
44828 if(this.resizeEl != this.el){
44829 width -= this.el.getFrameWidth('lr');
44830 height -= this.el.getFrameWidth('tb');
44833 var te = this.toolbar.getEl();
44834 te.setWidth(width);
44835 height -= te.getHeight();
44838 var te = this.footer.getEl();
44839 te.setWidth(width);
44840 height -= te.getHeight();
44844 if(this.adjustments){
44845 width += this.adjustments[0];
44846 height += this.adjustments[1];
44848 return {"width": width, "height": height};
44851 setSize : function(width, height){
44852 if(this.fitToFrame && !this.ignoreResize(width, height)){
44853 if(this.fitContainer && this.resizeEl != this.el){
44854 this.el.setSize(width, height);
44856 var size = this.adjustForComponents(width, height);
44858 this.iframeEl.setSize(width,height);
44861 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
44862 this.fireEvent('resize', this, size.width, size.height);
44869 * Returns this panel's title
44872 getTitle : function(){
44874 if (typeof(this.title) != 'object') {
44879 for (var k in this.title) {
44880 if (!this.title.hasOwnProperty(k)) {
44884 if (k.indexOf('-') >= 0) {
44885 var s = k.split('-');
44886 for (var i = 0; i<s.length; i++) {
44887 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
44890 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
44897 * Set this panel's title
44898 * @param {String} title
44900 setTitle : function(title){
44901 this.title = title;
44903 this.region.updatePanelTitle(this, title);
44908 * Returns true is this panel was configured to be closable
44909 * @return {Boolean}
44911 isClosable : function(){
44912 return this.closable;
44915 beforeSlide : function(){
44917 this.resizeEl.clip();
44920 afterSlide : function(){
44922 this.resizeEl.unclip();
44926 * Force a content refresh from the URL specified in the {@link #setUrl} method.
44927 * Will fail silently if the {@link #setUrl} method has not been called.
44928 * This does not activate the panel, just updates its content.
44930 refresh : function(){
44931 if(this.refreshDelegate){
44932 this.loaded = false;
44933 this.refreshDelegate();
44938 * Destroys this panel
44940 destroy : function(){
44941 this.el.removeAllListeners();
44942 var tempEl = document.createElement("span");
44943 tempEl.appendChild(this.el.dom);
44944 tempEl.innerHTML = "";
44950 * form - if the content panel contains a form - this is a reference to it.
44951 * @type {Roo.form.Form}
44955 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
44956 * This contains a reference to it.
44962 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
44972 * @param {Object} cfg Xtype definition of item to add.
44976 getChildContainer: function () {
44977 return this.getEl();
44981 onScroll : function(e)
44983 this.fireEvent('scroll', this, e);
44988 var ret = new Roo.factory(cfg);
44993 if (cfg.xtype.match(/^Form$/)) {
44996 //if (this.footer) {
44997 // el = this.footer.container.insertSibling(false, 'before');
44999 el = this.el.createChild();
45002 this.form = new Roo.form.Form(cfg);
45005 if ( this.form.allItems.length) {
45006 this.form.render(el.dom);
45010 // should only have one of theses..
45011 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
45012 // views.. should not be just added - used named prop 'view''
45014 cfg.el = this.el.appendChild(document.createElement("div"));
45017 var ret = new Roo.factory(cfg);
45019 ret.render && ret.render(false, ''); // render blank..
45029 * @class Roo.bootstrap.panel.Grid
45030 * @extends Roo.bootstrap.panel.Content
45032 * Create a new GridPanel.
45033 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
45034 * @cfg {Roo.bootstrap.nav.Simplebar} toolbar the toolbar at the top of the grid.
45035 * @param {Object} config A the config object
45041 Roo.bootstrap.panel.Grid = function(config)
45045 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
45046 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
45048 config.el = this.wrapper;
45049 //this.el = this.wrapper;
45051 if (config.container) {
45052 // ctor'ed from a Border/panel.grid
45055 this.wrapper.setStyle("overflow", "hidden");
45056 this.wrapper.addClass('roo-grid-container');
45061 if(config.toolbar){
45062 var tool_el = this.wrapper.createChild();
45063 this.toolbar = Roo.factory(config.toolbar);
45065 if (config.toolbar.items) {
45066 ti = config.toolbar.items ;
45067 delete config.toolbar.items ;
45071 this.toolbar.render(tool_el);
45072 for(var i =0;i < ti.length;i++) {
45073 // Roo.log(['add child', items[i]]);
45074 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
45076 this.toolbar.items = nitems;
45078 delete config.toolbar;
45081 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
45082 config.grid.scrollBody = true;;
45083 config.grid.monitorWindowResize = false; // turn off autosizing
45084 config.grid.autoHeight = false;
45085 config.grid.autoWidth = false;
45087 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
45089 if (config.background) {
45090 // render grid on panel activation (if panel background)
45091 this.on('activate', function(gp) {
45092 if (!gp.grid.rendered) {
45093 gp.grid.render(this.wrapper);
45094 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
45099 this.grid.render(this.wrapper);
45100 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
45103 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
45104 // ??? needed ??? config.el = this.wrapper;
45109 // xtype created footer. - not sure if will work as we normally have to render first..
45110 if (this.footer && !this.footer.el && this.footer.xtype) {
45112 var ctr = this.grid.getView().getFooterPanel(true);
45113 this.footer.dataSource = this.grid.dataSource;
45114 this.footer = Roo.factory(this.footer, Roo);
45115 this.footer.render(ctr);
45125 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content,
45128 getId : function(){
45129 return this.grid.id;
45133 * Returns the grid for this panel
45134 * @return {Roo.bootstrap.Table}
45136 getGrid : function(){
45140 setSize : function(width, height)
45143 //if(!this.ignoreResize(width, height)){
45144 var grid = this.grid;
45145 var size = this.adjustForComponents(width, height);
45146 // tfoot is not a footer?
45149 var gridel = grid.getGridEl();
45150 gridel.setSize(size.width, size.height);
45152 var tbd = grid.getGridEl().select('tbody', true).first();
45153 var thd = grid.getGridEl().select('thead',true).first();
45154 var tbf= grid.getGridEl().select('tfoot', true).first();
45157 size.height -= tbf.getHeight();
45160 size.height -= thd.getHeight();
45163 tbd.setSize(size.width, size.height );
45164 // this is for the account management tab -seems to work there.
45165 var thd = grid.getGridEl().select('thead',true).first();
45167 // tbd.setSize(size.width, size.height - thd.getHeight());
45177 beforeSlide : function(){
45178 this.grid.getView().scroller.clip();
45181 afterSlide : function(){
45182 this.grid.getView().scroller.unclip();
45185 destroy : function(){
45186 this.grid.destroy();
45188 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
45193 * @class Roo.bootstrap.panel.Nest
45194 * @extends Roo.bootstrap.panel.Content
45196 * Create a new Panel, that can contain a layout.Border.
45199 * @param {String/Object} config A string to set only the title or a config object
45201 Roo.bootstrap.panel.Nest = function(config)
45203 // construct with only one argument..
45204 /* FIXME - implement nicer consturctors
45205 if (layout.layout) {
45207 layout = config.layout;
45208 delete config.layout;
45210 if (layout.xtype && !layout.getEl) {
45211 // then layout needs constructing..
45212 layout = Roo.factory(layout, Roo);
45216 config.el = config.layout.getEl();
45218 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
45220 config.layout.monitorWindowResize = false; // turn off autosizing
45221 this.layout = config.layout;
45222 this.layout.getEl().addClass("roo-layout-nested-layout");
45223 this.layout.parent = this;
45230 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
45232 * @cfg {Roo.BorderLayout} layout The layout for this panel
45236 setSize : function(width, height){
45237 if(!this.ignoreResize(width, height)){
45238 var size = this.adjustForComponents(width, height);
45239 var el = this.layout.getEl();
45240 if (size.height < 1) {
45241 el.setWidth(size.width);
45243 el.setSize(size.width, size.height);
45245 var touch = el.dom.offsetWidth;
45246 this.layout.layout();
45247 // ie requires a double layout on the first pass
45248 if(Roo.isIE && !this.initialized){
45249 this.initialized = true;
45250 this.layout.layout();
45255 // activate all subpanels if not currently active..
45257 setActiveState : function(active){
45258 this.active = active;
45259 this.setActiveClass(active);
45262 this.fireEvent("deactivate", this);
45266 this.fireEvent("activate", this);
45267 // not sure if this should happen before or after..
45268 if (!this.layout) {
45269 return; // should not happen..
45272 for (var r in this.layout.regions) {
45273 reg = this.layout.getRegion(r);
45274 if (reg.getActivePanel()) {
45275 //reg.showPanel(reg.getActivePanel()); // force it to activate..
45276 reg.setActivePanel(reg.getActivePanel());
45279 if (!reg.panels.length) {
45282 reg.showPanel(reg.getPanel(0));
45291 * Returns the nested BorderLayout for this panel
45292 * @return {Roo.BorderLayout}
45294 getLayout : function(){
45295 return this.layout;
45299 * Adds a xtype elements to the layout of the nested panel
45303 xtype : 'ContentPanel',
45310 xtype : 'NestedLayoutPanel',
45316 items : [ ... list of content panels or nested layout panels.. ]
45320 * @param {Object} cfg Xtype definition of item to add.
45322 addxtype : function(cfg) {
45323 return this.layout.addxtype(cfg);
45328 * Ext JS Library 1.1.1
45329 * Copyright(c) 2006-2007, Ext JS, LLC.
45331 * Originally Released Under LGPL - original licence link has changed is not relivant.
45334 * <script type="text/javascript">
45337 * @class Roo.TabPanel
45338 * @extends Roo.util.Observable
45339 * A lightweight tab container.
45343 // basic tabs 1, built from existing content
45344 var tabs = new Roo.TabPanel("tabs1");
45345 tabs.addTab("script", "View Script");
45346 tabs.addTab("markup", "View Markup");
45347 tabs.activate("script");
45349 // more advanced tabs, built from javascript
45350 var jtabs = new Roo.TabPanel("jtabs");
45351 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
45353 // set up the UpdateManager
45354 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
45355 var updater = tab2.getUpdateManager();
45356 updater.setDefaultUrl("ajax1.htm");
45357 tab2.on('activate', updater.refresh, updater, true);
45359 // Use setUrl for Ajax loading
45360 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
45361 tab3.setUrl("ajax2.htm", null, true);
45364 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
45367 jtabs.activate("jtabs-1");
45370 * Create a new TabPanel.
45371 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
45372 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
45374 Roo.bootstrap.panel.Tabs = function(config){
45376 * The container element for this TabPanel.
45377 * @type Roo.Element
45379 this.el = Roo.get(config.el);
45382 if(typeof config == "boolean"){
45383 this.tabPosition = config ? "bottom" : "top";
45385 Roo.apply(this, config);
45389 if(this.tabPosition == "bottom"){
45390 // if tabs are at the bottom = create the body first.
45391 this.bodyEl = Roo.get(this.createBody(this.el.dom));
45392 this.el.addClass("roo-tabs-bottom");
45394 // next create the tabs holders
45396 if (this.tabPosition == "west"){
45398 var reg = this.region; // fake it..
45400 if (!reg.mgr.parent) {
45403 reg = reg.mgr.parent.region;
45405 Roo.log("got nest?");
45407 if (reg.mgr.getRegion('west')) {
45408 var ctrdom = reg.mgr.getRegion('west').bodyEl.dom;
45409 this.stripWrap = Roo.get(this.createStrip(ctrdom ), true);
45410 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
45411 this.stripEl.setVisibilityMode(Roo.Element.DISPLAY);
45412 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
45420 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
45421 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
45422 this.stripEl.setVisibilityMode(Roo.Element.DISPLAY);
45423 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
45428 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
45431 // finally - if tabs are at the top, then create the body last..
45432 if(this.tabPosition != "bottom"){
45433 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
45434 * @type Roo.Element
45436 this.bodyEl = Roo.get(this.createBody(this.el.dom));
45437 this.el.addClass("roo-tabs-top");
45441 this.bodyEl.setStyle("position", "relative");
45443 this.active = null;
45444 this.activateDelegate = this.activate.createDelegate(this);
45449 * Fires when the active tab changes
45450 * @param {Roo.TabPanel} this
45451 * @param {Roo.TabPanelItem} activePanel The new active tab
45455 * @event beforetabchange
45456 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
45457 * @param {Roo.TabPanel} this
45458 * @param {Object} e Set cancel to true on this object to cancel the tab change
45459 * @param {Roo.TabPanelItem} tab The tab being changed to
45461 "beforetabchange" : true
45464 Roo.EventManager.onWindowResize(this.onResize, this);
45465 this.cpad = this.el.getPadding("lr");
45466 this.hiddenCount = 0;
45469 // toolbar on the tabbar support...
45470 if (this.toolbar) {
45471 alert("no toolbar support yet");
45472 this.toolbar = false;
45474 var tcfg = this.toolbar;
45475 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
45476 this.toolbar = new Roo.Toolbar(tcfg);
45477 if (Roo.isSafari) {
45478 var tbl = tcfg.container.child('table', true);
45479 tbl.setAttribute('width', '100%');
45487 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
45490 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
45492 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
45494 tabPosition : "top",
45496 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
45498 currentTabWidth : 0,
45500 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
45504 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
45508 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
45510 preferredTabWidth : 175,
45512 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
45514 resizeTabs : false,
45516 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
45518 monitorResize : true,
45520 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
45522 toolbar : false, // set by caller..
45524 region : false, /// set by caller
45526 disableTooltips : true, // not used yet...
45529 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
45530 * @param {String} id The id of the div to use <b>or create</b>
45531 * @param {String} text The text for the tab
45532 * @param {String} content (optional) Content to put in the TabPanelItem body
45533 * @param {Boolean} closable (optional) True to create a close icon on the tab
45534 * @return {Roo.TabPanelItem} The created TabPanelItem
45536 addTab : function(id, text, content, closable, tpl)
45538 var item = new Roo.bootstrap.panel.TabItem({
45542 closable : closable,
45545 this.addTabItem(item);
45547 item.setContent(content);
45553 * Returns the {@link Roo.TabPanelItem} with the specified id/index
45554 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
45555 * @return {Roo.TabPanelItem}
45557 getTab : function(id){
45558 return this.items[id];
45562 * Hides the {@link Roo.TabPanelItem} with the specified id/index
45563 * @param {String/Number} id The id or index of the TabPanelItem to hide.
45565 hideTab : function(id){
45566 var t = this.items[id];
45569 this.hiddenCount++;
45570 this.autoSizeTabs();
45575 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
45576 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
45578 unhideTab : function(id){
45579 var t = this.items[id];
45581 t.setHidden(false);
45582 this.hiddenCount--;
45583 this.autoSizeTabs();
45588 * Adds an existing {@link Roo.TabPanelItem}.
45589 * @param {Roo.TabPanelItem} item The TabPanelItem to add
45591 addTabItem : function(item)
45593 this.items[item.id] = item;
45594 this.items.push(item);
45595 this.autoSizeTabs();
45596 // if(this.resizeTabs){
45597 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
45598 // this.autoSizeTabs();
45600 // item.autoSize();
45605 * Removes a {@link Roo.TabPanelItem}.
45606 * @param {String/Number} id The id or index of the TabPanelItem to remove.
45608 removeTab : function(id){
45609 var items = this.items;
45610 var tab = items[id];
45611 if(!tab) { return; }
45612 var index = items.indexOf(tab);
45613 if(this.active == tab && items.length > 1){
45614 var newTab = this.getNextAvailable(index);
45619 this.stripEl.dom.removeChild(tab.pnode.dom);
45620 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
45621 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
45623 items.splice(index, 1);
45624 delete this.items[tab.id];
45625 tab.fireEvent("close", tab);
45626 tab.purgeListeners();
45627 this.autoSizeTabs();
45630 getNextAvailable : function(start){
45631 var items = this.items;
45633 // look for a next tab that will slide over to
45634 // replace the one being removed
45635 while(index < items.length){
45636 var item = items[++index];
45637 if(item && !item.isHidden()){
45641 // if one isn't found select the previous tab (on the left)
45644 var item = items[--index];
45645 if(item && !item.isHidden()){
45653 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
45654 * @param {String/Number} id The id or index of the TabPanelItem to disable.
45656 disableTab : function(id){
45657 var tab = this.items[id];
45658 if(tab && this.active != tab){
45664 * Enables a {@link Roo.TabPanelItem} that is disabled.
45665 * @param {String/Number} id The id or index of the TabPanelItem to enable.
45667 enableTab : function(id){
45668 var tab = this.items[id];
45673 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
45674 * @param {String/Number} id The id or index of the TabPanelItem to activate.
45675 * @return {Roo.TabPanelItem} The TabPanelItem.
45677 activate : function(id)
45679 //Roo.log('activite:' + id);
45681 var tab = this.items[id];
45685 if(tab == this.active || tab.disabled){
45689 this.fireEvent("beforetabchange", this, e, tab);
45690 if(e.cancel !== true && !tab.disabled){
45692 this.active.hide();
45694 this.active = this.items[id];
45695 this.active.show();
45696 this.fireEvent("tabchange", this, this.active);
45702 * Gets the active {@link Roo.TabPanelItem}.
45703 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
45705 getActiveTab : function(){
45706 return this.active;
45710 * Updates the tab body element to fit the height of the container element
45711 * for overflow scrolling
45712 * @param {Number} targetHeight (optional) Override the starting height from the elements height
45714 syncHeight : function(targetHeight){
45715 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
45716 var bm = this.bodyEl.getMargins();
45717 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
45718 this.bodyEl.setHeight(newHeight);
45722 onResize : function(){
45723 if(this.monitorResize){
45724 this.autoSizeTabs();
45729 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
45731 beginUpdate : function(){
45732 this.updating = true;
45736 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
45738 endUpdate : function(){
45739 this.updating = false;
45740 this.autoSizeTabs();
45744 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
45746 autoSizeTabs : function()
45748 var count = this.items.length;
45749 var vcount = count - this.hiddenCount;
45752 this.stripEl.hide();
45754 this.stripEl.show();
45757 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
45762 var w = Math.max(this.el.getWidth() - this.cpad, 10);
45763 var availWidth = Math.floor(w / vcount);
45764 var b = this.stripBody;
45765 if(b.getWidth() > w){
45766 var tabs = this.items;
45767 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
45768 if(availWidth < this.minTabWidth){
45769 /*if(!this.sleft){ // incomplete scrolling code
45770 this.createScrollButtons();
45773 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
45776 if(this.currentTabWidth < this.preferredTabWidth){
45777 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
45783 * Returns the number of tabs in this TabPanel.
45786 getCount : function(){
45787 return this.items.length;
45791 * Resizes all the tabs to the passed width
45792 * @param {Number} The new width
45794 setTabWidth : function(width){
45795 this.currentTabWidth = width;
45796 for(var i = 0, len = this.items.length; i < len; i++) {
45797 if(!this.items[i].isHidden()) {
45798 this.items[i].setWidth(width);
45804 * Destroys this TabPanel
45805 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
45807 destroy : function(removeEl){
45808 Roo.EventManager.removeResizeListener(this.onResize, this);
45809 for(var i = 0, len = this.items.length; i < len; i++){
45810 this.items[i].purgeListeners();
45812 if(removeEl === true){
45813 this.el.update("");
45818 createStrip : function(container)
45820 var strip = document.createElement("nav");
45821 strip.className = Roo.bootstrap.version == 4 ?
45822 "navbar-light bg-light" :
45823 "navbar navbar-default"; //"x-tabs-wrap";
45824 container.appendChild(strip);
45828 createStripList : function(strip)
45830 // div wrapper for retard IE
45831 // returns the "tr" element.
45832 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
45833 //'<div class="x-tabs-strip-wrap">'+
45834 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
45835 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
45836 return strip.firstChild; //.firstChild.firstChild.firstChild;
45838 createBody : function(container)
45840 var body = document.createElement("div");
45841 Roo.id(body, "tab-body");
45842 //Roo.fly(body).addClass("x-tabs-body");
45843 Roo.fly(body).addClass("tab-content");
45844 container.appendChild(body);
45847 createItemBody :function(bodyEl, id){
45848 var body = Roo.getDom(id);
45850 body = document.createElement("div");
45853 //Roo.fly(body).addClass("x-tabs-item-body");
45854 Roo.fly(body).addClass("tab-pane");
45855 bodyEl.insertBefore(body, bodyEl.firstChild);
45859 createStripElements : function(stripEl, text, closable, tpl)
45861 var td = document.createElement("li"); // was td..
45862 td.className = 'nav-item';
45864 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
45867 stripEl.appendChild(td);
45869 td.className = "x-tabs-closable";
45870 if(!this.closeTpl){
45871 this.closeTpl = new Roo.Template(
45872 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
45873 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
45874 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
45877 var el = this.closeTpl.overwrite(td, {"text": text});
45878 var close = el.getElementsByTagName("div")[0];
45879 var inner = el.getElementsByTagName("em")[0];
45880 return {"el": el, "close": close, "inner": inner};
45883 // not sure what this is..
45884 // if(!this.tabTpl){
45885 //this.tabTpl = new Roo.Template(
45886 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
45887 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
45889 // this.tabTpl = new Roo.Template(
45890 // '<a href="#">' +
45891 // '<span unselectable="on"' +
45892 // (this.disableTooltips ? '' : ' title="{text}"') +
45893 // ' >{text}</span></a>'
45899 var template = tpl || this.tabTpl || false;
45902 template = new Roo.Template(
45903 Roo.bootstrap.version == 4 ?
45905 '<a class="nav-link" href="#" unselectable="on"' +
45906 (this.disableTooltips ? '' : ' title="{text}"') +
45909 '<a class="nav-link" href="#">' +
45910 '<span unselectable="on"' +
45911 (this.disableTooltips ? '' : ' title="{text}"') +
45912 ' >{text}</span></a>'
45917 switch (typeof(template)) {
45921 template = new Roo.Template(template);
45927 var el = template.overwrite(td, {"text": text});
45929 var inner = el.getElementsByTagName("span")[0];
45931 return {"el": el, "inner": inner};
45939 * @class Roo.TabPanelItem
45940 * @extends Roo.util.Observable
45941 * Represents an individual item (tab plus body) in a TabPanel.
45942 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
45943 * @param {String} id The id of this TabPanelItem
45944 * @param {String} text The text for the tab of this TabPanelItem
45945 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
45947 Roo.bootstrap.panel.TabItem = function(config){
45949 * The {@link Roo.TabPanel} this TabPanelItem belongs to
45950 * @type Roo.TabPanel
45952 this.tabPanel = config.panel;
45954 * The id for this TabPanelItem
45957 this.id = config.id;
45959 this.disabled = false;
45961 this.text = config.text;
45963 this.loaded = false;
45964 this.closable = config.closable;
45967 * The body element for this TabPanelItem.
45968 * @type Roo.Element
45970 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
45971 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
45972 this.bodyEl.setStyle("display", "block");
45973 this.bodyEl.setStyle("zoom", "1");
45974 //this.hideAction();
45976 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
45978 this.el = Roo.get(els.el);
45979 this.inner = Roo.get(els.inner, true);
45980 this.textEl = Roo.bootstrap.version == 4 ?
45981 this.el : Roo.get(this.el.dom.firstChild, true);
45983 this.pnode = this.linode = Roo.get(els.el.parentNode, true);
45984 this.status_node = Roo.bootstrap.version == 4 ? this.el : this.linode;
45987 // this.el.on("mousedown", this.onTabMouseDown, this);
45988 this.el.on("click", this.onTabClick, this);
45990 if(config.closable){
45991 var c = Roo.get(els.close, true);
45992 c.dom.title = this.closeText;
45993 c.addClassOnOver("close-over");
45994 c.on("click", this.closeClick, this);
46000 * Fires when this tab becomes the active tab.
46001 * @param {Roo.TabPanel} tabPanel The parent TabPanel
46002 * @param {Roo.TabPanelItem} this
46006 * @event beforeclose
46007 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
46008 * @param {Roo.TabPanelItem} this
46009 * @param {Object} e Set cancel to true on this object to cancel the close.
46011 "beforeclose": true,
46014 * Fires when this tab is closed.
46015 * @param {Roo.TabPanelItem} this
46019 * @event deactivate
46020 * Fires when this tab is no longer the active tab.
46021 * @param {Roo.TabPanel} tabPanel The parent TabPanel
46022 * @param {Roo.TabPanelItem} this
46024 "deactivate" : true
46026 this.hidden = false;
46028 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
46031 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
46033 purgeListeners : function(){
46034 Roo.util.Observable.prototype.purgeListeners.call(this);
46035 this.el.removeAllListeners();
46038 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
46041 this.status_node.addClass("active");
46044 this.tabPanel.stripWrap.repaint();
46046 this.fireEvent("activate", this.tabPanel, this);
46050 * Returns true if this tab is the active tab.
46051 * @return {Boolean}
46053 isActive : function(){
46054 return this.tabPanel.getActiveTab() == this;
46058 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
46061 this.status_node.removeClass("active");
46063 this.fireEvent("deactivate", this.tabPanel, this);
46066 hideAction : function(){
46067 this.bodyEl.hide();
46068 this.bodyEl.setStyle("position", "absolute");
46069 this.bodyEl.setLeft("-20000px");
46070 this.bodyEl.setTop("-20000px");
46073 showAction : function(){
46074 this.bodyEl.setStyle("position", "relative");
46075 this.bodyEl.setTop("");
46076 this.bodyEl.setLeft("");
46077 this.bodyEl.show();
46081 * Set the tooltip for the tab.
46082 * @param {String} tooltip The tab's tooltip
46084 setTooltip : function(text){
46085 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
46086 this.textEl.dom.qtip = text;
46087 this.textEl.dom.removeAttribute('title');
46089 this.textEl.dom.title = text;
46093 onTabClick : function(e){
46094 e.preventDefault();
46095 this.tabPanel.activate(this.id);
46098 onTabMouseDown : function(e){
46099 e.preventDefault();
46100 this.tabPanel.activate(this.id);
46103 getWidth : function(){
46104 return this.inner.getWidth();
46107 setWidth : function(width){
46108 var iwidth = width - this.linode.getPadding("lr");
46109 this.inner.setWidth(iwidth);
46110 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
46111 this.linode.setWidth(width);
46115 * Show or hide the tab
46116 * @param {Boolean} hidden True to hide or false to show.
46118 setHidden : function(hidden){
46119 this.hidden = hidden;
46120 this.linode.setStyle("display", hidden ? "none" : "");
46124 * Returns true if this tab is "hidden"
46125 * @return {Boolean}
46127 isHidden : function(){
46128 return this.hidden;
46132 * Returns the text for this tab
46135 getText : function(){
46139 autoSize : function(){
46140 //this.el.beginMeasure();
46141 this.textEl.setWidth(1);
46143 * #2804 [new] Tabs in Roojs
46144 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
46146 //this.setWidth(this.textEl.dom.scrollWidth+this.linode.getPadding("lr")+this.inner.getPadding("lr") + 2);
46147 //this.el.endMeasure();
46151 * Sets the text for the tab (Note: this also sets the tooltip text)
46152 * @param {String} text The tab's text and tooltip
46154 setText : function(text){
46156 this.textEl.update(text);
46157 this.setTooltip(text);
46158 //if(!this.tabPanel.resizeTabs){
46159 // this.autoSize();
46163 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
46165 activate : function(){
46166 this.tabPanel.activate(this.id);
46170 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
46172 disable : function(){
46173 if(this.tabPanel.active != this){
46174 this.disabled = true;
46175 this.status_node.addClass("disabled");
46180 * Enables this TabPanelItem if it was previously disabled.
46182 enable : function(){
46183 this.disabled = false;
46184 this.status_node.removeClass("disabled");
46188 * Sets the content for this TabPanelItem.
46189 * @param {String} content The content
46190 * @param {Boolean} loadScripts true to look for and load scripts
46192 setContent : function(content, loadScripts){
46193 this.bodyEl.update(content, loadScripts);
46197 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
46198 * @return {Roo.UpdateManager} The UpdateManager
46200 getUpdateManager : function(){
46201 return this.bodyEl.getUpdateManager();
46205 * Set a URL to be used to load the content for this TabPanelItem.
46206 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
46207 * @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)
46208 * @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)
46209 * @return {Roo.UpdateManager} The UpdateManager
46211 setUrl : function(url, params, loadOnce){
46212 if(this.refreshDelegate){
46213 this.un('activate', this.refreshDelegate);
46215 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
46216 this.on("activate", this.refreshDelegate);
46217 return this.bodyEl.getUpdateManager();
46221 _handleRefresh : function(url, params, loadOnce){
46222 if(!loadOnce || !this.loaded){
46223 var updater = this.bodyEl.getUpdateManager();
46224 updater.update(url, params, this._setLoaded.createDelegate(this));
46229 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
46230 * Will fail silently if the setUrl method has not been called.
46231 * This does not activate the panel, just updates its content.
46233 refresh : function(){
46234 if(this.refreshDelegate){
46235 this.loaded = false;
46236 this.refreshDelegate();
46241 _setLoaded : function(){
46242 this.loaded = true;
46246 closeClick : function(e){
46249 this.fireEvent("beforeclose", this, o);
46250 if(o.cancel !== true){
46251 this.tabPanel.removeTab(this.id);
46255 * The text displayed in the tooltip for the close icon.
46258 closeText : "Close this tab"
46261 * This script refer to:
46262 * Title: International Telephone Input
46263 * Author: Jack O'Connor
46264 * Code version: v12.1.12
46265 * Availability: https://github.com/jackocnr/intl-tel-input.git
46268 Roo.bootstrap.form.PhoneInputData = function() {
46271 "Afghanistan (افغانستان)",
46276 "Albania (Shqipëri)",
46281 "Algeria (الجزائر)",
46306 "Antigua and Barbuda",
46316 "Armenia (Հայաստան)",
46332 "Austria (Österreich)",
46337 "Azerbaijan (Azərbaycan)",
46347 "Bahrain (البحرين)",
46352 "Bangladesh (বাংলাদেশ)",
46362 "Belarus (Беларусь)",
46367 "Belgium (België)",
46397 "Bosnia and Herzegovina (Босна и Херцеговина)",
46412 "British Indian Ocean Territory",
46417 "British Virgin Islands",
46427 "Bulgaria (България)",
46437 "Burundi (Uburundi)",
46442 "Cambodia (កម្ពុជា)",
46447 "Cameroon (Cameroun)",
46456 ["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"]
46459 "Cape Verde (Kabu Verdi)",
46464 "Caribbean Netherlands",
46475 "Central African Republic (République centrafricaine)",
46495 "Christmas Island",
46501 "Cocos (Keeling) Islands",
46512 "Comoros (جزر القمر)",
46517 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
46522 "Congo (Republic) (Congo-Brazzaville)",
46542 "Croatia (Hrvatska)",
46563 "Czech Republic (Česká republika)",
46568 "Denmark (Danmark)",
46583 "Dominican Republic (República Dominicana)",
46587 ["809", "829", "849"]
46605 "Equatorial Guinea (Guinea Ecuatorial)",
46625 "Falkland Islands (Islas Malvinas)",
46630 "Faroe Islands (Føroyar)",
46651 "French Guiana (Guyane française)",
46656 "French Polynesia (Polynésie française)",
46671 "Georgia (საქართველო)",
46676 "Germany (Deutschland)",
46696 "Greenland (Kalaallit Nunaat)",
46733 "Guinea-Bissau (Guiné Bissau)",
46758 "Hungary (Magyarország)",
46763 "Iceland (Ísland)",
46783 "Iraq (العراق)",
46799 "Israel (ישראל)",
46826 "Jordan (الأردن)",
46831 "Kazakhstan (Казахстан)",
46852 "Kuwait (الكويت)",
46857 "Kyrgyzstan (Кыргызстан)",
46867 "Latvia (Latvija)",
46872 "Lebanon (لبنان)",
46887 "Libya (ليبيا)",
46897 "Lithuania (Lietuva)",
46912 "Macedonia (FYROM) (Македонија)",
46917 "Madagascar (Madagasikara)",
46947 "Marshall Islands",
46957 "Mauritania (موريتانيا)",
46962 "Mauritius (Moris)",
46983 "Moldova (Republica Moldova)",
46993 "Mongolia (Монгол)",
46998 "Montenegro (Crna Gora)",
47008 "Morocco (المغرب)",
47014 "Mozambique (Moçambique)",
47019 "Myanmar (Burma) (မြန်မာ)",
47024 "Namibia (Namibië)",
47039 "Netherlands (Nederland)",
47044 "New Caledonia (Nouvelle-Calédonie)",
47079 "North Korea (조선 민주주의 인민 공화국)",
47084 "Northern Mariana Islands",
47100 "Pakistan (پاکستان)",
47110 "Palestine (فلسطين)",
47120 "Papua New Guinea",
47162 "Réunion (La Réunion)",
47168 "Romania (România)",
47184 "Saint Barthélemy",
47195 "Saint Kitts and Nevis",
47205 "Saint Martin (Saint-Martin (partie française))",
47211 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
47216 "Saint Vincent and the Grenadines",
47231 "São Tomé and Príncipe (São Tomé e Príncipe)",
47236 "Saudi Arabia (المملكة العربية السعودية)",
47241 "Senegal (Sénégal)",
47271 "Slovakia (Slovensko)",
47276 "Slovenia (Slovenija)",
47286 "Somalia (Soomaaliya)",
47296 "South Korea (대한민국)",
47301 "South Sudan (جنوب السودان)",
47311 "Sri Lanka (ශ්රී ලංකාව)",
47316 "Sudan (السودان)",
47326 "Svalbard and Jan Mayen",
47337 "Sweden (Sverige)",
47342 "Switzerland (Schweiz)",
47347 "Syria (سوريا)",
47392 "Trinidad and Tobago",
47397 "Tunisia (تونس)",
47402 "Turkey (Türkiye)",
47412 "Turks and Caicos Islands",
47422 "U.S. Virgin Islands",
47432 "Ukraine (Україна)",
47437 "United Arab Emirates (الإمارات العربية المتحدة)",
47459 "Uzbekistan (Oʻzbekiston)",
47469 "Vatican City (Città del Vaticano)",
47480 "Vietnam (Việt Nam)",
47485 "Wallis and Futuna (Wallis-et-Futuna)",
47490 "Western Sahara (الصحراء الغربية)",
47496 "Yemen (اليمن)",
47520 * This script refer to:
47521 * Title: International Telephone Input
47522 * Author: Jack O'Connor
47523 * Code version: v12.1.12
47524 * Availability: https://github.com/jackocnr/intl-tel-input.git
47528 * @class Roo.bootstrap.form.PhoneInput
47529 * @extends Roo.bootstrap.form.TriggerField
47530 * An input with International dial-code selection
47532 * @cfg {String} defaultDialCode default '+852'
47533 * @cfg {Array} preferedCountries default []
47536 * Create a new PhoneInput.
47537 * @param {Object} config Configuration options
47540 Roo.bootstrap.form.PhoneInput = function(config) {
47541 Roo.bootstrap.form.PhoneInput.superclass.constructor.call(this, config);
47544 Roo.extend(Roo.bootstrap.form.PhoneInput, Roo.bootstrap.form.TriggerField, {
47546 * @cfg {Roo.data.Store} store [required] The data store to which this combo is bound (defaults to undefined)
47548 listWidth: undefined,
47550 selectedClass: 'active',
47552 invalidClass : "has-warning",
47554 validClass: 'has-success',
47556 allowed: '0123456789',
47561 * @cfg {String} defaultDialCode The default dial code when initializing the input
47563 defaultDialCode: '+852',
47566 * @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
47568 preferedCountries: false,
47570 getAutoCreate : function()
47572 var data = Roo.bootstrap.form.PhoneInputData();
47573 var align = this.labelAlign || this.parentLabelAlign();
47576 this.allCountries = [];
47577 this.dialCodeMapping = [];
47579 for (var i = 0; i < data.length; i++) {
47581 this.allCountries[i] = {
47585 priority: c[3] || 0,
47586 areaCodes: c[4] || null
47588 this.dialCodeMapping[c[2]] = {
47591 priority: c[3] || 0,
47592 areaCodes: c[4] || null
47604 // type: 'number', -- do not use number - we get the flaky up/down arrows.
47605 maxlength: this.max_length,
47606 cls : 'form-control tel-input',
47607 autocomplete: 'new-password'
47610 var hiddenInput = {
47613 cls: 'hidden-tel-input'
47617 hiddenInput.name = this.name;
47620 if (this.disabled) {
47621 input.disabled = true;
47624 var flag_container = {
47641 cls: this.hasFeedback ? 'has-feedback' : '',
47647 cls: 'dial-code-holder',
47654 cls: 'roo-select2-container input-group',
47661 if (this.fieldLabel.length) {
47664 tooltip: 'This field is required'
47670 cls: 'control-label',
47676 html: this.fieldLabel
47679 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
47685 if(this.indicatorpos == 'right') {
47686 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
47693 if(align == 'left') {
47701 if(this.labelWidth > 12){
47702 label.style = "width: " + this.labelWidth + 'px';
47704 if(this.labelWidth < 13 && this.labelmd == 0){
47705 this.labelmd = this.labelWidth;
47707 if(this.labellg > 0){
47708 label.cls += ' col-lg-' + this.labellg;
47709 input.cls += ' col-lg-' + (12 - this.labellg);
47711 if(this.labelmd > 0){
47712 label.cls += ' col-md-' + this.labelmd;
47713 container.cls += ' col-md-' + (12 - this.labelmd);
47715 if(this.labelsm > 0){
47716 label.cls += ' col-sm-' + this.labelsm;
47717 container.cls += ' col-sm-' + (12 - this.labelsm);
47719 if(this.labelxs > 0){
47720 label.cls += ' col-xs-' + this.labelxs;
47721 container.cls += ' col-xs-' + (12 - this.labelxs);
47731 var settings = this;
47733 ['xs','sm','md','lg'].map(function(size){
47734 if (settings[size]) {
47735 cfg.cls += ' col-' + size + '-' + settings[size];
47739 this.store = new Roo.data.Store({
47740 proxy : new Roo.data.MemoryProxy({}),
47741 reader : new Roo.data.JsonReader({
47752 'name' : 'dialCode',
47756 'name' : 'priority',
47760 'name' : 'areaCodes',
47767 if(!this.preferedCountries) {
47768 this.preferedCountries = [
47775 var p = this.preferedCountries.reverse();
47778 for (var i = 0; i < p.length; i++) {
47779 for (var j = 0; j < this.allCountries.length; j++) {
47780 if(this.allCountries[j].iso2 == p[i]) {
47781 var t = this.allCountries[j];
47782 this.allCountries.splice(j,1);
47783 this.allCountries.unshift(t);
47789 this.store.proxy.data = {
47791 data: this.allCountries
47797 initEvents : function()
47800 Roo.bootstrap.form.PhoneInput.superclass.initEvents.call(this);
47802 this.indicator = this.indicatorEl();
47803 this.flag = this.flagEl();
47804 this.dialCodeHolder = this.dialCodeHolderEl();
47806 this.trigger = this.el.select('div.flag-box',true).first();
47807 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
47812 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
47813 _this.list.setWidth(lw);
47816 this.list.on('mouseover', this.onViewOver, this);
47817 this.list.on('mousemove', this.onViewMove, this);
47818 this.inputEl().on("keyup", this.onKeyUp, this);
47819 this.inputEl().on("keypress", this.onKeyPress, this);
47821 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
47823 this.view = new Roo.View(this.list, this.tpl, {
47824 singleSelect:true, store: this.store, selectedClass: this.selectedClass
47827 this.view.on('click', this.onViewClick, this);
47828 this.setValue(this.defaultDialCode);
47831 onTriggerClick : function(e)
47833 Roo.log('trigger click');
47838 if(this.isExpanded()){
47840 this.hasFocus = false;
47842 this.store.load({});
47843 this.hasFocus = true;
47848 isExpanded : function()
47850 return this.list.isVisible();
47853 collapse : function()
47855 if(!this.isExpanded()){
47859 Roo.get(document).un('mousedown', this.collapseIf, this);
47860 Roo.get(document).un('mousewheel', this.collapseIf, this);
47861 this.fireEvent('collapse', this);
47865 expand : function()
47869 if(this.isExpanded() || !this.hasFocus){
47873 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
47874 this.list.setWidth(lw);
47877 this.restrictHeight();
47879 Roo.get(document).on('mousedown', this.collapseIf, this);
47880 Roo.get(document).on('mousewheel', this.collapseIf, this);
47882 this.fireEvent('expand', this);
47885 restrictHeight : function()
47887 this.list.alignTo(this.inputEl(), this.listAlign);
47888 this.list.alignTo(this.inputEl(), this.listAlign);
47891 onViewOver : function(e, t)
47893 if(this.inKeyMode){
47896 var item = this.view.findItemFromChild(t);
47899 var index = this.view.indexOf(item);
47900 this.select(index, false);
47905 onViewClick : function(view, doFocus, el, e)
47907 var index = this.view.getSelectedIndexes()[0];
47909 var r = this.store.getAt(index);
47912 this.onSelect(r, index);
47914 if(doFocus !== false && !this.blockFocus){
47915 this.inputEl().focus();
47919 onViewMove : function(e, t)
47921 this.inKeyMode = false;
47924 select : function(index, scrollIntoView)
47926 this.selectedIndex = index;
47927 this.view.select(index);
47928 if(scrollIntoView !== false){
47929 var el = this.view.getNode(index);
47931 this.list.scrollChildIntoView(el, false);
47936 createList : function()
47938 this.list = Roo.get(document.body).createChild({
47940 cls: 'typeahead typeahead-long dropdown-menu tel-list',
47941 style: 'display:none'
47944 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
47947 collapseIf : function(e)
47949 var in_combo = e.within(this.el);
47950 var in_list = e.within(this.list);
47951 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
47953 if (in_combo || in_list || is_list) {
47959 onSelect : function(record, index)
47961 if(this.fireEvent('beforeselect', this, record, index) !== false){
47963 this.setFlagClass(record.data.iso2);
47964 this.setDialCode(record.data.dialCode);
47965 this.hasFocus = false;
47967 this.fireEvent('select', this, record, index);
47971 flagEl : function()
47973 var flag = this.el.select('div.flag',true).first();
47980 dialCodeHolderEl : function()
47982 var d = this.el.select('input.dial-code-holder',true).first();
47989 setDialCode : function(v)
47991 this.dialCodeHolder.dom.value = '+'+v;
47994 setFlagClass : function(n)
47996 this.flag.dom.className = 'flag '+n;
47999 getValue : function()
48001 var v = this.inputEl().getValue();
48002 if(this.dialCodeHolder) {
48003 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
48008 setValue : function(v)
48010 var d = this.getDialCode(v);
48012 //invalid dial code
48013 if(v.length == 0 || !d || d.length == 0) {
48015 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
48016 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
48022 this.setFlagClass(this.dialCodeMapping[d].iso2);
48023 this.setDialCode(d);
48024 this.inputEl().dom.value = v.replace('+'+d,'');
48025 this.hiddenEl().dom.value = this.getValue();
48030 getDialCode : function(v)
48034 if (v.length == 0) {
48035 return this.dialCodeHolder.dom.value;
48039 if (v.charAt(0) != "+") {
48042 var numericChars = "";
48043 for (var i = 1; i < v.length; i++) {
48044 var c = v.charAt(i);
48047 if (this.dialCodeMapping[numericChars]) {
48048 dialCode = v.substr(1, i);
48050 if (numericChars.length == 4) {
48060 this.setValue(this.defaultDialCode);
48064 hiddenEl : function()
48066 return this.el.select('input.hidden-tel-input',true).first();
48069 // after setting val
48070 onKeyUp : function(e){
48071 this.setValue(this.getValue());
48074 onKeyPress : function(e){
48075 if(this.allowed.indexOf(String.fromCharCode(e.getCharCode())) === -1){
48082 * @class Roo.bootstrap.form.MoneyField
48083 * @extends Roo.bootstrap.form.ComboBox
48084 * Bootstrap MoneyField class
48087 * Create a new MoneyField.
48088 * @param {Object} config Configuration options
48091 Roo.bootstrap.form.MoneyField = function(config) {
48093 Roo.bootstrap.form.MoneyField.superclass.constructor.call(this, config);
48097 Roo.extend(Roo.bootstrap.form.MoneyField, Roo.bootstrap.form.ComboBox, {
48100 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
48102 allowDecimals : true,
48104 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
48106 decimalSeparator : ".",
48108 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
48110 decimalPrecision : 0,
48112 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
48114 allowNegative : true,
48116 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
48120 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
48122 minValue : Number.NEGATIVE_INFINITY,
48124 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
48126 maxValue : Number.MAX_VALUE,
48128 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
48130 minText : "The minimum value for this field is {0}",
48132 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
48134 maxText : "The maximum value for this field is {0}",
48136 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
48137 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
48139 nanText : "{0} is not a valid number",
48141 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
48145 * @cfg {String} defaults currency of the MoneyField
48146 * value should be in lkey
48148 defaultCurrency : false,
48150 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
48152 thousandsDelimiter : false,
48154 * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
48163 * @cfg {Roo.data.Store} store Store to lookup currency??
48167 getAutoCreate : function()
48169 var align = this.labelAlign || this.parentLabelAlign();
48181 cls : 'form-control roo-money-amount-input',
48182 autocomplete: 'new-password'
48185 var hiddenInput = {
48189 cls: 'hidden-number-input'
48192 if(this.max_length) {
48193 input.maxlength = this.max_length;
48197 hiddenInput.name = this.name;
48200 if (this.disabled) {
48201 input.disabled = true;
48204 var clg = 12 - this.inputlg;
48205 var cmd = 12 - this.inputmd;
48206 var csm = 12 - this.inputsm;
48207 var cxs = 12 - this.inputxs;
48211 cls : 'row roo-money-field',
48215 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
48219 cls: 'roo-select2-container input-group',
48223 cls : 'form-control roo-money-currency-input',
48224 autocomplete: 'new-password',
48226 name : this.currencyName
48230 cls : 'input-group-addon',
48244 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
48248 cls: this.hasFeedback ? 'has-feedback' : '',
48259 if (this.fieldLabel.length) {
48262 tooltip: 'This field is required'
48268 cls: 'control-label',
48274 html: this.fieldLabel
48277 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
48283 if(this.indicatorpos == 'right') {
48284 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
48291 if(align == 'left') {
48299 if(this.labelWidth > 12){
48300 label.style = "width: " + this.labelWidth + 'px';
48302 if(this.labelWidth < 13 && this.labelmd == 0){
48303 this.labelmd = this.labelWidth;
48305 if(this.labellg > 0){
48306 label.cls += ' col-lg-' + this.labellg;
48307 input.cls += ' col-lg-' + (12 - this.labellg);
48309 if(this.labelmd > 0){
48310 label.cls += ' col-md-' + this.labelmd;
48311 container.cls += ' col-md-' + (12 - this.labelmd);
48313 if(this.labelsm > 0){
48314 label.cls += ' col-sm-' + this.labelsm;
48315 container.cls += ' col-sm-' + (12 - this.labelsm);
48317 if(this.labelxs > 0){
48318 label.cls += ' col-xs-' + this.labelxs;
48319 container.cls += ' col-xs-' + (12 - this.labelxs);
48330 var settings = this;
48332 ['xs','sm','md','lg'].map(function(size){
48333 if (settings[size]) {
48334 cfg.cls += ' col-' + size + '-' + settings[size];
48341 initEvents : function()
48343 this.indicator = this.indicatorEl();
48345 this.initCurrencyEvent();
48347 this.initNumberEvent();
48350 initCurrencyEvent : function()
48353 throw "can not find store for combo";
48356 this.store = Roo.factory(this.store, Roo.data);
48357 this.store.parent = this;
48361 this.triggerEl = this.el.select('.input-group-addon', true).first();
48363 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
48368 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
48369 _this.list.setWidth(lw);
48372 this.list.on('mouseover', this.onViewOver, this);
48373 this.list.on('mousemove', this.onViewMove, this);
48374 this.list.on('scroll', this.onViewScroll, this);
48377 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
48380 this.view = new Roo.View(this.list, this.tpl, {
48381 singleSelect:true, store: this.store, selectedClass: this.selectedClass
48384 this.view.on('click', this.onViewClick, this);
48386 this.store.on('beforeload', this.onBeforeLoad, this);
48387 this.store.on('load', this.onLoad, this);
48388 this.store.on('loadexception', this.onLoadException, this);
48390 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
48391 "up" : function(e){
48392 this.inKeyMode = true;
48396 "down" : function(e){
48397 if(!this.isExpanded()){
48398 this.onTriggerClick();
48400 this.inKeyMode = true;
48405 "enter" : function(e){
48408 if(this.fireEvent("specialkey", this, e)){
48409 this.onViewClick(false);
48415 "esc" : function(e){
48419 "tab" : function(e){
48422 if(this.fireEvent("specialkey", this, e)){
48423 this.onViewClick(false);
48431 doRelay : function(foo, bar, hname){
48432 if(hname == 'down' || this.scope.isExpanded()){
48433 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
48441 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
48445 initNumberEvent : function(e)
48447 this.inputEl().on("keydown" , this.fireKey, this);
48448 this.inputEl().on("focus", this.onFocus, this);
48449 this.inputEl().on("blur", this.onBlur, this);
48451 this.inputEl().relayEvent('keyup', this);
48453 if(this.indicator){
48454 this.indicator.addClass('invisible');
48457 this.originalValue = this.getValue();
48459 if(this.validationEvent == 'keyup'){
48460 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
48461 this.inputEl().on('keyup', this.filterValidation, this);
48463 else if(this.validationEvent !== false){
48464 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
48467 if(this.selectOnFocus){
48468 this.on("focus", this.preFocus, this);
48471 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
48472 this.inputEl().on("keypress", this.filterKeys, this);
48474 this.inputEl().relayEvent('keypress', this);
48477 var allowed = "0123456789";
48479 if(this.allowDecimals){
48480 allowed += this.decimalSeparator;
48483 if(this.allowNegative){
48487 if(this.thousandsDelimiter) {
48491 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
48493 var keyPress = function(e){
48495 var k = e.getKey();
48497 var c = e.getCharCode();
48500 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
48501 allowed.indexOf(String.fromCharCode(c)) === -1
48507 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
48511 if(allowed.indexOf(String.fromCharCode(c)) === -1){
48516 this.inputEl().on("keypress", keyPress, this);
48520 onTriggerClick : function(e)
48527 this.loadNext = false;
48529 if(this.isExpanded()){
48534 this.hasFocus = true;
48536 if(this.triggerAction == 'all') {
48537 this.doQuery(this.allQuery, true);
48541 this.doQuery(this.getRawValue());
48544 getCurrency : function()
48546 var v = this.currencyEl().getValue();
48551 restrictHeight : function()
48553 this.list.alignTo(this.currencyEl(), this.listAlign);
48554 this.list.alignTo(this.currencyEl(), this.listAlign);
48557 onViewClick : function(view, doFocus, el, e)
48559 var index = this.view.getSelectedIndexes()[0];
48561 var r = this.store.getAt(index);
48564 this.onSelect(r, index);
48568 onSelect : function(record, index){
48570 if(this.fireEvent('beforeselect', this, record, index) !== false){
48572 this.setFromCurrencyData(index > -1 ? record.data : false);
48576 this.fireEvent('select', this, record, index);
48580 setFromCurrencyData : function(o)
48584 this.lastCurrency = o;
48586 if (this.currencyField) {
48587 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
48589 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
48592 this.lastSelectionText = currency;
48594 //setting default currency
48595 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
48596 this.setCurrency(this.defaultCurrency);
48600 this.setCurrency(currency);
48603 setFromData : function(o)
48607 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
48609 this.setFromCurrencyData(c);
48614 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
48616 Roo.log('no value set for '+ (this.name ? this.name : this.id));
48619 this.setValue(value);
48623 setCurrency : function(v)
48625 this.currencyValue = v;
48628 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
48633 setValue : function(v)
48635 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
48641 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
48643 this.inputEl().dom.value = (v == '') ? '' :
48644 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
48646 if(!this.allowZero && v === '0') {
48647 this.hiddenEl().dom.value = '';
48648 this.inputEl().dom.value = '';
48655 getRawValue : function()
48657 var v = this.inputEl().getValue();
48662 getValue : function()
48664 return this.fixPrecision(this.parseValue(this.getRawValue()));
48667 parseValue : function(value)
48669 if(this.thousandsDelimiter) {
48671 r = new RegExp(",", "g");
48672 value = value.replace(r, "");
48675 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
48676 return isNaN(value) ? '' : value;
48680 fixPrecision : function(value)
48682 if(this.thousandsDelimiter) {
48684 r = new RegExp(",", "g");
48685 value = value.replace(r, "");
48688 var nan = isNaN(value);
48690 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
48691 return nan ? '' : value;
48693 return parseFloat(value).toFixed(this.decimalPrecision);
48696 decimalPrecisionFcn : function(v)
48698 return Math.floor(v);
48701 validateValue : function(value)
48703 if(!Roo.bootstrap.form.MoneyField.superclass.validateValue.call(this, value)){
48707 var num = this.parseValue(value);
48710 this.markInvalid(String.format(this.nanText, value));
48714 if(num < this.minValue){
48715 this.markInvalid(String.format(this.minText, this.minValue));
48719 if(num > this.maxValue){
48720 this.markInvalid(String.format(this.maxText, this.maxValue));
48727 validate : function()
48729 if(this.disabled || this.allowBlank){
48734 var currency = this.getCurrency();
48736 if(this.validateValue(this.getRawValue()) && currency.length){
48741 this.markInvalid();
48745 getName: function()
48750 beforeBlur : function()
48756 var v = this.parseValue(this.getRawValue());
48763 onBlur : function()
48767 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
48768 //this.el.removeClass(this.focusClass);
48771 this.hasFocus = false;
48773 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
48777 var v = this.getValue();
48779 if(String(v) !== String(this.startValue)){
48780 this.fireEvent('change', this, v, this.startValue);
48783 this.fireEvent("blur", this);
48786 inputEl : function()
48788 return this.el.select('.roo-money-amount-input', true).first();
48791 currencyEl : function()
48793 return this.el.select('.roo-money-currency-input', true).first();
48796 hiddenEl : function()
48798 return this.el.select('input.hidden-number-input',true).first();
48802 * @class Roo.bootstrap.BezierSignature
48803 * @extends Roo.bootstrap.Component
48804 * Bootstrap BezierSignature class
48805 * This script refer to:
48806 * Title: Signature Pad
48808 * Availability: https://github.com/szimek/signature_pad
48811 * Create a new BezierSignature
48812 * @param {Object} config The config object
48815 Roo.bootstrap.BezierSignature = function(config){
48816 Roo.bootstrap.BezierSignature.superclass.constructor.call(this, config);
48822 Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component,
48829 mouse_btn_down: true,
48832 * @cfg {int} canvas height
48834 canvas_height: '200px',
48837 * @cfg {float|function} Radius of a single dot.
48842 * @cfg {float} Minimum width of a line. Defaults to 0.5.
48847 * @cfg {float} Maximum width of a line. Defaults to 2.5.
48852 * @cfg {integer} Draw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling. Defaults to 16.
48857 * @cfg {integer} Add the next point only if the previous one is farther than x pixels. Defaults to 5.
48862 * @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.
48864 bg_color: 'rgba(0, 0, 0, 0)',
48867 * @cfg {string} Color used to draw the lines. Can be any color format accepted by context.fillStyle. Defaults to "black".
48869 dot_color: 'black',
48872 * @cfg {float} Weight used to modify new velocity based on the previous velocity. Defaults to 0.7.
48874 velocity_filter_weight: 0.7,
48877 * @cfg {function} Callback when stroke begin.
48882 * @cfg {function} Callback when stroke end.
48886 getAutoCreate : function()
48888 var cls = 'roo-signature column';
48891 cls += ' ' + this.cls;
48901 for(var i = 0; i < col_sizes.length; i++) {
48902 if(this[col_sizes[i]]) {
48903 cls += " col-"+col_sizes[i]+"-"+this[col_sizes[i]];
48913 cls: 'roo-signature-body',
48917 cls: 'roo-signature-body-canvas',
48918 height: this.canvas_height,
48919 width: this.canvas_width
48926 style: 'display: none'
48934 initEvents: function()
48936 Roo.bootstrap.BezierSignature.superclass.initEvents.call(this);
48938 var canvas = this.canvasEl();
48940 // mouse && touch event swapping...
48941 canvas.dom.style.touchAction = 'none';
48942 canvas.dom.style.msTouchAction = 'none';
48944 this.mouse_btn_down = false;
48945 canvas.on('mousedown', this._handleMouseDown, this);
48946 canvas.on('mousemove', this._handleMouseMove, this);
48947 Roo.select('html').first().on('mouseup', this._handleMouseUp, this);
48949 if (window.PointerEvent) {
48950 canvas.on('pointerdown', this._handleMouseDown, this);
48951 canvas.on('pointermove', this._handleMouseMove, this);
48952 Roo.select('html').first().on('pointerup', this._handleMouseUp, this);
48955 if ('ontouchstart' in window) {
48956 canvas.on('touchstart', this._handleTouchStart, this);
48957 canvas.on('touchmove', this._handleTouchMove, this);
48958 canvas.on('touchend', this._handleTouchEnd, this);
48961 Roo.EventManager.onWindowResize(this.resize, this, true);
48963 // file input event
48964 this.fileEl().on('change', this.uploadImage, this);
48971 resize: function(){
48973 var canvas = this.canvasEl().dom;
48974 var ctx = this.canvasElCtx();
48975 var img_data = false;
48977 if(canvas.width > 0) {
48978 var img_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
48980 // setting canvas width will clean img data
48983 var style = window.getComputedStyle ?
48984 getComputedStyle(this.el.dom, null) : this.el.dom.currentStyle;
48986 var padding_left = parseInt(style.paddingLeft) || 0;
48987 var padding_right = parseInt(style.paddingRight) || 0;
48989 canvas.width = this.el.dom.clientWidth - padding_left - padding_right;
48992 ctx.putImageData(img_data, 0, 0);
48996 _handleMouseDown: function(e)
48998 if (e.browserEvent.which === 1) {
48999 this.mouse_btn_down = true;
49000 this.strokeBegin(e);
49004 _handleMouseMove: function (e)
49006 if (this.mouse_btn_down) {
49007 this.strokeMoveUpdate(e);
49011 _handleMouseUp: function (e)
49013 if (e.browserEvent.which === 1 && this.mouse_btn_down) {
49014 this.mouse_btn_down = false;
49019 _handleTouchStart: function (e) {
49021 e.preventDefault();
49022 if (e.browserEvent.targetTouches.length === 1) {
49023 // var touch = e.browserEvent.changedTouches[0];
49024 // this.strokeBegin(touch);
49026 this.strokeBegin(e); // assume e catching the correct xy...
49030 _handleTouchMove: function (e) {
49031 e.preventDefault();
49032 // var touch = event.targetTouches[0];
49033 // _this._strokeMoveUpdate(touch);
49034 this.strokeMoveUpdate(e);
49037 _handleTouchEnd: function (e) {
49038 var wasCanvasTouched = e.target === this.canvasEl().dom;
49039 if (wasCanvasTouched) {
49040 e.preventDefault();
49041 // var touch = event.changedTouches[0];
49042 // _this._strokeEnd(touch);
49047 reset: function () {
49048 this._lastPoints = [];
49049 this._lastVelocity = 0;
49050 this._lastWidth = (this.min_width + this.max_width) / 2;
49051 this.canvasElCtx().fillStyle = this.dot_color;
49054 strokeMoveUpdate: function(e)
49056 this.strokeUpdate(e);
49058 if (this.throttle) {
49059 this.throttleStroke(this.strokeUpdate, this.throttle);
49062 this.strokeUpdate(e);
49066 strokeBegin: function(e)
49068 var newPointGroup = {
49069 color: this.dot_color,
49073 if (typeof this.onBegin === 'function') {
49077 this.curve_data.push(newPointGroup);
49079 this.strokeUpdate(e);
49082 strokeUpdate: function(e)
49084 var rect = this.canvasEl().dom.getBoundingClientRect();
49085 var point = new this.Point(e.xy[0] - rect.left, e.xy[1] - rect.top, new Date().getTime());
49086 var lastPointGroup = this.curve_data[this.curve_data.length - 1];
49087 var lastPoints = lastPointGroup.points;
49088 var lastPoint = lastPoints.length > 0 && lastPoints[lastPoints.length - 1];
49089 var isLastPointTooClose = lastPoint
49090 ? point.distanceTo(lastPoint) <= this.min_distance
49092 var color = lastPointGroup.color;
49093 if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
49094 var curve = this.addPoint(point);
49096 this.drawDot({color: color, point: point});
49099 this.drawCurve({color: color, curve: curve});
49109 strokeEnd: function(e)
49111 this.strokeUpdate(e);
49112 if (typeof this.onEnd === 'function') {
49117 addPoint: function (point) {
49118 var _lastPoints = this._lastPoints;
49119 _lastPoints.push(point);
49120 if (_lastPoints.length > 2) {
49121 if (_lastPoints.length === 3) {
49122 _lastPoints.unshift(_lastPoints[0]);
49124 var widths = this.calculateCurveWidths(_lastPoints[1], _lastPoints[2]);
49125 var curve = this.Bezier.fromPoints(_lastPoints, widths, this);
49126 _lastPoints.shift();
49132 calculateCurveWidths: function (startPoint, endPoint) {
49133 var velocity = this.velocity_filter_weight * endPoint.velocityFrom(startPoint) +
49134 (1 - this.velocity_filter_weight) * this._lastVelocity;
49136 var newWidth = Math.max(this.max_width / (velocity + 1), this.min_width);
49139 start: this._lastWidth
49142 this._lastVelocity = velocity;
49143 this._lastWidth = newWidth;
49147 drawDot: function (_a) {
49148 var color = _a.color, point = _a.point;
49149 var ctx = this.canvasElCtx();
49150 var width = typeof this.dot_size === 'function' ? this.dot_size() : this.dot_size;
49152 this.drawCurveSegment(point.x, point.y, width);
49154 ctx.fillStyle = color;
49158 drawCurve: function (_a) {
49159 var color = _a.color, curve = _a.curve;
49160 var ctx = this.canvasElCtx();
49161 var widthDelta = curve.endWidth - curve.startWidth;
49162 var drawSteps = Math.floor(curve.length()) * 2;
49164 ctx.fillStyle = color;
49165 for (var i = 0; i < drawSteps; i += 1) {
49166 var t = i / drawSteps;
49172 var x = uuu * curve.startPoint.x;
49173 x += 3 * uu * t * curve.control1.x;
49174 x += 3 * u * tt * curve.control2.x;
49175 x += ttt * curve.endPoint.x;
49176 var y = uuu * curve.startPoint.y;
49177 y += 3 * uu * t * curve.control1.y;
49178 y += 3 * u * tt * curve.control2.y;
49179 y += ttt * curve.endPoint.y;
49180 var width = curve.startWidth + ttt * widthDelta;
49181 this.drawCurveSegment(x, y, width);
49187 drawCurveSegment: function (x, y, width) {
49188 var ctx = this.canvasElCtx();
49190 ctx.arc(x, y, width, 0, 2 * Math.PI, false);
49191 this.is_empty = false;
49196 var ctx = this.canvasElCtx();
49197 var canvas = this.canvasEl().dom;
49198 ctx.fillStyle = this.bg_color;
49199 ctx.clearRect(0, 0, canvas.width, canvas.height);
49200 ctx.fillRect(0, 0, canvas.width, canvas.height);
49201 this.curve_data = [];
49203 this.is_empty = true;
49208 return this.el.select('input',true).first();
49211 canvasEl: function()
49213 return this.el.select('canvas',true).first();
49216 canvasElCtx: function()
49218 return this.el.select('canvas',true).first().dom.getContext('2d');
49221 getImage: function(type)
49223 if(this.is_empty) {
49228 return this.canvasEl().dom.toDataURL('image/'+type, 1);
49231 drawFromImage: function(img_src)
49233 var img = new Image();
49235 img.onload = function(){
49236 this.canvasElCtx().drawImage(img, 0, 0);
49241 this.is_empty = false;
49244 selectImage: function()
49246 this.fileEl().dom.click();
49249 uploadImage: function(e)
49251 var reader = new FileReader();
49253 reader.onload = function(e){
49254 var img = new Image();
49255 img.onload = function(){
49257 this.canvasElCtx().drawImage(img, 0, 0);
49259 img.src = e.target.result;
49262 reader.readAsDataURL(e.target.files[0]);
49265 // Bezier Point Constructor
49266 Point: (function () {
49267 function Point(x, y, time) {
49270 this.time = time || Date.now();
49272 Point.prototype.distanceTo = function (start) {
49273 return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
49275 Point.prototype.equals = function (other) {
49276 return this.x === other.x && this.y === other.y && this.time === other.time;
49278 Point.prototype.velocityFrom = function (start) {
49279 return this.time !== start.time
49280 ? this.distanceTo(start) / (this.time - start.time)
49287 // Bezier Constructor
49288 Bezier: (function () {
49289 function Bezier(startPoint, control2, control1, endPoint, startWidth, endWidth) {
49290 this.startPoint = startPoint;
49291 this.control2 = control2;
49292 this.control1 = control1;
49293 this.endPoint = endPoint;
49294 this.startWidth = startWidth;
49295 this.endWidth = endWidth;
49297 Bezier.fromPoints = function (points, widths, scope) {
49298 var c2 = this.calculateControlPoints(points[0], points[1], points[2], scope).c2;
49299 var c3 = this.calculateControlPoints(points[1], points[2], points[3], scope).c1;
49300 return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
49302 Bezier.calculateControlPoints = function (s1, s2, s3, scope) {
49303 var dx1 = s1.x - s2.x;
49304 var dy1 = s1.y - s2.y;
49305 var dx2 = s2.x - s3.x;
49306 var dy2 = s2.y - s3.y;
49307 var m1 = { x: (s1.x + s2.x) / 2.0, y: (s1.y + s2.y) / 2.0 };
49308 var m2 = { x: (s2.x + s3.x) / 2.0, y: (s2.y + s3.y) / 2.0 };
49309 var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
49310 var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
49311 var dxm = m1.x - m2.x;
49312 var dym = m1.y - m2.y;
49313 var k = l2 / (l1 + l2);
49314 var cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
49315 var tx = s2.x - cm.x;
49316 var ty = s2.y - cm.y;
49318 c1: new scope.Point(m1.x + tx, m1.y + ty),
49319 c2: new scope.Point(m2.x + tx, m2.y + ty)
49322 Bezier.prototype.length = function () {
49327 for (var i = 0; i <= steps; i += 1) {
49329 var cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
49330 var cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
49332 var xdiff = cx - px;
49333 var ydiff = cy - py;
49334 length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
49341 Bezier.prototype.point = function (t, start, c1, c2, end) {
49342 return (start * (1.0 - t) * (1.0 - t) * (1.0 - t))
49343 + (3.0 * c1 * (1.0 - t) * (1.0 - t) * t)
49344 + (3.0 * c2 * (1.0 - t) * t * t)
49345 + (end * t * t * t);
49350 throttleStroke: function(fn, wait) {
49351 if (wait === void 0) { wait = 250; }
49353 var timeout = null;
49357 var later = function () {
49358 previous = Date.now();
49360 result = fn.apply(storedContext, storedArgs);
49362 storedContext = null;
49366 return function wrapper() {
49368 for (var _i = 0; _i < arguments.length; _i++) {
49369 args[_i] = arguments[_i];
49371 var now = Date.now();
49372 var remaining = wait - (now - previous);
49373 storedContext = this;
49375 if (remaining <= 0 || remaining > wait) {
49377 clearTimeout(timeout);
49381 result = fn.apply(storedContext, storedArgs);
49383 storedContext = null;
49387 else if (!timeout) {
49388 timeout = window.setTimeout(later, remaining);
49398 // old names for form elements
49399 Roo.bootstrap.Form = Roo.bootstrap.form.Form;
49400 Roo.bootstrap.Input = Roo.bootstrap.form.Input;
49401 Roo.bootstrap.TextArea = Roo.bootstrap.form.TextArea;
49402 Roo.bootstrap.TriggerField = Roo.bootstrap.form.TriggerField;
49403 Roo.bootstrap.ComboBox = Roo.bootstrap.form.ComboBox;
49404 Roo.bootstrap.DateField = Roo.bootstrap.form.DateField;
49405 Roo.bootstrap.TimeField = Roo.bootstrap.form.TimeField;
49406 Roo.bootstrap.MonthField = Roo.bootstrap.form.MonthField;
49407 Roo.bootstrap.CheckBox = Roo.bootstrap.form.CheckBox;
49408 Roo.bootstrap.Radio = Roo.bootstrap.form.Radio;
49409 Roo.bootstrap.RadioSet = Roo.bootstrap.form.RadioSet;
49410 Roo.bootstrap.SecurePass = Roo.bootstrap.form.SecurePass;
49411 Roo.bootstrap.FieldLabel = Roo.bootstrap.form.FieldLabel;
49412 Roo.bootstrap.DateSplitField= Roo.bootstrap.form.DateSplitField;
49413 Roo.bootstrap.NumberField = Roo.bootstrap.form.NumberField;
49414 Roo.bootstrap.PhoneInput = Roo.bootstrap.form.PhoneInput;
49415 Roo.bootstrap.PhoneInputData= Roo.bootstrap.form.PhoneInputData;
49416 Roo.bootstrap.MoneyField = Roo.bootstrap.form.MoneyField;
49417 Roo.bootstrap.HtmlEditor = Roo.bootstrap.form.HtmlEditor;
49418 Roo.bootstrap.HtmlEditor.ToolbarStandard = Roo.bootstrap.form.HtmlEditorToolbarStandard;
49419 Roo.bootstrap.Markdown = Roo.bootstrap.form.Markdown;
49420 Roo.bootstrap.CardUploader = Roo.bootstrap.form.CardUploader;// depricated.
49421 Roo.bootstrap.Navbar = Roo.bootstrap.nav.Bar;
49422 Roo.bootstrap.NavGroup = Roo.bootstrap.nav.Group;
49423 Roo.bootstrap.NavHeaderbar = Roo.bootstrap.nav.Headerbar;
49424 Roo.bootstrap.NavItem = Roo.bootstrap.nav.Item;
49426 Roo.bootstrap.NavProgressBar = Roo.bootstrap.nav.ProgressBar;
49427 Roo.bootstrap.NavProgressBarItem = Roo.bootstrap.nav.ProgressBarItem;
49429 Roo.bootstrap.NavSidebar = Roo.bootstrap.nav.Sidebar;
49430 Roo.bootstrap.NavSidebarItem = Roo.bootstrap.nav.SidebarItem;
49432 Roo.bootstrap.NavSimplebar = Roo.bootstrap.nav.Simplebar;// deprciated
49433 Roo.bootstrap.Menu = Roo.bootstrap.menu.Menu;
49434 Roo.bootstrap.MenuItem = Roo.bootstrap.menu.Item;
49435 Roo.bootstrap.MenuSeparator = Roo.bootstrap.menu.Separator