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} tooltipClass Class for the tooltip element
240 * @cfg {string} container_method method to fetch parents container element (used by NavHeaderbar - getHeaderChildContainer)
241 * @cfg {string|object} visibilityEl (el|parent) What element to use for visibility (@see getVisibilityEl())
244 * Do not use directly - it does not do anything..
245 * @param {Object} config The config object
250 Roo.bootstrap.Component = function(config){
251 Roo.bootstrap.Component.superclass.constructor.call(this, config);
255 * @event childrenrendered
256 * Fires when the children have been rendered..
257 * @param {Roo.bootstrap.Component} this
259 "childrenrendered" : true
268 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, {
271 allowDomMove : false, // to stop relocations in parent onRender...
283 * Initialize Events for the element
285 initEvents : function() { },
291 can_build_overlaid : true,
293 container_method : false,
300 // returns the parent component..
301 return Roo.ComponentMgr.get(this.parentId)
307 onRender : function(ct, position)
309 // Roo.log("Call onRender: " + this.xtype);
311 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
314 if (this.el.attr('xtype')) {
315 this.el.attr('xtypex', this.el.attr('xtype'));
316 this.el.dom.removeAttribute('xtype');
326 var cfg = Roo.apply({}, this.getAutoCreate());
328 cfg.id = this.id || Roo.id();
330 // fill in the extra attributes
331 if (this.xattr && typeof(this.xattr) =='object') {
332 for (var i in this.xattr) {
333 cfg[i] = this.xattr[i];
338 cfg.dataId = this.dataId;
342 cfg.cls = (typeof(cfg.cls) == 'undefined' ? this.cls : cfg.cls) + ' ' + this.cls;
345 if (this.style) { // fixme needs to support more complex style data.
346 cfg.style = (typeof(cfg.style) == 'undefined' ? this.style : cfg.style) + '; ' + this.style;
350 cfg.name = this.name;
353 this.el = ct.createChild(cfg, position);
356 this.tooltipEl().attr('tooltip', this.tooltip);
359 if (this.tooltipClass) {
360 this.tooltipEl().attr('tooltip-class', this.tooltipClass);
363 if(this.tabIndex !== undefined){
364 this.el.dom.setAttribute('tabIndex', this.tabIndex);
371 * Fetch the element to add children to
372 * @return {Roo.Element} defaults to this.el
374 getChildContainer : function()
378 getDocumentBody : function() // used by menus - as they are attached to the body so zIndexes work
380 return Roo.get(document.body);
384 * Fetch the element to display the tooltip on.
385 * @return {Roo.Element} defaults to this.el
387 tooltipEl : function()
392 addxtype : function(tree,cntr)
396 cn = Roo.factory(tree);
397 //Roo.log(['addxtype', cn]);
399 cn.parentType = this.xtype; //??
400 cn.parentId = this.id;
402 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
403 if (typeof(cn.container_method) == 'string') {
404 cntr = cn.container_method;
408 var has_flexy_each = (typeof(tree['flexy:foreach']) != 'undefined');
410 var has_flexy_if = (typeof(tree['flexy:if']) != 'undefined');
412 var build_from_html = Roo.XComponent.build_from_html;
414 var is_body = (tree.xtype == 'Body') ;
416 var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
418 var self_cntr_el = Roo.get(this[cntr](false));
420 // do not try and build conditional elements
421 if ((has_flexy_each || has_flexy_if || this.can_build_overlaid == false ) && build_from_html) {
425 if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
426 if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
427 return this.addxtypeChild(tree,cntr, is_body);
430 var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
433 return this.addxtypeChild(Roo.apply({}, tree),cntr);
436 Roo.log('skipping render');
442 if (!build_from_html) {
446 // this i think handles overlaying multiple children of the same type
447 // with the sam eelement.. - which might be buggy..
449 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
455 if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
459 ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
466 addxtypeChild : function (tree, cntr, is_body)
468 Roo.debug && Roo.log('addxtypeChild:' + cntr);
470 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
473 var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
474 (typeof(tree['flexy:foreach']) != 'undefined');
478 skip_children = false;
479 // render the element if it's not BODY.
482 // if parent was disabled, then do not try and create the children..
483 if(!this[cntr](true)){
488 cn = Roo.factory(tree);
490 cn.parentType = this.xtype; //??
491 cn.parentId = this.id;
493 var build_from_html = Roo.XComponent.build_from_html;
496 // does the container contain child eleemnts with 'xtype' attributes.
497 // that match this xtype..
498 // note - when we render we create these as well..
499 // so we should check to see if body has xtype set.
500 if (build_from_html && Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
502 var self_cntr_el = Roo.get(this[cntr](false));
503 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
505 //Roo.log(Roo.XComponent.build_from_html);
506 //Roo.log("got echild:");
509 // there is a scenario where some of the child elements are flexy:if (and all of the same type)
510 // and are not displayed -this causes this to use up the wrong element when matching.
511 // at present the only work around for this is to nest flexy:if elements in another element that is always rendered.
514 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
515 // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
521 //echild.dom.removeAttribute('xtype');
523 Roo.debug && Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
524 Roo.debug && Roo.log(self_cntr_el);
525 Roo.debug && Roo.log(echild);
526 Roo.debug && Roo.log(cn);
532 // if object has flexy:if - then it may or may not be rendered.
533 if (build_from_html && has_flexy && !cn.el && cn.can_build_overlaid) {
534 // skip a flexy if element.
535 Roo.debug && Roo.log('skipping render');
536 Roo.debug && Roo.log(tree);
538 Roo.debug && Roo.log('skipping all children');
539 skip_children = true;
544 // actually if flexy:foreach is found, we really want to create
545 // multiple copies here...
547 //Roo.log(this[cntr]());
548 // some elements do not have render methods.. like the layouts...
550 if(this[cntr](true) === false){
555 cn.render && cn.render(this[cntr](true));
558 // then add the element..
565 if (typeof (tree.menu) != 'undefined') {
566 tree.menu.parentType = cn.xtype;
567 tree.menu.triggerEl = cn.el;
568 nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
572 if (!tree.items || !tree.items.length) {
574 //Roo.log(["no children", this]);
579 var items = tree.items;
582 //Roo.log(items.length);
584 if (!skip_children) {
585 for(var i =0;i < items.length;i++) {
586 // Roo.log(['add child', items[i]]);
587 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
593 //Roo.log("fire childrenrendered");
595 cn.fireEvent('childrenrendered', this);
601 * Set the element that will be used to show or hide
603 setVisibilityEl : function(el)
605 this.visibilityEl = el;
609 * Get the element that will be used to show or hide
611 getVisibilityEl : function()
613 if (typeof(this.visibilityEl) == 'object') {
614 return this.visibilityEl;
617 if (typeof(this.visibilityEl) == 'string') {
618 return this.visibilityEl == 'parent' ? this.parent().getEl() : this.getEl();
625 * Show a component - removes 'hidden' class
629 if(!this.getVisibilityEl()){
633 this.getVisibilityEl().removeClass(['hidden','d-none']);
635 this.fireEvent('show', this);
640 * Hide a component - adds 'hidden' class
644 if(!this.getVisibilityEl()){
648 this.getVisibilityEl().addClass(['hidden','d-none']);
650 this.fireEvent('hide', this);
663 * @class Roo.bootstrap.Element
664 * @extends Roo.bootstrap.Component
665 * @children Roo.bootstrap.Component
666 * Bootstrap Element class (basically a DIV used to make random stuff )
668 * @cfg {String} html contents of the element
669 * @cfg {String} tag tag of the element
670 * @cfg {String} cls class of the element
671 * @cfg {Boolean} preventDefault (true|false) default false
672 * @cfg {Boolean} clickable (true|false) default false
673 * @cfg {String} role default blank - set to button to force cursor pointer
677 * Create a new Element
678 * @param {Object} config The config object
681 Roo.bootstrap.Element = function(config){
682 Roo.bootstrap.Element.superclass.constructor.call(this, config);
688 * When a element is chick
689 * @param {Roo.bootstrap.Element} this
690 * @param {Roo.EventObject} e
698 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
703 preventDefault: false,
708 getAutoCreate : function(){
712 // cls: this.cls, double assign in parent class Component.js :: onRender
715 if (this.role !== false) {
716 cfg.role = this.role;
722 initEvents: function()
724 Roo.bootstrap.Element.superclass.initEvents.call(this);
727 this.el.on('click', this.onClick, this);
733 onClick : function(e)
735 if(this.preventDefault){
739 this.fireEvent('click', this, e); // why was this double click before?
747 getValue : function()
749 return this.el.dom.innerHTML;
752 setValue : function(value)
754 this.el.dom.innerHTML = value;
769 * @class Roo.bootstrap.DropTarget
770 * @extends Roo.bootstrap.Element
771 * Bootstrap DropTarget class
773 * @cfg {string} name dropable name
776 * Create a new Dropable Area
777 * @param {Object} config The config object
780 Roo.bootstrap.DropTarget = function(config){
781 Roo.bootstrap.DropTarget.superclass.constructor.call(this, config);
787 * When a element is chick
788 * @param {Roo.bootstrap.Element} this
789 * @param {Roo.EventObject} e
795 Roo.extend(Roo.bootstrap.DropTarget, Roo.bootstrap.Element, {
798 getAutoCreate : function(){
803 initEvents: function()
805 Roo.bootstrap.DropTarget.superclass.initEvents.call(this);
806 this.dropZone = new Roo.dd.DropTarget(this.getEl(), {
809 drop : this.dragDrop.createDelegate(this),
810 enter : this.dragEnter.createDelegate(this),
811 out : this.dragOut.createDelegate(this),
812 over : this.dragOver.createDelegate(this)
816 this.dropZone.DDM.useCache = false // so data gets refreshed when we resize stuff
819 dragDrop : function(source,e,data)
821 // user has to decide how to impliment this.
824 //this.fireEvent('drop', this, source, e ,data);
828 dragEnter : function(n, dd, e, data)
830 // probably want to resize the element to match the dropped element..
832 this.originalSize = this.el.getSize();
833 this.el.setSize( n.el.getSize());
834 this.dropZone.DDM.refreshCache(this.name);
835 Roo.log([n, dd, e, data]);
838 dragOut : function(value)
840 // resize back to normal
842 this.el.setSize(this.originalSize);
843 this.dropZone.resetConstraints();
846 dragOver : function()
863 * @class Roo.bootstrap.Body
864 * @extends Roo.bootstrap.Component
865 * @children Roo.bootstrap.Component
866 * @parent none builder
867 * Bootstrap Body class
871 * @param {Object} config The config object
874 Roo.bootstrap.Body = function(config){
876 config = config || {};
878 Roo.bootstrap.Body.superclass.constructor.call(this, config);
879 this.el = Roo.get(config.el ? config.el : document.body );
880 if (this.cls && this.cls.length) {
881 Roo.get(document.body).addClass(this.cls);
885 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
887 is_body : true,// just to make sure it's constructed?
892 onRender : function(ct, position)
894 /* Roo.log("Roo.bootstrap.Body - onRender");
895 if (this.cls && this.cls.length) {
896 Roo.get(document.body).addClass(this.cls);
915 * @class Roo.bootstrap.ButtonGroup
916 * @extends Roo.bootstrap.Component
917 * Bootstrap ButtonGroup class
918 * @children Roo.bootstrap.Button Roo.bootstrap.form.Form
920 * @cfg {String} size lg | sm | xs (default empty normal)
921 * @cfg {String} align vertical | justified (default none)
922 * @cfg {String} direction up | down (default down)
923 * @cfg {Boolean} toolbar false | true
924 * @cfg {Boolean} btn true | false
929 * @param {Object} config The config object
932 Roo.bootstrap.ButtonGroup = function(config){
933 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
936 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
944 getAutoCreate : function(){
950 cfg.html = this.html || cfg.html;
961 if (['vertical','justified'].indexOf(this.align)!==-1) {
962 cfg.cls = 'btn-group-' + this.align;
964 if (this.align == 'justified') {
965 console.log(this.items);
969 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
970 cfg.cls += ' btn-group-' + this.size;
973 if (this.direction == 'up') {
974 cfg.cls += ' dropup' ;
980 * Add a button to the group (similar to NavItem API.)
982 addItem : function(cfg)
984 var cn = new Roo.bootstrap.Button(cfg);
986 cn.parentId = this.id;
987 cn.onRender(this.el, null);
1001 * @class Roo.bootstrap.Button
1002 * @extends Roo.bootstrap.Component
1003 * Bootstrap Button class
1004 * @cfg {String} html The button content
1005 * @cfg {String} weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default
1006 * @cfg {String} badge_weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default (same as button)
1007 * @cfg {Boolean} outline default false (except for weight=default which emulates old behaveiour with an outline)
1008 * @cfg {String} size (lg|sm|xs)
1009 * @cfg {String} tag (a|input|submit)
1010 * @cfg {String} href empty or href
1011 * @cfg {Boolean} disabled default false;
1012 * @cfg {Boolean} isClose default false;
1013 * @cfg {String} glyphicon depricated - use fa
1014 * @cfg {String} fa fontawesome icon - eg. 'comment' - without the fa/fas etc..
1015 * @cfg {String} badge text for badge
1016 * @cfg {String} theme (default|glow)
1017 * @cfg {Boolean} inverse dark themed version
1018 * @cfg {Boolean} toggle is it a slidy toggle button
1019 * @cfg {Boolean} pressed default null - if the button ahs active state
1020 * @cfg {String} ontext text for on slidy toggle state
1021 * @cfg {String} offtext text for off slidy toggle state
1022 * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.)
1023 * @cfg {Boolean} removeClass remove the standard class..
1024 * @cfg {String} target (_self|_blank|_parent|_top|other) target for a href.
1025 * @cfg {Boolean} grpup if parent is a btn group - then it turns it into a toogleGroup.
1026 * @cfg {Roo.bootstrap.menu.Menu} menu a Menu
1029 * Create a new button
1030 * @param {Object} config The config object
1034 Roo.bootstrap.Button = function(config){
1035 Roo.bootstrap.Button.superclass.constructor.call(this, config);
1041 * When a button is pressed
1042 * @param {Roo.bootstrap.Button} btn
1043 * @param {Roo.EventObject} e
1048 * When a button is double clicked
1049 * @param {Roo.bootstrap.Button} btn
1050 * @param {Roo.EventObject} e
1055 * After the button has been toggles
1056 * @param {Roo.bootstrap.Button} btn
1057 * @param {Roo.EventObject} e
1058 * @param {boolean} pressed (also available as button.pressed)
1064 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
1085 preventDefault: true,
1094 getAutoCreate : function(){
1102 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
1103 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
1104 this.tag = 'button';
1108 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
1110 if (this.toggle == true) {
1113 cls: 'slider-frame roo-button',
1117 'data-on-text':'ON',
1118 'data-off-text':'OFF',
1119 cls: 'slider-button',
1124 // why are we validating the weights?
1125 if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) {
1126 cfg.cls += ' ' + this.weight;
1133 cfg.cls += ' close';
1135 cfg["aria-hidden"] = true;
1137 cfg.html = "×";
1143 if (this.theme==='default') {
1144 cfg.cls = 'btn roo-button';
1146 //if (this.parentType != 'Navbar') {
1147 this.weight = this.weight.length ? this.weight : 'default';
1149 if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) {
1151 var outline = this.outline || this.weight == 'default' ? 'outline-' : '';
1152 var weight = this.weight == 'default' ? 'secondary' : this.weight;
1153 cfg.cls += ' btn-' + outline + weight;
1154 if (this.weight == 'default') {
1156 cfg.cls += ' btn-' + this.weight;
1159 } else if (this.theme==='glow') {
1162 cfg.cls = 'btn-glow roo-button';
1164 if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) {
1166 cfg.cls += ' ' + this.weight;
1172 this.cls += ' inverse';
1176 if (this.active || this.pressed === true) {
1177 cfg.cls += ' active';
1180 if (this.disabled) {
1181 cfg.disabled = 'disabled';
1185 Roo.log('changing to ul' );
1187 this.glyphicon = 'caret';
1188 if (Roo.bootstrap.version == 4) {
1189 this.fa = 'caret-down';
1194 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
1196 //gsRoo.log(this.parentType);
1197 if (this.parentType === 'Navbar' && !this.parent().bar) {
1198 Roo.log('changing to li?');
1207 href : this.href || '#'
1210 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
1211 cfg.cls += ' dropdown';
1218 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
1220 if (this.glyphicon) {
1221 cfg.html = ' ' + cfg.html;
1226 cls: 'glyphicon glyphicon-' + this.glyphicon
1231 cfg.html = ' ' + cfg.html;
1236 cls: 'fa fas fa-' + this.fa
1246 // cfg.cls='btn roo-button';
1250 var value = cfg.html;
1255 cls: 'glyphicon glyphicon-' + this.glyphicon,
1262 cls: 'fa fas fa-' + this.fa,
1267 var bw = this.badge_weight.length ? this.badge_weight :
1268 (this.weight.length ? this.weight : 'secondary');
1269 bw = bw == 'default' ? 'secondary' : bw;
1275 cls: 'badge badge-' + bw,
1284 cfg.cls += ' dropdown';
1285 cfg.html = typeof(cfg.html) != 'undefined' ?
1286 cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
1289 if (cfg.tag !== 'a' && this.href !== '') {
1290 throw "Tag must be a to set href.";
1291 } else if (this.href.length > 0) {
1292 cfg.href = this.href;
1295 if(this.removeClass){
1300 cfg.target = this.target;
1305 initEvents: function() {
1306 // Roo.log('init events?');
1307 // Roo.log(this.el.dom);
1310 if (typeof (this.menu) != 'undefined') {
1311 this.menu.parentType = this.xtype;
1312 this.menu.triggerEl = this.el;
1313 this.addxtype(Roo.apply({}, this.menu));
1317 if (this.el.hasClass('roo-button')) {
1318 this.el.on('click', this.onClick, this);
1319 this.el.on('dblclick', this.onDblClick, this);
1321 this.el.select('.roo-button').on('click', this.onClick, this);
1322 this.el.select('.roo-button').on('dblclick', this.onDblClick, this);
1326 if(this.removeClass){
1327 this.el.on('click', this.onClick, this);
1330 if (this.group === true) {
1331 if (this.pressed === false || this.pressed === true) {
1334 this.pressed = false;
1335 this.setActive(this.pressed);
1340 this.el.enableDisplayMode();
1343 onClick : function(e)
1345 if (this.disabled) {
1349 Roo.log('button on click ');
1350 if(this.href === '' || this.preventDefault){
1359 this.setActive(true);
1360 var pi = this.parent().items;
1361 for (var i = 0;i < pi.length;i++) {
1362 if (this == pi[i]) {
1365 if (pi[i].el.hasClass('roo-button')) {
1366 pi[i].setActive(false);
1369 this.fireEvent('click', this, e);
1373 if (this.pressed === true || this.pressed === false) {
1374 this.toggleActive(e);
1378 this.fireEvent('click', this, e);
1380 onDblClick: function(e)
1382 if (this.disabled) {
1385 if(this.preventDefault){
1388 this.fireEvent('dblclick', this, e);
1391 * Enables this button
1395 this.disabled = false;
1396 this.el.removeClass('disabled');
1397 this.el.dom.removeAttribute("disabled");
1401 * Disable this button
1403 disable : function()
1405 this.disabled = true;
1406 this.el.addClass('disabled');
1407 this.el.attr("disabled", "disabled")
1410 * sets the active state on/off,
1411 * @param {Boolean} state (optional) Force a particular state
1413 setActive : function(v) {
1415 this.el[v ? 'addClass' : 'removeClass']('active');
1419 * toggles the current active state
1421 toggleActive : function(e)
1423 this.setActive(!this.pressed); // this modifies pressed...
1424 this.fireEvent('toggle', this, e, this.pressed);
1427 * get the current active state
1428 * @return {boolean} true if it's active
1430 isActive : function()
1432 return this.el.hasClass('active');
1435 * set the text of the first selected button
1437 setText : function(str)
1439 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
1442 * get the text of the first selected button
1444 getText : function()
1446 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
1449 setWeight : function(str)
1451 this.el.removeClass(Roo.bootstrap.Button.weights.map(function(w) { return 'btn-' + w; } ) );
1452 this.el.removeClass(Roo.bootstrap.Button.weights.map(function(w) { return 'btn-outline-' + w; } ) );
1454 var outline = this.outline ? 'outline-' : '';
1455 if (str == 'default') {
1456 this.el.addClass('btn-default btn-outline-secondary');
1459 this.el.addClass('btn-' + outline + str);
1464 // fixme - this is probably generic bootstrap - should go in some kind of enum file.. - like sizes.
1466 Roo.bootstrap.Button.weights = [
1486 * @class Roo.bootstrap.Column
1487 * @extends Roo.bootstrap.Component
1488 * @children Roo.bootstrap.Component
1489 * Bootstrap Column class
1490 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
1491 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
1492 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
1493 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
1494 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
1495 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
1496 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
1497 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
1500 * @cfg {Boolean} hidden (true|false) hide the element
1501 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1502 * @cfg {String} fa (ban|check|...) font awesome icon
1503 * @cfg {Number} fasize (1|2|....) font awsome size
1505 * @cfg {String} icon (info-sign|check|...) glyphicon name
1507 * @cfg {String} html content of column.
1510 * Create a new Column
1511 * @param {Object} config The config object
1514 Roo.bootstrap.Column = function(config){
1515 Roo.bootstrap.Column.superclass.constructor.call(this, config);
1518 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
1536 getAutoCreate : function(){
1537 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
1545 var sizes = ['xs','sm','md','lg'];
1546 sizes.map(function(size ,ix){
1547 //Roo.log( size + ':' + settings[size]);
1549 if (settings[size+'off'] !== false) {
1550 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1553 if (settings[size] === false) {
1557 if (!settings[size]) { // 0 = hidden
1558 cfg.cls += ' hidden-' + size + ' hidden-' + size + '-down';
1560 for (var i = ix; i > -1; i--) {
1561 cfg.cls += ' d-' + sizes[i] + '-none';
1567 cfg.cls += ' col-' + size + '-' + settings[size] + (
1568 size == 'xs' ? (' col-' + settings[size] ) : '' // bs4 col-{num} replaces col-xs
1574 cfg.cls += ' hidden';
1577 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1578 cfg.cls +=' alert alert-' + this.alert;
1582 if (this.html.length) {
1583 cfg.html = this.html;
1587 if (this.fasize > 1) {
1588 fasize = ' fa-' + this.fasize + 'x';
1590 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1595 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1614 * @class Roo.bootstrap.Container
1615 * @extends Roo.bootstrap.Component
1616 * @children Roo.bootstrap.Component
1618 * Bootstrap Container class
1619 * @cfg {Boolean} jumbotron is it a jumbotron element
1620 * @cfg {String} html content of element
1621 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1622 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1623 * @cfg {String} header content of header (for panel)
1624 * @cfg {String} footer content of footer (for panel)
1625 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1626 * @cfg {String} tag (header|aside|section) type of HTML tag.
1627 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1628 * @cfg {String} fa font awesome icon
1629 * @cfg {String} icon (info-sign|check|...) glyphicon name
1630 * @cfg {Boolean} hidden (true|false) hide the element
1631 * @cfg {Boolean} expandable (true|false) default false
1632 * @cfg {Boolean} expanded (true|false) default true
1633 * @cfg {String} rheader contet on the right of header
1634 * @cfg {Boolean} clickable (true|false) default false
1638 * Create a new Container
1639 * @param {Object} config The config object
1642 Roo.bootstrap.Container = function(config){
1643 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1649 * After the panel has been expand
1651 * @param {Roo.bootstrap.Container} this
1656 * After the panel has been collapsed
1658 * @param {Roo.bootstrap.Container} this
1663 * When a element is chick
1664 * @param {Roo.bootstrap.Container} this
1665 * @param {Roo.EventObject} e
1671 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1689 getChildContainer : function() {
1695 if (this.panel.length) {
1696 return this.el.select('.panel-body',true).first();
1703 getAutoCreate : function(){
1706 tag : this.tag || 'div',
1710 if (this.jumbotron) {
1711 cfg.cls = 'jumbotron';
1716 // - this is applied by the parent..
1718 // cfg.cls = this.cls + '';
1721 if (this.sticky.length) {
1723 var bd = Roo.get(document.body);
1724 if (!bd.hasClass('bootstrap-sticky')) {
1725 bd.addClass('bootstrap-sticky');
1726 Roo.select('html',true).setStyle('height', '100%');
1729 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1733 if (this.well.length) {
1734 switch (this.well) {
1737 cfg.cls +=' well well-' +this.well;
1746 cfg.cls += ' hidden';
1750 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1751 cfg.cls +=' alert alert-' + this.alert;
1756 if (this.panel.length) {
1757 cfg.cls += ' panel panel-' + this.panel;
1759 if (this.header.length) {
1763 if(this.expandable){
1765 cfg.cls = cfg.cls + ' expandable';
1769 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1777 cls : 'panel-title',
1778 html : (this.expandable ? ' ' : '') + this.header
1782 cls: 'panel-header-right',
1788 cls : 'panel-heading',
1789 style : this.expandable ? 'cursor: pointer' : '',
1797 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1802 if (this.footer.length) {
1804 cls : 'panel-footer',
1813 body.html = this.html || cfg.html;
1814 // prefix with the icons..
1816 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1819 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1824 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1825 cfg.cls = 'container';
1831 initEvents: function()
1833 if(this.expandable){
1834 var headerEl = this.headerEl();
1837 headerEl.on('click', this.onToggleClick, this);
1842 this.el.on('click', this.onClick, this);
1847 onToggleClick : function()
1849 var headerEl = this.headerEl();
1865 if(this.fireEvent('expand', this)) {
1867 this.expanded = true;
1869 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1871 this.el.select('.panel-body',true).first().removeClass('hide');
1873 var toggleEl = this.toggleEl();
1879 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1884 collapse : function()
1886 if(this.fireEvent('collapse', this)) {
1888 this.expanded = false;
1890 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1891 this.el.select('.panel-body',true).first().addClass('hide');
1893 var toggleEl = this.toggleEl();
1899 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1903 toggleEl : function()
1905 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1909 return this.el.select('.panel-heading .fa',true).first();
1912 headerEl : function()
1914 if(!this.el || !this.panel.length || !this.header.length){
1918 return this.el.select('.panel-heading',true).first()
1923 if(!this.el || !this.panel.length){
1927 return this.el.select('.panel-body',true).first()
1930 titleEl : function()
1932 if(!this.el || !this.panel.length || !this.header.length){
1936 return this.el.select('.panel-title',true).first();
1939 setTitle : function(v)
1941 var titleEl = this.titleEl();
1947 titleEl.dom.innerHTML = v;
1950 getTitle : function()
1953 var titleEl = this.titleEl();
1959 return titleEl.dom.innerHTML;
1962 setRightTitle : function(v)
1964 var t = this.el.select('.panel-header-right',true).first();
1970 t.dom.innerHTML = v;
1973 onClick : function(e)
1977 this.fireEvent('click', this, e);
1982 * @class Roo.bootstrap.Card
1983 * @extends Roo.bootstrap.Component
1984 * @children Roo.bootstrap.Component
1986 * Bootstrap Card class - note this has children as CardHeader/ImageTop/Footer.. - which should really be listed properties?
1989 * possible... may not be implemented..
1990 * @cfg {String} header_image src url of image.
1991 * @cfg {String|Object} header
1992 * @cfg {Number} header_size (0|1|2|3|4|5) H1 or H2 etc.. 0 indicates default
1993 * @cfg {Number} header_weight (primary|secondary|success|info|warning|danger|light|dark)
1995 * @cfg {String} title
1996 * @cfg {String} subtitle
1997 * @cfg {String|Boolean} html -- html contents - or just use children.. use false to hide it..
1998 * @cfg {String} footer
2000 * @cfg {String} weight (primary|warning|info|danger|secondary|success|light|dark)
2002 * @cfg {String} margin (0|1|2|3|4|5|auto)
2003 * @cfg {String} margin_top (0|1|2|3|4|5|auto)
2004 * @cfg {String} margin_bottom (0|1|2|3|4|5|auto)
2005 * @cfg {String} margin_left (0|1|2|3|4|5|auto)
2006 * @cfg {String} margin_right (0|1|2|3|4|5|auto)
2007 * @cfg {String} margin_x (0|1|2|3|4|5|auto)
2008 * @cfg {String} margin_y (0|1|2|3|4|5|auto)
2010 * @cfg {String} padding (0|1|2|3|4|5)
2011 * @cfg {String} padding_top (0|1|2|3|4|5)next_to_card
2012 * @cfg {String} padding_bottom (0|1|2|3|4|5)
2013 * @cfg {String} padding_left (0|1|2|3|4|5)
2014 * @cfg {String} padding_right (0|1|2|3|4|5)
2015 * @cfg {String} padding_x (0|1|2|3|4|5)
2016 * @cfg {String} padding_y (0|1|2|3|4|5)
2018 * @cfg {String} display (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2019 * @cfg {String} display_xs (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2020 * @cfg {String} display_sm (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2021 * @cfg {String} display_lg (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2022 * @cfg {String} display_xl (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
2024 * @config {Boolean} dragable if this card can be dragged.
2025 * @config {String} drag_group group for drag
2026 * @config {Boolean} dropable if this card can recieve other cards being dropped onto it..
2027 * @config {String} drop_group group for drag
2029 * @config {Boolean} collapsable can the body be collapsed.
2030 * @config {Boolean} collapsed is the body collapsed when rendered...
2031 * @config {Boolean} rotateable can the body be rotated by clicking on it..
2032 * @config {Boolean} rotated is the body rotated when rendered...
2035 * Create a new Container
2036 * @param {Object} config The config object
2039 Roo.bootstrap.Card = function(config){
2040 Roo.bootstrap.Card.superclass.constructor.call(this, config);
2046 * When a element a card is dropped
2047 * @param {Roo.bootstrap.Card} this
2050 * @param {Roo.bootstrap.Card} move_card the card being dropped?
2051 * @param {String} position 'above' or 'below'
2052 * @param {Roo.bootstrap.Card} next_to_card What card position is relative to of 'false' for empty list.
2058 * When a element a card is rotate
2059 * @param {Roo.bootstrap.Card} this
2060 * @param {Roo.Element} n the node being dropped?
2061 * @param {Boolean} rotate status
2066 * When a card element is dragged over ready to drop (return false to block dropable)
2067 * @param {Roo.bootstrap.Card} this
2068 * @param {Object} data from dragdrop
2076 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component, {
2081 margin: '', /// may be better in component?
2111 collapsable : false,
2120 childContainer : false,
2121 dropEl : false, /// the dom placeholde element that indicates drop location.
2122 containerEl: false, // body container
2123 bodyEl: false, // card-body
2124 headerContainerEl : false, //
2126 header_imageEl : false,
2129 layoutCls : function()
2133 Roo.log(this.margin_bottom.length);
2134 ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
2135 // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
2137 if (('' + t['margin' + (v.length ? '_' : '') + v]).length) {
2138 cls += ' m' + (v.length ? v[0] : '') + '-' + t['margin' + (v.length ? '_' : '') + v];
2140 if (('' + t['padding' + (v.length ? '_' : '') + v]).length) {
2141 cls += ' p' + (v.length ? v[0] : '') + '-' + t['padding' + (v.length ? '_' : '') + v];
2145 ['', 'xs', 'sm', 'lg', 'xl'].forEach(function(v) {
2146 if (('' + t['display' + (v.length ? '_' : '') + v]).length) {
2147 cls += ' d' + (v.length ? '-' : '') + v + '-' + t['display' + (v.length ? '_' : '') + v]
2151 // more generic support?
2159 // Roo.log("Call onRender: " + this.xtype);
2160 /* We are looking at something like this.
2162 <img src="..." class="card-img-top" alt="...">
2163 <div class="card-body">
2164 <h5 class="card-title">Card title</h5>
2165 <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
2167 >> this bit is really the body...
2168 <div> << we will ad dthis in hopefully it will not break shit.
2170 ** card text does not actually have any styling...
2172 <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>
2175 <a href="#" class="card-link">Card link</a>
2178 <div class="card-footer">
2179 <small class="text-muted">Last updated 3 mins ago</small>
2183 getAutoCreate : function(){
2191 if (this.weight.length && this.weight != 'light') {
2192 cfg.cls += ' text-white';
2194 cfg.cls += ' text-dark'; // need as it's nested..
2196 if (this.weight.length) {
2197 cfg.cls += ' bg-' + this.weight;
2200 cfg.cls += ' ' + this.layoutCls();
2203 var hdr_ctr = false;
2204 if (this.header.length) {
2206 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
2207 cls : 'card-header ' + (this.header_weight ? 'bg-' + this.header_weight : ''),
2215 cls : 'card-header d-none ' + (this.header_weight ? 'bg-' + this.header_weight : ''),
2221 if (this.collapsable) {
2224 cls : 'd-block user-select-none',
2228 cls : 'roo-collapse-toggle fa fa-chevron-down float-right ' + (this.collapsed ? 'collapsed' : '')
2233 hdr.cn.push(hdr_ctr);
2238 cls: 'roo-card-header-ctr' + ( this.header.length ? '' : ' d-none'),
2243 if (this.header_image.length) {
2246 cls : 'card-img-top',
2247 src: this.header_image // escape?
2252 cls : 'card-img-top d-none'
2258 cls : 'card-body' + (this.html === false ? ' d-none' : ''),
2262 if (this.collapsable || this.rotateable) {
2265 cls : 'roo-collapsable collapse ' + (this.collapsed || this.rotated ? '' : 'show'),
2272 if (this.title.length) {
2276 src: this.title // escape?
2280 if (this.subtitle.length) {
2284 src: this.subtitle // escape?
2290 cls : 'roo-card-body-ctr'
2293 if (this.html.length) {
2299 // fixme ? handle objects?
2301 if (this.footer.length) {
2304 cls : 'card-footer ' + (this.rotated ? 'd-none' : ''),
2309 cfg.cn.push({cls : 'card-footer d-none'});
2318 getCardHeader : function()
2320 var ret = this.el.select('.card-header',true).first();
2321 if (ret.hasClass('d-none')) {
2322 ret.removeClass('d-none');
2327 getCardFooter : function()
2329 var ret = this.el.select('.card-footer',true).first();
2330 if (ret.hasClass('d-none')) {
2331 ret.removeClass('d-none');
2336 getCardImageTop : function()
2338 var ret = this.header_imageEl;
2339 if (ret.hasClass('d-none')) {
2340 ret.removeClass('d-none');
2346 getChildContainer : function()
2352 return this.el.select('.roo-card-body-ctr',true).first();
2355 initEvents: function()
2357 this.bodyEl = this.el.select('.card-body',true).first();
2358 this.containerEl = this.getChildContainer();
2360 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
2361 containerScroll: true,
2362 ddGroup: this.drag_group || 'default_card_drag_group'
2364 this.dragZone.getDragData = this.getDragData.createDelegate(this);
2366 if (this.dropable) {
2367 this.dropZone = new Roo.dd.DropZone(this.el.select('.card-body',true).first() , {
2368 containerScroll: true,
2369 ddGroup: this.drop_group || 'default_card_drag_group'
2371 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
2372 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
2373 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
2374 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
2375 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
2378 if (this.collapsable) {
2379 this.el.select('.card-header',true).on('click', this.onToggleCollapse, this);
2381 if (this.rotateable) {
2382 this.el.select('.card-header',true).on('click', this.onToggleRotate, this);
2384 this.collapsableEl = this.el.select('.roo-collapsable',true).first();
2386 this.footerEl = this.el.select('.card-footer',true).first();
2387 this.collapsableToggleEl = this.el.select('.roo-collapse-toggle',true).first();
2388 this.headerContainerEl = this.el.select('.roo-card-header-ctr',true).first();
2389 this.headerEl = this.el.select('.card-header',true).first();
2392 this.el.addClass('roo-card-rotated');
2393 this.fireEvent('rotate', this, true);
2395 this.header_imageEl = this.el.select('.card-img-top',true).first();
2396 this.header_imageEl.on('load', this.onHeaderImageLoad, this );
2399 getDragData : function(e)
2401 var target = this.getEl();
2403 //this.handleSelection(e);
2408 nodes: this.getEl(),
2413 dragData.ddel = target.dom ; // the div element
2414 Roo.log(target.getWidth( ));
2415 dragData.ddel.style.width = target.getWidth() + 'px';
2422 * Part of the Roo.dd.DropZone interface. If no target node is found, the
2423 * whole Element becomes the target, and this causes the drop gesture to append.
2425 * Returns an object:
2428 position : 'below' or 'above'
2429 card : relateive to card OBJECT (or true for no cards listed)
2430 items_n : relative to nth item in list
2431 card_n : relative to nth card in list
2436 getTargetFromEvent : function(e, dragged_card_el)
2438 var target = e.getTarget();
2439 while ((target !== null) && (target.parentNode != this.containerEl.dom)) {
2440 target = target.parentNode;
2451 //Roo.log([ 'target' , target ? target.id : '--nothing--']);
2452 // see if target is one of the 'cards'...
2455 //Roo.log(this.items.length);
2458 var last_card_n = 0;
2460 for (var i = 0;i< this.items.length;i++) {
2462 if (!this.items[i].el.hasClass('card')) {
2465 pos = this.getDropPoint(e, this.items[i].el.dom);
2467 cards_len = ret.cards.length;
2468 //Roo.log(this.items[i].el.dom.id);
2469 ret.cards.push(this.items[i]);
2471 if (ret.card_n < 0 && pos == 'above') {
2472 ret.position = cards_len > 0 ? 'below' : pos;
2473 ret.items_n = i > 0 ? i - 1 : 0;
2474 ret.card_n = cards_len > 0 ? cards_len - 1 : 0;
2475 ret.card = ret.cards[ret.card_n];
2478 if (!ret.cards.length) {
2480 ret.position = 'below';
2484 // could not find a card.. stick it at the end..
2485 if (ret.card_n < 0) {
2486 ret.card_n = last_card_n;
2487 ret.card = ret.cards[last_card_n];
2488 ret.items_n = this.items.indexOf(ret.cards[last_card_n]);
2489 ret.position = 'below';
2492 if (this.items[ret.items_n].el == dragged_card_el) {
2496 if (ret.position == 'below') {
2497 var card_after = ret.card_n+1 == ret.cards.length ? false : ret.cards[ret.card_n+1];
2499 if (card_after && card_after.el == dragged_card_el) {
2506 var card_before = ret.card_n > 0 ? ret.cards[ret.card_n-1] : false;
2508 if (card_before && card_before.el == dragged_card_el) {
2515 onNodeEnter : function(n, dd, e, data){
2518 onNodeOver : function(n, dd, e, data)
2521 var target_info = this.getTargetFromEvent(e,data.source.el);
2522 if (target_info === false) {
2523 this.dropPlaceHolder('hide');
2526 Roo.log(['getTargetFromEvent', target_info ]);
2529 if (this.fireEvent('cardover', this, [ data ]) === false) {
2533 this.dropPlaceHolder('show', target_info,data);
2537 onNodeOut : function(n, dd, e, data){
2538 this.dropPlaceHolder('hide');
2541 onNodeDrop : function(n, dd, e, data)
2544 // call drop - return false if
2546 // this could actually fail - if the Network drops..
2547 // we will ignore this at present..- client should probably reload
2548 // the whole set of cards if stuff like that fails.
2551 var info = this.getTargetFromEvent(e,data.source.el);
2552 if (info === false) {
2555 this.dropPlaceHolder('hide');
2559 this.acceptCard(data.source, info.position, info.card, info.items_n);
2563 firstChildCard : function()
2565 for (var i = 0;i< this.items.length;i++) {
2567 if (!this.items[i].el.hasClass('card')) {
2570 return this.items[i];
2572 return this.items.length ? this.items[this.items.length-1] : false; // don't try and put stuff after the cards...
2577 * - card.acceptCard(move_card, info.position, info.card, info.items_n);
2579 acceptCard : function(move_card, position, next_to_card )
2581 if (this.fireEvent("drop", this, move_card, position, next_to_card) === false) {
2585 var to_items_n = next_to_card ? this.items.indexOf(next_to_card) : 0;
2587 move_card.parent().removeCard(move_card);
2590 var dom = move_card.el.dom;
2591 dom.style.width = ''; // clear with - which is set by drag.
2593 if (next_to_card !== false && next_to_card !== true && next_to_card.el.dom.parentNode) {
2594 var cardel = next_to_card.el.dom;
2596 if (position == 'above' ) {
2597 cardel.parentNode.insertBefore(dom, cardel);
2598 } else if (cardel.nextSibling) {
2599 cardel.parentNode.insertBefore(dom,cardel.nextSibling);
2601 cardel.parentNode.append(dom);
2604 // card container???
2605 this.containerEl.dom.append(dom);
2608 //FIXME HANDLE card = true
2610 // add this to the correct place in items.
2612 // remove Card from items.
2615 if (this.items.length) {
2617 //Roo.log([info.items_n, info.position, this.items.length]);
2618 for (var i =0; i < this.items.length; i++) {
2619 if (i == to_items_n && position == 'above') {
2620 nitems.push(move_card);
2622 nitems.push(this.items[i]);
2623 if (i == to_items_n && position == 'below') {
2624 nitems.push(move_card);
2627 this.items = nitems;
2628 Roo.log(this.items);
2630 this.items.push(move_card);
2633 move_card.parentId = this.id;
2639 removeCard : function(c)
2641 this.items = this.items.filter(function(e) { return e != c });
2644 dom.parentNode.removeChild(dom);
2645 dom.style.width = ''; // clear with - which is set by drag.
2650 /** Decide whether to drop above or below a View node. */
2651 getDropPoint : function(e, n, dd)
2656 if (n == this.containerEl.dom) {
2659 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
2660 var c = t + (b - t) / 2;
2661 var y = Roo.lib.Event.getPageY(e);
2668 onToggleCollapse : function(e)
2670 if (this.collapsed) {
2671 this.el.select('.roo-collapse-toggle').removeClass('collapsed');
2672 this.collapsableEl.addClass('show');
2673 this.collapsed = false;
2676 this.el.select('.roo-collapse-toggle').addClass('collapsed');
2677 this.collapsableEl.removeClass('show');
2678 this.collapsed = true;
2683 onToggleRotate : function(e)
2685 this.collapsableEl.removeClass('show');
2686 this.footerEl.removeClass('d-none');
2687 this.el.removeClass('roo-card-rotated');
2688 this.el.removeClass('d-none');
2691 this.collapsableEl.addClass('show');
2692 this.rotated = false;
2693 this.fireEvent('rotate', this, this.rotated);
2696 this.el.addClass('roo-card-rotated');
2697 this.footerEl.addClass('d-none');
2698 this.el.select('.roo-collapsable').removeClass('show');
2700 this.rotated = true;
2701 this.fireEvent('rotate', this, this.rotated);
2705 dropPlaceHolder: function (action, info, data)
2707 if (this.dropEl === false) {
2708 this.dropEl = Roo.DomHelper.append(this.containerEl, {
2712 this.dropEl.removeClass(['d-none', 'd-block']);
2713 if (action == 'hide') {
2715 this.dropEl.addClass('d-none');
2718 // FIXME - info.card == true!!!
2719 this.dropEl.dom.parentNode.removeChild(this.dropEl.dom);
2721 if (info.card !== true) {
2722 var cardel = info.card.el.dom;
2724 if (info.position == 'above') {
2725 cardel.parentNode.insertBefore(this.dropEl.dom, cardel);
2726 } else if (cardel.nextSibling) {
2727 cardel.parentNode.insertBefore(this.dropEl.dom,cardel.nextSibling);
2729 cardel.parentNode.append(this.dropEl.dom);
2732 // card container???
2733 this.containerEl.dom.append(this.dropEl.dom);
2736 this.dropEl.addClass('d-block roo-card-dropzone');
2738 this.dropEl.setHeight( Roo.get(data.ddel).getHeight() );
2745 setHeaderText: function(html)
2748 if (this.headerContainerEl) {
2749 this.headerContainerEl.dom.innerHTML = html;
2752 onHeaderImageLoad : function(ev, he)
2754 if (!this.header_image_fit_square) {
2758 var hw = he.naturalHeight / he.naturalWidth;
2761 //var w = he.dom.naturalWidth;
2764 he.style.position = 'relative';
2766 var nw = (ww * (1/hw));
2767 Roo.get(he).setSize( ww * (1/hw), ww);
2768 he.style.left = ((ww - nw)/ 2) + 'px';
2769 he.style.position = 'relative';
2780 * Card header - holder for the card header elements.
2785 * @class Roo.bootstrap.CardHeader
2786 * @extends Roo.bootstrap.Element
2787 * @parent Roo.bootstrap.Card
2788 * @children Roo.bootstrap.Component
2789 * Bootstrap CardHeader class
2791 * Create a new Card Header - that you can embed children into
2792 * @param {Object} config The config object
2795 Roo.bootstrap.CardHeader = function(config){
2796 Roo.bootstrap.CardHeader.superclass.constructor.call(this, config);
2799 Roo.extend(Roo.bootstrap.CardHeader, Roo.bootstrap.Element, {
2802 container_method : 'getCardHeader'
2815 * Card footer - holder for the card footer elements.
2820 * @class Roo.bootstrap.CardFooter
2821 * @extends Roo.bootstrap.Element
2822 * @parent Roo.bootstrap.Card
2823 * @children Roo.bootstrap.Component
2824 * Bootstrap CardFooter class
2827 * Create a new Card Footer - that you can embed children into
2828 * @param {Object} config The config object
2831 Roo.bootstrap.CardFooter = function(config){
2832 Roo.bootstrap.CardFooter.superclass.constructor.call(this, config);
2835 Roo.extend(Roo.bootstrap.CardFooter, Roo.bootstrap.Element, {
2838 container_method : 'getCardFooter'
2851 * Card header - holder for the card header elements.
2856 * @class Roo.bootstrap.CardImageTop
2857 * @extends Roo.bootstrap.Element
2858 * @parent Roo.bootstrap.Card
2859 * @children Roo.bootstrap.Component
2860 * Bootstrap CardImageTop class
2863 * Create a new Card Image Top container
2864 * @param {Object} config The config object
2867 Roo.bootstrap.CardImageTop = function(config){
2868 Roo.bootstrap.CardImageTop.superclass.constructor.call(this, config);
2871 Roo.extend(Roo.bootstrap.CardImageTop, Roo.bootstrap.Element, {
2874 container_method : 'getCardImageTop'
2889 * @class Roo.bootstrap.ButtonUploader
2890 * @extends Roo.bootstrap.Button
2891 * Bootstrap Button Uploader class - it's a button which when you add files to it
2894 * @cfg {Number} errorTimeout default 3000
2895 * @cfg {Array} images an array of ?? Img objects ??? when loading existing files..
2896 * @cfg {Array} html The button text.
2897 * @cfg {Boolean} multiple (default true) Should the upload allow multiple files to be uploaded.
2900 * Create a new CardUploader
2901 * @param {Object} config The config object
2904 Roo.bootstrap.ButtonUploader = function(config){
2908 Roo.bootstrap.ButtonUploader.superclass.constructor.call(this, config);
2914 * @event beforeselect
2915 * When button is pressed, before show upload files dialog is shown
2916 * @param {Roo.bootstrap.UploaderButton} this
2919 'beforeselect' : true,
2921 * @event fired when files have been selected,
2922 * When a the download link is clicked
2923 * @param {Roo.bootstrap.UploaderButton} this
2924 * @param {Array} Array of files that have been uploaded
2931 Roo.extend(Roo.bootstrap.ButtonUploader, Roo.bootstrap.Button, {
2934 errorTimeout : 3000,
2938 fileCollection : false,
2943 getAutoCreate : function()
2950 Roo.bootstrap.Button.prototype.getAutoCreate.call(this)
2958 initEvents : function()
2961 Roo.bootstrap.Button.prototype.initEvents.call(this);
2967 this.urlAPI = (window.createObjectURL && window) ||
2968 (window.URL && URL.revokeObjectURL && URL) ||
2969 (window.webkitURL && webkitURL);
2974 cls : 'd-none roo-card-upload-selector'
2977 if (this.multiple) {
2978 im.multiple = 'multiple';
2980 this.selectorEl = Roo.get(document.body).createChild(im); // so it does not capture click event for navitem.
2982 //this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
2984 this.selectorEl.on('change', this.onFileSelected, this);
2991 onClick : function(e)
2995 if ( this.fireEvent('beforeselect', this) === false) {
2999 this.selectorEl.dom.click();
3003 onFileSelected : function(e)
3007 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
3010 var files = Array.prototype.slice.call(this.selectorEl.dom.files);
3011 this.selectorEl.dom.value = '';// hopefully reset..
3013 this.fireEvent('uploaded', this, files );
3021 * addCard - add an Attachment to the uploader
3022 * @param data - the data about the image to upload
3026 title : "Title of file",
3027 is_uploaded : false,
3028 src : "http://.....",
3029 srcfile : { the File upload object },
3030 mimetype : file.type,
3033 .. any other data...
3058 * @class Roo.bootstrap.Img
3059 * @extends Roo.bootstrap.Component
3060 * Bootstrap Img class
3061 * @cfg {Boolean} imgResponsive false | true
3062 * @cfg {String} border rounded | circle | thumbnail
3063 * @cfg {String} src image source
3064 * @cfg {String} alt image alternative text
3065 * @cfg {String} href a tag href
3066 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
3067 * @cfg {String} xsUrl xs image source
3068 * @cfg {String} smUrl sm image source
3069 * @cfg {String} mdUrl md image source
3070 * @cfg {String} lgUrl lg image source
3071 * @cfg {Boolean} backgroundContain (use style background and contain image in content)
3074 * Create a new Input
3075 * @param {Object} config The config object
3078 Roo.bootstrap.Img = function(config){
3079 Roo.bootstrap.Img.superclass.constructor.call(this, config);
3085 * The img click event for the img.
3086 * @param {Roo.EventObject} e
3091 * The when any image loads
3092 * @param {Roo.EventObject} e
3098 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
3100 imgResponsive: true,
3109 backgroundContain : false,
3111 getAutoCreate : function()
3113 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
3114 return this.createSingleImg();
3119 cls: 'roo-image-responsive-group',
3124 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
3126 if(!_this[size + 'Url']){
3132 cls: (_this.imgResponsive) ? 'img-responsive' : '',
3133 html: _this.html || cfg.html,
3134 src: _this[size + 'Url']
3137 img.cls += ' roo-image-responsive-' + size;
3139 var s = ['xs', 'sm', 'md', 'lg'];
3141 s.splice(s.indexOf(size), 1);
3143 Roo.each(s, function(ss){
3144 img.cls += ' hidden-' + ss;
3147 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
3148 cfg.cls += ' img-' + _this.border;
3152 cfg.alt = _this.alt;
3165 a.target = _this.target;
3169 cfg.cn.push((_this.href) ? a : img);
3176 createSingleImg : function()
3180 cls: (this.imgResponsive) ? 'img-responsive' : '',
3182 src : Roo.BLANK_IMAGE_URL // just incase src get's set to undefined?!?
3185 if (this.backgroundContain) {
3186 cfg.cls += ' background-contain';
3189 cfg.html = this.html || cfg.html;
3191 if (this.backgroundContain) {
3192 cfg.style="background-image: url(" + this.src + ')';
3194 cfg.src = this.src || cfg.src;
3197 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
3198 cfg.cls += ' img-' + this.border;
3215 a.target = this.target;
3220 return (this.href) ? a : cfg;
3223 initEvents: function()
3226 this.el.on('click', this.onClick, this);
3228 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
3229 this.el.on('load', this.onImageLoad, this);
3231 // not sure if this works.. not tested
3232 this.el.select('img', true).on('load', this.onImageLoad, this);
3237 onClick : function(e)
3239 Roo.log('img onclick');
3240 this.fireEvent('click', this, e);
3242 onImageLoad: function(e)
3244 Roo.log('img load');
3245 this.fireEvent('load', this, e);
3249 * Sets the url of the image - used to update it
3250 * @param {String} url the url of the image
3253 setSrc : function(url)
3257 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
3258 if (this.backgroundContain) {
3259 this.el.dom.style.backgroundImage = 'url(' + url + ')';
3261 this.el.dom.src = url;
3266 this.el.select('img', true).first().dom.src = url;
3282 * @class Roo.bootstrap.Link
3283 * @extends Roo.bootstrap.Component
3284 * @children Roo.bootstrap.Component
3285 * Bootstrap Link Class (eg. '<a href>')
3287 * @cfg {String} alt image alternative text
3288 * @cfg {String} href a tag href
3289 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
3290 * @cfg {String} html the content of the link.
3291 * @cfg {String} anchor name for the anchor link
3292 * @cfg {String} fa - favicon
3294 * @cfg {Boolean} preventDefault (true | false) default false
3298 * Create a new Input
3299 * @param {Object} config The config object
3302 Roo.bootstrap.Link = function(config){
3303 Roo.bootstrap.Link.superclass.constructor.call(this, config);
3309 * The img click event for the img.
3310 * @param {Roo.EventObject} e
3316 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
3320 preventDefault: false,
3326 getAutoCreate : function()
3328 var html = this.html || '';
3330 if (this.fa !== false) {
3331 html = '<i class="fa fa-' + this.fa + '"></i>';
3336 // anchor's do not require html/href...
3337 if (this.anchor === false) {
3339 cfg.href = this.href || '#';
3341 cfg.name = this.anchor;
3342 if (this.html !== false || this.fa !== false) {
3345 if (this.href !== false) {
3346 cfg.href = this.href;
3350 if(this.alt !== false){
3355 if(this.target !== false) {
3356 cfg.target = this.target;
3362 initEvents: function() {
3364 if(!this.href || this.preventDefault){
3365 this.el.on('click', this.onClick, this);
3369 onClick : function(e)
3371 if(this.preventDefault){
3374 //Roo.log('img onclick');
3375 this.fireEvent('click', this, e);
3388 * @class Roo.bootstrap.Header
3389 * @extends Roo.bootstrap.Component
3390 * @children Roo.bootstrap.Component
3391 * Bootstrap Header class
3394 * @cfg {String} html content of header
3395 * @cfg {Number} level (1|2|3|4|5|6) default 1
3398 * Create a new Header
3399 * @param {Object} config The config object
3403 Roo.bootstrap.Header = function(config){
3404 Roo.bootstrap.Header.superclass.constructor.call(this, config);
3407 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
3415 getAutoCreate : function(){
3420 tag: 'h' + (1 *this.level),
3421 html: this.html || ''
3432 * @class Roo.bootstrap.MenuMgr
3434 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
3437 Roo.bootstrap.menu.Manager = function(){
3438 var menus, active, groups = {}, attached = false, lastShow = new Date();
3440 // private - called when first menu is created
3443 active = new Roo.util.MixedCollection();
3444 Roo.get(document).addKeyListener(27, function(){
3445 if(active.length > 0){
3453 if(active && active.length > 0){
3454 var c = active.clone();
3464 if(active.length < 1){
3465 Roo.get(document).un("mouseup", onMouseDown);
3473 var last = active.last();
3474 lastShow = new Date();
3477 Roo.get(document).on("mouseup", onMouseDown);
3482 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
3483 m.parentMenu.activeChild = m;
3484 }else if(last && last.isVisible()){
3485 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
3490 function onBeforeHide(m){
3492 m.activeChild.hide();
3494 if(m.autoHideTimer){
3495 clearTimeout(m.autoHideTimer);
3496 delete m.autoHideTimer;
3501 function onBeforeShow(m){
3502 var pm = m.parentMenu;
3503 if(!pm && !m.allowOtherMenus){
3505 }else if(pm && pm.activeChild && active != m){
3506 pm.activeChild.hide();
3510 // private this should really trigger on mouseup..
3511 function onMouseDown(e){
3512 Roo.log("on Mouse Up");
3514 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
3515 Roo.log("MenuManager hideAll");
3524 function onBeforeCheck(mi, state){
3526 var g = groups[mi.group];
3527 for(var i = 0, l = g.length; i < l; i++){
3529 g[i].setChecked(false);
3538 * Hides all menus that are currently visible
3540 hideAll : function(){
3545 register : function(menu){
3549 menus[menu.id] = menu;
3550 menu.on("beforehide", onBeforeHide);
3551 menu.on("hide", onHide);
3552 menu.on("beforeshow", onBeforeShow);
3553 menu.on("show", onShow);
3555 if(g && menu.events["checkchange"]){
3559 groups[g].push(menu);
3560 menu.on("checkchange", onCheck);
3565 * Returns a {@link Roo.menu.Menu} object
3566 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
3567 * be used to generate and return a new Menu instance.
3569 get : function(menu){
3570 if(typeof menu == "string"){ // menu id
3572 }else if(menu.events){ // menu instance
3575 /*else if(typeof menu.length == 'number'){ // array of menu items?
3576 return new Roo.bootstrap.Menu({items:menu});
3577 }else{ // otherwise, must be a config
3578 return new Roo.bootstrap.Menu(menu);
3585 unregister : function(menu){
3586 delete menus[menu.id];
3587 menu.un("beforehide", onBeforeHide);
3588 menu.un("hide", onHide);
3589 menu.un("beforeshow", onBeforeShow);
3590 menu.un("show", onShow);
3592 if(g && menu.events["checkchange"]){
3593 groups[g].remove(menu);
3594 menu.un("checkchange", onCheck);
3599 registerCheckable : function(menuItem){
3600 var g = menuItem.group;
3605 groups[g].push(menuItem);
3606 menuItem.on("beforecheckchange", onBeforeCheck);
3611 unregisterCheckable : function(menuItem){
3612 var g = menuItem.group;
3614 groups[g].remove(menuItem);
3615 menuItem.un("beforecheckchange", onBeforeCheck);
3621 * @class Roo.bootstrap.menu.Menu
3622 * @extends Roo.bootstrap.Component
3624 * @children Roo.bootstrap.menu.Item Roo.bootstrap.menu.Separator
3626 * Bootstrap Menu class - container for MenuItems - normally has to be added to a object that supports the menu property
3628 * @cfg {String} type (dropdown|treeview|submenu) type of menu
3629 * @cfg {bool} hidden if the menu should be hidden when rendered.
3630 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
3631 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
3632 * @cfg {bool} hideTrigger (true|false) default false - hide the carret for trigger.
3633 * @cfg {String} align default tl-bl? == below - how the menu should be aligned.
3637 * @param {Object} config The config objectQ
3641 Roo.bootstrap.menu.Menu = function(config){
3643 if (config.type == 'treeview') {
3644 // normally menu's are drawn attached to the document to handle layering etc..
3645 // however treeview (used by the docs menu is drawn into the parent element)
3646 this.container_method = 'getChildContainer';
3649 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
3650 if (this.registerMenu && this.type != 'treeview') {
3651 Roo.bootstrap.menu.Manager.register(this);
3658 * Fires before this menu is displayed (return false to block)
3659 * @param {Roo.menu.Menu} this
3664 * Fires before this menu is hidden (return false to block)
3665 * @param {Roo.menu.Menu} this
3670 * Fires after this menu is displayed
3671 * @param {Roo.menu.Menu} this
3676 * Fires after this menu is hidden
3677 * @param {Roo.menu.Menu} this
3682 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
3683 * @param {Roo.menu.Menu} this
3684 * @param {Roo.menu.Item} menuItem The menu item that was clicked
3685 * @param {Roo.EventObject} e
3690 * Fires when the mouse is hovering over this menu
3691 * @param {Roo.menu.Menu} this
3692 * @param {Roo.EventObject} e
3693 * @param {Roo.menu.Item} menuItem The menu item that was clicked
3698 * Fires when the mouse exits this menu
3699 * @param {Roo.menu.Menu} this
3700 * @param {Roo.EventObject} e
3701 * @param {Roo.menu.Item} menuItem The menu item that was clicked
3706 * Fires when a menu item contained in this menu is clicked
3707 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
3708 * @param {Roo.EventObject} e
3712 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
3715 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
3719 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
3722 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
3724 registerMenu : true,
3726 menuItems :false, // stores the menu items..
3736 container_method : 'getDocumentBody', // so the menu is rendered on the body and zIndex works.
3738 hideTrigger : false,
3743 getChildContainer : function() {
3747 getAutoCreate : function(){
3749 //if (['right'].indexOf(this.align)!==-1) {
3750 // cfg.cn[1].cls += ' pull-right'
3755 cls : 'dropdown-menu shadow' ,
3756 style : 'z-index:1000'
3760 if (this.type === 'submenu') {
3761 cfg.cls = 'submenu active';
3763 if (this.type === 'treeview') {
3764 cfg.cls = 'treeview-menu';
3769 initEvents : function() {
3771 // Roo.log("ADD event");
3772 // Roo.log(this.triggerEl.dom);
3773 if (this.triggerEl) {
3775 this.triggerEl.on('click', this.onTriggerClick, this);
3777 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
3779 if (!this.hideTrigger) {
3780 if (this.triggerEl.hasClass('nav-item') && this.triggerEl.select('.nav-link',true).length) {
3781 // dropdown toggle on the 'a' in BS4?
3782 this.triggerEl.select('.nav-link',true).first().addClass('dropdown-toggle');
3784 this.triggerEl.addClass('dropdown-toggle');
3790 this.el.on('touchstart' , this.onTouch, this);
3792 this.el.on('click' , this.onClick, this);
3794 this.el.on("mouseover", this.onMouseOver, this);
3795 this.el.on("mouseout", this.onMouseOut, this);
3799 findTargetItem : function(e)
3801 var t = e.getTarget(".dropdown-menu-item", this.el, true);
3805 //Roo.log(t); Roo.log(t.id);
3807 //Roo.log(this.menuitems);
3808 return this.menuitems.get(t.id);
3810 //return this.items.get(t.menuItemId);
3816 onTouch : function(e)
3818 Roo.log("menu.onTouch");
3819 //e.stopEvent(); this make the user popdown broken
3823 onClick : function(e)
3825 Roo.log("menu.onClick");
3827 var t = this.findTargetItem(e);
3828 if(!t || t.isContainer){
3833 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
3834 if(t == this.activeItem && t.shouldDeactivate(e)){
3835 this.activeItem.deactivate();
3836 delete this.activeItem;
3840 this.setActiveItem(t, true);
3848 Roo.log('pass click event');
3852 this.fireEvent("click", this, t, e);
3856 if(!t.href.length || t.href == '#'){
3857 (function() { _this.hide(); }).defer(100);
3862 onMouseOver : function(e){
3863 var t = this.findTargetItem(e);
3866 // if(t.canActivate && !t.disabled){
3867 // this.setActiveItem(t, true);
3871 this.fireEvent("mouseover", this, e, t);
3873 isVisible : function(){
3874 return !this.hidden;
3876 onMouseOut : function(e){
3877 var t = this.findTargetItem(e);
3880 // if(t == this.activeItem && t.shouldDeactivate(e)){
3881 // this.activeItem.deactivate();
3882 // delete this.activeItem;
3885 this.fireEvent("mouseout", this, e, t);
3890 * Displays this menu relative to another element
3891 * @param {String/HTMLElement/Roo.Element} element The element to align to
3892 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
3893 * the element (defaults to this.defaultAlign)
3894 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
3896 show : function(el, pos, parentMenu)
3898 if (false === this.fireEvent("beforeshow", this)) {
3899 Roo.log("show canceled");
3902 this.parentMenu = parentMenu;
3906 this.el.addClass('show'); // show otherwise we do not know how big we are..
3908 var xy = this.el.getAlignToXY(el, pos);
3910 // bl-tl << left align below
3911 // tl-bl << left align
3913 if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
3914 // if it goes to far to the right.. -> align left.
3915 xy = this.el.getAlignToXY(el, this.align.replace('/l/g', 'r'))
3918 // was left align - go right?
3919 xy = this.el.getAlignToXY(el, this.align.replace('/r/g', 'l'))
3922 // goes down the bottom
3923 if(this.el.getHeight() + xy[1] >= Roo.lib.Dom.getViewHeight() ||
3925 var a = this.align.replace('?', '').split('-');
3926 xy = this.el.getAlignToXY(el, a[1] + '-' + a[0] + '?')
3930 this.showAt( xy , parentMenu, false);
3933 * Displays this menu at a specific xy position
3934 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
3935 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
3937 showAt : function(xy, parentMenu, /* private: */_e){
3938 this.parentMenu = parentMenu;
3943 this.fireEvent("beforeshow", this);
3944 //xy = this.el.adjustForConstraints(xy);
3948 this.hideMenuItems();
3949 this.hidden = false;
3950 if (this.triggerEl) {
3951 this.triggerEl.addClass('open');
3954 this.el.addClass('show');
3958 // reassign x when hitting right
3960 // reassign y when hitting bottom
3962 // but the list may align on trigger left or trigger top... should it be a properity?
3964 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
3969 this.fireEvent("show", this);
3975 this.doFocus.defer(50, this);
3979 doFocus : function(){
3981 this.focusEl.focus();
3986 * Hides this menu and optionally all parent menus
3987 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
3989 hide : function(deep)
3991 if (false === this.fireEvent("beforehide", this)) {
3992 Roo.log("hide canceled");
3995 this.hideMenuItems();
3996 if(this.el && this.isVisible()){
3998 if(this.activeItem){
3999 this.activeItem.deactivate();
4000 this.activeItem = null;
4002 if (this.triggerEl) {
4003 this.triggerEl.removeClass('open');
4006 this.el.removeClass('show');
4008 this.fireEvent("hide", this);
4010 if(deep === true && this.parentMenu){
4011 this.parentMenu.hide(true);
4015 onTriggerClick : function(e)
4017 Roo.log('trigger click');
4019 var target = e.getTarget();
4021 Roo.log(target.nodeName.toLowerCase());
4023 if(target.nodeName.toLowerCase() === 'i'){
4029 onTriggerPress : function(e)
4031 Roo.log('trigger press');
4032 //Roo.log(e.getTarget());
4033 // Roo.log(this.triggerEl.dom);
4035 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
4036 var pel = Roo.get(e.getTarget());
4037 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
4038 Roo.log('is treeview or dropdown?');
4042 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
4046 if (this.isVisible()) {
4052 this.show(this.triggerEl, this.align, false);
4055 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
4062 hideMenuItems : function()
4064 Roo.log("hide Menu Items");
4069 this.el.select('.open',true).each(function(aa) {
4071 aa.removeClass('open');
4075 addxtypeChild : function (tree, cntr) {
4076 var comp= Roo.bootstrap.menu.Menu.superclass.addxtypeChild.call(this, tree, cntr);
4078 this.menuitems.add(comp);
4090 this.getEl().dom.innerHTML = '';
4091 this.menuitems.clear();
4097 * @class Roo.bootstrap.menu.Item
4098 * @extends Roo.bootstrap.Component
4099 * @children Roo.bootstrap.Button Roo.bootstrap.ButtonUploader Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Container
4100 * @parent Roo.bootstrap.menu.Menu
4102 * Bootstrap MenuItem class
4104 * @cfg {String} html the menu label
4105 * @cfg {String} href the link
4106 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
4107 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
4108 * @cfg {Boolean} active used on sidebars to highlight active itesm
4109 * @cfg {String} fa favicon to show on left of menu item.
4110 * @cfg {Roo.bootsrap.Menu} menu the child menu.
4114 * Create a new MenuItem
4115 * @param {Object} config The config object
4119 Roo.bootstrap.menu.Item = function(config){
4120 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
4125 * The raw click event for the entire grid.
4126 * @param {Roo.bootstrap.menu.Item} this
4127 * @param {Roo.EventObject} e
4133 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
4137 preventDefault: false,
4138 isContainer : false,
4142 getAutoCreate : function(){
4144 if(this.isContainer){
4147 cls: 'dropdown-menu-item '
4157 cls : 'dropdown-item',
4162 if (this.fa !== false) {
4165 cls : 'fa fa-' + this.fa
4174 cls: 'dropdown-menu-item',
4177 if (this.parent().type == 'treeview') {
4178 cfg.cls = 'treeview-menu';
4181 cfg.cls += ' active';
4186 anc.href = this.href || cfg.cn[0].href ;
4187 ctag.html = this.html || cfg.cn[0].html ;
4191 initEvents: function()
4193 if (this.parent().type == 'treeview') {
4194 this.el.select('a').on('click', this.onClick, this);
4198 this.menu.parentType = this.xtype;
4199 this.menu.triggerEl = this.el;
4200 this.menu = this.addxtype(Roo.apply({}, this.menu));
4204 onClick : function(e)
4206 //Roo.log('item on click ');
4208 if(this.href === false || this.preventDefault){
4211 //this.parent().hideMenuItems();
4213 this.fireEvent('click', this, e);
4227 * @class Roo.bootstrap.menu.Separator
4228 * @extends Roo.bootstrap.Component
4230 * @parent Roo.bootstrap.menu.Menu
4231 * Bootstrap Separator class
4234 * Create a new Separator
4235 * @param {Object} config The config object
4239 Roo.bootstrap.menu.Separator = function(config){
4240 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
4243 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
4245 getAutoCreate : function(){
4248 cls: 'dropdown-divider divider'
4264 * @class Roo.bootstrap.Modal
4265 * @extends Roo.bootstrap.Component
4266 * @parent none builder
4267 * @children Roo.bootstrap.Component
4268 * Bootstrap Modal class
4269 * @cfg {String} title Title of dialog
4270 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
4271 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
4272 * @cfg {Boolean} specificTitle default false
4273 * @cfg {Roo.bootstrap.Button} buttons[] Array of buttons or standard button set..
4274 * @cfg {String} buttonPosition (left|right|center) default right (DEPRICATED) - use mr-auto on buttons to put them on the left
4275 * @cfg {Boolean} animate default true
4276 * @cfg {Boolean} allow_close default true
4277 * @cfg {Boolean} fitwindow default false
4278 * @cfg {Boolean} bodyOverflow should the body element have overflow auto added default false
4279 * @cfg {Number} width fixed width - usefull for chrome extension only really.
4280 * @cfg {Number} height fixed height - usefull for chrome extension only really.
4281 * @cfg {String} size (sm|lg|xl) default empty
4282 * @cfg {Number} max_width set the max width of modal
4283 * @cfg {Boolean} editableTitle can the title be edited
4288 * Create a new Modal Dialog
4289 * @param {Object} config The config object
4292 Roo.bootstrap.Modal = function(config){
4293 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
4298 * The raw btnclick event for the button
4299 * @param {Roo.EventObject} e
4304 * Fire when dialog resize
4305 * @param {Roo.bootstrap.Modal} this
4306 * @param {Roo.EventObject} e
4310 * @event titlechanged
4311 * Fire when the editable title has been changed
4312 * @param {Roo.bootstrap.Modal} this
4313 * @param {Roo.EventObject} value
4315 "titlechanged" : true
4318 this.buttons = this.buttons || [];
4321 this.tmpl = Roo.factory(this.tmpl);
4326 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
4328 title : 'test dialog',
4338 specificTitle: false,
4340 buttonPosition: 'right',
4362 editableTitle : false,
4364 onRender : function(ct, position)
4366 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
4369 var cfg = Roo.apply({}, this.getAutoCreate());
4372 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
4374 //if (!cfg.name.length) {
4378 cfg.cls += ' ' + this.cls;
4381 cfg.style = this.style;
4383 this.el = Roo.get(document.body).createChild(cfg, position);
4385 //var type = this.el.dom.type;
4388 if(this.tabIndex !== undefined){
4389 this.el.dom.setAttribute('tabIndex', this.tabIndex);
4392 this.dialogEl = this.el.select('.modal-dialog',true).first();
4393 this.bodyEl = this.el.select('.modal-body',true).first();
4394 this.closeEl = this.el.select('.modal-header .close', true).first();
4395 this.headerEl = this.el.select('.modal-header',true).first();
4396 this.titleEl = this.el.select('.modal-title',true).first();
4397 this.footerEl = this.el.select('.modal-footer',true).first();
4399 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
4401 //this.el.addClass("x-dlg-modal");
4403 if (this.buttons.length) {
4404 Roo.each(this.buttons, function(bb) {
4405 var b = Roo.apply({}, bb);
4406 b.xns = b.xns || Roo.bootstrap;
4407 b.xtype = b.xtype || 'Button';
4408 if (typeof(b.listeners) == 'undefined') {
4409 b.listeners = { click : this.onButtonClick.createDelegate(this) };
4412 var btn = Roo.factory(b);
4414 btn.render(this.getButtonContainer());
4418 // render the children.
4421 if(typeof(this.items) != 'undefined'){
4422 var items = this.items;
4425 for(var i =0;i < items.length;i++) {
4426 // we force children not to montor widnow resize - as we do that for them.
4427 items[i].monitorWindowResize = false;
4428 nitems.push(this.addxtype(Roo.apply({}, items[i])));
4432 this.items = nitems;
4434 // where are these used - they used to be body/close/footer
4438 //this.el.addClass([this.fieldClass, this.cls]);
4442 getAutoCreate : function()
4444 // we will default to modal-body-overflow - might need to remove or make optional later.
4446 cls : 'modal-body ' + (this.bodyOverflow ? 'overflow-auto' : ''),
4447 html : this.html || ''
4452 cls : 'modal-title',
4456 if(this.specificTitle){ // WTF is this?
4461 if (this.allow_close && Roo.bootstrap.version == 3) {
4471 if (this.editableTitle) {
4473 cls: 'form-control roo-editable-title d-none',
4479 if (this.allow_close && Roo.bootstrap.version == 4) {
4489 if(this.size.length){
4490 size = 'modal-' + this.size;
4493 var footer = Roo.bootstrap.version == 3 ?
4495 cls : 'modal-footer',
4499 cls: 'btn-' + this.buttonPosition
4504 { // BS4 uses mr-auto on left buttons....
4505 cls : 'modal-footer'
4516 cls: "modal-dialog " + size,
4519 cls : "modal-content",
4522 cls : 'modal-header',
4537 modal.cls += ' fade';
4543 getChildContainer : function() {
4548 getButtonContainer : function() {
4550 return Roo.bootstrap.version == 4 ?
4551 this.el.select('.modal-footer',true).first()
4552 : this.el.select('.modal-footer div',true).first();
4555 initEvents : function()
4557 if (this.allow_close) {
4558 this.closeEl.on('click', this.hide, this);
4560 Roo.EventManager.onWindowResize(this.resize, this, true);
4561 if (this.editableTitle) {
4562 this.headerEditEl = this.headerEl.select('.form-control',true).first();
4563 this.headerEl.on('click', function() { this.toggleHeaderInput(true) } , this);
4564 this.headerEditEl.on('keyup', function(e) {
4565 if([ e.RETURN , e.TAB , e.ESC ].indexOf(e.keyCode) > -1) {
4566 this.toggleHeaderInput(false)
4569 this.headerEditEl.on('blur', function(e) {
4570 this.toggleHeaderInput(false)
4579 this.maskEl.setSize(
4580 Roo.lib.Dom.getViewWidth(true),
4581 Roo.lib.Dom.getViewHeight(true)
4584 if (this.fitwindow) {
4586 this.dialogEl.setStyle( { 'max-width' : '100%' });
4588 this.width || Roo.lib.Dom.getViewportWidth(true) - 30,
4589 this.height || Roo.lib.Dom.getViewportHeight(true) // catering margin-top 30 margin-bottom 30
4594 if(this.max_width !== 0) {
4596 var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
4599 this.setSize(w, this.height);
4603 if(this.max_height) {
4604 this.setSize(w,Math.min(
4606 Roo.lib.Dom.getViewportHeight(true) - 60
4612 if(!this.fit_content) {
4613 this.setSize(w, Roo.lib.Dom.getViewportHeight(true) - 60);
4617 this.setSize(w, Math.min(
4619 this.headerEl.getHeight() +
4620 this.footerEl.getHeight() +
4621 this.getChildHeight(this.bodyEl.dom.childNodes),
4622 Roo.lib.Dom.getViewportHeight(true) - 60)
4628 setSize : function(w,h)
4635 // any layout/border etc.. resize..
4637 this.items.forEach( function(e) {
4638 e.layout ? e.layout() : false;
4647 if (!this.rendered) {
4650 this.toggleHeaderInput(false);
4651 //this.el.setStyle('display', 'block');
4652 this.el.removeClass('hideing');
4653 this.el.dom.style.display='block';
4655 Roo.get(document.body).addClass('modal-open');
4657 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
4660 this.el.addClass('show');
4661 this.el.addClass('in');
4664 this.el.addClass('show');
4665 this.el.addClass('in');
4668 // not sure how we can show data in here..
4670 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
4673 Roo.get(document.body).addClass("x-body-masked");
4675 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
4676 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
4677 this.maskEl.dom.style.display = 'block';
4678 this.maskEl.addClass('show');
4683 this.fireEvent('show', this);
4685 // set zindex here - otherwise it appears to be ignored...
4686 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
4689 // this is for children that are... layout.Border
4691 this.items.forEach( function(e) {
4692 e.layout ? e.layout() : false;
4700 if(this.fireEvent("beforehide", this) !== false){
4702 this.maskEl.removeClass('show');
4704 this.maskEl.dom.style.display = '';
4705 Roo.get(document.body).removeClass("x-body-masked");
4706 this.el.removeClass('in');
4707 this.el.select('.modal-dialog', true).first().setStyle('transform','');
4709 if(this.animate){ // why
4710 this.el.addClass('hideing');
4711 this.el.removeClass('show');
4713 if (!this.el.hasClass('hideing')) {
4714 return; // it's been shown again...
4717 this.el.dom.style.display='';
4719 Roo.get(document.body).removeClass('modal-open');
4720 this.el.removeClass('hideing');
4724 this.el.removeClass('show');
4725 this.el.dom.style.display='';
4726 Roo.get(document.body).removeClass('modal-open');
4729 this.fireEvent('hide', this);
4732 isVisible : function()
4735 return this.el.hasClass('show') && !this.el.hasClass('hideing');
4739 addButton : function(str, cb)
4743 var b = Roo.apply({}, { html : str } );
4744 b.xns = b.xns || Roo.bootstrap;
4745 b.xtype = b.xtype || 'Button';
4746 if (typeof(b.listeners) == 'undefined') {
4747 b.listeners = { click : cb.createDelegate(this) };
4750 var btn = Roo.factory(b);
4752 btn.render(this.getButtonContainer());
4758 setDefaultButton : function(btn)
4760 //this.el.select('.modal-footer').()
4763 resizeTo: function(w,h)
4765 this.dialogEl.setWidth(w);
4767 var diff = this.headerEl.getHeight() + this.footerEl.getHeight() + 60; // dialog margin-bottom: 30
4769 this.bodyEl.setHeight(h - diff);
4771 this.fireEvent('resize', this);
4774 setContentSize : function(w, h)
4778 onButtonClick: function(btn,e)
4781 this.fireEvent('btnclick', btn.name, e);
4784 * Set the title of the Dialog
4785 * @param {String} str new Title
4787 setTitle: function(str) {
4788 this.titleEl.dom.innerHTML = str;
4792 * Set the body of the Dialog
4793 * @param {String} str new Title
4795 setBody: function(str) {
4796 this.bodyEl.dom.innerHTML = str;
4799 * Set the body of the Dialog using the template
4800 * @param {Obj} data - apply this data to the template and replace the body contents.
4802 applyBody: function(obj)
4805 Roo.log("Error - using apply Body without a template");
4808 this.tmpl.overwrite(this.bodyEl, obj);
4811 getChildHeight : function(child_nodes)
4815 child_nodes.length == 0
4820 var child_height = 0;
4822 for(var i = 0; i < child_nodes.length; i++) {
4825 * for modal with tabs...
4826 if(child_nodes[i].classList.contains('roo-layout-panel')) {
4828 var layout_childs = child_nodes[i].childNodes;
4830 for(var j = 0; j < layout_childs.length; j++) {
4832 if(layout_childs[j].classList.contains('roo-layout-panel-body')) {
4834 var layout_body_childs = layout_childs[j].childNodes;
4836 for(var k = 0; k < layout_body_childs.length; k++) {
4838 if(layout_body_childs[k].classList.contains('navbar')) {
4839 child_height += layout_body_childs[k].offsetHeight;
4843 if(layout_body_childs[k].classList.contains('roo-layout-tabs-body')) {
4845 var layout_body_tab_childs = layout_body_childs[k].childNodes;
4847 for(var m = 0; m < layout_body_tab_childs.length; m++) {
4849 if(layout_body_tab_childs[m].classList.contains('roo-layout-active-content')) {
4850 child_height += this.getChildHeight(layout_body_tab_childs[m].childNodes);
4865 child_height += child_nodes[i].offsetHeight;
4866 // Roo.log(child_nodes[i].offsetHeight);
4869 return child_height;
4871 toggleHeaderInput : function(is_edit)
4873 if (!this.editableTitle) {
4874 return; // not editable.
4876 if (is_edit && this.is_header_editing) {
4877 return; // already editing..
4881 this.headerEditEl.dom.value = this.title;
4882 this.headerEditEl.removeClass('d-none');
4883 this.headerEditEl.dom.focus();
4884 this.titleEl.addClass('d-none');
4886 this.is_header_editing = true;
4889 // flip back to not editing.
4890 this.title = this.headerEditEl.dom.value;
4891 this.headerEditEl.addClass('d-none');
4892 this.titleEl.removeClass('d-none');
4893 this.titleEl.dom.innerHTML = String.format('{0}', this.title);
4894 this.is_header_editing = false;
4895 this.fireEvent('titlechanged', this, this.title);
4904 Roo.apply(Roo.bootstrap.Modal, {
4906 * Button config that displays a single OK button
4915 * Button config that displays Yes and No buttons
4931 * Button config that displays OK and Cancel buttons
4946 * Button config that displays Yes, No and Cancel buttons
4971 * messagebox - can be used as a replace
4975 * @class Roo.MessageBox
4976 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
4980 Roo.Msg.alert('Status', 'Changes saved successfully.');
4982 // Prompt for user data:
4983 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
4985 // process text value...
4989 // Show a dialog using config options:
4991 title:'Save Changes?',
4992 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
4993 buttons: Roo.Msg.YESNOCANCEL,
5000 Roo.bootstrap.MessageBox = function(){
5001 var dlg, opt, mask, waitTimer;
5002 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
5003 var buttons, activeTextEl, bwidth;
5007 var handleButton = function(button){
5009 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
5013 var handleHide = function(){
5015 dlg.el.removeClass(opt.cls);
5018 // Roo.TaskMgr.stop(waitTimer);
5019 // waitTimer = null;
5024 var updateButtons = function(b){
5027 buttons["ok"].hide();
5028 buttons["cancel"].hide();
5029 buttons["yes"].hide();
5030 buttons["no"].hide();
5031 dlg.footerEl.hide();
5035 dlg.footerEl.show();
5036 for(var k in buttons){
5037 if(typeof buttons[k] != "function"){
5040 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
5041 width += buttons[k].el.getWidth()+15;
5051 var handleEsc = function(d, k, e){
5052 if(opt && opt.closable !== false){
5062 * Returns a reference to the underlying {@link Roo.BasicDialog} element
5063 * @return {Roo.BasicDialog} The BasicDialog element
5065 getDialog : function(){
5067 dlg = new Roo.bootstrap.Modal( {
5070 //constraintoviewport:false,
5072 //collapsible : false,
5077 //buttonAlign:"center",
5078 closeClick : function(){
5079 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
5082 handleButton("cancel");
5087 dlg.on("hide", handleHide);
5089 //dlg.addKeyListener(27, handleEsc);
5091 this.buttons = buttons;
5092 var bt = this.buttonText;
5093 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
5094 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
5095 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
5096 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
5098 bodyEl = dlg.bodyEl.createChild({
5100 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
5101 '<textarea class="roo-mb-textarea"></textarea>' +
5102 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
5104 msgEl = bodyEl.dom.firstChild;
5105 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
5106 textboxEl.enableDisplayMode();
5107 textboxEl.addKeyListener([10,13], function(){
5108 if(dlg.isVisible() && opt && opt.buttons){
5111 }else if(opt.buttons.yes){
5112 handleButton("yes");
5116 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
5117 textareaEl.enableDisplayMode();
5118 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
5119 progressEl.enableDisplayMode();
5121 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
5122 var pf = progressEl.dom.firstChild;
5124 pp = Roo.get(pf.firstChild);
5125 pp.setHeight(pf.offsetHeight);
5133 * Updates the message box body text
5134 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
5135 * the XHTML-compliant non-breaking space character '&#160;')
5136 * @return {Roo.MessageBox} This message box
5138 updateText : function(text)
5140 if(!dlg.isVisible() && !opt.width){
5141 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
5142 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
5144 msgEl.innerHTML = text || ' ';
5146 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
5147 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
5149 Math.min(opt.width || cw , this.maxWidth),
5150 Math.max(opt.minWidth || this.minWidth, bwidth)
5153 activeTextEl.setWidth(w);
5155 if(dlg.isVisible()){
5156 dlg.fixedcenter = false;
5158 // to big, make it scroll. = But as usual stupid IE does not support
5161 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
5162 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
5163 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
5165 bodyEl.dom.style.height = '';
5166 bodyEl.dom.style.overflowY = '';
5169 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
5171 bodyEl.dom.style.overflowX = '';
5174 dlg.setContentSize(w, bodyEl.getHeight());
5175 if(dlg.isVisible()){
5176 dlg.fixedcenter = true;
5182 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
5183 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
5184 * @param {Number} value Any number between 0 and 1 (e.g., .5)
5185 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
5186 * @return {Roo.MessageBox} This message box
5188 updateProgress : function(value, text){
5190 this.updateText(text);
5193 if (pp) { // weird bug on my firefox - for some reason this is not defined
5194 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
5195 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
5201 * Returns true if the message box is currently displayed
5202 * @return {Boolean} True if the message box is visible, else false
5204 isVisible : function(){
5205 return dlg && dlg.isVisible();
5209 * Hides the message box if it is displayed
5212 if(this.isVisible()){
5218 * Displays a new message box, or reinitializes an existing message box, based on the config options
5219 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
5220 * The following config object properties are supported:
5222 Property Type Description
5223 ---------- --------------- ------------------------------------------------------------------------------------
5224 animEl String/Element An id or Element from which the message box should animate as it opens and
5225 closes (defaults to undefined)
5226 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
5227 cancel:'Bar'}), or false to not show any buttons (defaults to false)
5228 closable Boolean False to hide the top-right close button (defaults to true). Note that
5229 progress and wait dialogs will ignore this property and always hide the
5230 close button as they can only be closed programmatically.
5231 cls String A custom CSS class to apply to the message box element
5232 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
5233 displayed (defaults to 75)
5234 fn Function A callback function to execute after closing the dialog. The arguments to the
5235 function will be btn (the name of the button that was clicked, if applicable,
5236 e.g. "ok"), and text (the value of the active text field, if applicable).
5237 Progress and wait dialogs will ignore this option since they do not respond to
5238 user actions and can only be closed programmatically, so any required function
5239 should be called by the same code after it closes the dialog.
5240 icon String A CSS class that provides a background image to be used as an icon for
5241 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
5242 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
5243 minWidth Number The minimum width in pixels of the message box (defaults to 100)
5244 modal Boolean False to allow user interaction with the page while the message box is
5245 displayed (defaults to true)
5246 msg String A string that will replace the existing message box body text (defaults
5247 to the XHTML-compliant non-breaking space character ' ')
5248 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
5249 progress Boolean True to display a progress bar (defaults to false)
5250 progressText String The text to display inside the progress bar if progress = true (defaults to '')
5251 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
5252 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
5253 title String The title text
5254 value String The string value to set into the active textbox element if displayed
5255 wait Boolean True to display a progress bar (defaults to false)
5256 width Number The width of the dialog in pixels
5263 msg: 'Please enter your address:',
5265 buttons: Roo.MessageBox.OKCANCEL,
5268 animEl: 'addAddressBtn'
5271 * @param {Object} config Configuration options
5272 * @return {Roo.MessageBox} This message box
5274 show : function(options)
5277 // this causes nightmares if you show one dialog after another
5278 // especially on callbacks..
5280 if(this.isVisible()){
5283 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
5284 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
5285 Roo.log("New Dialog Message:" + options.msg )
5286 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
5287 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
5290 var d = this.getDialog();
5292 d.setTitle(opt.title || " ");
5293 d.closeEl.setDisplayed(opt.closable !== false);
5294 activeTextEl = textboxEl;
5295 opt.prompt = opt.prompt || (opt.multiline ? true : false);
5300 textareaEl.setHeight(typeof opt.multiline == "number" ?
5301 opt.multiline : this.defaultTextHeight);
5302 activeTextEl = textareaEl;
5311 progressEl.setDisplayed(opt.progress === true);
5313 d.animate = false; // do not animate progress, as it may not have finished animating before we close it..
5315 this.updateProgress(0);
5316 activeTextEl.dom.value = opt.value || "";
5318 dlg.setDefaultButton(activeTextEl);
5320 var bs = opt.buttons;
5324 }else if(bs && bs.yes){
5325 db = buttons["yes"];
5327 dlg.setDefaultButton(db);
5329 bwidth = updateButtons(opt.buttons);
5330 this.updateText(opt.msg);
5332 d.el.addClass(opt.cls);
5334 d.proxyDrag = opt.proxyDrag === true;
5335 d.modal = opt.modal !== false;
5336 d.mask = opt.modal !== false ? mask : false;
5338 // force it to the end of the z-index stack so it gets a cursor in FF
5339 document.body.appendChild(dlg.el.dom);
5340 d.animateTarget = null;
5341 d.show(options.animEl);
5347 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
5348 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
5349 * and closing the message box when the process is complete.
5350 * @param {String} title The title bar text
5351 * @param {String} msg The message box body text
5352 * @return {Roo.MessageBox} This message box
5354 progress : function(title, msg){
5361 minWidth: this.minProgressWidth,
5368 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
5369 * If a callback function is passed it will be called after the user clicks the button, and the
5370 * id of the button that was clicked will be passed as the only parameter to the callback
5371 * (could also be the top-right close button).
5372 * @param {String} title The title bar text
5373 * @param {String} msg The message box body text
5374 * @param {Function} fn (optional) The callback function invoked after the message box is closed
5375 * @param {Object} scope (optional) The scope of the callback function
5376 * @return {Roo.MessageBox} This message box
5378 alert : function(title, msg, fn, scope)
5393 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
5394 * interaction while waiting for a long-running process to complete that does not have defined intervals.
5395 * You are responsible for closing the message box when the process is complete.
5396 * @param {String} msg The message box body text
5397 * @param {String} title (optional) The title bar text
5398 * @return {Roo.MessageBox} This message box
5400 wait : function(msg, title){
5411 waitTimer = Roo.TaskMgr.start({
5413 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
5421 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
5422 * If a callback function is passed it will be called after the user clicks either button, and the id of the
5423 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
5424 * @param {String} title The title bar text
5425 * @param {String} msg The message box body text
5426 * @param {Function} fn (optional) The callback function invoked after the message box is closed
5427 * @param {Object} scope (optional) The scope of the callback function
5428 * @return {Roo.MessageBox} This message box
5430 confirm : function(title, msg, fn, scope){
5434 buttons: this.YESNO,
5443 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
5444 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
5445 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
5446 * (could also be the top-right close button) and the text that was entered will be passed as the two
5447 * parameters to the callback.
5448 * @param {String} title The title bar text
5449 * @param {String} msg The message box body text
5450 * @param {Function} fn (optional) The callback function invoked after the message box is closed
5451 * @param {Object} scope (optional) The scope of the callback function
5452 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
5453 * property, or the height in pixels to create the textbox (defaults to false / single-line)
5454 * @return {Roo.MessageBox} This message box
5456 prompt : function(title, msg, fn, scope, multiline){
5460 buttons: this.OKCANCEL,
5465 multiline: multiline,
5472 * Button config that displays a single OK button
5477 * Button config that displays Yes and No buttons
5480 YESNO : {yes:true, no:true},
5482 * Button config that displays OK and Cancel buttons
5485 OKCANCEL : {ok:true, cancel:true},
5487 * Button config that displays Yes, No and Cancel buttons
5490 YESNOCANCEL : {yes:true, no:true, cancel:true},
5493 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
5496 defaultTextHeight : 75,
5498 * The maximum width in pixels of the message box (defaults to 600)
5503 * The minimum width in pixels of the message box (defaults to 100)
5508 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
5509 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
5512 minProgressWidth : 250,
5514 * An object containing the default button text strings that can be overriden for localized language support.
5515 * Supported properties are: ok, cancel, yes and no.
5516 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
5529 * Shorthand for {@link Roo.MessageBox}
5531 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
5532 Roo.Msg = Roo.Msg || Roo.MessageBox;
5541 * @class Roo.bootstrap.nav.Bar
5542 * @extends Roo.bootstrap.Component
5544 * Bootstrap Navbar class
5547 * Create a new Navbar
5548 * @param {Object} config The config object
5552 Roo.bootstrap.nav.Bar = function(config){
5553 Roo.bootstrap.nav.Bar.superclass.constructor.call(this, config);
5557 * @event beforetoggle
5558 * Fire before toggle the menu
5559 * @param {Roo.EventObject} e
5561 "beforetoggle" : true
5565 Roo.extend(Roo.bootstrap.nav.Bar, Roo.bootstrap.Component, {
5574 getAutoCreate : function(){
5577 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
5581 initEvents :function ()
5583 //Roo.log(this.el.select('.navbar-toggle',true));
5584 this.el.select('.navbar-toggle',true).on('click', this.onToggle , this);
5591 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
5593 var size = this.el.getSize();
5594 this.maskEl.setSize(size.width, size.height);
5595 this.maskEl.enableDisplayMode("block");
5604 getChildContainer : function()
5606 if (this.el && this.el.select('.collapse').getCount()) {
5607 return this.el.select('.collapse',true).first();
5622 onToggle : function()
5625 if(this.fireEvent('beforetoggle', this) === false){
5628 var ce = this.el.select('.navbar-collapse',true).first();
5630 if (!ce.hasClass('show')) {
5640 * Expand the navbar pulldown
5642 expand : function ()
5645 var ce = this.el.select('.navbar-collapse',true).first();
5646 if (ce.hasClass('collapsing')) {
5649 ce.dom.style.height = '';
5651 ce.addClass('in'); // old...
5652 ce.removeClass('collapse');
5653 ce.addClass('show');
5654 var h = ce.getHeight();
5656 ce.removeClass('show');
5657 // at this point we should be able to see it..
5658 ce.addClass('collapsing');
5660 ce.setHeight(0); // resize it ...
5661 ce.on('transitionend', function() {
5662 //Roo.log('done transition');
5663 ce.removeClass('collapsing');
5664 ce.addClass('show');
5665 ce.removeClass('collapse');
5667 ce.dom.style.height = '';
5668 }, this, { single: true} );
5670 ce.dom.scrollTop = 0;
5673 * Collapse the navbar pulldown
5675 collapse : function()
5677 var ce = this.el.select('.navbar-collapse',true).first();
5679 if (ce.hasClass('collapsing') || ce.hasClass('collapse') ) {
5680 // it's collapsed or collapsing..
5683 ce.removeClass('in'); // old...
5684 ce.setHeight(ce.getHeight());
5685 ce.removeClass('show');
5686 ce.addClass('collapsing');
5688 ce.on('transitionend', function() {
5689 ce.dom.style.height = '';
5690 ce.removeClass('collapsing');
5691 ce.addClass('collapse');
5692 }, this, { single: true} );
5712 * @class Roo.bootstrap.nav.Simplebar
5713 * @extends Roo.bootstrap.nav.Bar
5714 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container Roo.bootstrap.form.Form Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Link
5715 * Bootstrap Sidebar class
5717 * @cfg {Boolean} inverse is inverted color
5719 * @cfg {String} type (nav | pills | tabs)
5720 * @cfg {Boolean} arrangement stacked | justified
5721 * @cfg {String} align (left | right) alignment
5723 * @cfg {Boolean} main (true|false) main nav bar? default false
5724 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
5726 * @cfg {String} tag (header|footer|nav|div) default is nav
5728 * @cfg {String} weight (light|primary|secondary|success|danger|warning|info|dark|white) default is light.
5732 * Create a new Sidebar
5733 * @param {Object} config The config object
5737 Roo.bootstrap.nav.Simplebar = function(config){
5738 Roo.bootstrap.nav.Simplebar.superclass.constructor.call(this, config);
5741 Roo.extend(Roo.bootstrap.nav.Simplebar, Roo.bootstrap.nav.Bar, {
5757 getAutoCreate : function(){
5761 tag : this.tag || 'div',
5762 cls : 'navbar roo-navbar-simple' //navbar-expand-lg ??
5764 if (['light','white'].indexOf(this.weight) > -1) {
5765 cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
5767 cfg.cls += ' bg-' + this.weight;
5770 cfg.cls += ' navbar-inverse';
5774 // i'm not actually sure these are really used - normally we add a navGroup to a navbar
5776 if (Roo.bootstrap.version == 4 && this.xtype == 'NavSimplebar') {
5785 cls: 'nav nav-' + this.xtype,
5791 this.type = this.type || 'nav';
5792 if (['tabs','pills'].indexOf(this.type) != -1) {
5793 cfg.cn[0].cls += ' nav-' + this.type
5797 if (this.type!=='nav') {
5798 Roo.log('nav type must be nav/tabs/pills')
5800 cfg.cn[0].cls += ' navbar-nav'
5806 if (['stacked','justified'].indexOf(this.arrangement) != -1) {
5807 cfg.cn[0].cls += ' nav-' + this.arrangement;
5811 if (this.align === 'right') {
5812 cfg.cn[0].cls += ' navbar-right';
5837 * navbar-expand-md fixed-top
5841 * @class Roo.bootstrap.nav.Headerbar
5842 * @extends Roo.bootstrap.nav.Simplebar
5843 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container Roo.bootstrap.form.Form Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Link
5844 * Bootstrap Sidebar class
5846 * @cfg {String} brand what is brand
5847 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
5848 * @cfg {String} brand_href href of the brand
5849 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
5850 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
5851 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
5852 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
5855 * Create a new Sidebar
5856 * @param {Object} config The config object
5860 Roo.bootstrap.nav.Headerbar = function(config){
5861 Roo.bootstrap.nav.Headerbar.superclass.constructor.call(this, config);
5865 Roo.extend(Roo.bootstrap.nav.Headerbar, Roo.bootstrap.nav.Simplebar, {
5872 desktopCenter : false,
5875 getAutoCreate : function(){
5878 tag: this.nav || 'nav',
5879 cls: 'navbar navbar-expand-md',
5885 if (this.desktopCenter) {
5886 cn.push({cls : 'container', cn : []});
5894 cls: 'navbar-toggle navbar-toggler',
5895 'data-toggle': 'collapse',
5900 html: 'Toggle navigation'
5904 cls: 'icon-bar navbar-toggler-icon'
5917 cn.push( Roo.bootstrap.version == 4 ? btn : {
5919 cls: 'navbar-header',
5928 cls: Roo.bootstrap.version == 4 ? 'nav flex-row roo-navbar-collapse collapse navbar-collapse' : 'collapse navbar-collapse roo-navbar-collapse',
5932 cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
5934 if (['light','white'].indexOf(this.weight) > -1) {
5935 cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
5937 cfg.cls += ' bg-' + this.weight;
5940 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
5941 cfg.cls += ' navbar-' + this.position + ' ' + this.position ;
5943 // tag can override this..
5945 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
5948 if (this.brand !== '') {
5949 var cp = Roo.bootstrap.version == 4 ? cn : cn[0].cn;
5950 cp.unshift({ // changed from push ?? BS4 needs it at the start? - does this break or exsiting?
5952 href: this.brand_href ? this.brand_href : '#',
5953 cls: 'navbar-brand',
5961 cfg.cls += ' main-nav';
5969 getHeaderChildContainer : function()
5971 if (this.srButton && this.el.select('.navbar-header').getCount()) {
5972 return this.el.select('.navbar-header',true).first();
5975 return this.getChildContainer();
5978 getChildContainer : function()
5981 return this.el.select('.roo-navbar-collapse',true).first();
5986 initEvents : function()
5988 Roo.bootstrap.nav.Headerbar.superclass.initEvents.call(this);
5990 if (this.autohide) {
5995 Roo.get(document).on('scroll',function(e) {
5996 var ns = Roo.get(document).getScroll().top;
5997 var os = prevScroll;
6001 ft.removeClass('slideDown');
6002 ft.addClass('slideUp');
6005 ft.removeClass('slideUp');
6006 ft.addClass('slideDown');
6027 * @class Roo.bootstrap.nav.Sidebar
6028 * @extends Roo.bootstrap.nav.Bar
6029 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container Roo.bootstrap.form.Form Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Link
6030 * Bootstrap Sidebar class
6033 * Create a new Sidebar
6034 * @param {Object} config The config object
6038 Roo.bootstrap.nav.Sidebar = function(config){
6039 Roo.bootstrap.nav.Sidebar.superclass.constructor.call(this, config);
6042 Roo.extend(Roo.bootstrap.nav.Sidebar, Roo.bootstrap.nav.Bar, {
6044 sidebar : true, // used by Navbar Item and NavbarGroup at present...
6046 getAutoCreate : function(){
6051 cls: 'sidebar sidebar-nav'
6073 * @class Roo.bootstrap.nav.Group
6074 * @extends Roo.bootstrap.Component
6075 * @children Roo.bootstrap.nav.Item
6076 * Bootstrap NavGroup class
6077 * @cfg {String} align (left|right)
6078 * @cfg {Boolean} inverse
6079 * @cfg {String} type (nav|pills|tab) default nav
6080 * @cfg {String} navId - reference Id for navbar.
6081 * @cfg {Boolean} pilltype default true (turn to off to disable active toggle)
6084 * Create a new nav group
6085 * @param {Object} config The config object
6088 Roo.bootstrap.nav.Group = function(config){
6089 Roo.bootstrap.nav.Group.superclass.constructor.call(this, config);
6092 Roo.bootstrap.nav.Group.register(this);
6096 * Fires when the active item changes
6097 * @param {Roo.bootstrap.nav.Group} this
6098 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
6099 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
6106 Roo.extend(Roo.bootstrap.nav.Group, Roo.bootstrap.Component, {
6118 getAutoCreate : function()
6120 var cfg = Roo.apply({}, Roo.bootstrap.nav.Group.superclass.getAutoCreate.call(this));
6126 if (Roo.bootstrap.version == 4) {
6127 if (['tabs','pills'].indexOf(this.type) != -1) {
6128 cfg.cls += ' nav-' + this.type;
6130 // trying to remove so header bar can right align top?
6131 if (this.parent() && this.parent().xtype != 'NavHeaderbar') {
6132 // do not use on header bar...
6133 cfg.cls += ' navbar-nav';
6138 if (['tabs','pills'].indexOf(this.type) != -1) {
6139 cfg.cls += ' nav-' + this.type
6141 if (this.type !== 'nav') {
6142 Roo.log('nav type must be nav/tabs/pills')
6144 cfg.cls += ' navbar-nav'
6148 if (this.parent() && this.parent().sidebar) {
6151 cls: 'dashboard-menu sidebar-menu'
6157 if (this.form === true) {
6160 cls: 'navbar-form form-inline'
6162 //nav navbar-right ml-md-auto
6163 if (this.align === 'right') {
6164 cfg.cls += ' navbar-right ml-md-auto';
6166 cfg.cls += ' navbar-left';
6170 if (this.align === 'right') {
6171 cfg.cls += ' navbar-right ml-md-auto';
6173 cfg.cls += ' mr-auto';
6177 cfg.cls += ' navbar-inverse';
6185 * sets the active Navigation item
6186 * @param {Roo.bootstrap.nav.Item} the new current navitem
6188 setActiveItem : function(item)
6191 Roo.each(this.navItems, function(v){
6196 v.setActive(false, true);
6203 item.setActive(true, true);
6204 this.fireEvent('changed', this, item, prev);
6209 * gets the active Navigation item
6210 * @return {Roo.bootstrap.nav.Item} the current navitem
6212 getActive : function()
6216 Roo.each(this.navItems, function(v){
6227 indexOfNav : function()
6231 Roo.each(this.navItems, function(v,i){
6242 * adds a Navigation item
6243 * @param {Roo.bootstrap.nav.Item} the navitem to add
6245 addItem : function(cfg)
6247 if (this.form && Roo.bootstrap.version == 4) {
6250 var cn = new Roo.bootstrap.nav.Item(cfg);
6252 cn.parentId = this.id;
6253 cn.onRender(this.el, null);
6257 * register a Navigation item
6258 * @param {Roo.bootstrap.nav.Item} the navitem to add
6260 register : function(item)
6262 this.navItems.push( item);
6263 item.navId = this.navId;
6268 * clear all the Navigation item
6271 clearAll : function()
6274 this.el.dom.innerHTML = '';
6277 getNavItem: function(tabId)
6280 Roo.each(this.navItems, function(e) {
6281 if (e.tabId == tabId) {
6291 setActiveNext : function()
6293 var i = this.indexOfNav(this.getActive());
6294 if (i > this.navItems.length) {
6297 this.setActiveItem(this.navItems[i+1]);
6299 setActivePrev : function()
6301 var i = this.indexOfNav(this.getActive());
6305 this.setActiveItem(this.navItems[i-1]);
6307 clearWasActive : function(except) {
6308 Roo.each(this.navItems, function(e) {
6309 if (e.tabId != except.tabId && e.was_active) {
6310 e.was_active = false;
6317 getWasActive : function ()
6320 Roo.each(this.navItems, function(e) {
6335 Roo.apply(Roo.bootstrap.nav.Group, {
6339 * register a Navigation Group
6340 * @param {Roo.bootstrap.nav.Group} the navgroup to add
6342 register : function(navgrp)
6344 this.groups[navgrp.navId] = navgrp;
6348 * fetch a Navigation Group based on the navigation ID
6349 * @param {string} the navgroup to add
6350 * @returns {Roo.bootstrap.nav.Group} the navgroup
6352 get: function(navId) {
6353 if (typeof(this.groups[navId]) == 'undefined') {
6355 //this.register(new Roo.bootstrap.nav.Group({ navId : navId }));
6357 return this.groups[navId] ;
6365 * @class Roo.bootstrap.nav.Item
6366 * @extends Roo.bootstrap.Component
6367 * @children Roo.bootstrap.Container Roo.bootstrap.Button
6368 * @parent Roo.bootstrap.nav.Group
6370 * Bootstrap Navbar.NavItem class
6372 * @cfg {String} href link to
6373 * @cfg {String} button_weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default none
6374 * @cfg {Boolean} button_outline show and outlined button
6375 * @cfg {String} html content of button
6376 * @cfg {String} badge text inside badge
6377 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
6378 * @cfg {String} glyphicon DEPRICATED - use fa
6379 * @cfg {String} icon DEPRICATED - use fa
6380 * @cfg {String} fa - Fontawsome icon name (can add stuff to it like fa-2x)
6381 * @cfg {Boolean} active Is item active
6382 * @cfg {Boolean} disabled Is item disabled
6383 * @cfg {String} linkcls Link Class
6384 * @cfg {Boolean} preventDefault (true | false) default false
6385 * @cfg {String} tabId the tab that this item activates.
6386 * @cfg {String} tagtype (a|span) render as a href or span?
6387 * @cfg {Boolean} animateRef (true|false) link to element default false
6388 * @cfg {Roo.bootstrap.menu.Menu} menu a Menu
6391 * Create a new Navbar Item
6392 * @param {Object} config The config object
6394 Roo.bootstrap.nav.Item = function(config){
6395 Roo.bootstrap.nav.Item.superclass.constructor.call(this, config);
6400 * The raw click event for the entire grid.
6401 * @param {Roo.EventObject} e
6406 * Fires when the active item active state changes
6407 * @param {Roo.bootstrap.nav.Item} this
6408 * @param {boolean} state the new state
6414 * Fires when scroll to element
6415 * @param {Roo.bootstrap.nav.Item} this
6416 * @param {Object} options
6417 * @param {Roo.EventObject} e
6425 Roo.extend(Roo.bootstrap.nav.Item, Roo.bootstrap.Component, {
6434 preventDefault : false,
6442 button_outline : false,
6446 getAutoCreate : function(){
6453 cfg.cls = typeof(cfg.cls) == 'undefined' ? '' : cfg.cls;
6456 cfg.cls += ' active' ;
6458 if (this.disabled) {
6459 cfg.cls += ' disabled';
6463 if (this.button_weight.length) {
6464 cfg.tag = this.href ? 'a' : 'button';
6465 cfg.html = this.html || '';
6466 cfg.cls += ' btn btn' + (this.button_outline ? '-outline' : '') + '-' + this.button_weight;
6468 cfg.href = this.href;
6471 cfg.html = '<i class="fa fas fa-'+this.fa+'"></i> <span class="nav-html">' + this.html + '</span>';
6473 cfg.cls += " nav-html";
6476 // menu .. should add dropdown-menu class - so no need for carat..
6478 if (this.badge !== '') {
6480 cfg.html += ' <span class="badge badge-secondary">' + this.badge + '</span>';
6485 if (this.href || this.html || this.glyphicon || this.icon || this.fa) {
6489 href : this.href || "#",
6490 html: this.html || '',
6494 if (this.tagtype == 'a') {
6495 cfg.cn[0].cls = 'nav-link' + (this.active ? ' active' : '') + ' ' + this.linkcls;
6499 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span class="nav-html">' + cfg.cn[0].html + '</span>';
6500 } else if (this.fa) {
6501 cfg.cn[0].html = '<i class="fa fas fa-'+this.fa+'"></i> <span class="nav-html">' + cfg.cn[0].html + '</span>';
6502 } else if(this.glyphicon) {
6503 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
6505 cfg.cn[0].cls += " nav-html";
6509 cfg.cn[0].html += " <span class='caret'></span>";
6513 if (this.badge !== '') {
6514 cfg.cn[0].html += ' <span class="badge badge-secondary">' + this.badge + '</span>';
6522 onRender : function(ct, position)
6524 // Roo.log("Call onRender: " + this.xtype);
6525 if (Roo.bootstrap.version == 4 && ct.dom.type != 'ul') {
6529 var ret = Roo.bootstrap.nav.Item.superclass.onRender.call(this, ct, position);
6530 this.navLink = this.el.select('.nav-link',true).first();
6531 this.htmlEl = this.el.hasClass('nav-html') ? this.el : this.el.select('.nav-html',true).first();
6536 initEvents: function()
6538 if (typeof (this.menu) != 'undefined') {
6539 this.menu.parentType = this.xtype;
6540 this.menu.triggerEl = this.el;
6541 this.menu = this.addxtype(Roo.apply({}, this.menu));
6544 this.el.on('click', this.onClick, this);
6546 //if(this.tagtype == 'span'){
6547 // this.el.select('span',true).on('click', this.onClick, this);
6550 // at this point parent should be available..
6551 this.parent().register(this);
6554 onClick : function(e)
6556 if (e.getTarget('.dropdown-menu-item')) {
6557 // did you click on a menu itemm.... - then don't trigger onclick..
6562 this.preventDefault ||
6563 this.href === false ||
6566 //Roo.log("NavItem - prevent Default?");
6570 if (this.disabled) {
6574 var tg = Roo.bootstrap.TabGroup.get(this.navId);
6575 if (tg && tg.transition) {
6576 Roo.log("waiting for the transitionend");
6582 //Roo.log("fire event clicked");
6583 if(this.fireEvent('click', this, e) === false){
6587 if(this.tagtype == 'span'){
6591 //Roo.log(this.href);
6592 var ael = this.el.select('a',true).first();
6595 if(ael && this.animateRef && this.href.indexOf('#') > -1){
6596 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
6597 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
6598 return; // ignore... - it's a 'hash' to another page.
6600 Roo.log("NavItem - prevent Default?");
6602 this.scrollToElement(e);
6606 var p = this.parent();
6608 if (['tabs','pills'].indexOf(p.type)!==-1 && p.pilltype) {
6609 if (typeof(p.setActiveItem) !== 'undefined') {
6610 p.setActiveItem(this);
6614 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
6615 if (p.parentType == 'NavHeaderbar' && !this.menu) {
6616 // remove the collapsed menu expand...
6617 p.parent().el.select('.roo-navbar-collapse',true).removeClass('in');
6621 isActive: function () {
6624 setActive : function(state, fire, is_was_active)
6626 if (this.active && !state && this.navId) {
6627 this.was_active = true;
6628 var nv = Roo.bootstrap.nav.Group.get(this.navId);
6630 nv.clearWasActive(this);
6634 this.active = state;
6637 this.el.removeClass('active');
6638 this.navLink ? this.navLink.removeClass('active') : false;
6639 } else if (!this.el.hasClass('active')) {
6641 this.el.addClass('active');
6642 if (Roo.bootstrap.version == 4 && this.navLink ) {
6643 this.navLink.addClass('active');
6648 this.fireEvent('changed', this, state);
6651 // show a panel if it's registered and related..
6653 if (!this.navId || !this.tabId || !state || is_was_active) {
6657 var tg = Roo.bootstrap.TabGroup.get(this.navId);
6661 var pan = tg.getPanelByName(this.tabId);
6665 // if we can not flip to new panel - go back to old nav highlight..
6666 if (false == tg.showPanel(pan)) {
6667 var nv = Roo.bootstrap.nav.Group.get(this.navId);
6669 var onav = nv.getWasActive();
6671 onav.setActive(true, false, true);
6680 // this should not be here...
6681 setDisabled : function(state)
6683 this.disabled = state;
6685 this.el.removeClass('disabled');
6686 } else if (!this.el.hasClass('disabled')) {
6687 this.el.addClass('disabled');
6693 * Fetch the element to display the tooltip on.
6694 * @return {Roo.Element} defaults to this.el
6696 tooltipEl : function()
6698 return this.el; //this.tagtype == 'a' ? this.el : this.el.select('' + this.tagtype + '', true).first();
6701 scrollToElement : function(e)
6703 var c = document.body;
6706 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
6708 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
6709 c = document.documentElement;
6712 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
6718 var o = target.calcOffsetsTo(c);
6725 this.fireEvent('scrollto', this, options, e);
6727 Roo.get(c).scrollTo('top', options.value, true);
6732 * Set the HTML (text content) of the item
6733 * @param {string} html content for the nav item
6735 setHtml : function(html)
6738 this.htmlEl.dom.innerHTML = html;
6750 * <span> icon </span>
6751 * <span> text </span>
6752 * <span>badge </span>
6756 * @class Roo.bootstrap.nav.SidebarItem
6757 * @extends Roo.bootstrap.nav.Item
6758 * Bootstrap Navbar.NavSidebarItem class
6760 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
6761 * {Boolean} open is the menu open
6762 * {Boolean} buttonView use button as the tigger el rather that a (default false)
6763 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
6764 * {String} buttonSize (sm|md|lg)the extra classes for the button
6765 * {Boolean} showArrow show arrow next to the text (default true)
6767 * Create a new Navbar Button
6768 * @param {Object} config The config object
6770 Roo.bootstrap.nav.SidebarItem = function(config){
6771 Roo.bootstrap.nav.SidebarItem.superclass.constructor.call(this, config);
6776 * The raw click event for the entire grid.
6777 * @param {Roo.EventObject} e
6782 * Fires when the active item active state changes
6783 * @param {Roo.bootstrap.nav.SidebarItem} this
6784 * @param {boolean} state the new state
6792 Roo.extend(Roo.bootstrap.nav.SidebarItem, Roo.bootstrap.nav.Item, {
6794 badgeWeight : 'default',
6800 buttonWeight : 'default',
6806 getAutoCreate : function(){
6811 href : this.href || '#',
6817 if(this.buttonView){
6820 href : this.href || '#',
6821 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
6834 cfg.cls += ' active';
6837 if (this.disabled) {
6838 cfg.cls += ' disabled';
6841 cfg.cls += ' open x-open';
6844 if (this.glyphicon || this.icon) {
6845 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
6846 a.cn.push({ tag : 'i', cls : c }) ;
6849 if(!this.buttonView){
6852 html : this.html || ''
6859 if (this.badge !== '') {
6860 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
6866 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
6869 a.cls += ' dropdown-toggle treeview' ;
6875 initEvents : function()
6877 if (typeof (this.menu) != 'undefined') {
6878 this.menu.parentType = this.xtype;
6879 this.menu.triggerEl = this.el;
6880 this.menu = this.addxtype(Roo.apply({}, this.menu));
6883 this.el.on('click', this.onClick, this);
6885 if(this.badge !== ''){
6886 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
6891 onClick : function(e)
6898 if(this.preventDefault){
6902 this.fireEvent('click', this, e);
6905 disable : function()
6907 this.setDisabled(true);
6912 this.setDisabled(false);
6915 setDisabled : function(state)
6917 if(this.disabled == state){
6921 this.disabled = state;
6924 this.el.addClass('disabled');
6928 this.el.removeClass('disabled');
6933 setActive : function(state)
6935 if(this.active == state){
6939 this.active = state;
6942 this.el.addClass('active');
6946 this.el.removeClass('active');
6951 isActive: function ()
6956 setBadge : function(str)
6962 this.badgeEl.dom.innerHTML = str;
6979 * @class Roo.bootstrap.nav.ProgressBar
6980 * @extends Roo.bootstrap.Component
6981 * @children Roo.bootstrap.nav.ProgressBarItem
6982 * Bootstrap NavProgressBar class
6985 * Create a new nav progress bar - a bar indicating step along a process
6986 * @param {Object} config The config object
6989 Roo.bootstrap.nav.ProgressBar = function(config){
6990 Roo.bootstrap.nav.ProgressBar.superclass.constructor.call(this, config);
6992 this.bullets = this.bullets || [];
6994 // Roo.bootstrap.nav.ProgressBar.register(this);
6998 * Fires when the active item changes
6999 * @param {Roo.bootstrap.nav.ProgressBar} this
7000 * @param {Roo.bootstrap.nav.ProgressItem} selected The item selected
7001 * @param {Roo.bootstrap.nav.ProgressItem} prev The previously selected item
7008 Roo.extend(Roo.bootstrap.nav.ProgressBar, Roo.bootstrap.Component, {
7010 * @cfg {Roo.bootstrap.nav.ProgressItem} NavProgressBar:bullets[]
7011 * Bullets for the Nav Progress bar for the toolbar
7016 getAutoCreate : function()
7018 var cfg = Roo.apply({}, Roo.bootstrap.nav.ProgressBar.superclass.getAutoCreate.call(this));
7022 cls : 'roo-navigation-bar-group',
7026 cls : 'roo-navigation-top-bar'
7030 cls : 'roo-navigation-bullets-bar',
7034 cls : 'roo-navigation-bar'
7041 cls : 'roo-navigation-bottom-bar'
7051 initEvents: function()
7056 onRender : function(ct, position)
7058 Roo.bootstrap.nav.ProgressBar.superclass.onRender.call(this, ct, position);
7060 if(this.bullets.length){
7061 Roo.each(this.bullets, function(b){
7070 addItem : function(cfg)
7072 var item = new Roo.bootstrap.nav.ProgressItem(cfg);
7074 item.parentId = this.id;
7075 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
7078 var top = new Roo.bootstrap.Element({
7080 cls : 'roo-navigation-bar-text'
7083 var bottom = new Roo.bootstrap.Element({
7085 cls : 'roo-navigation-bar-text'
7088 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
7089 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
7091 var topText = new Roo.bootstrap.Element({
7093 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
7096 var bottomText = new Roo.bootstrap.Element({
7098 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
7101 topText.onRender(top.el, null);
7102 bottomText.onRender(bottom.el, null);
7105 item.bottomEl = bottom;
7108 this.barItems.push(item);
7113 getActive : function()
7117 Roo.each(this.barItems, function(v){
7119 if (!v.isActive()) {
7131 setActiveItem : function(item)
7135 Roo.each(this.barItems, function(v){
7136 if (v.rid == item.rid) {
7146 item.setActive(true);
7148 this.fireEvent('changed', this, item, prev);
7151 getBarItem: function(rid)
7155 Roo.each(this.barItems, function(e) {
7167 indexOfItem : function(item)
7171 Roo.each(this.barItems, function(v, i){
7173 if (v.rid != item.rid) {
7184 setActiveNext : function()
7186 var i = this.indexOfItem(this.getActive());
7188 if (i > this.barItems.length) {
7192 this.setActiveItem(this.barItems[i+1]);
7195 setActivePrev : function()
7197 var i = this.indexOfItem(this.getActive());
7203 this.setActiveItem(this.barItems[i-1]);
7208 if(!this.barItems.length){
7212 var width = 100 / this.barItems.length;
7214 Roo.each(this.barItems, function(i){
7215 i.el.setStyle('width', width + '%');
7216 i.topEl.el.setStyle('width', width + '%');
7217 i.bottomEl.el.setStyle('width', width + '%');
7231 * @class Roo.bootstrap.nav.ProgressBarItem
7232 * @extends Roo.bootstrap.Component
7233 * Bootstrap NavProgressBarItem class
7234 * @cfg {String} rid the reference id
7235 * @cfg {Boolean} active (true|false) Is item active default false
7236 * @cfg {Boolean} disabled (true|false) Is item active default false
7237 * @cfg {String} html
7238 * @cfg {String} position (top|bottom) text position default bottom
7239 * @cfg {String} icon show icon instead of number
7242 * Create a new NavProgressBarItem
7243 * @param {Object} config The config object
7245 Roo.bootstrap.nav.ProgressBarItem = function(config){
7246 Roo.bootstrap.nav.ProgressBarItem.superclass.constructor.call(this, config);
7251 * The raw click event for the entire grid.
7252 * @param {Roo.bootstrap.nav.ProgressBarItem} this
7253 * @param {Roo.EventObject} e
7260 Roo.extend(Roo.bootstrap.nav.ProgressBarItem, Roo.bootstrap.Component, {
7266 position : 'bottom',
7269 getAutoCreate : function()
7271 var iconCls = 'roo-navigation-bar-item-icon';
7273 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
7277 cls: 'roo-navigation-bar-item',
7287 cfg.cls += ' active';
7290 cfg.cls += ' disabled';
7296 disable : function()
7298 this.setDisabled(true);
7303 this.setDisabled(false);
7306 initEvents: function()
7308 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
7310 this.iconEl.on('click', this.onClick, this);
7313 onClick : function(e)
7321 if(this.fireEvent('click', this, e) === false){
7325 this.parent().setActiveItem(this);
7328 isActive: function ()
7333 setActive : function(state)
7335 if(this.active == state){
7339 this.active = state;
7342 this.el.addClass('active');
7346 this.el.removeClass('active');
7351 setDisabled : function(state)
7353 if(this.disabled == state){
7357 this.disabled = state;
7360 this.el.addClass('disabled');
7364 this.el.removeClass('disabled');
7367 tooltipEl : function()
7369 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
7380 Roo.namespace('Roo.bootstrap.breadcrumb');
7384 * @class Roo.bootstrap.breadcrumb.Nav
7385 * @extends Roo.bootstrap.Component
7386 * Bootstrap Breadcrumb Nav Class
7388 * @children Roo.bootstrap.breadcrumb.Item
7391 * Create a new breadcrumb.Nav
7392 * @param {Object} config The config object
7396 Roo.bootstrap.breadcrumb.Nav = function(config){
7397 Roo.bootstrap.breadcrumb.Nav.superclass.constructor.call(this, config);
7402 Roo.extend(Roo.bootstrap.breadcrumb.Nav, Roo.bootstrap.Component, {
7404 getAutoCreate : function()
7421 initEvents: function()
7423 this.olEl = this.el.select('ol',true).first();
7425 getChildContainer : function()
7441 * @class Roo.bootstrap.breadcrumb.Nav
7442 * @extends Roo.bootstrap.Component
7443 * @children Roo.bootstrap.Component
7444 * @parent Roo.bootstrap.breadcrumb.Nav
7445 * Bootstrap Breadcrumb Nav Class
7448 * @cfg {String} html the content of the link.
7449 * @cfg {String} href where it links to if '#' is used the link will be handled by onClick.
7450 * @cfg {Boolean} active is it active
7454 * Create a new breadcrumb.Nav
7455 * @param {Object} config The config object
7458 Roo.bootstrap.breadcrumb.Item = function(config){
7459 Roo.bootstrap.breadcrumb.Item.superclass.constructor.call(this, config);
7464 * The img click event for the img.
7465 * @param {Roo.EventObject} e
7472 Roo.extend(Roo.bootstrap.breadcrumb.Item, Roo.bootstrap.Component, {
7477 getAutoCreate : function()
7482 cls : 'breadcrumb-item' + (this.active ? ' active' : '')
7484 if (this.href !== false) {
7491 cfg.html = this.html;
7497 initEvents: function()
7500 this.el.select('a', true).first().on('click',this.onClick, this)
7504 onClick : function(e)
7507 this.fireEvent('click',this, e);
7520 * @class Roo.bootstrap.Row
7521 * @extends Roo.bootstrap.Component
7522 * @children Roo.bootstrap.Component
7523 * Bootstrap Row class (contains columns...)
7527 * @param {Object} config The config object
7530 Roo.bootstrap.Row = function(config){
7531 Roo.bootstrap.Row.superclass.constructor.call(this, config);
7534 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
7536 getAutoCreate : function(){
7555 * @class Roo.bootstrap.Pagination
7556 * @extends Roo.bootstrap.Component
7557 * @children Roo.bootstrap.Pagination
7558 * Bootstrap Pagination class
7560 * @cfg {String} size (xs|sm|md|lg|xl)
7561 * @cfg {Boolean} inverse
7564 * Create a new Pagination
7565 * @param {Object} config The config object
7568 Roo.bootstrap.Pagination = function(config){
7569 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
7572 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
7578 getAutoCreate : function(){
7584 cfg.cls += ' inverse';
7590 cfg.cls += " " + this.cls;
7608 * @class Roo.bootstrap.PaginationItem
7609 * @extends Roo.bootstrap.Component
7610 * Bootstrap PaginationItem class
7611 * @cfg {String} html text
7612 * @cfg {String} href the link
7613 * @cfg {Boolean} preventDefault (true | false) default true
7614 * @cfg {Boolean} active (true | false) default false
7615 * @cfg {Boolean} disabled default false
7619 * Create a new PaginationItem
7620 * @param {Object} config The config object
7624 Roo.bootstrap.PaginationItem = function(config){
7625 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
7630 * The raw click event for the entire grid.
7631 * @param {Roo.EventObject} e
7637 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
7641 preventDefault: true,
7646 getAutoCreate : function(){
7652 href : this.href ? this.href : '#',
7653 html : this.html ? this.html : ''
7663 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
7667 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
7673 initEvents: function() {
7675 this.el.on('click', this.onClick, this);
7678 onClick : function(e)
7680 Roo.log('PaginationItem on click ');
7681 if(this.preventDefault){
7689 this.fireEvent('click', this, e);
7705 * @class Roo.bootstrap.Slider
7706 * @extends Roo.bootstrap.Component
7707 * Bootstrap Slider class
7710 * Create a new Slider
7711 * @param {Object} config The config object
7714 Roo.bootstrap.Slider = function(config){
7715 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
7718 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
7720 getAutoCreate : function(){
7724 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
7728 cls: 'ui-slider-handle ui-state-default ui-corner-all'
7740 * Ext JS Library 1.1.1
7741 * Copyright(c) 2006-2007, Ext JS, LLC.
7743 * Originally Released Under LGPL - original licence link has changed is not relivant.
7746 * <script type="text/javascript">
7749 * @extends Roo.dd.DDProxy
7750 * @class Roo.grid.SplitDragZone
7751 * Support for Column Header resizing
7753 * @param {Object} config
7756 // This is a support class used internally by the Grid components
7757 Roo.grid.SplitDragZone = function(grid, hd, hd2){
7759 this.view = grid.getView();
7760 this.proxy = this.view.resizeProxy;
7761 Roo.grid.SplitDragZone.superclass.constructor.call(
7764 "gridSplitters" + this.grid.getGridEl().id, // SGROUP
7766 dragElId : Roo.id(this.proxy.dom),
7771 this.setHandleElId(Roo.id(hd));
7772 if (hd2 !== false) {
7773 this.setOuterHandleElId(Roo.id(hd2));
7776 this.scroll = false;
7778 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
7779 fly: Roo.Element.fly,
7781 b4StartDrag : function(x, y){
7782 this.view.headersDisabled = true;
7783 var h = this.view.mainWrap ? this.view.mainWrap.getHeight() : (
7784 this.view.headEl.getHeight() + this.view.bodyEl.getHeight()
7786 this.proxy.setHeight(h);
7788 // for old system colWidth really stored the actual width?
7789 // in bootstrap we tried using xs/ms/etc.. to do % sizing?
7790 // which in reality did not work.. - it worked only for fixed sizes
7791 // for resizable we need to use actual sizes.
7792 var w = this.cm.getColumnWidth(this.cellIndex);
7793 if (!this.view.mainWrap) {
7795 w = this.view.getHeaderIndex(this.cellIndex).getWidth();
7800 // this was w-this.grid.minColumnWidth;
7801 // doesnt really make sense? - w = thie curren width or the rendered one?
7802 var minw = Math.max(w-this.grid.minColumnWidth, 0);
7803 this.resetConstraints();
7804 this.setXConstraint(minw, 1000);
7805 this.setYConstraint(0, 0);
7806 this.minX = x - minw;
7807 this.maxX = x + 1000;
7809 if (!this.view.mainWrap) { // this is Bootstrap code..
7810 this.getDragEl().style.display='block';
7813 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
7817 handleMouseDown : function(e){
7818 ev = Roo.EventObject.setEvent(e);
7819 var t = this.fly(ev.getTarget());
7820 if(t.hasClass("x-grid-split")){
7821 this.cellIndex = this.view.getCellIndex(t.dom);
7823 this.cm = this.grid.colModel;
7824 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
7825 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
7830 endDrag : function(e){
7831 this.view.headersDisabled = false;
7832 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
7833 var diff = endX - this.startPos;
7835 var w = this.cm.getColumnWidth(this.cellIndex);
7836 if (!this.view.mainWrap) {
7839 this.view.onColumnSplitterMoved(this.cellIndex, w+diff);
7842 autoOffset : function(){
7847 * Ext JS Library 1.1.1
7848 * Copyright(c) 2006-2007, Ext JS, LLC.
7850 * Originally Released Under LGPL - original licence link has changed is not relivant.
7853 * <script type="text/javascript">
7857 * @class Roo.grid.AbstractSelectionModel
7858 * @extends Roo.util.Observable
7860 * Abstract base class for grid SelectionModels. It provides the interface that should be
7861 * implemented by descendant classes. This class should not be directly instantiated.
7864 Roo.grid.AbstractSelectionModel = function(){
7865 this.locked = false;
7866 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
7869 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
7870 /** @ignore Called by the grid automatically. Do not call directly. */
7871 init : function(grid){
7877 * Locks the selections.
7884 * Unlocks the selections.
7886 unlock : function(){
7887 this.locked = false;
7891 * Returns true if the selections are locked.
7894 isLocked : function(){
7899 * Ext JS Library 1.1.1
7900 * Copyright(c) 2006-2007, Ext JS, LLC.
7902 * Originally Released Under LGPL - original licence link has changed is not relivant.
7905 * <script type="text/javascript">
7908 * @extends Roo.grid.AbstractSelectionModel
7909 * @class Roo.grid.RowSelectionModel
7910 * The default SelectionModel used by {@link Roo.grid.Grid}.
7911 * It supports multiple selections and keyboard selection/navigation.
7913 * @param {Object} config
7915 Roo.grid.RowSelectionModel = function(config){
7916 Roo.apply(this, config);
7917 this.selections = new Roo.util.MixedCollection(false, function(o){
7922 this.lastActive = false;
7926 * @event selectionchange
7927 * Fires when the selection changes
7928 * @param {SelectionModel} this
7930 "selectionchange" : true,
7932 * @event afterselectionchange
7933 * Fires after the selection changes (eg. by key press or clicking)
7934 * @param {SelectionModel} this
7936 "afterselectionchange" : true,
7938 * @event beforerowselect
7939 * Fires when a row is selected being selected, return false to cancel.
7940 * @param {SelectionModel} this
7941 * @param {Number} rowIndex The selected index
7942 * @param {Boolean} keepExisting False if other selections will be cleared
7944 "beforerowselect" : true,
7947 * Fires when a row is selected.
7948 * @param {SelectionModel} this
7949 * @param {Number} rowIndex The selected index
7950 * @param {Roo.data.Record} r The record
7954 * @event rowdeselect
7955 * Fires when a row is deselected.
7956 * @param {SelectionModel} this
7957 * @param {Number} rowIndex The selected index
7959 "rowdeselect" : true
7961 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
7962 this.locked = false;
7965 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
7967 * @cfg {Boolean} singleSelect
7968 * True to allow selection of only one row at a time (defaults to false)
7970 singleSelect : false,
7973 initEvents : function(){
7975 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
7976 this.grid.on("mousedown", this.handleMouseDown, this);
7977 }else{ // allow click to work like normal
7978 this.grid.on("rowclick", this.handleDragableRowClick, this);
7980 // bootstrap does not have a view..
7981 var view = this.grid.view ? this.grid.view : this.grid;
7982 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
7985 this.selectPrevious(e.shiftKey);
7986 }else if(this.last !== false && this.lastActive !== false){
7987 var last = this.last;
7988 this.selectRange(this.last, this.lastActive-1);
7989 view.focusRow(this.lastActive);
7994 this.selectFirstRow();
7996 this.fireEvent("afterselectionchange", this);
7998 "down" : function(e){
8000 this.selectNext(e.shiftKey);
8001 }else if(this.last !== false && this.lastActive !== false){
8002 var last = this.last;
8003 this.selectRange(this.last, this.lastActive+1);
8004 view.focusRow(this.lastActive);
8009 this.selectFirstRow();
8011 this.fireEvent("afterselectionchange", this);
8017 view.on("refresh", this.onRefresh, this);
8018 view.on("rowupdated", this.onRowUpdated, this);
8019 view.on("rowremoved", this.onRemove, this);
8023 onRefresh : function(){
8024 var ds = this.grid.ds, i, v = this.grid.view;
8025 var s = this.selections;
8027 if((i = ds.indexOfId(r.id)) != -1){
8029 s.add(ds.getAt(i)); // updating the selection relate data
8037 onRemove : function(v, index, r){
8038 this.selections.remove(r);
8042 onRowUpdated : function(v, index, r){
8043 if(this.isSelected(r)){
8044 v.onRowSelect(index);
8050 * @param {Array} records The records to select
8051 * @param {Boolean} keepExisting (optional) True to keep existing selections
8053 selectRecords : function(records, keepExisting){
8055 this.clearSelections();
8057 var ds = this.grid.ds;
8058 for(var i = 0, len = records.length; i < len; i++){
8059 this.selectRow(ds.indexOf(records[i]), true);
8064 * Gets the number of selected rows.
8067 getCount : function(){
8068 return this.selections.length;
8072 * Selects the first row in the grid.
8074 selectFirstRow : function(){
8079 * Select the last row.
8080 * @param {Boolean} keepExisting (optional) True to keep existing selections
8082 selectLastRow : function(keepExisting){
8083 this.selectRow(this.grid.ds.getCount() - 1, keepExisting);
8087 * Selects the row immediately following the last selected row.
8088 * @param {Boolean} keepExisting (optional) True to keep existing selections
8090 selectNext : function(keepExisting){
8091 if(this.last !== false && (this.last+1) < this.grid.ds.getCount()){
8092 this.selectRow(this.last+1, keepExisting);
8093 var view = this.grid.view ? this.grid.view : this.grid;
8094 view.focusRow(this.last);
8099 * Selects the row that precedes the last selected row.
8100 * @param {Boolean} keepExisting (optional) True to keep existing selections
8102 selectPrevious : function(keepExisting){
8104 this.selectRow(this.last-1, keepExisting);
8105 var view = this.grid.view ? this.grid.view : this.grid;
8106 view.focusRow(this.last);
8111 * Returns the selected records
8112 * @return {Array} Array of selected records
8114 getSelections : function(){
8115 return [].concat(this.selections.items);
8119 * Returns the first selected record.
8122 getSelected : function(){
8123 return this.selections.itemAt(0);
8128 * Clears all selections.
8130 clearSelections : function(fast){
8135 var ds = this.grid.ds;
8136 var s = this.selections;
8138 this.deselectRow(ds.indexOfId(r.id));
8142 this.selections.clear();
8151 selectAll : function(){
8155 this.selections.clear();
8156 for(var i = 0, len = this.grid.ds.getCount(); i < len; i++){
8157 this.selectRow(i, true);
8162 * Returns True if there is a selection.
8165 hasSelection : function(){
8166 return this.selections.length > 0;
8170 * Returns True if the specified row is selected.
8171 * @param {Number/Record} record The record or index of the record to check
8174 isSelected : function(index){
8175 var r = typeof index == "number" ? this.grid.ds.getAt(index) : index;
8176 return (r && this.selections.key(r.id) ? true : false);
8180 * Returns True if the specified record id is selected.
8181 * @param {String} id The id of record to check
8184 isIdSelected : function(id){
8185 return (this.selections.key(id) ? true : false);
8189 handleMouseDown : function(e, t)
8191 var view = this.grid.view ? this.grid.view : this.grid;
8193 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
8196 if(e.shiftKey && this.last !== false){
8197 var last = this.last;
8198 this.selectRange(last, rowIndex, e.ctrlKey);
8199 this.last = last; // reset the last
8200 view.focusRow(rowIndex);
8202 var isSelected = this.isSelected(rowIndex);
8203 if(e.button !== 0 && isSelected){
8204 view.focusRow(rowIndex);
8205 }else if(e.ctrlKey && isSelected){
8206 this.deselectRow(rowIndex);
8207 }else if(!isSelected){
8208 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
8209 view.focusRow(rowIndex);
8212 this.fireEvent("afterselectionchange", this);
8215 handleDragableRowClick : function(grid, rowIndex, e)
8217 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
8218 this.selectRow(rowIndex, false);
8219 var view = this.grid.view ? this.grid.view : this.grid;
8220 view.focusRow(rowIndex);
8221 this.fireEvent("afterselectionchange", this);
8226 * Selects multiple rows.
8227 * @param {Array} rows Array of the indexes of the row to select
8228 * @param {Boolean} keepExisting (optional) True to keep existing selections
8230 selectRows : function(rows, keepExisting){
8232 this.clearSelections();
8234 for(var i = 0, len = rows.length; i < len; i++){
8235 this.selectRow(rows[i], true);
8240 * Selects a range of rows. All rows in between startRow and endRow are also selected.
8241 * @param {Number} startRow The index of the first row in the range
8242 * @param {Number} endRow The index of the last row in the range
8243 * @param {Boolean} keepExisting (optional) True to retain existing selections
8245 selectRange : function(startRow, endRow, keepExisting){
8250 this.clearSelections();
8252 if(startRow <= endRow){
8253 for(var i = startRow; i <= endRow; i++){
8254 this.selectRow(i, true);
8257 for(var i = startRow; i >= endRow; i--){
8258 this.selectRow(i, true);
8264 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
8265 * @param {Number} startRow The index of the first row in the range
8266 * @param {Number} endRow The index of the last row in the range
8268 deselectRange : function(startRow, endRow, preventViewNotify){
8272 for(var i = startRow; i <= endRow; i++){
8273 this.deselectRow(i, preventViewNotify);
8279 * @param {Number} row The index of the row to select
8280 * @param {Boolean} keepExisting (optional) True to keep existing selections
8282 selectRow : function(index, keepExisting, preventViewNotify){
8283 if(this.locked || (index < 0 || index >= this.grid.ds.getCount())) {
8286 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
8287 if(!keepExisting || this.singleSelect){
8288 this.clearSelections();
8290 var r = this.grid.ds.getAt(index);
8291 this.selections.add(r);
8292 this.last = this.lastActive = index;
8293 if(!preventViewNotify){
8294 var view = this.grid.view ? this.grid.view : this.grid;
8295 view.onRowSelect(index);
8297 this.fireEvent("rowselect", this, index, r);
8298 this.fireEvent("selectionchange", this);
8304 * @param {Number} row The index of the row to deselect
8306 deselectRow : function(index, preventViewNotify){
8310 if(this.last == index){
8313 if(this.lastActive == index){
8314 this.lastActive = false;
8316 var r = this.grid.ds.getAt(index);
8317 this.selections.remove(r);
8318 if(!preventViewNotify){
8319 var view = this.grid.view ? this.grid.view : this.grid;
8320 view.onRowDeselect(index);
8322 this.fireEvent("rowdeselect", this, index);
8323 this.fireEvent("selectionchange", this);
8327 restoreLast : function(){
8329 this.last = this._last;
8334 acceptsNav : function(row, col, cm){
8335 return !cm.isHidden(col) && cm.isCellEditable(col, row);
8339 onEditorKey : function(field, e){
8340 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
8345 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
8347 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
8349 }else if(k == e.ENTER && !e.ctrlKey){
8353 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
8355 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
8357 }else if(k == e.ESC){
8361 g.startEditing(newCell[0], newCell[1]);
8366 * Ext JS Library 1.1.1
8367 * Copyright(c) 2006-2007, Ext JS, LLC.
8369 * Originally Released Under LGPL - original licence link has changed is not relivant.
8372 * <script type="text/javascript">
8377 * @class Roo.grid.ColumnModel
8378 * @extends Roo.util.Observable
8379 * This is the default implementation of a ColumnModel used by the Grid. It defines
8380 * the columns in the grid.
8383 var colModel = new Roo.grid.ColumnModel([
8384 {header: "Ticker", width: 60, sortable: true, locked: true},
8385 {header: "Company Name", width: 150, sortable: true},
8386 {header: "Market Cap.", width: 100, sortable: true},
8387 {header: "$ Sales", width: 100, sortable: true, renderer: money},
8388 {header: "Employees", width: 100, sortable: true, resizable: false}
8393 * The config options listed for this class are options which may appear in each
8394 * individual column definition.
8395 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
8397 * @param {Object} config An Array of column config objects. See this class's
8398 * config objects for details.
8400 Roo.grid.ColumnModel = function(config){
8402 * The config passed into the constructor
8404 this.config = []; //config;
8407 // if no id, create one
8408 // if the column does not have a dataIndex mapping,
8409 // map it to the order it is in the config
8410 for(var i = 0, len = config.length; i < len; i++){
8411 this.addColumn(config[i]);
8416 * The width of columns which have no width specified (defaults to 100)
8419 this.defaultWidth = 100;
8422 * Default sortable of columns which have no sortable specified (defaults to false)
8425 this.defaultSortable = false;
8429 * @event widthchange
8430 * Fires when the width of a column changes.
8431 * @param {ColumnModel} this
8432 * @param {Number} columnIndex The column index
8433 * @param {Number} newWidth The new width
8435 "widthchange": true,
8437 * @event headerchange
8438 * Fires when the text of a header changes.
8439 * @param {ColumnModel} this
8440 * @param {Number} columnIndex The column index
8441 * @param {Number} newText The new header text
8443 "headerchange": true,
8445 * @event hiddenchange
8446 * Fires when a column is hidden or "unhidden".
8447 * @param {ColumnModel} this
8448 * @param {Number} columnIndex The column index
8449 * @param {Boolean} hidden true if hidden, false otherwise
8451 "hiddenchange": true,
8453 * @event columnmoved
8454 * Fires when a column is moved.
8455 * @param {ColumnModel} this
8456 * @param {Number} oldIndex
8457 * @param {Number} newIndex
8459 "columnmoved" : true,
8461 * @event columlockchange
8462 * Fires when a column's locked state is changed
8463 * @param {ColumnModel} this
8464 * @param {Number} colIndex
8465 * @param {Boolean} locked true if locked
8467 "columnlockchange" : true
8469 Roo.grid.ColumnModel.superclass.constructor.call(this);
8471 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
8473 * @cfg {String} header [required] The header text to display in the Grid view.
8476 * @cfg {String} xsHeader Header at Bootsrap Extra Small width (default for all)
8479 * @cfg {String} smHeader Header at Bootsrap Small width
8482 * @cfg {String} mdHeader Header at Bootsrap Medium width
8485 * @cfg {String} lgHeader Header at Bootsrap Large width
8488 * @cfg {String} xlHeader Header at Bootsrap extra Large width
8491 * @cfg {String} dataIndex The name of the field in the grid's {@link Roo.data.Store}'s
8492 * {@link Roo.data.Record} definition from which to draw the column's value. If not
8493 * specified, the column's index is used as an index into the Record's data Array.
8496 * @cfg {Number} width The initial width in pixels of the column. Using this
8497 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
8500 * @cfg {Boolean} sortable True if sorting is to be allowed on this column.
8501 * Defaults to the value of the {@link #defaultSortable} property.
8502 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
8505 * @cfg {Boolean} locked True to lock the column in place while scrolling the Grid. Defaults to false.
8508 * @cfg {Boolean} fixed True if the column width cannot be changed. Defaults to false.
8511 * @cfg {Boolean} resizable False to disable column resizing. Defaults to true.
8514 * @cfg {Boolean} hidden True to hide the column. Defaults to false.
8517 * @cfg {Function} renderer A function used to generate HTML markup for a cell
8518 * given the cell's data value. See {@link #setRenderer}. If not specified, the
8519 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
8520 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
8523 * @cfg {Roo.grid.GridEditor} editor For grid editors - returns the grid editor
8526 * @cfg {String} align (left|right) Set the CSS text-align property of the column. Defaults to undefined (left).
8529 * @cfg {String} valign (top|bottom|middle) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined (middle)
8532 * @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)
8535 * @cfg {String} tooltip mouse over tooltip text
8538 * @cfg {Number} xs can be '0' for hidden at this size (number less than 12)
8541 * @cfg {Number} sm can be '0' for hidden at this size (number less than 12)
8544 * @cfg {Number} md can be '0' for hidden at this size (number less than 12)
8547 * @cfg {Number} lg can be '0' for hidden at this size (number less than 12)
8550 * @cfg {Number} xl can be '0' for hidden at this size (number less than 12)
8553 * Returns the id of the column at the specified index.
8554 * @param {Number} index The column index
8555 * @return {String} the id
8557 getColumnId : function(index){
8558 return this.config[index].id;
8562 * Returns the column for a specified id.
8563 * @param {String} id The column id
8564 * @return {Object} the column
8566 getColumnById : function(id){
8567 return this.lookup[id];
8572 * Returns the column Object for a specified dataIndex.
8573 * @param {String} dataIndex The column dataIndex
8574 * @return {Object|Boolean} the column or false if not found
8576 getColumnByDataIndex: function(dataIndex){
8577 var index = this.findColumnIndex(dataIndex);
8578 return index > -1 ? this.config[index] : false;
8582 * Returns the index for a specified column id.
8583 * @param {String} id The column id
8584 * @return {Number} the index, or -1 if not found
8586 getIndexById : function(id){
8587 for(var i = 0, len = this.config.length; i < len; i++){
8588 if(this.config[i].id == id){
8596 * Returns the index for a specified column dataIndex.
8597 * @param {String} dataIndex The column dataIndex
8598 * @return {Number} the index, or -1 if not found
8601 findColumnIndex : function(dataIndex){
8602 for(var i = 0, len = this.config.length; i < len; i++){
8603 if(this.config[i].dataIndex == dataIndex){
8611 moveColumn : function(oldIndex, newIndex){
8612 var c = this.config[oldIndex];
8613 this.config.splice(oldIndex, 1);
8614 this.config.splice(newIndex, 0, c);
8615 this.dataMap = null;
8616 this.fireEvent("columnmoved", this, oldIndex, newIndex);
8619 isLocked : function(colIndex){
8620 return this.config[colIndex].locked === true;
8623 setLocked : function(colIndex, value, suppressEvent){
8624 if(this.isLocked(colIndex) == value){
8627 this.config[colIndex].locked = value;
8629 this.fireEvent("columnlockchange", this, colIndex, value);
8633 getTotalLockedWidth : function(){
8635 for(var i = 0; i < this.config.length; i++){
8636 if(this.isLocked(i) && !this.isHidden(i)){
8637 this.totalWidth += this.getColumnWidth(i);
8643 getLockedCount : function(){
8644 for(var i = 0, len = this.config.length; i < len; i++){
8645 if(!this.isLocked(i)){
8650 return this.config.length;
8654 * Returns the number of columns.
8657 getColumnCount : function(visibleOnly){
8658 if(visibleOnly === true){
8660 for(var i = 0, len = this.config.length; i < len; i++){
8661 if(!this.isHidden(i)){
8667 return this.config.length;
8671 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
8672 * @param {Function} fn
8673 * @param {Object} scope (optional)
8674 * @return {Array} result
8676 getColumnsBy : function(fn, scope){
8678 for(var i = 0, len = this.config.length; i < len; i++){
8679 var c = this.config[i];
8680 if(fn.call(scope||this, c, i) === true){
8688 * Returns true if the specified column is sortable.
8689 * @param {Number} col The column index
8692 isSortable : function(col){
8693 if(typeof this.config[col].sortable == "undefined"){
8694 return this.defaultSortable;
8696 return this.config[col].sortable;
8700 * Returns the rendering (formatting) function defined for the column.
8701 * @param {Number} col The column index.
8702 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
8704 getRenderer : function(col){
8705 if(!this.config[col].renderer){
8706 return Roo.grid.ColumnModel.defaultRenderer;
8708 return this.config[col].renderer;
8712 * Sets the rendering (formatting) function for a column.
8713 * @param {Number} col The column index
8714 * @param {Function} fn The function to use to process the cell's raw data
8715 * to return HTML markup for the grid view. The render function is called with
8716 * the following parameters:<ul>
8717 * <li>Data value.</li>
8718 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
8719 * <li>css A CSS style string to apply to the table cell.</li>
8720 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
8721 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
8722 * <li>Row index</li>
8723 * <li>Column index</li>
8724 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
8726 setRenderer : function(col, fn){
8727 this.config[col].renderer = fn;
8731 * Returns the width for the specified column.
8732 * @param {Number} col The column index
8733 * @param (optional) {String} gridSize bootstrap width size.
8736 getColumnWidth : function(col, gridSize)
8738 var cfg = this.config[col];
8740 if (typeof(gridSize) == 'undefined') {
8741 return cfg.width * 1 || this.defaultWidth;
8743 if (gridSize === false) { // if we set it..
8744 return cfg.width || false;
8746 var sizes = ['xl', 'lg', 'md', 'sm', 'xs'];
8748 for(var i = sizes.indexOf(gridSize); i < sizes.length; i++) {
8749 if (typeof(cfg[ sizes[i] ] ) == 'undefined') {
8752 return cfg[ sizes[i] ];
8759 * Sets the width for a column.
8760 * @param {Number} col The column index
8761 * @param {Number} width The new width
8763 setColumnWidth : function(col, width, suppressEvent){
8764 this.config[col].width = width;
8765 this.totalWidth = null;
8767 this.fireEvent("widthchange", this, col, width);
8772 * Returns the total width of all columns.
8773 * @param {Boolean} includeHidden True to include hidden column widths
8776 getTotalWidth : function(includeHidden){
8777 if(!this.totalWidth){
8778 this.totalWidth = 0;
8779 for(var i = 0, len = this.config.length; i < len; i++){
8780 if(includeHidden || !this.isHidden(i)){
8781 this.totalWidth += this.getColumnWidth(i);
8785 return this.totalWidth;
8789 * Returns the header for the specified column.
8790 * @param {Number} col The column index
8793 getColumnHeader : function(col){
8794 return this.config[col].header;
8798 * Sets the header for a column.
8799 * @param {Number} col The column index
8800 * @param {String} header The new header
8802 setColumnHeader : function(col, header){
8803 this.config[col].header = header;
8804 this.fireEvent("headerchange", this, col, header);
8808 * Returns the tooltip for the specified column.
8809 * @param {Number} col The column index
8812 getColumnTooltip : function(col){
8813 return this.config[col].tooltip;
8816 * Sets the tooltip for a column.
8817 * @param {Number} col The column index
8818 * @param {String} tooltip The new tooltip
8820 setColumnTooltip : function(col, tooltip){
8821 this.config[col].tooltip = tooltip;
8825 * Returns the dataIndex for the specified column.
8826 * @param {Number} col The column index
8829 getDataIndex : function(col){
8830 return this.config[col].dataIndex;
8834 * Sets the dataIndex for a column.
8835 * @param {Number} col The column index
8836 * @param {Number} dataIndex The new dataIndex
8838 setDataIndex : function(col, dataIndex){
8839 this.config[col].dataIndex = dataIndex;
8845 * Returns true if the cell is editable.
8846 * @param {Number} colIndex The column index
8847 * @param {Number} rowIndex The row index - this is nto actually used..?
8850 isCellEditable : function(colIndex, rowIndex){
8851 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
8855 * Returns the editor defined for the cell/column.
8856 * return false or null to disable editing.
8857 * @param {Number} colIndex The column index
8858 * @param {Number} rowIndex The row index
8861 getCellEditor : function(colIndex, rowIndex){
8862 return this.config[colIndex].editor;
8866 * Sets if a column is editable.
8867 * @param {Number} col The column index
8868 * @param {Boolean} editable True if the column is editable
8870 setEditable : function(col, editable){
8871 this.config[col].editable = editable;
8876 * Returns true if the column is hidden.
8877 * @param {Number} colIndex The column index
8880 isHidden : function(colIndex){
8881 return this.config[colIndex].hidden;
8886 * Returns true if the column width cannot be changed
8888 isFixed : function(colIndex){
8889 return this.config[colIndex].fixed;
8893 * Returns true if the column can be resized
8896 isResizable : function(colIndex){
8897 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
8900 * Sets if a column is hidden.
8901 * @param {Number} colIndex The column index
8902 * @param {Boolean} hidden True if the column is hidden
8904 setHidden : function(colIndex, hidden){
8905 this.config[colIndex].hidden = hidden;
8906 this.totalWidth = null;
8907 this.fireEvent("hiddenchange", this, colIndex, hidden);
8911 * Sets the editor for a column.
8912 * @param {Number} col The column index
8913 * @param {Object} editor The editor object
8915 setEditor : function(col, editor){
8916 this.config[col].editor = editor;
8919 * Add a column (experimental...) - defaults to adding to the end..
8920 * @param {Object} config
8922 addColumn : function(c)
8925 var i = this.config.length;
8928 if(typeof c.dataIndex == "undefined"){
8931 if(typeof c.renderer == "string"){
8932 c.renderer = Roo.util.Format[c.renderer];
8934 if(typeof c.id == "undefined"){
8937 if(c.editor && c.editor.xtype){
8938 c.editor = Roo.factory(c.editor, Roo.grid);
8940 if(c.editor && c.editor.isFormField){
8941 c.editor = new Roo.grid.GridEditor(c.editor);
8943 this.lookup[c.id] = c;
8948 Roo.grid.ColumnModel.defaultRenderer = function(value)
8950 if(typeof value == "object") {
8953 if(typeof value == "string" && value.length < 1){
8957 return String.format("{0}", value);
8960 // Alias for backwards compatibility
8961 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
8964 * Ext JS Library 1.1.1
8965 * Copyright(c) 2006-2007, Ext JS, LLC.
8967 * Originally Released Under LGPL - original licence link has changed is not relivant.
8970 * <script type="text/javascript">
8974 * @class Roo.LoadMask
8975 * A simple utility class for generically masking elements while loading data. If the element being masked has
8976 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
8977 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
8978 * element's UpdateManager load indicator and will be destroyed after the initial load.
8980 * Create a new LoadMask
8981 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
8982 * @param {Object} config The config object
8984 Roo.LoadMask = function(el, config){
8985 this.el = Roo.get(el);
8986 Roo.apply(this, config);
8988 this.store.on('beforeload', this.onBeforeLoad, this);
8989 this.store.on('load', this.onLoad, this);
8990 this.store.on('loadexception', this.onLoadException, this);
8991 this.removeMask = false;
8993 var um = this.el.getUpdateManager();
8994 um.showLoadIndicator = false; // disable the default indicator
8995 um.on('beforeupdate', this.onBeforeLoad, this);
8996 um.on('update', this.onLoad, this);
8997 um.on('failure', this.onLoad, this);
8998 this.removeMask = true;
9002 Roo.LoadMask.prototype = {
9004 * @cfg {Boolean} removeMask
9005 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
9006 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
9011 * The text to display in a centered loading message box (defaults to 'Loading...')
9015 * @cfg {String} msgCls
9016 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
9018 msgCls : 'x-mask-loading',
9021 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
9027 * Disables the mask to prevent it from being displayed
9029 disable : function(){
9030 this.disabled = true;
9034 * Enables the mask so that it can be displayed
9036 enable : function(){
9037 this.disabled = false;
9040 onLoadException : function()
9044 if (typeof(arguments[3]) != 'undefined') {
9045 Roo.MessageBox.alert("Error loading",arguments[3]);
9049 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
9050 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
9057 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
9062 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
9066 onBeforeLoad : function(){
9068 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
9073 destroy : function(){
9075 this.store.un('beforeload', this.onBeforeLoad, this);
9076 this.store.un('load', this.onLoad, this);
9077 this.store.un('loadexception', this.onLoadException, this);
9079 var um = this.el.getUpdateManager();
9080 um.un('beforeupdate', this.onBeforeLoad, this);
9081 um.un('update', this.onLoad, this);
9082 um.un('failure', this.onLoad, this);
9086 * @class Roo.bootstrap.Table
9088 * @extends Roo.bootstrap.Component
9089 * @children Roo.bootstrap.TableBody
9090 * Bootstrap Table class. This class represents the primary interface of a component based grid control.
9091 * Similar to Roo.grid.Grid
9093 var table = Roo.factory({
9095 xns : Roo.bootstrap,
9096 autoSizeColumns: true,
9103 sortInfo : { direction : 'ASC', field: 'name' },
9105 xtype : 'HttpProxy',
9108 url : 'https://example.com/some.data.url.json'
9111 xtype : 'JsonReader',
9113 fields : [ 'id', 'name', whatever' ],
9120 xtype : 'ColumnModel',
9124 dataIndex : 'is_in_group',
9127 renderer : function(v, x , r) {
9129 return String.format("{0}", v)
9135 xtype : 'RowSelectionModel',
9136 xns : Roo.bootstrap.Table
9137 // you can add listeners to catch selection change here....
9143 grid.render(Roo.get("some-div"));
9146 Currently the Table uses multiple headers to try and handle XL / Medium etc... styling
9151 * @cfg {Roo.grid.AbstractSelectionModel} sm The selection model to use (cell selection is not supported yet)
9152 * @cfg {Roo.data.Store} store The data store to use
9153 * @cfg {Roo.grid.ColumnModel} cm[] A column for the grid.
9155 * @cfg {String} cls table class
9158 * @cfg {string} empty_results Text to display for no results
9159 * @cfg {boolean} striped Should the rows be alternative striped
9160 * @cfg {boolean} bordered Add borders to the table
9161 * @cfg {boolean} hover Add hover highlighting
9162 * @cfg {boolean} condensed Format condensed
9163 * @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,
9164 * also adds table-responsive (see bootstrap docs for details)
9165 * @cfg {Boolean} loadMask (true|false) default false
9166 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
9167 * @cfg {Boolean} headerShow (true|false) generate thead, default true
9168 * @cfg {Boolean} rowSelection (true|false) default false
9169 * @cfg {Boolean} cellSelection (true|false) default false
9170 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header (with resizable columns)
9171 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
9172 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
9173 * @cfg {Boolean} auto_hide_footer auto hide footer if only one page (default false)
9174 * @cfg {Boolean} enableColumnResize default true if columns can be resized = needs scrollBody to be set to work (drag/drop)
9175 * @cfg {Boolean} disableAutoSize disable autoSize() and initCSS()
9178 * @cfg {Number} minColumnWidth default 50 pixels minimum column width
9181 * Create a new Table
9182 * @param {Object} config The config object
9185 Roo.bootstrap.Table = function(config)
9187 Roo.bootstrap.Table.superclass.constructor.call(this, config);
9190 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
9191 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
9192 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
9193 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
9195 this.view = this; // compat with grid.
9197 this.sm = this.sm || {xtype: 'RowSelectionModel'};
9199 this.sm.grid = this;
9200 this.selModel = Roo.factory(this.sm, Roo.grid);
9201 this.sm = this.selModel;
9202 this.sm.xmodule = this.xmodule || false;
9205 if (this.cm && typeof(this.cm.config) == 'undefined') {
9206 this.colModel = new Roo.grid.ColumnModel(this.cm);
9207 this.cm = this.colModel;
9208 this.cm.xmodule = this.xmodule || false;
9211 this.store= Roo.factory(this.store, Roo.data);
9212 this.ds = this.store;
9213 this.ds.xmodule = this.xmodule || false;
9216 if (this.footer && this.store) {
9217 this.footer.dataSource = this.ds;
9218 this.footer = Roo.factory(this.footer);
9225 * Fires when a cell is clicked
9226 * @param {Roo.bootstrap.Table} this
9227 * @param {Roo.Element} el
9228 * @param {Number} rowIndex
9229 * @param {Number} columnIndex
9230 * @param {Roo.EventObject} e
9234 * @event celldblclick
9235 * Fires when a cell is double clicked
9236 * @param {Roo.bootstrap.Table} this
9237 * @param {Roo.Element} el
9238 * @param {Number} rowIndex
9239 * @param {Number} columnIndex
9240 * @param {Roo.EventObject} e
9242 "celldblclick" : true,
9245 * Fires when a row is clicked
9246 * @param {Roo.bootstrap.Table} this
9247 * @param {Roo.Element} el
9248 * @param {Number} rowIndex
9249 * @param {Roo.EventObject} e
9253 * @event rowdblclick
9254 * Fires when a row is double clicked
9255 * @param {Roo.bootstrap.Table} this
9256 * @param {Roo.Element} el
9257 * @param {Number} rowIndex
9258 * @param {Roo.EventObject} e
9260 "rowdblclick" : true,
9263 * Fires when a mouseover occur
9264 * @param {Roo.bootstrap.Table} this
9265 * @param {Roo.Element} el
9266 * @param {Number} rowIndex
9267 * @param {Number} columnIndex
9268 * @param {Roo.EventObject} e
9273 * Fires when a mouseout occur
9274 * @param {Roo.bootstrap.Table} this
9275 * @param {Roo.Element} el
9276 * @param {Number} rowIndex
9277 * @param {Number} columnIndex
9278 * @param {Roo.EventObject} e
9283 * Fires when a row is rendered, so you can change add a style to it.
9284 * @param {Roo.bootstrap.Table} this
9285 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
9289 * @event rowsrendered
9290 * Fires when all the rows have been rendered
9291 * @param {Roo.bootstrap.Table} this
9293 'rowsrendered' : true,
9295 * @event contextmenu
9296 * The raw contextmenu event for the entire grid.
9297 * @param {Roo.EventObject} e
9299 "contextmenu" : true,
9301 * @event rowcontextmenu
9302 * Fires when a row is right clicked
9303 * @param {Roo.bootstrap.Table} this
9304 * @param {Number} rowIndex
9305 * @param {Roo.EventObject} e
9307 "rowcontextmenu" : true,
9309 * @event cellcontextmenu
9310 * Fires when a cell is right clicked
9311 * @param {Roo.bootstrap.Table} this
9312 * @param {Number} rowIndex
9313 * @param {Number} cellIndex
9314 * @param {Roo.EventObject} e
9316 "cellcontextmenu" : true,
9318 * @event headercontextmenu
9319 * Fires when a header is right clicked
9320 * @param {Roo.bootstrap.Table} this
9321 * @param {Number} columnIndex
9322 * @param {Roo.EventObject} e
9324 "headercontextmenu" : true,
9327 * The raw mousedown event for the entire grid.
9328 * @param {Roo.EventObject} e
9335 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
9352 enableColumnResize: true,
9353 disableAutoSize: false,
9355 rowSelection : false,
9356 cellSelection : false,
9359 minColumnWidth : 50,
9361 // Roo.Element - the tbody
9362 bodyEl: false, // <tbody> Roo.Element - thead element
9363 headEl: false, // <thead> Roo.Element - thead element
9364 resizeProxy : false, // proxy element for dragging?
9368 container: false, // used by gridpanel...
9374 auto_hide_footer : false,
9376 view: false, // actually points to this..
9378 getAutoCreate : function()
9380 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
9387 // this get's auto added by panel.Grid
9388 if (this.scrollBody) {
9389 cfg.cls += ' table-body-fixed';
9392 cfg.cls += ' table-striped';
9396 cfg.cls += ' table-hover';
9398 if (this.bordered) {
9399 cfg.cls += ' table-bordered';
9401 if (this.condensed) {
9402 cfg.cls += ' table-condensed';
9405 if (this.responsive) {
9406 cfg.cls += ' table-responsive';
9410 cfg.cls+= ' ' +this.cls;
9416 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
9419 if(this.store || this.cm){
9420 if(this.headerShow){
9421 cfg.cn.push(this.renderHeader());
9424 cfg.cn.push(this.renderBody());
9426 if(this.footerShow){
9427 cfg.cn.push(this.renderFooter());
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()
9993 // Roo.log('ds onload');
9998 var ds = this.store;
10000 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
10001 e.select('i', true).removeClass(['fa-arrow-up', 'fa-arrow-down']);
10002 if (_this.store.sortInfo) {
10004 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
10005 e.select('i', true).addClass(['fa-arrow-up']);
10008 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
10009 e.select('i', true).addClass(['fa-arrow-down']);
10014 var tbody = this.bodyEl;
10016 if(ds.getCount() > 0){
10017 ds.data.each(function(d,rowIndex){
10018 var row = this.renderRow(cm, ds, rowIndex);
10020 tbody.createChild(row);
10024 if(row.cellObjects.length){
10025 Roo.each(row.cellObjects, function(r){
10026 _this.renderCellObject(r);
10031 } else if (this.empty_results.length) {
10032 this.el.mask(this.empty_results, 'no-spinner');
10035 var tfoot = this.el.select('tfoot', true).first();
10037 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
10039 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
10041 var total = this.ds.getTotalCount();
10043 if(this.footer.pageSize < total){
10044 this.mainFoot.show();
10048 Roo.each(this.el.select('tbody td', true).elements, function(e){
10049 e.on('mouseover', _this.onMouseover, _this);
10052 Roo.each(this.el.select('tbody td', true).elements, function(e){
10053 e.on('mouseout', _this.onMouseout, _this);
10055 this.fireEvent('rowsrendered', this);
10059 this.initCSS(); /// resize cols
10065 onUpdate : function(ds,record)
10067 this.refreshRow(record);
10071 onRemove : function(ds, record, index, isUpdate){
10072 if(isUpdate !== true){
10073 this.fireEvent("beforerowremoved", this, index, record);
10075 var bt = this.bodyEl.dom;
10077 var rows = this.el.select('tbody > tr', true).elements;
10079 if(typeof(rows[index]) != 'undefined'){
10080 bt.removeChild(rows[index].dom);
10083 // if(bt.rows[index]){
10084 // bt.removeChild(bt.rows[index]);
10087 if(isUpdate !== true){
10088 //this.stripeRows(index);
10089 //this.syncRowHeights(index, index);
10091 this.fireEvent("rowremoved", this, index, record);
10095 onAdd : function(ds, records, rowIndex)
10097 //Roo.log('on Add called');
10098 // - note this does not handle multiple adding very well..
10099 var bt = this.bodyEl.dom;
10100 for (var i =0 ; i < records.length;i++) {
10101 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
10102 //Roo.log(records[i]);
10103 //Roo.log(this.store.getAt(rowIndex+i));
10104 this.insertRow(this.store, rowIndex + i, false);
10111 refreshRow : function(record){
10112 var ds = this.store, index;
10113 if(typeof record == 'number'){
10115 record = ds.getAt(index);
10117 index = ds.indexOf(record);
10119 return; // should not happen - but seems to
10122 this.insertRow(ds, index, true);
10124 this.onRemove(ds, record, index+1, true);
10126 //this.syncRowHeights(index, index);
10128 this.fireEvent("rowupdated", this, index, record);
10130 // private - called by RowSelection
10131 onRowSelect : function(rowIndex){
10132 var row = this.getRowDom(rowIndex);
10133 row.addClass(['bg-info','info']);
10135 // private - called by RowSelection
10136 onRowDeselect : function(rowIndex)
10138 if (rowIndex < 0) {
10141 var row = this.getRowDom(rowIndex);
10142 row.removeClass(['bg-info','info']);
10145 * Focuses the specified row.
10146 * @param {Number} row The row index
10148 focusRow : function(row)
10150 //Roo.log('GridView.focusRow');
10151 var x = this.bodyEl.dom.scrollLeft;
10152 this.focusCell(row, 0, false);
10153 this.bodyEl.dom.scrollLeft = x;
10157 * Focuses the specified cell.
10158 * @param {Number} row The row index
10159 * @param {Number} col The column index
10160 * @param {Boolean} hscroll false to disable horizontal scrolling
10162 focusCell : function(row, col, hscroll)
10164 //Roo.log('GridView.focusCell');
10165 var el = this.ensureVisible(row, col, hscroll);
10166 // not sure what focusEL achives = it's a <a> pos relative
10167 //this.focusEl.alignTo(el, "tl-tl");
10169 // this.focusEl.focus();
10171 // this.focusEl.focus.defer(1, this.focusEl);
10176 * Scrolls the specified cell into view
10177 * @param {Number} row The row index
10178 * @param {Number} col The column index
10179 * @param {Boolean} hscroll false to disable horizontal scrolling
10181 ensureVisible : function(row, col, hscroll)
10183 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
10184 //return null; //disable for testing.
10185 if(typeof row != "number"){
10186 row = row.rowIndex;
10188 if(row < 0 && row >= this.ds.getCount()){
10191 col = (col !== undefined ? col : 0);
10193 while(cm.isHidden(col)){
10197 var el = this.getCellDom(row, col);
10201 var c = this.bodyEl.dom;
10203 var ctop = parseInt(el.offsetTop, 10);
10204 var cleft = parseInt(el.offsetLeft, 10);
10205 var cbot = ctop + el.offsetHeight;
10206 var cright = cleft + el.offsetWidth;
10208 //var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
10209 var ch = 0; //?? header is not withing the area?
10210 var stop = parseInt(c.scrollTop, 10);
10211 var sleft = parseInt(c.scrollLeft, 10);
10212 var sbot = stop + ch;
10213 var sright = sleft + c.clientWidth;
10215 Roo.log('GridView.ensureVisible:' +
10217 ' c.clientHeight:' + c.clientHeight +
10218 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
10226 c.scrollTop = ctop;
10227 //Roo.log("set scrolltop to ctop DISABLE?");
10228 }else if(cbot > sbot){
10229 //Roo.log("set scrolltop to cbot-ch");
10230 c.scrollTop = cbot-ch;
10233 if(hscroll !== false){
10235 c.scrollLeft = cleft;
10236 }else if(cright > sright){
10237 c.scrollLeft = cright-c.clientWidth;
10245 insertRow : function(dm, rowIndex, isUpdate){
10248 this.fireEvent("beforerowsinserted", this, rowIndex);
10250 //var s = this.getScrollState();
10251 var row = this.renderRow(this.cm, this.store, rowIndex);
10252 // insert before rowIndex..
10253 var e = this.bodyEl.createChild(row,this.getRowDom(rowIndex));
10257 if(row.cellObjects.length){
10258 Roo.each(row.cellObjects, function(r){
10259 _this.renderCellObject(r);
10264 this.fireEvent("rowsinserted", this, rowIndex);
10265 //this.syncRowHeights(firstRow, lastRow);
10266 //this.stripeRows(firstRow);
10273 getRowDom : function(rowIndex)
10275 var rows = this.el.select('tbody > tr', true).elements;
10277 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
10280 getCellDom : function(rowIndex, colIndex)
10282 var row = this.getRowDom(rowIndex);
10283 if (row === false) {
10286 var cols = row.select('td', true).elements;
10287 return (typeof(cols[colIndex]) == 'undefined') ? false : cols[colIndex];
10291 // returns the object tree for a tr..
10294 renderRow : function(cm, ds, rowIndex)
10296 var d = ds.getAt(rowIndex);
10300 cls : 'x-row-' + rowIndex,
10304 var cellObjects = [];
10306 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
10307 var config = cm.config[i];
10309 var renderer = cm.getRenderer(i);
10313 if(typeof(renderer) !== 'undefined'){
10314 value = renderer(d.data[cm.getDataIndex(i)], false, d);
10316 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
10317 // and are rendered into the cells after the row is rendered - using the id for the element.
10319 if(typeof(value) === 'object'){
10329 rowIndex : rowIndex,
10334 this.fireEvent('rowclass', this, rowcfg);
10338 // this might end up displaying HTML?
10339 // this is too messy... - better to only do it on columsn you know are going to be too long
10340 //tooltip : (typeof(value) === 'object') ? '' : value,
10341 cls : rowcfg.rowClass + ' x-col-' + i,
10343 html: (typeof(value) === 'object') ? '' : value
10350 if(typeof(config.colspan) != 'undefined'){
10351 td.colspan = config.colspan;
10356 if(typeof(config.align) != 'undefined' && config.align.length){
10357 td.style += ' text-align:' + config.align + ';';
10359 if(typeof(config.valign) != 'undefined' && config.valign.length){
10360 td.style += ' vertical-align:' + config.valign + ';';
10363 if(typeof(config.width) != 'undefined'){
10364 td.style += ' width:' + config.width + 'px;';
10368 if(typeof(config.cursor) != 'undefined'){
10369 td.style += ' cursor:' + config.cursor + ';';
10372 if(typeof(config.cls) != 'undefined'){
10373 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
10375 if (this.responsive) {
10376 ['xs','sm','md','lg'].map(function(size){
10378 if(typeof(config[size]) == 'undefined'){
10384 if (!config[size]) { // 0 = hidden
10385 // BS 4 '0' is treated as hide that column and below.
10386 td.cls += ' hidden-' + size + ' hidden' + size + '-down';
10390 td.cls += ' col-' + size + '-' + config[size] + (
10391 size == 'xs' ? (' col-' + config[size] ) : '' // bs4 col-{num} replaces col-xs
10401 row.cellObjects = cellObjects;
10409 onBeforeLoad : function()
10411 this.el.unmask(); // if needed.
10418 this.el.select('tbody', true).first().dom.innerHTML = '';
10421 * Show or hide a row.
10422 * @param {Number} rowIndex to show or hide
10423 * @param {Boolean} state hide
10425 setRowVisibility : function(rowIndex, state)
10427 var bt = this.bodyEl.dom;
10429 var rows = this.el.select('tbody > tr', true).elements;
10431 if(typeof(rows[rowIndex]) == 'undefined'){
10434 rows[rowIndex][ state ? 'removeClass' : 'addClass']('d-none');
10439 getSelectionModel : function(){
10440 if(!this.selModel){
10441 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
10443 return this.selModel;
10446 * Render the Roo.bootstrap object from renderder
10448 renderCellObject : function(r)
10452 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
10454 var t = r.cfg.render(r.container);
10457 Roo.each(r.cfg.cn, function(c){
10459 container: t.getChildContainer(),
10462 _this.renderCellObject(child);
10467 * get the Row Index from a dom element.
10468 * @param {Roo.Element} row The row to look for
10469 * @returns {Number} the row
10471 getRowIndex : function(row)
10475 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
10486 * get the header TH element for columnIndex
10487 * @param {Number} columnIndex
10488 * @returns {Roo.Element}
10490 getHeaderIndex: function(colIndex)
10492 var cols = this.headEl.select('th', true).elements;
10493 return cols[colIndex];
10496 * get the Column Index from a dom element. (using regex on x-hcol-{colid})
10497 * @param {domElement} cell to look for
10498 * @returns {Number} the column
10500 getCellIndex : function(cell)
10502 var id = String(cell.className).match(Roo.bootstrap.Table.cellRE);
10504 return parseInt(id[1], 10);
10509 * Returns the grid's underlying element = used by panel.Grid
10510 * @return {Element} The element
10512 getGridEl : function(){
10516 * Forces a resize - used by panel.Grid
10517 * @return {Element} The element
10519 autoSize : function()
10521 if(this.disableAutoSize) {
10524 //var ctr = Roo.get(this.container.dom.parentElement);
10525 var ctr = Roo.get(this.el.dom);
10527 var thd = this.getGridEl().select('thead',true).first();
10528 var tbd = this.getGridEl().select('tbody', true).first();
10529 var tfd = this.getGridEl().select('tfoot', true).first();
10531 var cw = ctr.getWidth();
10532 this.getGridEl().select('tfoot tr, tfoot td',true).setWidth(cw);
10536 tbd.setWidth(ctr.getWidth());
10537 // if the body has a max height - and then scrolls - we should perhaps set up the height here
10538 // this needs fixing for various usage - currently only hydra job advers I think..
10540 // ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
10542 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
10545 cw = Math.max(cw, this.totalWidth);
10546 this.getGridEl().select('tbody tr',true).setWidth(cw);
10549 // resize 'expandable coloumn?
10551 return; // we doe not have a view in this design..
10554 onBodyScroll: function()
10556 //Roo.log("body scrolled');" + this.bodyEl.dom.scrollLeft);
10558 this.headEl.setStyle({
10559 'position' : 'relative',
10560 'left': (-1* this.bodyEl.dom.scrollLeft) + 'px'
10566 var scrollHeight = this.bodyEl.dom.scrollHeight;
10568 var scrollTop = Math.ceil(this.bodyEl.getScroll().top);
10570 var height = this.bodyEl.getHeight();
10572 if(scrollHeight - height == scrollTop) {
10574 var total = this.ds.getTotalCount();
10576 if(this.footer.cursor + this.footer.pageSize < total){
10578 this.footer.ds.load({
10580 start : this.footer.cursor + this.footer.pageSize,
10581 limit : this.footer.pageSize
10590 onColumnSplitterMoved : function(i, diff)
10592 this.userResized = true;
10594 var cm = this.colModel;
10596 var w = this.getHeaderIndex(i).getWidth() + diff;
10599 cm.setColumnWidth(i, w, true);
10601 //var cid = cm.getColumnId(i); << not used in this version?
10602 /* Roo.log(['#' + this.id + ' .x-col-' + i, "width", w + "px"]);
10604 this.CSS.updateRule( '#' + this.id + ' .x-col-' + i, "width", w + "px");
10605 this.CSS.updateRule('#' + this.id + ' .x-hcol-' + i, "width", w + "px");
10606 this.CSS.updateRule('#' + this.id + ' .x-grid-split-' + i, "left", w + "px");
10608 //this.updateSplitters();
10609 //this.layout(); << ??
10610 this.fireEvent("columnresize", i, w);
10612 onHeaderChange : function()
10614 var header = this.renderHeader();
10615 var table = this.el.select('table', true).first();
10617 this.headEl.remove();
10618 this.headEl = table.createChild(header, this.bodyEl, false);
10620 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
10621 e.on('click', this.sort, this);
10624 if(this.enableColumnResize !== false && Roo.grid.SplitDragZone){
10625 new Roo.grid.SplitDragZone(this, this.headEl.dom, false); // not sure what 'lockedHd is for this implementation..)
10630 onHiddenChange : function(colModel, colIndex, hidden)
10633 this.cm.setHidden()
10634 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
10635 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
10637 this.CSS.updateRule(thSelector, "display", "");
10638 this.CSS.updateRule(tdSelector, "display", "");
10641 this.CSS.updateRule(thSelector, "display", "none");
10642 this.CSS.updateRule(tdSelector, "display", "none");
10645 // onload calls initCSS()
10646 this.onHeaderChange();
10650 setColumnWidth: function(col_index, width)
10652 // width = "md-2 xs-2..."
10653 if(!this.colModel.config[col_index]) {
10657 var w = width.split(" ");
10659 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
10661 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
10664 for(var j = 0; j < w.length; j++) {
10670 var size_cls = w[j].split("-");
10672 if(!Number.isInteger(size_cls[1] * 1)) {
10676 if(!this.colModel.config[col_index][size_cls[0]]) {
10680 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
10684 h_row[0].classList.replace(
10685 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
10686 "col-"+size_cls[0]+"-"+size_cls[1]
10689 for(var i = 0; i < rows.length; i++) {
10691 var size_cls = w[j].split("-");
10693 if(!Number.isInteger(size_cls[1] * 1)) {
10697 if(!this.colModel.config[col_index][size_cls[0]]) {
10701 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
10705 rows[i].classList.replace(
10706 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
10707 "col-"+size_cls[0]+"-"+size_cls[1]
10711 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
10716 // currently only used to find the split on drag..
10717 Roo.bootstrap.Table.cellRE = /(?:.*?)x-grid-(?:hd|cell|split)-([\d]+)(?:.*?)/;
10722 Roo.bootstrap.Table.AbstractSelectionModel = Roo.grid.AbstractSelectionModel;
10723 Roo.bootstrap.Table.RowSelectionModel = Roo.grid.RowSelectionModel;
10732 * @class Roo.bootstrap.TableCell
10733 * @extends Roo.bootstrap.Component
10734 * @children Roo.bootstrap.Component
10735 * @parent Roo.bootstrap.TableRow
10736 * Bootstrap TableCell class
10738 * @cfg {String} html cell contain text
10739 * @cfg {String} cls cell class
10740 * @cfg {String} tag cell tag (td|th) default td
10741 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
10742 * @cfg {String} align Aligns the content in a cell
10743 * @cfg {String} axis Categorizes cells
10744 * @cfg {String} bgcolor Specifies the background color of a cell
10745 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
10746 * @cfg {Number} colspan Specifies the number of columns a cell should span
10747 * @cfg {String} headers Specifies one or more header cells a cell is related to
10748 * @cfg {Number} height Sets the height of a cell
10749 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
10750 * @cfg {Number} rowspan Sets the number of rows a cell should span
10751 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
10752 * @cfg {String} valign Vertical aligns the content in a cell
10753 * @cfg {Number} width Specifies the width of a cell
10756 * Create a new TableCell
10757 * @param {Object} config The config object
10760 Roo.bootstrap.TableCell = function(config){
10761 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
10764 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
10784 getAutoCreate : function(){
10785 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
10792 cfg.tag = this.tag;
10805 cfg.align=this.align
10810 if (this.bgcolor) {
10811 cfg.bgcolor=this.bgcolor
10813 if (this.charoff) {
10814 cfg.charoff=this.charoff
10816 if (this.colspan) {
10817 cfg.colspan=this.colspan
10819 if (this.headers) {
10820 cfg.headers=this.headers
10823 cfg.height=this.height
10826 cfg.nowrap=this.nowrap
10828 if (this.rowspan) {
10829 cfg.rowspan=this.rowspan
10832 cfg.scope=this.scope
10835 cfg.valign=this.valign
10838 cfg.width=this.width
10857 * @class Roo.bootstrap.TableRow
10858 * @extends Roo.bootstrap.Component
10859 * @children Roo.bootstrap.TableCell
10860 * @parent Roo.bootstrap.TableBody
10861 * Bootstrap TableRow class
10862 * @cfg {String} cls row class
10863 * @cfg {String} align Aligns the content in a table row
10864 * @cfg {String} bgcolor Specifies a background color for a table row
10865 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
10866 * @cfg {String} valign Vertical aligns the content in a table row
10869 * Create a new TableRow
10870 * @param {Object} config The config object
10873 Roo.bootstrap.TableRow = function(config){
10874 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
10877 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
10885 getAutoCreate : function(){
10886 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
10893 cfg.cls = this.cls;
10896 cfg.align = this.align;
10899 cfg.bgcolor = this.bgcolor;
10902 cfg.charoff = this.charoff;
10905 cfg.valign = this.valign;
10923 * @class Roo.bootstrap.TableBody
10924 * @extends Roo.bootstrap.Component
10925 * @children Roo.bootstrap.TableRow
10926 * @parent Roo.bootstrap.Table
10927 * Bootstrap TableBody class
10928 * @cfg {String} cls element class
10929 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
10930 * @cfg {String} align Aligns the content inside the element
10931 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
10932 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
10935 * Create a new TableBody
10936 * @param {Object} config The config object
10939 Roo.bootstrap.TableBody = function(config){
10940 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
10943 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
10951 getAutoCreate : function(){
10952 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
10962 cfg.tag = this.tag;
10966 cfg.align = this.align;
10969 cfg.charoff = this.charoff;
10972 cfg.valign = this.valign;
10979 // initEvents : function()
10982 // if(!this.store){
10986 // this.store = Roo.factory(this.store, Roo.data);
10987 // this.store.on('load', this.onLoad, this);
10989 // this.store.load();
10993 // onLoad: function ()
10995 // this.fireEvent('load', this);
11005 * Ext JS Library 1.1.1
11006 * Copyright(c) 2006-2007, Ext JS, LLC.
11008 * Originally Released Under LGPL - original licence link has changed is not relivant.
11011 * <script type="text/javascript">
11014 // as we use this in bootstrap.
11015 Roo.namespace('Roo.form');
11017 * @class Roo.form.Action
11018 * Internal Class used to handle form actions
11020 * @param {Roo.form.BasicForm} el The form element or its id
11021 * @param {Object} config Configuration options
11026 // define the action interface
11027 Roo.form.Action = function(form, options){
11029 this.options = options || {};
11032 * Client Validation Failed
11035 Roo.form.Action.CLIENT_INVALID = 'client';
11037 * Server Validation Failed
11040 Roo.form.Action.SERVER_INVALID = 'server';
11042 * Connect to Server Failed
11045 Roo.form.Action.CONNECT_FAILURE = 'connect';
11047 * Reading Data from Server Failed
11050 Roo.form.Action.LOAD_FAILURE = 'load';
11052 Roo.form.Action.prototype = {
11054 failureType : undefined,
11055 response : undefined,
11056 result : undefined,
11058 // interface method
11059 run : function(options){
11063 // interface method
11064 success : function(response){
11068 // interface method
11069 handleResponse : function(response){
11073 // default connection failure
11074 failure : function(response){
11076 this.response = response;
11077 this.failureType = Roo.form.Action.CONNECT_FAILURE;
11078 this.form.afterAction(this, false);
11081 processResponse : function(response){
11082 this.response = response;
11083 if(!response.responseText){
11086 this.result = this.handleResponse(response);
11087 return this.result;
11090 // utility functions used internally
11091 getUrl : function(appendParams){
11092 var url = this.options.url || this.form.url || this.form.el.dom.action;
11094 var p = this.getParams();
11096 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11102 getMethod : function(){
11103 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
11106 getParams : function(){
11107 var bp = this.form.baseParams;
11108 var p = this.options.params;
11110 if(typeof p == "object"){
11111 p = Roo.urlEncode(Roo.applyIf(p, bp));
11112 }else if(typeof p == 'string' && bp){
11113 p += '&' + Roo.urlEncode(bp);
11116 p = Roo.urlEncode(bp);
11121 createCallback : function(){
11123 success: this.success,
11124 failure: this.failure,
11126 timeout: (this.form.timeout*1000),
11127 upload: this.form.fileUpload ? this.success : undefined
11132 Roo.form.Action.Submit = function(form, options){
11133 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
11136 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
11139 haveProgress : false,
11140 uploadComplete : false,
11142 // uploadProgress indicator.
11143 uploadProgress : function()
11145 if (!this.form.progressUrl) {
11149 if (!this.haveProgress) {
11150 Roo.MessageBox.progress("Uploading", "Uploading");
11152 if (this.uploadComplete) {
11153 Roo.MessageBox.hide();
11157 this.haveProgress = true;
11159 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
11161 var c = new Roo.data.Connection();
11163 url : this.form.progressUrl,
11168 success : function(req){
11169 //console.log(data);
11173 rdata = Roo.decode(req.responseText)
11175 Roo.log("Invalid data from server..");
11179 if (!rdata || !rdata.success) {
11181 Roo.MessageBox.alert(Roo.encode(rdata));
11184 var data = rdata.data;
11186 if (this.uploadComplete) {
11187 Roo.MessageBox.hide();
11192 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
11193 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
11196 this.uploadProgress.defer(2000,this);
11199 failure: function(data) {
11200 Roo.log('progress url failed ');
11211 // run get Values on the form, so it syncs any secondary forms.
11212 this.form.getValues();
11214 var o = this.options;
11215 var method = this.getMethod();
11216 var isPost = method == 'POST';
11217 if(o.clientValidation === false || this.form.isValid()){
11219 if (this.form.progressUrl) {
11220 this.form.findField('UPLOAD_IDENTIFIER').setValue(
11221 (new Date() * 1) + '' + Math.random());
11226 Roo.Ajax.request(Roo.apply(this.createCallback(), {
11227 form:this.form.el.dom,
11228 url:this.getUrl(!isPost),
11230 params:isPost ? this.getParams() : null,
11231 isUpload: this.form.fileUpload,
11232 formData : this.form.formData
11235 this.uploadProgress();
11237 }else if (o.clientValidation !== false){ // client validation failed
11238 this.failureType = Roo.form.Action.CLIENT_INVALID;
11239 this.form.afterAction(this, false);
11243 success : function(response)
11245 this.uploadComplete= true;
11246 if (this.haveProgress) {
11247 Roo.MessageBox.hide();
11251 var result = this.processResponse(response);
11252 if(result === true || result.success){
11253 this.form.afterAction(this, true);
11257 this.form.markInvalid(result.errors);
11258 this.failureType = Roo.form.Action.SERVER_INVALID;
11260 this.form.afterAction(this, false);
11262 failure : function(response)
11264 this.uploadComplete= true;
11265 if (this.haveProgress) {
11266 Roo.MessageBox.hide();
11269 this.response = response;
11270 this.failureType = Roo.form.Action.CONNECT_FAILURE;
11271 this.form.afterAction(this, false);
11274 handleResponse : function(response){
11275 if(this.form.errorReader){
11276 var rs = this.form.errorReader.read(response);
11279 for(var i = 0, len = rs.records.length; i < len; i++) {
11280 var r = rs.records[i];
11281 errors[i] = r.data;
11284 if(errors.length < 1){
11288 success : rs.success,
11294 ret = Roo.decode(response.responseText);
11298 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
11308 Roo.form.Action.Load = function(form, options){
11309 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
11310 this.reader = this.form.reader;
11313 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
11318 Roo.Ajax.request(Roo.apply(
11319 this.createCallback(), {
11320 method:this.getMethod(),
11321 url:this.getUrl(false),
11322 params:this.getParams()
11326 success : function(response){
11328 var result = this.processResponse(response);
11329 if(result === true || !result.success || !result.data){
11330 this.failureType = Roo.form.Action.LOAD_FAILURE;
11331 this.form.afterAction(this, false);
11334 this.form.clearInvalid();
11335 this.form.setValues(result.data);
11336 this.form.afterAction(this, true);
11339 handleResponse : function(response){
11340 if(this.form.reader){
11341 var rs = this.form.reader.read(response);
11342 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
11344 success : rs.success,
11348 return Roo.decode(response.responseText);
11352 Roo.form.Action.ACTION_TYPES = {
11353 'load' : Roo.form.Action.Load,
11354 'submit' : Roo.form.Action.Submit
11363 * @class Roo.bootstrap.form.Form
11364 * @extends Roo.bootstrap.Component
11365 * @children Roo.bootstrap.Component
11366 * Bootstrap Form class
11367 * @cfg {String} method GET | POST (default POST)
11368 * @cfg {String} labelAlign top | left (default top)
11369 * @cfg {String} align left | right - for navbars
11370 * @cfg {Boolean} loadMask load mask when submit (default true)
11374 * Create a new Form
11375 * @param {Object} config The config object
11379 Roo.bootstrap.form.Form = function(config){
11381 Roo.bootstrap.form.Form.superclass.constructor.call(this, config);
11383 Roo.bootstrap.form.Form.popover.apply();
11387 * @event clientvalidation
11388 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
11389 * @param {Form} this
11390 * @param {Boolean} valid true if the form has passed client-side validation
11392 clientvalidation: true,
11394 * @event beforeaction
11395 * Fires before any action is performed. Return false to cancel the action.
11396 * @param {Form} this
11397 * @param {Action} action The action to be performed
11399 beforeaction: true,
11401 * @event actionfailed
11402 * Fires when an action fails.
11403 * @param {Form} this
11404 * @param {Action} action The action that failed
11406 actionfailed : true,
11408 * @event actioncomplete
11409 * Fires when an action is completed.
11410 * @param {Form} this
11411 * @param {Action} action The action that completed
11413 actioncomplete : true
11417 Roo.extend(Roo.bootstrap.form.Form, Roo.bootstrap.Component, {
11420 * @cfg {String} method
11421 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
11425 * @cfg {String} url
11426 * The URL to use for form actions if one isn't supplied in the action options.
11429 * @cfg {Boolean} fileUpload
11430 * Set to true if this form is a file upload.
11434 * @cfg {Object} baseParams
11435 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
11439 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
11443 * @cfg {Sting} align (left|right) for navbar forms
11448 activeAction : null,
11451 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
11452 * element by passing it or its id or mask the form itself by passing in true.
11455 waitMsgTarget : false,
11460 * @cfg {Boolean} errorMask (true|false) default false
11465 * @cfg {Number} maskOffset Default 100
11470 * @cfg {Boolean} maskBody
11474 getAutoCreate : function(){
11478 method : this.method || 'POST',
11479 id : this.id || Roo.id(),
11482 if (this.parent().xtype.match(/^Nav/)) {
11483 cfg.cls = 'navbar-form form-inline navbar-' + this.align;
11487 if (this.labelAlign == 'left' ) {
11488 cfg.cls += ' form-horizontal';
11494 initEvents : function()
11496 this.el.on('submit', this.onSubmit, this);
11497 // this was added as random key presses on the form where triggering form submit.
11498 this.el.on('keypress', function(e) {
11499 if (e.getCharCode() != 13) {
11502 // we might need to allow it for textareas.. and some other items.
11503 // check e.getTarget().
11505 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
11509 Roo.log("keypress blocked");
11511 e.preventDefault();
11517 onSubmit : function(e){
11522 * Returns true if client-side validation on the form is successful.
11525 isValid : function(){
11526 var items = this.getItems();
11528 var target = false;
11530 items.each(function(f){
11536 Roo.log('invalid field: ' + f.name);
11540 if(!target && f.el.isVisible(true)){
11546 if(this.errorMask && !valid){
11547 Roo.bootstrap.form.Form.popover.mask(this, target);
11554 * Returns true if any fields in this form have changed since their original load.
11557 isDirty : function(){
11559 var items = this.getItems();
11560 items.each(function(f){
11570 * Performs a predefined action (submit or load) or custom actions you define on this form.
11571 * @param {String} actionName The name of the action type
11572 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
11573 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
11574 * accept other config options):
11576 Property Type Description
11577 ---------------- --------------- ----------------------------------------------------------------------------------
11578 url String The url for the action (defaults to the form's url)
11579 method String The form method to use (defaults to the form's method, or POST if not defined)
11580 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
11581 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
11582 validate the form on the client (defaults to false)
11584 * @return {BasicForm} this
11586 doAction : function(action, options){
11587 if(typeof action == 'string'){
11588 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
11590 if(this.fireEvent('beforeaction', this, action) !== false){
11591 this.beforeAction(action);
11592 action.run.defer(100, action);
11598 beforeAction : function(action){
11599 var o = action.options;
11604 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
11606 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
11609 // not really supported yet.. ??
11611 //if(this.waitMsgTarget === true){
11612 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
11613 //}else if(this.waitMsgTarget){
11614 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
11615 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
11617 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
11623 afterAction : function(action, success){
11624 this.activeAction = null;
11625 var o = action.options;
11630 Roo.get(document.body).unmask();
11636 //if(this.waitMsgTarget === true){
11637 // this.el.unmask();
11638 //}else if(this.waitMsgTarget){
11639 // this.waitMsgTarget.unmask();
11641 // Roo.MessageBox.updateProgress(1);
11642 // Roo.MessageBox.hide();
11649 Roo.callback(o.success, o.scope, [this, action]);
11650 this.fireEvent('actioncomplete', this, action);
11654 // failure condition..
11655 // we have a scenario where updates need confirming.
11656 // eg. if a locking scenario exists..
11657 // we look for { errors : { needs_confirm : true }} in the response.
11659 (typeof(action.result) != 'undefined') &&
11660 (typeof(action.result.errors) != 'undefined') &&
11661 (typeof(action.result.errors.needs_confirm) != 'undefined')
11664 Roo.log("not supported yet");
11667 Roo.MessageBox.confirm(
11668 "Change requires confirmation",
11669 action.result.errorMsg,
11674 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
11684 Roo.callback(o.failure, o.scope, [this, action]);
11685 // show an error message if no failed handler is set..
11686 if (!this.hasListener('actionfailed')) {
11687 Roo.log("need to add dialog support");
11689 Roo.MessageBox.alert("Error",
11690 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
11691 action.result.errorMsg :
11692 "Saving Failed, please check your entries or try again"
11697 this.fireEvent('actionfailed', this, action);
11702 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
11703 * @param {String} id The value to search for
11706 findField : function(id){
11707 var items = this.getItems();
11708 var field = items.get(id);
11710 items.each(function(f){
11711 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
11718 return field || null;
11721 * Mark fields in this form invalid in bulk.
11722 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
11723 * @return {BasicForm} this
11725 markInvalid : function(errors){
11726 if(errors instanceof Array){
11727 for(var i = 0, len = errors.length; i < len; i++){
11728 var fieldError = errors[i];
11729 var f = this.findField(fieldError.id);
11731 f.markInvalid(fieldError.msg);
11737 if(typeof errors[id] != 'function' && (field = this.findField(id))){
11738 field.markInvalid(errors[id]);
11742 //Roo.each(this.childForms || [], function (f) {
11743 // f.markInvalid(errors);
11750 * Set values for fields in this form in bulk.
11751 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
11752 * @return {BasicForm} this
11754 setValues : function(values){
11755 if(values instanceof Array){ // array of objects
11756 for(var i = 0, len = values.length; i < len; i++){
11758 var f = this.findField(v.id);
11760 f.setValue(v.value);
11761 if(this.trackResetOnLoad){
11762 f.originalValue = f.getValue();
11766 }else{ // object hash
11769 if(typeof values[id] != 'function' && (field = this.findField(id))){
11771 if (field.setFromData &&
11772 field.valueField &&
11773 field.displayField &&
11774 // combos' with local stores can
11775 // be queried via setValue()
11776 // to set their value..
11777 (field.store && !field.store.isLocal)
11781 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
11782 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
11783 field.setFromData(sd);
11785 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
11787 field.setFromData(values);
11790 field.setValue(values[id]);
11794 if(this.trackResetOnLoad){
11795 field.originalValue = field.getValue();
11801 //Roo.each(this.childForms || [], function (f) {
11802 // f.setValues(values);
11809 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
11810 * they are returned as an array.
11811 * @param {Boolean} asString
11814 getValues : function(asString){
11815 //if (this.childForms) {
11816 // copy values from the child forms
11817 // Roo.each(this.childForms, function (f) {
11818 // this.setValues(f.getValues());
11824 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
11825 if(asString === true){
11828 return Roo.urlDecode(fs);
11832 * Returns the fields in this form as an object with key/value pairs.
11833 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
11836 getFieldValues : function(with_hidden)
11838 var items = this.getItems();
11840 items.each(function(f){
11842 if (!f.getName()) {
11846 var v = f.getValue();
11848 if (f.inputType =='radio') {
11849 if (typeof(ret[f.getName()]) == 'undefined') {
11850 ret[f.getName()] = ''; // empty..
11853 if (!f.el.dom.checked) {
11857 v = f.el.dom.value;
11861 if(f.xtype == 'MoneyField'){
11862 ret[f.currencyName] = f.getCurrency();
11865 // not sure if this supported any more..
11866 if ((typeof(v) == 'object') && f.getRawValue) {
11867 v = f.getRawValue() ; // dates..
11869 // combo boxes where name != hiddenName...
11870 if (f.name !== false && f.name != '' && f.name != f.getName()) {
11871 ret[f.name] = f.getRawValue();
11873 ret[f.getName()] = v;
11880 * Clears all invalid messages in this form.
11881 * @return {BasicForm} this
11883 clearInvalid : function(){
11884 var items = this.getItems();
11886 items.each(function(f){
11894 * Resets this form.
11895 * @return {BasicForm} this
11897 reset : function(){
11898 var items = this.getItems();
11899 items.each(function(f){
11903 Roo.each(this.childForms || [], function (f) {
11911 getItems : function()
11913 var r=new Roo.util.MixedCollection(false, function(o){
11914 return o.id || (o.id = Roo.id());
11916 var iter = function(el) {
11923 Roo.each(el.items,function(e) {
11932 hideFields : function(items)
11934 Roo.each(items, function(i){
11936 var f = this.findField(i);
11947 showFields : function(items)
11949 Roo.each(items, function(i){
11951 var f = this.findField(i);
11964 Roo.apply(Roo.bootstrap.form.Form, {
11980 intervalID : false,
11986 if(this.isApplied){
11991 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
11992 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
11993 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
11994 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
11997 this.maskEl.top.enableDisplayMode("block");
11998 this.maskEl.left.enableDisplayMode("block");
11999 this.maskEl.bottom.enableDisplayMode("block");
12000 this.maskEl.right.enableDisplayMode("block");
12002 this.toolTip = new Roo.bootstrap.Tooltip({
12003 cls : 'roo-form-error-popover',
12005 'left' : ['r-l', [-2,0], 'right'],
12006 'right' : ['l-r', [2,0], 'left'],
12007 'bottom' : ['tl-bl', [0,2], 'top'],
12008 'top' : [ 'bl-tl', [0,-2], 'bottom']
12012 this.toolTip.render(Roo.get(document.body));
12014 this.toolTip.el.enableDisplayMode("block");
12016 Roo.get(document.body).on('click', function(){
12020 Roo.get(document.body).on('touchstart', function(){
12024 this.isApplied = true
12027 mask : function(form, target)
12031 this.target = target;
12033 if(!this.form.errorMask || !target.el){
12037 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
12039 Roo.log(scrollable);
12041 var ot = this.target.el.calcOffsetsTo(scrollable);
12043 var scrollTo = ot[1] - this.form.maskOffset;
12045 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
12047 scrollable.scrollTo('top', scrollTo);
12049 var box = this.target.el.getBox();
12051 var zIndex = Roo.bootstrap.Modal.zIndex++;
12054 this.maskEl.top.setStyle('position', 'absolute');
12055 this.maskEl.top.setStyle('z-index', zIndex);
12056 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
12057 this.maskEl.top.setLeft(0);
12058 this.maskEl.top.setTop(0);
12059 this.maskEl.top.show();
12061 this.maskEl.left.setStyle('position', 'absolute');
12062 this.maskEl.left.setStyle('z-index', zIndex);
12063 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
12064 this.maskEl.left.setLeft(0);
12065 this.maskEl.left.setTop(box.y - this.padding);
12066 this.maskEl.left.show();
12068 this.maskEl.bottom.setStyle('position', 'absolute');
12069 this.maskEl.bottom.setStyle('z-index', zIndex);
12070 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
12071 this.maskEl.bottom.setLeft(0);
12072 this.maskEl.bottom.setTop(box.bottom + this.padding);
12073 this.maskEl.bottom.show();
12075 this.maskEl.right.setStyle('position', 'absolute');
12076 this.maskEl.right.setStyle('z-index', zIndex);
12077 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
12078 this.maskEl.right.setLeft(box.right + this.padding);
12079 this.maskEl.right.setTop(box.y - this.padding);
12080 this.maskEl.right.show();
12082 this.toolTip.bindEl = this.target.el;
12084 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
12086 var tip = this.target.blankText;
12088 if(this.target.getValue() !== '' ) {
12090 if (this.target.invalidText.length) {
12091 tip = this.target.invalidText;
12092 } else if (this.target.regexText.length){
12093 tip = this.target.regexText;
12097 this.toolTip.show(tip);
12099 this.intervalID = window.setInterval(function() {
12100 Roo.bootstrap.form.Form.popover.unmask();
12103 window.onwheel = function(){ return false;};
12105 (function(){ this.isMasked = true; }).defer(500, this);
12109 unmask : function()
12111 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
12115 this.maskEl.top.setStyle('position', 'absolute');
12116 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
12117 this.maskEl.top.hide();
12119 this.maskEl.left.setStyle('position', 'absolute');
12120 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
12121 this.maskEl.left.hide();
12123 this.maskEl.bottom.setStyle('position', 'absolute');
12124 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
12125 this.maskEl.bottom.hide();
12127 this.maskEl.right.setStyle('position', 'absolute');
12128 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
12129 this.maskEl.right.hide();
12131 this.toolTip.hide();
12133 this.toolTip.el.hide();
12135 window.onwheel = function(){ return true;};
12137 if(this.intervalID){
12138 window.clearInterval(this.intervalID);
12139 this.intervalID = false;
12142 this.isMasked = false;
12152 * Ext JS Library 1.1.1
12153 * Copyright(c) 2006-2007, Ext JS, LLC.
12155 * Originally Released Under LGPL - original licence link has changed is not relivant.
12158 * <script type="text/javascript">
12161 * @class Roo.form.VTypes
12162 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
12165 Roo.form.VTypes = function(){
12166 // closure these in so they are only created once.
12167 var alpha = /^[a-zA-Z_]+$/;
12168 var alphanum = /^[a-zA-Z0-9_]+$/;
12169 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
12170 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
12172 // All these messages and functions are configurable
12175 * The function used to validate email addresses
12176 * @param {String} value The email address
12178 'email' : function(v){
12179 return email.test(v);
12182 * The error text to display when the email validation function returns false
12185 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
12187 * The keystroke filter mask to be applied on email input
12190 'emailMask' : /[a-z0-9_\.\-@]/i,
12193 * The function used to validate URLs
12194 * @param {String} value The URL
12196 'url' : function(v){
12197 return url.test(v);
12200 * The error text to display when the url validation function returns false
12203 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
12206 * The function used to validate alpha values
12207 * @param {String} value The value
12209 'alpha' : function(v){
12210 return alpha.test(v);
12213 * The error text to display when the alpha validation function returns false
12216 'alphaText' : 'This field should only contain letters and _',
12218 * The keystroke filter mask to be applied on alpha input
12221 'alphaMask' : /[a-z_]/i,
12224 * The function used to validate alphanumeric values
12225 * @param {String} value The value
12227 'alphanum' : function(v){
12228 return alphanum.test(v);
12231 * The error text to display when the alphanumeric validation function returns false
12234 'alphanumText' : 'This field should only contain letters, numbers and _',
12236 * The keystroke filter mask to be applied on alphanumeric input
12239 'alphanumMask' : /[a-z0-9_]/i
12249 * @class Roo.bootstrap.form.Input
12250 * @extends Roo.bootstrap.Component
12251 * Bootstrap Input class
12252 * @cfg {Boolean} disabled is it disabled
12253 * @cfg {String} inputType (button|checkbox|email|file|hidden|image|number|password|radio|range|reset|search|submit|text)
12254 * @cfg {String} name name of the input
12255 * @cfg {string} fieldLabel - the label associated
12256 * @cfg {string} placeholder - placeholder to put in text.
12257 * @cfg {string} before - input group add on before
12258 * @cfg {string} after - input group add on after
12259 * @cfg {string} size - (lg|sm) or leave empty..
12260 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
12261 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
12262 * @cfg {Number} md colspan out of 12 for computer-sized screens
12263 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
12264 * @cfg {string} value default value of the input
12265 * @cfg {Number} labelWidth set the width of label
12266 * @cfg {Number} labellg set the width of label (1-12)
12267 * @cfg {Number} labelmd set the width of label (1-12)
12268 * @cfg {Number} labelsm set the width of label (1-12)
12269 * @cfg {Number} labelxs set the width of label (1-12)
12270 * @cfg {String} labelAlign (top|left)
12271 * @cfg {Boolean} readOnly Specifies that the field should be read-only
12272 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
12273 * @cfg {String} indicatorpos (left|right) default left
12274 * @cfg {String} capture (user|camera) use for file input only. (default empty)
12275 * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
12276 * @cfg {Boolean} preventMark Do not show tick or cross if error/success
12277 * @cfg {Roo.bootstrap.Button} before Button to show before
12278 * @cfg {Roo.bootstrap.Button} afterButton to show before
12279 * @cfg {String} align (left|center|right) Default left
12280 * @cfg {Boolean} forceFeedback (true|false) Default false
12283 * Create a new Input
12284 * @param {Object} config The config object
12287 Roo.bootstrap.form.Input = function(config){
12289 Roo.bootstrap.form.Input.superclass.constructor.call(this, config);
12294 * Fires when this field receives input focus.
12295 * @param {Roo.form.Field} this
12300 * Fires when this field loses input focus.
12301 * @param {Roo.form.Field} this
12305 * @event specialkey
12306 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
12307 * {@link Roo.EventObject#getKey} to determine which key was pressed.
12308 * @param {Roo.form.Field} this
12309 * @param {Roo.EventObject} e The event object
12314 * Fires just before the field blurs if the field value has changed.
12315 * @param {Roo.form.Field} this
12316 * @param {Mixed} newValue The new value
12317 * @param {Mixed} oldValue The original value
12322 * Fires after the field has been marked as invalid.
12323 * @param {Roo.form.Field} this
12324 * @param {String} msg The validation message
12329 * Fires after the field has been validated with no errors.
12330 * @param {Roo.form.Field} this
12335 * Fires after the key up
12336 * @param {Roo.form.Field} this
12337 * @param {Roo.EventObject} e The event Object
12342 * Fires after the user pastes into input
12343 * @param {Roo.form.Field} this
12344 * @param {Roo.EventObject} e The event Object
12350 Roo.extend(Roo.bootstrap.form.Input, Roo.bootstrap.Component, {
12352 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
12353 automatic validation (defaults to "keyup").
12355 validationEvent : "keyup",
12357 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
12359 validateOnBlur : true,
12361 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
12363 validationDelay : 250,
12365 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
12367 focusClass : "x-form-focus", // not needed???
12371 * @cfg {String} invalidClass DEPRICATED - code uses BS4 - is-valid / is-invalid
12373 invalidClass : "has-warning",
12376 * @cfg {String} validClass DEPRICATED - code uses BS4 - is-valid / is-invalid
12378 validClass : "has-success",
12381 * @cfg {Boolean} hasFeedback (true|false) default true
12383 hasFeedback : true,
12386 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
12388 invalidFeedbackClass : "glyphicon-warning-sign",
12391 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
12393 validFeedbackClass : "glyphicon-ok",
12396 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
12398 selectOnFocus : false,
12401 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
12405 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
12410 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
12412 disableKeyFilter : false,
12415 * @cfg {Boolean} disabled True to disable the field (defaults to false).
12419 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
12423 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
12425 blankText : "Please complete this mandatory field",
12428 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
12432 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
12434 maxLength : Number.MAX_VALUE,
12436 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
12438 minLengthText : "The minimum length for this field is {0}",
12440 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
12442 maxLengthText : "The maximum length for this field is {0}",
12446 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
12447 * If available, this function will be called only after the basic validators all return true, and will be passed the
12448 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
12452 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
12453 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
12454 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
12458 * @cfg {String} regexText -- Depricated - use Invalid Text
12463 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
12469 autocomplete: false,
12473 inputType : 'text',
12476 placeholder: false,
12481 preventMark: false,
12482 isFormField : true,
12485 labelAlign : false,
12488 formatedValue : false,
12489 forceFeedback : false,
12491 indicatorpos : 'left',
12501 parentLabelAlign : function()
12504 while (parent.parent()) {
12505 parent = parent.parent();
12506 if (typeof(parent.labelAlign) !='undefined') {
12507 return parent.labelAlign;
12514 getAutoCreate : function()
12516 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
12522 if(this.inputType != 'hidden'){
12523 cfg.cls = 'form-group' //input-group
12529 type : this.inputType,
12530 value : this.value,
12531 cls : 'form-control',
12532 placeholder : this.placeholder || '',
12533 autocomplete : this.autocomplete || 'new-password'
12535 if (this.inputType == 'file') {
12536 input.style = 'overflow:hidden'; // why not in CSS?
12539 if(this.capture.length){
12540 input.capture = this.capture;
12543 if(this.accept.length){
12544 input.accept = this.accept + "/*";
12548 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
12551 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
12552 input.maxLength = this.maxLength;
12555 if (this.disabled) {
12556 input.disabled=true;
12559 if (this.readOnly) {
12560 input.readonly=true;
12564 input.name = this.name;
12568 input.cls += ' input-' + this.size;
12572 ['xs','sm','md','lg'].map(function(size){
12573 if (settings[size]) {
12574 cfg.cls += ' col-' + size + '-' + settings[size];
12578 var inputblock = input;
12582 cls: 'glyphicon form-control-feedback'
12585 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
12588 cls : 'has-feedback',
12596 if (this.before || this.after) {
12599 cls : 'input-group',
12603 if (this.before && typeof(this.before) == 'string') {
12605 inputblock.cn.push({
12607 cls : 'roo-input-before input-group-addon input-group-prepend input-group-text',
12611 if (this.before && typeof(this.before) == 'object') {
12612 this.before = Roo.factory(this.before);
12614 inputblock.cn.push({
12616 cls : 'roo-input-before input-group-prepend input-group-' +
12617 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
12621 inputblock.cn.push(input);
12623 if (this.after && typeof(this.after) == 'string') {
12624 inputblock.cn.push({
12626 cls : 'roo-input-after input-group-append input-group-text input-group-addon',
12630 if (this.after && typeof(this.after) == 'object') {
12631 this.after = Roo.factory(this.after);
12633 inputblock.cn.push({
12635 cls : 'roo-input-after input-group-append input-group-' +
12636 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
12640 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
12641 inputblock.cls += ' has-feedback';
12642 inputblock.cn.push(feedback);
12647 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
12648 tooltip : 'This field is required'
12650 if (this.allowBlank ) {
12651 indicator.style = this.allowBlank ? ' display:none' : '';
12653 if (align ==='left' && this.fieldLabel.length) {
12655 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
12662 cls : 'control-label col-form-label',
12663 html : this.fieldLabel
12674 var labelCfg = cfg.cn[1];
12675 var contentCfg = cfg.cn[2];
12677 if(this.indicatorpos == 'right'){
12682 cls : 'control-label col-form-label',
12686 html : this.fieldLabel
12700 labelCfg = cfg.cn[0];
12701 contentCfg = cfg.cn[1];
12705 if(this.labelWidth > 12){
12706 labelCfg.style = "width: " + this.labelWidth + 'px';
12709 if(this.labelWidth < 13 && this.labelmd == 0){
12710 this.labellg = this.labellg > 0 ? this.labellg : this.labelWidth;
12713 if(this.labellg > 0){
12714 labelCfg.cls += ' col-lg-' + this.labellg;
12715 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
12718 if(this.labelmd > 0){
12719 labelCfg.cls += ' col-md-' + this.labelmd;
12720 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
12723 if(this.labelsm > 0){
12724 labelCfg.cls += ' col-sm-' + this.labelsm;
12725 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
12728 if(this.labelxs > 0){
12729 labelCfg.cls += ' col-xs-' + this.labelxs;
12730 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
12734 } else if ( this.fieldLabel.length) {
12741 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12742 tooltip : 'This field is required',
12743 style : this.allowBlank ? ' display:none' : ''
12747 //cls : 'input-group-addon',
12748 html : this.fieldLabel
12756 if(this.indicatorpos == 'right'){
12761 //cls : 'input-group-addon',
12762 html : this.fieldLabel
12767 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12768 tooltip : 'This field is required',
12769 style : this.allowBlank ? ' display:none' : ''
12789 if (this.parentType === 'Navbar' && this.parent().bar) {
12790 cfg.cls += ' navbar-form';
12793 if (this.parentType === 'NavGroup' && !(Roo.bootstrap.version == 4 && this.parent().form)) {
12794 // on BS4 we do this only if not form
12795 cfg.cls += ' navbar-form';
12803 * return the real input element.
12805 inputEl: function ()
12807 return this.el.select('input.form-control',true).first();
12810 tooltipEl : function()
12812 return this.inputEl();
12815 indicatorEl : function()
12817 if (Roo.bootstrap.version == 4) {
12818 return false; // not enabled in v4 yet.
12821 var indicator = this.el.select('i.roo-required-indicator',true).first();
12831 setDisabled : function(v)
12833 var i = this.inputEl().dom;
12835 i.removeAttribute('disabled');
12839 i.setAttribute('disabled','true');
12841 initEvents : function()
12844 this.inputEl().on("keydown" , this.fireKey, this);
12845 this.inputEl().on("focus", this.onFocus, this);
12846 this.inputEl().on("blur", this.onBlur, this);
12848 this.inputEl().relayEvent('keyup', this);
12849 this.inputEl().relayEvent('paste', this);
12851 this.indicator = this.indicatorEl();
12853 if(this.indicator){
12854 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? -
12857 // reference to original value for reset
12858 this.originalValue = this.getValue();
12859 //Roo.form.TextField.superclass.initEvents.call(this);
12860 if(this.validationEvent == 'keyup'){
12861 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
12862 this.inputEl().on('keyup', this.filterValidation, this);
12864 else if(this.validationEvent !== false){
12865 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
12868 if(this.selectOnFocus){
12869 this.on("focus", this.preFocus, this);
12872 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
12873 this.inputEl().on("keypress", this.filterKeys, this);
12875 this.inputEl().relayEvent('keypress', this);
12878 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
12879 this.el.on("click", this.autoSize, this);
12882 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
12883 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
12886 if (typeof(this.before) == 'object') {
12887 this.before.render(this.el.select('.roo-input-before',true).first());
12889 if (typeof(this.after) == 'object') {
12890 this.after.render(this.el.select('.roo-input-after',true).first());
12893 this.inputEl().on('change', this.onChange, this);
12896 filterValidation : function(e){
12897 if(!e.isNavKeyPress()){
12898 this.validationTask.delay(this.validationDelay);
12902 * Validates the field value
12903 * @return {Boolean} True if the value is valid, else false
12905 validate : function(){
12906 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
12907 if(this.disabled || this.validateValue(this.getRawValue())){
12912 this.markInvalid();
12918 * Validates a value according to the field's validation rules and marks the field as invalid
12919 * if the validation fails
12920 * @param {Mixed} value The value to validate
12921 * @return {Boolean} True if the value is valid, else false
12923 validateValue : function(value)
12925 if(this.getVisibilityEl().hasClass('hidden')){
12929 if(value.length < 1) { // if it's blank
12930 if(this.allowBlank){
12936 if(value.length < this.minLength){
12939 if(value.length > this.maxLength){
12943 var vt = Roo.form.VTypes;
12944 if(!vt[this.vtype](value, this)){
12948 if(typeof this.validator == "function"){
12949 var msg = this.validator(value);
12953 if (typeof(msg) == 'string') {
12954 this.invalidText = msg;
12958 if(this.regex && !this.regex.test(value)){
12966 fireKey : function(e){
12967 //Roo.log('field ' + e.getKey());
12968 if(e.isNavKeyPress()){
12969 this.fireEvent("specialkey", this, e);
12972 focus : function (selectText){
12974 this.inputEl().focus();
12975 if(selectText === true){
12976 this.inputEl().dom.select();
12982 onFocus : function(){
12983 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
12984 // this.el.addClass(this.focusClass);
12986 if(!this.hasFocus){
12987 this.hasFocus = true;
12988 this.startValue = this.getValue();
12989 this.fireEvent("focus", this);
12993 beforeBlur : Roo.emptyFn,
12997 onBlur : function(){
12999 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
13000 //this.el.removeClass(this.focusClass);
13002 this.hasFocus = false;
13003 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
13006 var v = this.getValue();
13007 if(String(v) !== String(this.startValue)){
13008 this.fireEvent('change', this, v, this.startValue);
13010 this.fireEvent("blur", this);
13013 onChange : function(e)
13015 var v = this.getValue();
13016 if(String(v) !== String(this.startValue)){
13017 this.fireEvent('change', this, v, this.startValue);
13023 * Resets the current field value to the originally loaded value and clears any validation messages
13025 reset : function(){
13026 this.setValue(this.originalValue);
13030 * Returns the name of the field
13031 * @return {Mixed} name The name field
13033 getName: function(){
13037 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
13038 * @return {Mixed} value The field value
13040 getValue : function(){
13042 var v = this.inputEl().getValue();
13047 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
13048 * @return {Mixed} value The field value
13050 getRawValue : function(){
13051 var v = this.inputEl().getValue();
13057 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
13058 * @param {Mixed} value The value to set
13060 setRawValue : function(v){
13061 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
13064 selectText : function(start, end){
13065 var v = this.getRawValue();
13067 start = start === undefined ? 0 : start;
13068 end = end === undefined ? v.length : end;
13069 var d = this.inputEl().dom;
13070 if(d.setSelectionRange){
13071 d.setSelectionRange(start, end);
13072 }else if(d.createTextRange){
13073 var range = d.createTextRange();
13074 range.moveStart("character", start);
13075 range.moveEnd("character", v.length-end);
13082 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
13083 * @param {Mixed} value The value to set
13085 setValue : function(v){
13088 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
13094 processValue : function(value){
13095 if(this.stripCharsRe){
13096 var newValue = value.replace(this.stripCharsRe, '');
13097 if(newValue !== value){
13098 this.setRawValue(newValue);
13105 preFocus : function(){
13107 if(this.selectOnFocus){
13108 this.inputEl().dom.select();
13111 filterKeys : function(e){
13112 var k = e.getKey();
13113 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
13116 var c = e.getCharCode(), cc = String.fromCharCode(c);
13117 if(Roo.isIE && (e.isSpecialKey() || !cc)){
13120 if(!this.maskRe.test(cc)){
13125 * Clear any invalid styles/messages for this field
13127 clearInvalid : function(){
13129 if(!this.el || this.preventMark){ // not rendered
13134 this.el.removeClass([this.invalidClass, 'is-invalid']);
13136 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13138 var feedback = this.el.select('.form-control-feedback', true).first();
13141 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
13146 if(this.indicator){
13147 this.indicator.removeClass('visible');
13148 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13151 this.fireEvent('valid', this);
13155 * Mark this field as valid
13157 markValid : function()
13159 if(!this.el || this.preventMark){ // not rendered...
13163 this.el.removeClass([this.invalidClass, this.validClass]);
13164 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13166 var feedback = this.el.select('.form-control-feedback', true).first();
13169 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13172 if(this.indicator){
13173 this.indicator.removeClass('visible');
13174 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13182 if(this.allowBlank && !this.getRawValue().length){
13185 if (Roo.bootstrap.version == 3) {
13186 this.el.addClass(this.validClass);
13188 this.inputEl().addClass('is-valid');
13191 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
13193 var feedback = this.el.select('.form-control-feedback', true).first();
13196 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13197 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
13202 this.fireEvent('valid', this);
13206 * Mark this field as invalid
13207 * @param {String} msg The validation message
13209 markInvalid : function(msg)
13211 if(!this.el || this.preventMark){ // not rendered
13215 this.el.removeClass([this.invalidClass, this.validClass]);
13216 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13218 var feedback = this.el.select('.form-control-feedback', true).first();
13221 this.el.select('.form-control-feedback', true).first().removeClass(
13222 [this.invalidFeedbackClass, this.validFeedbackClass]);
13229 if(this.allowBlank && !this.getRawValue().length){
13233 if(this.indicator){
13234 this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
13235 this.indicator.addClass('visible');
13237 if (Roo.bootstrap.version == 3) {
13238 this.el.addClass(this.invalidClass);
13240 this.inputEl().addClass('is-invalid');
13245 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13247 var feedback = this.el.select('.form-control-feedback', true).first();
13250 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13252 if(this.getValue().length || this.forceFeedback){
13253 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
13260 this.fireEvent('invalid', this, msg);
13263 SafariOnKeyDown : function(event)
13265 // this is a workaround for a password hang bug on chrome/ webkit.
13266 if (this.inputEl().dom.type != 'password') {
13270 var isSelectAll = false;
13272 if(this.inputEl().dom.selectionEnd > 0){
13273 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
13275 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
13276 event.preventDefault();
13281 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
13283 event.preventDefault();
13284 // this is very hacky as keydown always get's upper case.
13286 var cc = String.fromCharCode(event.getCharCode());
13287 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
13291 adjustWidth : function(tag, w){
13292 tag = tag.toLowerCase();
13293 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
13294 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
13295 if(tag == 'input'){
13298 if(tag == 'textarea'){
13301 }else if(Roo.isOpera){
13302 if(tag == 'input'){
13305 if(tag == 'textarea'){
13313 setFieldLabel : function(v)
13315 if(!this.rendered){
13319 if(this.indicatorEl()){
13320 var ar = this.el.select('label > span',true);
13322 if (ar.elements.length) {
13323 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13324 this.fieldLabel = v;
13328 var br = this.el.select('label',true);
13330 if(br.elements.length) {
13331 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13332 this.fieldLabel = v;
13336 Roo.log('Cannot Found any of label > span || label in input');
13340 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
13341 this.fieldLabel = v;
13356 * @class Roo.bootstrap.form.TextArea
13357 * @extends Roo.bootstrap.form.Input
13358 * Bootstrap TextArea class
13359 * @cfg {Number} cols Specifies the visible width of a text area
13360 * @cfg {Number} rows Specifies the visible number of lines in a text area
13361 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
13362 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
13363 * @cfg {string} html text
13366 * Create a new TextArea
13367 * @param {Object} config The config object
13370 Roo.bootstrap.form.TextArea = function(config){
13371 Roo.bootstrap.form.TextArea.superclass.constructor.call(this, config);
13375 Roo.extend(Roo.bootstrap.form.TextArea, Roo.bootstrap.form.Input, {
13385 getAutoCreate : function(){
13387 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
13393 if(this.inputType != 'hidden'){
13394 cfg.cls = 'form-group' //input-group
13402 value : this.value || '',
13403 html: this.html || '',
13404 cls : 'form-control',
13405 placeholder : this.placeholder || ''
13409 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
13410 input.maxLength = this.maxLength;
13414 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
13418 input.cols = this.cols;
13421 if (this.readOnly) {
13422 input.readonly = true;
13426 input.name = this.name;
13430 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
13434 ['xs','sm','md','lg'].map(function(size){
13435 if (settings[size]) {
13436 cfg.cls += ' col-' + size + '-' + settings[size];
13440 var inputblock = input;
13442 if(this.hasFeedback && !this.allowBlank){
13446 cls: 'glyphicon form-control-feedback'
13450 cls : 'has-feedback',
13459 if (this.before || this.after) {
13462 cls : 'input-group',
13466 inputblock.cn.push({
13468 cls : 'input-group-addon',
13473 inputblock.cn.push(input);
13475 if(this.hasFeedback && !this.allowBlank){
13476 inputblock.cls += ' has-feedback';
13477 inputblock.cn.push(feedback);
13481 inputblock.cn.push({
13483 cls : 'input-group-addon',
13490 if (align ==='left' && this.fieldLabel.length) {
13495 cls : 'control-label',
13496 html : this.fieldLabel
13507 if(this.labelWidth > 12){
13508 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
13511 if(this.labelWidth < 13 && this.labelmd == 0){
13512 this.labelmd = this.labelWidth;
13515 if(this.labellg > 0){
13516 cfg.cn[0].cls += ' col-lg-' + this.labellg;
13517 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
13520 if(this.labelmd > 0){
13521 cfg.cn[0].cls += ' col-md-' + this.labelmd;
13522 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
13525 if(this.labelsm > 0){
13526 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
13527 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
13530 if(this.labelxs > 0){
13531 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
13532 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
13535 } else if ( this.fieldLabel.length) {
13540 //cls : 'input-group-addon',
13541 html : this.fieldLabel
13559 if (this.disabled) {
13560 input.disabled=true;
13567 * return the real textarea element.
13569 inputEl: function ()
13571 return this.el.select('textarea.form-control',true).first();
13575 * Clear any invalid styles/messages for this field
13577 clearInvalid : function()
13580 if(!this.el || this.preventMark){ // not rendered
13584 var label = this.el.select('label', true).first();
13585 var icon = this.el.select('i.fa-star', true).first();
13590 this.el.removeClass( this.validClass);
13591 this.inputEl().removeClass('is-invalid');
13593 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13595 var feedback = this.el.select('.form-control-feedback', true).first();
13598 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
13603 this.fireEvent('valid', this);
13607 * Mark this field as valid
13609 markValid : function()
13611 if(!this.el || this.preventMark){ // not rendered
13615 this.el.removeClass([this.invalidClass, this.validClass]);
13616 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13618 var feedback = this.el.select('.form-control-feedback', true).first();
13621 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13624 if(this.disabled || this.allowBlank){
13628 var label = this.el.select('label', true).first();
13629 var icon = this.el.select('i.fa-star', true).first();
13634 if (Roo.bootstrap.version == 3) {
13635 this.el.addClass(this.validClass);
13637 this.inputEl().addClass('is-valid');
13641 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
13643 var feedback = this.el.select('.form-control-feedback', true).first();
13646 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13647 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
13652 this.fireEvent('valid', this);
13656 * Mark this field as invalid
13657 * @param {String} msg The validation message
13659 markInvalid : function(msg)
13661 if(!this.el || this.preventMark){ // not rendered
13665 this.el.removeClass([this.invalidClass, this.validClass]);
13666 this.inputEl().removeClass(['is-valid', 'is-invalid']);
13668 var feedback = this.el.select('.form-control-feedback', true).first();
13671 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13674 if(this.disabled || this.allowBlank){
13678 var label = this.el.select('label', true).first();
13679 var icon = this.el.select('i.fa-star', true).first();
13681 if(!this.getValue().length && label && !icon){
13682 this.el.createChild({
13684 cls : 'text-danger fa fa-lg fa-star',
13685 tooltip : 'This field is required',
13686 style : 'margin-right:5px;'
13690 if (Roo.bootstrap.version == 3) {
13691 this.el.addClass(this.invalidClass);
13693 this.inputEl().addClass('is-invalid');
13696 // fixme ... this may be depricated need to test..
13697 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
13699 var feedback = this.el.select('.form-control-feedback', true).first();
13702 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
13704 if(this.getValue().length || this.forceFeedback){
13705 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
13712 this.fireEvent('invalid', this, msg);
13720 * trigger field - base class for combo..
13725 * @class Roo.bootstrap.form.TriggerField
13726 * @extends Roo.bootstrap.form.Input
13727 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
13728 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
13729 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
13730 * for which you can provide a custom implementation. For example:
13732 var trigger = new Roo.bootstrap.form.TriggerField();
13733 trigger.onTriggerClick = myTriggerFn;
13734 trigger.applyTo('my-field');
13737 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
13738 * {@link Roo.bootstrap.form.DateField} and {@link Roo.bootstrap.form.ComboBox} are perfect examples of this.
13739 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
13740 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
13741 * @cfg {String} caret (search|calendar) BS3 only - carat fa name
13744 * Create a new TriggerField.
13745 * @param {Object} config Configuration options (valid {@Roo.bootstrap.form.Input} config options will also be applied
13746 * to the base TextField)
13748 Roo.bootstrap.form.TriggerField = function(config){
13749 this.mimicing = false;
13750 Roo.bootstrap.form.TriggerField.superclass.constructor.call(this, config);
13753 Roo.extend(Roo.bootstrap.form.TriggerField, Roo.bootstrap.form.Input, {
13755 * @cfg {String} triggerClass A CSS class to apply to the trigger
13758 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
13763 * @cfg {Boolean} removable (true|false) special filter default false
13767 /** @cfg {Boolean} grow @hide */
13768 /** @cfg {Number} growMin @hide */
13769 /** @cfg {Number} growMax @hide */
13775 autoSize: Roo.emptyFn,
13779 deferHeight : true,
13782 actionMode : 'wrap',
13787 getAutoCreate : function(){
13789 var align = this.labelAlign || this.parentLabelAlign();
13794 cls: 'form-group' //input-group
13801 type : this.inputType,
13802 cls : 'form-control',
13803 autocomplete: 'new-password',
13804 placeholder : this.placeholder || ''
13808 input.name = this.name;
13811 input.cls += ' input-' + this.size;
13814 if (this.disabled) {
13815 input.disabled=true;
13818 var inputblock = input;
13820 if(this.hasFeedback && !this.allowBlank){
13824 cls: 'glyphicon form-control-feedback'
13827 if(this.removable && !this.editable ){
13829 cls : 'has-feedback',
13835 cls : 'roo-combo-removable-btn close'
13842 cls : 'has-feedback',
13851 if(this.removable && !this.editable ){
13853 cls : 'roo-removable',
13859 cls : 'roo-combo-removable-btn close'
13866 if (this.before || this.after) {
13869 cls : 'input-group',
13873 inputblock.cn.push({
13875 cls : 'input-group-addon input-group-prepend input-group-text',
13880 inputblock.cn.push(input);
13882 if(this.hasFeedback && !this.allowBlank){
13883 inputblock.cls += ' has-feedback';
13884 inputblock.cn.push(feedback);
13888 inputblock.cn.push({
13890 cls : 'input-group-addon input-group-append input-group-text',
13899 var ibwrap = inputblock;
13904 cls: 'roo-select2-choices',
13908 cls: 'roo-select2-search-field',
13920 cls: 'roo-select2-container input-group',
13925 cls: 'form-hidden-field'
13931 if(!this.multiple && this.showToggleBtn){
13937 if (this.caret != false) {
13940 cls: 'fa fa-' + this.caret
13947 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
13949 Roo.bootstrap.version == 3 ? caret : '',
13952 cls: 'combobox-clear',
13966 combobox.cls += ' roo-select2-container-multi';
13970 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
13971 tooltip : 'This field is required'
13973 if (Roo.bootstrap.version == 4) {
13976 style : 'display:none'
13981 if (align ==='left' && this.fieldLabel.length) {
13983 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
13990 cls : 'control-label',
13991 html : this.fieldLabel
14003 var labelCfg = cfg.cn[1];
14004 var contentCfg = cfg.cn[2];
14006 if(this.indicatorpos == 'right'){
14011 cls : 'control-label',
14015 html : this.fieldLabel
14029 labelCfg = cfg.cn[0];
14030 contentCfg = cfg.cn[1];
14033 if(this.labelWidth > 12){
14034 labelCfg.style = "width: " + this.labelWidth + 'px';
14037 if(this.labelWidth < 13 && this.labelmd == 0){
14038 this.labelmd = this.labelWidth;
14041 if(this.labellg > 0){
14042 labelCfg.cls += ' col-lg-' + this.labellg;
14043 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
14046 if(this.labelmd > 0){
14047 labelCfg.cls += ' col-md-' + this.labelmd;
14048 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
14051 if(this.labelsm > 0){
14052 labelCfg.cls += ' col-sm-' + this.labelsm;
14053 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
14056 if(this.labelxs > 0){
14057 labelCfg.cls += ' col-xs-' + this.labelxs;
14058 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
14061 } else if ( this.fieldLabel.length) {
14062 // Roo.log(" label");
14067 //cls : 'input-group-addon',
14068 html : this.fieldLabel
14076 if(this.indicatorpos == 'right'){
14084 html : this.fieldLabel
14098 // Roo.log(" no label && no align");
14105 ['xs','sm','md','lg'].map(function(size){
14106 if (settings[size]) {
14107 cfg.cls += ' col-' + size + '-' + settings[size];
14118 onResize : function(w, h){
14119 // Roo.bootstrap.form.TriggerField.superclass.onResize.apply(this, arguments);
14120 // if(typeof w == 'number'){
14121 // var x = w - this.trigger.getWidth();
14122 // this.inputEl().setWidth(this.adjustWidth('input', x));
14123 // this.trigger.setStyle('left', x+'px');
14128 adjustSize : Roo.BoxComponent.prototype.adjustSize,
14131 getResizeEl : function(){
14132 return this.inputEl();
14136 getPositionEl : function(){
14137 return this.inputEl();
14141 alignErrorIcon : function(){
14142 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
14146 initEvents : function(){
14150 Roo.bootstrap.form.TriggerField.superclass.initEvents.call(this);
14151 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
14152 if(!this.multiple && this.showToggleBtn){
14153 this.trigger = this.el.select('span.dropdown-toggle',true).first();
14154 if(this.hideTrigger){
14155 this.trigger.setDisplayed(false);
14157 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
14161 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
14164 if(this.removable && !this.editable && !this.tickable){
14165 var close = this.closeTriggerEl();
14168 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
14169 close.on('click', this.removeBtnClick, this, close);
14173 //this.trigger.addClassOnOver('x-form-trigger-over');
14174 //this.trigger.addClassOnClick('x-form-trigger-click');
14177 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
14181 closeTriggerEl : function()
14183 var close = this.el.select('.roo-combo-removable-btn', true).first();
14184 return close ? close : false;
14187 removeBtnClick : function(e, h, el)
14189 e.preventDefault();
14191 if(this.fireEvent("remove", this) !== false){
14193 this.fireEvent("afterremove", this)
14197 createList : function()
14199 this.list = Roo.get(document.body).createChild({
14200 tag: Roo.bootstrap.version == 4 ? 'div' : 'ul',
14201 cls: 'typeahead typeahead-long dropdown-menu shadow',
14202 style: 'display:none'
14205 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
14210 initTrigger : function(){
14215 onDestroy : function(){
14217 this.trigger.removeAllListeners();
14218 // this.trigger.remove();
14221 // this.wrap.remove();
14223 Roo.bootstrap.form.TriggerField.superclass.onDestroy.call(this);
14227 onFocus : function(){
14228 Roo.bootstrap.form.TriggerField.superclass.onFocus.call(this);
14230 if(!this.mimicing){
14231 this.wrap.addClass('x-trigger-wrap-focus');
14232 this.mimicing = true;
14233 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
14234 if(this.monitorTab){
14235 this.el.on("keydown", this.checkTab, this);
14242 checkTab : function(e){
14243 if(e.getKey() == e.TAB){
14244 this.triggerBlur();
14249 onBlur : function(){
14254 mimicBlur : function(e, t){
14256 if(!this.wrap.contains(t) && this.validateBlur()){
14257 this.triggerBlur();
14263 triggerBlur : function(){
14264 this.mimicing = false;
14265 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
14266 if(this.monitorTab){
14267 this.el.un("keydown", this.checkTab, this);
14269 //this.wrap.removeClass('x-trigger-wrap-focus');
14270 Roo.bootstrap.form.TriggerField.superclass.onBlur.call(this);
14274 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
14275 validateBlur : function(e, t){
14280 onDisable : function(){
14281 this.inputEl().dom.disabled = true;
14282 //Roo.bootstrap.form.TriggerField.superclass.onDisable.call(this);
14284 // this.wrap.addClass('x-item-disabled');
14289 onEnable : function(){
14290 this.inputEl().dom.disabled = false;
14291 //Roo.bootstrap.form.TriggerField.superclass.onEnable.call(this);
14293 // this.el.removeClass('x-item-disabled');
14298 onShow : function(){
14299 var ae = this.getActionEl();
14302 ae.dom.style.display = '';
14303 ae.dom.style.visibility = 'visible';
14309 onHide : function(){
14310 var ae = this.getActionEl();
14311 ae.dom.style.display = 'none';
14315 * The function that should handle the trigger's click event. This method does nothing by default until overridden
14316 * by an implementing function.
14318 * @param {EventObject} e
14320 onTriggerClick : Roo.emptyFn
14328 * @class Roo.bootstrap.form.CardUploader
14329 * @extends Roo.bootstrap.Button
14330 * Bootstrap Card Uploader class - it's a button which when you add files to it, adds cards below with preview and the name...
14331 * @cfg {Number} errorTimeout default 3000
14332 * @cfg {Array} images an array of ?? Img objects ??? when loading existing files..
14333 * @cfg {Array} html The button text.
14337 * Create a new CardUploader
14338 * @param {Object} config The config object
14341 Roo.bootstrap.form.CardUploader = function(config){
14345 Roo.bootstrap.form.CardUploader.superclass.constructor.call(this, config);
14348 this.fileCollection = new Roo.util.MixedCollection(false,function(r) {
14356 * When a image is clicked on - and needs to display a slideshow or similar..
14357 * @param {Roo.bootstrap.Card} this
14358 * @param {Object} The image information data
14364 * When a the download link is clicked
14365 * @param {Roo.bootstrap.Card} this
14366 * @param {Object} The image information data contains
14373 Roo.extend(Roo.bootstrap.form.CardUploader, Roo.bootstrap.form.Input, {
14376 errorTimeout : 3000,
14380 fileCollection : false,
14383 getAutoCreate : function()
14387 cls :'form-group' ,
14392 //cls : 'input-group-addon',
14393 html : this.fieldLabel
14401 value : this.value,
14402 cls : 'd-none form-control'
14407 multiple : 'multiple',
14409 cls : 'd-none roo-card-upload-selector'
14413 cls : 'roo-card-uploader-button-container w-100 mb-2'
14416 cls : 'card-columns roo-card-uploader-container'
14426 getChildContainer : function() /// what children are added to.
14428 return this.containerEl;
14431 getButtonContainer : function() /// what children are added to.
14433 return this.el.select(".roo-card-uploader-button-container").first();
14436 initEvents : function()
14439 Roo.bootstrap.form.Input.prototype.initEvents.call(this);
14443 xns: Roo.bootstrap,
14446 container_method : 'getButtonContainer' ,
14447 html : this.html, // fix changable?
14450 'click' : function(btn, e) {
14459 this.urlAPI = (window.createObjectURL && window) ||
14460 (window.URL && URL.revokeObjectURL && URL) ||
14461 (window.webkitURL && webkitURL);
14466 this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
14468 this.selectorEl.on('change', this.onFileSelected, this);
14471 this.images.forEach(function(img) {
14474 this.images = false;
14476 this.containerEl = this.el.select('.roo-card-uploader-container', true).first();
14482 onClick : function(e)
14484 e.preventDefault();
14486 this.selectorEl.dom.click();
14490 onFileSelected : function(e)
14492 e.preventDefault();
14494 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
14498 Roo.each(this.selectorEl.dom.files, function(file){
14499 this.addFile(file);
14508 addFile : function(file)
14511 if(typeof(file) === 'string'){
14512 throw "Add file by name?"; // should not happen
14516 if(!file || !this.urlAPI){
14526 var url = _this.urlAPI.createObjectURL( file);
14529 id : Roo.bootstrap.form.CardUploader.ID--,
14530 is_uploaded : false,
14534 mimetype : file.type,
14542 * addCard - add an Attachment to the uploader
14543 * @param data - the data about the image to upload
14547 title : "Title of file",
14548 is_uploaded : false,
14549 src : "http://.....",
14550 srcfile : { the File upload object },
14551 mimetype : file.type,
14554 .. any other data...
14560 addCard : function (data)
14562 // hidden input element?
14563 // if the file is not an image...
14564 //then we need to use something other that and header_image
14569 xns : Roo.bootstrap,
14570 xtype : 'CardFooter',
14573 xns : Roo.bootstrap,
14579 xns : Roo.bootstrap,
14581 html : String.format("<small>{0}</small>", data.title),
14582 cls : 'col-10 text-left',
14587 click : function() {
14589 t.fireEvent( "download", t, data );
14595 xns : Roo.bootstrap,
14597 style: 'max-height: 28px; ',
14603 click : function() {
14604 t.removeCard(data.id)
14616 var cn = this.addxtype(
14619 xns : Roo.bootstrap,
14622 header : !data.mimetype.match(/image/) && !data.preview ? "Document": false,
14623 header_image : data.mimetype.match(/image/) ? data.src : data.preview,
14624 header_image_fit_square: true, // fixme - we probably need to use the 'Img' element to do stuff like this.
14629 initEvents : function() {
14630 Roo.bootstrap.Card.prototype.initEvents.call(this);
14632 this.imgEl = this.el.select('.card-img-top').first();
14634 this.imgEl.on('click', function() { t.fireEvent( "preview", t, data ); }, this);
14635 this.imgEl.set({ 'pointer' : 'cursor' });
14638 this.getCardFooter().addClass('p-1');
14645 // dont' really need ot update items.
14646 // this.items.push(cn);
14647 this.fileCollection.add(cn);
14649 if (!data.srcfile) {
14650 this.updateInput();
14655 var reader = new FileReader();
14656 reader.addEventListener("load", function() {
14657 data.srcdata = reader.result;
14660 reader.readAsDataURL(data.srcfile);
14665 removeCard : function(id)
14668 var card = this.fileCollection.get(id);
14669 card.data.is_deleted = 1;
14670 card.data.src = ''; /// delete the source - so it reduces size of not uploaded images etc.
14671 //this.fileCollection.remove(card);
14672 //this.items = this.items.filter(function(e) { return e != card });
14673 // dont' really need ot update items.
14674 card.el.dom.parentNode.removeChild(card.el.dom);
14675 this.updateInput();
14681 this.fileCollection.each(function(card) {
14682 if (card.el.dom && card.el.dom.parentNode) {
14683 card.el.dom.parentNode.removeChild(card.el.dom);
14686 this.fileCollection.clear();
14687 this.updateInput();
14690 updateInput : function()
14693 this.fileCollection.each(function(e) {
14697 this.inputEl().dom.value = JSON.stringify(data);
14707 Roo.bootstrap.form.CardUploader.ID = -1;/*
14709 * Ext JS Library 1.1.1
14710 * Copyright(c) 2006-2007, Ext JS, LLC.
14712 * Originally Released Under LGPL - original licence link has changed is not relivant.
14715 * <script type="text/javascript">
14720 * @class Roo.data.SortTypes
14722 * Defines the default sorting (casting?) comparison functions used when sorting data.
14724 Roo.data.SortTypes = {
14726 * Default sort that does nothing
14727 * @param {Mixed} s The value being converted
14728 * @return {Mixed} The comparison value
14730 none : function(s){
14735 * The regular expression used to strip tags
14739 stripTagsRE : /<\/?[^>]+>/gi,
14742 * Strips all HTML tags to sort on text only
14743 * @param {Mixed} s The value being converted
14744 * @return {String} The comparison value
14746 asText : function(s){
14747 return String(s).replace(this.stripTagsRE, "");
14751 * Strips all HTML tags to sort on text only - Case insensitive
14752 * @param {Mixed} s The value being converted
14753 * @return {String} The comparison value
14755 asUCText : function(s){
14756 return String(s).toUpperCase().replace(this.stripTagsRE, "");
14760 * Case insensitive string
14761 * @param {Mixed} s The value being converted
14762 * @return {String} The comparison value
14764 asUCString : function(s) {
14765 return String(s).toUpperCase();
14770 * @param {Mixed} s The value being converted
14771 * @return {Number} The comparison value
14773 asDate : function(s) {
14777 if(s instanceof Date){
14778 return s.getTime();
14780 return Date.parse(String(s));
14785 * @param {Mixed} s The value being converted
14786 * @return {Float} The comparison value
14788 asFloat : function(s) {
14789 var val = parseFloat(String(s).replace(/,/g, ""));
14798 * @param {Mixed} s The value being converted
14799 * @return {Number} The comparison value
14801 asInt : function(s) {
14802 var val = parseInt(String(s).replace(/,/g, ""));
14810 * Ext JS Library 1.1.1
14811 * Copyright(c) 2006-2007, Ext JS, LLC.
14813 * Originally Released Under LGPL - original licence link has changed is not relivant.
14816 * <script type="text/javascript">
14820 * @class Roo.data.Record
14821 * Instances of this class encapsulate both record <em>definition</em> information, and record
14822 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
14823 * to access Records cached in an {@link Roo.data.Store} object.<br>
14825 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
14826 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
14829 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
14831 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
14832 * {@link #create}. The parameters are the same.
14833 * @param {Array} data An associative Array of data values keyed by the field name.
14834 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
14835 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
14836 * not specified an integer id is generated.
14838 Roo.data.Record = function(data, id){
14839 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
14844 * Generate a constructor for a specific record layout.
14845 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
14846 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
14847 * Each field definition object may contain the following properties: <ul>
14848 * <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,
14849 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
14850 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
14851 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
14852 * is being used, then this is a string containing the javascript expression to reference the data relative to
14853 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
14854 * to the data item relative to the record element. If the mapping expression is the same as the field name,
14855 * this may be omitted.</p></li>
14856 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
14857 * <ul><li>auto (Default, implies no conversion)</li>
14862 * <li>date</li></ul></p></li>
14863 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
14864 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
14865 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
14866 * by the Reader into an object that will be stored in the Record. It is passed the
14867 * following parameters:<ul>
14868 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
14870 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
14872 * <br>usage:<br><pre><code>
14873 var TopicRecord = Roo.data.Record.create(
14874 {name: 'title', mapping: 'topic_title'},
14875 {name: 'author', mapping: 'username'},
14876 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
14877 {name: 'lastPost', mapping: 'post_time', type: 'date'},
14878 {name: 'lastPoster', mapping: 'user2'},
14879 {name: 'excerpt', mapping: 'post_text'}
14882 var myNewRecord = new TopicRecord({
14883 title: 'Do my job please',
14886 lastPost: new Date(),
14887 lastPoster: 'Animal',
14888 excerpt: 'No way dude!'
14890 myStore.add(myNewRecord);
14895 Roo.data.Record.create = function(o){
14896 var f = function(){
14897 f.superclass.constructor.apply(this, arguments);
14899 Roo.extend(f, Roo.data.Record);
14900 var p = f.prototype;
14901 p.fields = new Roo.util.MixedCollection(false, function(field){
14904 for(var i = 0, len = o.length; i < len; i++){
14905 p.fields.add(new Roo.data.Field(o[i]));
14907 f.getField = function(name){
14908 return p.fields.get(name);
14913 Roo.data.Record.AUTO_ID = 1000;
14914 Roo.data.Record.EDIT = 'edit';
14915 Roo.data.Record.REJECT = 'reject';
14916 Roo.data.Record.COMMIT = 'commit';
14918 Roo.data.Record.prototype = {
14920 * Readonly flag - true if this record has been modified.
14929 join : function(store){
14930 this.store = store;
14934 * Set the named field to the specified value.
14935 * @param {String} name The name of the field to set.
14936 * @param {Object} value The value to set the field to.
14938 set : function(name, value){
14939 if(this.data[name] == value){
14943 if(!this.modified){
14944 this.modified = {};
14946 if(typeof this.modified[name] == 'undefined'){
14947 this.modified[name] = this.data[name];
14949 this.data[name] = value;
14950 if(!this.editing && this.store){
14951 this.store.afterEdit(this);
14956 * Get the value of the named field.
14957 * @param {String} name The name of the field to get the value of.
14958 * @return {Object} The value of the field.
14960 get : function(name){
14961 return this.data[name];
14965 beginEdit : function(){
14966 this.editing = true;
14967 this.modified = {};
14971 cancelEdit : function(){
14972 this.editing = false;
14973 delete this.modified;
14977 endEdit : function(){
14978 this.editing = false;
14979 if(this.dirty && this.store){
14980 this.store.afterEdit(this);
14985 * Usually called by the {@link Roo.data.Store} which owns the Record.
14986 * Rejects all changes made to the Record since either creation, or the last commit operation.
14987 * Modified fields are reverted to their original values.
14989 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
14990 * of reject operations.
14992 reject : function(){
14993 var m = this.modified;
14995 if(typeof m[n] != "function"){
14996 this.data[n] = m[n];
14999 this.dirty = false;
15000 delete this.modified;
15001 this.editing = false;
15003 this.store.afterReject(this);
15008 * Usually called by the {@link Roo.data.Store} which owns the Record.
15009 * Commits all changes made to the Record since either creation, or the last commit operation.
15011 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
15012 * of commit operations.
15014 commit : function(){
15015 this.dirty = false;
15016 delete this.modified;
15017 this.editing = false;
15019 this.store.afterCommit(this);
15024 hasError : function(){
15025 return this.error != null;
15029 clearError : function(){
15034 * Creates a copy of this record.
15035 * @param {String} id (optional) A new record id if you don't want to use this record's id
15038 copy : function(newId) {
15039 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
15043 * Ext JS Library 1.1.1
15044 * Copyright(c) 2006-2007, Ext JS, LLC.
15046 * Originally Released Under LGPL - original licence link has changed is not relivant.
15049 * <script type="text/javascript">
15055 * @class Roo.data.Store
15056 * @extends Roo.util.Observable
15057 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
15058 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
15060 * 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
15061 * has no knowledge of the format of the data returned by the Proxy.<br>
15063 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
15064 * instances from the data object. These records are cached and made available through accessor functions.
15066 * Creates a new Store.
15067 * @param {Object} config A config object containing the objects needed for the Store to access data,
15068 * and read the data into Records.
15070 Roo.data.Store = function(config){
15071 this.data = new Roo.util.MixedCollection(false);
15072 this.data.getKey = function(o){
15075 this.baseParams = {};
15077 this.paramNames = {
15082 "multisort" : "_multisort"
15085 if(config && config.data){
15086 this.inlineData = config.data;
15087 delete config.data;
15090 Roo.apply(this, config);
15092 if(this.reader){ // reader passed
15093 this.reader = Roo.factory(this.reader, Roo.data);
15094 this.reader.xmodule = this.xmodule || false;
15095 if(!this.recordType){
15096 this.recordType = this.reader.recordType;
15098 if(this.reader.onMetaChange){
15099 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
15103 if(this.recordType){
15104 this.fields = this.recordType.prototype.fields;
15106 this.modified = [];
15110 * @event datachanged
15111 * Fires when the data cache has changed, and a widget which is using this Store
15112 * as a Record cache should refresh its view.
15113 * @param {Store} this
15115 datachanged : true,
15117 * @event metachange
15118 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
15119 * @param {Store} this
15120 * @param {Object} meta The JSON metadata
15125 * Fires when Records have been added to the Store
15126 * @param {Store} this
15127 * @param {Roo.data.Record[]} records The array of Records added
15128 * @param {Number} index The index at which the record(s) were added
15133 * Fires when a Record has been removed from the Store
15134 * @param {Store} this
15135 * @param {Roo.data.Record} record The Record that was removed
15136 * @param {Number} index The index at which the record was removed
15141 * Fires when a Record has been updated
15142 * @param {Store} this
15143 * @param {Roo.data.Record} record The Record that was updated
15144 * @param {String} operation The update operation being performed. Value may be one of:
15146 Roo.data.Record.EDIT
15147 Roo.data.Record.REJECT
15148 Roo.data.Record.COMMIT
15154 * Fires when the data cache has been cleared.
15155 * @param {Store} this
15159 * @event beforeload
15160 * Fires before a request is made for a new data object. If the beforeload handler returns false
15161 * the load action will be canceled.
15162 * @param {Store} this
15163 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15167 * @event beforeloadadd
15168 * Fires after a new set of Records has been loaded.
15169 * @param {Store} this
15170 * @param {Roo.data.Record[]} records The Records that were loaded
15171 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15173 beforeloadadd : true,
15176 * Fires after a new set of Records has been loaded, before they are added to the store.
15177 * @param {Store} this
15178 * @param {Roo.data.Record[]} records The Records that were loaded
15179 * @param {Object} options The loading options that were specified (see {@link #load} for details)
15180 * @params {Object} return from reader
15184 * @event loadexception
15185 * Fires if an exception occurs in the Proxy during loading.
15186 * Called with the signature of the Proxy's "loadexception" event.
15187 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
15190 * @param {Object} return from JsonData.reader() - success, totalRecords, records
15191 * @param {Object} load options
15192 * @param {Object} jsonData from your request (normally this contains the Exception)
15194 loadexception : true
15198 this.proxy = Roo.factory(this.proxy, Roo.data);
15199 this.proxy.xmodule = this.xmodule || false;
15200 this.relayEvents(this.proxy, ["loadexception"]);
15202 this.sortToggle = {};
15203 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
15205 Roo.data.Store.superclass.constructor.call(this);
15207 if(this.inlineData){
15208 this.loadData(this.inlineData);
15209 delete this.inlineData;
15213 Roo.extend(Roo.data.Store, Roo.util.Observable, {
15215 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
15216 * without a remote query - used by combo/forms at present.
15220 * @cfg {Roo.data.DataProxy} proxy [required] The Proxy object which provides access to a data object.
15223 * @cfg {Array} data Inline data to be loaded when the store is initialized.
15226 * @cfg {Roo.data.DataReader} reader [required] The Reader object which processes the data object and returns
15227 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
15230 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
15231 * on any HTTP request
15234 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
15237 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
15241 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
15242 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
15244 remoteSort : false,
15247 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
15248 * loaded or when a record is removed. (defaults to false).
15250 pruneModifiedRecords : false,
15253 lastOptions : null,
15256 * Add Records to the Store and fires the add event.
15257 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
15259 add : function(records){
15260 records = [].concat(records);
15261 for(var i = 0, len = records.length; i < len; i++){
15262 records[i].join(this);
15264 var index = this.data.length;
15265 this.data.addAll(records);
15266 this.fireEvent("add", this, records, index);
15270 * Remove a Record from the Store and fires the remove event.
15271 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
15273 remove : function(record){
15274 var index = this.data.indexOf(record);
15275 this.data.removeAt(index);
15277 if(this.pruneModifiedRecords){
15278 this.modified.remove(record);
15280 this.fireEvent("remove", this, record, index);
15284 * Remove all Records from the Store and fires the clear event.
15286 removeAll : function(){
15288 if(this.pruneModifiedRecords){
15289 this.modified = [];
15291 this.fireEvent("clear", this);
15295 * Inserts Records to the Store at the given index and fires the add event.
15296 * @param {Number} index The start index at which to insert the passed Records.
15297 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
15299 insert : function(index, records){
15300 records = [].concat(records);
15301 for(var i = 0, len = records.length; i < len; i++){
15302 this.data.insert(index, records[i]);
15303 records[i].join(this);
15305 this.fireEvent("add", this, records, index);
15309 * Get the index within the cache of the passed Record.
15310 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
15311 * @return {Number} The index of the passed Record. Returns -1 if not found.
15313 indexOf : function(record){
15314 return this.data.indexOf(record);
15318 * Get the index within the cache of the Record with the passed id.
15319 * @param {String} id The id of the Record to find.
15320 * @return {Number} The index of the Record. Returns -1 if not found.
15322 indexOfId : function(id){
15323 return this.data.indexOfKey(id);
15327 * Get the Record with the specified id.
15328 * @param {String} id The id of the Record to find.
15329 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
15331 getById : function(id){
15332 return this.data.key(id);
15336 * Get the Record at the specified index.
15337 * @param {Number} index The index of the Record to find.
15338 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
15340 getAt : function(index){
15341 return this.data.itemAt(index);
15345 * Returns a range of Records between specified indices.
15346 * @param {Number} startIndex (optional) The starting index (defaults to 0)
15347 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
15348 * @return {Roo.data.Record[]} An array of Records
15350 getRange : function(start, end){
15351 return this.data.getRange(start, end);
15355 storeOptions : function(o){
15356 o = Roo.apply({}, o);
15359 this.lastOptions = o;
15363 * Loads the Record cache from the configured Proxy using the configured Reader.
15365 * If using remote paging, then the first load call must specify the <em>start</em>
15366 * and <em>limit</em> properties in the options.params property to establish the initial
15367 * position within the dataset, and the number of Records to cache on each read from the Proxy.
15369 * <strong>It is important to note that for remote data sources, loading is asynchronous,
15370 * and this call will return before the new data has been loaded. Perform any post-processing
15371 * in a callback function, or in a "load" event handler.</strong>
15373 * @param {Object} options An object containing properties which control loading options:<ul>
15374 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
15375 * <li>params.data {Object} if you are using a MemoryProxy / JsonReader, use this as the data to load stuff..
15378 data : data, // array of key=>value data like JsonReader
15379 total : data.length,
15385 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
15386 * passed the following arguments:<ul>
15387 * <li>r : Roo.data.Record[]</li>
15388 * <li>options: Options object from the load call</li>
15389 * <li>success: Boolean success indicator</li></ul></li>
15390 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
15391 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
15394 load : function(options){
15395 options = options || {};
15396 if(this.fireEvent("beforeload", this, options) !== false){
15397 this.storeOptions(options);
15398 var p = Roo.apply(options.params || {}, this.baseParams);
15399 // if meta was not loaded from remote source.. try requesting it.
15400 if (!this.reader.metaFromRemote) {
15401 p._requestMeta = 1;
15403 if(this.sortInfo && this.remoteSort){
15404 var pn = this.paramNames;
15405 p[pn["sort"]] = this.sortInfo.field;
15406 p[pn["dir"]] = this.sortInfo.direction;
15408 if (this.multiSort) {
15409 var pn = this.paramNames;
15410 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
15413 this.proxy.load(p, this.reader, this.loadRecords, this, options);
15418 * Reloads the Record cache from the configured Proxy using the configured Reader and
15419 * the options from the last load operation performed.
15420 * @param {Object} options (optional) An object containing properties which may override the options
15421 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
15422 * the most recently used options are reused).
15424 reload : function(options){
15425 this.load(Roo.applyIf(options||{}, this.lastOptions));
15429 // Called as a callback by the Reader during a load operation.
15430 loadRecords : function(o, options, success){
15433 if(success !== false){
15434 this.fireEvent("load", this, [], options, o);
15436 if(options.callback){
15437 options.callback.call(options.scope || this, [], options, false);
15441 // if data returned failure - throw an exception.
15442 if (o.success === false) {
15443 // show a message if no listener is registered.
15444 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
15445 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
15447 // loadmask wil be hooked into this..
15448 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
15451 var r = o.records, t = o.totalRecords || r.length;
15453 this.fireEvent("beforeloadadd", this, r, options, o);
15455 if(!options || options.add !== true){
15456 if(this.pruneModifiedRecords){
15457 this.modified = [];
15459 for(var i = 0, len = r.length; i < len; i++){
15463 this.data = this.snapshot;
15464 delete this.snapshot;
15467 this.data.addAll(r);
15468 this.totalLength = t;
15470 this.fireEvent("datachanged", this);
15472 this.totalLength = Math.max(t, this.data.length+r.length);
15476 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
15478 var e = new Roo.data.Record({});
15480 e.set(this.parent.displayField, this.parent.emptyTitle);
15481 e.set(this.parent.valueField, '');
15486 this.fireEvent("load", this, r, options, o);
15487 if(options.callback){
15488 options.callback.call(options.scope || this, r, options, true);
15494 * Loads data from a passed data block. A Reader which understands the format of the data
15495 * must have been configured in the constructor.
15496 * @param {Object} data The data block from which to read the Records. The format of the data expected
15497 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
15498 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
15500 loadData : function(o, append){
15501 var r = this.reader.readRecords(o);
15502 this.loadRecords(r, {add: append}, true);
15506 * using 'cn' the nested child reader read the child array into it's child stores.
15507 * @param {Object} rec The record with a 'children array
15509 loadDataFromChildren : function(rec)
15511 this.loadData(this.reader.toLoadData(rec));
15516 * Gets the number of cached records.
15518 * <em>If using paging, this may not be the total size of the dataset. If the data object
15519 * used by the Reader contains the dataset size, then the getTotalCount() function returns
15520 * the data set size</em>
15522 getCount : function(){
15523 return this.data.length || 0;
15527 * Gets the total number of records in the dataset as returned by the server.
15529 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
15530 * the dataset size</em>
15532 getTotalCount : function(){
15533 return this.totalLength || 0;
15537 * Returns the sort state of the Store as an object with two properties:
15539 field {String} The name of the field by which the Records are sorted
15540 direction {String} The sort order, "ASC" or "DESC"
15543 getSortState : function(){
15544 return this.sortInfo;
15548 applySort : function(){
15549 if(this.sortInfo && !this.remoteSort){
15550 var s = this.sortInfo, f = s.field;
15551 var st = this.fields.get(f).sortType;
15552 var fn = function(r1, r2){
15553 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
15554 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
15556 this.data.sort(s.direction, fn);
15557 if(this.snapshot && this.snapshot != this.data){
15558 this.snapshot.sort(s.direction, fn);
15564 * Sets the default sort column and order to be used by the next load operation.
15565 * @param {String} fieldName The name of the field to sort by.
15566 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
15568 setDefaultSort : function(field, dir){
15569 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
15573 * Sort the Records.
15574 * If remote sorting is used, the sort is performed on the server, and the cache is
15575 * reloaded. If local sorting is used, the cache is sorted internally.
15576 * @param {String} fieldName The name of the field to sort by.
15577 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
15579 sort : function(fieldName, dir){
15580 var f = this.fields.get(fieldName);
15582 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
15584 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
15585 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
15590 this.sortToggle[f.name] = dir;
15591 this.sortInfo = {field: f.name, direction: dir};
15592 if(!this.remoteSort){
15594 this.fireEvent("datachanged", this);
15596 this.load(this.lastOptions);
15601 * Calls the specified function for each of the Records in the cache.
15602 * @param {Function} fn The function to call. The Record is passed as the first parameter.
15603 * Returning <em>false</em> aborts and exits the iteration.
15604 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
15606 each : function(fn, scope){
15607 this.data.each(fn, scope);
15611 * Gets all records modified since the last commit. Modified records are persisted across load operations
15612 * (e.g., during paging).
15613 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
15615 getModifiedRecords : function(){
15616 return this.modified;
15620 createFilterFn : function(property, value, anyMatch){
15621 if(!value.exec){ // not a regex
15622 value = String(value);
15623 if(value.length == 0){
15626 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
15628 return function(r){
15629 return value.test(r.data[property]);
15634 * Sums the value of <i>property</i> for each record between start and end and returns the result.
15635 * @param {String} property A field on your records
15636 * @param {Number} start The record index to start at (defaults to 0)
15637 * @param {Number} end The last record index to include (defaults to length - 1)
15638 * @return {Number} The sum
15640 sum : function(property, start, end){
15641 var rs = this.data.items, v = 0;
15642 start = start || 0;
15643 end = (end || end === 0) ? end : rs.length-1;
15645 for(var i = start; i <= end; i++){
15646 v += (rs[i].data[property] || 0);
15652 * Filter the records by a specified property.
15653 * @param {String} field A field on your records
15654 * @param {String/RegExp} value Either a string that the field
15655 * should start with or a RegExp to test against the field
15656 * @param {Boolean} anyMatch True to match any part not just the beginning
15658 filter : function(property, value, anyMatch){
15659 var fn = this.createFilterFn(property, value, anyMatch);
15660 return fn ? this.filterBy(fn) : this.clearFilter();
15664 * Filter by a function. The specified function will be called with each
15665 * record in this data source. If the function returns true the record is included,
15666 * otherwise it is filtered.
15667 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
15668 * @param {Object} scope (optional) The scope of the function (defaults to this)
15670 filterBy : function(fn, scope){
15671 this.snapshot = this.snapshot || this.data;
15672 this.data = this.queryBy(fn, scope||this);
15673 this.fireEvent("datachanged", this);
15677 * Query the records by a specified property.
15678 * @param {String} field A field on your records
15679 * @param {String/RegExp} value Either a string that the field
15680 * should start with or a RegExp to test against the field
15681 * @param {Boolean} anyMatch True to match any part not just the beginning
15682 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
15684 query : function(property, value, anyMatch){
15685 var fn = this.createFilterFn(property, value, anyMatch);
15686 return fn ? this.queryBy(fn) : this.data.clone();
15690 * Query by a function. The specified function will be called with each
15691 * record in this data source. If the function returns true the record is included
15693 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
15694 * @param {Object} scope (optional) The scope of the function (defaults to this)
15695 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
15697 queryBy : function(fn, scope){
15698 var data = this.snapshot || this.data;
15699 return data.filterBy(fn, scope||this);
15703 * Collects unique values for a particular dataIndex from this store.
15704 * @param {String} dataIndex The property to collect
15705 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
15706 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
15707 * @return {Array} An array of the unique values
15709 collect : function(dataIndex, allowNull, bypassFilter){
15710 var d = (bypassFilter === true && this.snapshot) ?
15711 this.snapshot.items : this.data.items;
15712 var v, sv, r = [], l = {};
15713 for(var i = 0, len = d.length; i < len; i++){
15714 v = d[i].data[dataIndex];
15716 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
15725 * Revert to a view of the Record cache with no filtering applied.
15726 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
15728 clearFilter : function(suppressEvent){
15729 if(this.snapshot && this.snapshot != this.data){
15730 this.data = this.snapshot;
15731 delete this.snapshot;
15732 if(suppressEvent !== true){
15733 this.fireEvent("datachanged", this);
15739 afterEdit : function(record){
15740 if(this.modified.indexOf(record) == -1){
15741 this.modified.push(record);
15743 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
15747 afterReject : function(record){
15748 this.modified.remove(record);
15749 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
15753 afterCommit : function(record){
15754 this.modified.remove(record);
15755 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
15759 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
15760 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
15762 commitChanges : function(){
15763 var m = this.modified.slice(0);
15764 this.modified = [];
15765 for(var i = 0, len = m.length; i < len; i++){
15771 * Cancel outstanding changes on all changed records.
15773 rejectChanges : function(){
15774 var m = this.modified.slice(0);
15775 this.modified = [];
15776 for(var i = 0, len = m.length; i < len; i++){
15781 onMetaChange : function(meta, rtype, o){
15782 this.recordType = rtype;
15783 this.fields = rtype.prototype.fields;
15784 delete this.snapshot;
15785 this.sortInfo = meta.sortInfo || this.sortInfo;
15786 this.modified = [];
15787 this.fireEvent('metachange', this, this.reader.meta);
15790 moveIndex : function(data, type)
15792 var index = this.indexOf(data);
15794 var newIndex = index + type;
15798 this.insert(newIndex, data);
15803 * Ext JS Library 1.1.1
15804 * Copyright(c) 2006-2007, Ext JS, LLC.
15806 * Originally Released Under LGPL - original licence link has changed is not relivant.
15809 * <script type="text/javascript">
15813 * @class Roo.data.SimpleStore
15814 * @extends Roo.data.Store
15815 * Small helper class to make creating Stores from Array data easier.
15816 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
15817 * @cfg {Array} fields An array of field definition objects, or field name strings.
15818 * @cfg {Object} an existing reader (eg. copied from another store)
15819 * @cfg {Array} data The multi-dimensional array of data
15820 * @cfg {Roo.data.DataProxy} proxy [not-required]
15821 * @cfg {Roo.data.Reader} reader [not-required]
15823 * @param {Object} config
15825 Roo.data.SimpleStore = function(config)
15827 Roo.data.SimpleStore.superclass.constructor.call(this, {
15829 reader: typeof(config.reader) != 'undefined' ? config.reader : new Roo.data.ArrayReader({
15832 Roo.data.Record.create(config.fields)
15834 proxy : new Roo.data.MemoryProxy(config.data)
15838 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
15840 * Ext JS Library 1.1.1
15841 * Copyright(c) 2006-2007, Ext JS, LLC.
15843 * Originally Released Under LGPL - original licence link has changed is not relivant.
15846 * <script type="text/javascript">
15851 * @extends Roo.data.Store
15852 * @class Roo.data.JsonStore
15853 * Small helper class to make creating Stores for JSON data easier. <br/>
15855 var store = new Roo.data.JsonStore({
15856 url: 'get-images.php',
15858 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
15861 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
15862 * JsonReader and HttpProxy (unless inline data is provided).</b>
15863 * @cfg {Array} fields An array of field definition objects, or field name strings.
15865 * @param {Object} config
15867 Roo.data.JsonStore = function(c){
15868 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
15869 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
15870 reader: new Roo.data.JsonReader(c, c.fields)
15873 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
15875 * Ext JS Library 1.1.1
15876 * Copyright(c) 2006-2007, Ext JS, LLC.
15878 * Originally Released Under LGPL - original licence link has changed is not relivant.
15881 * <script type="text/javascript">
15885 Roo.data.Field = function(config){
15886 if(typeof config == "string"){
15887 config = {name: config};
15889 Roo.apply(this, config);
15892 this.type = "auto";
15895 var st = Roo.data.SortTypes;
15896 // named sortTypes are supported, here we look them up
15897 if(typeof this.sortType == "string"){
15898 this.sortType = st[this.sortType];
15901 // set default sortType for strings and dates
15902 if(!this.sortType){
15905 this.sortType = st.asUCString;
15908 this.sortType = st.asDate;
15911 this.sortType = st.none;
15916 var stripRe = /[\$,%]/g;
15918 // prebuilt conversion function for this field, instead of
15919 // switching every time we're reading a value
15921 var cv, dateFormat = this.dateFormat;
15926 cv = function(v){ return v; };
15929 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
15933 return v !== undefined && v !== null && v !== '' ?
15934 parseInt(String(v).replace(stripRe, ""), 10) : '';
15939 return v !== undefined && v !== null && v !== '' ?
15940 parseFloat(String(v).replace(stripRe, ""), 10) : '';
15945 cv = function(v){ return v === true || v === "true" || v == 1; };
15952 if(v instanceof Date){
15956 if(dateFormat == "timestamp"){
15957 return new Date(v*1000);
15959 return Date.parseDate(v, dateFormat);
15961 var parsed = Date.parse(v);
15962 return parsed ? new Date(parsed) : null;
15971 Roo.data.Field.prototype = {
15979 * Ext JS Library 1.1.1
15980 * Copyright(c) 2006-2007, Ext JS, LLC.
15982 * Originally Released Under LGPL - original licence link has changed is not relivant.
15985 * <script type="text/javascript">
15988 // Base class for reading structured data from a data source. This class is intended to be
15989 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
15992 * @class Roo.data.DataReader
15994 * Base class for reading structured data from a data source. This class is intended to be
15995 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
15998 Roo.data.DataReader = function(meta, recordType){
16002 this.recordType = recordType instanceof Array ?
16003 Roo.data.Record.create(recordType) : recordType;
16006 Roo.data.DataReader.prototype = {
16009 readerType : 'Data',
16011 * Create an empty record
16012 * @param {Object} data (optional) - overlay some values
16013 * @return {Roo.data.Record} record created.
16015 newRow : function(d) {
16017 this.recordType.prototype.fields.each(function(c) {
16019 case 'int' : da[c.name] = 0; break;
16020 case 'date' : da[c.name] = new Date(); break;
16021 case 'float' : da[c.name] = 0.0; break;
16022 case 'boolean' : da[c.name] = false; break;
16023 default : da[c.name] = ""; break;
16027 return new this.recordType(Roo.apply(da, d));
16033 * Ext JS Library 1.1.1
16034 * Copyright(c) 2006-2007, Ext JS, LLC.
16036 * Originally Released Under LGPL - original licence link has changed is not relivant.
16039 * <script type="text/javascript">
16043 * @class Roo.data.DataProxy
16044 * @extends Roo.util.Observable
16046 * This class is an abstract base class for implementations which provide retrieval of
16047 * unformatted data objects.<br>
16049 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
16050 * (of the appropriate type which knows how to parse the data object) to provide a block of
16051 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
16053 * Custom implementations must implement the load method as described in
16054 * {@link Roo.data.HttpProxy#load}.
16056 Roo.data.DataProxy = function(){
16059 * @event beforeload
16060 * Fires before a network request is made to retrieve a data object.
16061 * @param {Object} This DataProxy object.
16062 * @param {Object} params The params parameter to the load function.
16067 * Fires before the load method's callback is called.
16068 * @param {Object} This DataProxy object.
16069 * @param {Object} o The data object.
16070 * @param {Object} arg The callback argument object passed to the load function.
16074 * @event loadexception
16075 * Fires if an Exception occurs during data retrieval.
16076 * @param {Object} This DataProxy object.
16077 * @param {Object} o The data object.
16078 * @param {Object} arg The callback argument object passed to the load function.
16079 * @param {Object} e The Exception.
16081 loadexception : true
16083 Roo.data.DataProxy.superclass.constructor.call(this);
16086 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
16089 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
16093 * Ext JS Library 1.1.1
16094 * Copyright(c) 2006-2007, Ext JS, LLC.
16096 * Originally Released Under LGPL - original licence link has changed is not relivant.
16099 * <script type="text/javascript">
16102 * @class Roo.data.MemoryProxy
16103 * @extends Roo.data.DataProxy
16104 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
16105 * to the Reader when its load method is called.
16107 * @param {Object} config A config object containing the objects needed for the Store to access data,
16109 Roo.data.MemoryProxy = function(config){
16111 if (typeof(config) != 'undefined' && typeof(config.data) != 'undefined') {
16112 data = config.data;
16114 Roo.data.MemoryProxy.superclass.constructor.call(this);
16118 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
16121 * @cfg {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
16124 * Load data from the requested source (in this case an in-memory
16125 * data object passed to the constructor), read the data object into
16126 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
16127 * process that block using the passed callback.
16128 * @param {Object} params This parameter is not used by the MemoryProxy class.
16129 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16130 * object into a block of Roo.data.Records.
16131 * @param {Function} callback The function into which to pass the block of Roo.data.records.
16132 * The function must be passed <ul>
16133 * <li>The Record block object</li>
16134 * <li>The "arg" argument from the load function</li>
16135 * <li>A boolean success indicator</li>
16137 * @param {Object} scope The scope in which to call the callback
16138 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16140 load : function(params, reader, callback, scope, arg){
16141 params = params || {};
16144 result = reader.readRecords(params.data ? params.data :this.data);
16146 this.fireEvent("loadexception", this, arg, null, e);
16147 callback.call(scope, null, arg, false);
16150 callback.call(scope, result, arg, true);
16154 update : function(params, records){
16159 * Ext JS Library 1.1.1
16160 * Copyright(c) 2006-2007, Ext JS, LLC.
16162 * Originally Released Under LGPL - original licence link has changed is not relivant.
16165 * <script type="text/javascript">
16168 * @class Roo.data.HttpProxy
16169 * @extends Roo.data.DataProxy
16170 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
16171 * configured to reference a certain URL.<br><br>
16173 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
16174 * from which the running page was served.<br><br>
16176 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
16178 * Be aware that to enable the browser to parse an XML document, the server must set
16179 * the Content-Type header in the HTTP response to "text/xml".
16181 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
16182 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
16183 * will be used to make the request.
16185 Roo.data.HttpProxy = function(conn){
16186 Roo.data.HttpProxy.superclass.constructor.call(this);
16187 // is conn a conn config or a real conn?
16189 this.useAjax = !conn || !conn.events;
16193 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
16194 // thse are take from connection...
16197 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
16200 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
16201 * extra parameters to each request made by this object. (defaults to undefined)
16204 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
16205 * to each request made by this object. (defaults to undefined)
16208 * @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)
16211 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
16214 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
16220 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
16224 * Return the {@link Roo.data.Connection} object being used by this Proxy.
16225 * @return {Connection} The Connection object. This object may be used to subscribe to events on
16226 * a finer-grained basis than the DataProxy events.
16228 getConnection : function(){
16229 return this.useAjax ? Roo.Ajax : this.conn;
16233 * Load data from the configured {@link Roo.data.Connection}, read the data object into
16234 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
16235 * process that block using the passed callback.
16236 * @param {Object} params An object containing properties which are to be used as HTTP parameters
16237 * for the request to the remote server.
16238 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16239 * object into a block of Roo.data.Records.
16240 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
16241 * The function must be passed <ul>
16242 * <li>The Record block object</li>
16243 * <li>The "arg" argument from the load function</li>
16244 * <li>A boolean success indicator</li>
16246 * @param {Object} scope The scope in which to call the callback
16247 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16249 load : function(params, reader, callback, scope, arg){
16250 if(this.fireEvent("beforeload", this, params) !== false){
16252 params : params || {},
16254 callback : callback,
16259 callback : this.loadResponse,
16263 Roo.applyIf(o, this.conn);
16264 if(this.activeRequest){
16265 Roo.Ajax.abort(this.activeRequest);
16267 this.activeRequest = Roo.Ajax.request(o);
16269 this.conn.request(o);
16272 callback.call(scope||this, null, arg, false);
16277 loadResponse : function(o, success, response){
16278 delete this.activeRequest;
16280 this.fireEvent("loadexception", this, o, response);
16281 o.request.callback.call(o.request.scope, null, o.request.arg, false);
16286 result = o.reader.read(response);
16289 o.raw = { errorMsg : response.responseText };
16290 this.fireEvent("loadexception", this, o, response, e);
16291 o.request.callback.call(o.request.scope, o, o.request.arg, false);
16295 this.fireEvent("load", this, o, o.request.arg);
16296 o.request.callback.call(o.request.scope, result, o.request.arg, true);
16300 update : function(dataSet){
16305 updateResponse : function(dataSet){
16310 * Ext JS Library 1.1.1
16311 * Copyright(c) 2006-2007, Ext JS, LLC.
16313 * Originally Released Under LGPL - original licence link has changed is not relivant.
16316 * <script type="text/javascript">
16320 * @class Roo.data.ScriptTagProxy
16321 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
16322 * other than the originating domain of the running page.<br><br>
16324 * <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
16325 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
16327 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
16328 * source code that is used as the source inside a <script> tag.<br><br>
16330 * In order for the browser to process the returned data, the server must wrap the data object
16331 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
16332 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
16333 * depending on whether the callback name was passed:
16336 boolean scriptTag = false;
16337 String cb = request.getParameter("callback");
16340 response.setContentType("text/javascript");
16342 response.setContentType("application/x-json");
16344 Writer out = response.getWriter();
16346 out.write(cb + "(");
16348 out.print(dataBlock.toJsonString());
16355 * @param {Object} config A configuration object.
16357 Roo.data.ScriptTagProxy = function(config){
16358 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
16359 Roo.apply(this, config);
16360 this.head = document.getElementsByTagName("head")[0];
16363 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
16365 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
16367 * @cfg {String} url The URL from which to request the data object.
16370 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
16374 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
16375 * the server the name of the callback function set up by the load call to process the returned data object.
16376 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
16377 * javascript output which calls this named function passing the data object as its only parameter.
16379 callbackParam : "callback",
16381 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
16382 * name to the request.
16387 * Load data from the configured URL, read the data object into
16388 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
16389 * process that block using the passed callback.
16390 * @param {Object} params An object containing properties which are to be used as HTTP parameters
16391 * for the request to the remote server.
16392 * @param {Roo.data.DataReader} reader The Reader object which converts the data
16393 * object into a block of Roo.data.Records.
16394 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
16395 * The function must be passed <ul>
16396 * <li>The Record block object</li>
16397 * <li>The "arg" argument from the load function</li>
16398 * <li>A boolean success indicator</li>
16400 * @param {Object} scope The scope in which to call the callback
16401 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
16403 load : function(params, reader, callback, scope, arg){
16404 if(this.fireEvent("beforeload", this, params) !== false){
16406 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
16408 var url = this.url;
16409 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
16411 url += "&_dc=" + (new Date().getTime());
16413 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
16416 cb : "stcCallback"+transId,
16417 scriptId : "stcScript"+transId,
16421 callback : callback,
16427 window[trans.cb] = function(o){
16428 conn.handleResponse(o, trans);
16431 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
16433 if(this.autoAbort !== false){
16437 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
16439 var script = document.createElement("script");
16440 script.setAttribute("src", url);
16441 script.setAttribute("type", "text/javascript");
16442 script.setAttribute("id", trans.scriptId);
16443 this.head.appendChild(script);
16445 this.trans = trans;
16447 callback.call(scope||this, null, arg, false);
16452 isLoading : function(){
16453 return this.trans ? true : false;
16457 * Abort the current server request.
16459 abort : function(){
16460 if(this.isLoading()){
16461 this.destroyTrans(this.trans);
16466 destroyTrans : function(trans, isLoaded){
16467 this.head.removeChild(document.getElementById(trans.scriptId));
16468 clearTimeout(trans.timeoutId);
16470 window[trans.cb] = undefined;
16472 delete window[trans.cb];
16475 // if hasn't been loaded, wait for load to remove it to prevent script error
16476 window[trans.cb] = function(){
16477 window[trans.cb] = undefined;
16479 delete window[trans.cb];
16486 handleResponse : function(o, trans){
16487 this.trans = false;
16488 this.destroyTrans(trans, true);
16491 result = trans.reader.readRecords(o);
16493 this.fireEvent("loadexception", this, o, trans.arg, e);
16494 trans.callback.call(trans.scope||window, null, trans.arg, false);
16497 this.fireEvent("load", this, o, trans.arg);
16498 trans.callback.call(trans.scope||window, result, trans.arg, true);
16502 handleFailure : function(trans){
16503 this.trans = false;
16504 this.destroyTrans(trans, false);
16505 this.fireEvent("loadexception", this, null, trans.arg);
16506 trans.callback.call(trans.scope||window, null, trans.arg, false);
16510 * Ext JS Library 1.1.1
16511 * Copyright(c) 2006-2007, Ext JS, LLC.
16513 * Originally Released Under LGPL - original licence link has changed is not relivant.
16516 * <script type="text/javascript">
16520 * @class Roo.data.JsonReader
16521 * @extends Roo.data.DataReader
16522 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
16523 * based on mappings in a provided Roo.data.Record constructor.
16525 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
16526 * in the reply previously.
16531 var RecordDef = Roo.data.Record.create([
16532 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
16533 {name: 'occupation'} // This field will use "occupation" as the mapping.
16535 var myReader = new Roo.data.JsonReader({
16536 totalProperty: "results", // The property which contains the total dataset size (optional)
16537 root: "rows", // The property which contains an Array of row objects
16538 id: "id" // The property within each row object that provides an ID for the record (optional)
16542 * This would consume a JSON file like this:
16544 { 'results': 2, 'rows': [
16545 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
16546 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
16549 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
16550 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
16551 * paged from the remote server.
16552 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
16553 * @cfg {String} root name of the property which contains the Array of row objects.
16554 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
16555 * @cfg {Array} fields Array of field definition objects
16557 * Create a new JsonReader
16558 * @param {Object} meta Metadata configuration options
16559 * @param {Object} recordType Either an Array of field definition objects,
16560 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
16562 Roo.data.JsonReader = function(meta, recordType){
16565 // set some defaults:
16566 Roo.applyIf(meta, {
16567 totalProperty: 'total',
16568 successProperty : 'success',
16573 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
16575 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
16577 readerType : 'Json',
16580 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
16581 * Used by Store query builder to append _requestMeta to params.
16584 metaFromRemote : false,
16586 * This method is only used by a DataProxy which has retrieved data from a remote server.
16587 * @param {Object} response The XHR object which contains the JSON data in its responseText.
16588 * @return {Object} data A data block which is used by an Roo.data.Store object as
16589 * a cache of Roo.data.Records.
16591 read : function(response){
16592 var json = response.responseText;
16594 var o = /* eval:var:o */ eval("("+json+")");
16596 throw {message: "JsonReader.read: Json object not found"};
16602 this.metaFromRemote = true;
16603 this.meta = o.metaData;
16604 this.recordType = Roo.data.Record.create(o.metaData.fields);
16605 this.onMetaChange(this.meta, this.recordType, o);
16607 return this.readRecords(o);
16610 // private function a store will implement
16611 onMetaChange : function(meta, recordType, o){
16618 simpleAccess: function(obj, subsc) {
16625 getJsonAccessor: function(){
16627 return function(expr) {
16629 return(re.test(expr))
16630 ? new Function("obj", "return obj." + expr)
16635 return Roo.emptyFn;
16640 * Create a data block containing Roo.data.Records from an XML document.
16641 * @param {Object} o An object which contains an Array of row objects in the property specified
16642 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
16643 * which contains the total size of the dataset.
16644 * @return {Object} data A data block which is used by an Roo.data.Store object as
16645 * a cache of Roo.data.Records.
16647 readRecords : function(o){
16649 * After any data loads, the raw JSON data is available for further custom processing.
16653 var s = this.meta, Record = this.recordType,
16654 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
16656 // Generate extraction functions for the totalProperty, the root, the id, and for each field
16658 if(s.totalProperty) {
16659 this.getTotal = this.getJsonAccessor(s.totalProperty);
16661 if(s.successProperty) {
16662 this.getSuccess = this.getJsonAccessor(s.successProperty);
16664 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
16666 var g = this.getJsonAccessor(s.id);
16667 this.getId = function(rec) {
16669 return (r === undefined || r === "") ? null : r;
16672 this.getId = function(){return null;};
16675 for(var jj = 0; jj < fl; jj++){
16677 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
16678 this.ef[jj] = this.getJsonAccessor(map);
16682 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
16683 if(s.totalProperty){
16684 var vt = parseInt(this.getTotal(o), 10);
16689 if(s.successProperty){
16690 var vs = this.getSuccess(o);
16691 if(vs === false || vs === 'false'){
16696 for(var i = 0; i < c; i++){
16699 var id = this.getId(n);
16700 for(var j = 0; j < fl; j++){
16702 var v = this.ef[j](n);
16704 Roo.log('missing convert for ' + f.name);
16708 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
16712 raw : { errorMsg : "JSON Reader Error: fields or metadata not available to create Record" },
16718 var record = new Record(values, id);
16720 records[i] = record;
16726 totalRecords : totalRecords
16729 // used when loading children.. @see loadDataFromChildren
16730 toLoadData: function(rec)
16732 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
16733 var data = typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
16734 return { data : data, total : data.length };
16739 * Ext JS Library 1.1.1
16740 * Copyright(c) 2006-2007, Ext JS, LLC.
16742 * Originally Released Under LGPL - original licence link has changed is not relivant.
16745 * <script type="text/javascript">
16749 * @class Roo.data.ArrayReader
16750 * @extends Roo.data.DataReader
16751 * Data reader class to create an Array of Roo.data.Record objects from an Array.
16752 * Each element of that Array represents a row of data fields. The
16753 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
16754 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
16758 var RecordDef = Roo.data.Record.create([
16759 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
16760 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
16762 var myReader = new Roo.data.ArrayReader({
16763 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
16767 * This would consume an Array like this:
16769 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
16773 * Create a new JsonReader
16774 * @param {Object} meta Metadata configuration options.
16775 * @param {Object|Array} recordType Either an Array of field definition objects
16777 * @cfg {Array} fields Array of field definition objects
16778 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
16779 * as specified to {@link Roo.data.Record#create},
16780 * or an {@link Roo.data.Record} object
16783 * created using {@link Roo.data.Record#create}.
16785 Roo.data.ArrayReader = function(meta, recordType)
16787 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType||meta.fields);
16790 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
16793 * Create a data block containing Roo.data.Records from an XML document.
16794 * @param {Object} o An Array of row objects which represents the dataset.
16795 * @return {Object} A data block which is used by an {@link Roo.data.Store} object as
16796 * a cache of Roo.data.Records.
16798 readRecords : function(o)
16800 var sid = this.meta ? this.meta.id : null;
16801 var recordType = this.recordType, fields = recordType.prototype.fields;
16804 for(var i = 0; i < root.length; i++){
16807 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
16808 for(var j = 0, jlen = fields.length; j < jlen; j++){
16809 var f = fields.items[j];
16810 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
16811 var v = n[k] !== undefined ? n[k] : f.defaultValue;
16813 values[f.name] = v;
16815 var record = new recordType(values, id);
16817 records[records.length] = record;
16821 totalRecords : records.length
16824 // used when loading children.. @see loadDataFromChildren
16825 toLoadData: function(rec)
16827 // expect rec just to be an array.. eg [a,b,c, [...] << cn ]
16828 return typeof(rec.data.cn) == 'undefined' ? [] : rec.data.cn;
16839 * @class Roo.bootstrap.form.ComboBox
16840 * @extends Roo.bootstrap.form.TriggerField
16841 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
16842 * @cfg {Boolean} append (true|false) default false
16843 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
16844 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
16845 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
16846 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
16847 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16848 * @cfg {Boolean} animate default true
16849 * @cfg {Boolean} emptyResultText only for touch device
16850 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
16851 * @cfg {String} emptyTitle default ''
16852 * @cfg {Number} width fixed with? experimental
16854 * Create a new ComboBox.
16855 * @param {Object} config Configuration options
16857 Roo.bootstrap.form.ComboBox = function(config){
16858 Roo.bootstrap.form.ComboBox.superclass.constructor.call(this, config);
16862 * Fires when the dropdown list is expanded
16863 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16868 * Fires when the dropdown list is collapsed
16869 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16873 * @event beforeselect
16874 * Fires before a list item is selected. Return false to cancel the selection.
16875 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16876 * @param {Roo.data.Record} record The data record returned from the underlying store
16877 * @param {Number} index The index of the selected item in the dropdown list
16879 'beforeselect' : true,
16882 * Fires when a list item is selected
16883 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16884 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
16885 * @param {Number} index The index of the selected item in the dropdown list
16889 * @event beforequery
16890 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
16891 * The event object passed has these properties:
16892 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16893 * @param {String} query The query
16894 * @param {Boolean} forceAll true to force "all" query
16895 * @param {Boolean} cancel true to cancel the query
16896 * @param {Object} e The query event object
16898 'beforequery': true,
16901 * Fires when the 'add' icon is pressed (add a listener to enable add button)
16902 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16907 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
16908 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16909 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
16914 * Fires when the remove value from the combobox array
16915 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16919 * @event afterremove
16920 * Fires when the remove value from the combobox array
16921 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16923 'afterremove' : true,
16925 * @event specialfilter
16926 * Fires when specialfilter
16927 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16929 'specialfilter' : true,
16932 * Fires when tick the element
16933 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16937 * @event touchviewdisplay
16938 * Fires when touch view require special display (default is using displayField)
16939 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
16940 * @param {Object} cfg set html .
16942 'touchviewdisplay' : true
16947 this.tickItems = [];
16949 this.selectedIndex = -1;
16950 if(this.mode == 'local'){
16951 if(config.queryDelay === undefined){
16952 this.queryDelay = 10;
16954 if(config.minChars === undefined){
16960 Roo.extend(Roo.bootstrap.form.ComboBox, Roo.bootstrap.form.TriggerField, {
16963 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
16964 * rendering into an Roo.Editor, defaults to false)
16967 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
16968 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
16971 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
16974 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
16975 * the dropdown list (defaults to undefined, with no header element)
16979 * @cfg {String/Roo.Template} tpl The template to use to render the output default is '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>'
16983 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
16985 listWidth: undefined,
16987 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
16988 * mode = 'remote' or 'text' if mode = 'local')
16990 displayField: undefined,
16993 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
16994 * mode = 'remote' or 'value' if mode = 'local').
16995 * Note: use of a valueField requires the user make a selection
16996 * in order for a value to be mapped.
16998 valueField: undefined,
17000 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
17005 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
17006 * field's data value (defaults to the underlying DOM element's name)
17008 hiddenName: undefined,
17010 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
17014 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
17016 selectedClass: 'active',
17019 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
17023 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
17024 * anchor positions (defaults to 'tl-bl')
17026 listAlign: 'tl-bl?',
17028 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
17032 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
17033 * query specified by the allQuery config option (defaults to 'query')
17035 triggerAction: 'query',
17037 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
17038 * (defaults to 4, does not apply if editable = false)
17042 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
17043 * delay (typeAheadDelay) if it matches a known value (defaults to false)
17047 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
17048 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
17052 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
17053 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
17057 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
17058 * when editable = true (defaults to false)
17060 selectOnFocus:false,
17062 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
17064 queryParam: 'query',
17066 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
17067 * when mode = 'remote' (defaults to 'Loading...')
17069 loadingText: 'Loading...',
17071 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
17075 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
17079 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
17080 * traditional select (defaults to true)
17084 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
17088 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
17092 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
17093 * listWidth has a higher value)
17097 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
17098 * allow the user to set arbitrary text into the field (defaults to false)
17100 forceSelection:false,
17102 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
17103 * if typeAhead = true (defaults to 250)
17105 typeAheadDelay : 250,
17107 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
17108 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
17110 valueNotFoundText : undefined,
17112 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
17114 blockFocus : false,
17117 * @cfg {Boolean} disableClear Disable showing of clear button.
17119 disableClear : false,
17121 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
17123 alwaysQuery : false,
17126 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
17131 * @cfg {String} invalidClass DEPRICATED - uses BS4 is-valid now
17133 invalidClass : "has-warning",
17136 * @cfg {String} validClass DEPRICATED - uses BS4 is-valid now
17138 validClass : "has-success",
17141 * @cfg {Boolean} specialFilter (true|false) special filter default false
17143 specialFilter : false,
17146 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
17148 mobileTouchView : true,
17151 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
17153 useNativeIOS : false,
17156 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
17158 mobile_restrict_height : false,
17160 ios_options : false,
17172 btnPosition : 'right',
17173 triggerList : true,
17174 showToggleBtn : true,
17176 emptyResultText: 'Empty',
17177 triggerText : 'Select',
17181 // element that contains real text value.. (when hidden is used..)
17183 getAutoCreate : function()
17188 * Render classic select for iso
17191 if(Roo.isIOS && this.useNativeIOS){
17192 cfg = this.getAutoCreateNativeIOS();
17200 if(Roo.isTouch && this.mobileTouchView){
17201 cfg = this.getAutoCreateTouchView();
17208 if(!this.tickable){
17209 cfg = Roo.bootstrap.form.ComboBox.superclass.getAutoCreate.call(this);
17214 * ComboBox with tickable selections
17217 var align = this.labelAlign || this.parentLabelAlign();
17220 cls : 'form-group roo-combobox-tickable' //input-group
17223 var btn_text_select = '';
17224 var btn_text_done = '';
17225 var btn_text_cancel = '';
17227 if (this.btn_text_show) {
17228 btn_text_select = 'Select';
17229 btn_text_done = 'Done';
17230 btn_text_cancel = 'Cancel';
17235 cls : 'tickable-buttons',
17240 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
17241 //html : this.triggerText
17242 html: btn_text_select
17248 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
17250 html: btn_text_done
17256 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
17258 html: btn_text_cancel
17264 buttons.cn.unshift({
17266 cls: 'roo-select2-search-field-input'
17272 Roo.each(buttons.cn, function(c){
17274 c.cls += ' btn-' + _this.size;
17277 if (_this.disabled) {
17284 style : 'display: contents',
17289 cls: 'form-hidden-field'
17293 cls: 'roo-select2-choices',
17297 cls: 'roo-select2-search-field',
17308 cls: 'roo-select2-container input-group roo-select2-container-multi',
17314 // cls: 'typeahead typeahead-long dropdown-menu',
17315 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
17320 if(this.hasFeedback && !this.allowBlank){
17324 cls: 'glyphicon form-control-feedback'
17327 combobox.cn.push(feedback);
17334 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
17335 tooltip : 'This field is required'
17337 if (Roo.bootstrap.version == 4) {
17340 style : 'display:none'
17343 if (align ==='left' && this.fieldLabel.length) {
17345 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
17352 cls : 'control-label col-form-label',
17353 html : this.fieldLabel
17365 var labelCfg = cfg.cn[1];
17366 var contentCfg = cfg.cn[2];
17369 if(this.indicatorpos == 'right'){
17375 cls : 'control-label col-form-label',
17379 html : this.fieldLabel
17395 labelCfg = cfg.cn[0];
17396 contentCfg = cfg.cn[1];
17400 if(this.labelWidth > 12){
17401 labelCfg.style = "width: " + this.labelWidth + 'px';
17403 if(this.width * 1 > 0){
17404 contentCfg.style = "width: " + this.width + 'px';
17406 if(this.labelWidth < 13 && this.labelmd == 0){
17407 this.labelmd = this.labelWidth;
17410 if(this.labellg > 0){
17411 labelCfg.cls += ' col-lg-' + this.labellg;
17412 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
17415 if(this.labelmd > 0){
17416 labelCfg.cls += ' col-md-' + this.labelmd;
17417 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
17420 if(this.labelsm > 0){
17421 labelCfg.cls += ' col-sm-' + this.labelsm;
17422 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
17425 if(this.labelxs > 0){
17426 labelCfg.cls += ' col-xs-' + this.labelxs;
17427 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
17431 } else if ( this.fieldLabel.length) {
17432 // Roo.log(" label");
17437 //cls : 'input-group-addon',
17438 html : this.fieldLabel
17443 if(this.indicatorpos == 'right'){
17447 //cls : 'input-group-addon',
17448 html : this.fieldLabel
17458 // Roo.log(" no label && no align");
17465 ['xs','sm','md','lg'].map(function(size){
17466 if (settings[size]) {
17467 cfg.cls += ' col-' + size + '-' + settings[size];
17475 _initEventsCalled : false,
17478 initEvents: function()
17480 if (this._initEventsCalled) { // as we call render... prevent looping...
17483 this._initEventsCalled = true;
17486 throw "can not find store for combo";
17489 this.indicator = this.indicatorEl();
17491 this.store = Roo.factory(this.store, Roo.data);
17492 this.store.parent = this;
17494 // if we are building from html. then this element is so complex, that we can not really
17495 // use the rendered HTML.
17496 // so we have to trash and replace the previous code.
17497 if (Roo.XComponent.build_from_html) {
17498 // remove this element....
17499 var e = this.el.dom, k=0;
17500 while (e ) { e = e.previousSibling; ++k;}
17505 this.rendered = false;
17507 this.render(this.parent().getChildContainer(true), k);
17510 if(Roo.isIOS && this.useNativeIOS){
17511 this.initIOSView();
17519 if(Roo.isTouch && this.mobileTouchView){
17520 this.initTouchView();
17525 this.initTickableEvents();
17529 Roo.bootstrap.form.ComboBox.superclass.initEvents.call(this);
17531 if(this.hiddenName){
17533 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
17535 this.hiddenField.dom.value =
17536 this.hiddenValue !== undefined ? this.hiddenValue :
17537 this.value !== undefined ? this.value : '';
17539 // prevent input submission
17540 this.el.dom.removeAttribute('name');
17541 this.hiddenField.dom.setAttribute('name', this.hiddenName);
17546 // this.el.dom.setAttribute('autocomplete', 'off');
17549 var cls = 'x-combo-list';
17551 //this.list = new Roo.Layer({
17552 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
17558 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
17559 _this.list.setWidth(lw);
17562 this.list.on('mouseover', this.onViewOver, this);
17563 this.list.on('mousemove', this.onViewMove, this);
17564 this.list.on('scroll', this.onViewScroll, this);
17567 this.list.swallowEvent('mousewheel');
17568 this.assetHeight = 0;
17571 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
17572 this.assetHeight += this.header.getHeight();
17575 this.innerList = this.list.createChild({cls:cls+'-inner'});
17576 this.innerList.on('mouseover', this.onViewOver, this);
17577 this.innerList.on('mousemove', this.onViewMove, this);
17578 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
17580 if(this.allowBlank && !this.pageSize && !this.disableClear){
17581 this.footer = this.list.createChild({cls:cls+'-ft'});
17582 this.pageTb = new Roo.Toolbar(this.footer);
17586 this.footer = this.list.createChild({cls:cls+'-ft'});
17587 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
17588 {pageSize: this.pageSize});
17592 if (this.pageTb && this.allowBlank && !this.disableClear) {
17594 this.pageTb.add(new Roo.Toolbar.Fill(), {
17595 cls: 'x-btn-icon x-btn-clear',
17597 handler: function()
17600 _this.clearValue();
17601 _this.onSelect(false, -1);
17606 this.assetHeight += this.footer.getHeight();
17611 this.tpl = Roo.bootstrap.version == 4 ?
17612 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
17613 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
17616 this.view = new Roo.View(this.list, this.tpl, {
17617 singleSelect:true, store: this.store, selectedClass: this.selectedClass
17619 //this.view.wrapEl.setDisplayed(false);
17620 this.view.on('click', this.onViewClick, this);
17623 this.store.on('beforeload', this.onBeforeLoad, this);
17624 this.store.on('load', this.onLoad, this);
17625 this.store.on('loadexception', this.onLoadException, this);
17627 if(this.resizable){
17628 this.resizer = new Roo.Resizable(this.list, {
17629 pinned:true, handles:'se'
17631 this.resizer.on('resize', function(r, w, h){
17632 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
17633 this.listWidth = w;
17634 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
17635 this.restrictHeight();
17637 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
17640 if(!this.editable){
17641 this.editable = true;
17642 this.setEditable(false);
17647 if (typeof(this.events.add.listeners) != 'undefined') {
17649 this.addicon = this.wrap.createChild(
17650 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
17652 this.addicon.on('click', function(e) {
17653 this.fireEvent('add', this);
17656 if (typeof(this.events.edit.listeners) != 'undefined') {
17658 this.editicon = this.wrap.createChild(
17659 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
17660 if (this.addicon) {
17661 this.editicon.setStyle('margin-left', '40px');
17663 this.editicon.on('click', function(e) {
17665 // we fire even if inothing is selected..
17666 this.fireEvent('edit', this, this.lastData );
17672 this.keyNav = new Roo.KeyNav(this.inputEl(), {
17673 "up" : function(e){
17674 this.inKeyMode = true;
17678 "down" : function(e){
17679 if(!this.isExpanded()){
17680 this.onTriggerClick();
17682 this.inKeyMode = true;
17687 "enter" : function(e){
17688 // this.onViewClick();
17692 if(this.fireEvent("specialkey", this, e)){
17693 this.onViewClick(false);
17699 "esc" : function(e){
17703 "tab" : function(e){
17706 if(this.fireEvent("specialkey", this, e)){
17707 this.onViewClick(false);
17715 doRelay : function(foo, bar, hname){
17716 if(hname == 'down' || this.scope.isExpanded()){
17717 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
17726 this.queryDelay = Math.max(this.queryDelay || 10,
17727 this.mode == 'local' ? 10 : 250);
17730 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
17732 if(this.typeAhead){
17733 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
17735 if(this.editable !== false){
17736 this.inputEl().on("keyup", this.onKeyUp, this);
17738 if(this.forceSelection){
17739 this.inputEl().on('blur', this.doForce, this);
17743 this.choices = this.el.select('ul.roo-select2-choices', true).first();
17744 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
17748 initTickableEvents: function()
17752 if(this.hiddenName){
17754 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
17756 this.hiddenField.dom.value =
17757 this.hiddenValue !== undefined ? this.hiddenValue :
17758 this.value !== undefined ? this.value : '';
17760 // prevent input submission
17761 this.el.dom.removeAttribute('name');
17762 this.hiddenField.dom.setAttribute('name', this.hiddenName);
17767 // this.list = this.el.select('ul.dropdown-menu',true).first();
17769 this.choices = this.el.select('ul.roo-select2-choices', true).first();
17770 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
17771 if(this.triggerList){
17772 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
17775 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
17776 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
17778 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
17779 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
17781 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
17782 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
17784 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
17785 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
17786 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
17789 this.cancelBtn.hide();
17794 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
17795 _this.list.setWidth(lw);
17798 this.list.on('mouseover', this.onViewOver, this);
17799 this.list.on('mousemove', this.onViewMove, this);
17801 this.list.on('scroll', this.onViewScroll, this);
17804 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
17805 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
17808 this.view = new Roo.View(this.list, this.tpl, {
17813 selectedClass: this.selectedClass
17816 //this.view.wrapEl.setDisplayed(false);
17817 this.view.on('click', this.onViewClick, this);
17821 this.store.on('beforeload', this.onBeforeLoad, this);
17822 this.store.on('load', this.onLoad, this);
17823 this.store.on('loadexception', this.onLoadException, this);
17826 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
17827 "up" : function(e){
17828 this.inKeyMode = true;
17832 "down" : function(e){
17833 this.inKeyMode = true;
17837 "enter" : function(e){
17838 if(this.fireEvent("specialkey", this, e)){
17839 this.onViewClick(false);
17845 "esc" : function(e){
17846 this.onTickableFooterButtonClick(e, false, false);
17849 "tab" : function(e){
17850 this.fireEvent("specialkey", this, e);
17852 this.onTickableFooterButtonClick(e, false, false);
17859 doRelay : function(e, fn, key){
17860 if(this.scope.isExpanded()){
17861 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
17870 this.queryDelay = Math.max(this.queryDelay || 10,
17871 this.mode == 'local' ? 10 : 250);
17874 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
17876 if(this.typeAhead){
17877 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
17880 if(this.editable !== false){
17881 this.tickableInputEl().on("keyup", this.onKeyUp, this);
17884 this.indicator = this.indicatorEl();
17886 if(this.indicator){
17887 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
17888 this.indicator.hide();
17893 onDestroy : function(){
17895 this.view.setStore(null);
17896 this.view.el.removeAllListeners();
17897 this.view.el.remove();
17898 this.view.purgeListeners();
17901 this.list.dom.innerHTML = '';
17905 this.store.un('beforeload', this.onBeforeLoad, this);
17906 this.store.un('load', this.onLoad, this);
17907 this.store.un('loadexception', this.onLoadException, this);
17909 Roo.bootstrap.form.ComboBox.superclass.onDestroy.call(this);
17913 fireKey : function(e){
17914 if(e.isNavKeyPress() && !this.list.isVisible()){
17915 this.fireEvent("specialkey", this, e);
17920 onResize: function(w, h)
17924 // Roo.bootstrap.form.ComboBox.superclass.onResize.apply(this, arguments);
17926 // if(typeof w != 'number'){
17927 // // we do not handle it!?!?
17930 // var tw = this.trigger.getWidth();
17931 // // tw += this.addicon ? this.addicon.getWidth() : 0;
17932 // // tw += this.editicon ? this.editicon.getWidth() : 0;
17934 // this.inputEl().setWidth( this.adjustWidth('input', x));
17936 // //this.trigger.setStyle('left', x+'px');
17938 // if(this.list && this.listWidth === undefined){
17939 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
17940 // this.list.setWidth(lw);
17941 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
17949 * Allow or prevent the user from directly editing the field text. If false is passed,
17950 * the user will only be able to select from the items defined in the dropdown list. This method
17951 * is the runtime equivalent of setting the 'editable' config option at config time.
17952 * @param {Boolean} value True to allow the user to directly edit the field text
17954 setEditable : function(value){
17955 if(value == this.editable){
17958 this.editable = value;
17960 this.inputEl().dom.setAttribute('readOnly', true);
17961 this.inputEl().on('mousedown', this.onTriggerClick, this);
17962 this.inputEl().addClass('x-combo-noedit');
17964 this.inputEl().dom.removeAttribute('readOnly');
17965 this.inputEl().un('mousedown', this.onTriggerClick, this);
17966 this.inputEl().removeClass('x-combo-noedit');
17972 onBeforeLoad : function(combo,opts){
17973 if(!this.hasFocus){
17977 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
17979 this.restrictHeight();
17980 this.selectedIndex = -1;
17984 onLoad : function(){
17986 this.hasQuery = false;
17988 if(!this.hasFocus){
17992 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
17993 this.loading.hide();
17996 if(this.store.getCount() > 0){
17999 this.restrictHeight();
18000 if(this.lastQuery == this.allQuery){
18001 if(this.editable && !this.tickable){
18002 this.inputEl().dom.select();
18006 !this.selectByValue(this.value, true) &&
18009 !this.store.lastOptions ||
18010 typeof(this.store.lastOptions.add) == 'undefined' ||
18011 this.store.lastOptions.add != true
18014 this.select(0, true);
18017 if(this.autoFocus){
18020 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
18021 this.taTask.delay(this.typeAheadDelay);
18025 this.onEmptyResults();
18031 onLoadException : function()
18033 this.hasQuery = false;
18035 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
18036 this.loading.hide();
18039 if(this.tickable && this.editable){
18044 // only causes errors at present
18045 //Roo.log(this.store.reader.jsonData);
18046 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
18048 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
18054 onTypeAhead : function(){
18055 if(this.store.getCount() > 0){
18056 var r = this.store.getAt(0);
18057 var newValue = r.data[this.displayField];
18058 var len = newValue.length;
18059 var selStart = this.getRawValue().length;
18061 if(selStart != len){
18062 this.setRawValue(newValue);
18063 this.selectText(selStart, newValue.length);
18069 onSelect : function(record, index){
18071 if(this.fireEvent('beforeselect', this, record, index) !== false){
18073 this.setFromData(index > -1 ? record.data : false);
18076 this.fireEvent('select', this, record, index);
18081 * Returns the currently selected field value or empty string if no value is set.
18082 * @return {String} value The selected value
18084 getValue : function()
18086 if(Roo.isIOS && this.useNativeIOS){
18087 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
18091 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
18094 if(this.valueField){
18095 return typeof this.value != 'undefined' ? this.value : '';
18097 return Roo.bootstrap.form.ComboBox.superclass.getValue.call(this);
18101 getRawValue : function()
18103 if(Roo.isIOS && this.useNativeIOS){
18104 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
18107 var v = this.inputEl().getValue();
18113 * Clears any text/value currently set in the field
18115 clearValue : function(){
18117 if(this.hiddenField){
18118 this.hiddenField.dom.value = '';
18121 this.setRawValue('');
18122 this.lastSelectionText = '';
18123 this.lastData = false;
18125 var close = this.closeTriggerEl();
18136 * Sets the specified value into the field. If the value finds a match, the corresponding record text
18137 * will be displayed in the field. If the value does not match the data value of an existing item,
18138 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
18139 * Otherwise the field will be blank (although the value will still be set).
18140 * @param {String} value The value to match
18142 setValue : function(v)
18144 if(Roo.isIOS && this.useNativeIOS){
18145 this.setIOSValue(v);
18155 if(this.valueField){
18156 var r = this.findRecord(this.valueField, v);
18158 text = r.data[this.displayField];
18159 }else if(this.valueNotFoundText !== undefined){
18160 text = this.valueNotFoundText;
18163 this.lastSelectionText = text;
18164 if(this.hiddenField){
18165 this.hiddenField.dom.value = v;
18167 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, text);
18170 var close = this.closeTriggerEl();
18173 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
18179 * @property {Object} the last set data for the element
18184 * Sets the value of the field based on a object which is related to the record format for the store.
18185 * @param {Object} value the value to set as. or false on reset?
18187 setFromData : function(o){
18194 var dv = ''; // display value
18195 var vv = ''; // value value..
18197 if (this.displayField) {
18198 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
18200 // this is an error condition!!!
18201 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
18204 if(this.valueField){
18205 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
18208 var close = this.closeTriggerEl();
18211 if(dv.length || vv * 1 > 0){
18213 this.blockFocus=true;
18219 if(this.hiddenField){
18220 this.hiddenField.dom.value = vv;
18222 this.lastSelectionText = dv;
18223 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
18227 // no hidden field.. - we store the value in 'value', but still display
18228 // display field!!!!
18229 this.lastSelectionText = dv;
18230 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
18237 reset : function(){
18238 // overridden so that last data is reset..
18245 this.setValue(this.originalValue);
18246 //this.clearInvalid();
18247 this.lastData = false;
18249 this.view.clearSelections();
18255 findRecord : function(prop, value){
18257 if(this.store.getCount() > 0){
18258 this.store.each(function(r){
18259 if(r.data[prop] == value){
18269 getName: function()
18271 // returns hidden if it's set..
18272 if (!this.rendered) {return ''};
18273 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
18277 onViewMove : function(e, t){
18278 this.inKeyMode = false;
18282 onViewOver : function(e, t){
18283 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
18286 var item = this.view.findItemFromChild(t);
18289 var index = this.view.indexOf(item);
18290 this.select(index, false);
18295 onViewClick : function(view, doFocus, el, e)
18297 var index = this.view.getSelectedIndexes()[0];
18299 var r = this.store.getAt(index);
18303 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
18310 Roo.each(this.tickItems, function(v,k){
18312 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
18314 _this.tickItems.splice(k, 1);
18316 if(typeof(e) == 'undefined' && view == false){
18317 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
18329 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
18330 this.tickItems.push(r.data);
18333 if(typeof(e) == 'undefined' && view == false){
18334 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
18341 this.onSelect(r, index);
18343 if(doFocus !== false && !this.blockFocus){
18344 this.inputEl().focus();
18349 restrictHeight : function(){
18350 //this.innerList.dom.style.height = '';
18351 //var inner = this.innerList.dom;
18352 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
18353 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
18354 //this.list.beginUpdate();
18355 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
18356 this.list.alignTo(this.inputEl(), this.listAlign);
18357 this.list.alignTo(this.inputEl(), this.listAlign);
18358 //this.list.endUpdate();
18362 onEmptyResults : function(){
18364 if(this.tickable && this.editable){
18365 this.hasFocus = false;
18366 this.restrictHeight();
18374 * Returns true if the dropdown list is expanded, else false.
18376 isExpanded : function(){
18377 return this.list.isVisible();
18381 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
18382 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
18383 * @param {String} value The data value of the item to select
18384 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
18385 * selected item if it is not currently in view (defaults to true)
18386 * @return {Boolean} True if the value matched an item in the list, else false
18388 selectByValue : function(v, scrollIntoView){
18389 if(v !== undefined && v !== null){
18390 var r = this.findRecord(this.valueField || this.displayField, v);
18392 this.select(this.store.indexOf(r), scrollIntoView);
18400 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
18401 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
18402 * @param {Number} index The zero-based index of the list item to select
18403 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
18404 * selected item if it is not currently in view (defaults to true)
18406 select : function(index, scrollIntoView){
18407 this.selectedIndex = index;
18408 this.view.select(index);
18409 if(scrollIntoView !== false){
18410 var el = this.view.getNode(index);
18412 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
18415 this.list.scrollChildIntoView(el, false);
18421 selectNext : function(){
18422 var ct = this.store.getCount();
18424 if(this.selectedIndex == -1){
18426 }else if(this.selectedIndex < ct-1){
18427 this.select(this.selectedIndex+1);
18433 selectPrev : function(){
18434 var ct = this.store.getCount();
18436 if(this.selectedIndex == -1){
18438 }else if(this.selectedIndex != 0){
18439 this.select(this.selectedIndex-1);
18445 onKeyUp : function(e){
18446 if(this.editable !== false && !e.isSpecialKey()){
18447 this.lastKey = e.getKey();
18448 this.dqTask.delay(this.queryDelay);
18453 validateBlur : function(){
18454 return !this.list || !this.list.isVisible();
18458 initQuery : function(){
18460 var v = this.getRawValue();
18462 if(this.tickable && this.editable){
18463 v = this.tickableInputEl().getValue();
18470 doForce : function(){
18471 if(this.inputEl().dom.value.length > 0){
18472 this.inputEl().dom.value =
18473 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
18479 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
18480 * query allowing the query action to be canceled if needed.
18481 * @param {String} query The SQL query to execute
18482 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
18483 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
18484 * saved in the current store (defaults to false)
18486 doQuery : function(q, forceAll){
18488 if(q === undefined || q === null){
18493 forceAll: forceAll,
18497 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
18502 forceAll = qe.forceAll;
18503 if(forceAll === true || (q.length >= this.minChars)){
18505 this.hasQuery = true;
18507 if(this.lastQuery != q || this.alwaysQuery){
18508 this.lastQuery = q;
18509 if(this.mode == 'local'){
18510 this.selectedIndex = -1;
18512 this.store.clearFilter();
18515 if(this.specialFilter){
18516 this.fireEvent('specialfilter', this);
18521 this.store.filter(this.displayField, q);
18524 this.store.fireEvent("datachanged", this.store);
18531 this.store.baseParams[this.queryParam] = q;
18533 var options = {params : this.getParams(q)};
18536 options.add = true;
18537 options.params.start = this.page * this.pageSize;
18540 this.store.load(options);
18543 * this code will make the page width larger, at the beginning, the list not align correctly,
18544 * we should expand the list on onLoad
18545 * so command out it
18550 this.selectedIndex = -1;
18555 this.loadNext = false;
18559 getParams : function(q){
18561 //p[this.queryParam] = q;
18565 p.limit = this.pageSize;
18571 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
18573 collapse : function(){
18574 if(!this.isExpanded()){
18580 this.hasFocus = false;
18584 this.cancelBtn.hide();
18585 this.trigger.show();
18588 this.tickableInputEl().dom.value = '';
18589 this.tickableInputEl().blur();
18594 Roo.get(document).un('mousedown', this.collapseIf, this);
18595 Roo.get(document).un('mousewheel', this.collapseIf, this);
18596 if (!this.editable) {
18597 Roo.get(document).un('keydown', this.listKeyPress, this);
18599 this.fireEvent('collapse', this);
18605 collapseIf : function(e){
18606 var in_combo = e.within(this.el);
18607 var in_list = e.within(this.list);
18608 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
18610 if (in_combo || in_list || is_list) {
18611 //e.stopPropagation();
18616 this.onTickableFooterButtonClick(e, false, false);
18624 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
18626 expand : function(){
18628 if(this.isExpanded() || !this.hasFocus){
18632 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
18633 this.list.setWidth(lw);
18639 this.restrictHeight();
18643 this.tickItems = Roo.apply([], this.item);
18646 this.cancelBtn.show();
18647 this.trigger.hide();
18650 this.tickableInputEl().focus();
18655 Roo.get(document).on('mousedown', this.collapseIf, this);
18656 Roo.get(document).on('mousewheel', this.collapseIf, this);
18657 if (!this.editable) {
18658 Roo.get(document).on('keydown', this.listKeyPress, this);
18661 this.fireEvent('expand', this);
18665 // Implements the default empty TriggerField.onTriggerClick function
18666 onTriggerClick : function(e)
18668 Roo.log('trigger click');
18670 if(this.disabled || !this.triggerList){
18675 this.loadNext = false;
18677 if(this.isExpanded()){
18679 if (!this.blockFocus) {
18680 this.inputEl().focus();
18684 this.hasFocus = true;
18685 if(this.triggerAction == 'all') {
18686 this.doQuery(this.allQuery, true);
18688 this.doQuery(this.getRawValue());
18690 if (!this.blockFocus) {
18691 this.inputEl().focus();
18696 onTickableTriggerClick : function(e)
18703 this.loadNext = false;
18704 this.hasFocus = true;
18706 if(this.triggerAction == 'all') {
18707 this.doQuery(this.allQuery, true);
18709 this.doQuery(this.getRawValue());
18713 onSearchFieldClick : function(e)
18715 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
18716 this.onTickableFooterButtonClick(e, false, false);
18720 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
18725 this.loadNext = false;
18726 this.hasFocus = true;
18728 if(this.triggerAction == 'all') {
18729 this.doQuery(this.allQuery, true);
18731 this.doQuery(this.getRawValue());
18735 listKeyPress : function(e)
18737 //Roo.log('listkeypress');
18738 // scroll to first matching element based on key pres..
18739 if (e.isSpecialKey()) {
18742 var k = String.fromCharCode(e.getKey()).toUpperCase();
18745 var csel = this.view.getSelectedNodes();
18746 var cselitem = false;
18748 var ix = this.view.indexOf(csel[0]);
18749 cselitem = this.store.getAt(ix);
18750 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
18756 this.store.each(function(v) {
18758 // start at existing selection.
18759 if (cselitem.id == v.id) {
18765 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
18766 match = this.store.indexOf(v);
18772 if (match === false) {
18773 return true; // no more action?
18776 this.view.select(match);
18777 var sn = Roo.get(this.view.getSelectedNodes()[0]);
18778 sn.scrollIntoView(sn.dom.parentNode, false);
18781 onViewScroll : function(e, t){
18783 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){
18787 this.hasQuery = true;
18789 this.loading = this.list.select('.loading', true).first();
18791 if(this.loading === null){
18792 this.list.createChild({
18794 cls: 'loading roo-select2-more-results roo-select2-active',
18795 html: 'Loading more results...'
18798 this.loading = this.list.select('.loading', true).first();
18800 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
18802 this.loading.hide();
18805 this.loading.show();
18810 this.loadNext = true;
18812 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
18817 addItem : function(o)
18819 var dv = ''; // display value
18821 if (this.displayField) {
18822 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
18824 // this is an error condition!!!
18825 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
18832 var choice = this.choices.createChild({
18834 cls: 'roo-select2-search-choice',
18843 cls: 'roo-select2-search-choice-close fa fa-times',
18848 }, this.searchField);
18850 var close = choice.select('a.roo-select2-search-choice-close', true).first();
18852 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
18860 this.inputEl().dom.value = '';
18865 onRemoveItem : function(e, _self, o)
18867 e.preventDefault();
18869 this.lastItem = Roo.apply([], this.item);
18871 var index = this.item.indexOf(o.data) * 1;
18874 Roo.log('not this item?!');
18878 this.item.splice(index, 1);
18883 this.fireEvent('remove', this, e);
18889 syncValue : function()
18891 if(!this.item.length){
18898 Roo.each(this.item, function(i){
18899 if(_this.valueField){
18900 value.push(i[_this.valueField]);
18907 this.value = value.join(',');
18909 if(this.hiddenField){
18910 this.hiddenField.dom.value = this.value;
18913 this.store.fireEvent("datachanged", this.store);
18918 clearItem : function()
18920 if(!this.multiple){
18926 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
18934 if(this.tickable && !Roo.isTouch){
18935 this.view.refresh();
18939 inputEl: function ()
18941 if(Roo.isIOS && this.useNativeIOS){
18942 return this.el.select('select.roo-ios-select', true).first();
18945 if(Roo.isTouch && this.mobileTouchView){
18946 return this.el.select('input.form-control',true).first();
18950 return this.searchField;
18953 return this.el.select('input.form-control',true).first();
18956 onTickableFooterButtonClick : function(e, btn, el)
18958 e.preventDefault();
18960 this.lastItem = Roo.apply([], this.item);
18962 if(btn && btn.name == 'cancel'){
18963 this.tickItems = Roo.apply([], this.item);
18972 Roo.each(this.tickItems, function(o){
18980 validate : function()
18982 if(this.getVisibilityEl().hasClass('hidden')){
18986 var v = this.getRawValue();
18989 v = this.getValue();
18992 if(this.disabled || this.allowBlank || v.length){
18997 this.markInvalid();
19001 tickableInputEl : function()
19003 if(!this.tickable || !this.editable){
19004 return this.inputEl();
19007 return this.inputEl().select('.roo-select2-search-field-input', true).first();
19011 getAutoCreateTouchView : function()
19016 cls: 'form-group' //input-group
19022 type : this.inputType,
19023 cls : 'form-control x-combo-noedit',
19024 autocomplete: 'new-password',
19025 placeholder : this.placeholder || '',
19030 input.name = this.name;
19034 input.cls += ' input-' + this.size;
19037 if (this.disabled) {
19038 input.disabled = true;
19042 cls : 'roo-combobox-wrap',
19049 inputblock.cls += ' input-group';
19051 inputblock.cn.unshift({
19053 cls : 'input-group-addon input-group-prepend input-group-text',
19058 if(this.removable && !this.multiple){
19059 inputblock.cls += ' roo-removable';
19061 inputblock.cn.push({
19064 cls : 'roo-combo-removable-btn close'
19068 if(this.hasFeedback && !this.allowBlank){
19070 inputblock.cls += ' has-feedback';
19072 inputblock.cn.push({
19074 cls: 'glyphicon form-control-feedback'
19081 inputblock.cls += (this.before) ? '' : ' input-group';
19083 inputblock.cn.push({
19085 cls : 'input-group-addon input-group-append input-group-text',
19091 var ibwrap = inputblock;
19096 cls: 'roo-select2-choices',
19100 cls: 'roo-select2-search-field',
19113 cls: 'roo-select2-container input-group roo-touchview-combobox ',
19118 cls: 'form-hidden-field'
19124 if(!this.multiple && this.showToggleBtn){
19130 if (this.caret != false) {
19133 cls: 'fa fa-' + this.caret
19140 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
19142 Roo.bootstrap.version == 3 ? caret : '',
19145 cls: 'combobox-clear',
19159 combobox.cls += ' roo-select2-container-multi';
19162 var required = this.allowBlank ? {
19164 style: 'display: none'
19167 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
19168 tooltip : 'This field is required'
19171 var align = this.labelAlign || this.parentLabelAlign();
19173 if (align ==='left' && this.fieldLabel.length) {
19179 cls : 'control-label col-form-label',
19180 html : this.fieldLabel
19184 cls : 'roo-combobox-wrap ',
19191 var labelCfg = cfg.cn[1];
19192 var contentCfg = cfg.cn[2];
19195 if(this.indicatorpos == 'right'){
19200 cls : 'control-label col-form-label',
19204 html : this.fieldLabel
19210 cls : "roo-combobox-wrap ",
19218 labelCfg = cfg.cn[0];
19219 contentCfg = cfg.cn[1];
19224 if(this.labelWidth > 12){
19225 labelCfg.style = "width: " + this.labelWidth + 'px';
19228 if(this.labelWidth < 13 && this.labelmd == 0){
19229 this.labelmd = this.labelWidth;
19232 if(this.labellg > 0){
19233 labelCfg.cls += ' col-lg-' + this.labellg;
19234 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
19237 if(this.labelmd > 0){
19238 labelCfg.cls += ' col-md-' + this.labelmd;
19239 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
19242 if(this.labelsm > 0){
19243 labelCfg.cls += ' col-sm-' + this.labelsm;
19244 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
19247 if(this.labelxs > 0){
19248 labelCfg.cls += ' col-xs-' + this.labelxs;
19249 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
19253 } else if ( this.fieldLabel.length) {
19258 cls : 'control-label',
19259 html : this.fieldLabel
19270 if(this.indicatorpos == 'right'){
19274 cls : 'control-label',
19275 html : this.fieldLabel,
19293 var settings = this;
19295 ['xs','sm','md','lg'].map(function(size){
19296 if (settings[size]) {
19297 cfg.cls += ' col-' + size + '-' + settings[size];
19304 initTouchView : function()
19306 this.renderTouchView();
19308 this.touchViewEl.on('scroll', function(){
19309 this.el.dom.scrollTop = 0;
19312 this.originalValue = this.getValue();
19314 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
19316 this.inputEl().on("click", this.showTouchView, this);
19317 if (this.triggerEl) {
19318 this.triggerEl.on("click", this.showTouchView, this);
19322 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
19323 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
19325 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
19327 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
19328 this.store.on('load', this.onTouchViewLoad, this);
19329 this.store.on('loadexception', this.onTouchViewLoadException, this);
19331 if(this.hiddenName){
19333 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
19335 this.hiddenField.dom.value =
19336 this.hiddenValue !== undefined ? this.hiddenValue :
19337 this.value !== undefined ? this.value : '';
19339 this.el.dom.removeAttribute('name');
19340 this.hiddenField.dom.setAttribute('name', this.hiddenName);
19344 this.choices = this.el.select('ul.roo-select2-choices', true).first();
19345 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
19348 if(this.removable && !this.multiple){
19349 var close = this.closeTriggerEl();
19351 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
19352 close.on('click', this.removeBtnClick, this, close);
19356 * fix the bug in Safari iOS8
19358 this.inputEl().on("focus", function(e){
19359 document.activeElement.blur();
19362 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
19369 renderTouchView : function()
19371 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.form.ComboBox.touchViewTemplate);
19372 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19374 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
19375 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19377 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
19378 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19379 this.touchViewBodyEl.setStyle('overflow', 'auto');
19381 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
19382 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19384 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
19385 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19389 showTouchView : function()
19395 this.touchViewHeaderEl.hide();
19397 if(this.modalTitle.length){
19398 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
19399 this.touchViewHeaderEl.show();
19402 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
19403 this.touchViewEl.show();
19405 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
19407 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
19408 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
19410 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
19412 if(this.modalTitle.length){
19413 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
19416 this.touchViewBodyEl.setHeight(bodyHeight);
19420 (function(){ _this.touchViewEl.addClass(['in','show']); }).defer(50);
19422 this.touchViewEl.addClass(['in','show']);
19425 if(this._touchViewMask){
19426 Roo.get(document.body).addClass("x-body-masked");
19427 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
19428 this._touchViewMask.setStyle('z-index', 10000);
19429 this._touchViewMask.addClass('show');
19432 this.doTouchViewQuery();
19436 hideTouchView : function()
19438 this.touchViewEl.removeClass(['in','show']);
19442 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
19444 this.touchViewEl.setStyle('display', 'none');
19447 if(this._touchViewMask){
19448 this._touchViewMask.removeClass('show');
19449 Roo.get(document.body).removeClass("x-body-masked");
19453 setTouchViewValue : function()
19460 Roo.each(this.tickItems, function(o){
19465 this.hideTouchView();
19468 doTouchViewQuery : function()
19477 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
19481 if(!this.alwaysQuery || this.mode == 'local'){
19482 this.onTouchViewLoad();
19489 onTouchViewBeforeLoad : function(combo,opts)
19495 onTouchViewLoad : function()
19497 if(this.store.getCount() < 1){
19498 this.onTouchViewEmptyResults();
19502 this.clearTouchView();
19504 var rawValue = this.getRawValue();
19506 var template = (this.multiple) ? Roo.bootstrap.form.ComboBox.listItemCheckbox : Roo.bootstrap.form.ComboBox.listItemRadio;
19508 this.tickItems = [];
19510 this.store.data.each(function(d, rowIndex){
19511 var row = this.touchViewListGroup.createChild(template);
19513 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
19514 row.addClass(d.data.cls);
19517 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
19520 html : d.data[this.displayField]
19523 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
19524 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
19527 row.removeClass('selected');
19528 if(!this.multiple && this.valueField &&
19529 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
19532 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19533 row.addClass('selected');
19536 if(this.multiple && this.valueField &&
19537 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
19541 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19542 this.tickItems.push(d.data);
19545 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
19549 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
19551 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
19553 if(this.modalTitle.length){
19554 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
19557 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
19559 if(this.mobile_restrict_height && listHeight < bodyHeight){
19560 this.touchViewBodyEl.setHeight(listHeight);
19565 if(firstChecked && listHeight > bodyHeight){
19566 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
19571 onTouchViewLoadException : function()
19573 this.hideTouchView();
19576 onTouchViewEmptyResults : function()
19578 this.clearTouchView();
19580 this.touchViewListGroup.createChild(Roo.bootstrap.form.ComboBox.emptyResult);
19582 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
19586 clearTouchView : function()
19588 this.touchViewListGroup.dom.innerHTML = '';
19591 onTouchViewClick : function(e, el, o)
19593 e.preventDefault();
19596 var rowIndex = o.rowIndex;
19598 var r = this.store.getAt(rowIndex);
19600 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
19602 if(!this.multiple){
19603 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
19604 c.dom.removeAttribute('checked');
19607 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19609 this.setFromData(r.data);
19611 var close = this.closeTriggerEl();
19617 this.hideTouchView();
19619 this.fireEvent('select', this, r, rowIndex);
19624 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
19625 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
19626 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
19630 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
19631 this.addItem(r.data);
19632 this.tickItems.push(r.data);
19636 getAutoCreateNativeIOS : function()
19639 cls: 'form-group' //input-group,
19644 cls : 'roo-ios-select'
19648 combobox.name = this.name;
19651 if (this.disabled) {
19652 combobox.disabled = true;
19655 var settings = this;
19657 ['xs','sm','md','lg'].map(function(size){
19658 if (settings[size]) {
19659 cfg.cls += ' col-' + size + '-' + settings[size];
19669 initIOSView : function()
19671 this.store.on('load', this.onIOSViewLoad, this);
19676 onIOSViewLoad : function()
19678 if(this.store.getCount() < 1){
19682 this.clearIOSView();
19684 if(this.allowBlank) {
19686 var default_text = '-- SELECT --';
19688 if(this.placeholder.length){
19689 default_text = this.placeholder;
19692 if(this.emptyTitle.length){
19693 default_text += ' - ' + this.emptyTitle + ' -';
19696 var opt = this.inputEl().createChild({
19699 html : default_text
19703 o[this.valueField] = 0;
19704 o[this.displayField] = default_text;
19706 this.ios_options.push({
19713 this.store.data.each(function(d, rowIndex){
19717 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
19718 html = d.data[this.displayField];
19723 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
19724 value = d.data[this.valueField];
19733 if(this.value == d.data[this.valueField]){
19734 option['selected'] = true;
19737 var opt = this.inputEl().createChild(option);
19739 this.ios_options.push({
19746 this.inputEl().on('change', function(){
19747 this.fireEvent('select', this);
19752 clearIOSView: function()
19754 this.inputEl().dom.innerHTML = '';
19756 this.ios_options = [];
19759 setIOSValue: function(v)
19763 if(!this.ios_options){
19767 Roo.each(this.ios_options, function(opts){
19769 opts.el.dom.removeAttribute('selected');
19771 if(opts.data[this.valueField] != v){
19775 opts.el.dom.setAttribute('selected', true);
19781 * @cfg {Boolean} grow
19785 * @cfg {Number} growMin
19789 * @cfg {Number} growMax
19798 Roo.apply(Roo.bootstrap.form.ComboBox, {
19802 cls: 'modal-header',
19824 cls: 'list-group-item',
19828 cls: 'roo-combobox-list-group-item-value'
19832 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
19846 listItemCheckbox : {
19848 cls: 'list-group-item',
19852 cls: 'roo-combobox-list-group-item-value'
19856 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
19872 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
19877 cls: 'modal-footer',
19885 cls: 'col-xs-6 text-left',
19888 cls: 'btn btn-danger roo-touch-view-cancel',
19894 cls: 'col-xs-6 text-right',
19897 cls: 'btn btn-success roo-touch-view-ok',
19908 Roo.apply(Roo.bootstrap.form.ComboBox, {
19910 touchViewTemplate : {
19912 cls: 'modal fade roo-combobox-touch-view',
19916 cls: 'modal-dialog',
19917 style : 'position:fixed', // we have to fix position....
19921 cls: 'modal-content',
19923 Roo.bootstrap.form.ComboBox.header,
19924 Roo.bootstrap.form.ComboBox.body,
19925 Roo.bootstrap.form.ComboBox.footer
19934 * Ext JS Library 1.1.1
19935 * Copyright(c) 2006-2007, Ext JS, LLC.
19937 * Originally Released Under LGPL - original licence link has changed is not relivant.
19940 * <script type="text/javascript">
19945 * @extends Roo.util.Observable
19946 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
19947 * This class also supports single and multi selection modes. <br>
19948 * Create a data model bound view:
19950 var store = new Roo.data.Store(...);
19952 var view = new Roo.View({
19954 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
19956 singleSelect: true,
19957 selectedClass: "ydataview-selected",
19961 // listen for node click?
19962 view.on("click", function(vw, index, node, e){
19963 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
19967 dataModel.load("foobar.xml");
19969 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
19971 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
19972 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
19974 * Note: old style constructor is still suported (container, template, config)
19977 * Create a new View
19978 * @param {Object} config The config object
19981 Roo.View = function(config, depreciated_tpl, depreciated_config){
19983 this.parent = false;
19985 if (typeof(depreciated_tpl) == 'undefined') {
19986 // new way.. - universal constructor.
19987 Roo.apply(this, config);
19988 this.el = Roo.get(this.el);
19991 this.el = Roo.get(config);
19992 this.tpl = depreciated_tpl;
19993 Roo.apply(this, depreciated_config);
19995 this.wrapEl = this.el.wrap().wrap();
19996 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
19999 if(typeof(this.tpl) == "string"){
20000 this.tpl = new Roo.Template(this.tpl);
20002 // support xtype ctors..
20003 this.tpl = new Roo.factory(this.tpl, Roo);
20007 this.tpl.compile();
20012 * @event beforeclick
20013 * Fires before a click is processed. Returns false to cancel the default action.
20014 * @param {Roo.View} this
20015 * @param {Number} index The index of the target node
20016 * @param {HTMLElement} node The target node
20017 * @param {Roo.EventObject} e The raw event object
20019 "beforeclick" : true,
20022 * Fires when a template node is clicked.
20023 * @param {Roo.View} this
20024 * @param {Number} index The index of the target node
20025 * @param {HTMLElement} node The target node
20026 * @param {Roo.EventObject} e The raw event object
20031 * Fires when a template node is double clicked.
20032 * @param {Roo.View} this
20033 * @param {Number} index The index of the target node
20034 * @param {HTMLElement} node The target node
20035 * @param {Roo.EventObject} e The raw event object
20039 * @event contextmenu
20040 * Fires when a template node is right clicked.
20041 * @param {Roo.View} this
20042 * @param {Number} index The index of the target node
20043 * @param {HTMLElement} node The target node
20044 * @param {Roo.EventObject} e The raw event object
20046 "contextmenu" : true,
20048 * @event selectionchange
20049 * Fires when the selected nodes change.
20050 * @param {Roo.View} this
20051 * @param {Array} selections Array of the selected nodes
20053 "selectionchange" : true,
20056 * @event beforeselect
20057 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
20058 * @param {Roo.View} this
20059 * @param {HTMLElement} node The node to be selected
20060 * @param {Array} selections Array of currently selected nodes
20062 "beforeselect" : true,
20064 * @event preparedata
20065 * Fires on every row to render, to allow you to change the data.
20066 * @param {Roo.View} this
20067 * @param {Object} data to be rendered (change this)
20069 "preparedata" : true
20077 "click": this.onClick,
20078 "dblclick": this.onDblClick,
20079 "contextmenu": this.onContextMenu,
20083 this.selections = [];
20085 this.cmp = new Roo.CompositeElementLite([]);
20087 this.store = Roo.factory(this.store, Roo.data);
20088 this.setStore(this.store, true);
20091 if ( this.footer && this.footer.xtype) {
20093 var fctr = this.wrapEl.appendChild(document.createElement("div"));
20095 this.footer.dataSource = this.store;
20096 this.footer.container = fctr;
20097 this.footer = Roo.factory(this.footer, Roo);
20098 fctr.insertFirst(this.el);
20100 // this is a bit insane - as the paging toolbar seems to detach the el..
20101 // dom.parentNode.parentNode.parentNode
20102 // they get detached?
20106 Roo.View.superclass.constructor.call(this);
20111 Roo.extend(Roo.View, Roo.util.Observable, {
20114 * @cfg {Roo.data.Store} store Data store to load data from.
20119 * @cfg {String|Roo.Element} el The container element.
20124 * @cfg {String|Roo.Template} tpl The template used by this View
20128 * @cfg {String} dataName the named area of the template to use as the data area
20129 * Works with domtemplates roo-name="name"
20133 * @cfg {String} selectedClass The css class to add to selected nodes
20135 selectedClass : "x-view-selected",
20137 * @cfg {String} emptyText The empty text to show when nothing is loaded.
20142 * @cfg {String} text to display on mask (default Loading)
20146 * @cfg {Boolean} multiSelect Allow multiple selection
20148 multiSelect : false,
20150 * @cfg {Boolean} singleSelect Allow single selection
20152 singleSelect: false,
20155 * @cfg {Boolean} toggleSelect - selecting
20157 toggleSelect : false,
20160 * @cfg {Boolean} tickable - selecting
20165 * Returns the element this view is bound to.
20166 * @return {Roo.Element}
20168 getEl : function(){
20169 return this.wrapEl;
20175 * Refreshes the view. - called by datachanged on the store. - do not call directly.
20177 refresh : function(){
20178 //Roo.log('refresh');
20181 // if we are using something like 'domtemplate', then
20182 // the what gets used is:
20183 // t.applySubtemplate(NAME, data, wrapping data..)
20184 // the outer template then get' applied with
20185 // the store 'extra data'
20186 // and the body get's added to the
20187 // roo-name="data" node?
20188 // <span class='roo-tpl-{name}'></span> ?????
20192 this.clearSelections();
20193 this.el.update("");
20195 var records = this.store.getRange();
20196 if(records.length < 1) {
20198 // is this valid?? = should it render a template??
20200 this.el.update(this.emptyText);
20204 if (this.dataName) {
20205 this.el.update(t.apply(this.store.meta)); //????
20206 el = this.el.child('.roo-tpl-' + this.dataName);
20209 for(var i = 0, len = records.length; i < len; i++){
20210 var data = this.prepareData(records[i].data, i, records[i]);
20211 this.fireEvent("preparedata", this, data, i, records[i]);
20213 var d = Roo.apply({}, data);
20216 Roo.apply(d, {'roo-id' : Roo.id()});
20220 Roo.each(this.parent.item, function(item){
20221 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
20224 Roo.apply(d, {'roo-data-checked' : 'checked'});
20228 html[html.length] = Roo.util.Format.trim(
20230 t.applySubtemplate(this.dataName, d, this.store.meta) :
20237 el.update(html.join(""));
20238 this.nodes = el.dom.childNodes;
20239 this.updateIndexes(0);
20244 * Function to override to reformat the data that is sent to
20245 * the template for each node.
20246 * DEPRICATED - use the preparedata event handler.
20247 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
20248 * a JSON object for an UpdateManager bound view).
20250 prepareData : function(data, index, record)
20252 this.fireEvent("preparedata", this, data, index, record);
20256 onUpdate : function(ds, record){
20257 // Roo.log('on update');
20258 this.clearSelections();
20259 var index = this.store.indexOf(record);
20260 var n = this.nodes[index];
20261 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
20262 n.parentNode.removeChild(n);
20263 this.updateIndexes(index, index);
20269 onAdd : function(ds, records, index)
20271 //Roo.log(['on Add', ds, records, index] );
20272 this.clearSelections();
20273 if(this.nodes.length == 0){
20277 var n = this.nodes[index];
20278 for(var i = 0, len = records.length; i < len; i++){
20279 var d = this.prepareData(records[i].data, i, records[i]);
20281 this.tpl.insertBefore(n, d);
20284 this.tpl.append(this.el, d);
20287 this.updateIndexes(index);
20290 onRemove : function(ds, record, index){
20291 // Roo.log('onRemove');
20292 this.clearSelections();
20293 var el = this.dataName ?
20294 this.el.child('.roo-tpl-' + this.dataName) :
20297 el.dom.removeChild(this.nodes[index]);
20298 this.updateIndexes(index);
20302 * Refresh an individual node.
20303 * @param {Number} index
20305 refreshNode : function(index){
20306 this.onUpdate(this.store, this.store.getAt(index));
20309 updateIndexes : function(startIndex, endIndex){
20310 var ns = this.nodes;
20311 startIndex = startIndex || 0;
20312 endIndex = endIndex || ns.length - 1;
20313 for(var i = startIndex; i <= endIndex; i++){
20314 ns[i].nodeIndex = i;
20319 * Changes the data store this view uses and refresh the view.
20320 * @param {Store} store
20322 setStore : function(store, initial){
20323 if(!initial && this.store){
20324 this.store.un("datachanged", this.refresh);
20325 this.store.un("add", this.onAdd);
20326 this.store.un("remove", this.onRemove);
20327 this.store.un("update", this.onUpdate);
20328 this.store.un("clear", this.refresh);
20329 this.store.un("beforeload", this.onBeforeLoad);
20330 this.store.un("load", this.onLoad);
20331 this.store.un("loadexception", this.onLoad);
20335 store.on("datachanged", this.refresh, this);
20336 store.on("add", this.onAdd, this);
20337 store.on("remove", this.onRemove, this);
20338 store.on("update", this.onUpdate, this);
20339 store.on("clear", this.refresh, this);
20340 store.on("beforeload", this.onBeforeLoad, this);
20341 store.on("load", this.onLoad, this);
20342 store.on("loadexception", this.onLoad, this);
20350 * onbeforeLoad - masks the loading area.
20353 onBeforeLoad : function(store,opts)
20355 //Roo.log('onBeforeLoad');
20357 this.el.update("");
20359 this.el.mask(this.mask ? this.mask : "Loading" );
20361 onLoad : function ()
20368 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
20369 * @param {HTMLElement} node
20370 * @return {HTMLElement} The template node
20372 findItemFromChild : function(node){
20373 var el = this.dataName ?
20374 this.el.child('.roo-tpl-' + this.dataName,true) :
20377 if(!node || node.parentNode == el){
20380 var p = node.parentNode;
20381 while(p && p != el){
20382 if(p.parentNode == el){
20391 onClick : function(e){
20392 var item = this.findItemFromChild(e.getTarget());
20394 var index = this.indexOf(item);
20395 if(this.onItemClick(item, index, e) !== false){
20396 this.fireEvent("click", this, index, item, e);
20399 this.clearSelections();
20404 onContextMenu : function(e){
20405 var item = this.findItemFromChild(e.getTarget());
20407 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
20412 onDblClick : function(e){
20413 var item = this.findItemFromChild(e.getTarget());
20415 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
20419 onItemClick : function(item, index, e)
20421 if(this.fireEvent("beforeclick", this, index, item, e) === false){
20424 if (this.toggleSelect) {
20425 var m = this.isSelected(item) ? 'unselect' : 'select';
20428 _t[m](item, true, false);
20431 if(this.multiSelect || this.singleSelect){
20432 if(this.multiSelect && e.shiftKey && this.lastSelection){
20433 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
20435 this.select(item, this.multiSelect && e.ctrlKey);
20436 this.lastSelection = item;
20439 if(!this.tickable){
20440 e.preventDefault();
20448 * Get the number of selected nodes.
20451 getSelectionCount : function(){
20452 return this.selections.length;
20456 * Get the currently selected nodes.
20457 * @return {Array} An array of HTMLElements
20459 getSelectedNodes : function(){
20460 return this.selections;
20464 * Get the indexes of the selected nodes.
20467 getSelectedIndexes : function(){
20468 var indexes = [], s = this.selections;
20469 for(var i = 0, len = s.length; i < len; i++){
20470 indexes.push(s[i].nodeIndex);
20476 * Clear all selections
20477 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
20479 clearSelections : function(suppressEvent){
20480 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
20481 this.cmp.elements = this.selections;
20482 this.cmp.removeClass(this.selectedClass);
20483 this.selections = [];
20484 if(!suppressEvent){
20485 this.fireEvent("selectionchange", this, this.selections);
20491 * Returns true if the passed node is selected
20492 * @param {HTMLElement/Number} node The node or node index
20493 * @return {Boolean}
20495 isSelected : function(node){
20496 var s = this.selections;
20500 node = this.getNode(node);
20501 return s.indexOf(node) !== -1;
20506 * @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
20507 * @param {Boolean} keepExisting (optional) true to keep existing selections
20508 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
20510 select : function(nodeInfo, keepExisting, suppressEvent){
20511 if(nodeInfo instanceof Array){
20513 this.clearSelections(true);
20515 for(var i = 0, len = nodeInfo.length; i < len; i++){
20516 this.select(nodeInfo[i], true, true);
20520 var node = this.getNode(nodeInfo);
20521 if(!node || this.isSelected(node)){
20522 return; // already selected.
20525 this.clearSelections(true);
20528 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
20529 Roo.fly(node).addClass(this.selectedClass);
20530 this.selections.push(node);
20531 if(!suppressEvent){
20532 this.fireEvent("selectionchange", this, this.selections);
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 IGNORED (for campatibility with select)
20542 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
20544 unselect : function(nodeInfo, keepExisting, suppressEvent)
20546 if(nodeInfo instanceof Array){
20547 Roo.each(this.selections, function(s) {
20548 this.unselect(s, nodeInfo);
20552 var node = this.getNode(nodeInfo);
20553 if(!node || !this.isSelected(node)){
20554 //Roo.log("not selected");
20555 return; // not selected.
20559 Roo.each(this.selections, function(s) {
20561 Roo.fly(node).removeClass(this.selectedClass);
20568 this.selections= ns;
20569 this.fireEvent("selectionchange", this, this.selections);
20573 * Gets a template node.
20574 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
20575 * @return {HTMLElement} The node or null if it wasn't found
20577 getNode : function(nodeInfo){
20578 if(typeof nodeInfo == "string"){
20579 return document.getElementById(nodeInfo);
20580 }else if(typeof nodeInfo == "number"){
20581 return this.nodes[nodeInfo];
20587 * Gets a range template nodes.
20588 * @param {Number} startIndex
20589 * @param {Number} endIndex
20590 * @return {Array} An array of nodes
20592 getNodes : function(start, end){
20593 var ns = this.nodes;
20594 start = start || 0;
20595 end = typeof end == "undefined" ? ns.length - 1 : end;
20598 for(var i = start; i <= end; i++){
20602 for(var i = start; i >= end; i--){
20610 * Finds the index of the passed node
20611 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
20612 * @return {Number} The index of the node or -1
20614 indexOf : function(node){
20615 node = this.getNode(node);
20616 if(typeof node.nodeIndex == "number"){
20617 return node.nodeIndex;
20619 var ns = this.nodes;
20620 for(var i = 0, len = ns.length; i < len; i++){
20631 * based on jquery fullcalendar
20635 Roo.bootstrap = Roo.bootstrap || {};
20637 * @class Roo.bootstrap.Calendar
20638 * @extends Roo.bootstrap.Component
20639 * Bootstrap Calendar class
20640 * @cfg {Boolean} loadMask (true|false) default false
20641 * @cfg {Object} header generate the user specific header of the calendar, default false
20644 * Create a new Container
20645 * @param {Object} config The config object
20650 Roo.bootstrap.Calendar = function(config){
20651 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
20655 * Fires when a date is selected
20656 * @param {DatePicker} this
20657 * @param {Date} date The selected date
20661 * @event monthchange
20662 * Fires when the displayed month changes
20663 * @param {DatePicker} this
20664 * @param {Date} date The selected month
20666 'monthchange': true,
20668 * @event evententer
20669 * Fires when mouse over an event
20670 * @param {Calendar} this
20671 * @param {event} Event
20673 'evententer': true,
20675 * @event eventleave
20676 * Fires when the mouse leaves an
20677 * @param {Calendar} this
20680 'eventleave': true,
20682 * @event eventclick
20683 * Fires when the mouse click an
20684 * @param {Calendar} this
20693 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
20696 * @cfg {Roo.data.Store} store
20697 * The data source for the calendar
20701 * @cfg {Number} startDay
20702 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
20710 getAutoCreate : function(){
20713 var fc_button = function(name, corner, style, content ) {
20714 return Roo.apply({},{
20716 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
20718 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
20721 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
20732 style : 'width:100%',
20739 cls : 'fc-header-left',
20741 fc_button('prev', 'left', 'arrow', '‹' ),
20742 fc_button('next', 'right', 'arrow', '›' ),
20743 { tag: 'span', cls: 'fc-header-space' },
20744 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
20752 cls : 'fc-header-center',
20756 cls: 'fc-header-title',
20759 html : 'month / year'
20767 cls : 'fc-header-right',
20769 /* fc_button('month', 'left', '', 'month' ),
20770 fc_button('week', '', '', 'week' ),
20771 fc_button('day', 'right', '', 'day' )
20783 header = this.header;
20786 var cal_heads = function() {
20788 // fixme - handle this.
20790 for (var i =0; i < Date.dayNames.length; i++) {
20791 var d = Date.dayNames[i];
20794 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
20795 html : d.substring(0,3)
20799 ret[0].cls += ' fc-first';
20800 ret[6].cls += ' fc-last';
20803 var cal_cell = function(n) {
20806 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
20811 cls: 'fc-day-number',
20815 cls: 'fc-day-content',
20819 style: 'position: relative;' // height: 17px;
20831 var cal_rows = function() {
20834 for (var r = 0; r < 6; r++) {
20841 for (var i =0; i < Date.dayNames.length; i++) {
20842 var d = Date.dayNames[i];
20843 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
20846 row.cn[0].cls+=' fc-first';
20847 row.cn[0].cn[0].style = 'min-height:90px';
20848 row.cn[6].cls+=' fc-last';
20852 ret[0].cls += ' fc-first';
20853 ret[4].cls += ' fc-prev-last';
20854 ret[5].cls += ' fc-last';
20861 cls: 'fc-border-separate',
20862 style : 'width:100%',
20870 cls : 'fc-first fc-last',
20888 cls : 'fc-content',
20889 style : "position: relative;",
20892 cls : 'fc-view fc-view-month fc-grid',
20893 style : 'position: relative',
20894 unselectable : 'on',
20897 cls : 'fc-event-container',
20898 style : 'position:absolute;z-index:8;top:0;left:0;'
20916 initEvents : function()
20919 throw "can not find store for calendar";
20925 style: "text-align:center",
20929 style: "background-color:white;width:50%;margin:250 auto",
20933 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
20944 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
20946 var size = this.el.select('.fc-content', true).first().getSize();
20947 this.maskEl.setSize(size.width, size.height);
20948 this.maskEl.enableDisplayMode("block");
20949 if(!this.loadMask){
20950 this.maskEl.hide();
20953 this.store = Roo.factory(this.store, Roo.data);
20954 this.store.on('load', this.onLoad, this);
20955 this.store.on('beforeload', this.onBeforeLoad, this);
20959 this.cells = this.el.select('.fc-day',true);
20960 //Roo.log(this.cells);
20961 this.textNodes = this.el.query('.fc-day-number');
20962 this.cells.addClassOnOver('fc-state-hover');
20964 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
20965 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
20966 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
20967 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
20969 this.on('monthchange', this.onMonthChange, this);
20971 this.update(new Date().clearTime());
20974 resize : function() {
20975 var sz = this.el.getSize();
20977 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
20978 this.el.select('.fc-day-content div',true).setHeight(34);
20983 showPrevMonth : function(e){
20984 this.update(this.activeDate.add("mo", -1));
20986 showToday : function(e){
20987 this.update(new Date().clearTime());
20990 showNextMonth : function(e){
20991 this.update(this.activeDate.add("mo", 1));
20995 showPrevYear : function(){
20996 this.update(this.activeDate.add("y", -1));
21000 showNextYear : function(){
21001 this.update(this.activeDate.add("y", 1));
21006 update : function(date)
21008 var vd = this.activeDate;
21009 this.activeDate = date;
21010 // if(vd && this.el){
21011 // var t = date.getTime();
21012 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
21013 // Roo.log('using add remove');
21015 // this.fireEvent('monthchange', this, date);
21017 // this.cells.removeClass("fc-state-highlight");
21018 // this.cells.each(function(c){
21019 // if(c.dateValue == t){
21020 // c.addClass("fc-state-highlight");
21021 // setTimeout(function(){
21022 // try{c.dom.firstChild.focus();}catch(e){}
21032 var days = date.getDaysInMonth();
21034 var firstOfMonth = date.getFirstDateOfMonth();
21035 var startingPos = firstOfMonth.getDay()-this.startDay;
21037 if(startingPos < this.startDay){
21041 var pm = date.add(Date.MONTH, -1);
21042 var prevStart = pm.getDaysInMonth()-startingPos;
21044 this.cells = this.el.select('.fc-day',true);
21045 this.textNodes = this.el.query('.fc-day-number');
21046 this.cells.addClassOnOver('fc-state-hover');
21048 var cells = this.cells.elements;
21049 var textEls = this.textNodes;
21051 Roo.each(cells, function(cell){
21052 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
21055 days += startingPos;
21057 // convert everything to numbers so it's fast
21058 var day = 86400000;
21059 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
21062 //Roo.log(prevStart);
21064 var today = new Date().clearTime().getTime();
21065 var sel = date.clearTime().getTime();
21066 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
21067 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
21068 var ddMatch = this.disabledDatesRE;
21069 var ddText = this.disabledDatesText;
21070 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
21071 var ddaysText = this.disabledDaysText;
21072 var format = this.format;
21074 var setCellClass = function(cal, cell){
21078 //Roo.log('set Cell Class');
21080 var t = d.getTime();
21084 cell.dateValue = t;
21086 cell.className += " fc-today";
21087 cell.className += " fc-state-highlight";
21088 cell.title = cal.todayText;
21091 // disable highlight in other month..
21092 //cell.className += " fc-state-highlight";
21097 cell.className = " fc-state-disabled";
21098 cell.title = cal.minText;
21102 cell.className = " fc-state-disabled";
21103 cell.title = cal.maxText;
21107 if(ddays.indexOf(d.getDay()) != -1){
21108 cell.title = ddaysText;
21109 cell.className = " fc-state-disabled";
21112 if(ddMatch && format){
21113 var fvalue = d.dateFormat(format);
21114 if(ddMatch.test(fvalue)){
21115 cell.title = ddText.replace("%0", fvalue);
21116 cell.className = " fc-state-disabled";
21120 if (!cell.initialClassName) {
21121 cell.initialClassName = cell.dom.className;
21124 cell.dom.className = cell.initialClassName + ' ' + cell.className;
21129 for(; i < startingPos; i++) {
21130 textEls[i].innerHTML = (++prevStart);
21131 d.setDate(d.getDate()+1);
21133 cells[i].className = "fc-past fc-other-month";
21134 setCellClass(this, cells[i]);
21139 for(; i < days; i++){
21140 intDay = i - startingPos + 1;
21141 textEls[i].innerHTML = (intDay);
21142 d.setDate(d.getDate()+1);
21144 cells[i].className = ''; // "x-date-active";
21145 setCellClass(this, cells[i]);
21149 for(; i < 42; i++) {
21150 textEls[i].innerHTML = (++extraDays);
21151 d.setDate(d.getDate()+1);
21153 cells[i].className = "fc-future fc-other-month";
21154 setCellClass(this, cells[i]);
21157 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
21159 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
21161 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
21162 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
21164 if(totalRows != 6){
21165 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
21166 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
21169 this.fireEvent('monthchange', this, date);
21173 if(!this.internalRender){
21174 var main = this.el.dom.firstChild;
21175 var w = main.offsetWidth;
21176 this.el.setWidth(w + this.el.getBorderWidth("lr"));
21177 Roo.fly(main).setWidth(w);
21178 this.internalRender = true;
21179 // opera does not respect the auto grow header center column
21180 // then, after it gets a width opera refuses to recalculate
21181 // without a second pass
21182 if(Roo.isOpera && !this.secondPass){
21183 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
21184 this.secondPass = true;
21185 this.update.defer(10, this, [date]);
21192 findCell : function(dt) {
21193 dt = dt.clearTime().getTime();
21195 this.cells.each(function(c){
21196 //Roo.log("check " +c.dateValue + '?=' + dt);
21197 if(c.dateValue == dt){
21207 findCells : function(ev) {
21208 var s = ev.start.clone().clearTime().getTime();
21210 var e= ev.end.clone().clearTime().getTime();
21213 this.cells.each(function(c){
21214 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
21216 if(c.dateValue > e){
21219 if(c.dateValue < s){
21228 // findBestRow: function(cells)
21232 // for (var i =0 ; i < cells.length;i++) {
21233 // ret = Math.max(cells[i].rows || 0,ret);
21240 addItem : function(ev)
21242 // look for vertical location slot in
21243 var cells = this.findCells(ev);
21245 // ev.row = this.findBestRow(cells);
21247 // work out the location.
21251 for(var i =0; i < cells.length; i++) {
21253 cells[i].row = cells[0].row;
21256 cells[i].row = cells[i].row + 1;
21266 if (crow.start.getY() == cells[i].getY()) {
21268 crow.end = cells[i];
21285 cells[0].events.push(ev);
21287 this.calevents.push(ev);
21290 clearEvents: function() {
21292 if(!this.calevents){
21296 Roo.each(this.cells.elements, function(c){
21302 Roo.each(this.calevents, function(e) {
21303 Roo.each(e.els, function(el) {
21304 el.un('mouseenter' ,this.onEventEnter, this);
21305 el.un('mouseleave' ,this.onEventLeave, this);
21310 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
21316 renderEvents: function()
21320 this.cells.each(function(c) {
21329 if(c.row != c.events.length){
21330 r = 4 - (4 - (c.row - c.events.length));
21333 c.events = ev.slice(0, r);
21334 c.more = ev.slice(r);
21336 if(c.more.length && c.more.length == 1){
21337 c.events.push(c.more.pop());
21340 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
21344 this.cells.each(function(c) {
21346 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
21349 for (var e = 0; e < c.events.length; e++){
21350 var ev = c.events[e];
21351 var rows = ev.rows;
21353 for(var i = 0; i < rows.length; i++) {
21355 // how many rows should it span..
21358 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
21359 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
21361 unselectable : "on",
21364 cls: 'fc-event-inner',
21368 // cls: 'fc-event-time',
21369 // html : cells.length > 1 ? '' : ev.time
21373 cls: 'fc-event-title',
21374 html : String.format('{0}', ev.title)
21381 cls: 'ui-resizable-handle ui-resizable-e',
21382 html : '  '
21389 cfg.cls += ' fc-event-start';
21391 if ((i+1) == rows.length) {
21392 cfg.cls += ' fc-event-end';
21395 var ctr = _this.el.select('.fc-event-container',true).first();
21396 var cg = ctr.createChild(cfg);
21398 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
21399 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
21401 var r = (c.more.length) ? 1 : 0;
21402 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
21403 cg.setWidth(ebox.right - sbox.x -2);
21405 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
21406 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
21407 cg.on('click', _this.onEventClick, _this, ev);
21418 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
21419 style : 'position: absolute',
21420 unselectable : "on",
21423 cls: 'fc-event-inner',
21427 cls: 'fc-event-title',
21435 cls: 'ui-resizable-handle ui-resizable-e',
21436 html : '  '
21442 var ctr = _this.el.select('.fc-event-container',true).first();
21443 var cg = ctr.createChild(cfg);
21445 var sbox = c.select('.fc-day-content',true).first().getBox();
21446 var ebox = c.select('.fc-day-content',true).first().getBox();
21448 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
21449 cg.setWidth(ebox.right - sbox.x -2);
21451 cg.on('click', _this.onMoreEventClick, _this, c.more);
21461 onEventEnter: function (e, el,event,d) {
21462 this.fireEvent('evententer', this, el, event);
21465 onEventLeave: function (e, el,event,d) {
21466 this.fireEvent('eventleave', this, el, event);
21469 onEventClick: function (e, el,event,d) {
21470 this.fireEvent('eventclick', this, el, event);
21473 onMonthChange: function () {
21477 onMoreEventClick: function(e, el, more)
21481 this.calpopover.placement = 'right';
21482 this.calpopover.setTitle('More');
21484 this.calpopover.setContent('');
21486 var ctr = this.calpopover.el.select('.popover-content', true).first();
21488 Roo.each(more, function(m){
21490 cls : 'fc-event-hori fc-event-draggable',
21493 var cg = ctr.createChild(cfg);
21495 cg.on('click', _this.onEventClick, _this, m);
21498 this.calpopover.show(el);
21503 onLoad: function ()
21505 this.calevents = [];
21508 if(this.store.getCount() > 0){
21509 this.store.data.each(function(d){
21512 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
21513 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
21514 time : d.data.start_time,
21515 title : d.data.title,
21516 description : d.data.description,
21517 venue : d.data.venue
21522 this.renderEvents();
21524 if(this.calevents.length && this.loadMask){
21525 this.maskEl.hide();
21529 onBeforeLoad: function()
21531 this.clearEvents();
21533 this.maskEl.show();
21547 * @class Roo.bootstrap.Popover
21548 * @extends Roo.bootstrap.Component
21549 * @parent none builder
21550 * @children Roo.bootstrap.Component
21551 * Bootstrap Popover class
21552 * @cfg {String} html contents of the popover (or false to use children..)
21553 * @cfg {String} title of popover (or false to hide)
21554 * @cfg {String|function} (right|top|bottom|left|auto) placement how it is placed
21555 * @cfg {String} trigger click || hover (or false to trigger manually)
21556 * @cfg {Boolean} modal - popovers that are modal will mask the screen, and must be closed with another event.
21557 * @cfg {String|Boolean|Roo.Element} add click hander to trigger show over what element
21558 * - if false and it has a 'parent' then it will be automatically added to that element
21559 * - if string - Roo.get will be called
21560 * @cfg {Number} delay - delay before showing
21563 * Create a new Popover
21564 * @param {Object} config The config object
21567 Roo.bootstrap.Popover = function(config){
21568 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
21574 * After the popover show
21576 * @param {Roo.bootstrap.Popover} this
21581 * After the popover hide
21583 * @param {Roo.bootstrap.Popover} this
21589 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
21594 placement : 'right',
21595 trigger : 'hover', // hover
21601 can_build_overlaid : false,
21603 maskEl : false, // the mask element
21606 alignEl : false, // when show is called with an element - this get's stored.
21608 getChildContainer : function()
21610 return this.contentEl;
21613 getPopoverHeader : function()
21615 this.title = true; // flag not to hide it..
21616 this.headerEl.addClass('p-0');
21617 return this.headerEl
21621 getAutoCreate : function(){
21624 cls : 'popover roo-dynamic shadow roo-popover' + (this.modal ? '-modal' : ''),
21625 style: 'display:block',
21631 cls : 'popover-inner ',
21635 cls: 'popover-title popover-header',
21636 html : this.title === false ? '' : this.title
21639 cls : 'popover-content popover-body ' + (this.cls || ''),
21640 html : this.html || ''
21651 * @param {string} the title
21653 setTitle: function(str)
21657 this.headerEl.dom.innerHTML = str;
21662 * @param {string} the body content
21664 setContent: function(str)
21667 if (this.contentEl) {
21668 this.contentEl.dom.innerHTML = str;
21672 // as it get's added to the bottom of the page.
21673 onRender : function(ct, position)
21675 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
21680 var cfg = Roo.apply({}, this.getAutoCreate());
21684 cfg.cls += ' ' + this.cls;
21687 cfg.style = this.style;
21689 //Roo.log("adding to ");
21690 this.el = Roo.get(document.body).createChild(cfg, position);
21691 // Roo.log(this.el);
21694 this.contentEl = this.el.select('.popover-content',true).first();
21695 this.headerEl = this.el.select('.popover-title',true).first();
21698 if(typeof(this.items) != 'undefined'){
21699 var items = this.items;
21702 for(var i =0;i < items.length;i++) {
21703 nitems.push(this.addxtype(Roo.apply({}, items[i])));
21707 this.items = nitems;
21709 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
21710 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
21717 resizeMask : function()
21719 this.maskEl.setSize(
21720 Roo.lib.Dom.getViewWidth(true),
21721 Roo.lib.Dom.getViewHeight(true)
21725 initEvents : function()
21729 Roo.bootstrap.Popover.register(this);
21732 this.arrowEl = this.el.select('.arrow',true).first();
21733 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY); // probably not needed as it's default in BS4
21734 this.el.enableDisplayMode('block');
21738 if (this.over === false && !this.parent()) {
21741 if (this.triggers === false) {
21746 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
21747 var triggers = this.trigger ? this.trigger.split(' ') : [];
21748 Roo.each(triggers, function(trigger) {
21750 if (trigger == 'click') {
21751 on_el.on('click', this.toggle, this);
21752 } else if (trigger != 'manual') {
21753 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
21754 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
21756 on_el.on(eventIn ,this.enter, this);
21757 on_el.on(eventOut, this.leave, this);
21767 toggle : function () {
21768 this.hoverState == 'in' ? this.leave() : this.enter();
21771 enter : function () {
21773 clearTimeout(this.timeout);
21775 this.hoverState = 'in';
21777 if (!this.delay || !this.delay.show) {
21782 this.timeout = setTimeout(function () {
21783 if (_t.hoverState == 'in') {
21786 }, this.delay.show)
21789 leave : function() {
21790 clearTimeout(this.timeout);
21792 this.hoverState = 'out';
21794 if (!this.delay || !this.delay.hide) {
21799 this.timeout = setTimeout(function () {
21800 if (_t.hoverState == 'out') {
21803 }, this.delay.hide)
21807 * update the position of the dialog
21808 * normally this is needed if the popover get's bigger - due to a Table reload etc..
21813 doAlign : function()
21816 if (this.alignEl) {
21817 this.updatePosition(this.placement, true);
21820 // this is usually just done by the builder = to show the popoup in the middle of the scren.
21821 var es = this.el.getSize();
21822 var x = Roo.lib.Dom.getViewWidth()/2;
21823 var y = Roo.lib.Dom.getViewHeight()/2;
21824 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
21836 * @param {Roo.Element|string|Boolean} - element to align and point to. (set align to [ pos, offset ])
21837 * @param {string} (left|right|top|bottom) position
21839 show : function (on_el, placement)
21841 this.placement = typeof(placement) == 'undefined' ? this.placement : placement;
21842 on_el = on_el || false; // default to false
21845 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
21846 on_el = this.parent().el;
21847 } else if (this.over) {
21848 on_el = Roo.get(this.over);
21853 this.alignEl = Roo.get( on_el );
21856 this.render(document.body);
21862 if (this.title === false) {
21863 this.headerEl.hide();
21868 this.el.dom.style.display = 'block';
21872 //var arrow = this.el.select('.arrow',true).first();
21873 //arrow.set(align[2],
21875 this.el.addClass('in');
21879 this.hoverState = 'in';
21882 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
21883 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
21884 this.maskEl.dom.style.display = 'block';
21885 this.maskEl.addClass('show');
21887 this.el.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
21889 this.fireEvent('show', this);
21893 * fire this manually after loading a grid in the table for example
21894 * @param {string} (left|right|top|bottom) where to try and put it (use false to use the last one)
21895 * @param {Boolean} try and move it if we cant get right position.
21897 updatePosition : function(placement, try_move)
21899 // allow for calling with no parameters
21900 placement = placement ? placement : this.placement;
21901 try_move = typeof(try_move) == 'undefined' ? true : try_move;
21903 this.el.removeClass([
21904 'fade','top','bottom', 'left', 'right','in',
21905 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
21907 this.el.addClass(placement + ' bs-popover-' + placement);
21909 if (!this.alignEl ) {
21913 switch (placement) {
21915 var exact = this.el.getAlignToXY(this.alignEl, 'tl-tr', [10,0]);
21916 var offset = this.el.getAlignToXY(this.alignEl, 'tl-tr?',[10,0]);
21917 if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
21918 //normal display... or moved up/down.
21919 this.el.setXY(offset);
21920 var xy = this.alignEl.getAnchorXY('tr', false);
21922 this.arrowEl.setXY(xy);
21925 // continue through...
21926 return this.updatePosition('left', false);
21930 var exact = this.el.getAlignToXY(this.alignEl, 'tr-tl', [-10,0]);
21931 var offset = this.el.getAlignToXY(this.alignEl, 'tr-tl?',[-10,0]);
21932 if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
21933 //normal display... or moved up/down.
21934 this.el.setXY(offset);
21935 var xy = this.alignEl.getAnchorXY('tl', false);
21936 xy[0]-=10;xy[1]+=5; // << fix me
21937 this.arrowEl.setXY(xy);
21941 return this.updatePosition('right', false);
21944 var exact = this.el.getAlignToXY(this.alignEl, 'b-t', [0,-10]);
21945 var offset = this.el.getAlignToXY(this.alignEl, 'b-t?',[0,-10]);
21946 if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
21947 //normal display... or moved up/down.
21948 this.el.setXY(offset);
21949 var xy = this.alignEl.getAnchorXY('t', false);
21950 xy[1]-=10; // << fix me
21951 this.arrowEl.setXY(xy);
21955 return this.updatePosition('bottom', false);
21958 var exact = this.el.getAlignToXY(this.alignEl, 't-b', [0,10]);
21959 var offset = this.el.getAlignToXY(this.alignEl, 't-b?',[0,10]);
21960 if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
21961 //normal display... or moved up/down.
21962 this.el.setXY(offset);
21963 var xy = this.alignEl.getAnchorXY('b', false);
21964 xy[1]+=2; // << fix me
21965 this.arrowEl.setXY(xy);
21969 return this.updatePosition('top', false);
21980 this.el.setXY([0,0]);
21981 this.el.removeClass('in');
21983 this.hoverState = null;
21984 this.maskEl.hide(); // always..
21985 this.fireEvent('hide', this);
21991 Roo.apply(Roo.bootstrap.Popover, {
21994 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
21995 'right' : ['l-br', [10,0], 'right bs-popover-right'],
21996 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
21997 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
22002 clickHander : false,
22006 onMouseDown : function(e)
22008 if (this.popups.length && !e.getTarget(".roo-popover")) {
22009 /// what is nothing is showing..
22018 register : function(popup)
22020 if (!Roo.bootstrap.Popover.clickHandler) {
22021 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
22023 // hide other popups.
22024 popup.on('show', Roo.bootstrap.Popover.onShow, popup);
22025 popup.on('hide', Roo.bootstrap.Popover.onHide, popup);
22026 this.hideAll(); //<< why?
22027 //this.popups.push(popup);
22029 hideAll : function()
22031 this.popups.forEach(function(p) {
22035 onShow : function() {
22036 Roo.bootstrap.Popover.popups.push(this);
22038 onHide : function() {
22039 Roo.bootstrap.Popover.popups.remove(this);
22044 * @class Roo.bootstrap.PopoverNav
22045 * @extends Roo.bootstrap.nav.Simplebar
22046 * @parent Roo.bootstrap.Popover
22047 * @children Roo.bootstrap.nav.Group Roo.bootstrap.Container
22049 * Bootstrap Popover header navigation class
22050 * FIXME? should this go under nav?
22054 * Create a new Popover Header Navigation
22055 * @param {Object} config The config object
22058 Roo.bootstrap.PopoverNav = function(config){
22059 Roo.bootstrap.PopoverNav.superclass.constructor.call(this, config);
22062 Roo.extend(Roo.bootstrap.PopoverNav, Roo.bootstrap.nav.Simplebar, {
22065 container_method : 'getPopoverHeader'
22083 * @class Roo.bootstrap.Progress
22084 * @extends Roo.bootstrap.Component
22085 * @children Roo.bootstrap.ProgressBar
22086 * Bootstrap Progress class
22087 * @cfg {Boolean} striped striped of the progress bar
22088 * @cfg {Boolean} active animated of the progress bar
22092 * Create a new Progress
22093 * @param {Object} config The config object
22096 Roo.bootstrap.Progress = function(config){
22097 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
22100 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
22105 getAutoCreate : function(){
22113 cfg.cls += ' progress-striped';
22117 cfg.cls += ' active';
22136 * @class Roo.bootstrap.ProgressBar
22137 * @extends Roo.bootstrap.Component
22138 * Bootstrap ProgressBar class
22139 * @cfg {Number} aria_valuenow aria-value now
22140 * @cfg {Number} aria_valuemin aria-value min
22141 * @cfg {Number} aria_valuemax aria-value max
22142 * @cfg {String} label label for the progress bar
22143 * @cfg {String} panel (success | info | warning | danger )
22144 * @cfg {String} role role of the progress bar
22145 * @cfg {String} sr_only text
22149 * Create a new ProgressBar
22150 * @param {Object} config The config object
22153 Roo.bootstrap.ProgressBar = function(config){
22154 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
22157 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
22161 aria_valuemax : 100,
22167 getAutoCreate : function()
22172 cls: 'progress-bar',
22173 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
22185 cfg.role = this.role;
22188 if(this.aria_valuenow){
22189 cfg['aria-valuenow'] = this.aria_valuenow;
22192 if(this.aria_valuemin){
22193 cfg['aria-valuemin'] = this.aria_valuemin;
22196 if(this.aria_valuemax){
22197 cfg['aria-valuemax'] = this.aria_valuemax;
22200 if(this.label && !this.sr_only){
22201 cfg.html = this.label;
22205 cfg.cls += ' progress-bar-' + this.panel;
22211 update : function(aria_valuenow)
22213 this.aria_valuenow = aria_valuenow;
22215 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
22223 * @class Roo.bootstrap.TabGroup
22224 * @extends Roo.bootstrap.Column
22225 * @children Roo.bootstrap.TabPanel
22226 * Bootstrap Column class
22227 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
22228 * @cfg {Boolean} carousel true to make the group behave like a carousel
22229 * @cfg {Boolean} bullets show bullets for the panels
22230 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
22231 * @cfg {Number} timer auto slide timer .. default 0 millisecond
22232 * @cfg {Boolean} showarrow (true|false) show arrow default true
22235 * Create a new TabGroup
22236 * @param {Object} config The config object
22239 Roo.bootstrap.TabGroup = function(config){
22240 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
22242 this.navId = Roo.id();
22245 Roo.bootstrap.TabGroup.register(this);
22249 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
22252 transition : false,
22257 slideOnTouch : false,
22260 getAutoCreate : function()
22262 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
22264 cfg.cls += ' tab-content';
22266 if (this.carousel) {
22267 cfg.cls += ' carousel slide';
22270 cls : 'carousel-inner',
22274 if(this.bullets && !Roo.isTouch){
22277 cls : 'carousel-bullets',
22281 if(this.bullets_cls){
22282 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
22289 cfg.cn[0].cn.push(bullets);
22292 if(this.showarrow){
22293 cfg.cn[0].cn.push({
22295 class : 'carousel-arrow',
22299 class : 'carousel-prev',
22303 class : 'fa fa-chevron-left'
22309 class : 'carousel-next',
22313 class : 'fa fa-chevron-right'
22326 initEvents: function()
22328 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
22329 // this.el.on("touchstart", this.onTouchStart, this);
22332 if(this.autoslide){
22335 this.slideFn = window.setInterval(function() {
22336 _this.showPanelNext();
22340 if(this.showarrow){
22341 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
22342 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
22348 // onTouchStart : function(e, el, o)
22350 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
22354 // this.showPanelNext();
22358 getChildContainer : function()
22360 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
22364 * register a Navigation item
22365 * @param {Roo.bootstrap.nav.Item} the navitem to add
22367 register : function(item)
22369 this.tabs.push( item);
22370 item.navId = this.navId; // not really needed..
22375 getActivePanel : function()
22378 Roo.each(this.tabs, function(t) {
22388 getPanelByName : function(n)
22391 Roo.each(this.tabs, function(t) {
22392 if (t.tabId == n) {
22400 indexOfPanel : function(p)
22403 Roo.each(this.tabs, function(t,i) {
22404 if (t.tabId == p.tabId) {
22413 * show a specific panel
22414 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
22415 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
22417 showPanel : function (pan)
22419 if(this.transition || typeof(pan) == 'undefined'){
22420 Roo.log("waiting for the transitionend");
22424 if (typeof(pan) == 'number') {
22425 pan = this.tabs[pan];
22428 if (typeof(pan) == 'string') {
22429 pan = this.getPanelByName(pan);
22432 var cur = this.getActivePanel();
22435 Roo.log('pan or acitve pan is undefined');
22439 if (pan.tabId == this.getActivePanel().tabId) {
22443 if (false === cur.fireEvent('beforedeactivate')) {
22447 if(this.bullets > 0 && !Roo.isTouch){
22448 this.setActiveBullet(this.indexOfPanel(pan));
22451 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
22453 //class="carousel-item carousel-item-next carousel-item-left"
22455 this.transition = true;
22456 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
22457 var lr = dir == 'next' ? 'left' : 'right';
22458 pan.el.addClass(dir); // or prev
22459 pan.el.addClass('carousel-item-' + dir); // or prev
22460 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
22461 cur.el.addClass(lr); // or right
22462 pan.el.addClass(lr);
22463 cur.el.addClass('carousel-item-' +lr); // or right
22464 pan.el.addClass('carousel-item-' +lr);
22468 cur.el.on('transitionend', function() {
22469 Roo.log("trans end?");
22471 pan.el.removeClass([lr,dir, 'carousel-item-' + lr, 'carousel-item-' + dir]);
22472 pan.setActive(true);
22474 cur.el.removeClass([lr, 'carousel-item-' + lr]);
22475 cur.setActive(false);
22477 _this.transition = false;
22479 }, this, { single: true } );
22484 cur.setActive(false);
22485 pan.setActive(true);
22490 showPanelNext : function()
22492 var i = this.indexOfPanel(this.getActivePanel());
22494 if (i >= this.tabs.length - 1 && !this.autoslide) {
22498 if (i >= this.tabs.length - 1 && this.autoslide) {
22502 this.showPanel(this.tabs[i+1]);
22505 showPanelPrev : function()
22507 var i = this.indexOfPanel(this.getActivePanel());
22509 if (i < 1 && !this.autoslide) {
22513 if (i < 1 && this.autoslide) {
22514 i = this.tabs.length;
22517 this.showPanel(this.tabs[i-1]);
22521 addBullet: function()
22523 if(!this.bullets || Roo.isTouch){
22526 var ctr = this.el.select('.carousel-bullets',true).first();
22527 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
22528 var bullet = ctr.createChild({
22529 cls : 'bullet bullet-' + i
22530 },ctr.dom.lastChild);
22535 bullet.on('click', (function(e, el, o, ii, t){
22537 e.preventDefault();
22539 this.showPanel(ii);
22541 if(this.autoslide && this.slideFn){
22542 clearInterval(this.slideFn);
22543 this.slideFn = window.setInterval(function() {
22544 _this.showPanelNext();
22548 }).createDelegate(this, [i, bullet], true));
22553 setActiveBullet : function(i)
22559 Roo.each(this.el.select('.bullet', true).elements, function(el){
22560 el.removeClass('selected');
22563 var bullet = this.el.select('.bullet-' + i, true).first();
22569 bullet.addClass('selected');
22580 Roo.apply(Roo.bootstrap.TabGroup, {
22584 * register a Navigation Group
22585 * @param {Roo.bootstrap.nav.Group} the navgroup to add
22587 register : function(navgrp)
22589 this.groups[navgrp.navId] = navgrp;
22593 * fetch a Navigation Group based on the navigation ID
22594 * if one does not exist , it will get created.
22595 * @param {string} the navgroup to add
22596 * @returns {Roo.bootstrap.nav.Group} the navgroup
22598 get: function(navId) {
22599 if (typeof(this.groups[navId]) == 'undefined') {
22600 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
22602 return this.groups[navId] ;
22617 * @class Roo.bootstrap.TabPanel
22618 * @extends Roo.bootstrap.Component
22619 * @children Roo.bootstrap.Component
22620 * Bootstrap TabPanel class
22621 * @cfg {Boolean} active panel active
22622 * @cfg {String} html panel content
22623 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
22624 * @cfg {String} navId The Roo.bootstrap.nav.Group which triggers show hide ()
22625 * @cfg {String} href click to link..
22626 * @cfg {Boolean} touchSlide if swiping slides tab to next panel (default off)
22630 * Create a new TabPanel
22631 * @param {Object} config The config object
22634 Roo.bootstrap.TabPanel = function(config){
22635 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
22639 * Fires when the active status changes
22640 * @param {Roo.bootstrap.TabPanel} this
22641 * @param {Boolean} state the new state
22646 * @event beforedeactivate
22647 * Fires before a tab is de-activated - can be used to do validation on a form.
22648 * @param {Roo.bootstrap.TabPanel} this
22649 * @return {Boolean} false if there is an error
22652 'beforedeactivate': true
22655 this.tabId = this.tabId || Roo.id();
22659 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
22666 touchSlide : false,
22667 getAutoCreate : function(){
22672 // item is needed for carousel - not sure if it has any effect otherwise
22673 cls: 'carousel-item tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
22674 html: this.html || ''
22678 cfg.cls += ' active';
22682 cfg.tabId = this.tabId;
22690 initEvents: function()
22692 var p = this.parent();
22694 this.navId = this.navId || p.navId;
22696 if (typeof(this.navId) != 'undefined') {
22697 // not really needed.. but just in case.. parent should be a NavGroup.
22698 var tg = Roo.bootstrap.TabGroup.get(this.navId);
22702 var i = tg.tabs.length - 1;
22704 if(this.active && tg.bullets > 0 && i < tg.bullets){
22705 tg.setActiveBullet(i);
22709 this.el.on('click', this.onClick, this);
22711 if(Roo.isTouch && this.touchSlide){
22712 this.el.on("touchstart", this.onTouchStart, this);
22713 this.el.on("touchmove", this.onTouchMove, this);
22714 this.el.on("touchend", this.onTouchEnd, this);
22719 onRender : function(ct, position)
22721 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
22724 setActive : function(state)
22726 Roo.log("panel - set active " + this.tabId + "=" + state);
22728 this.active = state;
22730 this.el.removeClass('active');
22732 } else if (!this.el.hasClass('active')) {
22733 this.el.addClass('active');
22736 this.fireEvent('changed', this, state);
22739 onClick : function(e)
22741 e.preventDefault();
22743 if(!this.href.length){
22747 window.location.href = this.href;
22756 onTouchStart : function(e)
22758 this.swiping = false;
22760 this.startX = e.browserEvent.touches[0].clientX;
22761 this.startY = e.browserEvent.touches[0].clientY;
22764 onTouchMove : function(e)
22766 this.swiping = true;
22768 this.endX = e.browserEvent.touches[0].clientX;
22769 this.endY = e.browserEvent.touches[0].clientY;
22772 onTouchEnd : function(e)
22779 var tabGroup = this.parent();
22781 if(this.endX > this.startX){ // swiping right
22782 tabGroup.showPanelPrev();
22786 if(this.startX > this.endX){ // swiping left
22787 tabGroup.showPanelNext();
22806 * @class Roo.bootstrap.form.DateField
22807 * @extends Roo.bootstrap.form.Input
22808 * Bootstrap DateField class
22809 * @cfg {Number} weekStart default 0
22810 * @cfg {String} viewMode default empty, (months|years)
22811 * @cfg {String} minViewMode default empty, (months|years)
22812 * @cfg {Number} startDate default -Infinity
22813 * @cfg {Number} endDate default Infinity
22814 * @cfg {Boolean} todayHighlight default false
22815 * @cfg {Boolean} todayBtn default false
22816 * @cfg {Boolean} calendarWeeks default false
22817 * @cfg {Object} daysOfWeekDisabled default empty
22818 * @cfg {Boolean} singleMode default false (true | false)
22820 * @cfg {Boolean} keyboardNavigation default true
22821 * @cfg {String} language default en
22824 * Create a new DateField
22825 * @param {Object} config The config object
22828 Roo.bootstrap.form.DateField = function(config){
22829 Roo.bootstrap.form.DateField.superclass.constructor.call(this, config);
22833 * Fires when this field show.
22834 * @param {Roo.bootstrap.form.DateField} this
22835 * @param {Mixed} date The date value
22840 * Fires when this field hide.
22841 * @param {Roo.bootstrap.form.DateField} this
22842 * @param {Mixed} date The date value
22847 * Fires when select a date.
22848 * @param {Roo.bootstrap.form.DateField} this
22849 * @param {Mixed} date The date value
22853 * @event beforeselect
22854 * Fires when before select a date.
22855 * @param {Roo.bootstrap.form.DateField} this
22856 * @param {Mixed} date The date value
22858 beforeselect : true
22862 Roo.extend(Roo.bootstrap.form.DateField, Roo.bootstrap.form.Input, {
22865 * @cfg {String} format
22866 * The default date format string which can be overriden for localization support. The format must be
22867 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
22871 * @cfg {String} altFormats
22872 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
22873 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
22875 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
22883 todayHighlight : false,
22889 keyboardNavigation: true,
22891 calendarWeeks: false,
22893 startDate: -Infinity,
22897 daysOfWeekDisabled: [],
22901 singleMode : false,
22903 UTCDate: function()
22905 return new Date(Date.UTC.apply(Date, arguments));
22908 UTCToday: function()
22910 var today = new Date();
22911 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
22914 getDate: function() {
22915 var d = this.getUTCDate();
22916 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
22919 getUTCDate: function() {
22923 setDate: function(d) {
22924 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
22927 setUTCDate: function(d) {
22929 this.setValue(this.formatDate(this.date));
22932 onRender: function(ct, position)
22935 Roo.bootstrap.form.DateField.superclass.onRender.call(this, ct, position);
22937 this.language = this.language || 'en';
22938 this.language = this.language in Roo.bootstrap.form.DateField.dates ? this.language : this.language.split('-')[0];
22939 this.language = this.language in Roo.bootstrap.form.DateField.dates ? this.language : "en";
22941 this.isRTL = Roo.bootstrap.form.DateField.dates[this.language].rtl || false;
22942 this.format = this.format || 'm/d/y';
22943 this.isInline = false;
22944 this.isInput = true;
22945 this.component = this.el.select('.add-on', true).first() || false;
22946 this.component = (this.component && this.component.length === 0) ? false : this.component;
22947 this.hasInput = this.component && this.inputEl().length;
22949 if (typeof(this.minViewMode === 'string')) {
22950 switch (this.minViewMode) {
22952 this.minViewMode = 1;
22955 this.minViewMode = 2;
22958 this.minViewMode = 0;
22963 if (typeof(this.viewMode === 'string')) {
22964 switch (this.viewMode) {
22977 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.DateField.template);
22979 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.form.DateField.template);
22981 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
22983 this.picker().on('mousedown', this.onMousedown, this);
22984 this.picker().on('click', this.onClick, this);
22986 this.picker().addClass('datepicker-dropdown');
22988 this.startViewMode = this.viewMode;
22990 if(this.singleMode){
22991 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
22992 v.setVisibilityMode(Roo.Element.DISPLAY);
22996 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
22997 v.setStyle('width', '189px');
23001 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
23002 if(!this.calendarWeeks){
23007 v.dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].today;
23008 v.attr('colspan', function(i, val){
23009 return parseInt(val) + 1;
23014 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
23016 this.setStartDate(this.startDate);
23017 this.setEndDate(this.endDate);
23019 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
23026 if(this.isInline) {
23031 picker : function()
23033 return this.pickerEl;
23034 // return this.el.select('.datepicker', true).first();
23037 fillDow: function()
23039 var dowCnt = this.weekStart;
23048 if(this.calendarWeeks){
23056 while (dowCnt < this.weekStart + 7) {
23060 html: Roo.bootstrap.form.DateField.dates[this.language].daysMin[(dowCnt++)%7]
23064 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
23067 fillMonths: function()
23070 var months = this.picker().select('>.datepicker-months td', true).first();
23072 months.dom.innerHTML = '';
23078 html: Roo.bootstrap.form.DateField.dates[this.language].monthsShort[i++]
23081 months.createChild(month);
23088 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;
23090 if (this.date < this.startDate) {
23091 this.viewDate = new Date(this.startDate);
23092 } else if (this.date > this.endDate) {
23093 this.viewDate = new Date(this.endDate);
23095 this.viewDate = new Date(this.date);
23103 var d = new Date(this.viewDate),
23104 year = d.getUTCFullYear(),
23105 month = d.getUTCMonth(),
23106 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
23107 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
23108 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
23109 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
23110 currentDate = this.date && this.date.valueOf(),
23111 today = this.UTCToday();
23113 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].months[month]+' '+year;
23115 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.form.DateField.dates[this.language].today;
23117 // this.picker.select('>tfoot th.today').
23118 // .text(dates[this.language].today)
23119 // .toggle(this.todayBtn !== false);
23121 this.updateNavArrows();
23124 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
23126 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
23128 prevMonth.setUTCDate(day);
23130 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
23132 var nextMonth = new Date(prevMonth);
23134 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
23136 nextMonth = nextMonth.valueOf();
23138 var fillMonths = false;
23140 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
23142 while(prevMonth.valueOf() <= nextMonth) {
23145 if (prevMonth.getUTCDay() === this.weekStart) {
23147 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
23155 if(this.calendarWeeks){
23156 // ISO 8601: First week contains first thursday.
23157 // ISO also states week starts on Monday, but we can be more abstract here.
23159 // Start of current week: based on weekstart/current date
23160 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
23161 // Thursday of this week
23162 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
23163 // First Thursday of year, year from thursday
23164 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
23165 // Calendar week: ms between thursdays, div ms per day, div 7 days
23166 calWeek = (th - yth) / 864e5 / 7 + 1;
23168 fillMonths.cn.push({
23176 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
23178 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
23181 if (this.todayHighlight &&
23182 prevMonth.getUTCFullYear() == today.getFullYear() &&
23183 prevMonth.getUTCMonth() == today.getMonth() &&
23184 prevMonth.getUTCDate() == today.getDate()) {
23185 clsName += ' today';
23188 if (currentDate && prevMonth.valueOf() === currentDate) {
23189 clsName += ' active';
23192 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
23193 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
23194 clsName += ' disabled';
23197 fillMonths.cn.push({
23199 cls: 'day ' + clsName,
23200 html: prevMonth.getDate()
23203 prevMonth.setDate(prevMonth.getDate()+1);
23206 var currentYear = this.date && this.date.getUTCFullYear();
23207 var currentMonth = this.date && this.date.getUTCMonth();
23209 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
23211 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
23212 v.removeClass('active');
23214 if(currentYear === year && k === currentMonth){
23215 v.addClass('active');
23218 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
23219 v.addClass('disabled');
23225 year = parseInt(year/10, 10) * 10;
23227 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
23229 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
23232 for (var i = -1; i < 11; i++) {
23233 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
23235 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
23243 showMode: function(dir)
23246 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
23249 Roo.each(this.picker().select('>div',true).elements, function(v){
23250 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
23253 this.picker().select('>.datepicker-'+Roo.bootstrap.form.DateField.modes[this.viewMode].clsName, true).first().show();
23258 if(this.isInline) {
23262 this.picker().removeClass(['bottom', 'top']);
23264 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
23266 * place to the top of element!
23270 this.picker().addClass('top');
23271 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
23276 this.picker().addClass('bottom');
23278 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
23281 parseDate : function(value)
23283 if(!value || value instanceof Date){
23286 var v = Date.parseDate(value, this.format);
23287 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
23288 v = Date.parseDate(value, 'Y-m-d');
23290 if(!v && this.altFormats){
23291 if(!this.altFormatsArray){
23292 this.altFormatsArray = this.altFormats.split("|");
23294 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
23295 v = Date.parseDate(value, this.altFormatsArray[i]);
23301 formatDate : function(date, fmt)
23303 return (!date || !(date instanceof Date)) ?
23304 date : date.dateFormat(fmt || this.format);
23307 onFocus : function()
23309 Roo.bootstrap.form.DateField.superclass.onFocus.call(this);
23313 onBlur : function()
23315 Roo.bootstrap.form.DateField.superclass.onBlur.call(this);
23317 var d = this.inputEl().getValue();
23324 showPopup : function()
23326 this.picker().show();
23330 this.fireEvent('showpopup', this, this.date);
23333 hidePopup : function()
23335 if(this.isInline) {
23338 this.picker().hide();
23339 this.viewMode = this.startViewMode;
23342 this.fireEvent('hidepopup', this, this.date);
23346 onMousedown: function(e)
23348 e.stopPropagation();
23349 e.preventDefault();
23354 Roo.bootstrap.form.DateField.superclass.keyup.call(this);
23358 setValue: function(v)
23360 if(this.fireEvent('beforeselect', this, v) !== false){
23361 var d = new Date(this.parseDate(v) ).clearTime();
23363 if(isNaN(d.getTime())){
23364 this.date = this.viewDate = '';
23365 Roo.bootstrap.form.DateField.superclass.setValue.call(this, '');
23369 v = this.formatDate(d);
23371 Roo.bootstrap.form.DateField.superclass.setValue.call(this, v);
23373 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
23377 this.fireEvent('select', this, this.date);
23381 getValue: function()
23383 return this.formatDate(this.date);
23386 fireKey: function(e)
23388 if (!this.picker().isVisible()){
23389 if (e.keyCode == 27) { // allow escape to hide and re-show picker
23395 var dateChanged = false,
23397 newDate, newViewDate;
23402 e.preventDefault();
23406 if (!this.keyboardNavigation) {
23409 dir = e.keyCode == 37 ? -1 : 1;
23412 newDate = this.moveYear(this.date, dir);
23413 newViewDate = this.moveYear(this.viewDate, dir);
23414 } else if (e.shiftKey){
23415 newDate = this.moveMonth(this.date, dir);
23416 newViewDate = this.moveMonth(this.viewDate, dir);
23418 newDate = new Date(this.date);
23419 newDate.setUTCDate(this.date.getUTCDate() + dir);
23420 newViewDate = new Date(this.viewDate);
23421 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
23423 if (this.dateWithinRange(newDate)){
23424 this.date = newDate;
23425 this.viewDate = newViewDate;
23426 this.setValue(this.formatDate(this.date));
23428 e.preventDefault();
23429 dateChanged = true;
23434 if (!this.keyboardNavigation) {
23437 dir = e.keyCode == 38 ? -1 : 1;
23439 newDate = this.moveYear(this.date, dir);
23440 newViewDate = this.moveYear(this.viewDate, dir);
23441 } else if (e.shiftKey){
23442 newDate = this.moveMonth(this.date, dir);
23443 newViewDate = this.moveMonth(this.viewDate, dir);
23445 newDate = new Date(this.date);
23446 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
23447 newViewDate = new Date(this.viewDate);
23448 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
23450 if (this.dateWithinRange(newDate)){
23451 this.date = newDate;
23452 this.viewDate = newViewDate;
23453 this.setValue(this.formatDate(this.date));
23455 e.preventDefault();
23456 dateChanged = true;
23460 this.setValue(this.formatDate(this.date));
23462 e.preventDefault();
23465 this.setValue(this.formatDate(this.date));
23479 onClick: function(e)
23481 e.stopPropagation();
23482 e.preventDefault();
23484 var target = e.getTarget();
23486 if(target.nodeName.toLowerCase() === 'i'){
23487 target = Roo.get(target).dom.parentNode;
23490 var nodeName = target.nodeName;
23491 var className = target.className;
23492 var html = target.innerHTML;
23493 //Roo.log(nodeName);
23495 switch(nodeName.toLowerCase()) {
23497 switch(className) {
23503 var dir = Roo.bootstrap.form.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
23504 switch(this.viewMode){
23506 this.viewDate = this.moveMonth(this.viewDate, dir);
23510 this.viewDate = this.moveYear(this.viewDate, dir);
23516 var date = new Date();
23517 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
23519 this.setValue(this.formatDate(this.date));
23526 if (className.indexOf('disabled') < 0) {
23527 if (!this.viewDate) {
23528 this.viewDate = new Date();
23530 this.viewDate.setUTCDate(1);
23531 if (className.indexOf('month') > -1) {
23532 this.viewDate.setUTCMonth(Roo.bootstrap.form.DateField.dates[this.language].monthsShort.indexOf(html));
23534 var year = parseInt(html, 10) || 0;
23535 this.viewDate.setUTCFullYear(year);
23539 if(this.singleMode){
23540 this.setValue(this.formatDate(this.viewDate));
23551 //Roo.log(className);
23552 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
23553 var day = parseInt(html, 10) || 1;
23554 var year = (this.viewDate || new Date()).getUTCFullYear(),
23555 month = (this.viewDate || new Date()).getUTCMonth();
23557 if (className.indexOf('old') > -1) {
23564 } else if (className.indexOf('new') > -1) {
23572 //Roo.log([year,month,day]);
23573 this.date = this.UTCDate(year, month, day,0,0,0,0);
23574 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
23576 //Roo.log(this.formatDate(this.date));
23577 this.setValue(this.formatDate(this.date));
23584 setStartDate: function(startDate)
23586 this.startDate = startDate || -Infinity;
23587 if (this.startDate !== -Infinity) {
23588 this.startDate = this.parseDate(this.startDate);
23591 this.updateNavArrows();
23594 setEndDate: function(endDate)
23596 this.endDate = endDate || Infinity;
23597 if (this.endDate !== Infinity) {
23598 this.endDate = this.parseDate(this.endDate);
23601 this.updateNavArrows();
23604 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
23606 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
23607 if (typeof(this.daysOfWeekDisabled) !== 'object') {
23608 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
23610 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
23611 return parseInt(d, 10);
23614 this.updateNavArrows();
23617 updateNavArrows: function()
23619 if(this.singleMode){
23623 var d = new Date(this.viewDate),
23624 year = d.getUTCFullYear(),
23625 month = d.getUTCMonth();
23627 Roo.each(this.picker().select('.prev', true).elements, function(v){
23629 switch (this.viewMode) {
23632 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
23638 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
23645 Roo.each(this.picker().select('.next', true).elements, function(v){
23647 switch (this.viewMode) {
23650 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
23656 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
23664 moveMonth: function(date, dir)
23669 var new_date = new Date(date.valueOf()),
23670 day = new_date.getUTCDate(),
23671 month = new_date.getUTCMonth(),
23672 mag = Math.abs(dir),
23674 dir = dir > 0 ? 1 : -1;
23677 // If going back one month, make sure month is not current month
23678 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
23680 return new_date.getUTCMonth() == month;
23682 // If going forward one month, make sure month is as expected
23683 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
23685 return new_date.getUTCMonth() != new_month;
23687 new_month = month + dir;
23688 new_date.setUTCMonth(new_month);
23689 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
23690 if (new_month < 0 || new_month > 11) {
23691 new_month = (new_month + 12) % 12;
23694 // For magnitudes >1, move one month at a time...
23695 for (var i=0; i<mag; i++) {
23696 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
23697 new_date = this.moveMonth(new_date, dir);
23699 // ...then reset the day, keeping it in the new month
23700 new_month = new_date.getUTCMonth();
23701 new_date.setUTCDate(day);
23703 return new_month != new_date.getUTCMonth();
23706 // Common date-resetting loop -- if date is beyond end of month, make it
23709 new_date.setUTCDate(--day);
23710 new_date.setUTCMonth(new_month);
23715 moveYear: function(date, dir)
23717 return this.moveMonth(date, dir*12);
23720 dateWithinRange: function(date)
23722 return date >= this.startDate && date <= this.endDate;
23728 this.picker().remove();
23731 validateValue : function(value)
23733 if(this.getVisibilityEl().hasClass('hidden')){
23737 if(value.length < 1) {
23738 if(this.allowBlank){
23744 if(value.length < this.minLength){
23747 if(value.length > this.maxLength){
23751 var vt = Roo.form.VTypes;
23752 if(!vt[this.vtype](value, this)){
23756 if(typeof this.validator == "function"){
23757 var msg = this.validator(value);
23763 if(this.regex && !this.regex.test(value)){
23767 if(typeof(this.parseDate(value)) == 'undefined'){
23771 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
23775 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
23785 this.date = this.viewDate = '';
23787 Roo.bootstrap.form.DateField.superclass.setValue.call(this, '');
23792 Roo.apply(Roo.bootstrap.form.DateField, {
23803 html: '<i class="fa fa-arrow-left"/>'
23813 html: '<i class="fa fa-arrow-right"/>'
23855 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
23856 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
23857 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
23858 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
23859 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
23872 navFnc: 'FullYear',
23877 navFnc: 'FullYear',
23882 Roo.apply(Roo.bootstrap.form.DateField, {
23886 cls: 'datepicker dropdown-menu roo-dynamic shadow',
23890 cls: 'datepicker-days',
23894 cls: 'table-condensed',
23896 Roo.bootstrap.form.DateField.head,
23900 Roo.bootstrap.form.DateField.footer
23907 cls: 'datepicker-months',
23911 cls: 'table-condensed',
23913 Roo.bootstrap.form.DateField.head,
23914 Roo.bootstrap.form.DateField.content,
23915 Roo.bootstrap.form.DateField.footer
23922 cls: 'datepicker-years',
23926 cls: 'table-condensed',
23928 Roo.bootstrap.form.DateField.head,
23929 Roo.bootstrap.form.DateField.content,
23930 Roo.bootstrap.form.DateField.footer
23949 * @class Roo.bootstrap.form.TimeField
23950 * @extends Roo.bootstrap.form.Input
23951 * Bootstrap DateField class
23955 * Create a new TimeField
23956 * @param {Object} config The config object
23959 Roo.bootstrap.form.TimeField = function(config){
23960 Roo.bootstrap.form.TimeField.superclass.constructor.call(this, config);
23964 * Fires when this field show.
23965 * @param {Roo.bootstrap.form.DateField} thisthis
23966 * @param {Mixed} date The date value
23971 * Fires when this field hide.
23972 * @param {Roo.bootstrap.form.DateField} this
23973 * @param {Mixed} date The date value
23978 * Fires when select a date.
23979 * @param {Roo.bootstrap.form.DateField} this
23980 * @param {Mixed} date The date value
23986 Roo.extend(Roo.bootstrap.form.TimeField, Roo.bootstrap.form.Input, {
23989 * @cfg {String} format
23990 * The default time format string which can be overriden for localization support. The format must be
23991 * valid according to {@link Date#parseDate} (defaults to 'H:i').
23995 getAutoCreate : function()
23997 this.after = '<i class="fa far fa-clock"></i>';
23998 return Roo.bootstrap.form.TimeField.superclass.getAutoCreate.call(this);
24002 onRender: function(ct, position)
24005 Roo.bootstrap.form.TimeField.superclass.onRender.call(this, ct, position);
24007 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.TimeField.template);
24009 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24011 this.pop = this.picker().select('>.datepicker-time',true).first();
24012 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24014 this.picker().on('mousedown', this.onMousedown, this);
24015 this.picker().on('click', this.onClick, this);
24017 this.picker().addClass('datepicker-dropdown');
24022 this.pop.select('.hours-up', true).first().on('click', this.onIncrementHours, this);
24023 this.pop.select('.hours-down', true).first().on('click', this.onDecrementHours, this);
24024 this.pop.select('.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
24025 this.pop.select('.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
24026 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
24027 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
24031 fireKey: function(e){
24032 if (!this.picker().isVisible()){
24033 if (e.keyCode == 27) { // allow escape to hide and re-show picker
24039 e.preventDefault();
24047 this.onTogglePeriod();
24050 this.onIncrementMinutes();
24053 this.onDecrementMinutes();
24062 onClick: function(e) {
24063 e.stopPropagation();
24064 e.preventDefault();
24067 picker : function()
24069 return this.pickerEl;
24072 fillTime: function()
24074 var time = this.pop.select('tbody', true).first();
24076 time.dom.innerHTML = '';
24091 cls: 'hours-up fa fas fa-chevron-up'
24111 cls: 'minutes-up fa fas fa-chevron-up'
24132 cls: 'timepicker-hour',
24147 cls: 'timepicker-minute',
24162 cls: 'btn btn-primary period',
24184 cls: 'hours-down fa fas fa-chevron-down'
24204 cls: 'minutes-down fa fas fa-chevron-down'
24222 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
24229 var hours = this.time.getHours();
24230 var minutes = this.time.getMinutes();
24243 hours = hours - 12;
24247 hours = '0' + hours;
24251 minutes = '0' + minutes;
24254 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
24255 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
24256 this.pop.select('button', true).first().dom.innerHTML = period;
24262 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
24264 var cls = ['bottom'];
24266 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
24273 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
24277 //this.picker().setXY(20000,20000);
24278 this.picker().addClass(cls.join('-'));
24282 Roo.each(cls, function(c){
24287 _this.picker().alignTo(_this.inputEl(), "tr-br", [0, 10], false);
24288 //_this.picker().setTop(_this.inputEl().getHeight());
24292 _this.picker().alignTo(_this.inputEl(), "br-tr", [0, 10], false);
24294 //_this.picker().setTop(0 - _this.picker().getHeight());
24299 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
24303 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
24311 onFocus : function()
24313 Roo.bootstrap.form.TimeField.superclass.onFocus.call(this);
24317 onBlur : function()
24319 Roo.bootstrap.form.TimeField.superclass.onBlur.call(this);
24325 this.picker().show();
24330 this.fireEvent('show', this, this.date);
24335 this.picker().hide();
24338 this.fireEvent('hide', this, this.date);
24341 setTime : function()
24344 this.setValue(this.time.format(this.format));
24346 this.fireEvent('select', this, this.date);
24351 onMousedown: function(e){
24352 e.stopPropagation();
24353 e.preventDefault();
24356 onIncrementHours: function()
24358 Roo.log('onIncrementHours');
24359 this.time = this.time.add(Date.HOUR, 1);
24364 onDecrementHours: function()
24366 Roo.log('onDecrementHours');
24367 this.time = this.time.add(Date.HOUR, -1);
24371 onIncrementMinutes: function()
24373 Roo.log('onIncrementMinutes');
24374 this.time = this.time.add(Date.MINUTE, 1);
24378 onDecrementMinutes: function()
24380 Roo.log('onDecrementMinutes');
24381 this.time = this.time.add(Date.MINUTE, -1);
24385 onTogglePeriod: function()
24387 Roo.log('onTogglePeriod');
24388 this.time = this.time.add(Date.HOUR, 12);
24396 Roo.apply(Roo.bootstrap.form.TimeField, {
24400 cls: 'datepicker dropdown-menu',
24404 cls: 'datepicker-time',
24408 cls: 'table-condensed',
24437 cls: 'btn btn-info ok',
24465 * @class Roo.bootstrap.form.MonthField
24466 * @extends Roo.bootstrap.form.Input
24467 * Bootstrap MonthField class
24469 * @cfg {String} language default en
24472 * Create a new MonthField
24473 * @param {Object} config The config object
24476 Roo.bootstrap.form.MonthField = function(config){
24477 Roo.bootstrap.form.MonthField.superclass.constructor.call(this, config);
24482 * Fires when this field show.
24483 * @param {Roo.bootstrap.form.MonthField} this
24484 * @param {Mixed} date The date value
24489 * Fires when this field hide.
24490 * @param {Roo.bootstrap.form.MonthField} this
24491 * @param {Mixed} date The date value
24496 * Fires when select a date.
24497 * @param {Roo.bootstrap.form.MonthField} this
24498 * @param {String} oldvalue The old value
24499 * @param {String} newvalue The new value
24505 Roo.extend(Roo.bootstrap.form.MonthField, Roo.bootstrap.form.Input, {
24507 onRender: function(ct, position)
24510 Roo.bootstrap.form.MonthField.superclass.onRender.call(this, ct, position);
24512 this.language = this.language || 'en';
24513 this.language = this.language in Roo.bootstrap.form.MonthField.dates ? this.language : this.language.split('-')[0];
24514 this.language = this.language in Roo.bootstrap.form.MonthField.dates ? this.language : "en";
24516 this.isRTL = Roo.bootstrap.form.MonthField.dates[this.language].rtl || false;
24517 this.isInline = false;
24518 this.isInput = true;
24519 this.component = this.el.select('.add-on', true).first() || false;
24520 this.component = (this.component && this.component.length === 0) ? false : this.component;
24521 this.hasInput = this.component && this.inputEL().length;
24523 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.form.MonthField.template);
24525 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
24527 this.picker().on('mousedown', this.onMousedown, this);
24528 this.picker().on('click', this.onClick, this);
24530 this.picker().addClass('datepicker-dropdown');
24532 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
24533 v.setStyle('width', '189px');
24540 if(this.isInline) {
24546 setValue: function(v, suppressEvent)
24548 var o = this.getValue();
24550 Roo.bootstrap.form.MonthField.superclass.setValue.call(this, v);
24554 if(suppressEvent !== true){
24555 this.fireEvent('select', this, o, v);
24560 getValue: function()
24565 onClick: function(e)
24567 e.stopPropagation();
24568 e.preventDefault();
24570 var target = e.getTarget();
24572 if(target.nodeName.toLowerCase() === 'i'){
24573 target = Roo.get(target).dom.parentNode;
24576 var nodeName = target.nodeName;
24577 var className = target.className;
24578 var html = target.innerHTML;
24580 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
24584 this.vIndex = Roo.bootstrap.form.MonthField.dates[this.language].monthsShort.indexOf(html);
24586 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24592 picker : function()
24594 return this.pickerEl;
24597 fillMonths: function()
24600 var months = this.picker().select('>.datepicker-months td', true).first();
24602 months.dom.innerHTML = '';
24608 html: Roo.bootstrap.form.MonthField.dates[this.language].monthsShort[i++]
24611 months.createChild(month);
24620 if(typeof(this.vIndex) == 'undefined' && this.value.length){
24621 this.vIndex = Roo.bootstrap.form.MonthField.dates[this.language].months.indexOf(this.value);
24624 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
24625 e.removeClass('active');
24627 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
24628 e.addClass('active');
24635 if(this.isInline) {
24639 this.picker().removeClass(['bottom', 'top']);
24641 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
24643 * place to the top of element!
24647 this.picker().addClass('top');
24648 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
24653 this.picker().addClass('bottom');
24655 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
24658 onFocus : function()
24660 Roo.bootstrap.form.MonthField.superclass.onFocus.call(this);
24664 onBlur : function()
24666 Roo.bootstrap.form.MonthField.superclass.onBlur.call(this);
24668 var d = this.inputEl().getValue();
24677 this.picker().show();
24678 this.picker().select('>.datepicker-months', true).first().show();
24682 this.fireEvent('show', this, this.date);
24687 if(this.isInline) {
24690 this.picker().hide();
24691 this.fireEvent('hide', this, this.date);
24695 onMousedown: function(e)
24697 e.stopPropagation();
24698 e.preventDefault();
24703 Roo.bootstrap.form.MonthField.superclass.keyup.call(this);
24707 fireKey: function(e)
24709 if (!this.picker().isVisible()){
24710 if (e.keyCode == 27) {// allow escape to hide and re-show picker
24721 e.preventDefault();
24725 dir = e.keyCode == 37 ? -1 : 1;
24727 this.vIndex = this.vIndex + dir;
24729 if(this.vIndex < 0){
24733 if(this.vIndex > 11){
24737 if(isNaN(this.vIndex)){
24741 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24747 dir = e.keyCode == 38 ? -1 : 1;
24749 this.vIndex = this.vIndex + dir * 4;
24751 if(this.vIndex < 0){
24755 if(this.vIndex > 11){
24759 if(isNaN(this.vIndex)){
24763 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24768 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
24769 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24773 e.preventDefault();
24776 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
24777 this.setValue(Roo.bootstrap.form.MonthField.dates[this.language].months[this.vIndex]);
24793 this.picker().remove();
24798 Roo.apply(Roo.bootstrap.form.MonthField, {
24817 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
24818 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
24823 Roo.apply(Roo.bootstrap.form.MonthField, {
24827 cls: 'datepicker dropdown-menu roo-dynamic',
24831 cls: 'datepicker-months',
24835 cls: 'table-condensed',
24837 Roo.bootstrap.form.DateField.content
24857 * @class Roo.bootstrap.form.CheckBox
24858 * @extends Roo.bootstrap.form.Input
24859 * Bootstrap CheckBox class
24861 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
24862 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
24863 * @cfg {String} boxLabel The text that appears beside the checkbox
24864 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
24865 * @cfg {Boolean} checked initnal the element
24866 * @cfg {Boolean} inline inline the element (default false)
24867 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
24868 * @cfg {String} tooltip label tooltip
24871 * Create a new CheckBox
24872 * @param {Object} config The config object
24875 Roo.bootstrap.form.CheckBox = function(config){
24876 Roo.bootstrap.form.CheckBox.superclass.constructor.call(this, config);
24881 * Fires when the element is checked or unchecked.
24882 * @param {Roo.bootstrap.form.CheckBox} this This input
24883 * @param {Boolean} checked The new checked value
24888 * Fires when the element is click.
24889 * @param {Roo.bootstrap.form.CheckBox} this This input
24896 Roo.extend(Roo.bootstrap.form.CheckBox, Roo.bootstrap.form.Input, {
24898 inputType: 'checkbox',
24907 // checkbox success does not make any sense really..
24912 getAutoCreate : function()
24914 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
24920 cfg.cls = 'form-group form-check ' + this.inputType; //input-group
24923 cfg.cls += ' ' + this.inputType + '-inline form-check-inline';
24929 type : this.inputType,
24930 value : this.inputValue,
24931 cls : 'roo-' + this.inputType, //'form-box',
24932 placeholder : this.placeholder || ''
24936 if(this.inputType != 'radio'){
24940 cls : 'roo-hidden-value',
24941 value : this.checked ? this.inputValue : this.valueOff
24946 if (this.weight) { // Validity check?
24947 cfg.cls += " " + this.inputType + "-" + this.weight;
24950 if (this.disabled) {
24951 input.disabled=true;
24955 input.checked = this.checked;
24960 input.name = this.name;
24962 if(this.inputType != 'radio'){
24963 hidden.name = this.name;
24964 input.name = '_hidden_' + this.name;
24969 input.cls += ' input-' + this.size;
24974 ['xs','sm','md','lg'].map(function(size){
24975 if (settings[size]) {
24976 cfg.cls += ' col-' + size + '-' + settings[size];
24980 var inputblock = input;
24982 if (this.before || this.after) {
24985 cls : 'input-group',
24990 inputblock.cn.push({
24992 cls : 'input-group-addon',
24997 inputblock.cn.push(input);
24999 if(this.inputType != 'radio'){
25000 inputblock.cn.push(hidden);
25004 inputblock.cn.push({
25006 cls : 'input-group-addon',
25012 var boxLabelCfg = false;
25018 //'for': id, // box label is handled by onclick - so no for...
25020 html: this.boxLabel
25023 boxLabelCfg.tooltip = this.tooltip;
25029 if (align ==='left' && this.fieldLabel.length) {
25030 // Roo.log("left and has label");
25035 cls : 'control-label',
25036 html : this.fieldLabel
25047 cfg.cn[1].cn.push(boxLabelCfg);
25050 if(this.labelWidth > 12){
25051 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
25054 if(this.labelWidth < 13 && this.labelmd == 0){
25055 this.labelmd = this.labelWidth;
25058 if(this.labellg > 0){
25059 cfg.cn[0].cls += ' col-lg-' + this.labellg;
25060 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
25063 if(this.labelmd > 0){
25064 cfg.cn[0].cls += ' col-md-' + this.labelmd;
25065 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
25068 if(this.labelsm > 0){
25069 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
25070 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
25073 if(this.labelxs > 0){
25074 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
25075 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
25078 } else if ( this.fieldLabel.length) {
25079 // Roo.log(" label");
25083 tag: this.boxLabel ? 'span' : 'label',
25085 cls: 'control-label box-input-label',
25086 //cls : 'input-group-addon',
25087 html : this.fieldLabel
25094 cfg.cn.push(boxLabelCfg);
25099 // Roo.log(" no label && no align");
25100 cfg.cn = [ inputblock ] ;
25102 cfg.cn.push(boxLabelCfg);
25110 if(this.inputType != 'radio'){
25111 cfg.cn.push(hidden);
25119 * return the real input element.
25121 inputEl: function ()
25123 return this.el.select('input.roo-' + this.inputType,true).first();
25125 hiddenEl: function ()
25127 return this.el.select('input.roo-hidden-value',true).first();
25130 labelEl: function()
25132 return this.el.select('label.control-label',true).first();
25134 /* depricated... */
25138 return this.labelEl();
25141 boxLabelEl: function()
25143 return this.el.select('label.box-label',true).first();
25146 initEvents : function()
25148 // Roo.bootstrap.form.CheckBox.superclass.initEvents.call(this);
25150 this.inputEl().on('click', this.onClick, this);
25152 if (this.boxLabel) {
25153 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
25156 this.startValue = this.getValue();
25159 Roo.bootstrap.form.CheckBox.register(this);
25163 onClick : function(e)
25165 if(this.fireEvent('click', this, e) !== false){
25166 this.setChecked(!this.checked);
25171 setChecked : function(state,suppressEvent)
25173 this.startValue = this.getValue();
25175 if(this.inputType == 'radio'){
25177 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25178 e.dom.checked = false;
25181 this.inputEl().dom.checked = true;
25183 this.inputEl().dom.value = this.inputValue;
25185 if(suppressEvent !== true){
25186 this.fireEvent('check', this, true);
25194 this.checked = state;
25196 this.inputEl().dom.checked = state;
25199 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
25201 if(suppressEvent !== true){
25202 this.fireEvent('check', this, state);
25208 getValue : function()
25210 if(this.inputType == 'radio'){
25211 return this.getGroupValue();
25214 return this.hiddenEl().dom.value;
25218 getGroupValue : function()
25220 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
25224 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
25227 setValue : function(v,suppressEvent)
25229 if(this.inputType == 'radio'){
25230 this.setGroupValue(v, suppressEvent);
25234 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
25239 setGroupValue : function(v, suppressEvent)
25241 this.startValue = this.getValue();
25243 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25244 e.dom.checked = false;
25246 if(e.dom.value == v){
25247 e.dom.checked = true;
25251 if(suppressEvent !== true){
25252 this.fireEvent('check', this, true);
25260 validate : function()
25262 if(this.getVisibilityEl().hasClass('hidden')){
25268 (this.inputType == 'radio' && this.validateRadio()) ||
25269 (this.inputType == 'checkbox' && this.validateCheckbox())
25275 this.markInvalid();
25279 validateRadio : function()
25281 if(this.getVisibilityEl().hasClass('hidden')){
25285 if(this.allowBlank){
25291 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25292 if(!e.dom.checked){
25304 validateCheckbox : function()
25307 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
25308 //return (this.getValue() == this.inputValue) ? true : false;
25311 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25319 for(var i in group){
25320 if(group[i].el.isVisible(true)){
25328 for(var i in group){
25333 r = (group[i].getValue() == group[i].inputValue) ? true : false;
25340 * Mark this field as valid
25342 markValid : function()
25346 this.fireEvent('valid', this);
25348 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25351 label = Roo.bootstrap.form.FieldLabel.get(this.groupId + '-group');
25358 if(this.inputType == 'radio'){
25359 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25360 var fg = e.findParent('.form-group', false, true);
25361 if (Roo.bootstrap.version == 3) {
25362 fg.removeClass([_this.invalidClass, _this.validClass]);
25363 fg.addClass(_this.validClass);
25365 fg.removeClass(['is-valid', 'is-invalid']);
25366 fg.addClass('is-valid');
25374 var fg = this.el.findParent('.form-group', false, true);
25375 if (Roo.bootstrap.version == 3) {
25376 fg.removeClass([this.invalidClass, this.validClass]);
25377 fg.addClass(this.validClass);
25379 fg.removeClass(['is-valid', 'is-invalid']);
25380 fg.addClass('is-valid');
25385 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25391 for(var i in group){
25392 var fg = group[i].el.findParent('.form-group', false, true);
25393 if (Roo.bootstrap.version == 3) {
25394 fg.removeClass([this.invalidClass, this.validClass]);
25395 fg.addClass(this.validClass);
25397 fg.removeClass(['is-valid', 'is-invalid']);
25398 fg.addClass('is-valid');
25404 * Mark this field as invalid
25405 * @param {String} msg The validation message
25407 markInvalid : function(msg)
25409 if(this.allowBlank){
25415 this.fireEvent('invalid', this, msg);
25417 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25420 label = Roo.bootstrap.form.FieldLabel.get(this.groupId + '-group');
25424 label.markInvalid();
25427 if(this.inputType == 'radio'){
25429 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25430 var fg = e.findParent('.form-group', false, true);
25431 if (Roo.bootstrap.version == 3) {
25432 fg.removeClass([_this.invalidClass, _this.validClass]);
25433 fg.addClass(_this.invalidClass);
25435 fg.removeClass(['is-invalid', 'is-valid']);
25436 fg.addClass('is-invalid');
25444 var fg = this.el.findParent('.form-group', false, true);
25445 if (Roo.bootstrap.version == 3) {
25446 fg.removeClass([_this.invalidClass, _this.validClass]);
25447 fg.addClass(_this.invalidClass);
25449 fg.removeClass(['is-invalid', 'is-valid']);
25450 fg.addClass('is-invalid');
25455 var group = Roo.bootstrap.form.CheckBox.get(this.groupId);
25461 for(var i in group){
25462 var fg = group[i].el.findParent('.form-group', false, true);
25463 if (Roo.bootstrap.version == 3) {
25464 fg.removeClass([_this.invalidClass, _this.validClass]);
25465 fg.addClass(_this.invalidClass);
25467 fg.removeClass(['is-invalid', 'is-valid']);
25468 fg.addClass('is-invalid');
25474 clearInvalid : function()
25476 Roo.bootstrap.form.Input.prototype.clearInvalid.call(this);
25478 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
25480 var label = Roo.bootstrap.form.FieldLabel.get(this.name + '-group');
25482 if (label && label.iconEl) {
25483 label.iconEl.removeClass([ label.validClass, label.invalidClass ]);
25484 label.iconEl.removeClass(['is-invalid', 'is-valid']);
25488 disable : function()
25490 if(this.inputType != 'radio'){
25491 Roo.bootstrap.form.CheckBox.superclass.disable.call(this);
25498 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25499 _this.getActionEl().addClass(this.disabledClass);
25500 e.dom.disabled = true;
25504 this.disabled = true;
25505 this.fireEvent("disable", this);
25509 enable : function()
25511 if(this.inputType != 'radio'){
25512 Roo.bootstrap.form.CheckBox.superclass.enable.call(this);
25519 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
25520 _this.getActionEl().removeClass(this.disabledClass);
25521 e.dom.disabled = false;
25525 this.disabled = false;
25526 this.fireEvent("enable", this);
25530 setBoxLabel : function(v)
25535 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
25541 Roo.apply(Roo.bootstrap.form.CheckBox, {
25546 * register a CheckBox Group
25547 * @param {Roo.bootstrap.form.CheckBox} the CheckBox to add
25549 register : function(checkbox)
25551 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
25552 this.groups[checkbox.groupId] = {};
25555 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
25559 this.groups[checkbox.groupId][checkbox.name] = checkbox;
25563 * fetch a CheckBox Group based on the group ID
25564 * @param {string} the group ID
25565 * @returns {Roo.bootstrap.form.CheckBox} the CheckBox group
25567 get: function(groupId) {
25568 if (typeof(this.groups[groupId]) == 'undefined') {
25572 return this.groups[groupId] ;
25585 * @class Roo.bootstrap.form.Radio
25586 * @extends Roo.bootstrap.Component
25587 * Bootstrap Radio class
25588 * @cfg {String} boxLabel - the label associated
25589 * @cfg {String} value - the value of radio
25592 * Create a new Radio
25593 * @param {Object} config The config object
25595 Roo.bootstrap.form.Radio = function(config){
25596 Roo.bootstrap.form.Radio.superclass.constructor.call(this, config);
25600 Roo.extend(Roo.bootstrap.form.Radio, Roo.bootstrap.Component, {
25606 getAutoCreate : function()
25610 cls : 'form-group radio',
25615 html : this.boxLabel
25623 initEvents : function()
25625 this.parent().register(this);
25627 this.el.on('click', this.onClick, this);
25631 onClick : function(e)
25633 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
25634 this.setChecked(true);
25638 setChecked : function(state, suppressEvent)
25640 this.parent().setValue(this.value, suppressEvent);
25644 setBoxLabel : function(v)
25649 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
25664 * @class Roo.bootstrap.form.SecurePass
25665 * @extends Roo.bootstrap.form.Input
25666 * Bootstrap SecurePass class
25670 * Create a new SecurePass
25671 * @param {Object} config The config object
25674 Roo.bootstrap.form.SecurePass = function (config) {
25675 // these go here, so the translation tool can replace them..
25677 PwdEmpty: "Please type a password, and then retype it to confirm.",
25678 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
25679 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
25680 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
25681 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
25682 FNInPwd: "Your password can't contain your first name. Please type a different password.",
25683 LNInPwd: "Your password can't contain your last name. Please type a different password.",
25684 TooWeak: "Your password is Too Weak."
25686 this.meterLabel = "Password strength:";
25687 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
25688 this.meterClass = [
25689 "roo-password-meter-tooweak",
25690 "roo-password-meter-weak",
25691 "roo-password-meter-medium",
25692 "roo-password-meter-strong",
25693 "roo-password-meter-grey"
25698 Roo.bootstrap.form.SecurePass.superclass.constructor.call(this, config);
25701 Roo.extend(Roo.bootstrap.form.SecurePass, Roo.bootstrap.form.Input, {
25703 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
25705 * PwdEmpty: "Please type a password, and then retype it to confirm.",
25706 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
25707 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
25708 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
25709 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
25710 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
25711 * LNInPwd: "Your password can't contain your last name. Please type a different password."
25721 * @cfg {String/Object} Label for the strength meter (defaults to
25722 * 'Password strength:')
25727 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
25728 * ['Weak', 'Medium', 'Strong'])
25731 pwdStrengths: false,
25744 initEvents: function ()
25746 Roo.bootstrap.form.SecurePass.superclass.initEvents.call(this);
25748 if (this.el.is('input[type=password]') && Roo.isSafari) {
25749 this.el.on('keydown', this.SafariOnKeyDown, this);
25752 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
25755 onRender: function (ct, position)
25757 Roo.bootstrap.form.SecurePass.superclass.onRender.call(this, ct, position);
25758 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
25759 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
25761 this.trigger.createChild({
25766 cls: 'roo-password-meter-grey col-xs-12',
25769 //width: this.meterWidth + 'px'
25773 cls: 'roo-password-meter-text'
25779 if (this.hideTrigger) {
25780 this.trigger.setDisplayed(false);
25782 this.setSize(this.width || '', this.height || '');
25785 onDestroy: function ()
25787 if (this.trigger) {
25788 this.trigger.removeAllListeners();
25789 this.trigger.remove();
25792 this.wrap.remove();
25794 Roo.bootstrap.form.TriggerField.superclass.onDestroy.call(this);
25797 checkStrength: function ()
25799 var pwd = this.inputEl().getValue();
25800 if (pwd == this._lastPwd) {
25805 if (this.ClientSideStrongPassword(pwd)) {
25807 } else if (this.ClientSideMediumPassword(pwd)) {
25809 } else if (this.ClientSideWeakPassword(pwd)) {
25815 Roo.log('strength1: ' + strength);
25817 //var pm = this.trigger.child('div/div/div').dom;
25818 var pm = this.trigger.child('div/div');
25819 pm.removeClass(this.meterClass);
25820 pm.addClass(this.meterClass[strength]);
25823 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25825 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
25827 this._lastPwd = pwd;
25831 Roo.bootstrap.form.SecurePass.superclass.reset.call(this);
25833 this._lastPwd = '';
25835 var pm = this.trigger.child('div/div');
25836 pm.removeClass(this.meterClass);
25837 pm.addClass('roo-password-meter-grey');
25840 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25843 this.inputEl().dom.type='password';
25846 validateValue: function (value)
25848 if (!Roo.bootstrap.form.SecurePass.superclass.validateValue.call(this, value)) {
25851 if (value.length == 0) {
25852 if (this.allowBlank) {
25853 this.clearInvalid();
25857 this.markInvalid(this.errors.PwdEmpty);
25858 this.errorMsg = this.errors.PwdEmpty;
25866 if (!value.match(/[\x21-\x7e]+/)) {
25867 this.markInvalid(this.errors.PwdBadChar);
25868 this.errorMsg = this.errors.PwdBadChar;
25871 if (value.length < 6) {
25872 this.markInvalid(this.errors.PwdShort);
25873 this.errorMsg = this.errors.PwdShort;
25876 if (value.length > 16) {
25877 this.markInvalid(this.errors.PwdLong);
25878 this.errorMsg = this.errors.PwdLong;
25882 if (this.ClientSideStrongPassword(value)) {
25884 } else if (this.ClientSideMediumPassword(value)) {
25886 } else if (this.ClientSideWeakPassword(value)) {
25893 if (strength < 2) {
25894 //this.markInvalid(this.errors.TooWeak);
25895 this.errorMsg = this.errors.TooWeak;
25900 console.log('strength2: ' + strength);
25902 //var pm = this.trigger.child('div/div/div').dom;
25904 var pm = this.trigger.child('div/div');
25905 pm.removeClass(this.meterClass);
25906 pm.addClass(this.meterClass[strength]);
25908 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
25910 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
25912 this.errorMsg = '';
25916 CharacterSetChecks: function (type)
25919 this.fResult = false;
25922 isctype: function (character, type)
25925 case this.kCapitalLetter:
25926 if (character >= 'A' && character <= 'Z') {
25931 case this.kSmallLetter:
25932 if (character >= 'a' && character <= 'z') {
25938 if (character >= '0' && character <= '9') {
25943 case this.kPunctuation:
25944 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
25955 IsLongEnough: function (pwd, size)
25957 return !(pwd == null || isNaN(size) || pwd.length < size);
25960 SpansEnoughCharacterSets: function (word, nb)
25962 if (!this.IsLongEnough(word, nb))
25967 var characterSetChecks = new Array(
25968 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
25969 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
25972 for (var index = 0; index < word.length; ++index) {
25973 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
25974 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
25975 characterSetChecks[nCharSet].fResult = true;
25982 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
25983 if (characterSetChecks[nCharSet].fResult) {
25988 if (nCharSets < nb) {
25994 ClientSideStrongPassword: function (pwd)
25996 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
25999 ClientSideMediumPassword: function (pwd)
26001 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
26004 ClientSideWeakPassword: function (pwd)
26006 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
26010 Roo.htmleditor = {};
26013 * @class Roo.htmleditor.Filter
26014 * Base Class for filtering htmleditor stuff. - do not use this directly - extend it.
26015 * @cfg {DomElement} node The node to iterate and filter
26016 * @cfg {boolean|String|Array} tag Tags to replace
26018 * Create a new Filter.
26019 * @param {Object} config Configuration options
26024 Roo.htmleditor.Filter = function(cfg) {
26025 Roo.apply(this.cfg);
26026 // this does not actually call walk as it's really just a abstract class
26030 Roo.htmleditor.Filter.prototype = {
26036 // overrride to do replace comments.
26037 replaceComment : false,
26039 // overrride to do replace or do stuff with tags..
26040 replaceTag : false,
26042 walk : function(dom)
26044 Roo.each( Array.from(dom.childNodes), function( e ) {
26047 case e.nodeType == 8 && this.replaceComment !== false: // comment
26048 this.replaceComment(e);
26051 case e.nodeType != 1: //not a node.
26054 case this.tag === true: // everything
26055 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1:
26056 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":":
26057 case typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1: // array and it matches.
26058 case typeof(this.tag) == 'string' && this.tag == e.tagName: // array and it matches.
26059 if (this.replaceTag && false === this.replaceTag(e)) {
26062 if (e.hasChildNodes()) {
26067 default: // tags .. that do not match.
26068 if (e.hasChildNodes()) {
26078 removeNodeKeepChildren : function( node)
26081 ar = Array.from(node.childNodes);
26082 for (var i = 0; i < ar.length; i++) {
26084 node.removeChild(ar[i]);
26085 // what if we need to walk these???
26086 node.parentNode.insertBefore(ar[i], node);
26089 node.parentNode.removeChild(node);
26094 * @class Roo.htmleditor.FilterAttributes
26095 * clean attributes and styles including http:// etc.. in attribute
26097 * Run a new Attribute Filter
26098 * @param {Object} config Configuration options
26100 Roo.htmleditor.FilterAttributes = function(cfg)
26102 Roo.apply(this, cfg);
26103 this.attrib_black = this.attrib_black || [];
26104 this.attrib_white = this.attrib_white || [];
26106 this.attrib_clean = this.attrib_clean || [];
26107 this.style_white = this.style_white || [];
26108 this.style_black = this.style_black || [];
26109 this.walk(cfg.node);
26112 Roo.extend(Roo.htmleditor.FilterAttributes, Roo.htmleditor.Filter,
26114 tag: true, // all tags
26116 attrib_black : false, // array
26117 attrib_clean : false,
26118 attrib_white : false,
26120 style_white : false,
26121 style_black : false,
26124 replaceTag : function(node)
26126 if (!node.attributes || !node.attributes.length) {
26130 for (var i = node.attributes.length-1; i > -1 ; i--) {
26131 var a = node.attributes[i];
26133 if (this.attrib_white.length && this.attrib_white.indexOf(a.name.toLowerCase()) < 0) {
26134 node.removeAttribute(a.name);
26140 if (a.name.toLowerCase().substr(0,2)=='on') {
26141 node.removeAttribute(a.name);
26146 if (this.attrib_black.indexOf(a.name.toLowerCase()) > -1) {
26147 node.removeAttribute(a.name);
26150 if (this.attrib_clean.indexOf(a.name.toLowerCase()) > -1) {
26151 this.cleanAttr(node,a.name,a.value); // fixme..
26154 if (a.name == 'style') {
26155 this.cleanStyle(node,a.name,a.value);
26158 /// clean up MS crap..
26159 // tecnically this should be a list of valid class'es..
26162 if (a.name == 'class') {
26163 if (a.value.match(/^Mso/)) {
26164 node.removeAttribute('class');
26167 if (a.value.match(/^body$/)) {
26168 node.removeAttribute('class');
26178 return true; // clean children
26181 cleanAttr: function(node, n,v)
26184 if (v.match(/^\./) || v.match(/^\//)) {
26187 if (v.match(/^(http|https):\/\//)
26188 || v.match(/^mailto:/)
26189 || v.match(/^ftp:/)
26190 || v.match(/^data:/)
26194 if (v.match(/^#/)) {
26197 if (v.match(/^\{/)) { // allow template editing.
26200 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
26201 node.removeAttribute(n);
26204 cleanStyle : function(node, n,v)
26206 if (v.match(/expression/)) { //XSS?? should we even bother..
26207 node.removeAttribute(n);
26211 var parts = v.split(/;/);
26214 Roo.each(parts, function(p) {
26215 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
26219 var l = p.split(':').shift().replace(/\s+/g,'');
26220 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
26222 if ( this.style_black.length && (this.style_black.indexOf(l) > -1 || this.style_black.indexOf(l.toLowerCase()) > -1)) {
26226 // only allow 'c whitelisted system attributes'
26227 if ( this.style_white.length && style_white.indexOf(l) < 0 && style_white.indexOf(l.toLowerCase()) < 0 ) {
26235 if (clean.length) {
26236 node.setAttribute(n, clean.join(';'));
26238 node.removeAttribute(n);
26247 * @class Roo.htmleditor.FilterBlack
26248 * remove blacklisted elements.
26250 * Run a new Blacklisted Filter
26251 * @param {Object} config Configuration options
26254 Roo.htmleditor.FilterBlack = function(cfg)
26256 Roo.apply(this, cfg);
26257 this.walk(cfg.node);
26260 Roo.extend(Roo.htmleditor.FilterBlack, Roo.htmleditor.Filter,
26262 tag : true, // all elements.
26264 replaceTag : function(n)
26266 n.parentNode.removeChild(n);
26270 * @class Roo.htmleditor.FilterComment
26273 * Run a new Comments Filter
26274 * @param {Object} config Configuration options
26276 Roo.htmleditor.FilterComment = function(cfg)
26278 this.walk(cfg.node);
26281 Roo.extend(Roo.htmleditor.FilterComment, Roo.htmleditor.Filter,
26284 replaceComment : function(n)
26286 n.parentNode.removeChild(n);
26289 * @class Roo.htmleditor.FilterKeepChildren
26290 * remove tags but keep children
26292 * Run a new Keep Children Filter
26293 * @param {Object} config Configuration options
26296 Roo.htmleditor.FilterKeepChildren = function(cfg)
26298 Roo.apply(this, cfg);
26299 if (this.tag === false) {
26300 return; // dont walk.. (you can use this to use this just to do a child removal on a single tag )
26303 if ((typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)) {
26304 this.cleanNamespace = true;
26307 this.walk(cfg.node);
26310 Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack,
26312 cleanNamespace : false, // should really be an option, rather than using ':' inside of this tag.
26314 replaceTag : function(node)
26316 // walk children...
26317 //Roo.log(node.tagName);
26318 var ar = Array.from(node.childNodes);
26321 for (var i = 0; i < ar.length; i++) {
26323 if (e.nodeType == 1) {
26325 (typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1)
26326 || // array and it matches
26327 (typeof(this.tag) == 'string' && this.tag == e.tagName)
26329 (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)
26331 (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":")
26333 this.replaceTag(ar[i]); // child is blacklisted as well...
26338 ar = Array.from(node.childNodes);
26339 for (var i = 0; i < ar.length; i++) {
26341 node.removeChild(ar[i]);
26342 // what if we need to walk these???
26343 node.parentNode.insertBefore(ar[i], node);
26344 if (this.tag !== false) {
26349 //Roo.log("REMOVE:" + node.tagName);
26350 node.parentNode.removeChild(node);
26351 return false; // don't walk children
26356 * @class Roo.htmleditor.FilterParagraph
26357 * paragraphs cause a nightmare for shared content - this filter is designed to be called ? at various points when editing
26358 * like on 'push' to remove the <p> tags and replace them with line breaks.
26360 * Run a new Paragraph Filter
26361 * @param {Object} config Configuration options
26364 Roo.htmleditor.FilterParagraph = function(cfg)
26366 // no need to apply config.
26367 this.walk(cfg.node);
26370 Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter,
26377 replaceTag : function(node)
26380 if (node.childNodes.length == 1 &&
26381 node.childNodes[0].nodeType == 3 &&
26382 node.childNodes[0].textContent.trim().length < 1
26384 // remove and replace with '<BR>';
26385 node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node);
26386 return false; // no need to walk..
26388 var ar = Array.from(node.childNodes);
26389 for (var i = 0; i < ar.length; i++) {
26390 node.removeChild(ar[i]);
26391 // what if we need to walk these???
26392 node.parentNode.insertBefore(ar[i], node);
26394 // now what about this?
26398 node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
26399 node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
26400 node.parentNode.removeChild(node);
26407 * @class Roo.htmleditor.FilterSpan
26408 * filter span's with no attributes out..
26410 * Run a new Span Filter
26411 * @param {Object} config Configuration options
26414 Roo.htmleditor.FilterSpan = function(cfg)
26416 // no need to apply config.
26417 this.walk(cfg.node);
26420 Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterKeepChildren,
26426 replaceTag : function(node)
26428 if (node.attributes && node.attributes.length > 0) {
26429 return true; // walk if there are any.
26431 Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this, node);
26437 * @class Roo.htmleditor.FilterTableWidth
26438 try and remove table width data - as that frequently messes up other stuff.
26440 * was cleanTableWidths.
26442 * Quite often pasting from word etc.. results in tables with column and widths.
26443 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
26446 * Run a new Table Filter
26447 * @param {Object} config Configuration options
26450 Roo.htmleditor.FilterTableWidth = function(cfg)
26452 // no need to apply config.
26453 this.tag = ['TABLE', 'TD', 'TR', 'TH', 'THEAD', 'TBODY' ];
26454 this.walk(cfg.node);
26457 Roo.extend(Roo.htmleditor.FilterTableWidth, Roo.htmleditor.Filter,
26462 replaceTag: function(node) {
26466 if (node.hasAttribute('width')) {
26467 node.removeAttribute('width');
26471 if (node.hasAttribute("style")) {
26474 var styles = node.getAttribute("style").split(";");
26476 Roo.each(styles, function(s) {
26477 if (!s.match(/:/)) {
26480 var kv = s.split(":");
26481 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
26484 // what ever is left... we allow.
26487 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
26488 if (!nstyle.length) {
26489 node.removeAttribute('style');
26493 return true; // continue doing children..
26496 * @class Roo.htmleditor.FilterWord
26497 * try and clean up all the mess that Word generates.
26499 * This is the 'nice version' - see 'Heavy' that white lists a very short list of elements, and multi-filters
26502 * Run a new Span Filter
26503 * @param {Object} config Configuration options
26506 Roo.htmleditor.FilterWord = function(cfg)
26508 // no need to apply config.
26509 this.replaceDocBullets(cfg.node);
26511 this.replaceAname(cfg.node);
26512 // this is disabled as the removal is done by other filters;
26513 // this.walk(cfg.node);
26518 Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
26524 * Clean up MS wordisms...
26526 replaceTag : function(node)
26529 // no idea what this does - span with text, replaceds with just text.
26531 node.nodeName == 'SPAN' &&
26532 !node.hasAttributes() &&
26533 node.childNodes.length == 1 &&
26534 node.firstChild.nodeName == "#text"
26536 var textNode = node.firstChild;
26537 node.removeChild(textNode);
26538 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
26539 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node);
26541 node.parentNode.insertBefore(textNode, node);
26542 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
26543 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node);
26546 node.parentNode.removeChild(node);
26547 return false; // dont do chidren - we have remove our node - so no need to do chdhilren?
26552 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
26553 node.parentNode.removeChild(node);
26554 return false; // dont do chidlren
26556 //Roo.log(node.tagName);
26557 // remove - but keep children..
26558 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) {
26559 //Roo.log('-- removed');
26560 while (node.childNodes.length) {
26561 var cn = node.childNodes[0];
26562 node.removeChild(cn);
26563 node.parentNode.insertBefore(cn, node);
26564 // move node to parent - and clean it..
26565 if (cn.nodeType == 1) {
26566 this.replaceTag(cn);
26570 node.parentNode.removeChild(node);
26571 /// no need to iterate chidlren = it's got none..
26572 //this.iterateChildren(node, this.cleanWord);
26573 return false; // no need to iterate children.
26576 if (node.className.length) {
26578 var cn = node.className.split(/\W+/);
26580 Roo.each(cn, function(cls) {
26581 if (cls.match(/Mso[a-zA-Z]+/)) {
26586 node.className = cna.length ? cna.join(' ') : '';
26588 node.removeAttribute("class");
26592 if (node.hasAttribute("lang")) {
26593 node.removeAttribute("lang");
26596 if (node.hasAttribute("style")) {
26598 var styles = node.getAttribute("style").split(";");
26600 Roo.each(styles, function(s) {
26601 if (!s.match(/:/)) {
26604 var kv = s.split(":");
26605 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
26608 // what ever is left... we allow.
26611 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
26612 if (!nstyle.length) {
26613 node.removeAttribute('style');
26616 return true; // do children
26622 styleToObject: function(node)
26624 var styles = (node.getAttribute("style") || '').split(";");
26626 Roo.each(styles, function(s) {
26627 if (!s.match(/:/)) {
26630 var kv = s.split(":");
26632 // what ever is left... we allow.
26633 ret[kv[0].trim()] = kv[1];
26639 replaceAname : function (doc)
26641 // replace all the a/name without..
26642 var aa = Array.from(doc.getElementsByTagName('a'));
26643 for (var i = 0; i < aa.length; i++) {
26645 if (a.hasAttribute("name")) {
26646 a.removeAttribute("name");
26648 if (a.hasAttribute("href")) {
26651 // reparent children.
26652 this.removeNodeKeepChildren(a);
26662 replaceDocBullets : function(doc)
26664 // this is a bit odd - but it appears some indents use ql-indent-1
26665 //Roo.log(doc.innerHTML);
26667 var listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpFirst'));
26668 for( var i = 0; i < listpara.length; i ++) {
26669 listpara[i].className = "MsoListParagraph";
26672 listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpMiddle'));
26673 for( var i = 0; i < listpara.length; i ++) {
26674 listpara[i].className = "MsoListParagraph";
26676 listpara = Array.from(doc.getElementsByClassName('MsoListParagraphCxSpLast'));
26677 for( var i = 0; i < listpara.length; i ++) {
26678 listpara[i].className = "MsoListParagraph";
26680 listpara = Array.from(doc.getElementsByClassName('ql-indent-1'));
26681 for( var i = 0; i < listpara.length; i ++) {
26682 listpara[i].className = "MsoListParagraph";
26685 // this is a bit hacky - we had one word document where h2 had a miso-list attribute.
26686 var htwo = Array.from(doc.getElementsByTagName('h2'));
26687 for( var i = 0; i < htwo.length; i ++) {
26688 if (htwo[i].hasAttribute('style') && htwo[i].getAttribute('style').match(/mso-list:/)) {
26689 htwo[i].className = "MsoListParagraph";
26692 listpara = Array.from(doc.getElementsByClassName('MsoNormal'));
26693 for( var i = 0; i < listpara.length; i ++) {
26694 if (listpara[i].hasAttribute('style') && listpara[i].getAttribute('style').match(/mso-list:/)) {
26695 listpara[i].className = "MsoListParagraph";
26697 listpara[i].className = "MsoNormalx";
26701 listpara = doc.getElementsByClassName('MsoListParagraph');
26702 // Roo.log(doc.innerHTML);
26706 while(listpara.length) {
26708 this.replaceDocBullet(listpara.item(0));
26715 replaceDocBullet : function(p)
26717 // gather all the siblings.
26719 parent = p.parentNode,
26720 doc = parent.ownerDocument,
26723 var listtype = 'ul';
26725 if (ns.nodeType != 1) {
26726 ns = ns.nextSibling;
26729 if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) {
26732 var spans = ns.getElementsByTagName('span');
26733 if (ns.hasAttribute('style') && ns.getAttribute('style').match(/mso-list/)) {
26735 ns = ns.nextSibling;
26737 if (spans.length && spans[0].hasAttribute('style')) {
26738 var style = this.styleToObject(spans[0]);
26739 if (typeof(style['font-family']) != 'undefined' && !style['font-family'].match(/Symbol/)) {
26746 var spans = ns.getElementsByTagName('span');
26747 if (!spans.length) {
26750 var has_list = false;
26751 for(var i = 0; i < spans.length; i++) {
26752 if (spans[i].hasAttribute('style') && spans[i].getAttribute('style').match(/mso-list/)) {
26761 ns = ns.nextSibling;
26765 if (!items.length) {
26770 var ul = parent.ownerDocument.createElement(listtype); // what about number lists...
26771 parent.insertBefore(ul, p);
26773 var stack = [ ul ];
26774 var last_li = false;
26776 var margin_to_depth = {};
26779 items.forEach(function(n, ipos) {
26780 //Roo.log("got innertHMLT=" + n.innerHTML);
26782 var spans = n.getElementsByTagName('span');
26783 if (!spans.length) {
26784 //Roo.log("No spans found");
26786 parent.removeChild(n);
26789 return; // skip it...
26795 for(var i = 0; i < spans.length; i++) {
26797 style = this.styleToObject(spans[i]);
26798 if (typeof(style['mso-list']) == 'undefined') {
26801 if (listtype == 'ol') {
26802 num = spans[i].innerText.replace(/[^0-9]+]/g,'') * 1;
26804 spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet.
26807 //Roo.log("NOW GOT innertHMLT=" + n.innerHTML);
26808 style = this.styleToObject(n); // mo-list is from the parent node.
26809 if (typeof(style['mso-list']) == 'undefined') {
26810 //Roo.log("parent is missing level");
26812 parent.removeChild(n);
26817 var margin = style['margin-left'];
26818 if (typeof(margin_to_depth[margin]) == 'undefined') {
26820 margin_to_depth[margin] = max_margins;
26822 nlvl = margin_to_depth[margin] ;
26826 var nul = doc.createElement(listtype); // what about number lists...
26828 last_li = doc.createElement('li');
26829 stack[lvl].appendChild(last_li);
26831 last_li.appendChild(nul);
26837 // not starting at 1..
26838 if (!stack[nlvl].hasAttribute("start") && listtype == "ol") {
26839 stack[nlvl].setAttribute("start", num);
26842 var nli = stack[nlvl].appendChild(doc.createElement('li'));
26844 nli.innerHTML = n.innerHTML;
26845 //Roo.log("innerHTML = " + n.innerHTML);
26846 parent.removeChild(n);
26862 * @class Roo.htmleditor.FilterStyleToTag
26863 * part of the word stuff... - certain 'styles' should be converted to tags.
26865 * font-weight: bold -> bold
26866 * ?? super / subscrit etc..
26869 * Run a new style to tag filter.
26870 * @param {Object} config Configuration options
26872 Roo.htmleditor.FilterStyleToTag = function(cfg)
26876 B : [ 'fontWeight' , 'bold'],
26877 I : [ 'fontStyle' , 'italic'],
26878 //pre : [ 'font-style' , 'italic'],
26879 // h1.. h6 ?? font-size?
26880 SUP : [ 'verticalAlign' , 'super' ],
26881 SUB : [ 'verticalAlign' , 'sub' ]
26886 Roo.apply(this, cfg);
26889 this.walk(cfg.node);
26896 Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter,
26898 tag: true, // all tags
26903 replaceTag : function(node)
26907 if (node.getAttribute("style") === null) {
26911 for (var k in this.tags) {
26912 if (node.style[this.tags[k][0]] == this.tags[k][1]) {
26914 node.style.removeProperty(this.tags[k][0]);
26917 if (!inject.length) {
26920 var cn = Array.from(node.childNodes);
26922 Roo.each(inject, function(t) {
26923 var nc = node.ownerDocument.createElement(t);
26924 nn.appendChild(nc);
26927 for(var i = 0;i < cn.length;cn++) {
26928 node.removeChild(cn[i]);
26929 nn.appendChild(cn[i]);
26931 return true /// iterate thru
26935 * @class Roo.htmleditor.FilterLongBr
26936 * BR/BR/BR - keep a maximum of 2...
26938 * Run a new Long BR Filter
26939 * @param {Object} config Configuration options
26942 Roo.htmleditor.FilterLongBr = function(cfg)
26944 // no need to apply config.
26945 this.walk(cfg.node);
26948 Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter,
26955 replaceTag : function(node)
26958 var ps = node.nextSibling;
26959 while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
26960 ps = ps.nextSibling;
26963 if (!ps && [ 'TD', 'TH', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(node.parentNode.tagName) > -1) {
26964 node.parentNode.removeChild(node); // remove last BR inside one fo these tags
26968 if (!ps || ps.nodeType != 1) {
26972 if (!ps || ps.tagName != 'BR') {
26981 if (!node.previousSibling) {
26984 var ps = node.previousSibling;
26986 while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
26987 ps = ps.previousSibling;
26989 if (!ps || ps.nodeType != 1) {
26992 // if header or BR before.. then it's a candidate for removal.. - as we only want '2' of these..
26993 if (!ps || [ 'BR', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(ps.tagName) < 0) {
26997 node.parentNode.removeChild(node); // remove me...
26999 return false; // no need to do children
27006 * @class Roo.htmleditor.FilterBlock
27007 * removes id / data-block and contenteditable that are associated with blocks
27008 * usage should be done on a cloned copy of the dom
27010 * Run a new Attribute Filter { node : xxxx }}
27011 * @param {Object} config Configuration options
27013 Roo.htmleditor.FilterBlock = function(cfg)
27015 Roo.apply(this, cfg);
27016 var qa = cfg.node.querySelectorAll;
27017 this.removeAttributes('data-block');
27018 this.removeAttributes('contenteditable');
27019 this.removeAttributes('id');
27023 Roo.apply(Roo.htmleditor.FilterBlock.prototype,
27025 node: true, // all tags
27028 removeAttributes : function(attr)
27030 var ar = this.node.querySelectorAll('*[' + attr + ']');
27031 for (var i =0;i<ar.length;i++) {
27032 ar[i].removeAttribute(attr);
27041 * @class Roo.htmleditor.KeyEnter
27042 * Handle Enter press..
27043 * @cfg {Roo.HtmlEditorCore} core the editor.
27045 * Create a new Filter.
27046 * @param {Object} config Configuration options
27053 Roo.htmleditor.KeyEnter = function(cfg) {
27054 Roo.apply(this, cfg);
27055 // this does not actually call walk as it's really just a abstract class
27057 Roo.get(this.core.doc.body).on('keypress', this.keypress, this);
27060 //Roo.htmleditor.KeyEnter.i = 0;
27063 Roo.htmleditor.KeyEnter.prototype = {
27067 keypress : function(e)
27069 if (e.charCode != 13 && e.charCode != 10) {
27070 Roo.log([e.charCode,e]);
27073 e.preventDefault();
27074 // https://stackoverflow.com/questions/18552336/prevent-contenteditable-adding-div-on-enter-chrome
27075 var doc = this.core.doc;
27079 var sel = this.core.getSelection();
27080 var range = sel.getRangeAt(0);
27081 var n = range.commonAncestorContainer;
27082 var pc = range.closest([ 'ol', 'ul']);
27083 var pli = range.closest('li');
27084 if (!pc || e.ctrlKey) {
27085 // on it list, or ctrl pressed.
27087 sel.insertNode('br', 'after');
27089 // only do this if we have ctrl key..
27090 var br = doc.createElement('br');
27091 br.className = 'clear';
27092 br.setAttribute('style', 'clear: both');
27093 sel.insertNode(br, 'after');
27097 this.core.undoManager.addEvent();
27098 this.core.fireEditorEvent(e);
27102 // deal with <li> insetion
27103 if (pli.innerText.trim() == '' &&
27104 pli.previousSibling &&
27105 pli.previousSibling.nodeName == 'LI' &&
27106 pli.previousSibling.innerText.trim() == '') {
27107 pli.parentNode.removeChild(pli.previousSibling);
27108 sel.cursorAfter(pc);
27109 this.core.undoManager.addEvent();
27110 this.core.fireEditorEvent(e);
27114 var li = doc.createElement('LI');
27115 li.innerHTML = ' ';
27116 if (!pli || !pli.firstSibling) {
27117 pc.appendChild(li);
27119 pli.parentNode.insertBefore(li, pli.firstSibling);
27121 sel.cursorText (li.firstChild);
27123 this.core.undoManager.addEvent();
27124 this.core.fireEditorEvent(e);
27136 * @class Roo.htmleditor.Block
27137 * Base class for html editor blocks - do not use it directly .. extend it..
27138 * @cfg {DomElement} node The node to apply stuff to.
27139 * @cfg {String} friendly_name the name that appears in the context bar about this block
27140 * @cfg {Object} Context menu - see Roo.form.HtmlEditor.ToolbarContext
27143 * Create a new Filter.
27144 * @param {Object} config Configuration options
27147 Roo.htmleditor.Block = function(cfg)
27149 // do nothing .. should not be called really.
27152 * factory method to get the block from an element (using cache if necessary)
27154 * @param {HtmlElement} the dom element
27156 Roo.htmleditor.Block.factory = function(node)
27158 var cc = Roo.htmleditor.Block.cache;
27159 var id = Roo.get(node).id;
27160 if (typeof(cc[id]) != 'undefined' && (!cc[id].node || cc[id].node.closest('body'))) {
27161 Roo.htmleditor.Block.cache[id].readElement(node);
27162 return Roo.htmleditor.Block.cache[id];
27164 var db = node.getAttribute('data-block');
27166 db = node.nodeName.toLowerCase().toUpperCaseFirst();
27168 var cls = Roo.htmleditor['Block' + db];
27169 if (typeof(cls) == 'undefined') {
27170 //Roo.log(node.getAttribute('data-block'));
27171 Roo.log("OOps missing block : " + 'Block' + db);
27174 Roo.htmleditor.Block.cache[id] = new cls({ node: node });
27175 return Roo.htmleditor.Block.cache[id]; /// should trigger update element
27179 * initalize all Elements from content that are 'blockable'
27181 * @param the body element
27183 Roo.htmleditor.Block.initAll = function(body, type)
27185 if (typeof(type) == 'undefined') {
27186 var ia = Roo.htmleditor.Block.initAll;
27192 Roo.each(Roo.get(body).query(type), function(e) {
27193 Roo.htmleditor.Block.factory(e);
27196 // question goes here... do we need to clear out this cache sometimes?
27197 // or show we make it relivant to the htmleditor.
27198 Roo.htmleditor.Block.cache = {};
27200 Roo.htmleditor.Block.prototype = {
27204 // used by context menu
27205 friendly_name : 'Based Block',
27207 // text for button to delete this element
27208 deleteTitle : false,
27212 * Update a node with values from this object
27213 * @param {DomElement} node
27215 updateElement : function(node)
27217 Roo.DomHelper.update(node === undefined ? this.node : node, this.toObject());
27220 * convert to plain HTML for calling insertAtCursor..
27222 toHTML : function()
27224 return Roo.DomHelper.markup(this.toObject());
27227 * used by readEleemnt to extract data from a node
27228 * may need improving as it's pretty basic
27230 * @param {DomElement} node
27231 * @param {String} tag - tag to find, eg. IMG ?? might be better to use DomQuery ?
27232 * @param {String} attribute (use html - for contents, style for using next param as style, or false to return the node)
27233 * @param {String} style the style property - eg. text-align
27235 getVal : function(node, tag, attr, style)
27238 if (tag !== true && n.tagName != tag.toUpperCase()) {
27239 // in theory we could do figure[3] << 3rd figure? or some more complex search..?
27240 // but kiss for now.
27241 n = node.getElementsByTagName(tag).item(0);
27246 if (attr === false) {
27249 if (attr == 'html') {
27250 return n.innerHTML;
27252 if (attr == 'style') {
27253 return n.style[style];
27256 return n.hasAttribute(attr) ? n.getAttribute(attr) : '';
27260 * create a DomHelper friendly object - for use with
27261 * Roo.DomHelper.markup / overwrite / etc..
27264 toObject : function()
27269 * Read a node that has a 'data-block' property - and extract the values from it.
27270 * @param {DomElement} node - the node
27272 readElement : function(node)
27283 * @class Roo.htmleditor.BlockFigure
27284 * Block that has an image and a figcaption
27285 * @cfg {String} image_src the url for the image
27286 * @cfg {String} align (left|right) alignment for the block default left
27287 * @cfg {String} caption the text to appear below (and in the alt tag)
27288 * @cfg {String} caption_display (block|none) display or not the caption
27289 * @cfg {String|number} image_width the width of the image number or %?
27290 * @cfg {String|number} image_height the height of the image number or %?
27293 * Create a new Filter.
27294 * @param {Object} config Configuration options
27297 Roo.htmleditor.BlockFigure = function(cfg)
27300 this.readElement(cfg.node);
27301 this.updateElement(cfg.node);
27303 Roo.apply(this, cfg);
27305 Roo.extend(Roo.htmleditor.BlockFigure, Roo.htmleditor.Block, {
27312 caption_display : 'block',
27318 // margin: '2%', not used
27320 text_align: 'left', // (left|right) alignment for the text caption default left. - not used at present
27323 // used by context menu
27324 friendly_name : 'Image with caption',
27325 deleteTitle : "Delete Image and Caption",
27327 contextMenu : function(toolbar)
27330 var block = function() {
27331 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
27335 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
27337 var syncValue = toolbar.editorcore.syncValue;
27343 xtype : 'TextItem',
27345 xns : rooui.Toolbar //Boostrap?
27349 text: 'Change Image URL',
27352 click: function (btn, state)
27356 Roo.MessageBox.show({
27357 title : "Image Source URL",
27358 msg : "Enter the url for the image",
27359 buttons: Roo.MessageBox.OKCANCEL,
27360 fn: function(btn, val){
27367 toolbar.editorcore.onEditorEvent();
27371 //multiline: multiline,
27373 value : b.image_src
27377 xns : rooui.Toolbar
27382 text: 'Change Link URL',
27385 click: function (btn, state)
27389 Roo.MessageBox.show({
27390 title : "Link URL",
27391 msg : "Enter the url for the link - leave blank to have no link",
27392 buttons: Roo.MessageBox.OKCANCEL,
27393 fn: function(btn, val){
27400 toolbar.editorcore.onEditorEvent();
27404 //multiline: multiline,
27410 xns : rooui.Toolbar
27414 text: 'Show Video URL',
27417 click: function (btn, state)
27419 Roo.MessageBox.alert("Video URL",
27420 block().video_url == '' ? 'This image is not linked ot a video' :
27421 'The image is linked to: <a target="_new" href="' + block().video_url + '">' + block().video_url + '</a>');
27424 xns : rooui.Toolbar
27429 xtype : 'TextItem',
27431 xns : rooui.Toolbar //Boostrap?
27434 xtype : 'ComboBox',
27435 allowBlank : false,
27436 displayField : 'val',
27439 triggerAction : 'all',
27441 valueField : 'val',
27445 select : function (combo, r, index)
27447 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
27449 b.width = r.get('val');
27452 toolbar.editorcore.onEditorEvent();
27457 xtype : 'SimpleStore',
27470 xtype : 'TextItem',
27472 xns : rooui.Toolbar //Boostrap?
27475 xtype : 'ComboBox',
27476 allowBlank : false,
27477 displayField : 'val',
27480 triggerAction : 'all',
27482 valueField : 'val',
27486 select : function (combo, r, index)
27488 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
27490 b.align = r.get('val');
27493 toolbar.editorcore.onEditorEvent();
27498 xtype : 'SimpleStore',
27512 text: 'Hide Caption',
27513 name : 'caption_display',
27515 enableToggle : true,
27516 setValue : function(v) {
27517 // this trigger toggle.
27519 this.setText(v ? "Hide Caption" : "Show Caption");
27520 this.setPressed(v != 'block');
27523 toggle: function (btn, state)
27526 b.caption_display = b.caption_display == 'block' ? 'none' : 'block';
27527 this.setText(b.caption_display == 'block' ? "Hide Caption" : "Show Caption");
27530 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
27531 toolbar.editorcore.onEditorEvent();
27534 xns : rooui.Toolbar
27540 * create a DomHelper friendly object - for use with
27541 * Roo.DomHelper.markup / overwrite / etc..
27543 toObject : function()
27545 var d = document.createElement('div');
27546 d.innerHTML = this.caption;
27548 var m = this.width != '100%' && this.align == 'center' ? '0 auto' : 0;
27550 var iw = this.align == 'center' ? this.width : '100%';
27553 contenteditable : 'false',
27554 src : this.image_src,
27555 alt : d.innerText.replace(/\n/g, " ").replace(/\s+/g, ' ').trim(), // removeHTML and reduce spaces..
27558 maxWidth : iw + ' !important', // this is not getting rendered?
27564 '<div class="{0}" width="420" height="315" src="{1}" frameborder="0" allowfullscreen>' +
27566 '<img class="{0}-thumbnail" src="{3}/Images/{4}/{5}#image-{4}" />' +
27571 if (this.href.length > 0) {
27575 contenteditable : 'true',
27583 if (this.video_url.length > 0) {
27588 allowfullscreen : true,
27589 width : 420, // these are for video tricks - that we replace the outer
27591 src : this.video_url,
27597 // we remove caption totally if its hidden... - will delete data.. but otherwise we end up with fake caption
27598 var captionhtml = this.caption_display == 'none' ? '' : (this.caption.length ? this.caption : "Caption");
27603 'data-block' : 'Figure',
27604 'data-width' : this.width,
27605 contenteditable : 'false',
27609 float : this.align ,
27610 maxWidth : this.align == 'center' ? '100% !important' : (this.width + ' !important'),
27611 width : this.align == 'center' ? '100%' : this.width,
27613 padding: this.align == 'center' ? '0' : '0 10px' ,
27614 textAlign : this.align // seems to work for email..
27619 align : this.align,
27625 'data-display' : this.caption_display,
27627 textAlign : 'left',
27629 lineHeight : '24px',
27630 display : this.caption_display,
27631 maxWidth : (this.align == 'center' ? this.width : '100%' ) + ' !important',
27633 width: this.align == 'center' ? this.width : '100%'
27637 cls : this.cls.length > 0 ? (this.cls + '-thumbnail' ) : '',
27642 marginTop : '16px',
27648 // we can not rely on yahoo syndication to use CSS elements - so have to use '<i>' to encase stuff.
27650 contenteditable : true,
27666 readElement : function(node)
27668 // this should not really come from the link...
27669 this.video_url = this.getVal(node, 'div', 'src');
27670 this.cls = this.getVal(node, 'div', 'class');
27671 this.href = this.getVal(node, 'a', 'href');
27674 this.image_src = this.getVal(node, 'img', 'src');
27676 this.align = this.getVal(node, 'figure', 'align');
27677 var figcaption = this.getVal(node, 'figcaption', false);
27678 if (figcaption !== '') {
27679 this.caption = this.getVal(figcaption, 'i', 'html');
27683 this.caption_display = this.getVal(node, 'figcaption', 'data-display');
27684 //this.text_align = this.getVal(node, 'figcaption', 'style','text-align');
27685 this.width = this.getVal(node, true, 'data-width');
27686 //this.margin = this.getVal(node, 'figure', 'style', 'margin');
27689 removeNode : function()
27706 * @class Roo.htmleditor.BlockTable
27707 * Block that manages a table
27710 * Create a new Filter.
27711 * @param {Object} config Configuration options
27714 Roo.htmleditor.BlockTable = function(cfg)
27717 this.readElement(cfg.node);
27718 this.updateElement(cfg.node);
27720 Roo.apply(this, cfg);
27723 for(var r = 0; r < this.no_row; r++) {
27725 for(var c = 0; c < this.no_col; c++) {
27726 this.rows[r][c] = this.emptyCell();
27733 Roo.extend(Roo.htmleditor.BlockTable, Roo.htmleditor.Block, {
27742 // used by context menu
27743 friendly_name : 'Table',
27744 deleteTitle : 'Delete Table',
27745 // context menu is drawn once..
27747 contextMenu : function(toolbar)
27750 var block = function() {
27751 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
27755 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
27757 var syncValue = toolbar.editorcore.syncValue;
27763 xtype : 'TextItem',
27765 xns : rooui.Toolbar //Boostrap?
27768 xtype : 'ComboBox',
27769 allowBlank : false,
27770 displayField : 'val',
27773 triggerAction : 'all',
27775 valueField : 'val',
27779 select : function (combo, r, index)
27781 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
27783 b.width = r.get('val');
27786 toolbar.editorcore.onEditorEvent();
27791 xtype : 'SimpleStore',
27803 xtype : 'TextItem',
27804 text : "Columns: ",
27805 xns : rooui.Toolbar //Boostrap?
27812 click : function (_self, e)
27814 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
27815 block().removeColumn();
27817 toolbar.editorcore.onEditorEvent();
27820 xns : rooui.Toolbar
27826 click : function (_self, e)
27828 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
27829 block().addColumn();
27831 toolbar.editorcore.onEditorEvent();
27834 xns : rooui.Toolbar
27838 xtype : 'TextItem',
27840 xns : rooui.Toolbar //Boostrap?
27847 click : function (_self, e)
27849 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
27850 block().removeRow();
27852 toolbar.editorcore.onEditorEvent();
27855 xns : rooui.Toolbar
27861 click : function (_self, e)
27865 toolbar.editorcore.onEditorEvent();
27868 xns : rooui.Toolbar
27873 text: 'Reset Column Widths',
27876 click : function (_self, e)
27878 block().resetWidths();
27880 toolbar.editorcore.onEditorEvent();
27883 xns : rooui.Toolbar
27894 * create a DomHelper friendly object - for use with
27895 * Roo.DomHelper.markup / overwrite / etc..
27896 * ?? should it be called with option to hide all editing features?
27898 toObject : function()
27903 contenteditable : 'false', // this stops cell selection from picking the table.
27904 'data-block' : 'Table',
27907 border : 'solid 1px #000', // ??? hard coded?
27908 'border-collapse' : 'collapse'
27911 { tag : 'tbody' , cn : [] }
27915 // do we have a head = not really
27917 Roo.each(this.rows, function( row ) {
27922 border : 'solid 1px #000',
27928 ret.cn[0].cn.push(tr);
27929 // does the row have any properties? ?? height?
27931 Roo.each(row, function( cell ) {
27935 contenteditable : 'true',
27936 'data-block' : 'Td',
27940 if (cell.colspan > 1) {
27941 td.colspan = cell.colspan ;
27942 nc += cell.colspan;
27946 if (cell.rowspan > 1) {
27947 td.rowspan = cell.rowspan ;
27956 ncols = Math.max(nc, ncols);
27960 // add the header row..
27969 readElement : function(node)
27971 node = node ? node : this.node ;
27972 this.width = this.getVal(node, true, 'style', 'width') || '100%';
27976 var trs = Array.from(node.rows);
27977 trs.forEach(function(tr) {
27979 this.rows.push(row);
27983 Array.from(tr.cells).forEach(function(td) {
27986 colspan : td.hasAttribute('colspan') ? td.getAttribute('colspan')*1 : 1,
27987 rowspan : td.hasAttribute('rowspan') ? td.getAttribute('rowspan')*1 : 1,
27988 style : td.hasAttribute('style') ? td.getAttribute('style') : '',
27989 html : td.innerHTML
27991 no_column += add.colspan;
27998 this.no_col = Math.max(this.no_col, no_column);
28005 normalizeRows: function()
28009 this.rows.forEach(function(row) {
28012 row = this.normalizeRow(row);
28014 row.forEach(function(c) {
28015 while (typeof(ret[rid][cid]) != 'undefined') {
28018 if (typeof(ret[rid]) == 'undefined') {
28024 if (c.rowspan < 2) {
28028 for(var i = 1 ;i < c.rowspan; i++) {
28029 if (typeof(ret[rid+i]) == 'undefined') {
28032 ret[rid+i][cid] = c;
28040 normalizeRow: function(row)
28043 row.forEach(function(c) {
28044 if (c.colspan < 2) {
28048 for(var i =0 ;i < c.colspan; i++) {
28056 deleteColumn : function(sel)
28058 if (!sel || sel.type != 'col') {
28061 if (this.no_col < 2) {
28065 this.rows.forEach(function(row) {
28066 var cols = this.normalizeRow(row);
28067 var col = cols[sel.col];
28068 if (col.colspan > 1) {
28078 removeColumn : function()
28080 this.deleteColumn({
28082 col : this.no_col-1
28084 this.updateElement();
28088 addColumn : function()
28091 this.rows.forEach(function(row) {
28092 row.push(this.emptyCell());
28095 this.updateElement();
28098 deleteRow : function(sel)
28100 if (!sel || sel.type != 'row') {
28104 if (this.no_row < 2) {
28108 var rows = this.normalizeRows();
28111 rows[sel.row].forEach(function(col) {
28112 if (col.rowspan > 1) {
28115 col.remove = 1; // flage it as removed.
28120 this.rows.forEach(function(row) {
28122 row.forEach(function(c) {
28123 if (typeof(c.remove) == 'undefined') {
28128 if (newrow.length > 0) {
28132 this.rows = newrows;
28137 this.updateElement();
28140 removeRow : function()
28144 row : this.no_row-1
28150 addRow : function()
28154 for (var i = 0; i < this.no_col; i++ ) {
28156 row.push(this.emptyCell());
28159 this.rows.push(row);
28160 this.updateElement();
28164 // the default cell object... at present...
28165 emptyCell : function() {
28166 return (new Roo.htmleditor.BlockTd({})).toObject();
28171 removeNode : function()
28178 resetWidths : function()
28180 Array.from(this.node.getElementsByTagName('td')).forEach(function(n) {
28181 var nn = Roo.htmleditor.Block.factory(n);
28183 nn.updateElement(n);
28196 * since selections really work on the table cell, then editing really should work from there
28198 * The original plan was to support merging etc... - but that may not be needed yet..
28200 * So this simple version will support:
28202 * adjust the width +/-
28203 * reset the width...
28212 * @class Roo.htmleditor.BlockTable
28213 * Block that manages a table
28216 * Create a new Filter.
28217 * @param {Object} config Configuration options
28220 Roo.htmleditor.BlockTd = function(cfg)
28223 this.readElement(cfg.node);
28224 this.updateElement(cfg.node);
28226 Roo.apply(this, cfg);
28231 Roo.extend(Roo.htmleditor.BlockTd, Roo.htmleditor.Block, {
28236 textAlign : 'left',
28243 // used by context menu
28244 friendly_name : 'Table Cell',
28245 deleteTitle : false, // use our customer delete
28247 // context menu is drawn once..
28249 contextMenu : function(toolbar)
28252 var cell = function() {
28253 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
28256 var table = function() {
28257 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode.closest('table'));
28261 var saveSel = function()
28263 lr = toolbar.editorcore.getSelection().getRangeAt(0);
28265 var restoreSel = function()
28269 toolbar.editorcore.focus();
28270 var cr = toolbar.editorcore.getSelection();
28271 cr.removeAllRanges();
28273 toolbar.editorcore.onEditorEvent();
28274 }).defer(10, this);
28280 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
28282 var syncValue = toolbar.editorcore.syncValue;
28289 text : 'Edit Table',
28291 click : function() {
28292 var t = toolbar.tb.selectedNode.closest('table');
28293 toolbar.editorcore.selectNode(t);
28294 toolbar.editorcore.onEditorEvent();
28303 xtype : 'TextItem',
28304 text : "Column Width: ",
28305 xns : rooui.Toolbar
28312 click : function (_self, e)
28314 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28315 cell().shrinkColumn();
28317 toolbar.editorcore.onEditorEvent();
28320 xns : rooui.Toolbar
28326 click : function (_self, e)
28328 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28329 cell().growColumn();
28331 toolbar.editorcore.onEditorEvent();
28334 xns : rooui.Toolbar
28338 xtype : 'TextItem',
28339 text : "Vertical Align: ",
28340 xns : rooui.Toolbar //Boostrap?
28343 xtype : 'ComboBox',
28344 allowBlank : false,
28345 displayField : 'val',
28348 triggerAction : 'all',
28350 valueField : 'val',
28354 select : function (combo, r, index)
28356 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28358 b.valign = r.get('val');
28361 toolbar.editorcore.onEditorEvent();
28366 xtype : 'SimpleStore',
28370 ['bottom'] // there are afew more...
28378 xtype : 'TextItem',
28379 text : "Merge Cells: ",
28380 xns : rooui.Toolbar
28389 click : function (_self, e)
28391 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28392 cell().mergeRight();
28393 //block().growColumn();
28395 toolbar.editorcore.onEditorEvent();
28398 xns : rooui.Toolbar
28405 click : function (_self, e)
28407 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28408 cell().mergeBelow();
28409 //block().growColumn();
28411 toolbar.editorcore.onEditorEvent();
28414 xns : rooui.Toolbar
28417 xtype : 'TextItem',
28419 xns : rooui.Toolbar
28427 click : function (_self, e)
28429 //toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28432 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
28433 toolbar.editorcore.onEditorEvent();
28437 xns : rooui.Toolbar
28441 xns : rooui.Toolbar
28450 xns : rooui.Toolbar,
28459 click : function (_self, e)
28463 cell().deleteColumn();
28465 toolbar.editorcore.selectNode(t.node);
28466 toolbar.editorcore.onEditorEvent();
28475 click : function (_self, e)
28478 cell().deleteRow();
28481 toolbar.editorcore.selectNode(t.node);
28482 toolbar.editorcore.onEditorEvent();
28489 xtype : 'Separator',
28496 click : function (_self, e)
28499 var nn = t.node.nextSibling || t.node.previousSibling;
28500 t.node.parentNode.removeChild(t.node);
28502 toolbar.editorcore.selectNode(nn, true);
28504 toolbar.editorcore.onEditorEvent();
28514 // align... << fixme
28522 * create a DomHelper friendly object - for use with
28523 * Roo.DomHelper.markup / overwrite / etc..
28524 * ?? should it be called with option to hide all editing features?
28527 * create a DomHelper friendly object - for use with
28528 * Roo.DomHelper.markup / overwrite / etc..
28529 * ?? should it be called with option to hide all editing features?
28531 toObject : function()
28535 contenteditable : 'true', // this stops cell selection from picking the table.
28536 'data-block' : 'Td',
28537 valign : this.valign,
28539 'text-align' : this.textAlign,
28540 border : 'solid 1px rgb(0, 0, 0)', // ??? hard coded?
28541 'border-collapse' : 'collapse',
28542 padding : '6px', // 8 for desktop / 4 for mobile
28543 'vertical-align': this.valign
28547 if (this.width != '') {
28548 ret.width = this.width;
28549 ret.style.width = this.width;
28553 if (this.colspan > 1) {
28554 ret.colspan = this.colspan ;
28556 if (this.rowspan > 1) {
28557 ret.rowspan = this.rowspan ;
28566 readElement : function(node)
28568 node = node ? node : this.node ;
28569 this.width = node.style.width;
28570 this.colspan = Math.max(1,1*node.getAttribute('colspan'));
28571 this.rowspan = Math.max(1,1*node.getAttribute('rowspan'));
28572 this.html = node.innerHTML;
28573 if (node.style.textAlign != '') {
28574 this.textAlign = node.style.textAlign;
28580 // the default cell object... at present...
28581 emptyCell : function() {
28585 textAlign : 'left',
28586 html : " " // is this going to be editable now?
28591 removeNode : function()
28593 return this.node.closest('table');
28601 toTableArray : function()
28604 var tab = this.node.closest('tr').closest('table');
28605 Array.from(tab.rows).forEach(function(r, ri){
28609 this.colWidths = [];
28610 var all_auto = true;
28611 Array.from(tab.rows).forEach(function(r, ri){
28614 Array.from(r.cells).forEach(function(ce, ci){
28619 colspan : ce.colSpan,
28620 rowspan : ce.rowSpan
28622 if (ce.isEqualNode(this.node)) {
28625 // if we have been filled up by a row?
28626 if (typeof(ret[rn][cn]) != 'undefined') {
28627 while(typeof(ret[rn][cn]) != 'undefined') {
28633 if (typeof(this.colWidths[cn]) == 'undefined' && c.colspan < 2) {
28634 this.colWidths[cn] = ce.style.width;
28635 if (this.colWidths[cn] != '') {
28641 if (c.colspan < 2 && c.rowspan < 2 ) {
28646 for(var j = 0; j < c.rowspan; j++) {
28647 if (typeof(ret[rn+j]) == 'undefined') {
28648 continue; // we have a problem..
28651 for(var i = 0; i < c.colspan; i++) {
28652 ret[rn+j][cn+i] = c;
28661 // initalize widths.?
28662 // either all widths or no widths..
28664 this.colWidths[0] = false; // no widths flag.
28675 mergeRight: function()
28678 // get the contents of the next cell along..
28679 var tr = this.node.closest('tr');
28680 var i = Array.prototype.indexOf.call(tr.childNodes, this.node);
28681 if (i >= tr.childNodes.length - 1) {
28682 return; // no cells on right to merge with.
28684 var table = this.toTableArray();
28686 if (typeof(table[this.cellData.row][this.cellData.col+this.cellData.colspan]) == 'undefined') {
28687 return; // nothing right?
28689 var rc = table[this.cellData.row][this.cellData.col+this.cellData.colspan];
28690 // right cell - must be same rowspan and on the same row.
28691 if (rc.rowspan != this.cellData.rowspan || rc.row != this.cellData.row) {
28692 return; // right hand side is not same rowspan.
28697 this.node.innerHTML += ' ' + rc.cell.innerHTML;
28698 tr.removeChild(rc.cell);
28699 this.colspan += rc.colspan;
28700 this.node.setAttribute('colspan', this.colspan);
28702 var table = this.toTableArray();
28703 this.normalizeWidths(table);
28704 this.updateWidths(table);
28708 mergeBelow : function()
28710 var table = this.toTableArray();
28711 if (typeof(table[this.cellData.row+this.cellData.rowspan]) == 'undefined') {
28712 return; // no row below
28714 if (typeof(table[this.cellData.row+this.cellData.rowspan][this.cellData.col]) == 'undefined') {
28715 return; // nothing right?
28717 var rc = table[this.cellData.row+this.cellData.rowspan][this.cellData.col];
28719 if (rc.colspan != this.cellData.colspan || rc.col != this.cellData.col) {
28720 return; // right hand side is not same rowspan.
28722 this.node.innerHTML = this.node.innerHTML + rc.cell.innerHTML ;
28723 rc.cell.parentNode.removeChild(rc.cell);
28724 this.rowspan += rc.rowspan;
28725 this.node.setAttribute('rowspan', this.rowspan);
28730 if (this.node.rowSpan < 2 && this.node.colSpan < 2) {
28733 var table = this.toTableArray();
28734 var cd = this.cellData;
28738 for(var r = cd.row; r < cd.row + cd.rowspan; r++) {
28741 for(var c = cd.col; c < cd.col + cd.colspan; c++) {
28742 if (r == cd.row && c == cd.col) {
28743 this.node.removeAttribute('rowspan');
28744 this.node.removeAttribute('colspan');
28747 var ntd = this.node.cloneNode(); // which col/row should be 0..
28748 ntd.removeAttribute('id');
28749 ntd.style.width = this.colWidths[c];
28750 ntd.innerHTML = '';
28751 table[r][c] = { cell : ntd, col : c, row: r , colspan : 1 , rowspan : 1 };
28755 this.redrawAllCells(table);
28761 redrawAllCells: function(table)
28765 var tab = this.node.closest('tr').closest('table');
28766 var ctr = tab.rows[0].parentNode;
28767 Array.from(tab.rows).forEach(function(r, ri){
28769 Array.from(r.cells).forEach(function(ce, ci){
28770 ce.parentNode.removeChild(ce);
28772 r.parentNode.removeChild(r);
28774 for(var r = 0 ; r < table.length; r++) {
28775 var re = tab.rows[r];
28777 var re = tab.ownerDocument.createElement('tr');
28778 ctr.appendChild(re);
28779 for(var c = 0 ; c < table[r].length; c++) {
28780 if (table[r][c].cell === false) {
28784 re.appendChild(table[r][c].cell);
28786 table[r][c].cell = false;
28791 updateWidths : function(table)
28793 for(var r = 0 ; r < table.length; r++) {
28795 for(var c = 0 ; c < table[r].length; c++) {
28796 if (table[r][c].cell === false) {
28800 if (this.colWidths[0] != false && table[r][c].colspan < 2) {
28801 var el = Roo.htmleditor.Block.factory(table[r][c].cell);
28802 el.width = Math.floor(this.colWidths[c]) +'%';
28803 el.updateElement(el.node);
28805 if (this.colWidths[0] != false && table[r][c].colspan > 1) {
28806 var el = Roo.htmleditor.Block.factory(table[r][c].cell);
28808 for(var i = 0; i < table[r][c].colspan; i ++) {
28809 width += Math.floor(this.colWidths[c + i]);
28811 el.width = width +'%';
28812 el.updateElement(el.node);
28814 table[r][c].cell = false; // done
28818 normalizeWidths : function(table)
28820 if (this.colWidths[0] === false) {
28821 var nw = 100.0 / this.colWidths.length;
28822 this.colWidths.forEach(function(w,i) {
28823 this.colWidths[i] = nw;
28828 var t = 0, missing = [];
28830 this.colWidths.forEach(function(w,i) {
28832 this.colWidths[i] = this.colWidths[i] == '' ? 0 : (this.colWidths[i]+'').replace(/[^0-9]+/g,'')*1;
28833 var add = this.colWidths[i];
28842 var nc = this.colWidths.length;
28843 if (missing.length) {
28844 var mult = (nc - missing.length) / (1.0 * nc);
28846 var ew = (100 -t) / (1.0 * missing.length);
28847 this.colWidths.forEach(function(w,i) {
28849 this.colWidths[i] = w * mult;
28853 this.colWidths[i] = ew;
28855 // have to make up numbers..
28858 // now we should have all the widths..
28863 shrinkColumn : function()
28865 var table = this.toTableArray();
28866 this.normalizeWidths(table);
28867 var col = this.cellData.col;
28868 var nw = this.colWidths[col] * 0.8;
28872 var otherAdd = (this.colWidths[col] * 0.2) / (this.colWidths.length -1);
28873 this.colWidths.forEach(function(w,i) {
28875 this.colWidths[i] = nw;
28878 this.colWidths[i] += otherAdd
28880 this.updateWidths(table);
28883 growColumn : function()
28885 var table = this.toTableArray();
28886 this.normalizeWidths(table);
28887 var col = this.cellData.col;
28888 var nw = this.colWidths[col] * 1.2;
28892 var otherSub = (this.colWidths[col] * 0.2) / (this.colWidths.length -1);
28893 this.colWidths.forEach(function(w,i) {
28895 this.colWidths[i] = nw;
28898 this.colWidths[i] -= otherSub
28900 this.updateWidths(table);
28903 deleteRow : function()
28905 // delete this rows 'tr'
28906 // if any of the cells in this row have a rowspan > 1 && row!= this row..
28907 // then reduce the rowspan.
28908 var table = this.toTableArray();
28909 // this.cellData.row;
28910 for (var i =0;i< table[this.cellData.row].length ; i++) {
28911 var c = table[this.cellData.row][i];
28912 if (c.row != this.cellData.row) {
28915 c.cell.setAttribute('rowspan', c.rowspan);
28918 if (c.rowspan > 1) {
28920 c.cell.setAttribute('rowspan', c.rowspan);
28923 table.splice(this.cellData.row,1);
28924 this.redrawAllCells(table);
28927 deleteColumn : function()
28929 var table = this.toTableArray();
28931 for (var i =0;i< table.length ; i++) {
28932 var c = table[i][this.cellData.col];
28933 if (c.col != this.cellData.col) {
28934 table[i][this.cellData.col].colspan--;
28935 } else if (c.colspan > 1) {
28937 c.cell.setAttribute('colspan', c.colspan);
28939 table[i].splice(this.cellData.col,1);
28942 this.redrawAllCells(table);
28950 //<script type="text/javascript">
28953 * Based Ext JS Library 1.1.1
28954 * Copyright(c) 2006-2007, Ext JS, LLC.
28960 * @class Roo.HtmlEditorCore
28961 * @extends Roo.Component
28962 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
28964 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
28967 Roo.HtmlEditorCore = function(config){
28970 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
28975 * @event initialize
28976 * Fires when the editor is fully initialized (including the iframe)
28977 * @param {Roo.HtmlEditorCore} this
28982 * Fires when the editor is first receives the focus. Any insertion must wait
28983 * until after this event.
28984 * @param {Roo.HtmlEditorCore} this
28988 * @event beforesync
28989 * Fires before the textarea is updated with content from the editor iframe. Return false
28990 * to cancel the sync.
28991 * @param {Roo.HtmlEditorCore} this
28992 * @param {String} html
28996 * @event beforepush
28997 * Fires before the iframe editor is updated with content from the textarea. Return false
28998 * to cancel the push.
28999 * @param {Roo.HtmlEditorCore} this
29000 * @param {String} html
29005 * Fires when the textarea is updated with content from the editor iframe.
29006 * @param {Roo.HtmlEditorCore} this
29007 * @param {String} html
29012 * Fires when the iframe editor is updated with content from the textarea.
29013 * @param {Roo.HtmlEditorCore} this
29014 * @param {String} html
29019 * @event editorevent
29020 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
29021 * @param {Roo.HtmlEditorCore} this
29028 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
29030 // defaults : white / black...
29031 this.applyBlacklists();
29038 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
29042 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
29048 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
29053 * @cfg {Number} height (in pixels)
29057 * @cfg {Number} width (in pixels)
29061 * @cfg {boolean} autoClean - default true - loading and saving will remove quite a bit of formating,
29062 * if you are doing an email editor, this probably needs disabling, it's designed
29067 * @cfg {boolean} enableBlocks - default true - if the block editor (table and figure should be enabled)
29069 enableBlocks : true,
29071 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
29074 stylesheets: false,
29076 * @cfg {String} language default en - language of text (usefull for rtl languages)
29082 * @cfg {boolean} allowComments - default false - allow comments in HTML source
29083 * - by default they are stripped - if you are editing email you may need this.
29085 allowComments: false,
29089 // private properties
29090 validationEvent : false,
29092 initialized : false,
29094 sourceEditMode : false,
29095 onFocus : Roo.emptyFn,
29097 hideMode:'offsets',
29101 // blacklist + whitelisted elements..
29108 undoManager : false,
29110 * Protected method that will not generally be called directly. It
29111 * is called when the editor initializes the iframe with HTML contents. Override this method if you
29112 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
29114 getDocMarkup : function(){
29118 // inherit styels from page...??
29119 if (this.stylesheets === false) {
29121 Roo.get(document.head).select('style').each(function(node) {
29122 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
29125 Roo.get(document.head).select('link').each(function(node) {
29126 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
29129 } else if (!this.stylesheets.length) {
29131 st = '<style type="text/css">' +
29132 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
29135 for (var i in this.stylesheets) {
29136 if (typeof(this.stylesheets[i]) != 'string') {
29139 st += '<link rel="stylesheet" href="' + this.stylesheets[i] +'" type="text/css">';
29144 st += '<style type="text/css">' +
29145 'IMG { cursor: pointer } ' +
29148 st += '<meta name="google" content="notranslate">';
29150 var cls = 'notranslate roo-htmleditor-body';
29152 if(this.bodyCls.length){
29153 cls += ' ' + this.bodyCls;
29156 return '<html class="notranslate" translate="no"><head>' + st +
29157 //<style type="text/css">' +
29158 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
29160 ' </head><body contenteditable="true" data-enable-grammerly="true" class="' + cls + '"></body></html>';
29164 onRender : function(ct, position)
29167 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
29168 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
29171 this.el.dom.style.border = '0 none';
29172 this.el.dom.setAttribute('tabIndex', -1);
29173 this.el.addClass('x-hidden hide');
29177 if(Roo.isIE){ // fix IE 1px bogus margin
29178 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
29182 this.frameId = Roo.id();
29186 var iframe = this.owner.wrap.createChild({
29188 cls: 'form-control', // bootstrap..
29190 name: this.frameId,
29191 frameBorder : 'no',
29192 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
29197 this.iframe = iframe.dom;
29199 this.assignDocWin();
29201 this.doc.designMode = 'on';
29204 this.doc.write(this.getDocMarkup());
29208 var task = { // must defer to wait for browser to be ready
29210 //console.log("run task?" + this.doc.readyState);
29211 this.assignDocWin();
29212 if(this.doc.body || this.doc.readyState == 'complete'){
29214 this.doc.designMode="on";
29219 Roo.TaskMgr.stop(task);
29220 this.initEditor.defer(10, this);
29227 Roo.TaskMgr.start(task);
29232 onResize : function(w, h)
29234 Roo.log('resize: ' +w + ',' + h );
29235 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
29239 if(typeof w == 'number'){
29241 this.iframe.style.width = w + 'px';
29243 if(typeof h == 'number'){
29245 this.iframe.style.height = h + 'px';
29247 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
29254 * Toggles the editor between standard and source edit mode.
29255 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
29257 toggleSourceEdit : function(sourceEditMode){
29259 this.sourceEditMode = sourceEditMode === true;
29261 if(this.sourceEditMode){
29263 Roo.get(this.iframe).addClass(['x-hidden','hide', 'd-none']); //FIXME - what's the BS styles for these
29266 Roo.get(this.iframe).removeClass(['x-hidden','hide', 'd-none']);
29267 //this.iframe.className = '';
29270 //this.setSize(this.owner.wrap.getSize());
29271 //this.fireEvent('editmodechange', this, this.sourceEditMode);
29278 * Protected method that will not generally be called directly. If you need/want
29279 * custom HTML cleanup, this is the method you should override.
29280 * @param {String} html The HTML to be cleaned
29281 * return {String} The cleaned HTML
29283 cleanHtml : function(html)
29285 html = String(html);
29286 if(html.length > 5){
29287 if(Roo.isSafari){ // strip safari nonsense
29288 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
29291 if(html == ' '){
29298 * HTML Editor -> Textarea
29299 * Protected method that will not generally be called directly. Syncs the contents
29300 * of the editor iframe with the textarea.
29302 syncValue : function()
29304 //Roo.log("HtmlEditorCore:syncValue (EDITOR->TEXT)");
29305 if(this.initialized){
29307 if (this.undoManager) {
29308 this.undoManager.addEvent();
29312 var bd = (this.doc.body || this.doc.documentElement);
29315 var sel = this.win.getSelection();
29317 var div = document.createElement('div');
29318 div.innerHTML = bd.innerHTML;
29319 var gtx = div.getElementsByClassName('gtx-trans-icon'); // google translate - really annoying and difficult to get rid of.
29320 if (gtx.length > 0) {
29321 var rm = gtx.item(0).parentNode;
29322 rm.parentNode.removeChild(rm);
29326 if (this.enableBlocks) {
29327 new Roo.htmleditor.FilterBlock({ node : div });
29330 var html = div.innerHTML;
29333 if (this.autoClean) {
29335 new Roo.htmleditor.FilterAttributes({
29337 attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'],
29338 attrib_clean : ['href', 'src' ]
29341 var tidy = new Roo.htmleditor.TidySerializer({
29344 html = tidy.serialize(div);
29350 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
29351 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
29353 html = '<div style="'+m[0]+'">' + html + '</div>';
29356 html = this.cleanHtml(html);
29357 // fix up the special chars.. normaly like back quotes in word...
29358 // however we do not want to do this with chinese..
29359 html = html.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g, function(match) {
29361 var cc = match.charCodeAt();
29363 // Get the character value, handling surrogate pairs
29364 if (match.length == 2) {
29365 // It's a surrogate pair, calculate the Unicode code point
29366 var high = match.charCodeAt(0) - 0xD800;
29367 var low = match.charCodeAt(1) - 0xDC00;
29368 cc = (high * 0x400) + low + 0x10000;
29370 (cc >= 0x4E00 && cc < 0xA000 ) ||
29371 (cc >= 0x3400 && cc < 0x4E00 ) ||
29372 (cc >= 0xf900 && cc < 0xfb00 )
29377 // No, use a numeric entity. Here we brazenly (and possibly mistakenly)
29378 return "&#" + cc + ";";
29385 if(this.owner.fireEvent('beforesync', this, html) !== false){
29386 this.el.dom.value = html;
29387 this.owner.fireEvent('sync', this, html);
29393 * TEXTAREA -> EDITABLE
29394 * Protected method that will not generally be called directly. Pushes the value of the textarea
29395 * into the iframe editor.
29397 pushValue : function()
29399 //Roo.log("HtmlEditorCore:pushValue (TEXT->EDITOR)");
29400 if(this.initialized){
29401 var v = this.el.dom.value.trim();
29404 if(this.owner.fireEvent('beforepush', this, v) !== false){
29405 var d = (this.doc.body || this.doc.documentElement);
29408 this.el.dom.value = d.innerHTML;
29409 this.owner.fireEvent('push', this, v);
29411 if (this.autoClean) {
29412 new Roo.htmleditor.FilterParagraph({node : this.doc.body}); // paragraphs
29413 new Roo.htmleditor.FilterSpan({node : this.doc.body}); // empty spans
29415 if (this.enableBlocks) {
29416 Roo.htmleditor.Block.initAll(this.doc.body);
29419 this.updateLanguage();
29421 var lc = this.doc.body.lastChild;
29422 if (lc && lc.nodeType == 1 && lc.getAttribute("contenteditable") == "false") {
29423 // add an extra line at the end.
29424 this.doc.body.appendChild(this.doc.createElement('br'));
29432 deferFocus : function(){
29433 this.focus.defer(10, this);
29437 focus : function(){
29438 if(this.win && !this.sourceEditMode){
29445 assignDocWin: function()
29447 var iframe = this.iframe;
29450 this.doc = iframe.contentWindow.document;
29451 this.win = iframe.contentWindow;
29453 // if (!Roo.get(this.frameId)) {
29456 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
29457 // this.win = Roo.get(this.frameId).dom.contentWindow;
29459 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
29463 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
29464 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
29469 initEditor : function(){
29470 //console.log("INIT EDITOR");
29471 this.assignDocWin();
29475 this.doc.designMode="on";
29477 this.doc.write(this.getDocMarkup());
29480 var dbody = (this.doc.body || this.doc.documentElement);
29481 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
29482 // this copies styles from the containing element into thsi one..
29483 // not sure why we need all of this..
29484 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
29486 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
29487 //ss['background-attachment'] = 'fixed'; // w3c
29488 dbody.bgProperties = 'fixed'; // ie
29489 dbody.setAttribute("translate", "no");
29491 //Roo.DomHelper.applyStyles(dbody, ss);
29492 Roo.EventManager.on(this.doc, {
29494 'mouseup': this.onEditorEvent,
29495 'dblclick': this.onEditorEvent,
29496 'click': this.onEditorEvent,
29497 'keyup': this.onEditorEvent,
29502 Roo.EventManager.on(this.doc, {
29503 'paste': this.onPasteEvent,
29507 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
29510 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
29511 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
29513 this.initialized = true;
29516 // initialize special key events - enter
29517 new Roo.htmleditor.KeyEnter({core : this});
29521 this.owner.fireEvent('initialize', this);
29524 // this is to prevent a href clicks resulting in a redirect?
29526 onPasteEvent : function(e,v)
29528 // I think we better assume paste is going to be a dirty load of rubish from word..
29530 // even pasting into a 'email version' of this widget will have to clean up that mess.
29531 var cd = (e.browserEvent.clipboardData || window.clipboardData);
29533 // check what type of paste - if it's an image, then handle it differently.
29534 if (cd.files && cd.files.length > 0) {
29536 var urlAPI = (window.createObjectURL && window) ||
29537 (window.URL && URL.revokeObjectURL && URL) ||
29538 (window.webkitURL && webkitURL);
29540 var url = urlAPI.createObjectURL( cd.files[0]);
29541 this.insertAtCursor('<img src=" + url + ">');
29544 if (cd.types.indexOf('text/html') < 0 ) {
29548 var html = cd.getData('text/html'); // clipboard event
29549 if (cd.types.indexOf('text/rtf') > -1) {
29550 var parser = new Roo.rtf.Parser(cd.getData('text/rtf'));
29551 images = parser.doc ? parser.doc.getElementsByType('pict') : [];
29556 images = images.filter(function(g) { return !g.path.match(/^rtf\/(head|pgdsctbl|listtable|footerf)/); }) // ignore headers/footers etc.
29557 .map(function(g) { return g.toDataURL(); })
29558 .filter(function(g) { return g != 'about:blank'; });
29561 html = this.cleanWordChars(html);
29563 var d = (new DOMParser().parseFromString(html, 'text/html')).body;
29566 var sn = this.getParentElement();
29567 // check if d contains a table, and prevent nesting??
29568 //Roo.log(d.getElementsByTagName('table'));
29570 //Roo.log(sn.closest('table'));
29571 if (d.getElementsByTagName('table').length && sn && sn.closest('table')) {
29572 e.preventDefault();
29573 this.insertAtCursor("You can not nest tables");
29574 //Roo.log("prevent?"); // fixme -
29580 if (images.length > 0) {
29581 // replace all v:imagedata - with img.
29582 var ar = Array.from(d.getElementsByTagName('v:imagedata'));
29583 Roo.each(ar, function(node) {
29584 node.parentNode.insertBefore(d.ownerDocument.createElement('img'), node );
29585 node.parentNode.removeChild(node);
29589 Roo.each(d.getElementsByTagName('img'), function(img, i) {
29590 img.setAttribute('src', images[i]);
29593 if (this.autoClean) {
29594 new Roo.htmleditor.FilterWord({ node : d });
29596 new Roo.htmleditor.FilterStyleToTag({ node : d });
29597 new Roo.htmleditor.FilterAttributes({
29599 attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'],
29600 attrib_clean : ['href', 'src' ]
29602 new Roo.htmleditor.FilterBlack({ node : d, tag : this.black});
29603 // should be fonts..
29604 new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT', ':' ]} );
29605 new Roo.htmleditor.FilterParagraph({ node : d });
29606 new Roo.htmleditor.FilterSpan({ node : d });
29607 new Roo.htmleditor.FilterLongBr({ node : d });
29608 new Roo.htmleditor.FilterComment({ node : d });
29612 if (this.enableBlocks) {
29614 Array.from(d.getElementsByTagName('img')).forEach(function(img) {
29615 if (img.closest('figure')) { // assume!! that it's aready
29618 var fig = new Roo.htmleditor.BlockFigure({
29619 image_src : img.src
29621 fig.updateElement(img); // replace it..
29627 this.insertAtCursor(d.innerHTML.replace(/ /g,' '));
29628 if (this.enableBlocks) {
29629 Roo.htmleditor.Block.initAll(this.doc.body);
29633 e.preventDefault();
29635 // default behaveiour should be our local cleanup paste? (optional?)
29636 // for simple editor - we want to hammer the paste and get rid of everything... - so over-rideable..
29637 //this.owner.fireEvent('paste', e, v);
29640 onDestroy : function(){
29646 //for (var i =0; i < this.toolbars.length;i++) {
29647 // // fixme - ask toolbars for heights?
29648 // this.toolbars[i].onDestroy();
29651 //this.wrap.dom.innerHTML = '';
29652 //this.wrap.remove();
29657 onFirstFocus : function(){
29659 this.assignDocWin();
29660 this.undoManager = new Roo.lib.UndoManager(100,(this.doc.body || this.doc.documentElement));
29662 this.activated = true;
29665 if(Roo.isGecko){ // prevent silly gecko errors
29667 var s = this.win.getSelection();
29668 if(!s.focusNode || s.focusNode.nodeType != 3){
29669 var r = s.getRangeAt(0);
29670 r.selectNodeContents((this.doc.body || this.doc.documentElement));
29675 this.execCmd('useCSS', true);
29676 this.execCmd('styleWithCSS', false);
29679 this.owner.fireEvent('activate', this);
29683 adjustFont: function(btn){
29684 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
29685 //if(Roo.isSafari){ // safari
29688 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
29689 if(Roo.isSafari){ // safari
29690 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
29691 v = (v < 10) ? 10 : v;
29692 v = (v > 48) ? 48 : v;
29693 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
29698 v = Math.max(1, v+adjust);
29700 this.execCmd('FontSize', v );
29703 onEditorEvent : function(e)
29707 if (e && (e.ctrlKey || e.metaKey) && e.keyCode === 90) {
29708 return; // we do not handle this.. (undo manager does..)
29710 // in theory this detects if the last element is not a br, then we try and do that.
29711 // its so clicking in space at bottom triggers adding a br and moving the cursor.
29713 e.target.nodeName == 'BODY' &&
29714 e.type == "mouseup" &&
29715 this.doc.body.lastChild
29717 var lc = this.doc.body.lastChild;
29718 // gtx-trans is google translate plugin adding crap.
29719 while ((lc.nodeType == 3 && lc.nodeValue == '') || lc.id == 'gtx-trans') {
29720 lc = lc.previousSibling;
29722 if (lc.nodeType == 1 && lc.nodeName != 'BR') {
29723 // if last element is <BR> - then dont do anything.
29725 var ns = this.doc.createElement('br');
29726 this.doc.body.appendChild(ns);
29727 range = this.doc.createRange();
29728 range.setStartAfter(ns);
29729 range.collapse(true);
29730 var sel = this.win.getSelection();
29731 sel.removeAllRanges();
29732 sel.addRange(range);
29738 this.fireEditorEvent(e);
29739 // this.updateToolbar();
29740 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
29743 fireEditorEvent: function(e)
29745 this.owner.fireEvent('editorevent', this, e);
29748 insertTag : function(tg)
29750 // could be a bit smarter... -> wrap the current selected tRoo..
29751 if (tg.toLowerCase() == 'span' ||
29752 tg.toLowerCase() == 'code' ||
29753 tg.toLowerCase() == 'sup' ||
29754 tg.toLowerCase() == 'sub'
29757 range = this.createRange(this.getSelection());
29758 var wrappingNode = this.doc.createElement(tg.toLowerCase());
29759 wrappingNode.appendChild(range.extractContents());
29760 range.insertNode(wrappingNode);
29767 this.execCmd("formatblock", tg);
29768 this.undoManager.addEvent();
29771 insertText : function(txt)
29775 var range = this.createRange();
29776 range.deleteContents();
29777 //alert(Sender.getAttribute('label'));
29779 range.insertNode(this.doc.createTextNode(txt));
29780 this.undoManager.addEvent();
29786 * Executes a Midas editor command on the editor document and performs necessary focus and
29787 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
29788 * @param {String} cmd The Midas command
29789 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
29791 relayCmd : function(cmd, value)
29795 case 'justifyleft':
29796 case 'justifyright':
29797 case 'justifycenter':
29798 // if we are in a cell, then we will adjust the
29799 var n = this.getParentElement();
29800 var td = n.closest('td');
29802 var bl = Roo.htmleditor.Block.factory(td);
29803 bl.textAlign = cmd.replace('justify','');
29804 bl.updateElement();
29805 this.owner.fireEvent('editorevent', this);
29808 this.execCmd('styleWithCSS', true); //
29812 // if there is no selection, then we insert, and set the curson inside it..
29813 this.execCmd('styleWithCSS', false);
29823 this.execCmd(cmd, value);
29824 this.owner.fireEvent('editorevent', this);
29825 //this.updateToolbar();
29826 this.owner.deferFocus();
29830 * Executes a Midas editor command directly on the editor document.
29831 * For visual commands, you should use {@link #relayCmd} instead.
29832 * <b>This should only be called after the editor is initialized.</b>
29833 * @param {String} cmd The Midas command
29834 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
29836 execCmd : function(cmd, value){
29837 this.doc.execCommand(cmd, false, value === undefined ? null : value);
29844 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
29846 * @param {String} text | dom node..
29848 insertAtCursor : function(text)
29851 if(!this.activated){
29855 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
29859 // from jquery ui (MIT licenced)
29861 var win = this.win;
29863 if (win.getSelection && win.getSelection().getRangeAt) {
29865 // delete the existing?
29867 this.createRange(this.getSelection()).deleteContents();
29868 range = win.getSelection().getRangeAt(0);
29869 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
29870 range.insertNode(node);
29871 range = range.cloneRange();
29872 range.collapse(false);
29874 win.getSelection().removeAllRanges();
29875 win.getSelection().addRange(range);
29879 } else if (win.document.selection && win.document.selection.createRange) {
29880 // no firefox support
29881 var txt = typeof(text) == 'string' ? text : text.outerHTML;
29882 win.document.selection.createRange().pasteHTML(txt);
29885 // no firefox support
29886 var txt = typeof(text) == 'string' ? text : text.outerHTML;
29887 this.execCmd('InsertHTML', txt);
29895 mozKeyPress : function(e){
29897 var c = e.getCharCode(), cmd;
29900 c = String.fromCharCode(c).toLowerCase();
29914 // this.cleanUpPaste.defer(100, this);
29920 this.relayCmd(cmd);
29921 //this.win.focus();
29922 //this.execCmd(cmd);
29923 //this.deferFocus();
29924 e.preventDefault();
29932 fixKeys : function(){ // load time branching for fastest keydown performance
29936 return function(e){
29937 var k = e.getKey(), r;
29940 r = this.doc.selection.createRange();
29943 r.pasteHTML('    ');
29948 /// this is handled by Roo.htmleditor.KeyEnter
29951 r = this.doc.selection.createRange();
29953 var target = r.parentElement();
29954 if(!target || target.tagName.toLowerCase() != 'li'){
29956 r.pasteHTML('<br/>');
29963 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
29964 // this.cleanUpPaste.defer(100, this);
29970 }else if(Roo.isOpera){
29971 return function(e){
29972 var k = e.getKey();
29976 this.execCmd('InsertHTML','    ');
29980 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
29981 // this.cleanUpPaste.defer(100, this);
29986 }else if(Roo.isSafari){
29987 return function(e){
29988 var k = e.getKey();
29992 this.execCmd('InsertText','\t');
29996 this.mozKeyPress(e);
29998 //if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
29999 // this.cleanUpPaste.defer(100, this);
30007 getAllAncestors: function()
30009 var p = this.getSelectedNode();
30012 a.push(p); // push blank onto stack..
30013 p = this.getParentElement();
30017 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
30021 a.push(this.doc.body);
30025 lastSelNode : false,
30028 getSelection : function()
30030 this.assignDocWin();
30031 return Roo.lib.Selection.wrap(Roo.isIE ? this.doc.selection : this.win.getSelection(), this.doc);
30034 * Select a dom node
30035 * @param {DomElement} node the node to select
30037 selectNode : function(node, collapse)
30039 var nodeRange = node.ownerDocument.createRange();
30041 nodeRange.selectNode(node);
30043 nodeRange.selectNodeContents(node);
30045 if (collapse === true) {
30046 nodeRange.collapse(true);
30049 var s = this.win.getSelection();
30050 s.removeAllRanges();
30051 s.addRange(nodeRange);
30054 getSelectedNode: function()
30056 // this may only work on Gecko!!!
30058 // should we cache this!!!!
30062 var range = this.createRange(this.getSelection()).cloneRange();
30065 var parent = range.parentElement();
30067 var testRange = range.duplicate();
30068 testRange.moveToElementText(parent);
30069 if (testRange.inRange(range)) {
30072 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
30075 parent = parent.parentElement;
30080 // is ancestor a text element.
30081 var ac = range.commonAncestorContainer;
30082 if (ac.nodeType == 3) {
30083 ac = ac.parentNode;
30086 var ar = ac.childNodes;
30089 var other_nodes = [];
30090 var has_other_nodes = false;
30091 for (var i=0;i<ar.length;i++) {
30092 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
30095 // fullly contained node.
30097 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
30102 // probably selected..
30103 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
30104 other_nodes.push(ar[i]);
30108 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
30113 has_other_nodes = true;
30115 if (!nodes.length && other_nodes.length) {
30116 nodes= other_nodes;
30118 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
30126 createRange: function(sel)
30128 // this has strange effects when using with
30129 // top toolbar - not sure if it's a great idea.
30130 //this.editor.contentWindow.focus();
30131 if (typeof sel != "undefined") {
30133 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
30135 return this.doc.createRange();
30138 return this.doc.createRange();
30141 getParentElement: function()
30144 this.assignDocWin();
30145 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
30147 var range = this.createRange(sel);
30150 var p = range.commonAncestorContainer;
30151 while (p.nodeType == 3) { // text node
30162 * Range intersection.. the hard stuff...
30166 * [ -- selected range --- ]
30170 * if end is before start or hits it. fail.
30171 * if start is after end or hits it fail.
30173 * if either hits (but other is outside. - then it's not
30179 // @see http://www.thismuchiknow.co.uk/?p=64.
30180 rangeIntersectsNode : function(range, node)
30182 var nodeRange = node.ownerDocument.createRange();
30184 nodeRange.selectNode(node);
30186 nodeRange.selectNodeContents(node);
30189 var rangeStartRange = range.cloneRange();
30190 rangeStartRange.collapse(true);
30192 var rangeEndRange = range.cloneRange();
30193 rangeEndRange.collapse(false);
30195 var nodeStartRange = nodeRange.cloneRange();
30196 nodeStartRange.collapse(true);
30198 var nodeEndRange = nodeRange.cloneRange();
30199 nodeEndRange.collapse(false);
30201 return rangeStartRange.compareBoundaryPoints(
30202 Range.START_TO_START, nodeEndRange) == -1 &&
30203 rangeEndRange.compareBoundaryPoints(
30204 Range.START_TO_START, nodeStartRange) == 1;
30208 rangeCompareNode : function(range, node)
30210 var nodeRange = node.ownerDocument.createRange();
30212 nodeRange.selectNode(node);
30214 nodeRange.selectNodeContents(node);
30218 range.collapse(true);
30220 nodeRange.collapse(true);
30222 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
30223 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
30225 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
30227 var nodeIsBefore = ss == 1;
30228 var nodeIsAfter = ee == -1;
30230 if (nodeIsBefore && nodeIsAfter) {
30233 if (!nodeIsBefore && nodeIsAfter) {
30234 return 1; //right trailed.
30237 if (nodeIsBefore && !nodeIsAfter) {
30238 return 2; // left trailed.
30244 cleanWordChars : function(input) {// change the chars to hex code
30247 [ 8211, "–" ],
30248 [ 8212, "—" ],
30256 var output = input;
30257 Roo.each(swapCodes, function(sw) {
30258 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
30260 output = output.replace(swapper, sw[1]);
30270 cleanUpChild : function (node)
30273 new Roo.htmleditor.FilterComment({node : node});
30274 new Roo.htmleditor.FilterAttributes({
30276 attrib_black : this.ablack,
30277 attrib_clean : this.aclean,
30278 style_white : this.cwhite,
30279 style_black : this.cblack
30281 new Roo.htmleditor.FilterBlack({ node : node, tag : this.black});
30282 new Roo.htmleditor.FilterKeepChildren({node : node, tag : this.tag_remove} );
30288 * Clean up MS wordisms...
30289 * @deprecated - use filter directly
30291 cleanWord : function(node)
30293 new Roo.htmleditor.FilterWord({ node : node ? node : this.doc.body });
30294 new Roo.htmleditor.FilterKeepChildren({node : node ? node : this.doc.body, tag : [ 'FONT', ':' ]} );
30301 * @deprecated - use filters
30303 cleanTableWidths : function(node)
30305 new Roo.htmleditor.FilterTableWidth({ node : node ? node : this.doc.body});
30312 applyBlacklists : function()
30314 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
30315 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
30317 this.aclean = typeof(this.owner.aclean) != 'undefined' && this.owner.aclean ? this.owner.aclean : Roo.HtmlEditorCore.aclean;
30318 this.ablack = typeof(this.owner.ablack) != 'undefined' && this.owner.ablack ? this.owner.ablack : Roo.HtmlEditorCore.ablack;
30319 this.tag_remove = typeof(this.owner.tag_remove) != 'undefined' && this.owner.tag_remove ? this.owner.tag_remove : Roo.HtmlEditorCore.tag_remove;
30323 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
30324 if (b.indexOf(tag) > -1) {
30327 this.white.push(tag);
30331 Roo.each(w, function(tag) {
30332 if (b.indexOf(tag) > -1) {
30335 if (this.white.indexOf(tag) > -1) {
30338 this.white.push(tag);
30343 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
30344 if (w.indexOf(tag) > -1) {
30347 this.black.push(tag);
30351 Roo.each(b, function(tag) {
30352 if (w.indexOf(tag) > -1) {
30355 if (this.black.indexOf(tag) > -1) {
30358 this.black.push(tag);
30363 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
30364 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
30368 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
30369 if (b.indexOf(tag) > -1) {
30372 this.cwhite.push(tag);
30376 Roo.each(w, function(tag) {
30377 if (b.indexOf(tag) > -1) {
30380 if (this.cwhite.indexOf(tag) > -1) {
30383 this.cwhite.push(tag);
30388 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
30389 if (w.indexOf(tag) > -1) {
30392 this.cblack.push(tag);
30396 Roo.each(b, function(tag) {
30397 if (w.indexOf(tag) > -1) {
30400 if (this.cblack.indexOf(tag) > -1) {
30403 this.cblack.push(tag);
30408 setStylesheets : function(stylesheets)
30410 if(typeof(stylesheets) == 'string'){
30411 Roo.get(this.iframe.contentDocument.head).createChild({
30413 rel : 'stylesheet',
30422 Roo.each(stylesheets, function(s) {
30427 Roo.get(_this.iframe.contentDocument.head).createChild({
30429 rel : 'stylesheet',
30439 updateLanguage : function()
30441 if (!this.iframe || !this.iframe.contentDocument) {
30444 Roo.get(this.iframe.contentDocument.body).attr("lang", this.language);
30448 removeStylesheets : function()
30452 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
30457 setStyle : function(style)
30459 Roo.get(this.iframe.contentDocument.head).createChild({
30468 // hide stuff that is not compatible
30482 * @event specialkey
30486 * @cfg {String} fieldClass @hide
30489 * @cfg {String} focusClass @hide
30492 * @cfg {String} autoCreate @hide
30495 * @cfg {String} inputType @hide
30498 * @cfg {String} invalidClass @hide
30501 * @cfg {String} invalidText @hide
30504 * @cfg {String} msgFx @hide
30507 * @cfg {String} validateOnBlur @hide
30511 Roo.HtmlEditorCore.white = [
30512 'AREA', 'BR', 'IMG', 'INPUT', 'HR', 'WBR',
30514 'ADDRESS', 'BLOCKQUOTE', 'CENTER', 'DD', 'DIR', 'DIV',
30515 'DL', 'DT', 'H1', 'H2', 'H3', 'H4',
30516 'H5', 'H6', 'HR', 'ISINDEX', 'LISTING', 'MARQUEE',
30517 'MENU', 'MULTICOL', 'OL', 'P', 'PLAINTEXT', 'PRE',
30518 'TABLE', 'UL', 'XMP',
30520 'CAPTION', 'COL', 'COLGROUP', 'TBODY', 'TD', 'TFOOT', 'TH',
30523 'DIR', 'MENU', 'OL', 'UL', 'DL',
30529 Roo.HtmlEditorCore.black = [
30530 // 'embed', 'object', // enable - backend responsiblity to clean thiese
30532 'BASE', 'BASEFONT', 'BGSOUND', 'BLINK', 'BODY',
30533 'FRAME', 'FRAMESET', 'HEAD', 'HTML', 'ILAYER',
30534 'IFRAME', 'LAYER', 'LINK', 'META', 'OBJECT',
30535 'SCRIPT', 'STYLE' ,'TITLE', 'XML',
30536 //'FONT' // CLEAN LATER..
30537 'COLGROUP', 'COL' // messy tables.
30541 Roo.HtmlEditorCore.clean = [ // ?? needed???
30542 'SCRIPT', 'STYLE', 'TITLE', 'XML'
30544 Roo.HtmlEditorCore.tag_remove = [
30549 Roo.HtmlEditorCore.ablack = [
30553 Roo.HtmlEditorCore.aclean = [
30554 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
30558 Roo.HtmlEditorCore.pwhite= [
30559 'http', 'https', 'mailto'
30562 // white listed style attributes.
30563 Roo.HtmlEditorCore.cwhite= [
30564 // 'text-align', /// default is to allow most things..
30570 // black listed style attributes.
30571 Roo.HtmlEditorCore.cblack= [
30572 // 'font-size' -- this can be set by the project
30586 * @class Roo.bootstrap.form.HtmlEditor
30587 * @extends Roo.bootstrap.form.TextArea
30588 * Bootstrap HtmlEditor class
30591 * Create a new HtmlEditor
30592 * @param {Object} config The config object
30595 Roo.bootstrap.form.HtmlEditor = function(config){
30596 Roo.bootstrap.form.HtmlEditor.superclass.constructor.call(this, config);
30597 if (!this.toolbars) {
30598 this.toolbars = [];
30601 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
30604 * @event initialize
30605 * Fires when the editor is fully initialized (including the iframe)
30606 * @param {HtmlEditor} this
30611 * Fires when the editor is first receives the focus. Any insertion must wait
30612 * until after this event.
30613 * @param {HtmlEditor} this
30617 * @event beforesync
30618 * Fires before the textarea is updated with content from the editor iframe. Return false
30619 * to cancel the sync.
30620 * @param {HtmlEditor} this
30621 * @param {String} html
30625 * @event beforepush
30626 * Fires before the iframe editor is updated with content from the textarea. Return false
30627 * to cancel the push.
30628 * @param {HtmlEditor} this
30629 * @param {String} html
30634 * Fires when the textarea is updated with content from the editor iframe.
30635 * @param {HtmlEditor} this
30636 * @param {String} html
30641 * Fires when the iframe editor is updated with content from the textarea.
30642 * @param {HtmlEditor} this
30643 * @param {String} html
30647 * @event editmodechange
30648 * Fires when the editor switches edit modes
30649 * @param {HtmlEditor} this
30650 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
30652 editmodechange: true,
30654 * @event editorevent
30655 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
30656 * @param {HtmlEditor} this
30660 * @event firstfocus
30661 * Fires when on first focus - needed by toolbars..
30662 * @param {HtmlEditor} this
30667 * Auto save the htmlEditor value as a file into Events
30668 * @param {HtmlEditor} this
30672 * @event savedpreview
30673 * preview the saved version of htmlEditor
30674 * @param {HtmlEditor} this
30681 Roo.extend(Roo.bootstrap.form.HtmlEditor, Roo.bootstrap.form.TextArea, {
30685 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
30690 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
30695 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
30700 * @cfg {Number} height (in pixels)
30704 * @cfg {Number} width (in pixels)
30709 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
30712 stylesheets: false,
30717 // private properties
30718 validationEvent : false,
30720 initialized : false,
30723 onFocus : Roo.emptyFn,
30725 hideMode:'offsets',
30727 tbContainer : false,
30731 toolbarContainer :function() {
30732 return this.wrap.select('.x-html-editor-tb',true).first();
30736 * Protected method that will not generally be called directly. It
30737 * is called when the editor creates its toolbar. Override this method if you need to
30738 * add custom toolbar buttons.
30739 * @param {HtmlEditor} editor
30741 createToolbar : function(){
30742 Roo.log('renewing');
30743 Roo.log("create toolbars");
30745 this.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard({editor: this} ) ];
30746 this.toolbars[0].render(this.toolbarContainer());
30750 // if (!editor.toolbars || !editor.toolbars.length) {
30751 // editor.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard() ]; // can be empty?
30754 // for (var i =0 ; i < editor.toolbars.length;i++) {
30755 // editor.toolbars[i] = Roo.factory(
30756 // typeof(editor.toolbars[i]) == 'string' ?
30757 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
30758 // Roo.bootstrap.form.HtmlEditor);
30759 // editor.toolbars[i].init(editor);
30765 onRender : function(ct, position)
30767 // Roo.log("Call onRender: " + this.xtype);
30769 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
30771 this.wrap = this.inputEl().wrap({
30772 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
30775 this.editorcore.onRender(ct, position);
30777 if (this.resizable) {
30778 this.resizeEl = new Roo.Resizable(this.wrap, {
30782 minHeight : this.height,
30783 height: this.height,
30784 handles : this.resizable,
30787 resize : function(r, w, h) {
30788 _t.onResize(w,h); // -something
30794 this.createToolbar(this);
30797 if(!this.width && this.resizable){
30798 this.setSize(this.wrap.getSize());
30800 if (this.resizeEl) {
30801 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
30802 // should trigger onReize..
30808 onResize : function(w, h)
30810 Roo.log('resize: ' +w + ',' + h );
30811 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
30815 if(this.inputEl() ){
30816 if(typeof w == 'number'){
30817 var aw = w - this.wrap.getFrameWidth('lr');
30818 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
30821 if(typeof h == 'number'){
30822 var tbh = -11; // fixme it needs to tool bar size!
30823 for (var i =0; i < this.toolbars.length;i++) {
30824 // fixme - ask toolbars for heights?
30825 tbh += this.toolbars[i].el.getHeight();
30826 //if (this.toolbars[i].footer) {
30827 // tbh += this.toolbars[i].footer.el.getHeight();
30835 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
30836 ah -= 5; // knock a few pixes off for look..
30837 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
30841 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
30842 this.editorcore.onResize(ew,eh);
30847 * Toggles the editor between standard and source edit mode.
30848 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
30850 toggleSourceEdit : function(sourceEditMode)
30852 this.editorcore.toggleSourceEdit(sourceEditMode);
30854 if(this.editorcore.sourceEditMode){
30855 Roo.log('editor - showing textarea');
30858 // Roo.log(this.syncValue());
30860 this.inputEl().removeClass(['hide', 'x-hidden']);
30861 this.inputEl().dom.removeAttribute('tabIndex');
30862 this.inputEl().focus();
30864 Roo.log('editor - hiding textarea');
30866 // Roo.log(this.pushValue());
30869 this.inputEl().addClass(['hide', 'x-hidden']);
30870 this.inputEl().dom.setAttribute('tabIndex', -1);
30871 //this.deferFocus();
30874 if(this.resizable){
30875 this.setSize(this.wrap.getSize());
30878 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
30881 // private (for BoxComponent)
30882 adjustSize : Roo.BoxComponent.prototype.adjustSize,
30884 // private (for BoxComponent)
30885 getResizeEl : function(){
30889 // private (for BoxComponent)
30890 getPositionEl : function(){
30895 initEvents : function(){
30896 this.originalValue = this.getValue();
30900 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
30903 // markInvalid : Roo.emptyFn,
30905 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
30908 // clearInvalid : Roo.emptyFn,
30910 setValue : function(v){
30911 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
30912 this.editorcore.pushValue();
30917 deferFocus : function(){
30918 this.focus.defer(10, this);
30922 focus : function(){
30923 this.editorcore.focus();
30929 onDestroy : function(){
30935 for (var i =0; i < this.toolbars.length;i++) {
30936 // fixme - ask toolbars for heights?
30937 this.toolbars[i].onDestroy();
30940 this.wrap.dom.innerHTML = '';
30941 this.wrap.remove();
30946 onFirstFocus : function(){
30947 //Roo.log("onFirstFocus");
30948 this.editorcore.onFirstFocus();
30949 for (var i =0; i < this.toolbars.length;i++) {
30950 this.toolbars[i].onFirstFocus();
30956 syncValue : function()
30958 this.editorcore.syncValue();
30961 pushValue : function()
30963 this.editorcore.pushValue();
30967 // hide stuff that is not compatible
30981 * @event specialkey
30985 * @cfg {String} fieldClass @hide
30988 * @cfg {String} focusClass @hide
30991 * @cfg {String} autoCreate @hide
30994 * @cfg {String} inputType @hide
30998 * @cfg {String} invalidText @hide
31001 * @cfg {String} msgFx @hide
31004 * @cfg {String} validateOnBlur @hide
31013 Roo.namespace('Roo.bootstrap.form.HtmlEditor');
31015 * @class Roo.bootstrap.form.HtmlEditorToolbarStandard
31016 * @parent Roo.bootstrap.form.HtmlEditor
31017 * @extends Roo.bootstrap.nav.Simplebar
31023 new Roo.bootstrap.form.HtmlEditor({
31026 new Roo.bootstrap.form.HtmlEditorToolbarStandard({
31027 disable : { fonts: 1 , format: 1, ..., ... , ...],
31033 * @cfg {Object} disable List of elements to disable..
31034 * @cfg {Array} btns List of additional buttons.
31038 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
31041 Roo.bootstrap.form.HtmlEditorToolbarStandard = function(config)
31044 Roo.apply(this, config);
31046 // default disabled, based on 'good practice'..
31047 this.disable = this.disable || {};
31048 Roo.applyIf(this.disable, {
31051 specialElements : true
31053 Roo.bootstrap.form.HtmlEditorToolbarStandard.superclass.constructor.call(this, config);
31055 this.editor = config.editor;
31056 this.editorcore = config.editor.editorcore;
31058 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
31060 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
31061 // dont call parent... till later.
31063 Roo.extend(Roo.bootstrap.form.HtmlEditorToolbarStandard, Roo.bootstrap.nav.Simplebar, {
31068 editorcore : false,
31073 "h1","h2","h3","h4","h5","h6",
31075 "abbr", "acronym", "address", "cite", "samp", "var",
31079 onRender : function(ct, position)
31081 // Roo.log("Call onRender: " + this.xtype);
31083 Roo.bootstrap.form.HtmlEditorToolbarStandard.superclass.onRender.call(this, ct, position);
31085 this.el.dom.style.marginBottom = '0';
31087 var editorcore = this.editorcore;
31088 var editor= this.editor;
31091 var btn = function(id,cmd , toggle, handler, html){
31093 var event = toggle ? 'toggle' : 'click';
31098 xns: Roo.bootstrap,
31102 enableToggle:toggle !== false,
31104 pressed : toggle ? false : null,
31107 a.listeners[toggle ? 'toggle' : 'click'] = function() {
31108 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
31114 // var cb_box = function...
31119 xns: Roo.bootstrap,
31124 xns: Roo.bootstrap,
31128 Roo.each(this.formats, function(f) {
31129 style.menu.items.push({
31131 xns: Roo.bootstrap,
31132 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
31137 editorcore.insertTag(this.tagname);
31144 children.push(style);
31146 btn('bold',false,true);
31147 btn('italic',false,true);
31148 btn('align-left', 'justifyleft',true);
31149 btn('align-center', 'justifycenter',true);
31150 btn('align-right' , 'justifyright',true);
31151 btn('link', false, false, function(btn) {
31152 //Roo.log("create link?");
31153 var url = prompt(this.createLinkText, this.defaultLinkValue);
31154 if(url && url != 'http:/'+'/'){
31155 this.editorcore.relayCmd('createlink', url);
31158 btn('list','insertunorderedlist',true);
31159 btn('pencil', false,true, function(btn){
31161 this.toggleSourceEdit(btn.pressed);
31164 if (this.editor.btns.length > 0) {
31165 for (var i = 0; i<this.editor.btns.length; i++) {
31166 children.push(this.editor.btns[i]);
31174 xns: Roo.bootstrap,
31179 xns: Roo.bootstrap,
31184 cog.menu.items.push({
31186 xns: Roo.bootstrap,
31187 html : Clean styles,
31192 editorcore.insertTag(this.tagname);
31201 this.xtype = 'NavSimplebar';
31203 for(var i=0;i< children.length;i++) {
31205 this.buttons.add(this.addxtypeChild(children[i]));
31209 editor.on('editorevent', this.updateToolbar, this);
31211 onBtnClick : function(id)
31213 this.editorcore.relayCmd(id);
31214 this.editorcore.focus();
31218 * Protected method that will not generally be called directly. It triggers
31219 * a toolbar update by reading the markup state of the current selection in the editor.
31221 updateToolbar: function(){
31223 if(!this.editorcore.activated){
31224 this.editor.onFirstFocus(); // is this neeed?
31228 var btns = this.buttons;
31229 var doc = this.editorcore.doc;
31230 btns.get('bold').setActive(doc.queryCommandState('bold'));
31231 btns.get('italic').setActive(doc.queryCommandState('italic'));
31232 //btns.get('underline').setActive(doc.queryCommandState('underline'));
31234 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
31235 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
31236 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
31238 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
31239 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
31242 var ans = this.editorcore.getAllAncestors();
31243 if (this.formatCombo) {
31246 var store = this.formatCombo.store;
31247 this.formatCombo.setValue("");
31248 for (var i =0; i < ans.length;i++) {
31249 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
31251 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
31259 // hides menus... - so this cant be on a menu...
31260 Roo.bootstrap.MenuMgr.hideAll();
31262 Roo.bootstrap.menu.Manager.hideAll();
31263 //this.editorsyncValue();
31265 onFirstFocus: function() {
31266 this.buttons.each(function(item){
31270 toggleSourceEdit : function(sourceEditMode){
31273 if(sourceEditMode){
31274 Roo.log("disabling buttons");
31275 this.buttons.each( function(item){
31276 if(item.cmd != 'pencil'){
31282 Roo.log("enabling buttons");
31283 if(this.editorcore.initialized){
31284 this.buttons.each( function(item){
31290 Roo.log("calling toggole on editor");
31291 // tell the editor that it's been pressed..
31292 this.editor.toggleSourceEdit(sourceEditMode);
31306 * @class Roo.bootstrap.form.Markdown
31307 * @extends Roo.bootstrap.form.TextArea
31308 * Bootstrap Showdown editable area
31309 * @cfg {string} content
31312 * Create a new Showdown
31315 Roo.bootstrap.form.Markdown = function(config){
31316 Roo.bootstrap.form.Markdown.superclass.constructor.call(this, config);
31320 Roo.extend(Roo.bootstrap.form.Markdown, Roo.bootstrap.form.TextArea, {
31324 initEvents : function()
31327 Roo.bootstrap.form.TextArea.prototype.initEvents.call(this);
31328 this.markdownEl = this.el.createChild({
31329 cls : 'roo-markdown-area'
31331 this.inputEl().addClass('d-none');
31332 if (this.getValue() == '') {
31333 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
31336 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
31338 this.markdownEl.on('click', this.toggleTextEdit, this);
31339 this.on('blur', this.toggleTextEdit, this);
31340 this.on('specialkey', this.resizeTextArea, this);
31343 toggleTextEdit : function()
31345 var sh = this.markdownEl.getHeight();
31346 this.inputEl().addClass('d-none');
31347 this.markdownEl.addClass('d-none');
31348 if (!this.editing) {
31350 this.inputEl().setHeight(Math.min(500, Math.max(sh,(this.getValue().split("\n").length+1) * 30)));
31351 this.inputEl().removeClass('d-none');
31352 this.inputEl().focus();
31353 this.editing = true;
31356 // show showdown...
31357 this.updateMarkdown();
31358 this.markdownEl.removeClass('d-none');
31359 this.editing = false;
31362 updateMarkdown : function()
31364 if (this.getValue() == '') {
31365 this.markdownEl.dom.innerHTML = String.format('<span class="roo-placeholder">{0}</span>', this.placeholder || '');
31369 this.markdownEl.dom.innerHTML = Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));
31372 resizeTextArea: function () {
31375 Roo.log([sh, this.getValue().split("\n").length * 30]);
31376 this.inputEl().setHeight(Math.min(500, Math.max(sh, (this.getValue().split("\n").length +1) * 30)));
31378 setValue : function(val)
31380 Roo.bootstrap.form.TextArea.prototype.setValue.call(this,val);
31381 if (!this.editing) {
31382 this.updateMarkdown();
31388 if (!this.editing) {
31389 this.toggleTextEdit();
31397 * Ext JS Library 1.1.1
31398 * Copyright(c) 2006-2007, Ext JS, LLC.
31400 * Originally Released Under LGPL - original licence link has changed is not relivant.
31403 * <script type="text/javascript">
31407 * @class Roo.bootstrap.PagingToolbar
31408 * @extends Roo.bootstrap.nav.Simplebar
31409 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
31411 * Create a new PagingToolbar
31412 * @param {Object} config The config object
31413 * @param {Roo.data.Store} store
31415 Roo.bootstrap.PagingToolbar = function(config)
31417 // old args format still supported... - xtype is prefered..
31418 // created from xtype...
31420 this.ds = config.dataSource;
31422 if (config.store && !this.ds) {
31423 this.store= Roo.factory(config.store, Roo.data);
31424 this.ds = this.store;
31425 this.ds.xmodule = this.xmodule || false;
31428 this.toolbarItems = [];
31429 if (config.items) {
31430 this.toolbarItems = config.items;
31433 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
31438 this.bind(this.ds);
31441 if (Roo.bootstrap.version == 4) {
31442 this.navgroup = new Roo.bootstrap.ButtonGroup({ cls: 'pagination' });
31444 this.navgroup = new Roo.bootstrap.nav.Group({ cls: 'pagination' });
31449 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.nav.Simplebar, {
31451 * @cfg {Roo.bootstrap.Button} buttons[]
31452 * Buttons for the toolbar
31455 * @cfg {Roo.data.Store} store
31456 * The underlying data store providing the paged data
31459 * @cfg {String/HTMLElement/Element} container
31460 * container The id or element that will contain the toolbar
31463 * @cfg {Boolean} displayInfo
31464 * True to display the displayMsg (defaults to false)
31467 * @cfg {Number} pageSize
31468 * The number of records to display per page (defaults to 20)
31472 * @cfg {String} displayMsg
31473 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
31475 displayMsg : 'Displaying {0} - {1} of {2}',
31477 * @cfg {String} emptyMsg
31478 * The message to display when no records are found (defaults to "No data to display")
31480 emptyMsg : 'No data to display',
31482 * Customizable piece of the default paging text (defaults to "Page")
31485 beforePageText : "Page",
31487 * Customizable piece of the default paging text (defaults to "of %0")
31490 afterPageText : "of {0}",
31492 * Customizable piece of the default paging text (defaults to "First Page")
31495 firstText : "First Page",
31497 * Customizable piece of the default paging text (defaults to "Previous Page")
31500 prevText : "Previous Page",
31502 * Customizable piece of the default paging text (defaults to "Next Page")
31505 nextText : "Next Page",
31507 * Customizable piece of the default paging text (defaults to "Last Page")
31510 lastText : "Last Page",
31512 * Customizable piece of the default paging text (defaults to "Refresh")
31515 refreshText : "Refresh",
31519 onRender : function(ct, position)
31521 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
31522 this.navgroup.parentId = this.id;
31523 this.navgroup.onRender(this.el, null);
31524 // add the buttons to the navgroup
31526 if(this.displayInfo){
31527 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
31528 this.displayEl = this.el.select('.x-paging-info', true).first();
31529 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
31530 // this.displayEl = navel.el.select('span',true).first();
31536 Roo.each(_this.buttons, function(e){ // this might need to use render????
31537 Roo.factory(e).render(_this.el);
31541 Roo.each(_this.toolbarItems, function(e) {
31542 _this.navgroup.addItem(e);
31546 this.first = this.navgroup.addItem({
31547 tooltip: this.firstText,
31548 cls: "prev btn-outline-secondary",
31549 html : ' <i class="fa fa-step-backward"></i>',
31551 preventDefault: true,
31552 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
31555 this.prev = this.navgroup.addItem({
31556 tooltip: this.prevText,
31557 cls: "prev btn-outline-secondary",
31558 html : ' <i class="fa fa-backward"></i>',
31560 preventDefault: true,
31561 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
31563 //this.addSeparator();
31566 var field = this.navgroup.addItem( {
31568 cls : 'x-paging-position btn-outline-secondary',
31570 html : this.beforePageText +
31571 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
31572 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
31575 this.field = field.el.select('input', true).first();
31576 this.field.on("keydown", this.onPagingKeydown, this);
31577 this.field.on("focus", function(){this.dom.select();});
31580 this.afterTextEl = field.el.select('.x-paging-after',true).first();
31581 //this.field.setHeight(18);
31582 //this.addSeparator();
31583 this.next = this.navgroup.addItem({
31584 tooltip: this.nextText,
31585 cls: "next btn-outline-secondary",
31586 html : ' <i class="fa fa-forward"></i>',
31588 preventDefault: true,
31589 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
31591 this.last = this.navgroup.addItem({
31592 tooltip: this.lastText,
31593 html : ' <i class="fa fa-step-forward"></i>',
31594 cls: "next btn-outline-secondary",
31596 preventDefault: true,
31597 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
31599 //this.addSeparator();
31600 this.loading = this.navgroup.addItem({
31601 tooltip: this.refreshText,
31602 cls: "btn-outline-secondary",
31603 html : ' <i class="fa fa-refresh"></i>',
31604 preventDefault: true,
31605 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
31611 updateInfo : function(){
31612 if(this.displayEl){
31613 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
31614 var msg = count == 0 ?
31618 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
31620 this.displayEl.update(msg);
31625 onLoad : function(ds, r, o)
31627 this.cursor = o.params && o.params.start ? o.params.start : 0;
31629 var d = this.getPageData(),
31634 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
31635 this.field.dom.value = ap;
31636 this.first.setDisabled(ap == 1);
31637 this.prev.setDisabled(ap == 1);
31638 this.next.setDisabled(ap == ps);
31639 this.last.setDisabled(ap == ps);
31640 this.loading.enable();
31645 getPageData : function(){
31646 var total = this.ds.getTotalCount();
31649 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
31650 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
31655 onLoadError : function(proxy, o){
31656 this.loading.enable();
31657 if (this.ds.events.loadexception.listeners.length < 2) {
31658 // nothing has been assigned to loadexception except this...
31660 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
31666 onPagingKeydown : function(e){
31667 var k = e.getKey();
31668 var d = this.getPageData();
31670 var v = this.field.dom.value, pageNum;
31671 if(!v || isNaN(pageNum = parseInt(v, 10))){
31672 this.field.dom.value = d.activePage;
31675 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
31676 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
31679 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))
31681 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
31682 this.field.dom.value = pageNum;
31683 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
31686 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
31688 var v = this.field.dom.value, pageNum;
31689 var increment = (e.shiftKey) ? 10 : 1;
31690 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
31693 if(!v || isNaN(pageNum = parseInt(v, 10))) {
31694 this.field.dom.value = d.activePage;
31697 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
31699 this.field.dom.value = parseInt(v, 10) + increment;
31700 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
31701 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
31708 beforeLoad : function(){
31710 this.loading.disable();
31715 onClick : function(which){
31724 ds.load({params:{start: 0, limit: this.pageSize}});
31727 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
31730 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
31733 var total = ds.getTotalCount();
31734 var extra = total % this.pageSize;
31735 var lastStart = extra ? (total - extra) : total-this.pageSize;
31736 ds.load({params:{start: lastStart, limit: this.pageSize}});
31739 ds.load({params:{start: this.cursor, limit: this.pageSize}});
31745 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
31746 * @param {Roo.data.Store} store The data store to unbind
31748 unbind : function(ds){
31749 ds.un("beforeload", this.beforeLoad, this);
31750 ds.un("load", this.onLoad, this);
31751 ds.un("loadexception", this.onLoadError, this);
31752 ds.un("remove", this.updateInfo, this);
31753 ds.un("add", this.updateInfo, this);
31754 this.ds = undefined;
31758 * Binds the paging toolbar to the specified {@link Roo.data.Store}
31759 * @param {Roo.data.Store} store The data store to bind
31761 bind : function(ds){
31762 ds.on("beforeload", this.beforeLoad, this);
31763 ds.on("load", this.onLoad, this);
31764 ds.on("loadexception", this.onLoadError, this);
31765 ds.on("remove", this.updateInfo, this);
31766 ds.on("add", this.updateInfo, this);
31777 * @class Roo.bootstrap.MessageBar
31778 * @extends Roo.bootstrap.Component
31779 * Bootstrap MessageBar class
31780 * @cfg {String} html contents of the MessageBar
31781 * @cfg {String} weight (info | success | warning | danger) default info
31782 * @cfg {String} beforeClass insert the bar before the given class
31783 * @cfg {Boolean} closable (true | false) default false
31784 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
31787 * Create a new Element
31788 * @param {Object} config The config object
31791 Roo.bootstrap.MessageBar = function(config){
31792 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
31795 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
31801 beforeClass: 'bootstrap-sticky-wrap',
31803 getAutoCreate : function(){
31807 cls: 'alert alert-dismissable alert-' + this.weight,
31812 html: this.html || ''
31818 cfg.cls += ' alert-messages-fixed';
31832 onRender : function(ct, position)
31834 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
31837 var cfg = Roo.apply({}, this.getAutoCreate());
31841 cfg.cls += ' ' + this.cls;
31844 cfg.style = this.style;
31846 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
31848 this.el.setVisibilityMode(Roo.Element.DISPLAY);
31851 this.el.select('>button.close').on('click', this.hide, this);
31857 if (!this.rendered) {
31863 this.fireEvent('show', this);
31869 if (!this.rendered) {
31875 this.fireEvent('hide', this);
31878 update : function()
31880 // var e = this.el.dom.firstChild;
31882 // if(this.closable){
31883 // e = e.nextSibling;
31886 // e.data = this.html || '';
31888 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
31904 * @class Roo.bootstrap.Graph
31905 * @extends Roo.bootstrap.Component
31906 * Bootstrap Graph class
31910 @cfg {String} graphtype bar | vbar | pie
31911 @cfg {number} g_x coodinator | centre x (pie)
31912 @cfg {number} g_y coodinator | centre y (pie)
31913 @cfg {number} g_r radius (pie)
31914 @cfg {number} g_height height of the chart (respected by all elements in the set)
31915 @cfg {number} g_width width of the chart (respected by all elements in the set)
31916 @cfg {Object} title The title of the chart
31919 -opts (object) options for the chart
31921 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
31922 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
31924 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.
31925 o stacked (boolean) whether or not to tread values as in a stacked bar chart
31927 o stretch (boolean)
31929 -opts (object) options for the pie
31932 o startAngle (number)
31933 o endAngle (number)
31937 * Create a new Input
31938 * @param {Object} config The config object
31941 Roo.bootstrap.Graph = function(config){
31942 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
31948 * The img click event for the img.
31949 * @param {Roo.EventObject} e
31955 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
31966 //g_colors: this.colors,
31973 getAutoCreate : function(){
31984 onRender : function(ct,position){
31987 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
31989 if (typeof(Raphael) == 'undefined') {
31990 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
31994 this.raphael = Raphael(this.el.dom);
31996 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
31997 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
31998 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
31999 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
32001 r.text(160, 10, "Single Series Chart").attr(txtattr);
32002 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
32003 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
32004 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
32006 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
32007 r.barchart(330, 10, 300, 220, data1);
32008 r.barchart(10, 250, 300, 220, data2, {stacked: true});
32009 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
32012 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
32013 // r.barchart(30, 30, 560, 250, xdata, {
32014 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
32015 // axis : "0 0 1 1",
32016 // axisxlabels : xdata
32017 // //yvalues : cols,
32020 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
32022 // this.load(null,xdata,{
32023 // axis : "0 0 1 1",
32024 // axisxlabels : xdata
32029 load : function(graphtype,xdata,opts)
32031 this.raphael.clear();
32033 graphtype = this.graphtype;
32038 var r = this.raphael,
32039 fin = function () {
32040 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
32042 fout = function () {
32043 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
32045 pfin = function() {
32046 this.sector.stop();
32047 this.sector.scale(1.1, 1.1, this.cx, this.cy);
32050 this.label[0].stop();
32051 this.label[0].attr({ r: 7.5 });
32052 this.label[1].attr({ "font-weight": 800 });
32055 pfout = function() {
32056 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
32059 this.label[0].animate({ r: 5 }, 500, "bounce");
32060 this.label[1].attr({ "font-weight": 400 });
32066 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
32069 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
32072 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
32073 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
32075 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
32082 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
32087 setTitle: function(o)
32092 initEvents: function() {
32095 this.el.on('click', this.onClick, this);
32099 onClick : function(e)
32101 Roo.log('img onclick');
32102 this.fireEvent('click', this, e);
32108 Roo.bootstrap.dash = {};/*
32114 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
32117 * @class Roo.bootstrap.dash.NumberBox
32118 * @extends Roo.bootstrap.Component
32119 * Bootstrap NumberBox class
32120 * @cfg {String} headline Box headline
32121 * @cfg {String} content Box content
32122 * @cfg {String} icon Box icon
32123 * @cfg {String} footer Footer text
32124 * @cfg {String} fhref Footer href
32127 * Create a new NumberBox
32128 * @param {Object} config The config object
32132 Roo.bootstrap.dash.NumberBox = function(config){
32133 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
32137 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
32146 getAutoCreate : function(){
32150 cls : 'small-box ',
32158 cls : 'roo-headline',
32159 html : this.headline
32163 cls : 'roo-content',
32164 html : this.content
32178 cls : 'ion ' + this.icon
32187 cls : 'small-box-footer',
32188 href : this.fhref || '#',
32192 cfg.cn.push(footer);
32199 onRender : function(ct,position){
32200 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
32207 setHeadline: function (value)
32209 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
32212 setFooter: function (value, href)
32214 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
32217 this.el.select('a.small-box-footer',true).first().attr('href', href);
32222 setContent: function (value)
32224 this.el.select('.roo-content',true).first().dom.innerHTML = value;
32227 initEvents: function()
32241 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
32244 * @class Roo.bootstrap.dash.TabBox
32245 * @extends Roo.bootstrap.Component
32246 * @children Roo.bootstrap.dash.TabPane
32247 * Bootstrap TabBox class
32248 * @cfg {String} title Title of the TabBox
32249 * @cfg {String} icon Icon of the TabBox
32250 * @cfg {Boolean} showtabs (true|false) show the tabs default true
32251 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
32254 * Create a new TabBox
32255 * @param {Object} config The config object
32259 Roo.bootstrap.dash.TabBox = function(config){
32260 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
32265 * When a pane is added
32266 * @param {Roo.bootstrap.dash.TabPane} pane
32270 * @event activatepane
32271 * When a pane is activated
32272 * @param {Roo.bootstrap.dash.TabPane} pane
32274 "activatepane" : true
32282 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
32287 tabScrollable : false,
32289 getChildContainer : function()
32291 return this.el.select('.tab-content', true).first();
32294 getAutoCreate : function(){
32298 cls: 'pull-left header',
32306 cls: 'fa ' + this.icon
32312 cls: 'nav nav-tabs pull-right',
32318 if(this.tabScrollable){
32325 cls: 'nav nav-tabs pull-right',
32336 cls: 'nav-tabs-custom',
32341 cls: 'tab-content no-padding',
32349 initEvents : function()
32351 //Roo.log('add add pane handler');
32352 this.on('addpane', this.onAddPane, this);
32355 * Updates the box title
32356 * @param {String} html to set the title to.
32358 setTitle : function(value)
32360 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
32362 onAddPane : function(pane)
32364 this.panes.push(pane);
32365 //Roo.log('addpane');
32367 // tabs are rendere left to right..
32368 if(!this.showtabs){
32372 var ctr = this.el.select('.nav-tabs', true).first();
32375 var existing = ctr.select('.nav-tab',true);
32376 var qty = existing.getCount();;
32379 var tab = ctr.createChild({
32381 cls : 'nav-tab' + (qty ? '' : ' active'),
32389 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
32392 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
32394 pane.el.addClass('active');
32399 onTabClick : function(ev,un,ob,pane)
32401 //Roo.log('tab - prev default');
32402 ev.preventDefault();
32405 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
32406 pane.tab.addClass('active');
32407 //Roo.log(pane.title);
32408 this.getChildContainer().select('.tab-pane',true).removeClass('active');
32409 // technically we should have a deactivate event.. but maybe add later.
32410 // and it should not de-activate the selected tab...
32411 this.fireEvent('activatepane', pane);
32412 pane.el.addClass('active');
32413 pane.fireEvent('activate');
32418 getActivePane : function()
32421 Roo.each(this.panes, function(p) {
32422 if(p.el.hasClass('active')){
32443 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
32445 * @class Roo.bootstrap.TabPane
32446 * @extends Roo.bootstrap.Component
32447 * @children Roo.bootstrap.Graph Roo.bootstrap.Column
32448 * Bootstrap TabPane class
32449 * @cfg {Boolean} active (false | true) Default false
32450 * @cfg {String} title title of panel
32454 * Create a new TabPane
32455 * @param {Object} config The config object
32458 Roo.bootstrap.dash.TabPane = function(config){
32459 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
32465 * When a pane is activated
32466 * @param {Roo.bootstrap.dash.TabPane} pane
32473 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
32478 // the tabBox that this is attached to.
32481 getAutoCreate : function()
32489 cfg.cls += ' active';
32494 initEvents : function()
32496 //Roo.log('trigger add pane handler');
32497 this.parent().fireEvent('addpane', this)
32501 * Updates the tab title
32502 * @param {String} html to set the title to.
32504 setTitle: function(str)
32510 this.tab.select('a', true).first().dom.innerHTML = str;
32529 * @class Roo.bootstrap.Tooltip
32530 * Bootstrap Tooltip class
32531 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
32532 * to determine which dom element triggers the tooltip.
32534 * It needs to add support for additional attributes like tooltip-position
32537 * Create a new Toolti
32538 * @param {Object} config The config object
32541 Roo.bootstrap.Tooltip = function(config){
32542 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
32544 this.alignment = Roo.bootstrap.Tooltip.alignment;
32546 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
32547 this.alignment = config.alignment;
32552 Roo.apply(Roo.bootstrap.Tooltip, {
32554 * @function init initialize tooltip monitoring.
32558 currentTip : false,
32559 currentRegion : false,
32565 Roo.get(document).on('mouseover', this.enter ,this);
32566 Roo.get(document).on('mouseout', this.leave, this);
32569 this.currentTip = new Roo.bootstrap.Tooltip();
32572 enter : function(ev)
32574 var dom = ev.getTarget();
32576 //Roo.log(['enter',dom]);
32577 var el = Roo.fly(dom);
32578 if (this.currentEl) {
32580 //Roo.log(this.currentEl);
32581 //Roo.log(this.currentEl.contains(dom));
32582 if (this.currentEl == el) {
32585 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
32591 if (this.currentTip.el) {
32592 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
32596 if(!el || el.dom == document){
32602 if (!el.attr('tooltip')) {
32603 pel = el.findParent("[tooltip]");
32605 bindEl = Roo.get(pel);
32611 // you can not look for children, as if el is the body.. then everythign is the child..
32612 if (!pel && !el.attr('tooltip')) { //
32613 if (!el.select("[tooltip]").elements.length) {
32616 // is the mouse over this child...?
32617 bindEl = el.select("[tooltip]").first();
32618 var xy = ev.getXY();
32619 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
32620 //Roo.log("not in region.");
32623 //Roo.log("child element over..");
32626 this.currentEl = el;
32627 this.currentTip.bind(bindEl);
32628 this.currentRegion = Roo.lib.Region.getRegion(dom);
32629 this.currentTip.enter();
32632 leave : function(ev)
32634 var dom = ev.getTarget();
32635 //Roo.log(['leave',dom]);
32636 if (!this.currentEl) {
32641 if (dom != this.currentEl.dom) {
32644 var xy = ev.getXY();
32645 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
32648 // only activate leave if mouse cursor is outside... bounding box..
32653 if (this.currentTip) {
32654 this.currentTip.leave();
32656 //Roo.log('clear currentEl');
32657 this.currentEl = false;
32662 'left' : ['r-l', [-2,0], 'right'],
32663 'right' : ['l-r', [2,0], 'left'],
32664 'bottom' : ['t-b', [0,2], 'top'],
32665 'top' : [ 'b-t', [0,-2], 'bottom']
32671 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
32676 delay : null, // can be { show : 300 , hide: 500}
32680 hoverState : null, //???
32682 placement : 'bottom',
32686 getAutoCreate : function(){
32693 cls : 'tooltip-arrow arrow'
32696 cls : 'tooltip-inner'
32703 bind : function(el)
32708 initEvents : function()
32710 this.arrowEl = this.el.select('.arrow', true).first();
32711 this.innerEl = this.el.select('.tooltip-inner', true).first();
32714 enter : function () {
32716 if (this.timeout != null) {
32717 clearTimeout(this.timeout);
32720 this.hoverState = 'in';
32721 //Roo.log("enter - show");
32722 if (!this.delay || !this.delay.show) {
32727 this.timeout = setTimeout(function () {
32728 if (_t.hoverState == 'in') {
32731 }, this.delay.show);
32735 clearTimeout(this.timeout);
32737 this.hoverState = 'out';
32738 if (!this.delay || !this.delay.hide) {
32744 this.timeout = setTimeout(function () {
32745 //Roo.log("leave - timeout");
32747 if (_t.hoverState == 'out') {
32749 Roo.bootstrap.Tooltip.currentEl = false;
32754 show : function (msg)
32757 this.render(document.body);
32760 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
32762 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
32764 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
32766 this.el.removeClass(['fade','top','bottom', 'left', 'right','in',
32767 'bs-tooltip-top','bs-tooltip-bottom', 'bs-tooltip-left', 'bs-tooltip-right']);
32769 this.el.addClass(this.bindEl.attr('tooltip-class'));
32771 var placement = typeof this.placement == 'function' ?
32772 this.placement.call(this, this.el, on_el) :
32775 var autoToken = /\s?auto?\s?/i;
32776 var autoPlace = autoToken.test(placement);
32778 placement = placement.replace(autoToken, '') || 'top';
32782 //this.el.setXY([0,0]);
32784 //this.el.dom.style.display='block';
32786 //this.el.appendTo(on_el);
32788 var p = this.getPosition();
32789 var box = this.el.getBox();
32795 var align = this.alignment[placement];
32797 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
32799 if(placement == 'top' || placement == 'bottom'){
32801 placement = 'right';
32804 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
32805 placement = 'left';
32808 var scroll = Roo.select('body', true).first().getScroll();
32810 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
32814 align = this.alignment[placement];
32816 this.arrowEl.setLeft((this.innerEl.getWidth()/2) - 5);
32820 var elems = document.getElementsByTagName('div');
32821 var highest = Number.MIN_SAFE_INTEGER || -(Math.pow(2, 53) - 1);
32822 for (var i = 0; i < elems.length; i++) {
32823 var zindex = Number.parseInt(
32824 document.defaultView.getComputedStyle(elems[i], null).getPropertyValue("z-index"),
32827 if (zindex > highest) {
32834 this.el.dom.style.zIndex = highest;
32836 this.el.alignTo(this.bindEl, align[0],align[1]);
32837 //var arrow = this.el.select('.arrow',true).first();
32838 //arrow.set(align[2],
32840 this.el.addClass(placement);
32841 this.el.addClass("bs-tooltip-"+ placement);
32843 this.el.addClass('in fade show');
32845 this.hoverState = null;
32847 if (this.el.hasClass('fade')) {
32862 //this.el.setXY([0,0]);
32863 this.el.removeClass(['show', 'in']);
32879 * @class Roo.bootstrap.LocationPicker
32880 * @extends Roo.bootstrap.Component
32881 * Bootstrap LocationPicker class
32882 * @cfg {Number} latitude Position when init default 0
32883 * @cfg {Number} longitude Position when init default 0
32884 * @cfg {Number} zoom default 15
32885 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
32886 * @cfg {Boolean} mapTypeControl default false
32887 * @cfg {Boolean} disableDoubleClickZoom default false
32888 * @cfg {Boolean} scrollwheel default true
32889 * @cfg {Boolean} streetViewControl default false
32890 * @cfg {Number} radius default 0
32891 * @cfg {String} locationName
32892 * @cfg {Boolean} draggable default true
32893 * @cfg {Boolean} enableAutocomplete default false
32894 * @cfg {Boolean} enableReverseGeocode default true
32895 * @cfg {String} markerTitle
32898 * Create a new LocationPicker
32899 * @param {Object} config The config object
32903 Roo.bootstrap.LocationPicker = function(config){
32905 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
32910 * Fires when the picker initialized.
32911 * @param {Roo.bootstrap.LocationPicker} this
32912 * @param {Google Location} location
32916 * @event positionchanged
32917 * Fires when the picker position changed.
32918 * @param {Roo.bootstrap.LocationPicker} this
32919 * @param {Google Location} location
32921 positionchanged : true,
32924 * Fires when the map resize.
32925 * @param {Roo.bootstrap.LocationPicker} this
32930 * Fires when the map show.
32931 * @param {Roo.bootstrap.LocationPicker} this
32936 * Fires when the map hide.
32937 * @param {Roo.bootstrap.LocationPicker} this
32942 * Fires when click the map.
32943 * @param {Roo.bootstrap.LocationPicker} this
32944 * @param {Map event} e
32948 * @event mapRightClick
32949 * Fires when right click the map.
32950 * @param {Roo.bootstrap.LocationPicker} this
32951 * @param {Map event} e
32953 mapRightClick : true,
32955 * @event markerClick
32956 * Fires when click the marker.
32957 * @param {Roo.bootstrap.LocationPicker} this
32958 * @param {Map event} e
32960 markerClick : true,
32962 * @event markerRightClick
32963 * Fires when right click the marker.
32964 * @param {Roo.bootstrap.LocationPicker} this
32965 * @param {Map event} e
32967 markerRightClick : true,
32969 * @event OverlayViewDraw
32970 * Fires when OverlayView Draw
32971 * @param {Roo.bootstrap.LocationPicker} this
32973 OverlayViewDraw : true,
32975 * @event OverlayViewOnAdd
32976 * Fires when OverlayView Draw
32977 * @param {Roo.bootstrap.LocationPicker} this
32979 OverlayViewOnAdd : true,
32981 * @event OverlayViewOnRemove
32982 * Fires when OverlayView Draw
32983 * @param {Roo.bootstrap.LocationPicker} this
32985 OverlayViewOnRemove : true,
32987 * @event OverlayViewShow
32988 * Fires when OverlayView Draw
32989 * @param {Roo.bootstrap.LocationPicker} this
32990 * @param {Pixel} cpx
32992 OverlayViewShow : true,
32994 * @event OverlayViewHide
32995 * Fires when OverlayView Draw
32996 * @param {Roo.bootstrap.LocationPicker} this
32998 OverlayViewHide : true,
33000 * @event loadexception
33001 * Fires when load google lib failed.
33002 * @param {Roo.bootstrap.LocationPicker} this
33004 loadexception : true
33009 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
33011 gMapContext: false,
33017 mapTypeControl: false,
33018 disableDoubleClickZoom: false,
33020 streetViewControl: false,
33024 enableAutocomplete: false,
33025 enableReverseGeocode: true,
33028 getAutoCreate: function()
33033 cls: 'roo-location-picker'
33039 initEvents: function(ct, position)
33041 if(!this.el.getWidth() || this.isApplied()){
33045 this.el.setVisibilityMode(Roo.Element.DISPLAY);
33050 initial: function()
33052 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
33053 this.fireEvent('loadexception', this);
33057 if(!this.mapTypeId){
33058 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
33061 this.gMapContext = this.GMapContext();
33063 this.initOverlayView();
33065 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
33069 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
33070 _this.setPosition(_this.gMapContext.marker.position);
33073 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
33074 _this.fireEvent('mapClick', this, event);
33078 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
33079 _this.fireEvent('mapRightClick', this, event);
33083 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
33084 _this.fireEvent('markerClick', this, event);
33088 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
33089 _this.fireEvent('markerRightClick', this, event);
33093 this.setPosition(this.gMapContext.location);
33095 this.fireEvent('initial', this, this.gMapContext.location);
33098 initOverlayView: function()
33102 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
33106 _this.fireEvent('OverlayViewDraw', _this);
33111 _this.fireEvent('OverlayViewOnAdd', _this);
33114 onRemove: function()
33116 _this.fireEvent('OverlayViewOnRemove', _this);
33119 show: function(cpx)
33121 _this.fireEvent('OverlayViewShow', _this, cpx);
33126 _this.fireEvent('OverlayViewHide', _this);
33132 fromLatLngToContainerPixel: function(event)
33134 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
33137 isApplied: function()
33139 return this.getGmapContext() == false ? false : true;
33142 getGmapContext: function()
33144 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
33147 GMapContext: function()
33149 var position = new google.maps.LatLng(this.latitude, this.longitude);
33151 var _map = new google.maps.Map(this.el.dom, {
33154 mapTypeId: this.mapTypeId,
33155 mapTypeControl: this.mapTypeControl,
33156 disableDoubleClickZoom: this.disableDoubleClickZoom,
33157 scrollwheel: this.scrollwheel,
33158 streetViewControl: this.streetViewControl,
33159 locationName: this.locationName,
33160 draggable: this.draggable,
33161 enableAutocomplete: this.enableAutocomplete,
33162 enableReverseGeocode: this.enableReverseGeocode
33165 var _marker = new google.maps.Marker({
33166 position: position,
33168 title: this.markerTitle,
33169 draggable: this.draggable
33176 location: position,
33177 radius: this.radius,
33178 locationName: this.locationName,
33179 addressComponents: {
33180 formatted_address: null,
33181 addressLine1: null,
33182 addressLine2: null,
33184 streetNumber: null,
33188 stateOrProvince: null
33191 domContainer: this.el.dom,
33192 geodecoder: new google.maps.Geocoder()
33196 drawCircle: function(center, radius, options)
33198 if (this.gMapContext.circle != null) {
33199 this.gMapContext.circle.setMap(null);
33203 options = Roo.apply({}, options, {
33204 strokeColor: "#0000FF",
33205 strokeOpacity: .35,
33207 fillColor: "#0000FF",
33211 options.map = this.gMapContext.map;
33212 options.radius = radius;
33213 options.center = center;
33214 this.gMapContext.circle = new google.maps.Circle(options);
33215 return this.gMapContext.circle;
33221 setPosition: function(location)
33223 this.gMapContext.location = location;
33224 this.gMapContext.marker.setPosition(location);
33225 this.gMapContext.map.panTo(location);
33226 this.drawCircle(location, this.gMapContext.radius, {});
33230 if (this.gMapContext.settings.enableReverseGeocode) {
33231 this.gMapContext.geodecoder.geocode({
33232 latLng: this.gMapContext.location
33233 }, function(results, status) {
33235 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
33236 _this.gMapContext.locationName = results[0].formatted_address;
33237 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
33239 _this.fireEvent('positionchanged', this, location);
33246 this.fireEvent('positionchanged', this, location);
33251 google.maps.event.trigger(this.gMapContext.map, "resize");
33253 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
33255 this.fireEvent('resize', this);
33258 setPositionByLatLng: function(latitude, longitude)
33260 this.setPosition(new google.maps.LatLng(latitude, longitude));
33263 getCurrentPosition: function()
33266 latitude: this.gMapContext.location.lat(),
33267 longitude: this.gMapContext.location.lng()
33271 getAddressName: function()
33273 return this.gMapContext.locationName;
33276 getAddressComponents: function()
33278 return this.gMapContext.addressComponents;
33281 address_component_from_google_geocode: function(address_components)
33285 for (var i = 0; i < address_components.length; i++) {
33286 var component = address_components[i];
33287 if (component.types.indexOf("postal_code") >= 0) {
33288 result.postalCode = component.short_name;
33289 } else if (component.types.indexOf("street_number") >= 0) {
33290 result.streetNumber = component.short_name;
33291 } else if (component.types.indexOf("route") >= 0) {
33292 result.streetName = component.short_name;
33293 } else if (component.types.indexOf("neighborhood") >= 0) {
33294 result.city = component.short_name;
33295 } else if (component.types.indexOf("locality") >= 0) {
33296 result.city = component.short_name;
33297 } else if (component.types.indexOf("sublocality") >= 0) {
33298 result.district = component.short_name;
33299 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
33300 result.stateOrProvince = component.short_name;
33301 } else if (component.types.indexOf("country") >= 0) {
33302 result.country = component.short_name;
33306 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
33307 result.addressLine2 = "";
33311 setZoomLevel: function(zoom)
33313 this.gMapContext.map.setZoom(zoom);
33326 this.fireEvent('show', this);
33337 this.fireEvent('hide', this);
33342 Roo.apply(Roo.bootstrap.LocationPicker, {
33344 OverlayView : function(map, options)
33346 options = options || {};
33353 * @class Roo.bootstrap.Alert
33354 * @extends Roo.bootstrap.Component
33355 * Bootstrap Alert class - shows an alert area box
33357 * <div class="alert alert-danger" role="alert"><span class="fa fa-exclamation-triangle"></span><span class="sr-only">Error:</span>
33358 Enter a valid email address
33361 * @cfg {String} title The title of alert
33362 * @cfg {String} html The content of alert
33363 * @cfg {String} weight (success|info|warning|danger) Weight of the message
33364 * @cfg {String} fa font-awesomeicon
33365 * @cfg {Number} seconds default:-1 Number of seconds until it disapears (-1 means never.)
33366 * @cfg {Boolean} close true to show a x closer
33370 * Create a new alert
33371 * @param {Object} config The config object
33375 Roo.bootstrap.Alert = function(config){
33376 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
33380 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
33386 faicon: false, // BC
33390 getAutoCreate : function()
33402 style : this.close ? '' : 'display:none'
33406 cls : 'roo-alert-icon'
33411 cls : 'roo-alert-title',
33416 cls : 'roo-alert-text',
33423 cfg.cn[0].cls += ' fa ' + this.faicon;
33426 cfg.cn[0].cls += ' fa ' + this.fa;
33430 cfg.cls += ' alert-' + this.weight;
33436 initEvents: function()
33438 this.el.setVisibilityMode(Roo.Element.DISPLAY);
33439 this.titleEl = this.el.select('.roo-alert-title',true).first();
33440 this.iconEl = this.el.select('.roo-alert-icon',true).first();
33441 this.htmlEl = this.el.select('.roo-alert-text',true).first();
33442 if (this.seconds > 0) {
33443 this.hide.defer(this.seconds, this);
33447 * Set the Title Message HTML
33448 * @param {String} html
33450 setTitle : function(str)
33452 this.titleEl.dom.innerHTML = str;
33456 * Set the Body Message HTML
33457 * @param {String} html
33459 setHtml : function(str)
33461 this.htmlEl.dom.innerHTML = str;
33464 * Set the Weight of the alert
33465 * @param {String} (success|info|warning|danger) weight
33468 setWeight : function(weight)
33471 this.el.removeClass('alert-' + this.weight);
33474 this.weight = weight;
33476 this.el.addClass('alert-' + this.weight);
33479 * Set the Icon of the alert
33480 * @param {String} see fontawsome names (name without the 'fa-' bit)
33482 setIcon : function(icon)
33485 this.alertEl.removeClass(['fa', 'fa-' + this.faicon]);
33488 this.faicon = icon;
33490 this.alertEl.addClass(['fa', 'fa-' + this.faicon]);
33515 * @class Roo.bootstrap.UploadCropbox
33516 * @extends Roo.bootstrap.Component
33517 * Bootstrap UploadCropbox class
33518 * @cfg {String} emptyText show when image has been loaded
33519 * @cfg {String} rotateNotify show when image too small to rotate
33520 * @cfg {Number} errorTimeout default 3000
33521 * @cfg {Number} minWidth default 300
33522 * @cfg {Number} minHeight default 300
33523 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
33524 * @cfg {Boolean} isDocument (true|false) default false
33525 * @cfg {String} url action url
33526 * @cfg {String} paramName default 'imageUpload'
33527 * @cfg {String} method default POST
33528 * @cfg {Boolean} loadMask (true|false) default true
33529 * @cfg {Boolean} loadingText default 'Loading...'
33532 * Create a new UploadCropbox
33533 * @param {Object} config The config object
33536 Roo.bootstrap.UploadCropbox = function(config){
33537 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
33541 * @event beforeselectfile
33542 * Fire before select file
33543 * @param {Roo.bootstrap.UploadCropbox} this
33545 "beforeselectfile" : true,
33548 * Fire after initEvent
33549 * @param {Roo.bootstrap.UploadCropbox} this
33554 * Fire after initEvent
33555 * @param {Roo.bootstrap.UploadCropbox} this
33556 * @param {String} data
33561 * Fire when preparing the file data
33562 * @param {Roo.bootstrap.UploadCropbox} this
33563 * @param {Object} file
33568 * Fire when get exception
33569 * @param {Roo.bootstrap.UploadCropbox} this
33570 * @param {XMLHttpRequest} xhr
33572 "exception" : true,
33574 * @event beforeloadcanvas
33575 * Fire before load the canvas
33576 * @param {Roo.bootstrap.UploadCropbox} this
33577 * @param {String} src
33579 "beforeloadcanvas" : true,
33582 * Fire when trash image
33583 * @param {Roo.bootstrap.UploadCropbox} this
33588 * Fire when download the image
33589 * @param {Roo.bootstrap.UploadCropbox} this
33593 * @event footerbuttonclick
33594 * Fire when footerbuttonclick
33595 * @param {Roo.bootstrap.UploadCropbox} this
33596 * @param {String} type
33598 "footerbuttonclick" : true,
33602 * @param {Roo.bootstrap.UploadCropbox} this
33607 * Fire when rotate the image
33608 * @param {Roo.bootstrap.UploadCropbox} this
33609 * @param {String} pos
33614 * Fire when inspect the file
33615 * @param {Roo.bootstrap.UploadCropbox} this
33616 * @param {Object} file
33621 * Fire when xhr upload the file
33622 * @param {Roo.bootstrap.UploadCropbox} this
33623 * @param {Object} data
33628 * Fire when arrange the file data
33629 * @param {Roo.bootstrap.UploadCropbox} this
33630 * @param {Object} formData
33635 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
33638 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
33640 emptyText : 'Click to upload image',
33641 rotateNotify : 'Image is too small to rotate',
33642 errorTimeout : 3000,
33656 cropType : 'image/jpeg',
33658 canvasLoaded : false,
33659 isDocument : false,
33661 paramName : 'imageUpload',
33663 loadingText : 'Loading...',
33666 getAutoCreate : function()
33670 cls : 'roo-upload-cropbox',
33674 cls : 'roo-upload-cropbox-selector',
33679 cls : 'roo-upload-cropbox-body',
33680 style : 'cursor:pointer',
33684 cls : 'roo-upload-cropbox-preview'
33688 cls : 'roo-upload-cropbox-thumb'
33692 cls : 'roo-upload-cropbox-empty-notify',
33693 html : this.emptyText
33697 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
33698 html : this.rotateNotify
33704 cls : 'roo-upload-cropbox-footer',
33707 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
33717 onRender : function(ct, position)
33719 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
33721 if (this.buttons.length) {
33723 Roo.each(this.buttons, function(bb) {
33725 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
33727 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
33733 this.maskEl = this.el;
33737 initEvents : function()
33739 this.urlAPI = (window.createObjectURL && window) ||
33740 (window.URL && URL.revokeObjectURL && URL) ||
33741 (window.webkitURL && webkitURL);
33743 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
33744 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
33746 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
33747 this.selectorEl.hide();
33749 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
33750 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
33752 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
33753 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
33754 this.thumbEl.hide();
33756 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
33757 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
33759 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
33760 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
33761 this.errorEl.hide();
33763 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
33764 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
33765 this.footerEl.hide();
33767 this.setThumbBoxSize();
33773 this.fireEvent('initial', this);
33780 window.addEventListener("resize", function() { _this.resize(); } );
33782 this.bodyEl.on('click', this.beforeSelectFile, this);
33785 this.bodyEl.on('touchstart', this.onTouchStart, this);
33786 this.bodyEl.on('touchmove', this.onTouchMove, this);
33787 this.bodyEl.on('touchend', this.onTouchEnd, this);
33791 this.bodyEl.on('mousedown', this.onMouseDown, this);
33792 this.bodyEl.on('mousemove', this.onMouseMove, this);
33793 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
33794 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
33795 Roo.get(document).on('mouseup', this.onMouseUp, this);
33798 this.selectorEl.on('change', this.onFileSelected, this);
33804 this.baseScale = 1;
33806 this.baseRotate = 1;
33807 this.dragable = false;
33808 this.pinching = false;
33811 this.cropData = false;
33812 this.notifyEl.dom.innerHTML = this.emptyText;
33814 this.selectorEl.dom.value = '';
33818 resize : function()
33820 if(this.fireEvent('resize', this) != false){
33821 this.setThumbBoxPosition();
33822 this.setCanvasPosition();
33826 onFooterButtonClick : function(e, el, o, type)
33829 case 'rotate-left' :
33830 this.onRotateLeft(e);
33832 case 'rotate-right' :
33833 this.onRotateRight(e);
33836 this.beforeSelectFile(e);
33851 this.fireEvent('footerbuttonclick', this, type);
33854 beforeSelectFile : function(e)
33856 e.preventDefault();
33858 if(this.fireEvent('beforeselectfile', this) != false){
33859 this.selectorEl.dom.click();
33863 onFileSelected : function(e)
33865 e.preventDefault();
33867 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
33871 var file = this.selectorEl.dom.files[0];
33873 if(this.fireEvent('inspect', this, file) != false){
33874 this.prepare(file);
33879 trash : function(e)
33881 this.fireEvent('trash', this);
33884 download : function(e)
33886 this.fireEvent('download', this);
33889 loadCanvas : function(src)
33891 if(this.fireEvent('beforeloadcanvas', this, src) != false){
33895 this.imageEl = document.createElement('img');
33899 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
33901 this.imageEl.src = src;
33905 onLoadCanvas : function()
33907 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
33908 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
33910 this.bodyEl.un('click', this.beforeSelectFile, this);
33912 this.notifyEl.hide();
33913 this.thumbEl.show();
33914 this.footerEl.show();
33916 this.baseRotateLevel();
33918 if(this.isDocument){
33919 this.setThumbBoxSize();
33922 this.setThumbBoxPosition();
33924 this.baseScaleLevel();
33930 this.canvasLoaded = true;
33933 this.maskEl.unmask();
33938 setCanvasPosition : function()
33940 if(!this.canvasEl){
33944 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
33945 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
33947 this.previewEl.setLeft(pw);
33948 this.previewEl.setTop(ph);
33952 onMouseDown : function(e)
33956 this.dragable = true;
33957 this.pinching = false;
33959 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
33960 this.dragable = false;
33964 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
33965 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
33969 onMouseMove : function(e)
33973 if(!this.canvasLoaded){
33977 if (!this.dragable){
33981 var minX = Math.ceil(this.thumbEl.getLeft(true));
33982 var minY = Math.ceil(this.thumbEl.getTop(true));
33984 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
33985 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
33987 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
33988 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
33990 x = x - this.mouseX;
33991 y = y - this.mouseY;
33993 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
33994 var bgY = Math.ceil(y + this.previewEl.getTop(true));
33996 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
33997 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
33999 this.previewEl.setLeft(bgX);
34000 this.previewEl.setTop(bgY);
34002 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
34003 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
34006 onMouseUp : function(e)
34010 this.dragable = false;
34013 onMouseWheel : function(e)
34017 this.startScale = this.scale;
34019 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
34021 if(!this.zoomable()){
34022 this.scale = this.startScale;
34031 zoomable : function()
34033 var minScale = this.thumbEl.getWidth() / this.minWidth;
34035 if(this.minWidth < this.minHeight){
34036 minScale = this.thumbEl.getHeight() / this.minHeight;
34039 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
34040 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
34044 (this.rotate == 0 || this.rotate == 180) &&
34046 width > this.imageEl.OriginWidth ||
34047 height > this.imageEl.OriginHeight ||
34048 (width < this.minWidth && height < this.minHeight)
34056 (this.rotate == 90 || this.rotate == 270) &&
34058 width > this.imageEl.OriginWidth ||
34059 height > this.imageEl.OriginHeight ||
34060 (width < this.minHeight && height < this.minWidth)
34067 !this.isDocument &&
34068 (this.rotate == 0 || this.rotate == 180) &&
34070 width < this.minWidth ||
34071 width > this.imageEl.OriginWidth ||
34072 height < this.minHeight ||
34073 height > this.imageEl.OriginHeight
34080 !this.isDocument &&
34081 (this.rotate == 90 || this.rotate == 270) &&
34083 width < this.minHeight ||
34084 width > this.imageEl.OriginWidth ||
34085 height < this.minWidth ||
34086 height > this.imageEl.OriginHeight
34096 onRotateLeft : function(e)
34098 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
34100 var minScale = this.thumbEl.getWidth() / this.minWidth;
34102 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
34103 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
34105 this.startScale = this.scale;
34107 while (this.getScaleLevel() < minScale){
34109 this.scale = this.scale + 1;
34111 if(!this.zoomable()){
34116 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
34117 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
34122 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
34129 this.scale = this.startScale;
34131 this.onRotateFail();
34136 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
34138 if(this.isDocument){
34139 this.setThumbBoxSize();
34140 this.setThumbBoxPosition();
34141 this.setCanvasPosition();
34146 this.fireEvent('rotate', this, 'left');
34150 onRotateRight : function(e)
34152 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
34154 var minScale = this.thumbEl.getWidth() / this.minWidth;
34156 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
34157 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
34159 this.startScale = this.scale;
34161 while (this.getScaleLevel() < minScale){
34163 this.scale = this.scale + 1;
34165 if(!this.zoomable()){
34170 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
34171 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
34176 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
34183 this.scale = this.startScale;
34185 this.onRotateFail();
34190 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
34192 if(this.isDocument){
34193 this.setThumbBoxSize();
34194 this.setThumbBoxPosition();
34195 this.setCanvasPosition();
34200 this.fireEvent('rotate', this, 'right');
34203 onRotateFail : function()
34205 this.errorEl.show(true);
34209 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
34214 this.previewEl.dom.innerHTML = '';
34216 var canvasEl = document.createElement("canvas");
34218 var contextEl = canvasEl.getContext("2d");
34220 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
34221 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
34222 var center = this.imageEl.OriginWidth / 2;
34224 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
34225 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
34226 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
34227 center = this.imageEl.OriginHeight / 2;
34230 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
34232 contextEl.translate(center, center);
34233 contextEl.rotate(this.rotate * Math.PI / 180);
34235 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
34237 this.canvasEl = document.createElement("canvas");
34239 this.contextEl = this.canvasEl.getContext("2d");
34241 switch (this.rotate) {
34244 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
34245 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
34247 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
34252 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
34253 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
34255 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
34256 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);
34260 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
34265 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
34266 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
34268 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
34269 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);
34273 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);
34278 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
34279 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
34281 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
34282 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
34286 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);
34293 this.previewEl.appendChild(this.canvasEl);
34295 this.setCanvasPosition();
34300 if(!this.canvasLoaded){
34304 var imageCanvas = document.createElement("canvas");
34306 var imageContext = imageCanvas.getContext("2d");
34308 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
34309 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
34311 var center = imageCanvas.width / 2;
34313 imageContext.translate(center, center);
34315 imageContext.rotate(this.rotate * Math.PI / 180);
34317 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
34319 var canvas = document.createElement("canvas");
34321 var context = canvas.getContext("2d");
34323 canvas.width = this.minWidth;
34324 canvas.height = this.minHeight;
34326 switch (this.rotate) {
34329 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
34330 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
34332 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
34333 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
34335 var targetWidth = this.minWidth - 2 * x;
34336 var targetHeight = this.minHeight - 2 * y;
34340 if((x == 0 && y == 0) || (x == 0 && y > 0)){
34341 scale = targetWidth / width;
34344 if(x > 0 && y == 0){
34345 scale = targetHeight / height;
34348 if(x > 0 && y > 0){
34349 scale = targetWidth / width;
34351 if(width < height){
34352 scale = targetHeight / height;
34356 context.scale(scale, scale);
34358 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
34359 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
34361 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
34362 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
34364 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
34369 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
34370 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
34372 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
34373 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
34375 var targetWidth = this.minWidth - 2 * x;
34376 var targetHeight = this.minHeight - 2 * y;
34380 if((x == 0 && y == 0) || (x == 0 && y > 0)){
34381 scale = targetWidth / width;
34384 if(x > 0 && y == 0){
34385 scale = targetHeight / height;
34388 if(x > 0 && y > 0){
34389 scale = targetWidth / width;
34391 if(width < height){
34392 scale = targetHeight / height;
34396 context.scale(scale, scale);
34398 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
34399 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
34401 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
34402 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
34404 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
34406 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
34411 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
34412 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
34414 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
34415 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
34417 var targetWidth = this.minWidth - 2 * x;
34418 var targetHeight = this.minHeight - 2 * y;
34422 if((x == 0 && y == 0) || (x == 0 && y > 0)){
34423 scale = targetWidth / width;
34426 if(x > 0 && y == 0){
34427 scale = targetHeight / height;
34430 if(x > 0 && y > 0){
34431 scale = targetWidth / width;
34433 if(width < height){
34434 scale = targetHeight / height;
34438 context.scale(scale, scale);
34440 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
34441 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
34443 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
34444 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
34446 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
34447 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
34449 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
34454 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
34455 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
34457 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
34458 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
34460 var targetWidth = this.minWidth - 2 * x;
34461 var targetHeight = this.minHeight - 2 * y;
34465 if((x == 0 && y == 0) || (x == 0 && y > 0)){
34466 scale = targetWidth / width;
34469 if(x > 0 && y == 0){
34470 scale = targetHeight / height;
34473 if(x > 0 && y > 0){
34474 scale = targetWidth / width;
34476 if(width < height){
34477 scale = targetHeight / height;
34481 context.scale(scale, scale);
34483 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
34484 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
34486 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
34487 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
34489 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
34491 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
34498 this.cropData = canvas.toDataURL(this.cropType);
34500 if(this.fireEvent('crop', this, this.cropData) !== false){
34501 this.process(this.file, this.cropData);
34508 setThumbBoxSize : function()
34512 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
34513 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
34514 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
34516 this.minWidth = width;
34517 this.minHeight = height;
34519 if(this.rotate == 90 || this.rotate == 270){
34520 this.minWidth = height;
34521 this.minHeight = width;
34526 width = Math.ceil(this.minWidth * height / this.minHeight);
34528 if(this.minWidth > this.minHeight){
34530 height = Math.ceil(this.minHeight * width / this.minWidth);
34533 this.thumbEl.setStyle({
34534 width : width + 'px',
34535 height : height + 'px'
34542 setThumbBoxPosition : function()
34544 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
34545 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
34547 this.thumbEl.setLeft(x);
34548 this.thumbEl.setTop(y);
34552 baseRotateLevel : function()
34554 this.baseRotate = 1;
34557 typeof(this.exif) != 'undefined' &&
34558 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
34559 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
34561 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
34564 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
34568 baseScaleLevel : function()
34572 if(this.isDocument){
34574 if(this.baseRotate == 6 || this.baseRotate == 8){
34576 height = this.thumbEl.getHeight();
34577 this.baseScale = height / this.imageEl.OriginWidth;
34579 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
34580 width = this.thumbEl.getWidth();
34581 this.baseScale = width / this.imageEl.OriginHeight;
34587 height = this.thumbEl.getHeight();
34588 this.baseScale = height / this.imageEl.OriginHeight;
34590 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
34591 width = this.thumbEl.getWidth();
34592 this.baseScale = width / this.imageEl.OriginWidth;
34598 if(this.baseRotate == 6 || this.baseRotate == 8){
34600 width = this.thumbEl.getHeight();
34601 this.baseScale = width / this.imageEl.OriginHeight;
34603 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
34604 height = this.thumbEl.getWidth();
34605 this.baseScale = height / this.imageEl.OriginHeight;
34608 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
34609 height = this.thumbEl.getWidth();
34610 this.baseScale = height / this.imageEl.OriginHeight;
34612 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
34613 width = this.thumbEl.getHeight();
34614 this.baseScale = width / this.imageEl.OriginWidth;
34621 width = this.thumbEl.getWidth();
34622 this.baseScale = width / this.imageEl.OriginWidth;
34624 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
34625 height = this.thumbEl.getHeight();
34626 this.baseScale = height / this.imageEl.OriginHeight;
34629 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
34631 height = this.thumbEl.getHeight();
34632 this.baseScale = height / this.imageEl.OriginHeight;
34634 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
34635 width = this.thumbEl.getWidth();
34636 this.baseScale = width / this.imageEl.OriginWidth;
34644 getScaleLevel : function()
34646 return this.baseScale * Math.pow(1.1, this.scale);
34649 onTouchStart : function(e)
34651 if(!this.canvasLoaded){
34652 this.beforeSelectFile(e);
34656 var touches = e.browserEvent.touches;
34662 if(touches.length == 1){
34663 this.onMouseDown(e);
34667 if(touches.length != 2){
34673 for(var i = 0, finger; finger = touches[i]; i++){
34674 coords.push(finger.pageX, finger.pageY);
34677 var x = Math.pow(coords[0] - coords[2], 2);
34678 var y = Math.pow(coords[1] - coords[3], 2);
34680 this.startDistance = Math.sqrt(x + y);
34682 this.startScale = this.scale;
34684 this.pinching = true;
34685 this.dragable = false;
34689 onTouchMove : function(e)
34691 if(!this.pinching && !this.dragable){
34695 var touches = e.browserEvent.touches;
34702 this.onMouseMove(e);
34708 for(var i = 0, finger; finger = touches[i]; i++){
34709 coords.push(finger.pageX, finger.pageY);
34712 var x = Math.pow(coords[0] - coords[2], 2);
34713 var y = Math.pow(coords[1] - coords[3], 2);
34715 this.endDistance = Math.sqrt(x + y);
34717 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
34719 if(!this.zoomable()){
34720 this.scale = this.startScale;
34728 onTouchEnd : function(e)
34730 this.pinching = false;
34731 this.dragable = false;
34735 process : function(file, crop)
34738 this.maskEl.mask(this.loadingText);
34741 this.xhr = new XMLHttpRequest();
34743 file.xhr = this.xhr;
34745 this.xhr.open(this.method, this.url, true);
34748 "Accept": "application/json",
34749 "Cache-Control": "no-cache",
34750 "X-Requested-With": "XMLHttpRequest"
34753 for (var headerName in headers) {
34754 var headerValue = headers[headerName];
34756 this.xhr.setRequestHeader(headerName, headerValue);
34762 this.xhr.onload = function()
34764 _this.xhrOnLoad(_this.xhr);
34767 this.xhr.onerror = function()
34769 _this.xhrOnError(_this.xhr);
34772 var formData = new FormData();
34774 formData.append('returnHTML', 'NO');
34777 formData.append('crop', crop);
34780 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
34781 formData.append(this.paramName, file, file.name);
34784 if(typeof(file.filename) != 'undefined'){
34785 formData.append('filename', file.filename);
34788 if(typeof(file.mimetype) != 'undefined'){
34789 formData.append('mimetype', file.mimetype);
34792 if(this.fireEvent('arrange', this, formData) != false){
34793 this.xhr.send(formData);
34797 xhrOnLoad : function(xhr)
34800 this.maskEl.unmask();
34803 if (xhr.readyState !== 4) {
34804 this.fireEvent('exception', this, xhr);
34808 var response = Roo.decode(xhr.responseText);
34810 if(!response.success){
34811 this.fireEvent('exception', this, xhr);
34815 var response = Roo.decode(xhr.responseText);
34817 this.fireEvent('upload', this, response);
34821 xhrOnError : function()
34824 this.maskEl.unmask();
34827 Roo.log('xhr on error');
34829 var response = Roo.decode(xhr.responseText);
34835 prepare : function(file)
34838 this.maskEl.mask(this.loadingText);
34844 if(typeof(file) === 'string'){
34845 this.loadCanvas(file);
34849 if(!file || !this.urlAPI){
34854 this.cropType = file.type;
34858 if(this.fireEvent('prepare', this, this.file) != false){
34860 var reader = new FileReader();
34862 reader.onload = function (e) {
34863 if (e.target.error) {
34864 Roo.log(e.target.error);
34868 var buffer = e.target.result,
34869 dataView = new DataView(buffer),
34871 maxOffset = dataView.byteLength - 4,
34875 if (dataView.getUint16(0) === 0xffd8) {
34876 while (offset < maxOffset) {
34877 markerBytes = dataView.getUint16(offset);
34879 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
34880 markerLength = dataView.getUint16(offset + 2) + 2;
34881 if (offset + markerLength > dataView.byteLength) {
34882 Roo.log('Invalid meta data: Invalid segment size.');
34886 if(markerBytes == 0xffe1){
34887 _this.parseExifData(
34894 offset += markerLength;
34904 var url = _this.urlAPI.createObjectURL(_this.file);
34906 _this.loadCanvas(url);
34911 reader.readAsArrayBuffer(this.file);
34917 parseExifData : function(dataView, offset, length)
34919 var tiffOffset = offset + 10,
34923 if (dataView.getUint32(offset + 4) !== 0x45786966) {
34924 // No Exif data, might be XMP data instead
34928 // Check for the ASCII code for "Exif" (0x45786966):
34929 if (dataView.getUint32(offset + 4) !== 0x45786966) {
34930 // No Exif data, might be XMP data instead
34933 if (tiffOffset + 8 > dataView.byteLength) {
34934 Roo.log('Invalid Exif data: Invalid segment size.');
34937 // Check for the two null bytes:
34938 if (dataView.getUint16(offset + 8) !== 0x0000) {
34939 Roo.log('Invalid Exif data: Missing byte alignment offset.');
34942 // Check the byte alignment:
34943 switch (dataView.getUint16(tiffOffset)) {
34945 littleEndian = true;
34948 littleEndian = false;
34951 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
34954 // Check for the TIFF tag marker (0x002A):
34955 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
34956 Roo.log('Invalid Exif data: Missing TIFF marker.');
34959 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
34960 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
34962 this.parseExifTags(
34965 tiffOffset + dirOffset,
34970 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
34975 if (dirOffset + 6 > dataView.byteLength) {
34976 Roo.log('Invalid Exif data: Invalid directory offset.');
34979 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
34980 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
34981 if (dirEndOffset + 4 > dataView.byteLength) {
34982 Roo.log('Invalid Exif data: Invalid directory size.');
34985 for (i = 0; i < tagsNumber; i += 1) {
34989 dirOffset + 2 + 12 * i, // tag offset
34993 // Return the offset to the next directory:
34994 return dataView.getUint32(dirEndOffset, littleEndian);
34997 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
34999 var tag = dataView.getUint16(offset, littleEndian);
35001 this.exif[tag] = this.getExifValue(
35005 dataView.getUint16(offset + 2, littleEndian), // tag type
35006 dataView.getUint32(offset + 4, littleEndian), // tag length
35011 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
35013 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
35022 Roo.log('Invalid Exif data: Invalid tag type.');
35026 tagSize = tagType.size * length;
35027 // Determine if the value is contained in the dataOffset bytes,
35028 // or if the value at the dataOffset is a pointer to the actual data:
35029 dataOffset = tagSize > 4 ?
35030 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
35031 if (dataOffset + tagSize > dataView.byteLength) {
35032 Roo.log('Invalid Exif data: Invalid data offset.');
35035 if (length === 1) {
35036 return tagType.getValue(dataView, dataOffset, littleEndian);
35039 for (i = 0; i < length; i += 1) {
35040 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
35043 if (tagType.ascii) {
35045 // Concatenate the chars:
35046 for (i = 0; i < values.length; i += 1) {
35048 // Ignore the terminating NULL byte(s):
35049 if (c === '\u0000') {
35061 Roo.apply(Roo.bootstrap.UploadCropbox, {
35063 'Orientation': 0x0112
35067 1: 0, //'top-left',
35069 3: 180, //'bottom-right',
35070 // 4: 'bottom-left',
35072 6: 90, //'right-top',
35073 // 7: 'right-bottom',
35074 8: 270 //'left-bottom'
35078 // byte, 8-bit unsigned int:
35080 getValue: function (dataView, dataOffset) {
35081 return dataView.getUint8(dataOffset);
35085 // ascii, 8-bit byte:
35087 getValue: function (dataView, dataOffset) {
35088 return String.fromCharCode(dataView.getUint8(dataOffset));
35093 // short, 16 bit int:
35095 getValue: function (dataView, dataOffset, littleEndian) {
35096 return dataView.getUint16(dataOffset, littleEndian);
35100 // long, 32 bit int:
35102 getValue: function (dataView, dataOffset, littleEndian) {
35103 return dataView.getUint32(dataOffset, littleEndian);
35107 // rational = two long values, first is numerator, second is denominator:
35109 getValue: function (dataView, dataOffset, littleEndian) {
35110 return dataView.getUint32(dataOffset, littleEndian) /
35111 dataView.getUint32(dataOffset + 4, littleEndian);
35115 // slong, 32 bit signed int:
35117 getValue: function (dataView, dataOffset, littleEndian) {
35118 return dataView.getInt32(dataOffset, littleEndian);
35122 // srational, two slongs, first is numerator, second is denominator:
35124 getValue: function (dataView, dataOffset, littleEndian) {
35125 return dataView.getInt32(dataOffset, littleEndian) /
35126 dataView.getInt32(dataOffset + 4, littleEndian);
35136 cls : 'btn-group roo-upload-cropbox-rotate-left',
35137 action : 'rotate-left',
35141 cls : 'btn btn-default',
35142 html : '<i class="fa fa-undo"></i>'
35148 cls : 'btn-group roo-upload-cropbox-picture',
35149 action : 'picture',
35153 cls : 'btn btn-default',
35154 html : '<i class="fa fa-picture-o"></i>'
35160 cls : 'btn-group roo-upload-cropbox-rotate-right',
35161 action : 'rotate-right',
35165 cls : 'btn btn-default',
35166 html : '<i class="fa fa-repeat"></i>'
35174 cls : 'btn-group roo-upload-cropbox-rotate-left',
35175 action : 'rotate-left',
35179 cls : 'btn btn-default',
35180 html : '<i class="fa fa-undo"></i>'
35186 cls : 'btn-group roo-upload-cropbox-download',
35187 action : 'download',
35191 cls : 'btn btn-default',
35192 html : '<i class="fa fa-download"></i>'
35198 cls : 'btn-group roo-upload-cropbox-crop',
35203 cls : 'btn btn-default',
35204 html : '<i class="fa fa-crop"></i>'
35210 cls : 'btn-group roo-upload-cropbox-trash',
35215 cls : 'btn btn-default',
35216 html : '<i class="fa fa-trash"></i>'
35222 cls : 'btn-group roo-upload-cropbox-rotate-right',
35223 action : 'rotate-right',
35227 cls : 'btn btn-default',
35228 html : '<i class="fa fa-repeat"></i>'
35236 cls : 'btn-group roo-upload-cropbox-rotate-left',
35237 action : 'rotate-left',
35241 cls : 'btn btn-default',
35242 html : '<i class="fa fa-undo"></i>'
35248 cls : 'btn-group roo-upload-cropbox-rotate-right',
35249 action : 'rotate-right',
35253 cls : 'btn btn-default',
35254 html : '<i class="fa fa-repeat"></i>'
35267 * @class Roo.bootstrap.DocumentManager
35268 * @extends Roo.bootstrap.Component
35269 * Bootstrap DocumentManager class
35270 * @cfg {String} paramName default 'imageUpload'
35271 * @cfg {String} toolTipName default 'filename'
35272 * @cfg {String} method default POST
35273 * @cfg {String} url action url
35274 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
35275 * @cfg {Boolean} multiple multiple upload default true
35276 * @cfg {Number} thumbSize default 300
35277 * @cfg {String} fieldLabel
35278 * @cfg {Number} labelWidth default 4
35279 * @cfg {String} labelAlign (left|top) default left
35280 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
35281 * @cfg {Number} labellg set the width of label (1-12)
35282 * @cfg {Number} labelmd set the width of label (1-12)
35283 * @cfg {Number} labelsm set the width of label (1-12)
35284 * @cfg {Number} labelxs set the width of label (1-12)
35287 * Create a new DocumentManager
35288 * @param {Object} config The config object
35291 Roo.bootstrap.DocumentManager = function(config){
35292 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
35295 this.delegates = [];
35300 * Fire when initial the DocumentManager
35301 * @param {Roo.bootstrap.DocumentManager} this
35306 * inspect selected file
35307 * @param {Roo.bootstrap.DocumentManager} this
35308 * @param {File} file
35313 * Fire when xhr load exception
35314 * @param {Roo.bootstrap.DocumentManager} this
35315 * @param {XMLHttpRequest} xhr
35317 "exception" : true,
35319 * @event afterupload
35320 * Fire when xhr load exception
35321 * @param {Roo.bootstrap.DocumentManager} this
35322 * @param {XMLHttpRequest} xhr
35324 "afterupload" : true,
35327 * prepare the form data
35328 * @param {Roo.bootstrap.DocumentManager} this
35329 * @param {Object} formData
35334 * Fire when remove the file
35335 * @param {Roo.bootstrap.DocumentManager} this
35336 * @param {Object} file
35341 * Fire after refresh the file
35342 * @param {Roo.bootstrap.DocumentManager} this
35347 * Fire after click the image
35348 * @param {Roo.bootstrap.DocumentManager} this
35349 * @param {Object} file
35354 * Fire when upload a image and editable set to true
35355 * @param {Roo.bootstrap.DocumentManager} this
35356 * @param {Object} file
35360 * @event beforeselectfile
35361 * Fire before select file
35362 * @param {Roo.bootstrap.DocumentManager} this
35364 "beforeselectfile" : true,
35367 * Fire before process file
35368 * @param {Roo.bootstrap.DocumentManager} this
35369 * @param {Object} file
35373 * @event previewrendered
35374 * Fire when preview rendered
35375 * @param {Roo.bootstrap.DocumentManager} this
35376 * @param {Object} file
35378 "previewrendered" : true,
35381 "previewResize" : true
35386 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
35395 paramName : 'imageUpload',
35396 toolTipName : 'filename',
35399 labelAlign : 'left',
35409 getAutoCreate : function()
35411 var managerWidget = {
35413 cls : 'roo-document-manager',
35417 cls : 'roo-document-manager-selector',
35422 cls : 'roo-document-manager-uploader',
35426 cls : 'roo-document-manager-upload-btn',
35427 html : '<i class="fa fa-plus"></i>'
35438 cls : 'column col-md-12',
35443 if(this.fieldLabel.length){
35448 cls : 'column col-md-12',
35449 html : this.fieldLabel
35453 cls : 'column col-md-12',
35458 if(this.labelAlign == 'left'){
35463 html : this.fieldLabel
35472 if(this.labelWidth > 12){
35473 content[0].style = "width: " + this.labelWidth + 'px';
35476 if(this.labelWidth < 13 && this.labelmd == 0){
35477 this.labelmd = this.labelWidth;
35480 if(this.labellg > 0){
35481 content[0].cls += ' col-lg-' + this.labellg;
35482 content[1].cls += ' col-lg-' + (12 - this.labellg);
35485 if(this.labelmd > 0){
35486 content[0].cls += ' col-md-' + this.labelmd;
35487 content[1].cls += ' col-md-' + (12 - this.labelmd);
35490 if(this.labelsm > 0){
35491 content[0].cls += ' col-sm-' + this.labelsm;
35492 content[1].cls += ' col-sm-' + (12 - this.labelsm);
35495 if(this.labelxs > 0){
35496 content[0].cls += ' col-xs-' + this.labelxs;
35497 content[1].cls += ' col-xs-' + (12 - this.labelxs);
35505 cls : 'row clearfix',
35513 initEvents : function()
35515 this.managerEl = this.el.select('.roo-document-manager', true).first();
35516 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35518 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
35519 this.selectorEl.hide();
35522 this.selectorEl.attr('multiple', 'multiple');
35525 this.selectorEl.on('change', this.onFileSelected, this);
35527 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
35528 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35530 this.uploader.on('click', this.onUploaderClick, this);
35532 this.renderProgressDialog();
35536 window.addEventListener("resize", function() { _this.refresh(); } );
35538 this.fireEvent('initial', this);
35541 renderProgressDialog : function()
35545 this.progressDialog = new Roo.bootstrap.Modal({
35546 cls : 'roo-document-manager-progress-dialog',
35547 allow_close : false,
35558 btnclick : function() {
35559 _this.uploadCancel();
35565 this.progressDialog.render(Roo.get(document.body));
35567 this.progress = new Roo.bootstrap.Progress({
35568 cls : 'roo-document-manager-progress',
35573 this.progress.render(this.progressDialog.getChildContainer());
35575 this.progressBar = new Roo.bootstrap.ProgressBar({
35576 cls : 'roo-document-manager-progress-bar',
35579 aria_valuemax : 12,
35583 this.progressBar.render(this.progress.getChildContainer());
35586 onUploaderClick : function(e)
35588 e.preventDefault();
35590 if(this.fireEvent('beforeselectfile', this) != false){
35591 this.selectorEl.dom.click();
35596 onFileSelected : function(e)
35598 e.preventDefault();
35600 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
35604 Roo.each(this.selectorEl.dom.files, function(file){
35605 if(this.fireEvent('inspect', this, file) != false){
35606 this.files.push(file);
35616 this.selectorEl.dom.value = '';
35618 if(!this.files || !this.files.length){
35622 if(this.boxes > 0 && this.files.length > this.boxes){
35623 this.files = this.files.slice(0, this.boxes);
35626 this.uploader.show();
35628 if(this.boxes > 0 && this.files.length > this.boxes - 1){
35629 this.uploader.hide();
35638 Roo.each(this.files, function(file){
35640 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
35641 var f = this.renderPreview(file);
35646 if(file.type.indexOf('image') != -1){
35647 this.delegates.push(
35649 _this.process(file);
35650 }).createDelegate(this)
35658 _this.process(file);
35659 }).createDelegate(this)
35664 this.files = files;
35666 this.delegates = this.delegates.concat(docs);
35668 if(!this.delegates.length){
35673 this.progressBar.aria_valuemax = this.delegates.length;
35680 arrange : function()
35682 if(!this.delegates.length){
35683 this.progressDialog.hide();
35688 var delegate = this.delegates.shift();
35690 this.progressDialog.show();
35692 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
35694 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
35699 refresh : function()
35701 this.uploader.show();
35703 if(this.boxes > 0 && this.files.length > this.boxes - 1){
35704 this.uploader.hide();
35707 Roo.isTouch ? this.closable(false) : this.closable(true);
35709 this.fireEvent('refresh', this);
35712 onRemove : function(e, el, o)
35714 e.preventDefault();
35716 this.fireEvent('remove', this, o);
35720 remove : function(o)
35724 Roo.each(this.files, function(file){
35725 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
35734 this.files = files;
35741 Roo.each(this.files, function(file){
35746 file.target.remove();
35755 onClick : function(e, el, o)
35757 e.preventDefault();
35759 this.fireEvent('click', this, o);
35763 closable : function(closable)
35765 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
35767 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
35779 xhrOnLoad : function(xhr)
35781 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
35785 if (xhr.readyState !== 4) {
35787 this.fireEvent('exception', this, xhr);
35791 var response = Roo.decode(xhr.responseText);
35793 if(!response.success){
35795 this.fireEvent('exception', this, xhr);
35799 var file = this.renderPreview(response.data);
35801 this.files.push(file);
35805 this.fireEvent('afterupload', this, xhr);
35809 xhrOnError : function(xhr)
35811 Roo.log('xhr on error');
35813 var response = Roo.decode(xhr.responseText);
35820 process : function(file)
35822 if(this.fireEvent('process', this, file) !== false){
35823 if(this.editable && file.type.indexOf('image') != -1){
35824 this.fireEvent('edit', this, file);
35828 this.uploadStart(file, false);
35835 uploadStart : function(file, crop)
35837 this.xhr = new XMLHttpRequest();
35839 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
35844 file.xhr = this.xhr;
35846 this.managerEl.createChild({
35848 cls : 'roo-document-manager-loading',
35852 tooltip : file.name,
35853 cls : 'roo-document-manager-thumb',
35854 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
35860 this.xhr.open(this.method, this.url, true);
35863 "Accept": "application/json",
35864 "Cache-Control": "no-cache",
35865 "X-Requested-With": "XMLHttpRequest"
35868 for (var headerName in headers) {
35869 var headerValue = headers[headerName];
35871 this.xhr.setRequestHeader(headerName, headerValue);
35877 this.xhr.onload = function()
35879 _this.xhrOnLoad(_this.xhr);
35882 this.xhr.onerror = function()
35884 _this.xhrOnError(_this.xhr);
35887 var formData = new FormData();
35889 formData.append('returnHTML', 'NO');
35892 formData.append('crop', crop);
35895 formData.append(this.paramName, file, file.name);
35902 if(this.fireEvent('prepare', this, formData, options) != false){
35904 if(options.manually){
35908 this.xhr.send(formData);
35912 this.uploadCancel();
35915 uploadCancel : function()
35921 this.delegates = [];
35923 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
35930 renderPreview : function(file)
35932 if(typeof(file.target) != 'undefined' && file.target){
35936 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
35938 var previewEl = this.managerEl.createChild({
35940 cls : 'roo-document-manager-preview',
35944 tooltip : file[this.toolTipName],
35945 cls : 'roo-document-manager-thumb',
35946 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
35951 html : '<i class="fa fa-times-circle"></i>'
35956 var close = previewEl.select('button.close', true).first();
35958 close.on('click', this.onRemove, this, file);
35960 file.target = previewEl;
35962 var image = previewEl.select('img', true).first();
35966 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
35968 image.on('click', this.onClick, this, file);
35970 this.fireEvent('previewrendered', this, file);
35976 onPreviewLoad : function(file, image)
35978 if(typeof(file.target) == 'undefined' || !file.target){
35982 var width = image.dom.naturalWidth || image.dom.width;
35983 var height = image.dom.naturalHeight || image.dom.height;
35985 if(!this.previewResize) {
35989 if(width > height){
35990 file.target.addClass('wide');
35994 file.target.addClass('tall');
35999 uploadFromSource : function(file, crop)
36001 this.xhr = new XMLHttpRequest();
36003 this.managerEl.createChild({
36005 cls : 'roo-document-manager-loading',
36009 tooltip : file.name,
36010 cls : 'roo-document-manager-thumb',
36011 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
36017 this.xhr.open(this.method, this.url, true);
36020 "Accept": "application/json",
36021 "Cache-Control": "no-cache",
36022 "X-Requested-With": "XMLHttpRequest"
36025 for (var headerName in headers) {
36026 var headerValue = headers[headerName];
36028 this.xhr.setRequestHeader(headerName, headerValue);
36034 this.xhr.onload = function()
36036 _this.xhrOnLoad(_this.xhr);
36039 this.xhr.onerror = function()
36041 _this.xhrOnError(_this.xhr);
36044 var formData = new FormData();
36046 formData.append('returnHTML', 'NO');
36048 formData.append('crop', crop);
36050 if(typeof(file.filename) != 'undefined'){
36051 formData.append('filename', file.filename);
36054 if(typeof(file.mimetype) != 'undefined'){
36055 formData.append('mimetype', file.mimetype);
36060 if(this.fireEvent('prepare', this, formData) != false){
36061 this.xhr.send(formData);
36071 * @class Roo.bootstrap.DocumentViewer
36072 * @extends Roo.bootstrap.Component
36073 * Bootstrap DocumentViewer class
36074 * @cfg {Boolean} showDownload (true|false) show download button (default true)
36075 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
36078 * Create a new DocumentViewer
36079 * @param {Object} config The config object
36082 Roo.bootstrap.DocumentViewer = function(config){
36083 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
36088 * Fire after initEvent
36089 * @param {Roo.bootstrap.DocumentViewer} this
36095 * @param {Roo.bootstrap.DocumentViewer} this
36100 * Fire after download button
36101 * @param {Roo.bootstrap.DocumentViewer} this
36106 * Fire after trash button
36107 * @param {Roo.bootstrap.DocumentViewer} this
36114 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
36116 showDownload : true,
36120 getAutoCreate : function()
36124 cls : 'roo-document-viewer',
36128 cls : 'roo-document-viewer-body',
36132 cls : 'roo-document-viewer-thumb',
36136 cls : 'roo-document-viewer-image'
36144 cls : 'roo-document-viewer-footer',
36147 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
36151 cls : 'btn-group roo-document-viewer-download',
36155 cls : 'btn btn-default',
36156 html : '<i class="fa fa-download"></i>'
36162 cls : 'btn-group roo-document-viewer-trash',
36166 cls : 'btn btn-default',
36167 html : '<i class="fa fa-trash"></i>'
36180 initEvents : function()
36182 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
36183 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
36185 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
36186 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
36188 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
36189 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
36191 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
36192 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
36194 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
36195 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
36197 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
36198 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
36200 this.bodyEl.on('click', this.onClick, this);
36201 this.downloadBtn.on('click', this.onDownload, this);
36202 this.trashBtn.on('click', this.onTrash, this);
36204 this.downloadBtn.hide();
36205 this.trashBtn.hide();
36207 if(this.showDownload){
36208 this.downloadBtn.show();
36211 if(this.showTrash){
36212 this.trashBtn.show();
36215 if(!this.showDownload && !this.showTrash) {
36216 this.footerEl.hide();
36221 initial : function()
36223 this.fireEvent('initial', this);
36227 onClick : function(e)
36229 e.preventDefault();
36231 this.fireEvent('click', this);
36234 onDownload : function(e)
36236 e.preventDefault();
36238 this.fireEvent('download', this);
36241 onTrash : function(e)
36243 e.preventDefault();
36245 this.fireEvent('trash', this);
36257 * @class Roo.bootstrap.form.FieldLabel
36258 * @extends Roo.bootstrap.Component
36259 * Bootstrap FieldLabel class
36260 * @cfg {String} html contents of the element
36261 * @cfg {String} tag tag of the element default label
36262 * @cfg {String} cls class of the element
36263 * @cfg {String} target label target
36264 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
36265 * @cfg {String} invalidClass DEPRICATED - BS4 uses is-invalid
36266 * @cfg {String} validClass DEPRICATED - BS4 uses is-valid
36267 * @cfg {String} iconTooltip default "This field is required"
36268 * @cfg {String} indicatorpos (left|right) default left
36271 * Create a new FieldLabel
36272 * @param {Object} config The config object
36275 Roo.bootstrap.form.FieldLabel = function(config){
36276 Roo.bootstrap.Element.superclass.constructor.call(this, config);
36281 * Fires after the field has been marked as invalid.
36282 * @param {Roo.form.FieldLabel} this
36283 * @param {String} msg The validation message
36288 * Fires after the field has been validated with no errors.
36289 * @param {Roo.form.FieldLabel} this
36295 Roo.extend(Roo.bootstrap.form.FieldLabel, Roo.bootstrap.Component, {
36302 invalidClass : 'has-warning',
36303 validClass : 'has-success',
36304 iconTooltip : 'This field is required',
36305 indicatorpos : 'left',
36307 getAutoCreate : function(){
36310 if (!this.allowBlank) {
36316 cls : 'roo-bootstrap-field-label ' + this.cls,
36321 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
36322 tooltip : this.iconTooltip
36331 if(this.indicatorpos == 'right'){
36334 cls : 'roo-bootstrap-field-label ' + this.cls,
36343 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
36344 tooltip : this.iconTooltip
36353 initEvents: function()
36355 Roo.bootstrap.Element.superclass.initEvents.call(this);
36357 this.indicator = this.indicatorEl();
36359 if(this.indicator){
36360 this.indicator.removeClass('visible');
36361 this.indicator.addClass('invisible');
36364 Roo.bootstrap.form.FieldLabel.register(this);
36367 indicatorEl : function()
36369 var indicator = this.el.select('i.roo-required-indicator',true).first();
36380 * Mark this field as valid
36382 markValid : function()
36384 if(this.indicator){
36385 this.indicator.removeClass('visible');
36386 this.indicator.addClass('invisible');
36388 if (Roo.bootstrap.version == 3) {
36389 this.el.removeClass(this.invalidClass);
36390 this.el.addClass(this.validClass);
36392 this.el.removeClass('is-invalid');
36393 this.el.addClass('is-valid');
36397 this.fireEvent('valid', this);
36401 * Mark this field as invalid
36402 * @param {String} msg The validation message
36404 markInvalid : function(msg)
36406 if(this.indicator){
36407 this.indicator.removeClass('invisible');
36408 this.indicator.addClass('visible');
36410 if (Roo.bootstrap.version == 3) {
36411 this.el.removeClass(this.validClass);
36412 this.el.addClass(this.invalidClass);
36414 this.el.removeClass('is-valid');
36415 this.el.addClass('is-invalid');
36419 this.fireEvent('invalid', this, msg);
36425 Roo.apply(Roo.bootstrap.form.FieldLabel, {
36430 * register a FieldLabel Group
36431 * @param {Roo.bootstrap.form.FieldLabel} the FieldLabel to add
36433 register : function(label)
36435 if(this.groups.hasOwnProperty(label.target)){
36439 this.groups[label.target] = label;
36443 * fetch a FieldLabel Group based on the target
36444 * @param {string} target
36445 * @returns {Roo.bootstrap.form.FieldLabel} the CheckBox group
36447 get: function(target) {
36448 if (typeof(this.groups[target]) == 'undefined') {
36452 return this.groups[target] ;
36461 * page DateSplitField.
36467 * @class Roo.bootstrap.form.DateSplitField
36468 * @extends Roo.bootstrap.Component
36469 * Bootstrap DateSplitField class
36470 * @cfg {string} fieldLabel - the label associated
36471 * @cfg {Number} labelWidth set the width of label (0-12)
36472 * @cfg {String} labelAlign (top|left)
36473 * @cfg {Boolean} dayAllowBlank (true|false) default false
36474 * @cfg {Boolean} monthAllowBlank (true|false) default false
36475 * @cfg {Boolean} yearAllowBlank (true|false) default false
36476 * @cfg {string} dayPlaceholder
36477 * @cfg {string} monthPlaceholder
36478 * @cfg {string} yearPlaceholder
36479 * @cfg {string} dayFormat default 'd'
36480 * @cfg {string} monthFormat default 'm'
36481 * @cfg {string} yearFormat default 'Y'
36482 * @cfg {Number} labellg set the width of label (1-12)
36483 * @cfg {Number} labelmd set the width of label (1-12)
36484 * @cfg {Number} labelsm set the width of label (1-12)
36485 * @cfg {Number} labelxs set the width of label (1-12)
36489 * Create a new DateSplitField
36490 * @param {Object} config The config object
36493 Roo.bootstrap.form.DateSplitField = function(config){
36494 Roo.bootstrap.form.DateSplitField.superclass.constructor.call(this, config);
36500 * getting the data of years
36501 * @param {Roo.bootstrap.form.DateSplitField} this
36502 * @param {Object} years
36507 * getting the data of days
36508 * @param {Roo.bootstrap.form.DateSplitField} this
36509 * @param {Object} days
36514 * Fires after the field has been marked as invalid.
36515 * @param {Roo.form.Field} this
36516 * @param {String} msg The validation message
36521 * Fires after the field has been validated with no errors.
36522 * @param {Roo.form.Field} this
36528 Roo.extend(Roo.bootstrap.form.DateSplitField, Roo.bootstrap.Component, {
36531 labelAlign : 'top',
36533 dayAllowBlank : false,
36534 monthAllowBlank : false,
36535 yearAllowBlank : false,
36536 dayPlaceholder : '',
36537 monthPlaceholder : '',
36538 yearPlaceholder : '',
36542 isFormField : true,
36548 getAutoCreate : function()
36552 cls : 'row roo-date-split-field-group',
36557 cls : 'form-hidden-field roo-date-split-field-group-value',
36563 var labelCls = 'col-md-12';
36564 var contentCls = 'col-md-4';
36566 if(this.fieldLabel){
36570 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
36574 html : this.fieldLabel
36579 if(this.labelAlign == 'left'){
36581 if(this.labelWidth > 12){
36582 label.style = "width: " + this.labelWidth + 'px';
36585 if(this.labelWidth < 13 && this.labelmd == 0){
36586 this.labelmd = this.labelWidth;
36589 if(this.labellg > 0){
36590 labelCls = ' col-lg-' + this.labellg;
36591 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
36594 if(this.labelmd > 0){
36595 labelCls = ' col-md-' + this.labelmd;
36596 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
36599 if(this.labelsm > 0){
36600 labelCls = ' col-sm-' + this.labelsm;
36601 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
36604 if(this.labelxs > 0){
36605 labelCls = ' col-xs-' + this.labelxs;
36606 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
36610 label.cls += ' ' + labelCls;
36612 cfg.cn.push(label);
36615 Roo.each(['day', 'month', 'year'], function(t){
36618 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
36625 inputEl: function ()
36627 return this.el.select('.roo-date-split-field-group-value', true).first();
36630 onRender : function(ct, position)
36634 Roo.bootstrap.DateSplitFiel.superclass.onRender.call(this, ct, position);
36636 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
36638 this.dayField = new Roo.bootstrap.form.ComboBox({
36639 allowBlank : this.dayAllowBlank,
36640 alwaysQuery : true,
36641 displayField : 'value',
36644 forceSelection : true,
36646 placeholder : this.dayPlaceholder,
36647 selectOnFocus : true,
36648 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
36649 triggerAction : 'all',
36651 valueField : 'value',
36652 store : new Roo.data.SimpleStore({
36653 data : (function() {
36655 _this.fireEvent('days', _this, days);
36658 fields : [ 'value' ]
36661 select : function (_self, record, index)
36663 _this.setValue(_this.getValue());
36668 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
36670 this.monthField = new Roo.bootstrap.form.MonthField({
36671 after : '<i class=\"fa fa-calendar\"></i>',
36672 allowBlank : this.monthAllowBlank,
36673 placeholder : this.monthPlaceholder,
36676 render : function (_self)
36678 this.el.select('span.input-group-addon', true).first().on('click', function(e){
36679 e.preventDefault();
36683 select : function (_self, oldvalue, newvalue)
36685 _this.setValue(_this.getValue());
36690 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
36692 this.yearField = new Roo.bootstrap.form.ComboBox({
36693 allowBlank : this.yearAllowBlank,
36694 alwaysQuery : true,
36695 displayField : 'value',
36698 forceSelection : true,
36700 placeholder : this.yearPlaceholder,
36701 selectOnFocus : true,
36702 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
36703 triggerAction : 'all',
36705 valueField : 'value',
36706 store : new Roo.data.SimpleStore({
36707 data : (function() {
36709 _this.fireEvent('years', _this, years);
36712 fields : [ 'value' ]
36715 select : function (_self, record, index)
36717 _this.setValue(_this.getValue());
36722 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
36725 setValue : function(v, format)
36727 this.inputEl.dom.value = v;
36729 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
36731 var d = Date.parseDate(v, f);
36738 this.setDay(d.format(this.dayFormat));
36739 this.setMonth(d.format(this.monthFormat));
36740 this.setYear(d.format(this.yearFormat));
36747 setDay : function(v)
36749 this.dayField.setValue(v);
36750 this.inputEl.dom.value = this.getValue();
36755 setMonth : function(v)
36757 this.monthField.setValue(v, true);
36758 this.inputEl.dom.value = this.getValue();
36763 setYear : function(v)
36765 this.yearField.setValue(v);
36766 this.inputEl.dom.value = this.getValue();
36771 getDay : function()
36773 return this.dayField.getValue();
36776 getMonth : function()
36778 return this.monthField.getValue();
36781 getYear : function()
36783 return this.yearField.getValue();
36786 getValue : function()
36788 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
36790 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
36800 this.inputEl.dom.value = '';
36805 validate : function()
36807 var d = this.dayField.validate();
36808 var m = this.monthField.validate();
36809 var y = this.yearField.validate();
36814 (!this.dayAllowBlank && !d) ||
36815 (!this.monthAllowBlank && !m) ||
36816 (!this.yearAllowBlank && !y)
36821 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
36830 this.markInvalid();
36835 markValid : function()
36838 var label = this.el.select('label', true).first();
36839 var icon = this.el.select('i.fa-star', true).first();
36845 this.fireEvent('valid', this);
36849 * Mark this field as invalid
36850 * @param {String} msg The validation message
36852 markInvalid : function(msg)
36855 var label = this.el.select('label', true).first();
36856 var icon = this.el.select('i.fa-star', true).first();
36858 if(label && !icon){
36859 this.el.select('.roo-date-split-field-label', true).createChild({
36861 cls : 'text-danger fa fa-lg fa-star',
36862 tooltip : 'This field is required',
36863 style : 'margin-right:5px;'
36867 this.fireEvent('invalid', this, msg);
36870 clearInvalid : function()
36872 var label = this.el.select('label', true).first();
36873 var icon = this.el.select('i.fa-star', true).first();
36879 this.fireEvent('valid', this);
36882 getName: function()
36892 * @class Roo.bootstrap.LayoutMasonry
36893 * @extends Roo.bootstrap.Component
36894 * @children Roo.bootstrap.Element Roo.bootstrap.Img Roo.bootstrap.MasonryBrick
36895 * Bootstrap Layout Masonry class
36898 * http://masonry.desandro.com
36900 * The idea is to render all the bricks based on vertical width...
36902 * The original code extends 'outlayer' - we might need to use that....
36905 * Create a new Element
36906 * @param {Object} config The config object
36909 Roo.bootstrap.LayoutMasonry = function(config){
36911 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
36915 Roo.bootstrap.LayoutMasonry.register(this);
36921 * Fire after layout the items
36922 * @param {Roo.bootstrap.LayoutMasonry} this
36923 * @param {Roo.EventObject} e
36930 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
36933 * @cfg {Boolean} isLayoutInstant = no animation?
36935 isLayoutInstant : false, // needed?
36938 * @cfg {Number} boxWidth width of the columns
36943 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
36948 * @cfg {Number} padWidth padding below box..
36953 * @cfg {Number} gutter gutter width..
36958 * @cfg {Number} maxCols maximum number of columns
36964 * @cfg {Boolean} isAutoInitial defalut true
36966 isAutoInitial : true,
36971 * @cfg {Boolean} isHorizontal defalut false
36973 isHorizontal : false,
36975 currentSize : null,
36981 bricks: null, //CompositeElement
36985 _isLayoutInited : false,
36987 // isAlternative : false, // only use for vertical layout...
36990 * @cfg {Number} alternativePadWidth padding below box..
36992 alternativePadWidth : 50,
36994 selectedBrick : [],
36996 getAutoCreate : function(){
36998 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
37002 cls: 'blog-masonary-wrapper ' + this.cls,
37004 cls : 'mas-boxes masonary'
37011 getChildContainer: function( )
37013 if (this.boxesEl) {
37014 return this.boxesEl;
37017 this.boxesEl = this.el.select('.mas-boxes').first();
37019 return this.boxesEl;
37023 initEvents : function()
37027 if(this.isAutoInitial){
37028 Roo.log('hook children rendered');
37029 this.on('childrenrendered', function() {
37030 Roo.log('children rendered');
37036 initial : function()
37038 this.selectedBrick = [];
37040 this.currentSize = this.el.getBox(true);
37042 Roo.EventManager.onWindowResize(this.resize, this);
37044 if(!this.isAutoInitial){
37052 //this.layout.defer(500,this);
37056 resize : function()
37058 var cs = this.el.getBox(true);
37061 this.currentSize.width == cs.width &&
37062 this.currentSize.x == cs.x &&
37063 this.currentSize.height == cs.height &&
37064 this.currentSize.y == cs.y
37066 Roo.log("no change in with or X or Y");
37070 this.currentSize = cs;
37076 layout : function()
37078 this._resetLayout();
37080 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
37082 this.layoutItems( isInstant );
37084 this._isLayoutInited = true;
37086 this.fireEvent('layout', this);
37090 _resetLayout : function()
37092 if(this.isHorizontal){
37093 this.horizontalMeasureColumns();
37097 this.verticalMeasureColumns();
37101 verticalMeasureColumns : function()
37103 this.getContainerWidth();
37105 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
37106 // this.colWidth = Math.floor(this.containerWidth * 0.8);
37110 var boxWidth = this.boxWidth + this.padWidth;
37112 if(this.containerWidth < this.boxWidth){
37113 boxWidth = this.containerWidth
37116 var containerWidth = this.containerWidth;
37118 var cols = Math.floor(containerWidth / boxWidth);
37120 this.cols = Math.max( cols, 1 );
37122 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
37124 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
37126 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
37128 this.colWidth = boxWidth + avail - this.padWidth;
37130 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
37131 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
37134 horizontalMeasureColumns : function()
37136 this.getContainerWidth();
37138 var boxWidth = this.boxWidth;
37140 if(this.containerWidth < boxWidth){
37141 boxWidth = this.containerWidth;
37144 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
37146 this.el.setHeight(boxWidth);
37150 getContainerWidth : function()
37152 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
37155 layoutItems : function( isInstant )
37157 Roo.log(this.bricks);
37159 var items = Roo.apply([], this.bricks);
37161 if(this.isHorizontal){
37162 this._horizontalLayoutItems( items , isInstant );
37166 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
37167 // this._verticalAlternativeLayoutItems( items , isInstant );
37171 this._verticalLayoutItems( items , isInstant );
37175 _verticalLayoutItems : function ( items , isInstant)
37177 if ( !items || !items.length ) {
37182 ['xs', 'xs', 'xs', 'tall'],
37183 ['xs', 'xs', 'tall'],
37184 ['xs', 'xs', 'sm'],
37185 ['xs', 'xs', 'xs'],
37191 ['sm', 'xs', 'xs'],
37195 ['tall', 'xs', 'xs', 'xs'],
37196 ['tall', 'xs', 'xs'],
37208 Roo.each(items, function(item, k){
37210 switch (item.size) {
37211 // these layouts take up a full box,
37222 boxes.push([item]);
37245 var filterPattern = function(box, length)
37253 var pattern = box.slice(0, length);
37257 Roo.each(pattern, function(i){
37258 format.push(i.size);
37261 Roo.each(standard, function(s){
37263 if(String(s) != String(format)){
37272 if(!match && length == 1){
37277 filterPattern(box, length - 1);
37281 queue.push(pattern);
37283 box = box.slice(length, box.length);
37285 filterPattern(box, 4);
37291 Roo.each(boxes, function(box, k){
37297 if(box.length == 1){
37302 filterPattern(box, 4);
37306 this._processVerticalLayoutQueue( queue, isInstant );
37310 // _verticalAlternativeLayoutItems : function( items , isInstant )
37312 // if ( !items || !items.length ) {
37316 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
37320 _horizontalLayoutItems : function ( items , isInstant)
37322 if ( !items || !items.length || items.length < 3) {
37328 var eItems = items.slice(0, 3);
37330 items = items.slice(3, items.length);
37333 ['xs', 'xs', 'xs', 'wide'],
37334 ['xs', 'xs', 'wide'],
37335 ['xs', 'xs', 'sm'],
37336 ['xs', 'xs', 'xs'],
37342 ['sm', 'xs', 'xs'],
37346 ['wide', 'xs', 'xs', 'xs'],
37347 ['wide', 'xs', 'xs'],
37360 Roo.each(items, function(item, k){
37362 switch (item.size) {
37373 boxes.push([item]);
37397 var filterPattern = function(box, length)
37405 var pattern = box.slice(0, length);
37409 Roo.each(pattern, function(i){
37410 format.push(i.size);
37413 Roo.each(standard, function(s){
37415 if(String(s) != String(format)){
37424 if(!match && length == 1){
37429 filterPattern(box, length - 1);
37433 queue.push(pattern);
37435 box = box.slice(length, box.length);
37437 filterPattern(box, 4);
37443 Roo.each(boxes, function(box, k){
37449 if(box.length == 1){
37454 filterPattern(box, 4);
37461 var pos = this.el.getBox(true);
37465 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
37467 var hit_end = false;
37469 Roo.each(queue, function(box){
37473 Roo.each(box, function(b){
37475 b.el.setVisibilityMode(Roo.Element.DISPLAY);
37485 Roo.each(box, function(b){
37487 b.el.setVisibilityMode(Roo.Element.DISPLAY);
37490 mx = Math.max(mx, b.x);
37494 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
37498 Roo.each(box, function(b){
37500 b.el.setVisibilityMode(Roo.Element.DISPLAY);
37514 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
37517 /** Sets position of item in DOM
37518 * @param {Element} item
37519 * @param {Number} x - horizontal position
37520 * @param {Number} y - vertical position
37521 * @param {Boolean} isInstant - disables transitions
37523 _processVerticalLayoutQueue : function( queue, isInstant )
37525 var pos = this.el.getBox(true);
37530 for (var i = 0; i < this.cols; i++){
37534 Roo.each(queue, function(box, k){
37536 var col = k % this.cols;
37538 Roo.each(box, function(b,kk){
37540 b.el.position('absolute');
37542 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
37543 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
37545 if(b.size == 'md-left' || b.size == 'md-right'){
37546 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
37547 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
37550 b.el.setWidth(width);
37551 b.el.setHeight(height);
37553 b.el.select('iframe',true).setSize(width,height);
37557 for (var i = 0; i < this.cols; i++){
37559 if(maxY[i] < maxY[col]){
37564 col = Math.min(col, i);
37568 x = pos.x + col * (this.colWidth + this.padWidth);
37572 var positions = [];
37574 switch (box.length){
37576 positions = this.getVerticalOneBoxColPositions(x, y, box);
37579 positions = this.getVerticalTwoBoxColPositions(x, y, box);
37582 positions = this.getVerticalThreeBoxColPositions(x, y, box);
37585 positions = this.getVerticalFourBoxColPositions(x, y, box);
37591 Roo.each(box, function(b,kk){
37593 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
37595 var sz = b.el.getSize();
37597 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
37605 for (var i = 0; i < this.cols; i++){
37606 mY = Math.max(mY, maxY[i]);
37609 this.el.setHeight(mY - pos.y);
37613 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
37615 // var pos = this.el.getBox(true);
37618 // var maxX = pos.right;
37620 // var maxHeight = 0;
37622 // Roo.each(items, function(item, k){
37626 // item.el.position('absolute');
37628 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
37630 // item.el.setWidth(width);
37632 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
37634 // item.el.setHeight(height);
37637 // item.el.setXY([x, y], isInstant ? false : true);
37639 // item.el.setXY([maxX - width, y], isInstant ? false : true);
37642 // y = y + height + this.alternativePadWidth;
37644 // maxHeight = maxHeight + height + this.alternativePadWidth;
37648 // this.el.setHeight(maxHeight);
37652 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
37654 var pos = this.el.getBox(true);
37659 var maxX = pos.right;
37661 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
37663 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
37665 Roo.each(queue, function(box, k){
37667 Roo.each(box, function(b, kk){
37669 b.el.position('absolute');
37671 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
37672 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
37674 if(b.size == 'md-left' || b.size == 'md-right'){
37675 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
37676 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
37679 b.el.setWidth(width);
37680 b.el.setHeight(height);
37688 var positions = [];
37690 switch (box.length){
37692 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
37695 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
37698 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
37701 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
37707 Roo.each(box, function(b,kk){
37709 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
37711 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
37719 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
37721 Roo.each(eItems, function(b,k){
37723 b.size = (k == 0) ? 'sm' : 'xs';
37724 b.x = (k == 0) ? 2 : 1;
37725 b.y = (k == 0) ? 2 : 1;
37727 b.el.position('absolute');
37729 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
37731 b.el.setWidth(width);
37733 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
37735 b.el.setHeight(height);
37739 var positions = [];
37742 x : maxX - this.unitWidth * 2 - this.gutter,
37747 x : maxX - this.unitWidth,
37748 y : minY + (this.unitWidth + this.gutter) * 2
37752 x : maxX - this.unitWidth * 3 - this.gutter * 2,
37756 Roo.each(eItems, function(b,k){
37758 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
37764 getVerticalOneBoxColPositions : function(x, y, box)
37768 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
37770 if(box[0].size == 'md-left'){
37774 if(box[0].size == 'md-right'){
37779 x : x + (this.unitWidth + this.gutter) * rand,
37786 getVerticalTwoBoxColPositions : function(x, y, box)
37790 if(box[0].size == 'xs'){
37794 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
37798 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
37812 x : x + (this.unitWidth + this.gutter) * 2,
37813 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
37820 getVerticalThreeBoxColPositions : function(x, y, box)
37824 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
37832 x : x + (this.unitWidth + this.gutter) * 1,
37837 x : x + (this.unitWidth + this.gutter) * 2,
37845 if(box[0].size == 'xs' && box[1].size == 'xs'){
37854 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
37858 x : x + (this.unitWidth + this.gutter) * 1,
37872 x : x + (this.unitWidth + this.gutter) * 2,
37877 x : x + (this.unitWidth + this.gutter) * 2,
37878 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
37885 getVerticalFourBoxColPositions : function(x, y, box)
37889 if(box[0].size == 'xs'){
37898 y : y + (this.unitHeight + this.gutter) * 1
37903 y : y + (this.unitHeight + this.gutter) * 2
37907 x : x + (this.unitWidth + this.gutter) * 1,
37921 x : x + (this.unitWidth + this.gutter) * 2,
37926 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
37927 y : y + (this.unitHeight + this.gutter) * 1
37931 x : x + (this.unitWidth + this.gutter) * 2,
37932 y : y + (this.unitWidth + this.gutter) * 2
37939 getHorizontalOneBoxColPositions : function(maxX, minY, box)
37943 if(box[0].size == 'md-left'){
37945 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
37952 if(box[0].size == 'md-right'){
37954 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
37955 y : minY + (this.unitWidth + this.gutter) * 1
37961 var rand = Math.floor(Math.random() * (4 - box[0].y));
37964 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
37965 y : minY + (this.unitWidth + this.gutter) * rand
37972 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
37976 if(box[0].size == 'xs'){
37979 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
37984 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
37985 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
37993 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
37998 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
37999 y : minY + (this.unitWidth + this.gutter) * 2
38006 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
38010 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
38013 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
38018 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
38019 y : minY + (this.unitWidth + this.gutter) * 1
38023 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
38024 y : minY + (this.unitWidth + this.gutter) * 2
38031 if(box[0].size == 'xs' && box[1].size == 'xs'){
38034 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
38039 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
38044 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
38045 y : minY + (this.unitWidth + this.gutter) * 1
38053 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
38058 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
38059 y : minY + (this.unitWidth + this.gutter) * 2
38063 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
38064 y : minY + (this.unitWidth + this.gutter) * 2
38071 getHorizontalFourBoxColPositions : function(maxX, minY, box)
38075 if(box[0].size == 'xs'){
38078 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
38083 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
38088 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),
38093 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
38094 y : minY + (this.unitWidth + this.gutter) * 1
38102 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
38107 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
38108 y : minY + (this.unitWidth + this.gutter) * 2
38112 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
38113 y : minY + (this.unitWidth + this.gutter) * 2
38117 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),
38118 y : minY + (this.unitWidth + this.gutter) * 2
38126 * remove a Masonry Brick
38127 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
38129 removeBrick : function(brick_id)
38135 for (var i = 0; i<this.bricks.length; i++) {
38136 if (this.bricks[i].id == brick_id) {
38137 this.bricks.splice(i,1);
38138 this.el.dom.removeChild(Roo.get(brick_id).dom);
38145 * adds a Masonry Brick
38146 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
38148 addBrick : function(cfg)
38150 var cn = new Roo.bootstrap.MasonryBrick(cfg);
38151 //this.register(cn);
38152 cn.parentId = this.id;
38153 cn.render(this.el);
38158 * register a Masonry Brick
38159 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
38162 register : function(brick)
38164 this.bricks.push(brick);
38165 brick.masonryId = this.id;
38169 * clear all the Masonry Brick
38171 clearAll : function()
38174 //this.getChildContainer().dom.innerHTML = "";
38175 this.el.dom.innerHTML = '';
38178 getSelected : function()
38180 if (!this.selectedBrick) {
38184 return this.selectedBrick;
38188 Roo.apply(Roo.bootstrap.LayoutMasonry, {
38192 * register a Masonry Layout
38193 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
38196 register : function(layout)
38198 this.groups[layout.id] = layout;
38201 * fetch a Masonry Layout based on the masonry layout ID
38202 * @param {string} the masonry layout to add
38203 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
38206 get: function(layout_id) {
38207 if (typeof(this.groups[layout_id]) == 'undefined') {
38210 return this.groups[layout_id] ;
38222 * http://masonry.desandro.com
38224 * The idea is to render all the bricks based on vertical width...
38226 * The original code extends 'outlayer' - we might need to use that....
38232 * @class Roo.bootstrap.LayoutMasonryAuto
38233 * @extends Roo.bootstrap.Component
38234 * Bootstrap Layout Masonry class
38237 * Create a new Element
38238 * @param {Object} config The config object
38241 Roo.bootstrap.LayoutMasonryAuto = function(config){
38242 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
38245 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
38248 * @cfg {Boolean} isFitWidth - resize the width..
38250 isFitWidth : false, // options..
38252 * @cfg {Boolean} isOriginLeft = left align?
38254 isOriginLeft : true,
38256 * @cfg {Boolean} isOriginTop = top align?
38258 isOriginTop : false,
38260 * @cfg {Boolean} isLayoutInstant = no animation?
38262 isLayoutInstant : false, // needed?
38264 * @cfg {Boolean} isResizingContainer = not sure if this is used..
38266 isResizingContainer : true,
38268 * @cfg {Number} columnWidth width of the columns
38274 * @cfg {Number} maxCols maximum number of columns
38279 * @cfg {Number} padHeight padding below box..
38285 * @cfg {Boolean} isAutoInitial defalut true
38288 isAutoInitial : true,
38294 initialColumnWidth : 0,
38295 currentSize : null,
38297 colYs : null, // array.
38304 bricks: null, //CompositeElement
38305 cols : 0, // array?
38306 // element : null, // wrapped now this.el
38307 _isLayoutInited : null,
38310 getAutoCreate : function(){
38314 cls: 'blog-masonary-wrapper ' + this.cls,
38316 cls : 'mas-boxes masonary'
38323 getChildContainer: function( )
38325 if (this.boxesEl) {
38326 return this.boxesEl;
38329 this.boxesEl = this.el.select('.mas-boxes').first();
38331 return this.boxesEl;
38335 initEvents : function()
38339 if(this.isAutoInitial){
38340 Roo.log('hook children rendered');
38341 this.on('childrenrendered', function() {
38342 Roo.log('children rendered');
38349 initial : function()
38351 this.reloadItems();
38353 this.currentSize = this.el.getBox(true);
38355 /// was window resize... - let's see if this works..
38356 Roo.EventManager.onWindowResize(this.resize, this);
38358 if(!this.isAutoInitial){
38363 this.layout.defer(500,this);
38366 reloadItems: function()
38368 this.bricks = this.el.select('.masonry-brick', true);
38370 this.bricks.each(function(b) {
38371 //Roo.log(b.getSize());
38372 if (!b.attr('originalwidth')) {
38373 b.attr('originalwidth', b.getSize().width);
38378 Roo.log(this.bricks.elements.length);
38381 resize : function()
38384 var cs = this.el.getBox(true);
38386 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
38387 Roo.log("no change in with or X");
38390 this.currentSize = cs;
38394 layout : function()
38397 this._resetLayout();
38398 //this._manageStamps();
38400 // don't animate first layout
38401 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
38402 this.layoutItems( isInstant );
38404 // flag for initalized
38405 this._isLayoutInited = true;
38408 layoutItems : function( isInstant )
38410 //var items = this._getItemsForLayout( this.items );
38411 // original code supports filtering layout items.. we just ignore it..
38413 this._layoutItems( this.bricks , isInstant );
38415 this._postLayout();
38417 _layoutItems : function ( items , isInstant)
38419 //this.fireEvent( 'layout', this, items );
38422 if ( !items || !items.elements.length ) {
38423 // no items, emit event with empty array
38428 items.each(function(item) {
38429 Roo.log("layout item");
38431 // get x/y object from method
38432 var position = this._getItemLayoutPosition( item );
38434 position.item = item;
38435 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
38436 queue.push( position );
38439 this._processLayoutQueue( queue );
38441 /** Sets position of item in DOM
38442 * @param {Element} item
38443 * @param {Number} x - horizontal position
38444 * @param {Number} y - vertical position
38445 * @param {Boolean} isInstant - disables transitions
38447 _processLayoutQueue : function( queue )
38449 for ( var i=0, len = queue.length; i < len; i++ ) {
38450 var obj = queue[i];
38451 obj.item.position('absolute');
38452 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
38458 * Any logic you want to do after each layout,
38459 * i.e. size the container
38461 _postLayout : function()
38463 this.resizeContainer();
38466 resizeContainer : function()
38468 if ( !this.isResizingContainer ) {
38471 var size = this._getContainerSize();
38473 this.el.setSize(size.width,size.height);
38474 this.boxesEl.setSize(size.width,size.height);
38480 _resetLayout : function()
38482 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
38483 this.colWidth = this.el.getWidth();
38484 //this.gutter = this.el.getWidth();
38486 this.measureColumns();
38492 this.colYs.push( 0 );
38498 measureColumns : function()
38500 this.getContainerWidth();
38501 // if columnWidth is 0, default to outerWidth of first item
38502 if ( !this.columnWidth ) {
38503 var firstItem = this.bricks.first();
38504 Roo.log(firstItem);
38505 this.columnWidth = this.containerWidth;
38506 if (firstItem && firstItem.attr('originalwidth') ) {
38507 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
38509 // columnWidth fall back to item of first element
38510 Roo.log("set column width?");
38511 this.initialColumnWidth = this.columnWidth ;
38513 // if first elem has no width, default to size of container
38518 if (this.initialColumnWidth) {
38519 this.columnWidth = this.initialColumnWidth;
38524 // column width is fixed at the top - however if container width get's smaller we should
38527 // this bit calcs how man columns..
38529 var columnWidth = this.columnWidth += this.gutter;
38531 // calculate columns
38532 var containerWidth = this.containerWidth + this.gutter;
38534 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
38535 // fix rounding errors, typically with gutters
38536 var excess = columnWidth - containerWidth % columnWidth;
38539 // if overshoot is less than a pixel, round up, otherwise floor it
38540 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
38541 cols = Math[ mathMethod ]( cols );
38542 this.cols = Math.max( cols, 1 );
38543 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
38545 // padding positioning..
38546 var totalColWidth = this.cols * this.columnWidth;
38547 var padavail = this.containerWidth - totalColWidth;
38548 // so for 2 columns - we need 3 'pads'
38550 var padNeeded = (1+this.cols) * this.padWidth;
38552 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
38554 this.columnWidth += padExtra
38555 //this.padWidth = Math.floor(padavail / ( this.cols));
38557 // adjust colum width so that padding is fixed??
38559 // we have 3 columns ... total = width * 3
38560 // we have X left over... that should be used by
38562 //if (this.expandC) {
38570 getContainerWidth : function()
38572 /* // container is parent if fit width
38573 var container = this.isFitWidth ? this.element.parentNode : this.element;
38574 // check that this.size and size are there
38575 // IE8 triggers resize on body size change, so they might not be
38577 var size = getSize( container ); //FIXME
38578 this.containerWidth = size && size.innerWidth; //FIXME
38581 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
38585 _getItemLayoutPosition : function( item ) // what is item?
38587 // we resize the item to our columnWidth..
38589 item.setWidth(this.columnWidth);
38590 item.autoBoxAdjust = false;
38592 var sz = item.getSize();
38594 // how many columns does this brick span
38595 var remainder = this.containerWidth % this.columnWidth;
38597 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
38598 // round if off by 1 pixel, otherwise use ceil
38599 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
38600 colSpan = Math.min( colSpan, this.cols );
38602 // normally this should be '1' as we dont' currently allow multi width columns..
38604 var colGroup = this._getColGroup( colSpan );
38605 // get the minimum Y value from the columns
38606 var minimumY = Math.min.apply( Math, colGroup );
38607 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
38609 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
38611 // position the brick
38613 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
38614 y: this.currentSize.y + minimumY + this.padHeight
38618 // apply setHeight to necessary columns
38619 var setHeight = minimumY + sz.height + this.padHeight;
38620 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
38622 var setSpan = this.cols + 1 - colGroup.length;
38623 for ( var i = 0; i < setSpan; i++ ) {
38624 this.colYs[ shortColIndex + i ] = setHeight ;
38631 * @param {Number} colSpan - number of columns the element spans
38632 * @returns {Array} colGroup
38634 _getColGroup : function( colSpan )
38636 if ( colSpan < 2 ) {
38637 // if brick spans only one column, use all the column Ys
38642 // how many different places could this brick fit horizontally
38643 var groupCount = this.cols + 1 - colSpan;
38644 // for each group potential horizontal position
38645 for ( var i = 0; i < groupCount; i++ ) {
38646 // make an array of colY values for that one group
38647 var groupColYs = this.colYs.slice( i, i + colSpan );
38648 // and get the max value of the array
38649 colGroup[i] = Math.max.apply( Math, groupColYs );
38654 _manageStamp : function( stamp )
38656 var stampSize = stamp.getSize();
38657 var offset = stamp.getBox();
38658 // get the columns that this stamp affects
38659 var firstX = this.isOriginLeft ? offset.x : offset.right;
38660 var lastX = firstX + stampSize.width;
38661 var firstCol = Math.floor( firstX / this.columnWidth );
38662 firstCol = Math.max( 0, firstCol );
38664 var lastCol = Math.floor( lastX / this.columnWidth );
38665 // lastCol should not go over if multiple of columnWidth #425
38666 lastCol -= lastX % this.columnWidth ? 0 : 1;
38667 lastCol = Math.min( this.cols - 1, lastCol );
38669 // set colYs to bottom of the stamp
38670 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
38673 for ( var i = firstCol; i <= lastCol; i++ ) {
38674 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
38679 _getContainerSize : function()
38681 this.maxY = Math.max.apply( Math, this.colYs );
38686 if ( this.isFitWidth ) {
38687 size.width = this._getContainerFitWidth();
38693 _getContainerFitWidth : function()
38695 var unusedCols = 0;
38696 // count unused columns
38699 if ( this.colYs[i] !== 0 ) {
38704 // fit container to columns that have been used
38705 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
38708 needsResizeLayout : function()
38710 var previousWidth = this.containerWidth;
38711 this.getContainerWidth();
38712 return previousWidth !== this.containerWidth;
38727 * @class Roo.bootstrap.MasonryBrick
38728 * @extends Roo.bootstrap.Component
38729 * Bootstrap MasonryBrick class
38732 * Create a new MasonryBrick
38733 * @param {Object} config The config object
38736 Roo.bootstrap.MasonryBrick = function(config){
38738 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
38740 Roo.bootstrap.MasonryBrick.register(this);
38746 * When a MasonryBrick is clcik
38747 * @param {Roo.bootstrap.MasonryBrick} this
38748 * @param {Roo.EventObject} e
38754 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
38757 * @cfg {String} title
38761 * @cfg {String} html
38765 * @cfg {String} bgimage
38769 * @cfg {String} videourl
38773 * @cfg {String} cls
38777 * @cfg {String} href
38781 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
38786 * @cfg {String} placetitle (center|bottom)
38791 * @cfg {Boolean} isFitContainer defalut true
38793 isFitContainer : true,
38796 * @cfg {Boolean} preventDefault defalut false
38798 preventDefault : false,
38801 * @cfg {Boolean} inverse defalut false
38803 maskInverse : false,
38805 getAutoCreate : function()
38807 if(!this.isFitContainer){
38808 return this.getSplitAutoCreate();
38811 var cls = 'masonry-brick masonry-brick-full';
38813 if(this.href.length){
38814 cls += ' masonry-brick-link';
38817 if(this.bgimage.length){
38818 cls += ' masonry-brick-image';
38821 if(this.maskInverse){
38822 cls += ' mask-inverse';
38825 if(!this.html.length && !this.maskInverse && !this.videourl.length){
38826 cls += ' enable-mask';
38830 cls += ' masonry-' + this.size + '-brick';
38833 if(this.placetitle.length){
38835 switch (this.placetitle) {
38837 cls += ' masonry-center-title';
38840 cls += ' masonry-bottom-title';
38847 if(!this.html.length && !this.bgimage.length){
38848 cls += ' masonry-center-title';
38851 if(!this.html.length && this.bgimage.length){
38852 cls += ' masonry-bottom-title';
38857 cls += ' ' + this.cls;
38861 tag: (this.href.length) ? 'a' : 'div',
38866 cls: 'masonry-brick-mask'
38870 cls: 'masonry-brick-paragraph',
38876 if(this.href.length){
38877 cfg.href = this.href;
38880 var cn = cfg.cn[1].cn;
38882 if(this.title.length){
38885 cls: 'masonry-brick-title',
38890 if(this.html.length){
38893 cls: 'masonry-brick-text',
38898 if (!this.title.length && !this.html.length) {
38899 cfg.cn[1].cls += ' hide';
38902 if(this.bgimage.length){
38905 cls: 'masonry-brick-image-view',
38910 if(this.videourl.length){
38911 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
38912 // youtube support only?
38915 cls: 'masonry-brick-image-view',
38918 allowfullscreen : true
38926 getSplitAutoCreate : function()
38928 var cls = 'masonry-brick masonry-brick-split';
38930 if(this.href.length){
38931 cls += ' masonry-brick-link';
38934 if(this.bgimage.length){
38935 cls += ' masonry-brick-image';
38939 cls += ' masonry-' + this.size + '-brick';
38942 switch (this.placetitle) {
38944 cls += ' masonry-center-title';
38947 cls += ' masonry-bottom-title';
38950 if(!this.bgimage.length){
38951 cls += ' masonry-center-title';
38954 if(this.bgimage.length){
38955 cls += ' masonry-bottom-title';
38961 cls += ' ' + this.cls;
38965 tag: (this.href.length) ? 'a' : 'div',
38970 cls: 'masonry-brick-split-head',
38974 cls: 'masonry-brick-paragraph',
38981 cls: 'masonry-brick-split-body',
38987 if(this.href.length){
38988 cfg.href = this.href;
38991 if(this.title.length){
38992 cfg.cn[0].cn[0].cn.push({
38994 cls: 'masonry-brick-title',
38999 if(this.html.length){
39000 cfg.cn[1].cn.push({
39002 cls: 'masonry-brick-text',
39007 if(this.bgimage.length){
39008 cfg.cn[0].cn.push({
39010 cls: 'masonry-brick-image-view',
39015 if(this.videourl.length){
39016 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
39017 // youtube support only?
39018 cfg.cn[0].cn.cn.push({
39020 cls: 'masonry-brick-image-view',
39023 allowfullscreen : true
39030 initEvents: function()
39032 switch (this.size) {
39065 this.el.on('touchstart', this.onTouchStart, this);
39066 this.el.on('touchmove', this.onTouchMove, this);
39067 this.el.on('touchend', this.onTouchEnd, this);
39068 this.el.on('contextmenu', this.onContextMenu, this);
39070 this.el.on('mouseenter' ,this.enter, this);
39071 this.el.on('mouseleave', this.leave, this);
39072 this.el.on('click', this.onClick, this);
39075 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
39076 this.parent().bricks.push(this);
39081 onClick: function(e, el)
39083 var time = this.endTimer - this.startTimer;
39084 // Roo.log(e.preventDefault());
39087 e.preventDefault();
39092 if(!this.preventDefault){
39096 e.preventDefault();
39098 if (this.activeClass != '') {
39099 this.selectBrick();
39102 this.fireEvent('click', this, e);
39105 enter: function(e, el)
39107 e.preventDefault();
39109 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
39113 if(this.bgimage.length && this.html.length){
39114 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
39118 leave: function(e, el)
39120 e.preventDefault();
39122 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
39126 if(this.bgimage.length && this.html.length){
39127 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
39131 onTouchStart: function(e, el)
39133 // e.preventDefault();
39135 this.touchmoved = false;
39137 if(!this.isFitContainer){
39141 if(!this.bgimage.length || !this.html.length){
39145 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
39147 this.timer = new Date().getTime();
39151 onTouchMove: function(e, el)
39153 this.touchmoved = true;
39156 onContextMenu : function(e,el)
39158 e.preventDefault();
39159 e.stopPropagation();
39163 onTouchEnd: function(e, el)
39165 // e.preventDefault();
39167 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
39174 if(!this.bgimage.length || !this.html.length){
39176 if(this.href.length){
39177 window.location.href = this.href;
39183 if(!this.isFitContainer){
39187 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
39189 window.location.href = this.href;
39192 //selection on single brick only
39193 selectBrick : function() {
39195 if (!this.parentId) {
39199 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
39200 var index = m.selectedBrick.indexOf(this.id);
39203 m.selectedBrick.splice(index,1);
39204 this.el.removeClass(this.activeClass);
39208 for(var i = 0; i < m.selectedBrick.length; i++) {
39209 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
39210 b.el.removeClass(b.activeClass);
39213 m.selectedBrick = [];
39215 m.selectedBrick.push(this.id);
39216 this.el.addClass(this.activeClass);
39220 isSelected : function(){
39221 return this.el.hasClass(this.activeClass);
39226 Roo.apply(Roo.bootstrap.MasonryBrick, {
39229 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
39231 * register a Masonry Brick
39232 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
39235 register : function(brick)
39237 //this.groups[brick.id] = brick;
39238 this.groups.add(brick.id, brick);
39241 * fetch a masonry brick based on the masonry brick ID
39242 * @param {string} the masonry brick to add
39243 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
39246 get: function(brick_id)
39248 // if (typeof(this.groups[brick_id]) == 'undefined') {
39251 // return this.groups[brick_id] ;
39253 if(this.groups.key(brick_id)) {
39254 return this.groups.key(brick_id);
39272 * @class Roo.bootstrap.Brick
39273 * @extends Roo.bootstrap.Component
39274 * Bootstrap Brick class
39277 * Create a new Brick
39278 * @param {Object} config The config object
39281 Roo.bootstrap.Brick = function(config){
39282 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
39288 * When a Brick is click
39289 * @param {Roo.bootstrap.Brick} this
39290 * @param {Roo.EventObject} e
39296 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
39299 * @cfg {String} title
39303 * @cfg {String} html
39307 * @cfg {String} bgimage
39311 * @cfg {String} cls
39315 * @cfg {String} href
39319 * @cfg {String} video
39323 * @cfg {Boolean} square
39327 getAutoCreate : function()
39329 var cls = 'roo-brick';
39331 if(this.href.length){
39332 cls += ' roo-brick-link';
39335 if(this.bgimage.length){
39336 cls += ' roo-brick-image';
39339 if(!this.html.length && !this.bgimage.length){
39340 cls += ' roo-brick-center-title';
39343 if(!this.html.length && this.bgimage.length){
39344 cls += ' roo-brick-bottom-title';
39348 cls += ' ' + this.cls;
39352 tag: (this.href.length) ? 'a' : 'div',
39357 cls: 'roo-brick-paragraph',
39363 if(this.href.length){
39364 cfg.href = this.href;
39367 var cn = cfg.cn[0].cn;
39369 if(this.title.length){
39372 cls: 'roo-brick-title',
39377 if(this.html.length){
39380 cls: 'roo-brick-text',
39387 if(this.bgimage.length){
39390 cls: 'roo-brick-image-view',
39398 initEvents: function()
39400 if(this.title.length || this.html.length){
39401 this.el.on('mouseenter' ,this.enter, this);
39402 this.el.on('mouseleave', this.leave, this);
39405 Roo.EventManager.onWindowResize(this.resize, this);
39407 if(this.bgimage.length){
39408 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
39409 this.imageEl.on('load', this.onImageLoad, this);
39416 onImageLoad : function()
39421 resize : function()
39423 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
39425 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
39427 if(this.bgimage.length){
39428 var image = this.el.select('.roo-brick-image-view', true).first();
39430 image.setWidth(paragraph.getWidth());
39433 image.setHeight(paragraph.getWidth());
39436 this.el.setHeight(image.getHeight());
39437 paragraph.setHeight(image.getHeight());
39443 enter: function(e, el)
39445 e.preventDefault();
39447 if(this.bgimage.length){
39448 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
39449 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
39453 leave: function(e, el)
39455 e.preventDefault();
39457 if(this.bgimage.length){
39458 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
39459 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
39474 * @class Roo.bootstrap.form.NumberField
39475 * @extends Roo.bootstrap.form.Input
39476 * Bootstrap NumberField class
39482 * Create a new NumberField
39483 * @param {Object} config The config object
39486 Roo.bootstrap.form.NumberField = function(config){
39487 Roo.bootstrap.form.NumberField.superclass.constructor.call(this, config);
39490 Roo.extend(Roo.bootstrap.form.NumberField, Roo.bootstrap.form.Input, {
39493 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
39495 allowDecimals : true,
39497 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
39499 decimalSeparator : ".",
39501 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
39503 decimalPrecision : 2,
39505 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
39507 allowNegative : true,
39510 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
39514 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
39516 minValue : Number.NEGATIVE_INFINITY,
39518 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
39520 maxValue : Number.MAX_VALUE,
39522 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
39524 minText : "The minimum value for this field is {0}",
39526 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
39528 maxText : "The maximum value for this field is {0}",
39530 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
39531 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
39533 nanText : "{0} is not a valid number",
39535 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
39537 thousandsDelimiter : false,
39539 * @cfg {String} valueAlign alignment of value
39541 valueAlign : "left",
39543 getAutoCreate : function()
39545 var hiddenInput = {
39549 cls: 'hidden-number-input'
39553 hiddenInput.name = this.name;
39558 var cfg = Roo.bootstrap.form.NumberField.superclass.getAutoCreate.call(this);
39560 this.name = hiddenInput.name;
39562 if(cfg.cn.length > 0) {
39563 cfg.cn.push(hiddenInput);
39570 initEvents : function()
39572 Roo.bootstrap.form.NumberField.superclass.initEvents.call(this);
39574 var allowed = "0123456789";
39576 if(this.allowDecimals){
39577 allowed += this.decimalSeparator;
39580 if(this.allowNegative){
39584 if(this.thousandsDelimiter) {
39588 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
39590 var keyPress = function(e){
39592 var k = e.getKey();
39594 var c = e.getCharCode();
39597 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
39598 allowed.indexOf(String.fromCharCode(c)) === -1
39604 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
39608 if(allowed.indexOf(String.fromCharCode(c)) === -1){
39613 this.el.on("keypress", keyPress, this);
39616 validateValue : function(value)
39619 if(!Roo.bootstrap.form.NumberField.superclass.validateValue.call(this, value)){
39623 var num = this.parseValue(value);
39626 this.markInvalid(String.format(this.nanText, value));
39630 if(num < this.minValue){
39631 this.markInvalid(String.format(this.minText, this.minValue));
39635 if(num > this.maxValue){
39636 this.markInvalid(String.format(this.maxText, this.maxValue));
39643 getValue : function()
39645 var v = this.hiddenEl().getValue();
39647 return this.fixPrecision(this.parseValue(v));
39650 parseValue : function(value)
39652 if(this.thousandsDelimiter) {
39654 r = new RegExp(",", "g");
39655 value = value.replace(r, "");
39658 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
39659 return isNaN(value) ? '' : value;
39662 fixPrecision : function(value)
39664 if(this.thousandsDelimiter) {
39666 r = new RegExp(",", "g");
39667 value = value.replace(r, "");
39670 var nan = isNaN(value);
39672 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
39673 return nan ? '' : value;
39675 return parseFloat(value).toFixed(this.decimalPrecision);
39678 setValue : function(v)
39680 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
39686 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
39688 this.inputEl().dom.value = (v == '') ? '' :
39689 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
39691 if(!this.allowZero && v === '0') {
39692 this.hiddenEl().dom.value = '';
39693 this.inputEl().dom.value = '';
39700 decimalPrecisionFcn : function(v)
39702 return Math.floor(v);
39705 beforeBlur : function()
39707 var v = this.parseValue(this.getRawValue());
39709 if(v || v === 0 || v === ''){
39714 hiddenEl : function()
39716 return this.el.select('input.hidden-number-input',true).first();
39728 * @class Roo.bootstrap.DocumentSlider
39729 * @extends Roo.bootstrap.Component
39730 * Bootstrap DocumentSlider class
39733 * Create a new DocumentViewer
39734 * @param {Object} config The config object
39737 Roo.bootstrap.DocumentSlider = function(config){
39738 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
39745 * Fire after initEvent
39746 * @param {Roo.bootstrap.DocumentSlider} this
39751 * Fire after update
39752 * @param {Roo.bootstrap.DocumentSlider} this
39758 * @param {Roo.bootstrap.DocumentSlider} this
39764 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
39770 getAutoCreate : function()
39774 cls : 'roo-document-slider',
39778 cls : 'roo-document-slider-header',
39782 cls : 'roo-document-slider-header-title'
39788 cls : 'roo-document-slider-body',
39792 cls : 'roo-document-slider-prev',
39796 cls : 'fa fa-chevron-left'
39802 cls : 'roo-document-slider-thumb',
39806 cls : 'roo-document-slider-image'
39812 cls : 'roo-document-slider-next',
39816 cls : 'fa fa-chevron-right'
39828 initEvents : function()
39830 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
39831 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
39833 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
39834 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
39836 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
39837 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
39839 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
39840 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
39842 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
39843 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
39845 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
39846 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
39848 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
39849 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
39851 this.thumbEl.on('click', this.onClick, this);
39853 this.prevIndicator.on('click', this.prev, this);
39855 this.nextIndicator.on('click', this.next, this);
39859 initial : function()
39861 if(this.files.length){
39862 this.indicator = 1;
39866 this.fireEvent('initial', this);
39869 update : function()
39871 this.imageEl.attr('src', this.files[this.indicator - 1]);
39873 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
39875 this.prevIndicator.show();
39877 if(this.indicator == 1){
39878 this.prevIndicator.hide();
39881 this.nextIndicator.show();
39883 if(this.indicator == this.files.length){
39884 this.nextIndicator.hide();
39887 this.thumbEl.scrollTo('top');
39889 this.fireEvent('update', this);
39892 onClick : function(e)
39894 e.preventDefault();
39896 this.fireEvent('click', this);
39901 e.preventDefault();
39903 this.indicator = Math.max(1, this.indicator - 1);
39910 e.preventDefault();
39912 this.indicator = Math.min(this.files.length, this.indicator + 1);
39926 * @class Roo.bootstrap.form.RadioSet
39927 * @extends Roo.bootstrap.form.Input
39928 * @children Roo.bootstrap.form.Radio
39929 * Bootstrap RadioSet class
39930 * @cfg {String} indicatorpos (left|right) default left
39931 * @cfg {Boolean} inline (true|false) inline the element (default true)
39932 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
39934 * Create a new RadioSet
39935 * @param {Object} config The config object
39938 Roo.bootstrap.form.RadioSet = function(config){
39940 Roo.bootstrap.form.RadioSet.superclass.constructor.call(this, config);
39944 Roo.bootstrap.form.RadioSet.register(this);
39949 * Fires when the element is checked or unchecked.
39950 * @param {Roo.bootstrap.form.RadioSet} this This radio
39951 * @param {Roo.bootstrap.form.Radio} item The checked item
39956 * Fires when the element is click.
39957 * @param {Roo.bootstrap.form.RadioSet} this This radio set
39958 * @param {Roo.bootstrap.form.Radio} item The checked item
39959 * @param {Roo.EventObject} e The event object
39966 Roo.extend(Roo.bootstrap.form.RadioSet, Roo.bootstrap.form.Input, {
39974 indicatorpos : 'left',
39976 getAutoCreate : function()
39980 cls : 'roo-radio-set-label',
39984 html : this.fieldLabel
39988 if (Roo.bootstrap.version == 3) {
39991 if(this.indicatorpos == 'left'){
39994 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
39995 tooltip : 'This field is required'
40000 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
40001 tooltip : 'This field is required'
40007 cls : 'roo-radio-set-items'
40010 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
40012 if (align === 'left' && this.fieldLabel.length) {
40015 cls : "roo-radio-set-right",
40021 if(this.labelWidth > 12){
40022 label.style = "width: " + this.labelWidth + 'px';
40025 if(this.labelWidth < 13 && this.labelmd == 0){
40026 this.labelmd = this.labelWidth;
40029 if(this.labellg > 0){
40030 label.cls += ' col-lg-' + this.labellg;
40031 items.cls += ' col-lg-' + (12 - this.labellg);
40034 if(this.labelmd > 0){
40035 label.cls += ' col-md-' + this.labelmd;
40036 items.cls += ' col-md-' + (12 - this.labelmd);
40039 if(this.labelsm > 0){
40040 label.cls += ' col-sm-' + this.labelsm;
40041 items.cls += ' col-sm-' + (12 - this.labelsm);
40044 if(this.labelxs > 0){
40045 label.cls += ' col-xs-' + this.labelxs;
40046 items.cls += ' col-xs-' + (12 - this.labelxs);
40052 cls : 'roo-radio-set',
40056 cls : 'roo-radio-set-input',
40059 value : this.value ? this.value : ''
40066 if(this.weight.length){
40067 cfg.cls += ' roo-radio-' + this.weight;
40071 cfg.cls += ' roo-radio-set-inline';
40075 ['xs','sm','md','lg'].map(function(size){
40076 if (settings[size]) {
40077 cfg.cls += ' col-' + size + '-' + settings[size];
40085 initEvents : function()
40087 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
40088 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
40090 if(!this.fieldLabel.length){
40091 this.labelEl.hide();
40094 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
40095 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
40097 this.indicator = this.indicatorEl();
40099 if(this.indicator){
40100 this.indicator.addClass('invisible');
40103 this.originalValue = this.getValue();
40107 inputEl: function ()
40109 return this.el.select('.roo-radio-set-input', true).first();
40112 getChildContainer : function()
40114 return this.itemsEl;
40117 register : function(item)
40119 this.radioes.push(item);
40123 validate : function()
40125 if(this.getVisibilityEl().hasClass('hidden')){
40131 Roo.each(this.radioes, function(i){
40140 if(this.allowBlank) {
40144 if(this.disabled || valid){
40149 this.markInvalid();
40154 markValid : function()
40156 if(this.labelEl.isVisible(true) && this.indicatorEl()){
40157 this.indicatorEl().removeClass('visible');
40158 this.indicatorEl().addClass('invisible');
40162 if (Roo.bootstrap.version == 3) {
40163 this.el.removeClass([this.invalidClass, this.validClass]);
40164 this.el.addClass(this.validClass);
40166 this.el.removeClass(['is-invalid','is-valid']);
40167 this.el.addClass(['is-valid']);
40169 this.fireEvent('valid', this);
40172 markInvalid : function(msg)
40174 if(this.allowBlank || this.disabled){
40178 if(this.labelEl.isVisible(true) && this.indicatorEl()){
40179 this.indicatorEl().removeClass('invisible');
40180 this.indicatorEl().addClass('visible');
40182 if (Roo.bootstrap.version == 3) {
40183 this.el.removeClass([this.invalidClass, this.validClass]);
40184 this.el.addClass(this.invalidClass);
40186 this.el.removeClass(['is-invalid','is-valid']);
40187 this.el.addClass(['is-invalid']);
40190 this.fireEvent('invalid', this, msg);
40194 setValue : function(v, suppressEvent)
40196 if(this.value === v){
40203 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40206 Roo.each(this.radioes, function(i){
40208 i.el.removeClass('checked');
40211 Roo.each(this.radioes, function(i){
40213 if(i.value === v || i.value.toString() === v.toString()){
40215 i.el.addClass('checked');
40217 if(suppressEvent !== true){
40218 this.fireEvent('check', this, i);
40229 clearInvalid : function(){
40231 if(!this.el || this.preventMark){
40235 this.el.removeClass([this.invalidClass]);
40237 this.fireEvent('valid', this);
40242 Roo.apply(Roo.bootstrap.form.RadioSet, {
40246 register : function(set)
40248 this.groups[set.name] = set;
40251 get: function(name)
40253 if (typeof(this.groups[name]) == 'undefined') {
40257 return this.groups[name] ;
40263 * Ext JS Library 1.1.1
40264 * Copyright(c) 2006-2007, Ext JS, LLC.
40266 * Originally Released Under LGPL - original licence link has changed is not relivant.
40269 * <script type="text/javascript">
40274 * @class Roo.bootstrap.SplitBar
40275 * @extends Roo.util.Observable
40276 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
40280 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
40281 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
40282 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
40283 split.minSize = 100;
40284 split.maxSize = 600;
40285 split.animate = true;
40286 split.on('moved', splitterMoved);
40289 * Create a new SplitBar
40290 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
40291 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
40292 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
40293 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
40294 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
40295 position of the SplitBar).
40297 Roo.bootstrap.SplitBar = function(cfg){
40302 // dragElement : elm
40303 // resizingElement: el,
40305 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
40306 // placement : Roo.bootstrap.SplitBar.LEFT ,
40307 // existingProxy ???
40310 this.el = Roo.get(cfg.dragElement, true);
40311 this.el.dom.unselectable = "on";
40313 this.resizingEl = Roo.get(cfg.resizingElement, true);
40317 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
40318 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
40321 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
40324 * The minimum size of the resizing element. (Defaults to 0)
40330 * The maximum size of the resizing element. (Defaults to 2000)
40333 this.maxSize = 2000;
40336 * Whether to animate the transition to the new size
40339 this.animate = false;
40342 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
40345 this.useShim = false;
40350 if(!cfg.existingProxy){
40352 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
40354 this.proxy = Roo.get(cfg.existingProxy).dom;
40357 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
40360 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
40363 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
40366 this.dragSpecs = {};
40369 * @private The adapter to use to positon and resize elements
40371 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
40372 this.adapter.init(this);
40374 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
40376 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
40377 this.el.addClass("roo-splitbar-h");
40380 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
40381 this.el.addClass("roo-splitbar-v");
40387 * Fires when the splitter is moved (alias for {@link #event-moved})
40388 * @param {Roo.bootstrap.SplitBar} this
40389 * @param {Number} newSize the new width or height
40394 * Fires when the splitter is moved
40395 * @param {Roo.bootstrap.SplitBar} this
40396 * @param {Number} newSize the new width or height
40400 * @event beforeresize
40401 * Fires before the splitter is dragged
40402 * @param {Roo.bootstrap.SplitBar} this
40404 "beforeresize" : true,
40406 "beforeapply" : true
40409 Roo.util.Observable.call(this);
40412 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
40413 onStartProxyDrag : function(x, y){
40414 this.fireEvent("beforeresize", this);
40416 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
40418 o.enableDisplayMode("block");
40419 // all splitbars share the same overlay
40420 Roo.bootstrap.SplitBar.prototype.overlay = o;
40422 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
40423 this.overlay.show();
40424 Roo.get(this.proxy).setDisplayed("block");
40425 var size = this.adapter.getElementSize(this);
40426 this.activeMinSize = this.getMinimumSize();;
40427 this.activeMaxSize = this.getMaximumSize();;
40428 var c1 = size - this.activeMinSize;
40429 var c2 = Math.max(this.activeMaxSize - size, 0);
40430 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
40431 this.dd.resetConstraints();
40432 this.dd.setXConstraint(
40433 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
40434 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
40436 this.dd.setYConstraint(0, 0);
40438 this.dd.resetConstraints();
40439 this.dd.setXConstraint(0, 0);
40440 this.dd.setYConstraint(
40441 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
40442 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
40445 this.dragSpecs.startSize = size;
40446 this.dragSpecs.startPoint = [x, y];
40447 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
40451 * @private Called after the drag operation by the DDProxy
40453 onEndProxyDrag : function(e){
40454 Roo.get(this.proxy).setDisplayed(false);
40455 var endPoint = Roo.lib.Event.getXY(e);
40457 this.overlay.hide();
40460 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
40461 newSize = this.dragSpecs.startSize +
40462 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
40463 endPoint[0] - this.dragSpecs.startPoint[0] :
40464 this.dragSpecs.startPoint[0] - endPoint[0]
40467 newSize = this.dragSpecs.startSize +
40468 (this.placement == Roo.bootstrap.SplitBar.TOP ?
40469 endPoint[1] - this.dragSpecs.startPoint[1] :
40470 this.dragSpecs.startPoint[1] - endPoint[1]
40473 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
40474 if(newSize != this.dragSpecs.startSize){
40475 if(this.fireEvent('beforeapply', this, newSize) !== false){
40476 this.adapter.setElementSize(this, newSize);
40477 this.fireEvent("moved", this, newSize);
40478 this.fireEvent("resize", this, newSize);
40484 * Get the adapter this SplitBar uses
40485 * @return The adapter object
40487 getAdapter : function(){
40488 return this.adapter;
40492 * Set the adapter this SplitBar uses
40493 * @param {Object} adapter A SplitBar adapter object
40495 setAdapter : function(adapter){
40496 this.adapter = adapter;
40497 this.adapter.init(this);
40501 * Gets the minimum size for the resizing element
40502 * @return {Number} The minimum size
40504 getMinimumSize : function(){
40505 return this.minSize;
40509 * Sets the minimum size for the resizing element
40510 * @param {Number} minSize The minimum size
40512 setMinimumSize : function(minSize){
40513 this.minSize = minSize;
40517 * Gets the maximum size for the resizing element
40518 * @return {Number} The maximum size
40520 getMaximumSize : function(){
40521 return this.maxSize;
40525 * Sets the maximum size for the resizing element
40526 * @param {Number} maxSize The maximum size
40528 setMaximumSize : function(maxSize){
40529 this.maxSize = maxSize;
40533 * Sets the initialize size for the resizing element
40534 * @param {Number} size The initial size
40536 setCurrentSize : function(size){
40537 var oldAnimate = this.animate;
40538 this.animate = false;
40539 this.adapter.setElementSize(this, size);
40540 this.animate = oldAnimate;
40544 * Destroy this splitbar.
40545 * @param {Boolean} removeEl True to remove the element
40547 destroy : function(removeEl){
40549 this.shim.remove();
40552 this.proxy.parentNode.removeChild(this.proxy);
40560 * @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.
40562 Roo.bootstrap.SplitBar.createProxy = function(dir){
40563 var proxy = new Roo.Element(document.createElement("div"));
40564 proxy.unselectable();
40565 var cls = 'roo-splitbar-proxy';
40566 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
40567 document.body.appendChild(proxy.dom);
40572 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
40573 * Default Adapter. It assumes the splitter and resizing element are not positioned
40574 * elements and only gets/sets the width of the element. Generally used for table based layouts.
40576 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
40579 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
40580 // do nothing for now
40581 init : function(s){
40585 * Called before drag operations to get the current size of the resizing element.
40586 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
40588 getElementSize : function(s){
40589 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
40590 return s.resizingEl.getWidth();
40592 return s.resizingEl.getHeight();
40597 * Called after drag operations to set the size of the resizing element.
40598 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
40599 * @param {Number} newSize The new size to set
40600 * @param {Function} onComplete A function to be invoked when resizing is complete
40602 setElementSize : function(s, newSize, onComplete){
40603 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
40605 s.resizingEl.setWidth(newSize);
40607 onComplete(s, newSize);
40610 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
40615 s.resizingEl.setHeight(newSize);
40617 onComplete(s, newSize);
40620 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
40627 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
40628 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
40629 * Adapter that moves the splitter element to align with the resized sizing element.
40630 * Used with an absolute positioned SplitBar.
40631 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
40632 * document.body, make sure you assign an id to the body element.
40634 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
40635 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
40636 this.container = Roo.get(container);
40639 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
40640 init : function(s){
40641 this.basic.init(s);
40644 getElementSize : function(s){
40645 return this.basic.getElementSize(s);
40648 setElementSize : function(s, newSize, onComplete){
40649 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
40652 moveSplitter : function(s){
40653 var yes = Roo.bootstrap.SplitBar;
40654 switch(s.placement){
40656 s.el.setX(s.resizingEl.getRight());
40659 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
40662 s.el.setY(s.resizingEl.getBottom());
40665 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
40672 * Orientation constant - Create a vertical SplitBar
40676 Roo.bootstrap.SplitBar.VERTICAL = 1;
40679 * Orientation constant - Create a horizontal SplitBar
40683 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
40686 * Placement constant - The resizing element is to the left of the splitter element
40690 Roo.bootstrap.SplitBar.LEFT = 1;
40693 * Placement constant - The resizing element is to the right of the splitter element
40697 Roo.bootstrap.SplitBar.RIGHT = 2;
40700 * Placement constant - The resizing element is positioned above the splitter element
40704 Roo.bootstrap.SplitBar.TOP = 3;
40707 * Placement constant - The resizing element is positioned under splitter element
40711 Roo.bootstrap.SplitBar.BOTTOM = 4;
40714 * Ext JS Library 1.1.1
40715 * Copyright(c) 2006-2007, Ext JS, LLC.
40717 * Originally Released Under LGPL - original licence link has changed is not relivant.
40720 * <script type="text/javascript">
40724 * @class Roo.bootstrap.layout.Manager
40725 * @extends Roo.bootstrap.Component
40727 * Base class for layout managers.
40729 Roo.bootstrap.layout.Manager = function(config)
40731 this.monitorWindowResize = true; // do this before we apply configuration.
40733 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
40739 /** false to disable window resize monitoring @type Boolean */
40745 * Fires when a layout is performed.
40746 * @param {Roo.LayoutManager} this
40750 * @event regionresized
40751 * Fires when the user resizes a region.
40752 * @param {Roo.LayoutRegion} region The resized region
40753 * @param {Number} newSize The new size (width for east/west, height for north/south)
40755 "regionresized" : true,
40757 * @event regioncollapsed
40758 * Fires when a region is collapsed.
40759 * @param {Roo.LayoutRegion} region The collapsed region
40761 "regioncollapsed" : true,
40763 * @event regionexpanded
40764 * Fires when a region is expanded.
40765 * @param {Roo.LayoutRegion} region The expanded region
40767 "regionexpanded" : true
40769 this.updating = false;
40772 this.el = Roo.get(config.el);
40778 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
40783 monitorWindowResize : true,
40789 onRender : function(ct, position)
40792 this.el = Roo.get(ct);
40795 //this.fireEvent('render',this);
40799 initEvents: function()
40803 // ie scrollbar fix
40804 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
40805 document.body.scroll = "no";
40806 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
40807 this.el.position('relative');
40809 this.id = this.el.id;
40810 this.el.addClass("roo-layout-container");
40811 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
40812 if(this.el.dom != document.body ) {
40813 this.el.on('resize', this.layout,this);
40814 this.el.on('show', this.layout,this);
40820 * Returns true if this layout is currently being updated
40821 * @return {Boolean}
40823 isUpdating : function(){
40824 return this.updating;
40828 * Suspend the LayoutManager from doing auto-layouts while
40829 * making multiple add or remove calls
40831 beginUpdate : function(){
40832 this.updating = true;
40836 * Restore auto-layouts and optionally disable the manager from performing a layout
40837 * @param {Boolean} noLayout true to disable a layout update
40839 endUpdate : function(noLayout){
40840 this.updating = false;
40846 layout: function(){
40850 onRegionResized : function(region, newSize){
40851 this.fireEvent("regionresized", region, newSize);
40855 onRegionCollapsed : function(region){
40856 this.fireEvent("regioncollapsed", region);
40859 onRegionExpanded : function(region){
40860 this.fireEvent("regionexpanded", region);
40864 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
40865 * performs box-model adjustments.
40866 * @return {Object} The size as an object {width: (the width), height: (the height)}
40868 getViewSize : function()
40871 if(this.el.dom != document.body){
40872 size = this.el.getSize();
40874 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
40876 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
40877 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
40882 * Returns the Element this layout is bound to.
40883 * @return {Roo.Element}
40885 getEl : function(){
40890 * Returns the specified region.
40891 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
40892 * @return {Roo.LayoutRegion}
40894 getRegion : function(target){
40895 return this.regions[target.toLowerCase()];
40898 onWindowResize : function(){
40899 if(this.monitorWindowResize){
40906 * Ext JS Library 1.1.1
40907 * Copyright(c) 2006-2007, Ext JS, LLC.
40909 * Originally Released Under LGPL - original licence link has changed is not relivant.
40912 * <script type="text/javascript">
40915 * @class Roo.bootstrap.layout.Border
40916 * @extends Roo.bootstrap.layout.Manager
40917 * @children Roo.bootstrap.panel.Content Roo.bootstrap.panel.Nest Roo.bootstrap.panel.Grid
40918 * @parent builder Roo.bootstrap.panel.Nest Roo.bootstrap.panel.Nest Roo.bootstrap.Modal
40919 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
40920 * please see: examples/bootstrap/nested.html<br><br>
40922 <b>The container the layout is rendered into can be either the body element or any other element.
40923 If it is not the body element, the container needs to either be an absolute positioned element,
40924 or you will need to add "position:relative" to the css of the container. You will also need to specify
40925 the container size if it is not the body element.</b>
40928 * Create a new Border
40929 * @param {Object} config Configuration options
40931 Roo.bootstrap.layout.Border = function(config){
40932 config = config || {};
40933 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
40937 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
40938 if(config[region]){
40939 config[region].region = region;
40940 this.addRegion(config[region]);
40946 Roo.bootstrap.layout.Border.regions = ["center", "north","south","east","west"];
40948 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
40951 * @cfg {Roo.bootstrap.layout.Region} center region to go in center
40954 * @cfg {Roo.bootstrap.layout.Region} west region to go in west
40957 * @cfg {Roo.bootstrap.layout.Region} east region to go in east
40960 * @cfg {Roo.bootstrap.layout.Region} south region to go in south
40963 * @cfg {Roo.bootstrap.layout.Region} north region to go in north
40969 parent : false, // this might point to a 'nest' or a ???
40972 * Creates and adds a new region if it doesn't already exist.
40973 * @param {String} target The target region key (north, south, east, west or center).
40974 * @param {Object} config The regions config object
40975 * @return {BorderLayoutRegion} The new region
40977 addRegion : function(config)
40979 if(!this.regions[config.region]){
40980 var r = this.factory(config);
40981 this.bindRegion(r);
40983 return this.regions[config.region];
40987 bindRegion : function(r){
40988 this.regions[r.config.region] = r;
40990 r.on("visibilitychange", this.layout, this);
40991 r.on("paneladded", this.layout, this);
40992 r.on("panelremoved", this.layout, this);
40993 r.on("invalidated", this.layout, this);
40994 r.on("resized", this.onRegionResized, this);
40995 r.on("collapsed", this.onRegionCollapsed, this);
40996 r.on("expanded", this.onRegionExpanded, this);
41000 * Performs a layout update.
41002 layout : function()
41004 if(this.updating) {
41008 // render all the rebions if they have not been done alreayd?
41009 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
41010 if(this.regions[region] && !this.regions[region].bodyEl){
41011 this.regions[region].onRender(this.el)
41015 var size = this.getViewSize();
41016 var w = size.width;
41017 var h = size.height;
41022 //var x = 0, y = 0;
41024 var rs = this.regions;
41025 var north = rs["north"];
41026 var south = rs["south"];
41027 var west = rs["west"];
41028 var east = rs["east"];
41029 var center = rs["center"];
41030 //if(this.hideOnLayout){ // not supported anymore
41031 //c.el.setStyle("display", "none");
41033 if(north && north.isVisible()){
41034 var b = north.getBox();
41035 var m = north.getMargins();
41036 b.width = w - (m.left+m.right);
41039 centerY = b.height + b.y + m.bottom;
41040 centerH -= centerY;
41041 north.updateBox(this.safeBox(b));
41043 if(south && south.isVisible()){
41044 var b = south.getBox();
41045 var m = south.getMargins();
41046 b.width = w - (m.left+m.right);
41048 var totalHeight = (b.height + m.top + m.bottom);
41049 b.y = h - totalHeight + m.top;
41050 centerH -= totalHeight;
41051 south.updateBox(this.safeBox(b));
41053 if(west && west.isVisible()){
41054 var b = west.getBox();
41055 var m = west.getMargins();
41056 b.height = centerH - (m.top+m.bottom);
41058 b.y = centerY + m.top;
41059 var totalWidth = (b.width + m.left + m.right);
41060 centerX += totalWidth;
41061 centerW -= totalWidth;
41062 west.updateBox(this.safeBox(b));
41064 if(east && east.isVisible()){
41065 var b = east.getBox();
41066 var m = east.getMargins();
41067 b.height = centerH - (m.top+m.bottom);
41068 var totalWidth = (b.width + m.left + m.right);
41069 b.x = w - totalWidth + m.left;
41070 b.y = centerY + m.top;
41071 centerW -= totalWidth;
41072 east.updateBox(this.safeBox(b));
41075 var m = center.getMargins();
41077 x: centerX + m.left,
41078 y: centerY + m.top,
41079 width: centerW - (m.left+m.right),
41080 height: centerH - (m.top+m.bottom)
41082 //if(this.hideOnLayout){
41083 //center.el.setStyle("display", "block");
41085 center.updateBox(this.safeBox(centerBox));
41088 this.fireEvent("layout", this);
41092 safeBox : function(box){
41093 box.width = Math.max(0, box.width);
41094 box.height = Math.max(0, box.height);
41099 * Adds a ContentPanel (or subclass) to this layout.
41100 * @param {String} target The target region key (north, south, east, west or center).
41101 * @param {Roo.ContentPanel} panel The panel to add
41102 * @return {Roo.ContentPanel} The added panel
41104 add : function(target, panel){
41106 target = target.toLowerCase();
41107 return this.regions[target].add(panel);
41111 * Remove a ContentPanel (or subclass) to this layout.
41112 * @param {String} target The target region key (north, south, east, west or center).
41113 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
41114 * @return {Roo.ContentPanel} The removed panel
41116 remove : function(target, panel){
41117 target = target.toLowerCase();
41118 return this.regions[target].remove(panel);
41122 * Searches all regions for a panel with the specified id
41123 * @param {String} panelId
41124 * @return {Roo.ContentPanel} The panel or null if it wasn't found
41126 findPanel : function(panelId){
41127 var rs = this.regions;
41128 for(var target in rs){
41129 if(typeof rs[target] != "function"){
41130 var p = rs[target].getPanel(panelId);
41140 * Searches all regions for a panel with the specified id and activates (shows) it.
41141 * @param {String/ContentPanel} panelId The panels id or the panel itself
41142 * @return {Roo.ContentPanel} The shown panel or null
41144 showPanel : function(panelId) {
41145 var rs = this.regions;
41146 for(var target in rs){
41147 var r = rs[target];
41148 if(typeof r != "function"){
41149 if(r.hasPanel(panelId)){
41150 return r.showPanel(panelId);
41158 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
41159 * @param {Roo.state.Provider} provider (optional) An alternate state provider
41162 restoreState : function(provider){
41164 provider = Roo.state.Manager;
41166 var sm = new Roo.LayoutStateManager();
41167 sm.init(this, provider);
41173 * Adds a xtype elements to the layout.
41177 xtype : 'ContentPanel',
41184 xtype : 'NestedLayoutPanel',
41190 items : [ ... list of content panels or nested layout panels.. ]
41194 * @param {Object} cfg Xtype definition of item to add.
41196 addxtype : function(cfg)
41198 // basically accepts a pannel...
41199 // can accept a layout region..!?!?
41200 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
41203 // theory? children can only be panels??
41205 //if (!cfg.xtype.match(/Panel$/)) {
41210 if (typeof(cfg.region) == 'undefined') {
41211 Roo.log("Failed to add Panel, region was not set");
41215 var region = cfg.region;
41221 xitems = cfg.items;
41226 if ( region == 'center') {
41227 Roo.log("Center: " + cfg.title);
41233 case 'Content': // ContentPanel (el, cfg)
41234 case 'Scroll': // ContentPanel (el, cfg)
41236 cfg.autoCreate = cfg.autoCreate || true;
41237 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
41239 // var el = this.el.createChild();
41240 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
41243 this.add(region, ret);
41247 case 'TreePanel': // our new panel!
41248 cfg.el = this.el.createChild();
41249 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
41250 this.add(region, ret);
41255 // create a new Layout (which is a Border Layout...
41257 var clayout = cfg.layout;
41258 clayout.el = this.el.createChild();
41259 clayout.items = clayout.items || [];
41263 // replace this exitems with the clayout ones..
41264 xitems = clayout.items;
41266 // force background off if it's in center...
41267 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
41268 cfg.background = false;
41270 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
41273 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
41274 //console.log('adding nested layout panel ' + cfg.toSource());
41275 this.add(region, ret);
41276 nb = {}; /// find first...
41281 // needs grid and region
41283 //var el = this.getRegion(region).el.createChild();
41285 *var el = this.el.createChild();
41286 // create the grid first...
41287 cfg.grid.container = el;
41288 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
41291 if (region == 'center' && this.active ) {
41292 cfg.background = false;
41295 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
41297 this.add(region, ret);
41299 if (cfg.background) {
41300 // render grid on panel activation (if panel background)
41301 ret.on('activate', function(gp) {
41302 if (!gp.grid.rendered) {
41303 // gp.grid.render(el);
41307 // cfg.grid.render(el);
41313 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
41314 // it was the old xcomponent building that caused this before.
41315 // espeically if border is the top element in the tree.
41325 if (typeof(Roo[cfg.xtype]) != 'undefined') {
41327 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
41328 this.add(region, ret);
41332 throw "Can not add '" + cfg.xtype + "' to Border";
41338 this.beginUpdate();
41342 Roo.each(xitems, function(i) {
41343 region = nb && i.region ? i.region : false;
41345 var add = ret.addxtype(i);
41348 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
41349 if (!i.background) {
41350 abn[region] = nb[region] ;
41357 // make the last non-background panel active..
41358 //if (nb) { Roo.log(abn); }
41361 for(var r in abn) {
41362 region = this.getRegion(r);
41364 // tried using nb[r], but it does not work..
41366 region.showPanel(abn[r]);
41377 factory : function(cfg)
41380 var validRegions = Roo.bootstrap.layout.Border.regions;
41382 var target = cfg.region;
41385 var r = Roo.bootstrap.layout;
41389 return new r.North(cfg);
41391 return new r.South(cfg);
41393 return new r.East(cfg);
41395 return new r.West(cfg);
41397 return new r.Center(cfg);
41399 throw 'Layout region "'+target+'" not supported.';
41406 * Ext JS Library 1.1.1
41407 * Copyright(c) 2006-2007, Ext JS, LLC.
41409 * Originally Released Under LGPL - original licence link has changed is not relivant.
41412 * <script type="text/javascript">
41416 * @class Roo.bootstrap.layout.Basic
41417 * @extends Roo.util.Observable
41418 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
41419 * and does not have a titlebar, tabs or any other features. All it does is size and position
41420 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
41421 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
41422 * @cfg {string} region the region that it inhabits..
41423 * @cfg {bool} skipConfig skip config?
41427 Roo.bootstrap.layout.Basic = function(config){
41429 this.mgr = config.mgr;
41431 this.position = config.region;
41433 var skipConfig = config.skipConfig;
41437 * @scope Roo.BasicLayoutRegion
41441 * @event beforeremove
41442 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
41443 * @param {Roo.LayoutRegion} this
41444 * @param {Roo.ContentPanel} panel The panel
41445 * @param {Object} e The cancel event object
41447 "beforeremove" : true,
41449 * @event invalidated
41450 * Fires when the layout for this region is changed.
41451 * @param {Roo.LayoutRegion} this
41453 "invalidated" : true,
41455 * @event visibilitychange
41456 * Fires when this region is shown or hidden
41457 * @param {Roo.LayoutRegion} this
41458 * @param {Boolean} visibility true or false
41460 "visibilitychange" : true,
41462 * @event paneladded
41463 * Fires when a panel is added.
41464 * @param {Roo.LayoutRegion} this
41465 * @param {Roo.ContentPanel} panel The panel
41467 "paneladded" : true,
41469 * @event panelremoved
41470 * Fires when a panel is removed.
41471 * @param {Roo.LayoutRegion} this
41472 * @param {Roo.ContentPanel} panel The panel
41474 "panelremoved" : true,
41476 * @event beforecollapse
41477 * Fires when this region before collapse.
41478 * @param {Roo.LayoutRegion} this
41480 "beforecollapse" : true,
41483 * Fires when this region is collapsed.
41484 * @param {Roo.LayoutRegion} this
41486 "collapsed" : true,
41489 * Fires when this region is expanded.
41490 * @param {Roo.LayoutRegion} this
41495 * Fires when this region is slid into view.
41496 * @param {Roo.LayoutRegion} this
41498 "slideshow" : true,
41501 * Fires when this region slides out of view.
41502 * @param {Roo.LayoutRegion} this
41504 "slidehide" : true,
41506 * @event panelactivated
41507 * Fires when a panel is activated.
41508 * @param {Roo.LayoutRegion} this
41509 * @param {Roo.ContentPanel} panel The activated panel
41511 "panelactivated" : true,
41514 * Fires when the user resizes this region.
41515 * @param {Roo.LayoutRegion} this
41516 * @param {Number} newSize The new size (width for east/west, height for north/south)
41520 /** A collection of panels in this region. @type Roo.util.MixedCollection */
41521 this.panels = new Roo.util.MixedCollection();
41522 this.panels.getKey = this.getPanelId.createDelegate(this);
41524 this.activePanel = null;
41525 // ensure listeners are added...
41527 if (config.listeners || config.events) {
41528 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
41529 listeners : config.listeners || {},
41530 events : config.events || {}
41534 if(skipConfig !== true){
41535 this.applyConfig(config);
41539 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
41541 getPanelId : function(p){
41545 applyConfig : function(config){
41546 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
41547 this.config = config;
41552 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
41553 * the width, for horizontal (north, south) the height.
41554 * @param {Number} newSize The new width or height
41556 resizeTo : function(newSize){
41557 var el = this.el ? this.el :
41558 (this.activePanel ? this.activePanel.getEl() : null);
41560 switch(this.position){
41563 el.setWidth(newSize);
41564 this.fireEvent("resized", this, newSize);
41568 el.setHeight(newSize);
41569 this.fireEvent("resized", this, newSize);
41575 getBox : function(){
41576 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
41579 getMargins : function(){
41580 return this.margins;
41583 updateBox : function(box){
41585 var el = this.activePanel.getEl();
41586 el.dom.style.left = box.x + "px";
41587 el.dom.style.top = box.y + "px";
41588 this.activePanel.setSize(box.width, box.height);
41592 * Returns the container element for this region.
41593 * @return {Roo.Element}
41595 getEl : function(){
41596 return this.activePanel;
41600 * Returns true if this region is currently visible.
41601 * @return {Boolean}
41603 isVisible : function(){
41604 return this.activePanel ? true : false;
41607 setActivePanel : function(panel){
41608 panel = this.getPanel(panel);
41609 if(this.activePanel && this.activePanel != panel){
41610 this.activePanel.setActiveState(false);
41611 this.activePanel.getEl().setLeftTop(-10000,-10000);
41613 this.activePanel = panel;
41614 panel.setActiveState(true);
41616 panel.setSize(this.box.width, this.box.height);
41618 this.fireEvent("panelactivated", this, panel);
41619 this.fireEvent("invalidated");
41623 * Show the specified panel.
41624 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
41625 * @return {Roo.ContentPanel} The shown panel or null
41627 showPanel : function(panel){
41628 panel = this.getPanel(panel);
41630 this.setActivePanel(panel);
41636 * Get the active panel for this region.
41637 * @return {Roo.ContentPanel} The active panel or null
41639 getActivePanel : function(){
41640 return this.activePanel;
41644 * Add the passed ContentPanel(s)
41645 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
41646 * @return {Roo.ContentPanel} The panel added (if only one was added)
41648 add : function(panel){
41649 if(arguments.length > 1){
41650 for(var i = 0, len = arguments.length; i < len; i++) {
41651 this.add(arguments[i]);
41655 if(this.hasPanel(panel)){
41656 this.showPanel(panel);
41659 var el = panel.getEl();
41660 if(el.dom.parentNode != this.mgr.el.dom){
41661 this.mgr.el.dom.appendChild(el.dom);
41663 if(panel.setRegion){
41664 panel.setRegion(this);
41666 this.panels.add(panel);
41667 el.setStyle("position", "absolute");
41668 if(!panel.background){
41669 this.setActivePanel(panel);
41670 if(this.config.initialSize && this.panels.getCount()==1){
41671 this.resizeTo(this.config.initialSize);
41674 this.fireEvent("paneladded", this, panel);
41679 * Returns true if the panel is in this region.
41680 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
41681 * @return {Boolean}
41683 hasPanel : function(panel){
41684 if(typeof panel == "object"){ // must be panel obj
41685 panel = panel.getId();
41687 return this.getPanel(panel) ? true : false;
41691 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
41692 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
41693 * @param {Boolean} preservePanel Overrides the config preservePanel option
41694 * @return {Roo.ContentPanel} The panel that was removed
41696 remove : function(panel, preservePanel){
41697 panel = this.getPanel(panel);
41702 this.fireEvent("beforeremove", this, panel, e);
41703 if(e.cancel === true){
41706 var panelId = panel.getId();
41707 this.panels.removeKey(panelId);
41712 * Returns the panel specified or null if it's not in this region.
41713 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
41714 * @return {Roo.ContentPanel}
41716 getPanel : function(id){
41717 if(typeof id == "object"){ // must be panel obj
41720 return this.panels.get(id);
41724 * Returns this regions position (north/south/east/west/center).
41727 getPosition: function(){
41728 return this.position;
41732 * Ext JS Library 1.1.1
41733 * Copyright(c) 2006-2007, Ext JS, LLC.
41735 * Originally Released Under LGPL - original licence link has changed is not relivant.
41738 * <script type="text/javascript">
41742 * @class Roo.bootstrap.layout.Region
41743 * @extends Roo.bootstrap.layout.Basic
41744 * This class represents a region in a layout manager.
41746 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
41747 * @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})
41748 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
41749 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
41750 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
41751 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
41752 * @cfg {String} title The title for the region (overrides panel titles)
41753 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
41754 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
41755 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
41756 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
41757 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
41758 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
41759 * the space available, similar to FireFox 1.5 tabs (defaults to false)
41760 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
41761 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
41762 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
41764 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
41765 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
41766 * @cfg {Boolean} disableTabTips True to disable tab tooltips
41767 * @cfg {Number} width For East/West panels
41768 * @cfg {Number} height For North/South panels
41769 * @cfg {Boolean} split To show the splitter
41770 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
41772 * @cfg {string} cls Extra CSS classes to add to region
41774 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
41775 * @cfg {string} region the region that it inhabits..
41778 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
41779 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
41781 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
41782 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
41783 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
41785 Roo.bootstrap.layout.Region = function(config)
41787 this.applyConfig(config);
41789 var mgr = config.mgr;
41790 var pos = config.region;
41791 config.skipConfig = true;
41792 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
41795 this.onRender(mgr.el);
41798 this.visible = true;
41799 this.collapsed = false;
41800 this.unrendered_panels = [];
41803 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
41805 position: '', // set by wrapper (eg. north/south etc..)
41806 unrendered_panels : null, // unrendered panels.
41808 tabPosition : false,
41810 mgr: false, // points to 'Border'
41813 createBody : function(){
41814 /** This region's body element
41815 * @type Roo.Element */
41816 this.bodyEl = this.el.createChild({
41818 cls: "roo-layout-panel-body tab-content" // bootstrap added...
41822 onRender: function(ctr, pos)
41824 var dh = Roo.DomHelper;
41825 /** This region's container element
41826 * @type Roo.Element */
41827 this.el = dh.append(ctr.dom, {
41829 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
41831 /** This region's title element
41832 * @type Roo.Element */
41834 this.titleEl = dh.append(this.el.dom, {
41836 unselectable: "on",
41837 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
41839 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
41840 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
41844 this.titleEl.enableDisplayMode();
41845 /** This region's title text element
41846 * @type HTMLElement */
41847 this.titleTextEl = this.titleEl.dom.firstChild;
41848 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
41850 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
41851 this.closeBtn.enableDisplayMode();
41852 this.closeBtn.on("click", this.closeClicked, this);
41853 this.closeBtn.hide();
41855 this.createBody(this.config);
41856 if(this.config.hideWhenEmpty){
41858 this.on("paneladded", this.validateVisibility, this);
41859 this.on("panelremoved", this.validateVisibility, this);
41861 if(this.autoScroll){
41862 this.bodyEl.setStyle("overflow", "auto");
41864 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
41866 //if(c.titlebar !== false){
41867 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
41868 this.titleEl.hide();
41870 this.titleEl.show();
41871 if(this.config.title){
41872 this.titleTextEl.innerHTML = this.config.title;
41876 if(this.config.collapsed){
41877 this.collapse(true);
41879 if(this.config.hidden){
41883 if (this.unrendered_panels && this.unrendered_panels.length) {
41884 for (var i =0;i< this.unrendered_panels.length; i++) {
41885 this.add(this.unrendered_panels[i]);
41887 this.unrendered_panels = null;
41893 applyConfig : function(c)
41896 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
41897 var dh = Roo.DomHelper;
41898 if(c.titlebar !== false){
41899 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
41900 this.collapseBtn.on("click", this.collapse, this);
41901 this.collapseBtn.enableDisplayMode();
41903 if(c.showPin === true || this.showPin){
41904 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
41905 this.stickBtn.enableDisplayMode();
41906 this.stickBtn.on("click", this.expand, this);
41907 this.stickBtn.hide();
41912 /** This region's collapsed element
41913 * @type Roo.Element */
41916 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
41917 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
41920 if(c.floatable !== false){
41921 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
41922 this.collapsedEl.on("click", this.collapseClick, this);
41925 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
41926 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
41927 id: "message", unselectable: "on", style:{"float":"left"}});
41928 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
41930 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
41931 this.expandBtn.on("click", this.expand, this);
41935 if(this.collapseBtn){
41936 this.collapseBtn.setVisible(c.collapsible == true);
41939 this.cmargins = c.cmargins || this.cmargins ||
41940 (this.position == "west" || this.position == "east" ?
41941 {top: 0, left: 2, right:2, bottom: 0} :
41942 {top: 2, left: 0, right:0, bottom: 2});
41944 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
41947 this.tabPosition = [ 'top','bottom', 'west'].indexOf(c.tabPosition) > -1 ? c.tabPosition : "top";
41949 this.autoScroll = c.autoScroll || false;
41954 this.duration = c.duration || .30;
41955 this.slideDuration = c.slideDuration || .45;
41960 * Returns true if this region is currently visible.
41961 * @return {Boolean}
41963 isVisible : function(){
41964 return this.visible;
41968 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
41969 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
41971 //setCollapsedTitle : function(title){
41972 // title = title || " ";
41973 // if(this.collapsedTitleTextEl){
41974 // this.collapsedTitleTextEl.innerHTML = title;
41978 getBox : function(){
41980 // if(!this.collapsed){
41981 b = this.el.getBox(false, true);
41983 // b = this.collapsedEl.getBox(false, true);
41988 getMargins : function(){
41989 return this.margins;
41990 //return this.collapsed ? this.cmargins : this.margins;
41993 highlight : function(){
41994 this.el.addClass("x-layout-panel-dragover");
41997 unhighlight : function(){
41998 this.el.removeClass("x-layout-panel-dragover");
42001 updateBox : function(box)
42003 if (!this.bodyEl) {
42004 return; // not rendered yet..
42008 if(!this.collapsed){
42009 this.el.dom.style.left = box.x + "px";
42010 this.el.dom.style.top = box.y + "px";
42011 this.updateBody(box.width, box.height);
42013 this.collapsedEl.dom.style.left = box.x + "px";
42014 this.collapsedEl.dom.style.top = box.y + "px";
42015 this.collapsedEl.setSize(box.width, box.height);
42018 this.tabs.autoSizeTabs();
42022 updateBody : function(w, h)
42025 this.el.setWidth(w);
42026 w -= this.el.getBorderWidth("rl");
42027 if(this.config.adjustments){
42028 w += this.config.adjustments[0];
42031 if(h !== null && h > 0){
42032 this.el.setHeight(h);
42033 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
42034 h -= this.el.getBorderWidth("tb");
42035 if(this.config.adjustments){
42036 h += this.config.adjustments[1];
42038 this.bodyEl.setHeight(h);
42040 h = this.tabs.syncHeight(h);
42043 if(this.panelSize){
42044 w = w !== null ? w : this.panelSize.width;
42045 h = h !== null ? h : this.panelSize.height;
42047 if(this.activePanel){
42048 var el = this.activePanel.getEl();
42049 w = w !== null ? w : el.getWidth();
42050 h = h !== null ? h : el.getHeight();
42051 this.panelSize = {width: w, height: h};
42052 this.activePanel.setSize(w, h);
42054 if(Roo.isIE && this.tabs){
42055 this.tabs.el.repaint();
42060 * Returns the container element for this region.
42061 * @return {Roo.Element}
42063 getEl : function(){
42068 * Hides this region.
42071 //if(!this.collapsed){
42072 this.el.dom.style.left = "-2000px";
42075 // this.collapsedEl.dom.style.left = "-2000px";
42076 // this.collapsedEl.hide();
42078 this.visible = false;
42079 this.fireEvent("visibilitychange", this, false);
42083 * Shows this region if it was previously hidden.
42086 //if(!this.collapsed){
42089 // this.collapsedEl.show();
42091 this.visible = true;
42092 this.fireEvent("visibilitychange", this, true);
42095 closeClicked : function(){
42096 if(this.activePanel){
42097 this.remove(this.activePanel);
42101 collapseClick : function(e){
42103 e.stopPropagation();
42106 e.stopPropagation();
42112 * Collapses this region.
42113 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
42116 collapse : function(skipAnim, skipCheck = false){
42117 if(this.collapsed) {
42121 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
42123 this.collapsed = true;
42125 this.split.el.hide();
42127 if(this.config.animate && skipAnim !== true){
42128 this.fireEvent("invalidated", this);
42129 this.animateCollapse();
42131 this.el.setLocation(-20000,-20000);
42133 this.collapsedEl.show();
42134 this.fireEvent("collapsed", this);
42135 this.fireEvent("invalidated", this);
42141 animateCollapse : function(){
42146 * Expands this region if it was previously collapsed.
42147 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
42148 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
42151 expand : function(e, skipAnim){
42153 e.stopPropagation();
42155 if(!this.collapsed || this.el.hasActiveFx()) {
42159 this.afterSlideIn();
42162 this.collapsed = false;
42163 if(this.config.animate && skipAnim !== true){
42164 this.animateExpand();
42168 this.split.el.show();
42170 this.collapsedEl.setLocation(-2000,-2000);
42171 this.collapsedEl.hide();
42172 this.fireEvent("invalidated", this);
42173 this.fireEvent("expanded", this);
42177 animateExpand : function(){
42181 initTabs : function()
42183 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
42185 var ts = new Roo.bootstrap.panel.Tabs({
42186 el: this.bodyEl.dom,
42188 tabPosition: this.tabPosition ? this.tabPosition : 'top',
42189 disableTooltips: this.config.disableTabTips,
42190 toolbar : this.config.toolbar
42193 if(this.config.hideTabs){
42194 ts.stripWrap.setDisplayed(false);
42197 ts.resizeTabs = this.config.resizeTabs === true;
42198 ts.minTabWidth = this.config.minTabWidth || 40;
42199 ts.maxTabWidth = this.config.maxTabWidth || 250;
42200 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
42201 ts.monitorResize = false;
42202 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
42203 ts.bodyEl.addClass('roo-layout-tabs-body');
42204 this.panels.each(this.initPanelAsTab, this);
42207 initPanelAsTab : function(panel){
42208 var ti = this.tabs.addTab(
42212 this.config.closeOnTab && panel.isClosable(),
42215 if(panel.tabTip !== undefined){
42216 ti.setTooltip(panel.tabTip);
42218 ti.on("activate", function(){
42219 this.setActivePanel(panel);
42222 if(this.config.closeOnTab){
42223 ti.on("beforeclose", function(t, e){
42225 this.remove(panel);
42229 panel.tabItem = ti;
42234 updatePanelTitle : function(panel, title)
42236 if(this.activePanel == panel){
42237 this.updateTitle(title);
42240 var ti = this.tabs.getTab(panel.getEl().id);
42242 if(panel.tabTip !== undefined){
42243 ti.setTooltip(panel.tabTip);
42248 updateTitle : function(title){
42249 if(this.titleTextEl && !this.config.title){
42250 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
42254 setActivePanel : function(panel)
42256 panel = this.getPanel(panel);
42257 if(this.activePanel && this.activePanel != panel){
42258 if(this.activePanel.setActiveState(false) === false){
42262 this.activePanel = panel;
42263 panel.setActiveState(true);
42264 if(this.panelSize){
42265 panel.setSize(this.panelSize.width, this.panelSize.height);
42268 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
42270 this.updateTitle(panel.getTitle());
42272 this.fireEvent("invalidated", this);
42274 this.fireEvent("panelactivated", this, panel);
42278 * Shows the specified panel.
42279 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
42280 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
42282 showPanel : function(panel)
42284 panel = this.getPanel(panel);
42287 var tab = this.tabs.getTab(panel.getEl().id);
42288 if(tab.isHidden()){
42289 this.tabs.unhideTab(tab.id);
42293 this.setActivePanel(panel);
42300 * Get the active panel for this region.
42301 * @return {Roo.ContentPanel} The active panel or null
42303 getActivePanel : function(){
42304 return this.activePanel;
42307 validateVisibility : function(){
42308 if(this.panels.getCount() < 1){
42309 this.updateTitle(" ");
42310 this.closeBtn.hide();
42313 if(!this.isVisible()){
42320 * Adds the passed ContentPanel(s) to this region.
42321 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
42322 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
42324 add : function(panel)
42326 if(arguments.length > 1){
42327 for(var i = 0, len = arguments.length; i < len; i++) {
42328 this.add(arguments[i]);
42333 // if we have not been rendered yet, then we can not really do much of this..
42334 if (!this.bodyEl) {
42335 this.unrendered_panels.push(panel);
42342 if(this.hasPanel(panel)){
42343 this.showPanel(panel);
42346 panel.setRegion(this);
42347 this.panels.add(panel);
42348 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
42349 // sinle panel - no tab...?? would it not be better to render it with the tabs,
42350 // and hide them... ???
42351 this.bodyEl.dom.appendChild(panel.getEl().dom);
42352 if(panel.background !== true){
42353 this.setActivePanel(panel);
42355 this.fireEvent("paneladded", this, panel);
42362 this.initPanelAsTab(panel);
42366 if(panel.background !== true){
42367 this.tabs.activate(panel.getEl().id);
42369 this.fireEvent("paneladded", this, panel);
42374 * Hides the tab for the specified panel.
42375 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
42377 hidePanel : function(panel){
42378 if(this.tabs && (panel = this.getPanel(panel))){
42379 this.tabs.hideTab(panel.getEl().id);
42384 * Unhides the tab for a previously hidden panel.
42385 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
42387 unhidePanel : function(panel){
42388 if(this.tabs && (panel = this.getPanel(panel))){
42389 this.tabs.unhideTab(panel.getEl().id);
42393 clearPanels : function(){
42394 while(this.panels.getCount() > 0){
42395 this.remove(this.panels.first());
42400 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
42401 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
42402 * @param {Boolean} preservePanel Overrides the config preservePanel option
42403 * @return {Roo.ContentPanel} The panel that was removed
42405 remove : function(panel, preservePanel)
42407 panel = this.getPanel(panel);
42412 this.fireEvent("beforeremove", this, panel, e);
42413 if(e.cancel === true){
42416 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
42417 var panelId = panel.getId();
42418 this.panels.removeKey(panelId);
42420 document.body.appendChild(panel.getEl().dom);
42423 this.tabs.removeTab(panel.getEl().id);
42424 }else if (!preservePanel){
42425 this.bodyEl.dom.removeChild(panel.getEl().dom);
42427 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
42428 var p = this.panels.first();
42429 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
42430 tempEl.appendChild(p.getEl().dom);
42431 this.bodyEl.update("");
42432 this.bodyEl.dom.appendChild(p.getEl().dom);
42434 this.updateTitle(p.getTitle());
42436 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
42437 this.setActivePanel(p);
42439 panel.setRegion(null);
42440 if(this.activePanel == panel){
42441 this.activePanel = null;
42443 if(this.config.autoDestroy !== false && preservePanel !== true){
42444 try{panel.destroy();}catch(e){}
42446 this.fireEvent("panelremoved", this, panel);
42451 * Returns the TabPanel component used by this region
42452 * @return {Roo.TabPanel}
42454 getTabs : function(){
42458 createTool : function(parentEl, className){
42459 var btn = Roo.DomHelper.append(parentEl, {
42461 cls: "x-layout-tools-button",
42464 cls: "roo-layout-tools-button-inner " + className,
42468 btn.addClassOnOver("roo-layout-tools-button-over");
42473 * Ext JS Library 1.1.1
42474 * Copyright(c) 2006-2007, Ext JS, LLC.
42476 * Originally Released Under LGPL - original licence link has changed is not relivant.
42479 * <script type="text/javascript">
42485 * @class Roo.SplitLayoutRegion
42486 * @extends Roo.LayoutRegion
42487 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
42489 Roo.bootstrap.layout.Split = function(config){
42490 this.cursor = config.cursor;
42491 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
42494 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
42496 splitTip : "Drag to resize.",
42497 collapsibleSplitTip : "Drag to resize. Double click to hide.",
42498 useSplitTips : false,
42500 applyConfig : function(config){
42501 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
42504 onRender : function(ctr,pos) {
42506 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
42507 if(!this.config.split){
42512 var splitEl = Roo.DomHelper.append(ctr.dom, {
42514 id: this.el.id + "-split",
42515 cls: "roo-layout-split roo-layout-split-"+this.position,
42518 /** The SplitBar for this region
42519 * @type Roo.SplitBar */
42520 // does not exist yet...
42521 Roo.log([this.position, this.orientation]);
42523 this.split = new Roo.bootstrap.SplitBar({
42524 dragElement : splitEl,
42525 resizingElement: this.el,
42526 orientation : this.orientation
42529 this.split.on("moved", this.onSplitMove, this);
42530 this.split.useShim = this.config.useShim === true;
42531 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
42532 if(this.useSplitTips){
42533 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
42535 //if(config.collapsible){
42536 // this.split.el.on("dblclick", this.collapse, this);
42539 if(typeof this.config.minSize != "undefined"){
42540 this.split.minSize = this.config.minSize;
42542 if(typeof this.config.maxSize != "undefined"){
42543 this.split.maxSize = this.config.maxSize;
42545 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
42546 this.hideSplitter();
42551 getHMaxSize : function(){
42552 var cmax = this.config.maxSize || 10000;
42553 var center = this.mgr.getRegion("center");
42554 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
42557 getVMaxSize : function(){
42558 var cmax = this.config.maxSize || 10000;
42559 var center = this.mgr.getRegion("center");
42560 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
42563 onSplitMove : function(split, newSize){
42564 this.fireEvent("resized", this, newSize);
42568 * Returns the {@link Roo.SplitBar} for this region.
42569 * @return {Roo.SplitBar}
42571 getSplitBar : function(){
42576 this.hideSplitter();
42577 Roo.bootstrap.layout.Split.superclass.hide.call(this);
42580 hideSplitter : function(){
42582 this.split.el.setLocation(-2000,-2000);
42583 this.split.el.hide();
42589 this.split.el.show();
42591 Roo.bootstrap.layout.Split.superclass.show.call(this);
42594 beforeSlide: function(){
42595 if(Roo.isGecko){// firefox overflow auto bug workaround
42596 this.bodyEl.clip();
42598 this.tabs.bodyEl.clip();
42600 if(this.activePanel){
42601 this.activePanel.getEl().clip();
42603 if(this.activePanel.beforeSlide){
42604 this.activePanel.beforeSlide();
42610 afterSlide : function(){
42611 if(Roo.isGecko){// firefox overflow auto bug workaround
42612 this.bodyEl.unclip();
42614 this.tabs.bodyEl.unclip();
42616 if(this.activePanel){
42617 this.activePanel.getEl().unclip();
42618 if(this.activePanel.afterSlide){
42619 this.activePanel.afterSlide();
42625 initAutoHide : function(){
42626 if(this.autoHide !== false){
42627 if(!this.autoHideHd){
42628 var st = new Roo.util.DelayedTask(this.slideIn, this);
42629 this.autoHideHd = {
42630 "mouseout": function(e){
42631 if(!e.within(this.el, true)){
42635 "mouseover" : function(e){
42641 this.el.on(this.autoHideHd);
42645 clearAutoHide : function(){
42646 if(this.autoHide !== false){
42647 this.el.un("mouseout", this.autoHideHd.mouseout);
42648 this.el.un("mouseover", this.autoHideHd.mouseover);
42652 clearMonitor : function(){
42653 Roo.get(document).un("click", this.slideInIf, this);
42656 // these names are backwards but not changed for compat
42657 slideOut : function(){
42658 if(this.isSlid || this.el.hasActiveFx()){
42661 this.isSlid = true;
42662 if(this.collapseBtn){
42663 this.collapseBtn.hide();
42665 this.closeBtnState = this.closeBtn.getStyle('display');
42666 this.closeBtn.hide();
42668 this.stickBtn.show();
42671 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
42672 this.beforeSlide();
42673 this.el.setStyle("z-index", 10001);
42674 this.el.slideIn(this.getSlideAnchor(), {
42675 callback: function(){
42677 this.initAutoHide();
42678 Roo.get(document).on("click", this.slideInIf, this);
42679 this.fireEvent("slideshow", this);
42686 afterSlideIn : function(){
42687 this.clearAutoHide();
42688 this.isSlid = false;
42689 this.clearMonitor();
42690 this.el.setStyle("z-index", "");
42691 if(this.collapseBtn){
42692 this.collapseBtn.show();
42694 this.closeBtn.setStyle('display', this.closeBtnState);
42696 this.stickBtn.hide();
42698 this.fireEvent("slidehide", this);
42701 slideIn : function(cb){
42702 if(!this.isSlid || this.el.hasActiveFx()){
42706 this.isSlid = false;
42707 this.beforeSlide();
42708 this.el.slideOut(this.getSlideAnchor(), {
42709 callback: function(){
42710 this.el.setLeftTop(-10000, -10000);
42712 this.afterSlideIn();
42720 slideInIf : function(e){
42721 if(!e.within(this.el)){
42726 animateCollapse : function(){
42727 this.beforeSlide();
42728 this.el.setStyle("z-index", 20000);
42729 var anchor = this.getSlideAnchor();
42730 this.el.slideOut(anchor, {
42731 callback : function(){
42732 this.el.setStyle("z-index", "");
42733 this.collapsedEl.slideIn(anchor, {duration:.3});
42735 this.el.setLocation(-10000,-10000);
42737 this.fireEvent("collapsed", this);
42744 animateExpand : function(){
42745 this.beforeSlide();
42746 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
42747 this.el.setStyle("z-index", 20000);
42748 this.collapsedEl.hide({
42751 this.el.slideIn(this.getSlideAnchor(), {
42752 callback : function(){
42753 this.el.setStyle("z-index", "");
42756 this.split.el.show();
42758 this.fireEvent("invalidated", this);
42759 this.fireEvent("expanded", this);
42787 getAnchor : function(){
42788 return this.anchors[this.position];
42791 getCollapseAnchor : function(){
42792 return this.canchors[this.position];
42795 getSlideAnchor : function(){
42796 return this.sanchors[this.position];
42799 getAlignAdj : function(){
42800 var cm = this.cmargins;
42801 switch(this.position){
42817 getExpandAdj : function(){
42818 var c = this.collapsedEl, cm = this.cmargins;
42819 switch(this.position){
42821 return [-(cm.right+c.getWidth()+cm.left), 0];
42824 return [cm.right+c.getWidth()+cm.left, 0];
42827 return [0, -(cm.top+cm.bottom+c.getHeight())];
42830 return [0, cm.top+cm.bottom+c.getHeight()];
42836 * Ext JS Library 1.1.1
42837 * Copyright(c) 2006-2007, Ext JS, LLC.
42839 * Originally Released Under LGPL - original licence link has changed is not relivant.
42842 * <script type="text/javascript">
42845 * These classes are private internal classes
42847 Roo.bootstrap.layout.Center = function(config){
42848 config.region = "center";
42849 Roo.bootstrap.layout.Region.call(this, config);
42850 this.visible = true;
42851 this.minWidth = config.minWidth || 20;
42852 this.minHeight = config.minHeight || 20;
42855 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
42857 // center panel can't be hidden
42861 // center panel can't be hidden
42864 getMinWidth: function(){
42865 return this.minWidth;
42868 getMinHeight: function(){
42869 return this.minHeight;
42883 Roo.bootstrap.layout.North = function(config)
42885 config.region = 'north';
42886 config.cursor = 'n-resize';
42888 Roo.bootstrap.layout.Split.call(this, config);
42892 this.split.placement = Roo.bootstrap.SplitBar.TOP;
42893 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
42894 this.split.el.addClass("roo-layout-split-v");
42896 //var size = config.initialSize || config.height;
42897 //if(this.el && typeof size != "undefined"){
42898 // this.el.setHeight(size);
42901 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
42903 orientation: Roo.bootstrap.SplitBar.VERTICAL,
42906 onRender : function(ctr, pos)
42908 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
42909 var size = this.config.initialSize || this.config.height;
42910 if(this.el && typeof size != "undefined"){
42911 this.el.setHeight(size);
42916 getBox : function(){
42917 if(this.collapsed){
42918 return this.collapsedEl.getBox();
42920 var box = this.el.getBox();
42922 box.height += this.split.el.getHeight();
42927 updateBox : function(box){
42928 if(this.split && !this.collapsed){
42929 box.height -= this.split.el.getHeight();
42930 this.split.el.setLeft(box.x);
42931 this.split.el.setTop(box.y+box.height);
42932 this.split.el.setWidth(box.width);
42934 if(this.collapsed){
42935 this.updateBody(box.width, null);
42937 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
42945 Roo.bootstrap.layout.South = function(config){
42946 config.region = 'south';
42947 config.cursor = 's-resize';
42948 Roo.bootstrap.layout.Split.call(this, config);
42950 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
42951 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
42952 this.split.el.addClass("roo-layout-split-v");
42957 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
42958 orientation: Roo.bootstrap.SplitBar.VERTICAL,
42960 onRender : function(ctr, pos)
42962 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
42963 var size = this.config.initialSize || this.config.height;
42964 if(this.el && typeof size != "undefined"){
42965 this.el.setHeight(size);
42970 getBox : function(){
42971 if(this.collapsed){
42972 return this.collapsedEl.getBox();
42974 var box = this.el.getBox();
42976 var sh = this.split.el.getHeight();
42983 updateBox : function(box){
42984 if(this.split && !this.collapsed){
42985 var sh = this.split.el.getHeight();
42988 this.split.el.setLeft(box.x);
42989 this.split.el.setTop(box.y-sh);
42990 this.split.el.setWidth(box.width);
42992 if(this.collapsed){
42993 this.updateBody(box.width, null);
42995 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
42999 Roo.bootstrap.layout.East = function(config){
43000 config.region = "east";
43001 config.cursor = "e-resize";
43002 Roo.bootstrap.layout.Split.call(this, config);
43004 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
43005 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
43006 this.split.el.addClass("roo-layout-split-h");
43010 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
43011 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
43013 onRender : function(ctr, pos)
43015 Roo.bootstrap.layout.Split.prototype.onRender.call(this, ctr, pos);
43016 var size = this.config.initialSize || this.config.width;
43017 if(this.el && typeof size != "undefined"){
43018 this.el.setWidth(size);
43023 getBox : function(){
43024 if(this.collapsed){
43025 return this.collapsedEl.getBox();
43027 var box = this.el.getBox();
43029 var sw = this.split.el.getWidth();
43036 updateBox : function(box){
43037 if(this.split && !this.collapsed){
43038 var sw = this.split.el.getWidth();
43040 this.split.el.setLeft(box.x);
43041 this.split.el.setTop(box.y);
43042 this.split.el.setHeight(box.height);
43045 if(this.collapsed){
43046 this.updateBody(null, box.height);
43048 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
43052 Roo.bootstrap.layout.West = function(config){
43053 config.region = "west";
43054 config.cursor = "w-resize";
43056 Roo.bootstrap.layout.Split.call(this, config);
43058 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
43059 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
43060 this.split.el.addClass("roo-layout-split-h");
43064 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
43065 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
43067 onRender: function(ctr, pos)
43069 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
43070 var size = this.config.initialSize || this.config.width;
43071 if(typeof size != "undefined"){
43072 this.el.setWidth(size);
43076 getBox : function(){
43077 if(this.collapsed){
43078 return this.collapsedEl.getBox();
43080 var box = this.el.getBox();
43081 if (box.width == 0) {
43082 box.width = this.config.width; // kludge?
43085 box.width += this.split.el.getWidth();
43090 updateBox : function(box){
43091 if(this.split && !this.collapsed){
43092 var sw = this.split.el.getWidth();
43094 this.split.el.setLeft(box.x+box.width);
43095 this.split.el.setTop(box.y);
43096 this.split.el.setHeight(box.height);
43098 if(this.collapsed){
43099 this.updateBody(null, box.height);
43101 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
43105 * Ext JS Library 1.1.1
43106 * Copyright(c) 2006-2007, Ext JS, LLC.
43108 * Originally Released Under LGPL - original licence link has changed is not relivant.
43111 * <script type="text/javascript">
43114 * @class Roo.bootstrap.paenl.Content
43115 * @extends Roo.util.Observable
43116 * @children Roo.bootstrap.Component
43117 * @parent builder Roo.bootstrap.layout.Border
43118 * A basic ContentPanel element. - a panel that contain any content (eg. forms etc.)
43119 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
43120 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
43121 * @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
43122 * @cfg {Boolean} closable True if the panel can be closed/removed
43123 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
43124 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
43125 * @cfg {Toolbar} toolbar A toolbar for this panel
43126 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
43127 * @cfg {String} title The title for this panel
43128 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
43129 * @cfg {String} url Calls {@link #setUrl} with this value
43130 * @cfg {String} region [required] (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
43131 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
43132 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
43133 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
43134 * @cfg {Boolean} iframe contents are an iframe - makes showing remote sources/CSS feasible..
43135 * @cfg {Boolean} badges render the badges
43136 * @cfg {String} cls extra classes to use
43137 * @cfg {String} background (primary|secondary|success|info|warning|danger|light|dark)
43140 * Create a new ContentPanel.
43141 * @param {String/Object} config A string to set only the title or a config object
43144 Roo.bootstrap.panel.Content = function( config){
43146 this.tpl = config.tpl || false;
43148 var el = config.el;
43149 var content = config.content;
43151 if(config.autoCreate){ // xtype is available if this is called from factory
43154 this.el = Roo.get(el);
43155 if(!this.el && config && config.autoCreate){
43156 if(typeof config.autoCreate == "object"){
43157 if(!config.autoCreate.id){
43158 config.autoCreate.id = config.id||el;
43160 this.el = Roo.DomHelper.append(document.body,
43161 config.autoCreate, true);
43165 cls: (config.cls || '') +
43166 (config.background ? ' bg-' + config.background : '') +
43167 " roo-layout-inactive-content",
43170 if (config.iframe) {
43174 style : 'border: 0px',
43175 src : 'about:blank'
43181 elcfg.html = config.html;
43185 this.el = Roo.DomHelper.append(document.body, elcfg , true);
43186 if (config.iframe) {
43187 this.iframeEl = this.el.select('iframe',true).first();
43192 this.closable = false;
43193 this.loaded = false;
43194 this.active = false;
43197 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
43199 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
43201 this.wrapEl = this.el; //this.el.wrap();
43203 if (config.toolbar.items) {
43204 ti = config.toolbar.items ;
43205 delete config.toolbar.items ;
43209 this.toolbar.render(this.wrapEl, 'before');
43210 for(var i =0;i < ti.length;i++) {
43211 // Roo.log(['add child', items[i]]);
43212 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
43214 this.toolbar.items = nitems;
43215 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
43216 delete config.toolbar;
43220 // xtype created footer. - not sure if will work as we normally have to render first..
43221 if (this.footer && !this.footer.el && this.footer.xtype) {
43222 if (!this.wrapEl) {
43223 this.wrapEl = this.el.wrap();
43226 this.footer.container = this.wrapEl.createChild();
43228 this.footer = Roo.factory(this.footer, Roo);
43233 if(typeof config == "string"){
43234 this.title = config;
43236 Roo.apply(this, config);
43240 this.resizeEl = Roo.get(this.resizeEl, true);
43242 this.resizeEl = this.el;
43244 // handle view.xtype
43252 * Fires when this panel is activated.
43253 * @param {Roo.ContentPanel} this
43257 * @event deactivate
43258 * Fires when this panel is activated.
43259 * @param {Roo.ContentPanel} this
43261 "deactivate" : true,
43265 * Fires when this panel is resized if fitToFrame is true.
43266 * @param {Roo.ContentPanel} this
43267 * @param {Number} width The width after any component adjustments
43268 * @param {Number} height The height after any component adjustments
43274 * Fires when this tab is created
43275 * @param {Roo.ContentPanel} this
43281 * Fires when this content is scrolled
43282 * @param {Roo.ContentPanel} this
43283 * @param {Event} scrollEvent
43294 if(this.autoScroll && !this.iframe){
43295 this.resizeEl.setStyle("overflow", "auto");
43296 this.resizeEl.on('scroll', this.onScroll, this);
43298 // fix randome scrolling
43299 //this.el.on('scroll', function() {
43300 // Roo.log('fix random scolling');
43301 // this.scrollTo('top',0);
43304 content = content || this.content;
43306 this.setContent(content);
43308 if(config && config.url){
43309 this.setUrl(this.url, this.params, this.loadOnce);
43314 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
43316 if (this.view && typeof(this.view.xtype) != 'undefined') {
43317 this.view.el = this.el.appendChild(document.createElement("div"));
43318 this.view = Roo.factory(this.view);
43319 this.view.render && this.view.render(false, '');
43323 this.fireEvent('render', this);
43326 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
43336 /* Resize Element - use this to work out scroll etc. */
43339 setRegion : function(region){
43340 this.region = region;
43341 this.setActiveClass(region && !this.background);
43345 setActiveClass: function(state)
43348 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
43349 this.el.setStyle('position','relative');
43351 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
43352 this.el.setStyle('position', 'absolute');
43357 * Returns the toolbar for this Panel if one was configured.
43358 * @return {Roo.Toolbar}
43360 getToolbar : function(){
43361 return this.toolbar;
43364 setActiveState : function(active)
43366 this.active = active;
43367 this.setActiveClass(active);
43369 if(this.fireEvent("deactivate", this) === false){
43374 this.fireEvent("activate", this);
43378 * Updates this panel's element (not for iframe)
43379 * @param {String} content The new content
43380 * @param {Boolean} loadScripts (optional) true to look for and process scripts
43382 setContent : function(content, loadScripts){
43387 this.el.update(content, loadScripts);
43390 ignoreResize : function(w, h)
43392 //return false; // always resize?
43393 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
43396 this.lastSize = {width: w, height: h};
43401 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
43402 * @return {Roo.UpdateManager} The UpdateManager
43404 getUpdateManager : function(){
43408 return this.el.getUpdateManager();
43411 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
43412 * Does not work with IFRAME contents
43413 * @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:
43416 url: "your-url.php",
43417 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
43418 callback: yourFunction,
43419 scope: yourObject, //(optional scope)
43422 text: "Loading...",
43428 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
43429 * 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.
43430 * @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}
43431 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
43432 * @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.
43433 * @return {Roo.ContentPanel} this
43441 var um = this.el.getUpdateManager();
43442 um.update.apply(um, arguments);
43448 * 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.
43449 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
43450 * @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)
43451 * @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)
43452 * @return {Roo.UpdateManager|Boolean} The UpdateManager or false if IFRAME
43454 setUrl : function(url, params, loadOnce){
43456 this.iframeEl.dom.src = url;
43460 if(this.refreshDelegate){
43461 this.removeListener("activate", this.refreshDelegate);
43463 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
43464 this.on("activate", this.refreshDelegate);
43465 return this.el.getUpdateManager();
43468 _handleRefresh : function(url, params, loadOnce){
43469 if(!loadOnce || !this.loaded){
43470 var updater = this.el.getUpdateManager();
43471 updater.update(url, params, this._setLoaded.createDelegate(this));
43475 _setLoaded : function(){
43476 this.loaded = true;
43480 * Returns this panel's id
43483 getId : function(){
43488 * Returns this panel's element - used by regiosn to add.
43489 * @return {Roo.Element}
43491 getEl : function(){
43492 return this.wrapEl || this.el;
43497 adjustForComponents : function(width, height)
43499 //Roo.log('adjustForComponents ');
43500 if(this.resizeEl != this.el){
43501 width -= this.el.getFrameWidth('lr');
43502 height -= this.el.getFrameWidth('tb');
43505 var te = this.toolbar.getEl();
43506 te.setWidth(width);
43507 height -= te.getHeight();
43510 var te = this.footer.getEl();
43511 te.setWidth(width);
43512 height -= te.getHeight();
43516 if(this.adjustments){
43517 width += this.adjustments[0];
43518 height += this.adjustments[1];
43520 return {"width": width, "height": height};
43523 setSize : function(width, height){
43524 if(this.fitToFrame && !this.ignoreResize(width, height)){
43525 if(this.fitContainer && this.resizeEl != this.el){
43526 this.el.setSize(width, height);
43528 var size = this.adjustForComponents(width, height);
43530 this.iframeEl.setSize(width,height);
43533 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
43534 this.fireEvent('resize', this, size.width, size.height);
43541 * Returns this panel's title
43544 getTitle : function(){
43546 if (typeof(this.title) != 'object') {
43551 for (var k in this.title) {
43552 if (!this.title.hasOwnProperty(k)) {
43556 if (k.indexOf('-') >= 0) {
43557 var s = k.split('-');
43558 for (var i = 0; i<s.length; i++) {
43559 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
43562 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
43569 * Set this panel's title
43570 * @param {String} title
43572 setTitle : function(title){
43573 this.title = title;
43575 this.region.updatePanelTitle(this, title);
43580 * Returns true is this panel was configured to be closable
43581 * @return {Boolean}
43583 isClosable : function(){
43584 return this.closable;
43587 beforeSlide : function(){
43589 this.resizeEl.clip();
43592 afterSlide : function(){
43594 this.resizeEl.unclip();
43598 * Force a content refresh from the URL specified in the {@link #setUrl} method.
43599 * Will fail silently if the {@link #setUrl} method has not been called.
43600 * This does not activate the panel, just updates its content.
43602 refresh : function(){
43603 if(this.refreshDelegate){
43604 this.loaded = false;
43605 this.refreshDelegate();
43610 * Destroys this panel
43612 destroy : function(){
43613 this.el.removeAllListeners();
43614 var tempEl = document.createElement("span");
43615 tempEl.appendChild(this.el.dom);
43616 tempEl.innerHTML = "";
43622 * form - if the content panel contains a form - this is a reference to it.
43623 * @type {Roo.form.Form}
43627 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
43628 * This contains a reference to it.
43634 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
43644 * @param {Object} cfg Xtype definition of item to add.
43648 getChildContainer: function () {
43649 return this.getEl();
43653 onScroll : function(e)
43655 this.fireEvent('scroll', this, e);
43660 var ret = new Roo.factory(cfg);
43665 if (cfg.xtype.match(/^Form$/)) {
43668 //if (this.footer) {
43669 // el = this.footer.container.insertSibling(false, 'before');
43671 el = this.el.createChild();
43674 this.form = new Roo.form.Form(cfg);
43677 if ( this.form.allItems.length) {
43678 this.form.render(el.dom);
43682 // should only have one of theses..
43683 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
43684 // views.. should not be just added - used named prop 'view''
43686 cfg.el = this.el.appendChild(document.createElement("div"));
43689 var ret = new Roo.factory(cfg);
43691 ret.render && ret.render(false, ''); // render blank..
43701 * @class Roo.bootstrap.panel.Grid
43702 * @extends Roo.bootstrap.panel.Content
43704 * Create a new GridPanel.
43705 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
43706 * @cfg {Roo.bootstrap.nav.Simplebar} toolbar the toolbar at the top of the grid.
43707 * @param {Object} config A the config object
43713 Roo.bootstrap.panel.Grid = function(config)
43717 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
43718 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
43720 config.el = this.wrapper;
43721 //this.el = this.wrapper;
43723 if (config.container) {
43724 // ctor'ed from a Border/panel.grid
43727 this.wrapper.setStyle("overflow", "hidden");
43728 this.wrapper.addClass('roo-grid-container');
43733 if(config.toolbar){
43734 var tool_el = this.wrapper.createChild();
43735 this.toolbar = Roo.factory(config.toolbar);
43737 if (config.toolbar.items) {
43738 ti = config.toolbar.items ;
43739 delete config.toolbar.items ;
43743 this.toolbar.render(tool_el);
43744 for(var i =0;i < ti.length;i++) {
43745 // Roo.log(['add child', items[i]]);
43746 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
43748 this.toolbar.items = nitems;
43750 delete config.toolbar;
43753 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
43754 config.grid.scrollBody = true;;
43755 config.grid.monitorWindowResize = false; // turn off autosizing
43756 config.grid.autoHeight = false;
43757 config.grid.autoWidth = false;
43759 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
43761 if (config.background) {
43762 // render grid on panel activation (if panel background)
43763 this.on('activate', function(gp) {
43764 if (!gp.grid.rendered) {
43765 gp.grid.render(this.wrapper);
43766 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
43771 this.grid.render(this.wrapper);
43772 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
43775 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
43776 // ??? needed ??? config.el = this.wrapper;
43781 // xtype created footer. - not sure if will work as we normally have to render first..
43782 if (this.footer && !this.footer.el && this.footer.xtype) {
43784 var ctr = this.grid.getView().getFooterPanel(true);
43785 this.footer.dataSource = this.grid.dataSource;
43786 this.footer = Roo.factory(this.footer, Roo);
43787 this.footer.render(ctr);
43797 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content,
43800 getId : function(){
43801 return this.grid.id;
43805 * Returns the grid for this panel
43806 * @return {Roo.bootstrap.Table}
43808 getGrid : function(){
43812 setSize : function(width, height)
43815 //if(!this.ignoreResize(width, height)){
43816 var grid = this.grid;
43817 var size = this.adjustForComponents(width, height);
43818 // tfoot is not a footer?
43821 var gridel = grid.getGridEl();
43822 gridel.setSize(size.width, size.height);
43824 var tbd = grid.getGridEl().select('tbody', true).first();
43825 var thd = grid.getGridEl().select('thead',true).first();
43826 var tbf= grid.getGridEl().select('tfoot', true).first();
43829 size.height -= tbf.getHeight();
43832 size.height -= thd.getHeight();
43835 tbd.setSize(size.width, size.height );
43836 // this is for the account management tab -seems to work there.
43837 var thd = grid.getGridEl().select('thead',true).first();
43839 // tbd.setSize(size.width, size.height - thd.getHeight());
43849 beforeSlide : function(){
43850 this.grid.getView().scroller.clip();
43853 afterSlide : function(){
43854 this.grid.getView().scroller.unclip();
43857 destroy : function(){
43858 this.grid.destroy();
43860 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
43865 * @class Roo.bootstrap.panel.Nest
43866 * @extends Roo.bootstrap.panel.Content
43868 * Create a new Panel, that can contain a layout.Border.
43871 * @param {String/Object} config A string to set only the title or a config object
43873 Roo.bootstrap.panel.Nest = function(config)
43875 // construct with only one argument..
43876 /* FIXME - implement nicer consturctors
43877 if (layout.layout) {
43879 layout = config.layout;
43880 delete config.layout;
43882 if (layout.xtype && !layout.getEl) {
43883 // then layout needs constructing..
43884 layout = Roo.factory(layout, Roo);
43888 config.el = config.layout.getEl();
43890 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
43892 config.layout.monitorWindowResize = false; // turn off autosizing
43893 this.layout = config.layout;
43894 this.layout.getEl().addClass("roo-layout-nested-layout");
43895 this.layout.parent = this;
43902 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
43904 * @cfg {Roo.BorderLayout} layout The layout for this panel
43908 setSize : function(width, height){
43909 if(!this.ignoreResize(width, height)){
43910 var size = this.adjustForComponents(width, height);
43911 var el = this.layout.getEl();
43912 if (size.height < 1) {
43913 el.setWidth(size.width);
43915 el.setSize(size.width, size.height);
43917 var touch = el.dom.offsetWidth;
43918 this.layout.layout();
43919 // ie requires a double layout on the first pass
43920 if(Roo.isIE && !this.initialized){
43921 this.initialized = true;
43922 this.layout.layout();
43927 // activate all subpanels if not currently active..
43929 setActiveState : function(active){
43930 this.active = active;
43931 this.setActiveClass(active);
43934 this.fireEvent("deactivate", this);
43938 this.fireEvent("activate", this);
43939 // not sure if this should happen before or after..
43940 if (!this.layout) {
43941 return; // should not happen..
43944 for (var r in this.layout.regions) {
43945 reg = this.layout.getRegion(r);
43946 if (reg.getActivePanel()) {
43947 //reg.showPanel(reg.getActivePanel()); // force it to activate..
43948 reg.setActivePanel(reg.getActivePanel());
43951 if (!reg.panels.length) {
43954 reg.showPanel(reg.getPanel(0));
43963 * Returns the nested BorderLayout for this panel
43964 * @return {Roo.BorderLayout}
43966 getLayout : function(){
43967 return this.layout;
43971 * Adds a xtype elements to the layout of the nested panel
43975 xtype : 'ContentPanel',
43982 xtype : 'NestedLayoutPanel',
43988 items : [ ... list of content panels or nested layout panels.. ]
43992 * @param {Object} cfg Xtype definition of item to add.
43994 addxtype : function(cfg) {
43995 return this.layout.addxtype(cfg);
44000 * Ext JS Library 1.1.1
44001 * Copyright(c) 2006-2007, Ext JS, LLC.
44003 * Originally Released Under LGPL - original licence link has changed is not relivant.
44006 * <script type="text/javascript">
44009 * @class Roo.TabPanel
44010 * @extends Roo.util.Observable
44011 * A lightweight tab container.
44015 // basic tabs 1, built from existing content
44016 var tabs = new Roo.TabPanel("tabs1");
44017 tabs.addTab("script", "View Script");
44018 tabs.addTab("markup", "View Markup");
44019 tabs.activate("script");
44021 // more advanced tabs, built from javascript
44022 var jtabs = new Roo.TabPanel("jtabs");
44023 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
44025 // set up the UpdateManager
44026 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
44027 var updater = tab2.getUpdateManager();
44028 updater.setDefaultUrl("ajax1.htm");
44029 tab2.on('activate', updater.refresh, updater, true);
44031 // Use setUrl for Ajax loading
44032 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
44033 tab3.setUrl("ajax2.htm", null, true);
44036 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
44039 jtabs.activate("jtabs-1");
44042 * Create a new TabPanel.
44043 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
44044 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
44046 Roo.bootstrap.panel.Tabs = function(config){
44048 * The container element for this TabPanel.
44049 * @type Roo.Element
44051 this.el = Roo.get(config.el);
44054 if(typeof config == "boolean"){
44055 this.tabPosition = config ? "bottom" : "top";
44057 Roo.apply(this, config);
44061 if(this.tabPosition == "bottom"){
44062 // if tabs are at the bottom = create the body first.
44063 this.bodyEl = Roo.get(this.createBody(this.el.dom));
44064 this.el.addClass("roo-tabs-bottom");
44066 // next create the tabs holders
44068 if (this.tabPosition == "west"){
44070 var reg = this.region; // fake it..
44072 if (!reg.mgr.parent) {
44075 reg = reg.mgr.parent.region;
44077 Roo.log("got nest?");
44079 if (reg.mgr.getRegion('west')) {
44080 var ctrdom = reg.mgr.getRegion('west').bodyEl.dom;
44081 this.stripWrap = Roo.get(this.createStrip(ctrdom ), true);
44082 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
44083 this.stripEl.setVisibilityMode(Roo.Element.DISPLAY);
44084 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
44092 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
44093 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
44094 this.stripEl.setVisibilityMode(Roo.Element.DISPLAY);
44095 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
44100 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
44103 // finally - if tabs are at the top, then create the body last..
44104 if(this.tabPosition != "bottom"){
44105 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
44106 * @type Roo.Element
44108 this.bodyEl = Roo.get(this.createBody(this.el.dom));
44109 this.el.addClass("roo-tabs-top");
44113 this.bodyEl.setStyle("position", "relative");
44115 this.active = null;
44116 this.activateDelegate = this.activate.createDelegate(this);
44121 * Fires when the active tab changes
44122 * @param {Roo.TabPanel} this
44123 * @param {Roo.TabPanelItem} activePanel The new active tab
44127 * @event beforetabchange
44128 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
44129 * @param {Roo.TabPanel} this
44130 * @param {Object} e Set cancel to true on this object to cancel the tab change
44131 * @param {Roo.TabPanelItem} tab The tab being changed to
44133 "beforetabchange" : true
44136 Roo.EventManager.onWindowResize(this.onResize, this);
44137 this.cpad = this.el.getPadding("lr");
44138 this.hiddenCount = 0;
44141 // toolbar on the tabbar support...
44142 if (this.toolbar) {
44143 alert("no toolbar support yet");
44144 this.toolbar = false;
44146 var tcfg = this.toolbar;
44147 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
44148 this.toolbar = new Roo.Toolbar(tcfg);
44149 if (Roo.isSafari) {
44150 var tbl = tcfg.container.child('table', true);
44151 tbl.setAttribute('width', '100%');
44159 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
44162 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
44164 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
44166 tabPosition : "top",
44168 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
44170 currentTabWidth : 0,
44172 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
44176 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
44180 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
44182 preferredTabWidth : 175,
44184 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
44186 resizeTabs : false,
44188 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
44190 monitorResize : true,
44192 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
44194 toolbar : false, // set by caller..
44196 region : false, /// set by caller
44198 disableTooltips : true, // not used yet...
44201 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
44202 * @param {String} id The id of the div to use <b>or create</b>
44203 * @param {String} text The text for the tab
44204 * @param {String} content (optional) Content to put in the TabPanelItem body
44205 * @param {Boolean} closable (optional) True to create a close icon on the tab
44206 * @return {Roo.TabPanelItem} The created TabPanelItem
44208 addTab : function(id, text, content, closable, tpl)
44210 var item = new Roo.bootstrap.panel.TabItem({
44214 closable : closable,
44217 this.addTabItem(item);
44219 item.setContent(content);
44225 * Returns the {@link Roo.TabPanelItem} with the specified id/index
44226 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
44227 * @return {Roo.TabPanelItem}
44229 getTab : function(id){
44230 return this.items[id];
44234 * Hides the {@link Roo.TabPanelItem} with the specified id/index
44235 * @param {String/Number} id The id or index of the TabPanelItem to hide.
44237 hideTab : function(id){
44238 var t = this.items[id];
44241 this.hiddenCount++;
44242 this.autoSizeTabs();
44247 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
44248 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
44250 unhideTab : function(id){
44251 var t = this.items[id];
44253 t.setHidden(false);
44254 this.hiddenCount--;
44255 this.autoSizeTabs();
44260 * Adds an existing {@link Roo.TabPanelItem}.
44261 * @param {Roo.TabPanelItem} item The TabPanelItem to add
44263 addTabItem : function(item)
44265 this.items[item.id] = item;
44266 this.items.push(item);
44267 this.autoSizeTabs();
44268 // if(this.resizeTabs){
44269 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
44270 // this.autoSizeTabs();
44272 // item.autoSize();
44277 * Removes a {@link Roo.TabPanelItem}.
44278 * @param {String/Number} id The id or index of the TabPanelItem to remove.
44280 removeTab : function(id){
44281 var items = this.items;
44282 var tab = items[id];
44283 if(!tab) { return; }
44284 var index = items.indexOf(tab);
44285 if(this.active == tab && items.length > 1){
44286 var newTab = this.getNextAvailable(index);
44291 this.stripEl.dom.removeChild(tab.pnode.dom);
44292 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
44293 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
44295 items.splice(index, 1);
44296 delete this.items[tab.id];
44297 tab.fireEvent("close", tab);
44298 tab.purgeListeners();
44299 this.autoSizeTabs();
44302 getNextAvailable : function(start){
44303 var items = this.items;
44305 // look for a next tab that will slide over to
44306 // replace the one being removed
44307 while(index < items.length){
44308 var item = items[++index];
44309 if(item && !item.isHidden()){
44313 // if one isn't found select the previous tab (on the left)
44316 var item = items[--index];
44317 if(item && !item.isHidden()){
44325 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
44326 * @param {String/Number} id The id or index of the TabPanelItem to disable.
44328 disableTab : function(id){
44329 var tab = this.items[id];
44330 if(tab && this.active != tab){
44336 * Enables a {@link Roo.TabPanelItem} that is disabled.
44337 * @param {String/Number} id The id or index of the TabPanelItem to enable.
44339 enableTab : function(id){
44340 var tab = this.items[id];
44345 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
44346 * @param {String/Number} id The id or index of the TabPanelItem to activate.
44347 * @return {Roo.TabPanelItem} The TabPanelItem.
44349 activate : function(id)
44351 //Roo.log('activite:' + id);
44353 var tab = this.items[id];
44357 if(tab == this.active || tab.disabled){
44361 this.fireEvent("beforetabchange", this, e, tab);
44362 if(e.cancel !== true && !tab.disabled){
44364 this.active.hide();
44366 this.active = this.items[id];
44367 this.active.show();
44368 this.fireEvent("tabchange", this, this.active);
44374 * Gets the active {@link Roo.TabPanelItem}.
44375 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
44377 getActiveTab : function(){
44378 return this.active;
44382 * Updates the tab body element to fit the height of the container element
44383 * for overflow scrolling
44384 * @param {Number} targetHeight (optional) Override the starting height from the elements height
44386 syncHeight : function(targetHeight){
44387 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
44388 var bm = this.bodyEl.getMargins();
44389 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
44390 this.bodyEl.setHeight(newHeight);
44394 onResize : function(){
44395 if(this.monitorResize){
44396 this.autoSizeTabs();
44401 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
44403 beginUpdate : function(){
44404 this.updating = true;
44408 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
44410 endUpdate : function(){
44411 this.updating = false;
44412 this.autoSizeTabs();
44416 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
44418 autoSizeTabs : function()
44420 var count = this.items.length;
44421 var vcount = count - this.hiddenCount;
44424 this.stripEl.hide();
44426 this.stripEl.show();
44429 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
44434 var w = Math.max(this.el.getWidth() - this.cpad, 10);
44435 var availWidth = Math.floor(w / vcount);
44436 var b = this.stripBody;
44437 if(b.getWidth() > w){
44438 var tabs = this.items;
44439 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
44440 if(availWidth < this.minTabWidth){
44441 /*if(!this.sleft){ // incomplete scrolling code
44442 this.createScrollButtons();
44445 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
44448 if(this.currentTabWidth < this.preferredTabWidth){
44449 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
44455 * Returns the number of tabs in this TabPanel.
44458 getCount : function(){
44459 return this.items.length;
44463 * Resizes all the tabs to the passed width
44464 * @param {Number} The new width
44466 setTabWidth : function(width){
44467 this.currentTabWidth = width;
44468 for(var i = 0, len = this.items.length; i < len; i++) {
44469 if(!this.items[i].isHidden()) {
44470 this.items[i].setWidth(width);
44476 * Destroys this TabPanel
44477 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
44479 destroy : function(removeEl){
44480 Roo.EventManager.removeResizeListener(this.onResize, this);
44481 for(var i = 0, len = this.items.length; i < len; i++){
44482 this.items[i].purgeListeners();
44484 if(removeEl === true){
44485 this.el.update("");
44490 createStrip : function(container)
44492 var strip = document.createElement("nav");
44493 strip.className = Roo.bootstrap.version == 4 ?
44494 "navbar-light bg-light" :
44495 "navbar navbar-default"; //"x-tabs-wrap";
44496 container.appendChild(strip);
44500 createStripList : function(strip)
44502 // div wrapper for retard IE
44503 // returns the "tr" element.
44504 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
44505 //'<div class="x-tabs-strip-wrap">'+
44506 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
44507 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
44508 return strip.firstChild; //.firstChild.firstChild.firstChild;
44510 createBody : function(container)
44512 var body = document.createElement("div");
44513 Roo.id(body, "tab-body");
44514 //Roo.fly(body).addClass("x-tabs-body");
44515 Roo.fly(body).addClass("tab-content");
44516 container.appendChild(body);
44519 createItemBody :function(bodyEl, id){
44520 var body = Roo.getDom(id);
44522 body = document.createElement("div");
44525 //Roo.fly(body).addClass("x-tabs-item-body");
44526 Roo.fly(body).addClass("tab-pane");
44527 bodyEl.insertBefore(body, bodyEl.firstChild);
44531 createStripElements : function(stripEl, text, closable, tpl)
44533 var td = document.createElement("li"); // was td..
44534 td.className = 'nav-item';
44536 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
44539 stripEl.appendChild(td);
44541 td.className = "x-tabs-closable";
44542 if(!this.closeTpl){
44543 this.closeTpl = new Roo.Template(
44544 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
44545 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
44546 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
44549 var el = this.closeTpl.overwrite(td, {"text": text});
44550 var close = el.getElementsByTagName("div")[0];
44551 var inner = el.getElementsByTagName("em")[0];
44552 return {"el": el, "close": close, "inner": inner};
44555 // not sure what this is..
44556 // if(!this.tabTpl){
44557 //this.tabTpl = new Roo.Template(
44558 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
44559 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
44561 // this.tabTpl = new Roo.Template(
44562 // '<a href="#">' +
44563 // '<span unselectable="on"' +
44564 // (this.disableTooltips ? '' : ' title="{text}"') +
44565 // ' >{text}</span></a>'
44571 var template = tpl || this.tabTpl || false;
44574 template = new Roo.Template(
44575 Roo.bootstrap.version == 4 ?
44577 '<a class="nav-link" href="#" unselectable="on"' +
44578 (this.disableTooltips ? '' : ' title="{text}"') +
44581 '<a class="nav-link" href="#">' +
44582 '<span unselectable="on"' +
44583 (this.disableTooltips ? '' : ' title="{text}"') +
44584 ' >{text}</span></a>'
44589 switch (typeof(template)) {
44593 template = new Roo.Template(template);
44599 var el = template.overwrite(td, {"text": text});
44601 var inner = el.getElementsByTagName("span")[0];
44603 return {"el": el, "inner": inner};
44611 * @class Roo.TabPanelItem
44612 * @extends Roo.util.Observable
44613 * Represents an individual item (tab plus body) in a TabPanel.
44614 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
44615 * @param {String} id The id of this TabPanelItem
44616 * @param {String} text The text for the tab of this TabPanelItem
44617 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
44619 Roo.bootstrap.panel.TabItem = function(config){
44621 * The {@link Roo.TabPanel} this TabPanelItem belongs to
44622 * @type Roo.TabPanel
44624 this.tabPanel = config.panel;
44626 * The id for this TabPanelItem
44629 this.id = config.id;
44631 this.disabled = false;
44633 this.text = config.text;
44635 this.loaded = false;
44636 this.closable = config.closable;
44639 * The body element for this TabPanelItem.
44640 * @type Roo.Element
44642 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
44643 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
44644 this.bodyEl.setStyle("display", "block");
44645 this.bodyEl.setStyle("zoom", "1");
44646 //this.hideAction();
44648 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
44650 this.el = Roo.get(els.el);
44651 this.inner = Roo.get(els.inner, true);
44652 this.textEl = Roo.bootstrap.version == 4 ?
44653 this.el : Roo.get(this.el.dom.firstChild, true);
44655 this.pnode = this.linode = Roo.get(els.el.parentNode, true);
44656 this.status_node = Roo.bootstrap.version == 4 ? this.el : this.linode;
44659 // this.el.on("mousedown", this.onTabMouseDown, this);
44660 this.el.on("click", this.onTabClick, this);
44662 if(config.closable){
44663 var c = Roo.get(els.close, true);
44664 c.dom.title = this.closeText;
44665 c.addClassOnOver("close-over");
44666 c.on("click", this.closeClick, this);
44672 * Fires when this tab becomes the active tab.
44673 * @param {Roo.TabPanel} tabPanel The parent TabPanel
44674 * @param {Roo.TabPanelItem} this
44678 * @event beforeclose
44679 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
44680 * @param {Roo.TabPanelItem} this
44681 * @param {Object} e Set cancel to true on this object to cancel the close.
44683 "beforeclose": true,
44686 * Fires when this tab is closed.
44687 * @param {Roo.TabPanelItem} this
44691 * @event deactivate
44692 * Fires when this tab is no longer the active tab.
44693 * @param {Roo.TabPanel} tabPanel The parent TabPanel
44694 * @param {Roo.TabPanelItem} this
44696 "deactivate" : true
44698 this.hidden = false;
44700 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
44703 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
44705 purgeListeners : function(){
44706 Roo.util.Observable.prototype.purgeListeners.call(this);
44707 this.el.removeAllListeners();
44710 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
44713 this.status_node.addClass("active");
44716 this.tabPanel.stripWrap.repaint();
44718 this.fireEvent("activate", this.tabPanel, this);
44722 * Returns true if this tab is the active tab.
44723 * @return {Boolean}
44725 isActive : function(){
44726 return this.tabPanel.getActiveTab() == this;
44730 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
44733 this.status_node.removeClass("active");
44735 this.fireEvent("deactivate", this.tabPanel, this);
44738 hideAction : function(){
44739 this.bodyEl.hide();
44740 this.bodyEl.setStyle("position", "absolute");
44741 this.bodyEl.setLeft("-20000px");
44742 this.bodyEl.setTop("-20000px");
44745 showAction : function(){
44746 this.bodyEl.setStyle("position", "relative");
44747 this.bodyEl.setTop("");
44748 this.bodyEl.setLeft("");
44749 this.bodyEl.show();
44753 * Set the tooltip for the tab.
44754 * @param {String} tooltip The tab's tooltip
44756 setTooltip : function(text){
44757 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
44758 this.textEl.dom.qtip = text;
44759 this.textEl.dom.removeAttribute('title');
44761 this.textEl.dom.title = text;
44765 onTabClick : function(e){
44766 e.preventDefault();
44767 this.tabPanel.activate(this.id);
44770 onTabMouseDown : function(e){
44771 e.preventDefault();
44772 this.tabPanel.activate(this.id);
44775 getWidth : function(){
44776 return this.inner.getWidth();
44779 setWidth : function(width){
44780 var iwidth = width - this.linode.getPadding("lr");
44781 this.inner.setWidth(iwidth);
44782 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
44783 this.linode.setWidth(width);
44787 * Show or hide the tab
44788 * @param {Boolean} hidden True to hide or false to show.
44790 setHidden : function(hidden){
44791 this.hidden = hidden;
44792 this.linode.setStyle("display", hidden ? "none" : "");
44796 * Returns true if this tab is "hidden"
44797 * @return {Boolean}
44799 isHidden : function(){
44800 return this.hidden;
44804 * Returns the text for this tab
44807 getText : function(){
44811 autoSize : function(){
44812 //this.el.beginMeasure();
44813 this.textEl.setWidth(1);
44815 * #2804 [new] Tabs in Roojs
44816 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
44818 //this.setWidth(this.textEl.dom.scrollWidth+this.linode.getPadding("lr")+this.inner.getPadding("lr") + 2);
44819 //this.el.endMeasure();
44823 * Sets the text for the tab (Note: this also sets the tooltip text)
44824 * @param {String} text The tab's text and tooltip
44826 setText : function(text){
44828 this.textEl.update(text);
44829 this.setTooltip(text);
44830 //if(!this.tabPanel.resizeTabs){
44831 // this.autoSize();
44835 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
44837 activate : function(){
44838 this.tabPanel.activate(this.id);
44842 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
44844 disable : function(){
44845 if(this.tabPanel.active != this){
44846 this.disabled = true;
44847 this.status_node.addClass("disabled");
44852 * Enables this TabPanelItem if it was previously disabled.
44854 enable : function(){
44855 this.disabled = false;
44856 this.status_node.removeClass("disabled");
44860 * Sets the content for this TabPanelItem.
44861 * @param {String} content The content
44862 * @param {Boolean} loadScripts true to look for and load scripts
44864 setContent : function(content, loadScripts){
44865 this.bodyEl.update(content, loadScripts);
44869 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
44870 * @return {Roo.UpdateManager} The UpdateManager
44872 getUpdateManager : function(){
44873 return this.bodyEl.getUpdateManager();
44877 * Set a URL to be used to load the content for this TabPanelItem.
44878 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
44879 * @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)
44880 * @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)
44881 * @return {Roo.UpdateManager} The UpdateManager
44883 setUrl : function(url, params, loadOnce){
44884 if(this.refreshDelegate){
44885 this.un('activate', this.refreshDelegate);
44887 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
44888 this.on("activate", this.refreshDelegate);
44889 return this.bodyEl.getUpdateManager();
44893 _handleRefresh : function(url, params, loadOnce){
44894 if(!loadOnce || !this.loaded){
44895 var updater = this.bodyEl.getUpdateManager();
44896 updater.update(url, params, this._setLoaded.createDelegate(this));
44901 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
44902 * Will fail silently if the setUrl method has not been called.
44903 * This does not activate the panel, just updates its content.
44905 refresh : function(){
44906 if(this.refreshDelegate){
44907 this.loaded = false;
44908 this.refreshDelegate();
44913 _setLoaded : function(){
44914 this.loaded = true;
44918 closeClick : function(e){
44921 this.fireEvent("beforeclose", this, o);
44922 if(o.cancel !== true){
44923 this.tabPanel.removeTab(this.id);
44927 * The text displayed in the tooltip for the close icon.
44930 closeText : "Close this tab"
44933 * This script refer to:
44934 * Title: International Telephone Input
44935 * Author: Jack O'Connor
44936 * Code version: v12.1.12
44937 * Availability: https://github.com/jackocnr/intl-tel-input.git
44940 Roo.bootstrap.form.PhoneInputData = function() {
44943 "Afghanistan (افغانستان)",
44948 "Albania (Shqipëri)",
44953 "Algeria (الجزائر)",
44978 "Antigua and Barbuda",
44988 "Armenia (Հայաստան)",
45004 "Austria (Österreich)",
45009 "Azerbaijan (Azərbaycan)",
45019 "Bahrain (البحرين)",
45024 "Bangladesh (বাংলাদেশ)",
45034 "Belarus (Беларусь)",
45039 "Belgium (België)",
45069 "Bosnia and Herzegovina (Босна и Херцеговина)",
45084 "British Indian Ocean Territory",
45089 "British Virgin Islands",
45099 "Bulgaria (България)",
45109 "Burundi (Uburundi)",
45114 "Cambodia (កម្ពុជា)",
45119 "Cameroon (Cameroun)",
45128 ["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"]
45131 "Cape Verde (Kabu Verdi)",
45136 "Caribbean Netherlands",
45147 "Central African Republic (République centrafricaine)",
45167 "Christmas Island",
45173 "Cocos (Keeling) Islands",
45184 "Comoros (جزر القمر)",
45189 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
45194 "Congo (Republic) (Congo-Brazzaville)",
45214 "Croatia (Hrvatska)",
45235 "Czech Republic (Česká republika)",
45240 "Denmark (Danmark)",
45255 "Dominican Republic (República Dominicana)",
45259 ["809", "829", "849"]
45277 "Equatorial Guinea (Guinea Ecuatorial)",
45297 "Falkland Islands (Islas Malvinas)",
45302 "Faroe Islands (Føroyar)",
45323 "French Guiana (Guyane française)",
45328 "French Polynesia (Polynésie française)",
45343 "Georgia (საქართველო)",
45348 "Germany (Deutschland)",
45368 "Greenland (Kalaallit Nunaat)",
45405 "Guinea-Bissau (Guiné Bissau)",
45430 "Hungary (Magyarország)",
45435 "Iceland (Ísland)",
45455 "Iraq (العراق)",
45471 "Israel (ישראל)",
45498 "Jordan (الأردن)",
45503 "Kazakhstan (Казахстан)",
45524 "Kuwait (الكويت)",
45529 "Kyrgyzstan (Кыргызстан)",
45539 "Latvia (Latvija)",
45544 "Lebanon (لبنان)",
45559 "Libya (ليبيا)",
45569 "Lithuania (Lietuva)",
45584 "Macedonia (FYROM) (Македонија)",
45589 "Madagascar (Madagasikara)",
45619 "Marshall Islands",
45629 "Mauritania (موريتانيا)",
45634 "Mauritius (Moris)",
45655 "Moldova (Republica Moldova)",
45665 "Mongolia (Монгол)",
45670 "Montenegro (Crna Gora)",
45680 "Morocco (المغرب)",
45686 "Mozambique (Moçambique)",
45691 "Myanmar (Burma) (မြန်မာ)",
45696 "Namibia (Namibië)",
45711 "Netherlands (Nederland)",
45716 "New Caledonia (Nouvelle-Calédonie)",
45751 "North Korea (조선 민주주의 인민 공화국)",
45756 "Northern Mariana Islands",
45772 "Pakistan (پاکستان)",
45782 "Palestine (فلسطين)",
45792 "Papua New Guinea",
45834 "Réunion (La Réunion)",
45840 "Romania (România)",
45856 "Saint Barthélemy",
45867 "Saint Kitts and Nevis",
45877 "Saint Martin (Saint-Martin (partie française))",
45883 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
45888 "Saint Vincent and the Grenadines",
45903 "São Tomé and Príncipe (São Tomé e Príncipe)",
45908 "Saudi Arabia (المملكة العربية السعودية)",
45913 "Senegal (Sénégal)",
45943 "Slovakia (Slovensko)",
45948 "Slovenia (Slovenija)",
45958 "Somalia (Soomaaliya)",
45968 "South Korea (대한민국)",
45973 "South Sudan (جنوب السودان)",
45983 "Sri Lanka (ශ්රී ලංකාව)",
45988 "Sudan (السودان)",
45998 "Svalbard and Jan Mayen",
46009 "Sweden (Sverige)",
46014 "Switzerland (Schweiz)",
46019 "Syria (سوريا)",
46064 "Trinidad and Tobago",
46069 "Tunisia (تونس)",
46074 "Turkey (Türkiye)",
46084 "Turks and Caicos Islands",
46094 "U.S. Virgin Islands",
46104 "Ukraine (Україна)",
46109 "United Arab Emirates (الإمارات العربية المتحدة)",
46131 "Uzbekistan (Oʻzbekiston)",
46141 "Vatican City (Città del Vaticano)",
46152 "Vietnam (Việt Nam)",
46157 "Wallis and Futuna (Wallis-et-Futuna)",
46162 "Western Sahara (الصحراء الغربية)",
46168 "Yemen (اليمن)",
46192 * This script refer to:
46193 * Title: International Telephone Input
46194 * Author: Jack O'Connor
46195 * Code version: v12.1.12
46196 * Availability: https://github.com/jackocnr/intl-tel-input.git
46200 * @class Roo.bootstrap.form.PhoneInput
46201 * @extends Roo.bootstrap.form.TriggerField
46202 * An input with International dial-code selection
46204 * @cfg {String} defaultDialCode default '+852'
46205 * @cfg {Array} preferedCountries default []
46208 * Create a new PhoneInput.
46209 * @param {Object} config Configuration options
46212 Roo.bootstrap.form.PhoneInput = function(config) {
46213 Roo.bootstrap.form.PhoneInput.superclass.constructor.call(this, config);
46216 Roo.extend(Roo.bootstrap.form.PhoneInput, Roo.bootstrap.form.TriggerField, {
46218 * @cfg {Roo.data.Store} store [required] The data store to which this combo is bound (defaults to undefined)
46220 listWidth: undefined,
46222 selectedClass: 'active',
46224 invalidClass : "has-warning",
46226 validClass: 'has-success',
46228 allowed: '0123456789',
46233 * @cfg {String} defaultDialCode The default dial code when initializing the input
46235 defaultDialCode: '+852',
46238 * @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
46240 preferedCountries: false,
46242 getAutoCreate : function()
46244 var data = Roo.bootstrap.form.PhoneInputData();
46245 var align = this.labelAlign || this.parentLabelAlign();
46248 this.allCountries = [];
46249 this.dialCodeMapping = [];
46251 for (var i = 0; i < data.length; i++) {
46253 this.allCountries[i] = {
46257 priority: c[3] || 0,
46258 areaCodes: c[4] || null
46260 this.dialCodeMapping[c[2]] = {
46263 priority: c[3] || 0,
46264 areaCodes: c[4] || null
46276 // type: 'number', -- do not use number - we get the flaky up/down arrows.
46277 maxlength: this.max_length,
46278 cls : 'form-control tel-input',
46279 autocomplete: 'new-password'
46282 var hiddenInput = {
46285 cls: 'hidden-tel-input'
46289 hiddenInput.name = this.name;
46292 if (this.disabled) {
46293 input.disabled = true;
46296 var flag_container = {
46313 cls: this.hasFeedback ? 'has-feedback' : '',
46319 cls: 'dial-code-holder',
46326 cls: 'roo-select2-container input-group',
46333 if (this.fieldLabel.length) {
46336 tooltip: 'This field is required'
46342 cls: 'control-label',
46348 html: this.fieldLabel
46351 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
46357 if(this.indicatorpos == 'right') {
46358 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
46365 if(align == 'left') {
46373 if(this.labelWidth > 12){
46374 label.style = "width: " + this.labelWidth + 'px';
46376 if(this.labelWidth < 13 && this.labelmd == 0){
46377 this.labelmd = this.labelWidth;
46379 if(this.labellg > 0){
46380 label.cls += ' col-lg-' + this.labellg;
46381 input.cls += ' col-lg-' + (12 - this.labellg);
46383 if(this.labelmd > 0){
46384 label.cls += ' col-md-' + this.labelmd;
46385 container.cls += ' col-md-' + (12 - this.labelmd);
46387 if(this.labelsm > 0){
46388 label.cls += ' col-sm-' + this.labelsm;
46389 container.cls += ' col-sm-' + (12 - this.labelsm);
46391 if(this.labelxs > 0){
46392 label.cls += ' col-xs-' + this.labelxs;
46393 container.cls += ' col-xs-' + (12 - this.labelxs);
46403 var settings = this;
46405 ['xs','sm','md','lg'].map(function(size){
46406 if (settings[size]) {
46407 cfg.cls += ' col-' + size + '-' + settings[size];
46411 this.store = new Roo.data.Store({
46412 proxy : new Roo.data.MemoryProxy({}),
46413 reader : new Roo.data.JsonReader({
46424 'name' : 'dialCode',
46428 'name' : 'priority',
46432 'name' : 'areaCodes',
46439 if(!this.preferedCountries) {
46440 this.preferedCountries = [
46447 var p = this.preferedCountries.reverse();
46450 for (var i = 0; i < p.length; i++) {
46451 for (var j = 0; j < this.allCountries.length; j++) {
46452 if(this.allCountries[j].iso2 == p[i]) {
46453 var t = this.allCountries[j];
46454 this.allCountries.splice(j,1);
46455 this.allCountries.unshift(t);
46461 this.store.proxy.data = {
46463 data: this.allCountries
46469 initEvents : function()
46472 Roo.bootstrap.form.PhoneInput.superclass.initEvents.call(this);
46474 this.indicator = this.indicatorEl();
46475 this.flag = this.flagEl();
46476 this.dialCodeHolder = this.dialCodeHolderEl();
46478 this.trigger = this.el.select('div.flag-box',true).first();
46479 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
46484 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
46485 _this.list.setWidth(lw);
46488 this.list.on('mouseover', this.onViewOver, this);
46489 this.list.on('mousemove', this.onViewMove, this);
46490 this.inputEl().on("keyup", this.onKeyUp, this);
46491 this.inputEl().on("keypress", this.onKeyPress, this);
46493 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
46495 this.view = new Roo.View(this.list, this.tpl, {
46496 singleSelect:true, store: this.store, selectedClass: this.selectedClass
46499 this.view.on('click', this.onViewClick, this);
46500 this.setValue(this.defaultDialCode);
46503 onTriggerClick : function(e)
46505 Roo.log('trigger click');
46510 if(this.isExpanded()){
46512 this.hasFocus = false;
46514 this.store.load({});
46515 this.hasFocus = true;
46520 isExpanded : function()
46522 return this.list.isVisible();
46525 collapse : function()
46527 if(!this.isExpanded()){
46531 Roo.get(document).un('mousedown', this.collapseIf, this);
46532 Roo.get(document).un('mousewheel', this.collapseIf, this);
46533 this.fireEvent('collapse', this);
46537 expand : function()
46541 if(this.isExpanded() || !this.hasFocus){
46545 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
46546 this.list.setWidth(lw);
46549 this.restrictHeight();
46551 Roo.get(document).on('mousedown', this.collapseIf, this);
46552 Roo.get(document).on('mousewheel', this.collapseIf, this);
46554 this.fireEvent('expand', this);
46557 restrictHeight : function()
46559 this.list.alignTo(this.inputEl(), this.listAlign);
46560 this.list.alignTo(this.inputEl(), this.listAlign);
46563 onViewOver : function(e, t)
46565 if(this.inKeyMode){
46568 var item = this.view.findItemFromChild(t);
46571 var index = this.view.indexOf(item);
46572 this.select(index, false);
46577 onViewClick : function(view, doFocus, el, e)
46579 var index = this.view.getSelectedIndexes()[0];
46581 var r = this.store.getAt(index);
46584 this.onSelect(r, index);
46586 if(doFocus !== false && !this.blockFocus){
46587 this.inputEl().focus();
46591 onViewMove : function(e, t)
46593 this.inKeyMode = false;
46596 select : function(index, scrollIntoView)
46598 this.selectedIndex = index;
46599 this.view.select(index);
46600 if(scrollIntoView !== false){
46601 var el = this.view.getNode(index);
46603 this.list.scrollChildIntoView(el, false);
46608 createList : function()
46610 this.list = Roo.get(document.body).createChild({
46612 cls: 'typeahead typeahead-long dropdown-menu tel-list',
46613 style: 'display:none'
46616 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
46619 collapseIf : function(e)
46621 var in_combo = e.within(this.el);
46622 var in_list = e.within(this.list);
46623 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
46625 if (in_combo || in_list || is_list) {
46631 onSelect : function(record, index)
46633 if(this.fireEvent('beforeselect', this, record, index) !== false){
46635 this.setFlagClass(record.data.iso2);
46636 this.setDialCode(record.data.dialCode);
46637 this.hasFocus = false;
46639 this.fireEvent('select', this, record, index);
46643 flagEl : function()
46645 var flag = this.el.select('div.flag',true).first();
46652 dialCodeHolderEl : function()
46654 var d = this.el.select('input.dial-code-holder',true).first();
46661 setDialCode : function(v)
46663 this.dialCodeHolder.dom.value = '+'+v;
46666 setFlagClass : function(n)
46668 this.flag.dom.className = 'flag '+n;
46671 getValue : function()
46673 var v = this.inputEl().getValue();
46674 if(this.dialCodeHolder) {
46675 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
46680 setValue : function(v)
46682 var d = this.getDialCode(v);
46684 //invalid dial code
46685 if(v.length == 0 || !d || d.length == 0) {
46687 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
46688 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
46694 this.setFlagClass(this.dialCodeMapping[d].iso2);
46695 this.setDialCode(d);
46696 this.inputEl().dom.value = v.replace('+'+d,'');
46697 this.hiddenEl().dom.value = this.getValue();
46702 getDialCode : function(v)
46706 if (v.length == 0) {
46707 return this.dialCodeHolder.dom.value;
46711 if (v.charAt(0) != "+") {
46714 var numericChars = "";
46715 for (var i = 1; i < v.length; i++) {
46716 var c = v.charAt(i);
46719 if (this.dialCodeMapping[numericChars]) {
46720 dialCode = v.substr(1, i);
46722 if (numericChars.length == 4) {
46732 this.setValue(this.defaultDialCode);
46736 hiddenEl : function()
46738 return this.el.select('input.hidden-tel-input',true).first();
46741 // after setting val
46742 onKeyUp : function(e){
46743 this.setValue(this.getValue());
46746 onKeyPress : function(e){
46747 if(this.allowed.indexOf(String.fromCharCode(e.getCharCode())) === -1){
46754 * @class Roo.bootstrap.form.MoneyField
46755 * @extends Roo.bootstrap.form.ComboBox
46756 * Bootstrap MoneyField class
46759 * Create a new MoneyField.
46760 * @param {Object} config Configuration options
46763 Roo.bootstrap.form.MoneyField = function(config) {
46765 Roo.bootstrap.form.MoneyField.superclass.constructor.call(this, config);
46769 Roo.extend(Roo.bootstrap.form.MoneyField, Roo.bootstrap.form.ComboBox, {
46772 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
46774 allowDecimals : true,
46776 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
46778 decimalSeparator : ".",
46780 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
46782 decimalPrecision : 0,
46784 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
46786 allowNegative : true,
46788 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
46792 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
46794 minValue : Number.NEGATIVE_INFINITY,
46796 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
46798 maxValue : Number.MAX_VALUE,
46800 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
46802 minText : "The minimum value for this field is {0}",
46804 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
46806 maxText : "The maximum value for this field is {0}",
46808 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
46809 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
46811 nanText : "{0} is not a valid number",
46813 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
46817 * @cfg {String} defaults currency of the MoneyField
46818 * value should be in lkey
46820 defaultCurrency : false,
46822 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
46824 thousandsDelimiter : false,
46826 * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
46835 * @cfg {Roo.data.Store} store Store to lookup currency??
46839 getAutoCreate : function()
46841 var align = this.labelAlign || this.parentLabelAlign();
46853 cls : 'form-control roo-money-amount-input',
46854 autocomplete: 'new-password'
46857 var hiddenInput = {
46861 cls: 'hidden-number-input'
46864 if(this.max_length) {
46865 input.maxlength = this.max_length;
46869 hiddenInput.name = this.name;
46872 if (this.disabled) {
46873 input.disabled = true;
46876 var clg = 12 - this.inputlg;
46877 var cmd = 12 - this.inputmd;
46878 var csm = 12 - this.inputsm;
46879 var cxs = 12 - this.inputxs;
46883 cls : 'row roo-money-field',
46887 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
46891 cls: 'roo-select2-container input-group',
46895 cls : 'form-control roo-money-currency-input',
46896 autocomplete: 'new-password',
46898 name : this.currencyName
46902 cls : 'input-group-addon',
46916 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
46920 cls: this.hasFeedback ? 'has-feedback' : '',
46931 if (this.fieldLabel.length) {
46934 tooltip: 'This field is required'
46940 cls: 'control-label',
46946 html: this.fieldLabel
46949 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
46955 if(this.indicatorpos == 'right') {
46956 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
46963 if(align == 'left') {
46971 if(this.labelWidth > 12){
46972 label.style = "width: " + this.labelWidth + 'px';
46974 if(this.labelWidth < 13 && this.labelmd == 0){
46975 this.labelmd = this.labelWidth;
46977 if(this.labellg > 0){
46978 label.cls += ' col-lg-' + this.labellg;
46979 input.cls += ' col-lg-' + (12 - this.labellg);
46981 if(this.labelmd > 0){
46982 label.cls += ' col-md-' + this.labelmd;
46983 container.cls += ' col-md-' + (12 - this.labelmd);
46985 if(this.labelsm > 0){
46986 label.cls += ' col-sm-' + this.labelsm;
46987 container.cls += ' col-sm-' + (12 - this.labelsm);
46989 if(this.labelxs > 0){
46990 label.cls += ' col-xs-' + this.labelxs;
46991 container.cls += ' col-xs-' + (12 - this.labelxs);
47002 var settings = this;
47004 ['xs','sm','md','lg'].map(function(size){
47005 if (settings[size]) {
47006 cfg.cls += ' col-' + size + '-' + settings[size];
47013 initEvents : function()
47015 this.indicator = this.indicatorEl();
47017 this.initCurrencyEvent();
47019 this.initNumberEvent();
47022 initCurrencyEvent : function()
47025 throw "can not find store for combo";
47028 this.store = Roo.factory(this.store, Roo.data);
47029 this.store.parent = this;
47033 this.triggerEl = this.el.select('.input-group-addon', true).first();
47035 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
47040 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
47041 _this.list.setWidth(lw);
47044 this.list.on('mouseover', this.onViewOver, this);
47045 this.list.on('mousemove', this.onViewMove, this);
47046 this.list.on('scroll', this.onViewScroll, this);
47049 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
47052 this.view = new Roo.View(this.list, this.tpl, {
47053 singleSelect:true, store: this.store, selectedClass: this.selectedClass
47056 this.view.on('click', this.onViewClick, this);
47058 this.store.on('beforeload', this.onBeforeLoad, this);
47059 this.store.on('load', this.onLoad, this);
47060 this.store.on('loadexception', this.onLoadException, this);
47062 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
47063 "up" : function(e){
47064 this.inKeyMode = true;
47068 "down" : function(e){
47069 if(!this.isExpanded()){
47070 this.onTriggerClick();
47072 this.inKeyMode = true;
47077 "enter" : function(e){
47080 if(this.fireEvent("specialkey", this, e)){
47081 this.onViewClick(false);
47087 "esc" : function(e){
47091 "tab" : function(e){
47094 if(this.fireEvent("specialkey", this, e)){
47095 this.onViewClick(false);
47103 doRelay : function(foo, bar, hname){
47104 if(hname == 'down' || this.scope.isExpanded()){
47105 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
47113 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
47117 initNumberEvent : function(e)
47119 this.inputEl().on("keydown" , this.fireKey, this);
47120 this.inputEl().on("focus", this.onFocus, this);
47121 this.inputEl().on("blur", this.onBlur, this);
47123 this.inputEl().relayEvent('keyup', this);
47125 if(this.indicator){
47126 this.indicator.addClass('invisible');
47129 this.originalValue = this.getValue();
47131 if(this.validationEvent == 'keyup'){
47132 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
47133 this.inputEl().on('keyup', this.filterValidation, this);
47135 else if(this.validationEvent !== false){
47136 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
47139 if(this.selectOnFocus){
47140 this.on("focus", this.preFocus, this);
47143 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
47144 this.inputEl().on("keypress", this.filterKeys, this);
47146 this.inputEl().relayEvent('keypress', this);
47149 var allowed = "0123456789";
47151 if(this.allowDecimals){
47152 allowed += this.decimalSeparator;
47155 if(this.allowNegative){
47159 if(this.thousandsDelimiter) {
47163 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
47165 var keyPress = function(e){
47167 var k = e.getKey();
47169 var c = e.getCharCode();
47172 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
47173 allowed.indexOf(String.fromCharCode(c)) === -1
47179 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
47183 if(allowed.indexOf(String.fromCharCode(c)) === -1){
47188 this.inputEl().on("keypress", keyPress, this);
47192 onTriggerClick : function(e)
47199 this.loadNext = false;
47201 if(this.isExpanded()){
47206 this.hasFocus = true;
47208 if(this.triggerAction == 'all') {
47209 this.doQuery(this.allQuery, true);
47213 this.doQuery(this.getRawValue());
47216 getCurrency : function()
47218 var v = this.currencyEl().getValue();
47223 restrictHeight : function()
47225 this.list.alignTo(this.currencyEl(), this.listAlign);
47226 this.list.alignTo(this.currencyEl(), this.listAlign);
47229 onViewClick : function(view, doFocus, el, e)
47231 var index = this.view.getSelectedIndexes()[0];
47233 var r = this.store.getAt(index);
47236 this.onSelect(r, index);
47240 onSelect : function(record, index){
47242 if(this.fireEvent('beforeselect', this, record, index) !== false){
47244 this.setFromCurrencyData(index > -1 ? record.data : false);
47248 this.fireEvent('select', this, record, index);
47252 setFromCurrencyData : function(o)
47256 this.lastCurrency = o;
47258 if (this.currencyField) {
47259 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
47261 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
47264 this.lastSelectionText = currency;
47266 //setting default currency
47267 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
47268 this.setCurrency(this.defaultCurrency);
47272 this.setCurrency(currency);
47275 setFromData : function(o)
47279 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
47281 this.setFromCurrencyData(c);
47286 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
47288 Roo.log('no value set for '+ (this.name ? this.name : this.id));
47291 this.setValue(value);
47295 setCurrency : function(v)
47297 this.currencyValue = v;
47300 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
47305 setValue : function(v)
47307 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
47313 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
47315 this.inputEl().dom.value = (v == '') ? '' :
47316 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
47318 if(!this.allowZero && v === '0') {
47319 this.hiddenEl().dom.value = '';
47320 this.inputEl().dom.value = '';
47327 getRawValue : function()
47329 var v = this.inputEl().getValue();
47334 getValue : function()
47336 return this.fixPrecision(this.parseValue(this.getRawValue()));
47339 parseValue : function(value)
47341 if(this.thousandsDelimiter) {
47343 r = new RegExp(",", "g");
47344 value = value.replace(r, "");
47347 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
47348 return isNaN(value) ? '' : value;
47352 fixPrecision : function(value)
47354 if(this.thousandsDelimiter) {
47356 r = new RegExp(",", "g");
47357 value = value.replace(r, "");
47360 var nan = isNaN(value);
47362 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
47363 return nan ? '' : value;
47365 return parseFloat(value).toFixed(this.decimalPrecision);
47368 decimalPrecisionFcn : function(v)
47370 return Math.floor(v);
47373 validateValue : function(value)
47375 if(!Roo.bootstrap.form.MoneyField.superclass.validateValue.call(this, value)){
47379 var num = this.parseValue(value);
47382 this.markInvalid(String.format(this.nanText, value));
47386 if(num < this.minValue){
47387 this.markInvalid(String.format(this.minText, this.minValue));
47391 if(num > this.maxValue){
47392 this.markInvalid(String.format(this.maxText, this.maxValue));
47399 validate : function()
47401 if(this.disabled || this.allowBlank){
47406 var currency = this.getCurrency();
47408 if(this.validateValue(this.getRawValue()) && currency.length){
47413 this.markInvalid();
47417 getName: function()
47422 beforeBlur : function()
47428 var v = this.parseValue(this.getRawValue());
47435 onBlur : function()
47439 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
47440 //this.el.removeClass(this.focusClass);
47443 this.hasFocus = false;
47445 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
47449 var v = this.getValue();
47451 if(String(v) !== String(this.startValue)){
47452 this.fireEvent('change', this, v, this.startValue);
47455 this.fireEvent("blur", this);
47458 inputEl : function()
47460 return this.el.select('.roo-money-amount-input', true).first();
47463 currencyEl : function()
47465 return this.el.select('.roo-money-currency-input', true).first();
47468 hiddenEl : function()
47470 return this.el.select('input.hidden-number-input',true).first();
47474 * @class Roo.bootstrap.BezierSignature
47475 * @extends Roo.bootstrap.Component
47476 * Bootstrap BezierSignature class
47477 * This script refer to:
47478 * Title: Signature Pad
47480 * Availability: https://github.com/szimek/signature_pad
47483 * Create a new BezierSignature
47484 * @param {Object} config The config object
47487 Roo.bootstrap.BezierSignature = function(config){
47488 Roo.bootstrap.BezierSignature.superclass.constructor.call(this, config);
47494 Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component,
47501 mouse_btn_down: true,
47504 * @cfg {int} canvas height
47506 canvas_height: '200px',
47509 * @cfg {float|function} Radius of a single dot.
47514 * @cfg {float} Minimum width of a line. Defaults to 0.5.
47519 * @cfg {float} Maximum width of a line. Defaults to 2.5.
47524 * @cfg {integer} Draw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling. Defaults to 16.
47529 * @cfg {integer} Add the next point only if the previous one is farther than x pixels. Defaults to 5.
47534 * @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.
47536 bg_color: 'rgba(0, 0, 0, 0)',
47539 * @cfg {string} Color used to draw the lines. Can be any color format accepted by context.fillStyle. Defaults to "black".
47541 dot_color: 'black',
47544 * @cfg {float} Weight used to modify new velocity based on the previous velocity. Defaults to 0.7.
47546 velocity_filter_weight: 0.7,
47549 * @cfg {function} Callback when stroke begin.
47554 * @cfg {function} Callback when stroke end.
47558 getAutoCreate : function()
47560 var cls = 'roo-signature column';
47563 cls += ' ' + this.cls;
47573 for(var i = 0; i < col_sizes.length; i++) {
47574 if(this[col_sizes[i]]) {
47575 cls += " col-"+col_sizes[i]+"-"+this[col_sizes[i]];
47585 cls: 'roo-signature-body',
47589 cls: 'roo-signature-body-canvas',
47590 height: this.canvas_height,
47591 width: this.canvas_width
47598 style: 'display: none'
47606 initEvents: function()
47608 Roo.bootstrap.BezierSignature.superclass.initEvents.call(this);
47610 var canvas = this.canvasEl();
47612 // mouse && touch event swapping...
47613 canvas.dom.style.touchAction = 'none';
47614 canvas.dom.style.msTouchAction = 'none';
47616 this.mouse_btn_down = false;
47617 canvas.on('mousedown', this._handleMouseDown, this);
47618 canvas.on('mousemove', this._handleMouseMove, this);
47619 Roo.select('html').first().on('mouseup', this._handleMouseUp, this);
47621 if (window.PointerEvent) {
47622 canvas.on('pointerdown', this._handleMouseDown, this);
47623 canvas.on('pointermove', this._handleMouseMove, this);
47624 Roo.select('html').first().on('pointerup', this._handleMouseUp, this);
47627 if ('ontouchstart' in window) {
47628 canvas.on('touchstart', this._handleTouchStart, this);
47629 canvas.on('touchmove', this._handleTouchMove, this);
47630 canvas.on('touchend', this._handleTouchEnd, this);
47633 Roo.EventManager.onWindowResize(this.resize, this, true);
47635 // file input event
47636 this.fileEl().on('change', this.uploadImage, this);
47643 resize: function(){
47645 var canvas = this.canvasEl().dom;
47646 var ctx = this.canvasElCtx();
47647 var img_data = false;
47649 if(canvas.width > 0) {
47650 var img_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
47652 // setting canvas width will clean img data
47655 var style = window.getComputedStyle ?
47656 getComputedStyle(this.el.dom, null) : this.el.dom.currentStyle;
47658 var padding_left = parseInt(style.paddingLeft) || 0;
47659 var padding_right = parseInt(style.paddingRight) || 0;
47661 canvas.width = this.el.dom.clientWidth - padding_left - padding_right;
47664 ctx.putImageData(img_data, 0, 0);
47668 _handleMouseDown: function(e)
47670 if (e.browserEvent.which === 1) {
47671 this.mouse_btn_down = true;
47672 this.strokeBegin(e);
47676 _handleMouseMove: function (e)
47678 if (this.mouse_btn_down) {
47679 this.strokeMoveUpdate(e);
47683 _handleMouseUp: function (e)
47685 if (e.browserEvent.which === 1 && this.mouse_btn_down) {
47686 this.mouse_btn_down = false;
47691 _handleTouchStart: function (e) {
47693 e.preventDefault();
47694 if (e.browserEvent.targetTouches.length === 1) {
47695 // var touch = e.browserEvent.changedTouches[0];
47696 // this.strokeBegin(touch);
47698 this.strokeBegin(e); // assume e catching the correct xy...
47702 _handleTouchMove: function (e) {
47703 e.preventDefault();
47704 // var touch = event.targetTouches[0];
47705 // _this._strokeMoveUpdate(touch);
47706 this.strokeMoveUpdate(e);
47709 _handleTouchEnd: function (e) {
47710 var wasCanvasTouched = e.target === this.canvasEl().dom;
47711 if (wasCanvasTouched) {
47712 e.preventDefault();
47713 // var touch = event.changedTouches[0];
47714 // _this._strokeEnd(touch);
47719 reset: function () {
47720 this._lastPoints = [];
47721 this._lastVelocity = 0;
47722 this._lastWidth = (this.min_width + this.max_width) / 2;
47723 this.canvasElCtx().fillStyle = this.dot_color;
47726 strokeMoveUpdate: function(e)
47728 this.strokeUpdate(e);
47730 if (this.throttle) {
47731 this.throttleStroke(this.strokeUpdate, this.throttle);
47734 this.strokeUpdate(e);
47738 strokeBegin: function(e)
47740 var newPointGroup = {
47741 color: this.dot_color,
47745 if (typeof this.onBegin === 'function') {
47749 this.curve_data.push(newPointGroup);
47751 this.strokeUpdate(e);
47754 strokeUpdate: function(e)
47756 var rect = this.canvasEl().dom.getBoundingClientRect();
47757 var point = new this.Point(e.xy[0] - rect.left, e.xy[1] - rect.top, new Date().getTime());
47758 var lastPointGroup = this.curve_data[this.curve_data.length - 1];
47759 var lastPoints = lastPointGroup.points;
47760 var lastPoint = lastPoints.length > 0 && lastPoints[lastPoints.length - 1];
47761 var isLastPointTooClose = lastPoint
47762 ? point.distanceTo(lastPoint) <= this.min_distance
47764 var color = lastPointGroup.color;
47765 if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
47766 var curve = this.addPoint(point);
47768 this.drawDot({color: color, point: point});
47771 this.drawCurve({color: color, curve: curve});
47781 strokeEnd: function(e)
47783 this.strokeUpdate(e);
47784 if (typeof this.onEnd === 'function') {
47789 addPoint: function (point) {
47790 var _lastPoints = this._lastPoints;
47791 _lastPoints.push(point);
47792 if (_lastPoints.length > 2) {
47793 if (_lastPoints.length === 3) {
47794 _lastPoints.unshift(_lastPoints[0]);
47796 var widths = this.calculateCurveWidths(_lastPoints[1], _lastPoints[2]);
47797 var curve = this.Bezier.fromPoints(_lastPoints, widths, this);
47798 _lastPoints.shift();
47804 calculateCurveWidths: function (startPoint, endPoint) {
47805 var velocity = this.velocity_filter_weight * endPoint.velocityFrom(startPoint) +
47806 (1 - this.velocity_filter_weight) * this._lastVelocity;
47808 var newWidth = Math.max(this.max_width / (velocity + 1), this.min_width);
47811 start: this._lastWidth
47814 this._lastVelocity = velocity;
47815 this._lastWidth = newWidth;
47819 drawDot: function (_a) {
47820 var color = _a.color, point = _a.point;
47821 var ctx = this.canvasElCtx();
47822 var width = typeof this.dot_size === 'function' ? this.dot_size() : this.dot_size;
47824 this.drawCurveSegment(point.x, point.y, width);
47826 ctx.fillStyle = color;
47830 drawCurve: function (_a) {
47831 var color = _a.color, curve = _a.curve;
47832 var ctx = this.canvasElCtx();
47833 var widthDelta = curve.endWidth - curve.startWidth;
47834 var drawSteps = Math.floor(curve.length()) * 2;
47836 ctx.fillStyle = color;
47837 for (var i = 0; i < drawSteps; i += 1) {
47838 var t = i / drawSteps;
47844 var x = uuu * curve.startPoint.x;
47845 x += 3 * uu * t * curve.control1.x;
47846 x += 3 * u * tt * curve.control2.x;
47847 x += ttt * curve.endPoint.x;
47848 var y = uuu * curve.startPoint.y;
47849 y += 3 * uu * t * curve.control1.y;
47850 y += 3 * u * tt * curve.control2.y;
47851 y += ttt * curve.endPoint.y;
47852 var width = curve.startWidth + ttt * widthDelta;
47853 this.drawCurveSegment(x, y, width);
47859 drawCurveSegment: function (x, y, width) {
47860 var ctx = this.canvasElCtx();
47862 ctx.arc(x, y, width, 0, 2 * Math.PI, false);
47863 this.is_empty = false;
47868 var ctx = this.canvasElCtx();
47869 var canvas = this.canvasEl().dom;
47870 ctx.fillStyle = this.bg_color;
47871 ctx.clearRect(0, 0, canvas.width, canvas.height);
47872 ctx.fillRect(0, 0, canvas.width, canvas.height);
47873 this.curve_data = [];
47875 this.is_empty = true;
47880 return this.el.select('input',true).first();
47883 canvasEl: function()
47885 return this.el.select('canvas',true).first();
47888 canvasElCtx: function()
47890 return this.el.select('canvas',true).first().dom.getContext('2d');
47893 getImage: function(type)
47895 if(this.is_empty) {
47900 return this.canvasEl().dom.toDataURL('image/'+type, 1);
47903 drawFromImage: function(img_src)
47905 var img = new Image();
47907 img.onload = function(){
47908 this.canvasElCtx().drawImage(img, 0, 0);
47913 this.is_empty = false;
47916 selectImage: function()
47918 this.fileEl().dom.click();
47921 uploadImage: function(e)
47923 var reader = new FileReader();
47925 reader.onload = function(e){
47926 var img = new Image();
47927 img.onload = function(){
47929 this.canvasElCtx().drawImage(img, 0, 0);
47931 img.src = e.target.result;
47934 reader.readAsDataURL(e.target.files[0]);
47937 // Bezier Point Constructor
47938 Point: (function () {
47939 function Point(x, y, time) {
47942 this.time = time || Date.now();
47944 Point.prototype.distanceTo = function (start) {
47945 return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
47947 Point.prototype.equals = function (other) {
47948 return this.x === other.x && this.y === other.y && this.time === other.time;
47950 Point.prototype.velocityFrom = function (start) {
47951 return this.time !== start.time
47952 ? this.distanceTo(start) / (this.time - start.time)
47959 // Bezier Constructor
47960 Bezier: (function () {
47961 function Bezier(startPoint, control2, control1, endPoint, startWidth, endWidth) {
47962 this.startPoint = startPoint;
47963 this.control2 = control2;
47964 this.control1 = control1;
47965 this.endPoint = endPoint;
47966 this.startWidth = startWidth;
47967 this.endWidth = endWidth;
47969 Bezier.fromPoints = function (points, widths, scope) {
47970 var c2 = this.calculateControlPoints(points[0], points[1], points[2], scope).c2;
47971 var c3 = this.calculateControlPoints(points[1], points[2], points[3], scope).c1;
47972 return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
47974 Bezier.calculateControlPoints = function (s1, s2, s3, scope) {
47975 var dx1 = s1.x - s2.x;
47976 var dy1 = s1.y - s2.y;
47977 var dx2 = s2.x - s3.x;
47978 var dy2 = s2.y - s3.y;
47979 var m1 = { x: (s1.x + s2.x) / 2.0, y: (s1.y + s2.y) / 2.0 };
47980 var m2 = { x: (s2.x + s3.x) / 2.0, y: (s2.y + s3.y) / 2.0 };
47981 var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
47982 var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
47983 var dxm = m1.x - m2.x;
47984 var dym = m1.y - m2.y;
47985 var k = l2 / (l1 + l2);
47986 var cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
47987 var tx = s2.x - cm.x;
47988 var ty = s2.y - cm.y;
47990 c1: new scope.Point(m1.x + tx, m1.y + ty),
47991 c2: new scope.Point(m2.x + tx, m2.y + ty)
47994 Bezier.prototype.length = function () {
47999 for (var i = 0; i <= steps; i += 1) {
48001 var cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
48002 var cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
48004 var xdiff = cx - px;
48005 var ydiff = cy - py;
48006 length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
48013 Bezier.prototype.point = function (t, start, c1, c2, end) {
48014 return (start * (1.0 - t) * (1.0 - t) * (1.0 - t))
48015 + (3.0 * c1 * (1.0 - t) * (1.0 - t) * t)
48016 + (3.0 * c2 * (1.0 - t) * t * t)
48017 + (end * t * t * t);
48022 throttleStroke: function(fn, wait) {
48023 if (wait === void 0) { wait = 250; }
48025 var timeout = null;
48029 var later = function () {
48030 previous = Date.now();
48032 result = fn.apply(storedContext, storedArgs);
48034 storedContext = null;
48038 return function wrapper() {
48040 for (var _i = 0; _i < arguments.length; _i++) {
48041 args[_i] = arguments[_i];
48043 var now = Date.now();
48044 var remaining = wait - (now - previous);
48045 storedContext = this;
48047 if (remaining <= 0 || remaining > wait) {
48049 clearTimeout(timeout);
48053 result = fn.apply(storedContext, storedArgs);
48055 storedContext = null;
48059 else if (!timeout) {
48060 timeout = window.setTimeout(later, remaining);
48070 // old names for form elements
48071 Roo.bootstrap.Form = Roo.bootstrap.form.Form;
48072 Roo.bootstrap.Input = Roo.bootstrap.form.Input;
48073 Roo.bootstrap.TextArea = Roo.bootstrap.form.TextArea;
48074 Roo.bootstrap.TriggerField = Roo.bootstrap.form.TriggerField;
48075 Roo.bootstrap.ComboBox = Roo.bootstrap.form.ComboBox;
48076 Roo.bootstrap.DateField = Roo.bootstrap.form.DateField;
48077 Roo.bootstrap.TimeField = Roo.bootstrap.form.TimeField;
48078 Roo.bootstrap.MonthField = Roo.bootstrap.form.MonthField;
48079 Roo.bootstrap.CheckBox = Roo.bootstrap.form.CheckBox;
48080 Roo.bootstrap.Radio = Roo.bootstrap.form.Radio;
48081 Roo.bootstrap.RadioSet = Roo.bootstrap.form.RadioSet;
48082 Roo.bootstrap.SecurePass = Roo.bootstrap.form.SecurePass;
48083 Roo.bootstrap.FieldLabel = Roo.bootstrap.form.FieldLabel;
48084 Roo.bootstrap.DateSplitField= Roo.bootstrap.form.DateSplitField;
48085 Roo.bootstrap.NumberField = Roo.bootstrap.form.NumberField;
48086 Roo.bootstrap.PhoneInput = Roo.bootstrap.form.PhoneInput;
48087 Roo.bootstrap.PhoneInputData= Roo.bootstrap.form.PhoneInputData;
48088 Roo.bootstrap.MoneyField = Roo.bootstrap.form.MoneyField;
48089 Roo.bootstrap.HtmlEditor = Roo.bootstrap.form.HtmlEditor;
48090 Roo.bootstrap.HtmlEditor.ToolbarStandard = Roo.bootstrap.form.HtmlEditorToolbarStandard;
48091 Roo.bootstrap.Markdown = Roo.bootstrap.form.Markdown;
48092 Roo.bootstrap.CardUploader = Roo.bootstrap.form.CardUploader;// depricated.
48093 Roo.bootstrap.Navbar = Roo.bootstrap.nav.Bar;
48094 Roo.bootstrap.NavGroup = Roo.bootstrap.nav.Group;
48095 Roo.bootstrap.NavHeaderbar = Roo.bootstrap.nav.Headerbar;
48096 Roo.bootstrap.NavItem = Roo.bootstrap.nav.Item;
48098 Roo.bootstrap.NavProgressBar = Roo.bootstrap.nav.ProgressBar;
48099 Roo.bootstrap.NavProgressBarItem = Roo.bootstrap.nav.ProgressBarItem;
48101 Roo.bootstrap.NavSidebar = Roo.bootstrap.nav.Sidebar;
48102 Roo.bootstrap.NavSidebarItem = Roo.bootstrap.nav.SidebarItem;
48104 Roo.bootstrap.NavSimplebar = Roo.bootstrap.nav.Simplebar;// deprciated
48105 Roo.bootstrap.Menu = Roo.bootstrap.menu.Menu;
48106 Roo.bootstrap.MenuItem = Roo.bootstrap.menu.Item;
48107 Roo.bootstrap.MenuSeparator = Roo.bootstrap.menu.Separator