cc9f54673648daea41139a6f96d4b8d3755dbddb
[roojs1] / roojs-bootstrap-debug.js
1 /**
2  * set the version of bootstrap based on the stylesheet...
3  *
4  */
5
6 Roo.bootstrap.version = (
7         function() {
8                 var ret=3;
9                 Roo.each(document.styleSheets[0], function(s) {
10                     if (s.href.match(/css-bootstrap4/)) {
11                         ret=4;
12                     }
13                 });
14         return ret;
15 })();/*
16  * - LGPL
17  *
18  * base class for bootstrap elements.
19  * 
20  */
21
22 Roo.bootstrap = Roo.bootstrap || {};
23 /**
24  * @class Roo.bootstrap.Component
25  * @extends Roo.Component
26  * Bootstrap Component base class
27  * @cfg {String} cls css class
28  * @cfg {String} style any extra css
29  * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.)
30  * @cfg {Boolean} can_build_overlaid  True if element can be rebuild from a HTML page
31  * @cfg {string} dataId cutomer id
32  * @cfg {string} name Specifies name attribute
33  * @cfg {string} tooltip  Text for the tooltip
34  * @cfg {string} container_method method to fetch parents container element (used by NavHeaderbar -  getHeaderChildContainer)
35  * @cfg {string|object} visibilityEl (el|parent) What element to use for visibility (@see getVisibilityEl())
36  
37  * @constructor
38  * Do not use directly - it does not do anything..
39  * @param {Object} config The config object
40  */
41
42
43
44 Roo.bootstrap.Component = function(config){
45     Roo.bootstrap.Component.superclass.constructor.call(this, config);
46        
47     this.addEvents({
48         /**
49          * @event childrenrendered
50          * Fires when the children have been rendered..
51          * @param {Roo.bootstrap.Component} this
52          */
53         "childrenrendered" : true
54         
55         
56         
57     });
58     
59     
60 };
61
62 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent,  {
63     
64     
65     allowDomMove : false, // to stop relocations in parent onRender...
66     
67     cls : false,
68     
69     style : false,
70     
71     autoCreate : false,
72     
73     tooltip : null,
74     /**
75      * Initialize Events for the element
76      */
77     initEvents : function() { },
78     
79     xattr : false,
80     
81     parentId : false,
82     
83     can_build_overlaid : true,
84     
85     container_method : false,
86     
87     dataId : false,
88     
89     name : false,
90     
91     parent: function() {
92         // returns the parent component..
93         return Roo.ComponentMgr.get(this.parentId)
94         
95         
96     },
97     
98     // private
99     onRender : function(ct, position)
100     {
101        // Roo.log("Call onRender: " + this.xtype);
102         
103         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
104         
105         if(this.el){
106             if (this.el.attr('xtype')) {
107                 this.el.attr('xtypex', this.el.attr('xtype'));
108                 this.el.dom.removeAttribute('xtype');
109                 
110                 this.initEvents();
111             }
112             
113             return;
114         }
115         
116          
117         
118         var cfg = Roo.apply({},  this.getAutoCreate());
119         
120         cfg.id = this.id || Roo.id();
121         
122         // fill in the extra attributes 
123         if (this.xattr && typeof(this.xattr) =='object') {
124             for (var i in this.xattr) {
125                 cfg[i] = this.xattr[i];
126             }
127         }
128         
129         if(this.dataId){
130             cfg.dataId = this.dataId;
131         }
132         
133         if (this.cls) {
134             cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
135         }
136         
137         if (this.style) { // fixme needs to support more complex style data.
138             cfg.style = this.style;
139         }
140         
141         if(this.name){
142             cfg.name = this.name;
143         }
144         
145         this.el = ct.createChild(cfg, position);
146         
147         if (this.tooltip) {
148             this.tooltipEl().attr('tooltip', this.tooltip);
149         }
150         
151         if(this.tabIndex !== undefined){
152             this.el.dom.setAttribute('tabIndex', this.tabIndex);
153         }
154         
155         this.initEvents();
156         
157     },
158     /**
159      * Fetch the element to add children to
160      * @return {Roo.Element} defaults to this.el
161      */
162     getChildContainer : function()
163     {
164         return this.el;
165     },
166     /**
167      * Fetch the element to display the tooltip on.
168      * @return {Roo.Element} defaults to this.el
169      */
170     tooltipEl : function()
171     {
172         return this.el;
173     },
174         
175     addxtype  : function(tree,cntr)
176     {
177         var cn = this;
178         
179         cn = Roo.factory(tree);
180         //Roo.log(['addxtype', cn]);
181            
182         cn.parentType = this.xtype; //??
183         cn.parentId = this.id;
184         
185         cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
186         if (typeof(cn.container_method) == 'string') {
187             cntr = cn.container_method;
188         }
189         
190         
191         var has_flexy_each =  (typeof(tree['flexy:foreach']) != 'undefined');
192         
193         var has_flexy_if =  (typeof(tree['flexy:if']) != 'undefined');
194         
195         var build_from_html =  Roo.XComponent.build_from_html;
196           
197         var is_body  = (tree.xtype == 'Body') ;
198           
199         var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
200           
201         var self_cntr_el = Roo.get(this[cntr](false));
202         
203         // do not try and build conditional elements 
204         if ((has_flexy_each || has_flexy_if || this.can_build_overlaid == false ) && build_from_html) {
205             return false;
206         }
207         
208         if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
209             if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
210                 return this.addxtypeChild(tree,cntr, is_body);
211             }
212             
213             var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
214                 
215             if(echild){
216                 return this.addxtypeChild(Roo.apply({}, tree),cntr);
217             }
218             
219             Roo.log('skipping render');
220             return cn;
221             
222         }
223         
224         var ret = false;
225         if (!build_from_html) {
226             return false;
227         }
228         
229         // this i think handles overlaying multiple children of the same type
230         // with the sam eelement.. - which might be buggy..
231         while (true) {
232             var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
233             
234             if (!echild) {
235                 break;
236             }
237             
238             if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
239                 break;
240             }
241             
242             ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
243         }
244        
245         return ret;
246     },
247     
248     
249     addxtypeChild : function (tree, cntr, is_body)
250     {
251         Roo.debug && Roo.log('addxtypeChild:' + cntr);
252         var cn = this;
253         cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
254         
255         
256         var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
257                     (typeof(tree['flexy:foreach']) != 'undefined');
258           
259     
260         
261         skip_children = false;
262         // render the element if it's not BODY.
263         if (!is_body) {
264             
265             // if parent was disabled, then do not try and create the children..
266             if(!this[cntr](true)){
267                 tree.items = [];
268                 return tree;
269             }
270            
271             cn = Roo.factory(tree);
272            
273             cn.parentType = this.xtype; //??
274             cn.parentId = this.id;
275             
276             var build_from_html =  Roo.XComponent.build_from_html;
277             
278             
279             // does the container contain child eleemnts with 'xtype' attributes.
280             // that match this xtype..
281             // note - when we render we create these as well..
282             // so we should check to see if body has xtype set.
283             if (build_from_html && Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
284                
285                 var self_cntr_el = Roo.get(this[cntr](false));
286                 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
287                 if (echild) { 
288                     //Roo.log(Roo.XComponent.build_from_html);
289                     //Roo.log("got echild:");
290                     //Roo.log(echild);
291                 }
292                 // there is a scenario where some of the child elements are flexy:if (and all of the same type)
293                 // and are not displayed -this causes this to use up the wrong element when matching.
294                 // at present the only work around for this is to nest flexy:if elements in another element that is always rendered.
295                 
296                 
297                 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
298                   //  Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
299                   
300                   
301                   
302                     cn.el = echild;
303                   //  Roo.log("GOT");
304                     //echild.dom.removeAttribute('xtype');
305                 } else {
306                     Roo.debug && Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
307                     Roo.debug && Roo.log(self_cntr_el);
308                     Roo.debug && Roo.log(echild);
309                     Roo.debug && Roo.log(cn);
310                 }
311             }
312            
313             
314            
315             // if object has flexy:if - then it may or may not be rendered.
316             if (build_from_html && has_flexy && !cn.el &&  cn.can_build_overlaid) {
317                 // skip a flexy if element.
318                 Roo.debug && Roo.log('skipping render');
319                 Roo.debug && Roo.log(tree);
320                 if (!cn.el) {
321                     Roo.debug && Roo.log('skipping all children');
322                     skip_children = true;
323                 }
324                 
325              } else {
326                  
327                 // actually if flexy:foreach is found, we really want to create 
328                 // multiple copies here...
329                 //Roo.log('render');
330                 //Roo.log(this[cntr]());
331                 // some elements do not have render methods.. like the layouts...
332                 /*
333                 if(this[cntr](true) === false){
334                     cn.items = [];
335                     return cn;
336                 }
337                 */
338                 cn.render && cn.render(this[cntr](true));
339                 
340              }
341             // then add the element..
342         }
343          
344         // handle the kids..
345         
346         var nitems = [];
347         /*
348         if (typeof (tree.menu) != 'undefined') {
349             tree.menu.parentType = cn.xtype;
350             tree.menu.triggerEl = cn.el;
351             nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
352             
353         }
354         */
355         if (!tree.items || !tree.items.length) {
356             cn.items = nitems;
357             //Roo.log(["no children", this]);
358             
359             return cn;
360         }
361          
362         var items = tree.items;
363         delete tree.items;
364         
365         //Roo.log(items.length);
366             // add the items..
367         if (!skip_children) {    
368             for(var i =0;i < items.length;i++) {
369               //  Roo.log(['add child', items[i]]);
370                 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
371             }
372         }
373         
374         cn.items = nitems;
375         
376         //Roo.log("fire childrenrendered");
377         
378         cn.fireEvent('childrenrendered', this);
379         
380         return cn;
381     },
382     
383     /**
384      * Set the element that will be used to show or hide
385      */
386     setVisibilityEl : function(el)
387     {
388         this.visibilityEl = el;
389     },
390     
391      /**
392      * Get the element that will be used to show or hide
393      */
394     getVisibilityEl : function()
395     {
396         if (typeof(this.visibilityEl) == 'object') {
397             return this.visibilityEl;
398         }
399         
400         if (typeof(this.visibilityEl) == 'string') {
401             return this.visibilityEl == 'parent' ? this.parent().getEl() : this.getEl();
402         }
403         
404         return this.getEl();
405     },
406     
407     /**
408      * Show a component - removes 'hidden' class
409      */
410     show : function()
411     {
412         if(!this.getVisibilityEl()){
413             return;
414         }
415          
416         this.getVisibilityEl().removeClass(['hidden','d-none']);
417         
418         this.fireEvent('show', this);
419         
420         
421     },
422     /**
423      * Hide a component - adds 'hidden' class
424      */
425     hide: function()
426     {
427         if(!this.getVisibilityEl()){
428             return;
429         }
430         
431         this.getVisibilityEl().addClass(['hidden','d-none']);
432         
433         this.fireEvent('hide', this);
434         
435     }
436 });
437
438  /*
439  * - LGPL
440  *
441  * Body
442  *
443  */
444
445 /**
446  * @class Roo.bootstrap.Body
447  * @extends Roo.bootstrap.Component
448  * Bootstrap Body class
449  *
450  * @constructor
451  * Create a new body
452  * @param {Object} config The config object
453  */
454
455 Roo.bootstrap.Body = function(config){
456
457     config = config || {};
458
459     Roo.bootstrap.Body.superclass.constructor.call(this, config);
460     this.el = Roo.get(config.el ? config.el : document.body );
461     if (this.cls && this.cls.length) {
462         Roo.get(document.body).addClass(this.cls);
463     }
464 };
465
466 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component,  {
467
468     is_body : true,// just to make sure it's constructed?
469
470         autoCreate : {
471         cls: 'container'
472     },
473     onRender : function(ct, position)
474     {
475        /* Roo.log("Roo.bootstrap.Body - onRender");
476         if (this.cls && this.cls.length) {
477             Roo.get(document.body).addClass(this.cls);
478         }
479         // style??? xttr???
480         */
481     }
482
483
484
485
486 });
487 /*
488  * - LGPL
489  *
490  * button group
491  * 
492  */
493
494
495 /**
496  * @class Roo.bootstrap.ButtonGroup
497  * @extends Roo.bootstrap.Component
498  * Bootstrap ButtonGroup class
499  * @cfg {String} size lg | sm | xs (default empty normal)
500  * @cfg {String} align vertical | justified  (default none)
501  * @cfg {String} direction up | down (default down)
502  * @cfg {Boolean} toolbar false | true
503  * @cfg {Boolean} btn true | false
504  * 
505  * 
506  * @constructor
507  * Create a new Input
508  * @param {Object} config The config object
509  */
510
511 Roo.bootstrap.ButtonGroup = function(config){
512     Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
513 };
514
515 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component,  {
516     
517     size: '',
518     align: '',
519     direction: '',
520     toolbar: false,
521     btn: true,
522
523     getAutoCreate : function(){
524         var cfg = {
525             cls: 'btn-group',
526             html : null
527         };
528         
529         cfg.html = this.html || cfg.html;
530         
531         if (this.toolbar) {
532             cfg = {
533                 cls: 'btn-toolbar',
534                 html: null
535             };
536             
537             return cfg;
538         }
539         
540         if (['vertical','justified'].indexOf(this.align)!==-1) {
541             cfg.cls = 'btn-group-' + this.align;
542             
543             if (this.align == 'justified') {
544                 console.log(this.items);
545             }
546         }
547         
548         if (['lg','sm','xs'].indexOf(this.size)!==-1) {
549             cfg.cls += ' btn-group-' + this.size;
550         }
551         
552         if (this.direction == 'up') {
553             cfg.cls += ' dropup' ;
554         }
555         
556         return cfg;
557     },
558     /**
559      * Add a button to the group (similar to NavItem API.)
560      */
561     addItem : function(cfg)
562     {
563         var cn = new Roo.bootstrap.Button(cfg);
564         //this.register(cn);
565         cn.parentId = this.id;
566         cn.onRender(this.el, null);
567         return cn;
568     }
569    
570 });
571
572  /*
573  * - LGPL
574  *
575  * button
576  * 
577  */
578
579 /**
580  * @class Roo.bootstrap.Button
581  * @extends Roo.bootstrap.Component
582  * Bootstrap Button class
583  * @cfg {String} html The button content
584  * @cfg {String} weight (default | primary | secondary | success | info | warning | danger | link ) default
585  * @cfg {String} badge_weight (default | primary | secondary | success | info | warning | danger | link ) default (same as button)
586  * @cfg {Boolean} outline default false (except for weight=default which emulates old behaveiour with an outline)
587  * @cfg {String} size ( lg | sm | xs)
588  * @cfg {String} tag ( a | input | submit)
589  * @cfg {String} href empty or href
590  * @cfg {Boolean} disabled default false;
591  * @cfg {Boolean} isClose default false;
592  * @cfg {String} glyphicon depricated - use fa
593  * @cfg {String} fa fontawesome icon - eg. 'comment' - without the fa/fas etc..
594  * @cfg {String} badge text for badge
595  * @cfg {String} theme (default|glow)  
596  * @cfg {Boolean} inverse dark themed version
597  * @cfg {Boolean} toggle is it a slidy toggle button
598  * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
599  * @cfg {String} ontext text for on slidy toggle state
600  * @cfg {String} offtext text for off slidy toggle state
601  * @cfg {Boolean} preventDefault  default true (stop click event triggering the URL if it's a link.)
602  * @cfg {Boolean} removeClass remove the standard class..
603  * @cfg {String} target  target for a href. (_self|_blank|_parent|_top| other)
604  * 
605  * @constructor
606  * Create a new button
607  * @param {Object} config The config object
608  */
609
610
611 Roo.bootstrap.Button = function(config){
612     Roo.bootstrap.Button.superclass.constructor.call(this, config);
613     this.weightClass = ["btn-default btn-outline-secondary", 
614                        "btn-primary", 
615                        "btn-success", 
616                        "btn-info", 
617                        "btn-warning",
618                        "btn-danger",
619                        "btn-link"
620                       ],  
621     this.addEvents({
622         // raw events
623         /**
624          * @event click
625          * When a butotn is pressed
626          * @param {Roo.bootstrap.Button} btn
627          * @param {Roo.EventObject} e
628          */
629         "click" : true,
630          /**
631          * @event toggle
632          * After the button has been toggles
633          * @param {Roo.bootstrap.Button} btn
634          * @param {Roo.EventObject} e
635          * @param {boolean} pressed (also available as button.pressed)
636          */
637         "toggle" : true
638     });
639 };
640
641 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component,  {
642     html: false,
643     active: false,
644     weight: '',
645     badge_weight: '',
646     outline : false,
647     size: '',
648     tag: 'button',
649     href: '',
650     disabled: false,
651     isClose: false,
652     glyphicon: '',
653     fa: '',
654     badge: '',
655     theme: 'default',
656     inverse: false,
657     
658     toggle: false,
659     ontext: 'ON',
660     offtext: 'OFF',
661     defaulton: true,
662     preventDefault: true,
663     removeClass: false,
664     name: false,
665     target: false,
666      
667     pressed : null,
668      
669     
670     getAutoCreate : function(){
671         
672         var cfg = {
673             tag : 'button',
674             cls : 'roo-button',
675             html: ''
676         };
677         
678         if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
679             throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
680             this.tag = 'button';
681         } else {
682             cfg.tag = this.tag;
683         }
684         cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
685         
686         if (this.toggle == true) {
687             cfg={
688                 tag: 'div',
689                 cls: 'slider-frame roo-button',
690                 cn: [
691                     {
692                         tag: 'span',
693                         'data-on-text':'ON',
694                         'data-off-text':'OFF',
695                         cls: 'slider-button',
696                         html: this.offtext
697                     }
698                 ]
699             };
700             
701             if (['default', 'secondary' , 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
702                 cfg.cls += ' '+this.weight;
703             }
704             
705             return cfg;
706         }
707         
708         if (this.isClose) {
709             cfg.cls += ' close';
710             
711             cfg["aria-hidden"] = true;
712             
713             cfg.html = "&times;";
714             
715             return cfg;
716         }
717         
718          
719         if (this.theme==='default') {
720             cfg.cls = 'btn roo-button';
721             
722             //if (this.parentType != 'Navbar') {
723             this.weight = this.weight.length ?  this.weight : 'default';
724             //}
725             if (['default', 'primary', 'secondary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
726                 
727                 var outline = this.outline || this.weight == 'default' ? 'outline-' : '';
728                 var weight = this.weight == 'default' ? 'secondary' : this.weight;
729                 cfg.cls += ' btn-' + outline + weight;
730                 if (this.weight == 'default') {
731                     // BC
732                     cfg.cls += ' btn-' + this.weight;
733                 }
734             }
735         } else if (this.theme==='glow') {
736             
737             cfg.tag = 'a';
738             cfg.cls = 'btn-glow roo-button';
739             
740             if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
741                 
742                 cfg.cls += ' ' + this.weight;
743             }
744         }
745    
746         
747         if (this.inverse) {
748             this.cls += ' inverse';
749         }
750         
751         
752         if (this.active || this.pressed === true) {
753             cfg.cls += ' active';
754         }
755         
756         if (this.disabled) {
757             cfg.disabled = 'disabled';
758         }
759         
760         if (this.items) {
761             Roo.log('changing to ul' );
762             cfg.tag = 'ul';
763             this.glyphicon = 'caret';
764             if (Roo.bootstrap.version == 4) {
765                 this.fa = 'caret-down';
766             }
767             
768         }
769         
770         cfg.cls += this.size.length ? (' btn-' + this.size) : '';
771          
772         //gsRoo.log(this.parentType);
773         if (this.parentType === 'Navbar' && !this.parent().bar) {
774             Roo.log('changing to li?');
775             
776             cfg.tag = 'li';
777             
778             cfg.cls = '';
779             cfg.cn =  [{
780                 tag : 'a',
781                 cls : 'roo-button',
782                 html : this.html,
783                 href : this.href || '#'
784             }];
785             if (this.menu) {
786                 cfg.cn[0].html = this.html  + ' <span class="caret"></span>';
787                 cfg.cls += ' dropdown';
788             }   
789             
790             delete cfg.html;
791             
792         }
793         
794        cfg.cls += this.parentType === 'Navbar' ?  ' navbar-btn' : '';
795         
796         if (this.glyphicon) {
797             cfg.html = ' ' + cfg.html;
798             
799             cfg.cn = [
800                 {
801                     tag: 'span',
802                     cls: 'glyphicon glyphicon-' + this.glyphicon
803                 }
804             ];
805         }
806         if (this.fa) {
807             cfg.html = ' ' + cfg.html;
808             
809             cfg.cn = [
810                 {
811                     tag: 'i',
812                     cls: 'fa fas fa-' + this.fa
813                 }
814             ];
815         }
816         
817         if (this.badge) {
818             cfg.html += ' ';
819             
820             cfg.tag = 'a';
821             
822 //            cfg.cls='btn roo-button';
823             
824             cfg.href=this.href;
825             
826             var value = cfg.html;
827             
828             if(this.glyphicon){
829                 value = {
830                     tag: 'span',
831                     cls: 'glyphicon glyphicon-' + this.glyphicon,
832                     html: this.html
833                 };
834             }
835             if(this.fa){
836                 value = {
837                     tag: 'i',
838                     cls: 'fa fas fa-' + this.fa,
839                     html: this.html
840                 };
841             }
842             
843             var bw = this.badge_weight.length ? this.badge_weight :
844                 (this.weight.length ? this.weight : 'secondary');
845             bw = bw == 'default' ? 'secondary' : bw;
846             
847             cfg.cn = [
848                 value,
849                 {
850                     tag: 'span',
851                     cls: 'badge badge-' + bw,
852                     html: this.badge
853                 }
854             ];
855             
856             cfg.html='';
857         }
858         
859         if (this.menu) {
860             cfg.cls += ' dropdown';
861             cfg.html = typeof(cfg.html) != 'undefined' ?
862                     cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
863         }
864         
865         if (cfg.tag !== 'a' && this.href !== '') {
866             throw "Tag must be a to set href.";
867         } else if (this.href.length > 0) {
868             cfg.href = this.href;
869         }
870         
871         if(this.removeClass){
872             cfg.cls = '';
873         }
874         
875         if(this.target){
876             cfg.target = this.target;
877         }
878         
879         return cfg;
880     },
881     initEvents: function() {
882        // Roo.log('init events?');
883 //        Roo.log(this.el.dom);
884         // add the menu...
885         
886         if (typeof (this.menu) != 'undefined') {
887             this.menu.parentType = this.xtype;
888             this.menu.triggerEl = this.el;
889             this.addxtype(Roo.apply({}, this.menu));
890         }
891
892
893        if (this.el.hasClass('roo-button')) {
894             this.el.on('click', this.onClick, this);
895        } else {
896             this.el.select('.roo-button').on('click', this.onClick, this);
897        }
898        
899        if(this.removeClass){
900            this.el.on('click', this.onClick, this);
901        }
902        
903        this.el.enableDisplayMode();
904         
905     },
906     onClick : function(e)
907     {
908         if (this.disabled) {
909             return;
910         }
911         
912         Roo.log('button on click ');
913         if(this.preventDefault){
914             e.preventDefault();
915         }
916         
917         if (this.pressed === true || this.pressed === false) {
918             this.toggleActive(e);
919         }
920         
921         
922         this.fireEvent('click', this, e);
923     },
924     
925     /**
926      * Enables this button
927      */
928     enable : function()
929     {
930         this.disabled = false;
931         this.el.removeClass('disabled');
932     },
933     
934     /**
935      * Disable this button
936      */
937     disable : function()
938     {
939         this.disabled = true;
940         this.el.addClass('disabled');
941     },
942      /**
943      * sets the active state on/off, 
944      * @param {Boolean} state (optional) Force a particular state
945      */
946     setActive : function(v) {
947         
948         this.el[v ? 'addClass' : 'removeClass']('active');
949         this.pressed = v;
950     },
951      /**
952      * toggles the current active state 
953      */
954     toggleActive : function(e)
955     {
956         this.setActive(!this.pressed);
957         this.fireEvent('toggle', this, e, !this.pressed);
958     },
959      /**
960      * get the current active state
961      * @return {boolean} true if it's active
962      */
963     isActive : function()
964     {
965         return this.el.hasClass('active');
966     },
967     /**
968      * set the text of the first selected button
969      */
970     setText : function(str)
971     {
972         this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
973     },
974     /**
975      * get the text of the first selected button
976      */
977     getText : function()
978     {
979         return this.el.select('.roo-button-text',true).first().dom.innerHTML;
980     },
981     
982     setWeight : function(str)
983     {
984         this.el.removeClass(this.weightClass);
985         this.weight = str;
986         var outline = this.outline ? 'outline-' : '';
987         if (str == 'default') {
988             this.el.addClass('btn-default btn-outline-secondary');        
989             return;
990         }
991         this.el.addClass('btn-' + outline + str);        
992     }
993     
994     
995 });
996
997  /*
998  * - LGPL
999  *
1000  * column
1001  * 
1002  */
1003
1004 /**
1005  * @class Roo.bootstrap.Column
1006  * @extends Roo.bootstrap.Component
1007  * Bootstrap Column class
1008  * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
1009  * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
1010  * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
1011  * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
1012  * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
1013  * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
1014  * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
1015  * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
1016  *
1017  * 
1018  * @cfg {Boolean} hidden (true|false) hide the element
1019  * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1020  * @cfg {String} fa (ban|check|...) font awesome icon
1021  * @cfg {Number} fasize (1|2|....) font awsome size
1022
1023  * @cfg {String} icon (info-sign|check|...) glyphicon name
1024
1025  * @cfg {String} html content of column.
1026  * 
1027  * @constructor
1028  * Create a new Column
1029  * @param {Object} config The config object
1030  */
1031
1032 Roo.bootstrap.Column = function(config){
1033     Roo.bootstrap.Column.superclass.constructor.call(this, config);
1034 };
1035
1036 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component,  {
1037     
1038     xs: false,
1039     sm: false,
1040     md: false,
1041     lg: false,
1042     xsoff: false,
1043     smoff: false,
1044     mdoff: false,
1045     lgoff: false,
1046     html: '',
1047     offset: 0,
1048     alert: false,
1049     fa: false,
1050     icon : false,
1051     hidden : false,
1052     fasize : 1,
1053     
1054     getAutoCreate : function(){
1055         var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
1056         
1057         cfg = {
1058             tag: 'div',
1059             cls: 'column'
1060         };
1061         
1062         var settings=this;
1063         ['xs','sm','md','lg'].map(function(size){
1064             //Roo.log( size + ':' + settings[size]);
1065             
1066             if (settings[size+'off'] !== false) {
1067                 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1068             }
1069             
1070             if (settings[size] === false) {
1071                 return;
1072             }
1073             
1074             if (!settings[size]) { // 0 = hidden
1075                 cfg.cls += ' hidden-' + size;
1076                 return;
1077             }
1078             cfg.cls += ' col-' + size + '-' + settings[size];
1079             
1080         });
1081         
1082         if (this.hidden) {
1083             cfg.cls += ' hidden';
1084         }
1085         
1086         if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1087             cfg.cls +=' alert alert-' + this.alert;
1088         }
1089         
1090         
1091         if (this.html.length) {
1092             cfg.html = this.html;
1093         }
1094         if (this.fa) {
1095             var fasize = '';
1096             if (this.fasize > 1) {
1097                 fasize = ' fa-' + this.fasize + 'x';
1098             }
1099             cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1100             
1101             
1102         }
1103         if (this.icon) {
1104             cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' +  (cfg.html || '');
1105         }
1106         
1107         return cfg;
1108     }
1109    
1110 });
1111
1112  
1113
1114  /*
1115  * - LGPL
1116  *
1117  * page container.
1118  * 
1119  */
1120
1121
1122 /**
1123  * @class Roo.bootstrap.Container
1124  * @extends Roo.bootstrap.Component
1125  * Bootstrap Container class
1126  * @cfg {Boolean} jumbotron is it a jumbotron element
1127  * @cfg {String} html content of element
1128  * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1129  * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel  - type - primary/success.....
1130  * @cfg {String} header content of header (for panel)
1131  * @cfg {String} footer content of footer (for panel)
1132  * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1133  * @cfg {String} tag (header|aside|section) type of HTML tag.
1134  * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1135  * @cfg {String} fa font awesome icon
1136  * @cfg {String} icon (info-sign|check|...) glyphicon name
1137  * @cfg {Boolean} hidden (true|false) hide the element
1138  * @cfg {Boolean} expandable (true|false) default false
1139  * @cfg {Boolean} expanded (true|false) default true
1140  * @cfg {String} rheader contet on the right of header
1141  * @cfg {Boolean} clickable (true|false) default false
1142
1143  *     
1144  * @constructor
1145  * Create a new Container
1146  * @param {Object} config The config object
1147  */
1148
1149 Roo.bootstrap.Container = function(config){
1150     Roo.bootstrap.Container.superclass.constructor.call(this, config);
1151     
1152     this.addEvents({
1153         // raw events
1154          /**
1155          * @event expand
1156          * After the panel has been expand
1157          * 
1158          * @param {Roo.bootstrap.Container} this
1159          */
1160         "expand" : true,
1161         /**
1162          * @event collapse
1163          * After the panel has been collapsed
1164          * 
1165          * @param {Roo.bootstrap.Container} this
1166          */
1167         "collapse" : true,
1168         /**
1169          * @event click
1170          * When a element is chick
1171          * @param {Roo.bootstrap.Container} this
1172          * @param {Roo.EventObject} e
1173          */
1174         "click" : true
1175     });
1176 };
1177
1178 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component,  {
1179     
1180     jumbotron : false,
1181     well: '',
1182     panel : '',
1183     header: '',
1184     footer : '',
1185     sticky: '',
1186     tag : false,
1187     alert : false,
1188     fa: false,
1189     icon : false,
1190     expandable : false,
1191     rheader : '',
1192     expanded : true,
1193     clickable: false,
1194   
1195      
1196     getChildContainer : function() {
1197         
1198         if(!this.el){
1199             return false;
1200         }
1201         
1202         if (this.panel.length) {
1203             return this.el.select('.panel-body',true).first();
1204         }
1205         
1206         return this.el;
1207     },
1208     
1209     
1210     getAutoCreate : function(){
1211         
1212         var cfg = {
1213             tag : this.tag || 'div',
1214             html : '',
1215             cls : ''
1216         };
1217         if (this.jumbotron) {
1218             cfg.cls = 'jumbotron';
1219         }
1220         
1221         
1222         
1223         // - this is applied by the parent..
1224         //if (this.cls) {
1225         //    cfg.cls = this.cls + '';
1226         //}
1227         
1228         if (this.sticky.length) {
1229             
1230             var bd = Roo.get(document.body);
1231             if (!bd.hasClass('bootstrap-sticky')) {
1232                 bd.addClass('bootstrap-sticky');
1233                 Roo.select('html',true).setStyle('height', '100%');
1234             }
1235              
1236             cfg.cls += 'bootstrap-sticky-' + this.sticky;
1237         }
1238         
1239         
1240         if (this.well.length) {
1241             switch (this.well) {
1242                 case 'lg':
1243                 case 'sm':
1244                     cfg.cls +=' well well-' +this.well;
1245                     break;
1246                 default:
1247                     cfg.cls +=' well';
1248                     break;
1249             }
1250         }
1251         
1252         if (this.hidden) {
1253             cfg.cls += ' hidden';
1254         }
1255         
1256         
1257         if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1258             cfg.cls +=' alert alert-' + this.alert;
1259         }
1260         
1261         var body = cfg;
1262         
1263         if (this.panel.length) {
1264             cfg.cls += ' panel panel-' + this.panel;
1265             cfg.cn = [];
1266             if (this.header.length) {
1267                 
1268                 var h = [];
1269                 
1270                 if(this.expandable){
1271                     
1272                     cfg.cls = cfg.cls + ' expandable';
1273                     
1274                     h.push({
1275                         tag: 'i',
1276                         cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus') 
1277                     });
1278                     
1279                 }
1280                 
1281                 h.push(
1282                     {
1283                         tag: 'span',
1284                         cls : 'panel-title',
1285                         html : (this.expandable ? '&nbsp;' : '') + this.header
1286                     },
1287                     {
1288                         tag: 'span',
1289                         cls: 'panel-header-right',
1290                         html: this.rheader
1291                     }
1292                 );
1293                 
1294                 cfg.cn.push({
1295                     cls : 'panel-heading',
1296                     style : this.expandable ? 'cursor: pointer' : '',
1297                     cn : h
1298                 });
1299                 
1300             }
1301             
1302             body = false;
1303             cfg.cn.push({
1304                 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1305                 html : this.html
1306             });
1307             
1308             
1309             if (this.footer.length) {
1310                 cfg.cn.push({
1311                     cls : 'panel-footer',
1312                     html : this.footer
1313                     
1314                 });
1315             }
1316             
1317         }
1318         
1319         if (body) {
1320             body.html = this.html || cfg.html;
1321             // prefix with the icons..
1322             if (this.fa) {
1323                 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1324             }
1325             if (this.icon) {
1326                 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1327             }
1328             
1329             
1330         }
1331         if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1332             cfg.cls =  'container';
1333         }
1334         
1335         return cfg;
1336     },
1337     
1338     initEvents: function() 
1339     {
1340         if(this.expandable){
1341             var headerEl = this.headerEl();
1342         
1343             if(headerEl){
1344                 headerEl.on('click', this.onToggleClick, this);
1345             }
1346         }
1347         
1348         if(this.clickable){
1349             this.el.on('click', this.onClick, this);
1350         }
1351         
1352     },
1353     
1354     onToggleClick : function()
1355     {
1356         var headerEl = this.headerEl();
1357         
1358         if(!headerEl){
1359             return;
1360         }
1361         
1362         if(this.expanded){
1363             this.collapse();
1364             return;
1365         }
1366         
1367         this.expand();
1368     },
1369     
1370     expand : function()
1371     {
1372         if(this.fireEvent('expand', this)) {
1373             
1374             this.expanded = true;
1375             
1376             //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1377             
1378             this.el.select('.panel-body',true).first().removeClass('hide');
1379             
1380             var toggleEl = this.toggleEl();
1381
1382             if(!toggleEl){
1383                 return;
1384             }
1385
1386             toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1387         }
1388         
1389     },
1390     
1391     collapse : function()
1392     {
1393         if(this.fireEvent('collapse', this)) {
1394             
1395             this.expanded = false;
1396             
1397             //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1398             this.el.select('.panel-body',true).first().addClass('hide');
1399         
1400             var toggleEl = this.toggleEl();
1401
1402             if(!toggleEl){
1403                 return;
1404             }
1405
1406             toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1407         }
1408     },
1409     
1410     toggleEl : function()
1411     {
1412         if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1413             return;
1414         }
1415         
1416         return this.el.select('.panel-heading .fa',true).first();
1417     },
1418     
1419     headerEl : function()
1420     {
1421         if(!this.el || !this.panel.length || !this.header.length){
1422             return;
1423         }
1424         
1425         return this.el.select('.panel-heading',true).first()
1426     },
1427     
1428     bodyEl : function()
1429     {
1430         if(!this.el || !this.panel.length){
1431             return;
1432         }
1433         
1434         return this.el.select('.panel-body',true).first()
1435     },
1436     
1437     titleEl : function()
1438     {
1439         if(!this.el || !this.panel.length || !this.header.length){
1440             return;
1441         }
1442         
1443         return this.el.select('.panel-title',true).first();
1444     },
1445     
1446     setTitle : function(v)
1447     {
1448         var titleEl = this.titleEl();
1449         
1450         if(!titleEl){
1451             return;
1452         }
1453         
1454         titleEl.dom.innerHTML = v;
1455     },
1456     
1457     getTitle : function()
1458     {
1459         
1460         var titleEl = this.titleEl();
1461         
1462         if(!titleEl){
1463             return '';
1464         }
1465         
1466         return titleEl.dom.innerHTML;
1467     },
1468     
1469     setRightTitle : function(v)
1470     {
1471         var t = this.el.select('.panel-header-right',true).first();
1472         
1473         if(!t){
1474             return;
1475         }
1476         
1477         t.dom.innerHTML = v;
1478     },
1479     
1480     onClick : function(e)
1481     {
1482         e.preventDefault();
1483         
1484         this.fireEvent('click', this, e);
1485     }
1486 });
1487
1488  /*
1489  * - LGPL
1490  *
1491  * image
1492  * 
1493  */
1494
1495
1496 /**
1497  * @class Roo.bootstrap.Img
1498  * @extends Roo.bootstrap.Component
1499  * Bootstrap Img class
1500  * @cfg {Boolean} imgResponsive false | true
1501  * @cfg {String} border rounded | circle | thumbnail
1502  * @cfg {String} src image source
1503  * @cfg {String} alt image alternative text
1504  * @cfg {String} href a tag href
1505  * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1506  * @cfg {String} xsUrl xs image source
1507  * @cfg {String} smUrl sm image source
1508  * @cfg {String} mdUrl md image source
1509  * @cfg {String} lgUrl lg image source
1510  * 
1511  * @constructor
1512  * Create a new Input
1513  * @param {Object} config The config object
1514  */
1515
1516 Roo.bootstrap.Img = function(config){
1517     Roo.bootstrap.Img.superclass.constructor.call(this, config);
1518     
1519     this.addEvents({
1520         // img events
1521         /**
1522          * @event click
1523          * The img click event for the img.
1524          * @param {Roo.EventObject} e
1525          */
1526         "click" : true
1527     });
1528 };
1529
1530 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
1531     
1532     imgResponsive: true,
1533     border: '',
1534     src: 'about:blank',
1535     href: false,
1536     target: false,
1537     xsUrl: '',
1538     smUrl: '',
1539     mdUrl: '',
1540     lgUrl: '',
1541
1542     getAutoCreate : function()
1543     {   
1544         if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1545             return this.createSingleImg();
1546         }
1547         
1548         var cfg = {
1549             tag: 'div',
1550             cls: 'roo-image-responsive-group',
1551             cn: []
1552         };
1553         var _this = this;
1554         
1555         Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1556             
1557             if(!_this[size + 'Url']){
1558                 return;
1559             }
1560             
1561             var img = {
1562                 tag: 'img',
1563                 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1564                 html: _this.html || cfg.html,
1565                 src: _this[size + 'Url']
1566             };
1567             
1568             img.cls += ' roo-image-responsive-' + size;
1569             
1570             var s = ['xs', 'sm', 'md', 'lg'];
1571             
1572             s.splice(s.indexOf(size), 1);
1573             
1574             Roo.each(s, function(ss){
1575                 img.cls += ' hidden-' + ss;
1576             });
1577             
1578             if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1579                 cfg.cls += ' img-' + _this.border;
1580             }
1581             
1582             if(_this.alt){
1583                 cfg.alt = _this.alt;
1584             }
1585             
1586             if(_this.href){
1587                 var a = {
1588                     tag: 'a',
1589                     href: _this.href,
1590                     cn: [
1591                         img
1592                     ]
1593                 };
1594
1595                 if(this.target){
1596                     a.target = _this.target;
1597                 }
1598             }
1599             
1600             cfg.cn.push((_this.href) ? a : img);
1601             
1602         });
1603         
1604         return cfg;
1605     },
1606     
1607     createSingleImg : function()
1608     {
1609         var cfg = {
1610             tag: 'img',
1611             cls: (this.imgResponsive) ? 'img-responsive' : '',
1612             html : null,
1613             src : 'about:blank'  // just incase src get's set to undefined?!?
1614         };
1615         
1616         cfg.html = this.html || cfg.html;
1617         
1618         cfg.src = this.src || cfg.src;
1619         
1620         if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1621             cfg.cls += ' img-' + this.border;
1622         }
1623         
1624         if(this.alt){
1625             cfg.alt = this.alt;
1626         }
1627         
1628         if(this.href){
1629             var a = {
1630                 tag: 'a',
1631                 href: this.href,
1632                 cn: [
1633                     cfg
1634                 ]
1635             };
1636             
1637             if(this.target){
1638                 a.target = this.target;
1639             }
1640             
1641         }
1642         
1643         return (this.href) ? a : cfg;
1644     },
1645     
1646     initEvents: function() 
1647     {
1648         if(!this.href){
1649             this.el.on('click', this.onClick, this);
1650         }
1651         
1652     },
1653     
1654     onClick : function(e)
1655     {
1656         Roo.log('img onclick');
1657         this.fireEvent('click', this, e);
1658     },
1659     /**
1660      * Sets the url of the image - used to update it
1661      * @param {String} url the url of the image
1662      */
1663     
1664     setSrc : function(url)
1665     {
1666         this.src =  url;
1667         
1668         if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1669             this.el.dom.src =  url;
1670             return;
1671         }
1672         
1673         this.el.select('img', true).first().dom.src =  url;
1674     }
1675     
1676     
1677    
1678 });
1679
1680  /*
1681  * - LGPL
1682  *
1683  * image
1684  * 
1685  */
1686
1687
1688 /**
1689  * @class Roo.bootstrap.Link
1690  * @extends Roo.bootstrap.Component
1691  * Bootstrap Link Class
1692  * @cfg {String} alt image alternative text
1693  * @cfg {String} href a tag href
1694  * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1695  * @cfg {String} html the content of the link.
1696  * @cfg {String} anchor name for the anchor link
1697  * @cfg {String} fa - favicon
1698
1699  * @cfg {Boolean} preventDefault (true | false) default false
1700
1701  * 
1702  * @constructor
1703  * Create a new Input
1704  * @param {Object} config The config object
1705  */
1706
1707 Roo.bootstrap.Link = function(config){
1708     Roo.bootstrap.Link.superclass.constructor.call(this, config);
1709     
1710     this.addEvents({
1711         // img events
1712         /**
1713          * @event click
1714          * The img click event for the img.
1715          * @param {Roo.EventObject} e
1716          */
1717         "click" : true
1718     });
1719 };
1720
1721 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component,  {
1722     
1723     href: false,
1724     target: false,
1725     preventDefault: false,
1726     anchor : false,
1727     alt : false,
1728     fa: false,
1729
1730
1731     getAutoCreate : function()
1732     {
1733         var html = this.html || '';
1734         
1735         if (this.fa !== false) {
1736             html = '<i class="fa fa-' + this.fa + '"></i>';
1737         }
1738         var cfg = {
1739             tag: 'a'
1740         };
1741         // anchor's do not require html/href...
1742         if (this.anchor === false) {
1743             cfg.html = html;
1744             cfg.href = this.href || '#';
1745         } else {
1746             cfg.name = this.anchor;
1747             if (this.html !== false || this.fa !== false) {
1748                 cfg.html = html;
1749             }
1750             if (this.href !== false) {
1751                 cfg.href = this.href;
1752             }
1753         }
1754         
1755         if(this.alt !== false){
1756             cfg.alt = this.alt;
1757         }
1758         
1759         
1760         if(this.target !== false) {
1761             cfg.target = this.target;
1762         }
1763         
1764         return cfg;
1765     },
1766     
1767     initEvents: function() {
1768         
1769         if(!this.href || this.preventDefault){
1770             this.el.on('click', this.onClick, this);
1771         }
1772     },
1773     
1774     onClick : function(e)
1775     {
1776         if(this.preventDefault){
1777             e.preventDefault();
1778         }
1779         //Roo.log('img onclick');
1780         this.fireEvent('click', this, e);
1781     }
1782    
1783 });
1784
1785  /*
1786  * - LGPL
1787  *
1788  * header
1789  * 
1790  */
1791
1792 /**
1793  * @class Roo.bootstrap.Header
1794  * @extends Roo.bootstrap.Component
1795  * Bootstrap Header class
1796  * @cfg {String} html content of header
1797  * @cfg {Number} level (1|2|3|4|5|6) default 1
1798  * 
1799  * @constructor
1800  * Create a new Header
1801  * @param {Object} config The config object
1802  */
1803
1804
1805 Roo.bootstrap.Header  = function(config){
1806     Roo.bootstrap.Header.superclass.constructor.call(this, config);
1807 };
1808
1809 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component,  {
1810     
1811     //href : false,
1812     html : false,
1813     level : 1,
1814     
1815     
1816     
1817     getAutoCreate : function(){
1818         
1819         
1820         
1821         var cfg = {
1822             tag: 'h' + (1 *this.level),
1823             html: this.html || ''
1824         } ;
1825         
1826         return cfg;
1827     }
1828    
1829 });
1830
1831  
1832
1833  /*
1834  * Based on:
1835  * Ext JS Library 1.1.1
1836  * Copyright(c) 2006-2007, Ext JS, LLC.
1837  *
1838  * Originally Released Under LGPL - original licence link has changed is not relivant.
1839  *
1840  * Fork - LGPL
1841  * <script type="text/javascript">
1842  */
1843  
1844 /**
1845  * @class Roo.bootstrap.MenuMgr
1846  * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1847  * @singleton
1848  */
1849 Roo.bootstrap.MenuMgr = function(){
1850    var menus, active, groups = {}, attached = false, lastShow = new Date();
1851
1852    // private - called when first menu is created
1853    function init(){
1854        menus = {};
1855        active = new Roo.util.MixedCollection();
1856        Roo.get(document).addKeyListener(27, function(){
1857            if(active.length > 0){
1858                hideAll();
1859            }
1860        });
1861    }
1862
1863    // private
1864    function hideAll(){
1865        if(active && active.length > 0){
1866            var c = active.clone();
1867            c.each(function(m){
1868                m.hide();
1869            });
1870        }
1871    }
1872
1873    // private
1874    function onHide(m){
1875        active.remove(m);
1876        if(active.length < 1){
1877            Roo.get(document).un("mouseup", onMouseDown);
1878             
1879            attached = false;
1880        }
1881    }
1882
1883    // private
1884    function onShow(m){
1885        var last = active.last();
1886        lastShow = new Date();
1887        active.add(m);
1888        if(!attached){
1889           Roo.get(document).on("mouseup", onMouseDown);
1890            
1891            attached = true;
1892        }
1893        if(m.parentMenu){
1894           //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1895           m.parentMenu.activeChild = m;
1896        }else if(last && last.isVisible()){
1897           //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1898        }
1899    }
1900
1901    // private
1902    function onBeforeHide(m){
1903        if(m.activeChild){
1904            m.activeChild.hide();
1905        }
1906        if(m.autoHideTimer){
1907            clearTimeout(m.autoHideTimer);
1908            delete m.autoHideTimer;
1909        }
1910    }
1911
1912    // private
1913    function onBeforeShow(m){
1914        var pm = m.parentMenu;
1915        if(!pm && !m.allowOtherMenus){
1916            hideAll();
1917        }else if(pm && pm.activeChild && active != m){
1918            pm.activeChild.hide();
1919        }
1920    }
1921
1922    // private this should really trigger on mouseup..
1923    function onMouseDown(e){
1924         Roo.log("on Mouse Up");
1925         
1926         if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1927             Roo.log("MenuManager hideAll");
1928             hideAll();
1929             e.stopEvent();
1930         }
1931         
1932         
1933    }
1934
1935    // private
1936    function onBeforeCheck(mi, state){
1937        if(state){
1938            var g = groups[mi.group];
1939            for(var i = 0, l = g.length; i < l; i++){
1940                if(g[i] != mi){
1941                    g[i].setChecked(false);
1942                }
1943            }
1944        }
1945    }
1946
1947    return {
1948
1949        /**
1950         * Hides all menus that are currently visible
1951         */
1952        hideAll : function(){
1953             hideAll();  
1954        },
1955
1956        // private
1957        register : function(menu){
1958            if(!menus){
1959                init();
1960            }
1961            menus[menu.id] = menu;
1962            menu.on("beforehide", onBeforeHide);
1963            menu.on("hide", onHide);
1964            menu.on("beforeshow", onBeforeShow);
1965            menu.on("show", onShow);
1966            var g = menu.group;
1967            if(g && menu.events["checkchange"]){
1968                if(!groups[g]){
1969                    groups[g] = [];
1970                }
1971                groups[g].push(menu);
1972                menu.on("checkchange", onCheck);
1973            }
1974        },
1975
1976         /**
1977          * Returns a {@link Roo.menu.Menu} object
1978          * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1979          * be used to generate and return a new Menu instance.
1980          */
1981        get : function(menu){
1982            if(typeof menu == "string"){ // menu id
1983                return menus[menu];
1984            }else if(menu.events){  // menu instance
1985                return menu;
1986            }
1987            /*else if(typeof menu.length == 'number'){ // array of menu items?
1988                return new Roo.bootstrap.Menu({items:menu});
1989            }else{ // otherwise, must be a config
1990                return new Roo.bootstrap.Menu(menu);
1991            }
1992            */
1993            return false;
1994        },
1995
1996        // private
1997        unregister : function(menu){
1998            delete menus[menu.id];
1999            menu.un("beforehide", onBeforeHide);
2000            menu.un("hide", onHide);
2001            menu.un("beforeshow", onBeforeShow);
2002            menu.un("show", onShow);
2003            var g = menu.group;
2004            if(g && menu.events["checkchange"]){
2005                groups[g].remove(menu);
2006                menu.un("checkchange", onCheck);
2007            }
2008        },
2009
2010        // private
2011        registerCheckable : function(menuItem){
2012            var g = menuItem.group;
2013            if(g){
2014                if(!groups[g]){
2015                    groups[g] = [];
2016                }
2017                groups[g].push(menuItem);
2018                menuItem.on("beforecheckchange", onBeforeCheck);
2019            }
2020        },
2021
2022        // private
2023        unregisterCheckable : function(menuItem){
2024            var g = menuItem.group;
2025            if(g){
2026                groups[g].remove(menuItem);
2027                menuItem.un("beforecheckchange", onBeforeCheck);
2028            }
2029        }
2030    };
2031 }();/*
2032  * - LGPL
2033  *
2034  * menu
2035  * 
2036  */
2037
2038 /**
2039  * @class Roo.bootstrap.Menu
2040  * @extends Roo.bootstrap.Component
2041  * Bootstrap Menu class - container for MenuItems
2042  * @cfg {String} type (dropdown|treeview|submenu) type of menu
2043  * @cfg {bool} hidden  if the menu should be hidden when rendered.
2044  * @cfg {bool} stopEvent (true|false)  Stop event after trigger press (default true)
2045  * @cfg {bool} isLink (true|false)  the menu has link disable auto expand and collaspe (default false)
2046  * 
2047  * @constructor
2048  * Create a new Menu
2049  * @param {Object} config The config object
2050  */
2051
2052
2053 Roo.bootstrap.Menu = function(config){
2054     Roo.bootstrap.Menu.superclass.constructor.call(this, config);
2055     if (this.registerMenu && this.type != 'treeview')  {
2056         Roo.bootstrap.MenuMgr.register(this);
2057     }
2058     
2059     
2060     this.addEvents({
2061         /**
2062          * @event beforeshow
2063          * Fires before this menu is displayed
2064          * @param {Roo.menu.Menu} this
2065          */
2066         beforeshow : true,
2067         /**
2068          * @event beforehide
2069          * Fires before this menu is hidden
2070          * @param {Roo.menu.Menu} this
2071          */
2072         beforehide : true,
2073         /**
2074          * @event show
2075          * Fires after this menu is displayed
2076          * @param {Roo.menu.Menu} this
2077          */
2078         show : true,
2079         /**
2080          * @event hide
2081          * Fires after this menu is hidden
2082          * @param {Roo.menu.Menu} this
2083          */
2084         hide : true,
2085         /**
2086          * @event click
2087          * Fires when this menu is clicked (or when the enter key is pressed while it is active)
2088          * @param {Roo.menu.Menu} this
2089          * @param {Roo.menu.Item} menuItem The menu item that was clicked
2090          * @param {Roo.EventObject} e
2091          */
2092         click : true,
2093         /**
2094          * @event mouseover
2095          * Fires when the mouse is hovering over this menu
2096          * @param {Roo.menu.Menu} this
2097          * @param {Roo.EventObject} e
2098          * @param {Roo.menu.Item} menuItem The menu item that was clicked
2099          */
2100         mouseover : true,
2101         /**
2102          * @event mouseout
2103          * Fires when the mouse exits this menu
2104          * @param {Roo.menu.Menu} this
2105          * @param {Roo.EventObject} e
2106          * @param {Roo.menu.Item} menuItem The menu item that was clicked
2107          */
2108         mouseout : true,
2109         /**
2110          * @event itemclick
2111          * Fires when a menu item contained in this menu is clicked
2112          * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
2113          * @param {Roo.EventObject} e
2114          */
2115         itemclick: true
2116     });
2117     this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
2118 };
2119
2120 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
2121     
2122    /// html : false,
2123     //align : '',
2124     triggerEl : false,  // is this set by component builder? -- it should really be fetched from parent()???
2125     type: false,
2126     /**
2127      * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2128      */
2129     registerMenu : true,
2130     
2131     menuItems :false, // stores the menu items..
2132     
2133     hidden:true,
2134         
2135     parentMenu : false,
2136     
2137     stopEvent : true,
2138     
2139     isLink : false,
2140     
2141     getChildContainer : function() {
2142         return this.el;  
2143     },
2144     
2145     getAutoCreate : function(){
2146          
2147         //if (['right'].indexOf(this.align)!==-1) {
2148         //    cfg.cn[1].cls += ' pull-right'
2149         //}
2150         
2151         
2152         var cfg = {
2153             tag : 'ul',
2154             cls : 'dropdown-menu' ,
2155             style : 'z-index:1000'
2156             
2157         };
2158         
2159         if (this.type === 'submenu') {
2160             cfg.cls = 'submenu active';
2161         }
2162         if (this.type === 'treeview') {
2163             cfg.cls = 'treeview-menu';
2164         }
2165         
2166         return cfg;
2167     },
2168     initEvents : function() {
2169         
2170        // Roo.log("ADD event");
2171        // Roo.log(this.triggerEl.dom);
2172         
2173         this.triggerEl.on('click', this.onTriggerClick, this);
2174         
2175         this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2176         
2177         
2178         if (this.triggerEl.hasClass('nav-item')) {
2179             // dropdown toggle on the 'a' in BS4?
2180             this.triggerEl.select('.nav-link',true).first().addClass('dropdown-toggle');
2181         } else {
2182             this.triggerEl.addClass('dropdown-toggle');
2183         }
2184         if (Roo.isTouch) {
2185             this.el.on('touchstart'  , this.onTouch, this);
2186         }
2187         this.el.on('click' , this.onClick, this);
2188
2189         this.el.on("mouseover", this.onMouseOver, this);
2190         this.el.on("mouseout", this.onMouseOut, this);
2191         
2192     },
2193     
2194     findTargetItem : function(e)
2195     {
2196         var t = e.getTarget(".dropdown-menu-item", this.el,  true);
2197         if(!t){
2198             return false;
2199         }
2200         //Roo.log(t);         Roo.log(t.id);
2201         if(t && t.id){
2202             //Roo.log(this.menuitems);
2203             return this.menuitems.get(t.id);
2204             
2205             //return this.items.get(t.menuItemId);
2206         }
2207         
2208         return false;
2209     },
2210     
2211     onTouch : function(e) 
2212     {
2213         Roo.log("menu.onTouch");
2214         //e.stopEvent(); this make the user popdown broken
2215         this.onClick(e);
2216     },
2217     
2218     onClick : function(e)
2219     {
2220         Roo.log("menu.onClick");
2221         
2222         var t = this.findTargetItem(e);
2223         if(!t || t.isContainer){
2224             return;
2225         }
2226         Roo.log(e);
2227         /*
2228         if (Roo.isTouch && e.type == 'touchstart' && t.menu  && !t.disabled) {
2229             if(t == this.activeItem && t.shouldDeactivate(e)){
2230                 this.activeItem.deactivate();
2231                 delete this.activeItem;
2232                 return;
2233             }
2234             if(t.canActivate){
2235                 this.setActiveItem(t, true);
2236             }
2237             return;
2238             
2239             
2240         }
2241         */
2242        
2243         Roo.log('pass click event');
2244         
2245         t.onClick(e);
2246         
2247         this.fireEvent("click", this, t, e);
2248         
2249         var _this = this;
2250         
2251         if(!t.href.length || t.href == '#'){
2252             (function() { _this.hide(); }).defer(100);
2253         }
2254         
2255     },
2256     
2257     onMouseOver : function(e){
2258         var t  = this.findTargetItem(e);
2259         //Roo.log(t);
2260         //if(t){
2261         //    if(t.canActivate && !t.disabled){
2262         //        this.setActiveItem(t, true);
2263         //    }
2264         //}
2265         
2266         this.fireEvent("mouseover", this, e, t);
2267     },
2268     isVisible : function(){
2269         return !this.hidden;
2270     },
2271      onMouseOut : function(e){
2272         var t  = this.findTargetItem(e);
2273         
2274         //if(t ){
2275         //    if(t == this.activeItem && t.shouldDeactivate(e)){
2276         //        this.activeItem.deactivate();
2277         //        delete this.activeItem;
2278         //    }
2279         //}
2280         this.fireEvent("mouseout", this, e, t);
2281     },
2282     
2283     
2284     /**
2285      * Displays this menu relative to another element
2286      * @param {String/HTMLElement/Roo.Element} element The element to align to
2287      * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2288      * the element (defaults to this.defaultAlign)
2289      * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2290      */
2291     show : function(el, pos, parentMenu){
2292         this.parentMenu = parentMenu;
2293         if(!this.el){
2294             this.render();
2295         }
2296         this.fireEvent("beforeshow", this);
2297         this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2298     },
2299      /**
2300      * Displays this menu at a specific xy position
2301      * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2302      * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2303      */
2304     showAt : function(xy, parentMenu, /* private: */_e){
2305         this.parentMenu = parentMenu;
2306         if(!this.el){
2307             this.render();
2308         }
2309         if(_e !== false){
2310             this.fireEvent("beforeshow", this);
2311             //xy = this.el.adjustForConstraints(xy);
2312         }
2313         
2314         //this.el.show();
2315         this.hideMenuItems();
2316         this.hidden = false;
2317         this.triggerEl.addClass('open');
2318         this.el.addClass('show');
2319         
2320         // reassign x when hitting right
2321         if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
2322             xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2323         }
2324         
2325         // reassign y when hitting bottom
2326         if(this.el.getHeight() + xy[1] >= Roo.lib.Dom.getViewHeight()){
2327             xy[1] = xy[1] - this.el.getHeight() - this.triggerEl.getHeight();
2328         }
2329         
2330         // but the list may align on trigger left or trigger top... should it be a properity?
2331         
2332         if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2333             this.el.setXY(xy);
2334         }
2335         
2336         this.focus();
2337         this.fireEvent("show", this);
2338     },
2339     
2340     focus : function(){
2341         return;
2342         if(!this.hidden){
2343             this.doFocus.defer(50, this);
2344         }
2345     },
2346
2347     doFocus : function(){
2348         if(!this.hidden){
2349             this.focusEl.focus();
2350         }
2351     },
2352
2353     /**
2354      * Hides this menu and optionally all parent menus
2355      * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2356      */
2357     hide : function(deep)
2358     {
2359         
2360         this.hideMenuItems();
2361         if(this.el && this.isVisible()){
2362             this.fireEvent("beforehide", this);
2363             if(this.activeItem){
2364                 this.activeItem.deactivate();
2365                 this.activeItem = null;
2366             }
2367             this.triggerEl.removeClass('open');;
2368             this.el.removeClass('show');
2369             this.hidden = true;
2370             this.fireEvent("hide", this);
2371         }
2372         if(deep === true && this.parentMenu){
2373             this.parentMenu.hide(true);
2374         }
2375     },
2376     
2377     onTriggerClick : function(e)
2378     {
2379         Roo.log('trigger click');
2380         
2381         var target = e.getTarget();
2382         
2383         Roo.log(target.nodeName.toLowerCase());
2384         
2385         if(target.nodeName.toLowerCase() === 'i'){
2386             e.preventDefault();
2387         }
2388         
2389     },
2390     
2391     onTriggerPress  : function(e)
2392     {
2393         Roo.log('trigger press');
2394         //Roo.log(e.getTarget());
2395        // Roo.log(this.triggerEl.dom);
2396        
2397         // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2398         var pel = Roo.get(e.getTarget());
2399         if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2400             Roo.log('is treeview or dropdown?');
2401             return;
2402         }
2403         
2404         if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2405             return;
2406         }
2407         
2408         if (this.isVisible()) {
2409             Roo.log('hide');
2410             this.hide();
2411         } else {
2412             Roo.log('show');
2413             this.show(this.triggerEl, '?', false);
2414         }
2415         
2416         if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2417             e.stopEvent();
2418         }
2419         
2420     },
2421        
2422     
2423     hideMenuItems : function()
2424     {
2425         Roo.log("hide Menu Items");
2426         if (!this.el) { 
2427             return;
2428         }
2429         //$(backdrop).remove()
2430         this.el.select('.open',true).each(function(aa) {
2431             
2432             aa.removeClass('open');
2433           //var parent = getParent($(this))
2434           //var relatedTarget = { relatedTarget: this }
2435           
2436            //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2437           //if (e.isDefaultPrevented()) return
2438            //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2439         });
2440     },
2441     addxtypeChild : function (tree, cntr) {
2442         var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2443           
2444         this.menuitems.add(comp);
2445         return comp;
2446
2447     },
2448     getEl : function()
2449     {
2450         Roo.log(this.el);
2451         return this.el;
2452     },
2453     
2454     clear : function()
2455     {
2456         this.getEl().dom.innerHTML = '';
2457         this.menuitems.clear();
2458     }
2459 });
2460
2461  
2462  /*
2463  * - LGPL
2464  *
2465  * menu item
2466  * 
2467  */
2468
2469
2470 /**
2471  * @class Roo.bootstrap.MenuItem
2472  * @extends Roo.bootstrap.Component
2473  * Bootstrap MenuItem class
2474  * @cfg {String} html the menu label
2475  * @cfg {String} href the link
2476  * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2477  * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2478  * @cfg {Boolean} active  used on sidebars to highlight active itesm
2479  * @cfg {String} fa favicon to show on left of menu item.
2480  * @cfg {Roo.bootsrap.Menu} menu the child menu.
2481  * 
2482  * 
2483  * @constructor
2484  * Create a new MenuItem
2485  * @param {Object} config The config object
2486  */
2487
2488
2489 Roo.bootstrap.MenuItem = function(config){
2490     Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2491     this.addEvents({
2492         // raw events
2493         /**
2494          * @event click
2495          * The raw click event for the entire grid.
2496          * @param {Roo.bootstrap.MenuItem} this
2497          * @param {Roo.EventObject} e
2498          */
2499         "click" : true
2500     });
2501 };
2502
2503 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component,  {
2504     
2505     href : false,
2506     html : false,
2507     preventDefault: false,
2508     isContainer : false,
2509     active : false,
2510     fa: false,
2511     
2512     getAutoCreate : function(){
2513         
2514         if(this.isContainer){
2515             return {
2516                 tag: 'li',
2517                 cls: 'dropdown-menu-item '
2518             };
2519         }
2520         var ctag = {
2521             tag: 'span',
2522             html: 'Link'
2523         };
2524         
2525         var anc = {
2526             tag : 'a',
2527             cls : 'dropdown-item',
2528             href : '#',
2529             cn : [  ]
2530         };
2531         
2532         if (this.fa !== false) {
2533             anc.cn.push({
2534                 tag : 'i',
2535                 cls : 'fa fa-' + this.fa
2536             });
2537         }
2538         
2539         anc.cn.push(ctag);
2540         
2541         
2542         var cfg= {
2543             tag: 'li',
2544             cls: 'dropdown-menu-item',
2545             cn: [ anc ]
2546         };
2547         if (this.parent().type == 'treeview') {
2548             cfg.cls = 'treeview-menu';
2549         }
2550         if (this.active) {
2551             cfg.cls += ' active';
2552         }
2553         
2554         
2555         
2556         anc.href = this.href || cfg.cn[0].href ;
2557         ctag.html = this.html || cfg.cn[0].html ;
2558         return cfg;
2559     },
2560     
2561     initEvents: function()
2562     {
2563         if (this.parent().type == 'treeview') {
2564             this.el.select('a').on('click', this.onClick, this);
2565         }
2566         
2567         if (this.menu) {
2568             this.menu.parentType = this.xtype;
2569             this.menu.triggerEl = this.el;
2570             this.menu = this.addxtype(Roo.apply({}, this.menu));
2571         }
2572         
2573     },
2574     onClick : function(e)
2575     {
2576         Roo.log('item on click ');
2577         
2578         if(this.preventDefault){
2579             e.preventDefault();
2580         }
2581         //this.parent().hideMenuItems();
2582         
2583         this.fireEvent('click', this, e);
2584     },
2585     getEl : function()
2586     {
2587         return this.el;
2588     } 
2589 });
2590
2591  
2592
2593  /*
2594  * - LGPL
2595  *
2596  * menu separator
2597  * 
2598  */
2599
2600
2601 /**
2602  * @class Roo.bootstrap.MenuSeparator
2603  * @extends Roo.bootstrap.Component
2604  * Bootstrap MenuSeparator class
2605  * 
2606  * @constructor
2607  * Create a new MenuItem
2608  * @param {Object} config The config object
2609  */
2610
2611
2612 Roo.bootstrap.MenuSeparator = function(config){
2613     Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2614 };
2615
2616 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component,  {
2617     
2618     getAutoCreate : function(){
2619         var cfg = {
2620             cls: 'divider',
2621             tag : 'li'
2622         };
2623         
2624         return cfg;
2625     }
2626    
2627 });
2628
2629  
2630
2631  
2632 /*
2633 * Licence: LGPL
2634 */
2635
2636 /**
2637  * @class Roo.bootstrap.Modal
2638  * @extends Roo.bootstrap.Component
2639  * Bootstrap Modal class
2640  * @cfg {String} title Title of dialog
2641  * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2642  * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method  adn
2643  * @cfg {Boolean} specificTitle default false
2644  * @cfg {Array} buttons Array of buttons or standard button set..
2645  * @cfg {String} buttonPosition (left|right|center) default right (DEPRICATED) - use mr-auto on buttons to put them on the left
2646  * @cfg {Boolean} animate default true
2647  * @cfg {Boolean} allow_close default true
2648  * @cfg {Boolean} fitwindow default false
2649  * @cfg {String} size (sm|lg) default empty
2650  * @cfg {Number} max_width set the max width of modal
2651  *
2652  *
2653  * @constructor
2654  * Create a new Modal Dialog
2655  * @param {Object} config The config object
2656  */
2657
2658 Roo.bootstrap.Modal = function(config){
2659     Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2660     this.addEvents({
2661         // raw events
2662         /**
2663          * @event btnclick
2664          * The raw btnclick event for the button
2665          * @param {Roo.EventObject} e
2666          */
2667         "btnclick" : true,
2668         /**
2669          * @event resize
2670          * Fire when dialog resize
2671          * @param {Roo.bootstrap.Modal} this
2672          * @param {Roo.EventObject} e
2673          */
2674         "resize" : true
2675     });
2676     this.buttons = this.buttons || [];
2677
2678     if (this.tmpl) {
2679         this.tmpl = Roo.factory(this.tmpl);
2680     }
2681
2682 };
2683
2684 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
2685
2686     title : 'test dialog',
2687
2688     buttons : false,
2689
2690     // set on load...
2691
2692     html: false,
2693
2694     tmp: false,
2695
2696     specificTitle: false,
2697
2698     buttonPosition: 'right',
2699
2700     allow_close : true,
2701
2702     animate : true,
2703
2704     fitwindow: false,
2705     
2706      // private
2707     dialogEl: false,
2708     bodyEl:  false,
2709     footerEl:  false,
2710     titleEl:  false,
2711     closeEl:  false,
2712
2713     size: '',
2714     
2715     max_width: 0,
2716     
2717     max_height: 0,
2718     
2719     fit_content: false,
2720
2721     onRender : function(ct, position)
2722     {
2723         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2724
2725         if(!this.el){
2726             var cfg = Roo.apply({},  this.getAutoCreate());
2727             cfg.id = Roo.id();
2728             //if(!cfg.name){
2729             //    cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2730             //}
2731             //if (!cfg.name.length) {
2732             //    delete cfg.name;
2733            // }
2734             if (this.cls) {
2735                 cfg.cls += ' ' + this.cls;
2736             }
2737             if (this.style) {
2738                 cfg.style = this.style;
2739             }
2740             this.el = Roo.get(document.body).createChild(cfg, position);
2741         }
2742         //var type = this.el.dom.type;
2743
2744
2745         if(this.tabIndex !== undefined){
2746             this.el.dom.setAttribute('tabIndex', this.tabIndex);
2747         }
2748
2749         this.dialogEl = this.el.select('.modal-dialog',true).first();
2750         this.bodyEl = this.el.select('.modal-body',true).first();
2751         this.closeEl = this.el.select('.modal-header .close', true).first();
2752         this.headerEl = this.el.select('.modal-header',true).first();
2753         this.titleEl = this.el.select('.modal-title',true).first();
2754         this.footerEl = this.el.select('.modal-footer',true).first();
2755
2756         this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2757         
2758         //this.el.addClass("x-dlg-modal");
2759
2760         if (this.buttons.length) {
2761             Roo.each(this.buttons, function(bb) {
2762                 var b = Roo.apply({}, bb);
2763                 b.xns = b.xns || Roo.bootstrap;
2764                 b.xtype = b.xtype || 'Button';
2765                 if (typeof(b.listeners) == 'undefined') {
2766                     b.listeners = { click : this.onButtonClick.createDelegate(this)  };
2767                 }
2768
2769                 var btn = Roo.factory(b);
2770
2771                 btn.render(this.getButtonContainer());
2772
2773             },this);
2774         }
2775         // render the children.
2776         var nitems = [];
2777
2778         if(typeof(this.items) != 'undefined'){
2779             var items = this.items;
2780             delete this.items;
2781
2782             for(var i =0;i < items.length;i++) {
2783                 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2784             }
2785         }
2786
2787         this.items = nitems;
2788
2789         // where are these used - they used to be body/close/footer
2790
2791
2792         this.initEvents();
2793         //this.el.addClass([this.fieldClass, this.cls]);
2794
2795     },
2796
2797     getAutoCreate : function()
2798     {
2799         var bdy = {
2800                 cls : 'modal-body',
2801                 html : this.html || ''
2802         };
2803
2804         var title = {
2805             tag: 'h4',
2806             cls : 'modal-title',
2807             html : this.title
2808         };
2809
2810         if(this.specificTitle){
2811             title = this.title;
2812
2813         };
2814
2815         var header = [];
2816         if (this.allow_close && Roo.bootstrap.version == 3) {
2817             header.push({
2818                 tag: 'button',
2819                 cls : 'close',
2820                 html : '&times'
2821             });
2822         }
2823
2824         header.push(title);
2825
2826         if (this.allow_close && Roo.bootstrap.version == 4) {
2827             header.push({
2828                 tag: 'button',
2829                 cls : 'close',
2830                 html : '&times'
2831             });
2832         }
2833         
2834         var size = '';
2835
2836         if(this.size.length){
2837             size = 'modal-' + this.size;
2838         }
2839         
2840         var footer = Roo.bootstrap.version == 3 ?
2841             {
2842                 cls : 'modal-footer',
2843                 cn : [
2844                     {
2845                         tag: 'div',
2846                         cls: 'btn-' + this.buttonPosition
2847                     }
2848                 ]
2849
2850             } :
2851             {  // BS4 uses mr-auto on left buttons....
2852                 cls : 'modal-footer'
2853             };
2854
2855             
2856
2857         
2858         
2859         var modal = {
2860             cls: "modal",
2861              cn : [
2862                 {
2863                     cls: "modal-dialog " + size,
2864                     cn : [
2865                         {
2866                             cls : "modal-content",
2867                             cn : [
2868                                 {
2869                                     cls : 'modal-header',
2870                                     cn : header
2871                                 },
2872                                 bdy,
2873                                 footer
2874                             ]
2875
2876                         }
2877                     ]
2878
2879                 }
2880             ]
2881         };
2882
2883         if(this.animate){
2884             modal.cls += ' fade';
2885         }
2886
2887         return modal;
2888
2889     },
2890     getChildContainer : function() {
2891
2892          return this.bodyEl;
2893
2894     },
2895     getButtonContainer : function() {
2896         
2897          return Roo.bootstrap.version == 4 ?
2898             this.el.select('.modal-footer',true).first()
2899             : this.el.select('.modal-footer div',true).first();
2900
2901     },
2902     initEvents : function()
2903     {
2904         if (this.allow_close) {
2905             this.closeEl.on('click', this.hide, this);
2906         }
2907         Roo.EventManager.onWindowResize(this.resize, this, true);
2908
2909
2910     },
2911
2912     resize : function()
2913     {
2914         this.maskEl.setSize(
2915             Roo.lib.Dom.getViewWidth(true),
2916             Roo.lib.Dom.getViewHeight(true)
2917         );
2918         
2919         if (this.fitwindow) {
2920             this.setSize(
2921                 this.width || Roo.lib.Dom.getViewportWidth(true) - 30,
2922                 this.height || Roo.lib.Dom.getViewportHeight(true) - 60
2923             );
2924             return;
2925         }
2926         
2927         if(this.max_width !== 0) {
2928             
2929             var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
2930             
2931             if(this.height) {
2932                 this.setSize(w, this.height);
2933                 return;
2934             }
2935             
2936             if(this.max_height) {
2937                 this.setSize(w,Math.min(
2938                     this.max_height,
2939                     Roo.lib.Dom.getViewportHeight(true) - 60
2940                 ));
2941                 
2942                 return;
2943             }
2944             
2945             if(!this.fit_content) {
2946                 this.setSize(w, Roo.lib.Dom.getViewportHeight(true) - 60);
2947                 return;
2948             }
2949             
2950             this.setSize(w, Math.min(
2951                 60 +
2952                 this.headerEl.getHeight() + 
2953                 this.footerEl.getHeight() + 
2954                 this.getChildHeight(this.bodyEl.dom.childNodes),
2955                 Roo.lib.Dom.getViewportHeight(true) - 60)
2956             );
2957         }
2958         
2959     },
2960
2961     setSize : function(w,h)
2962     {
2963         if (!w && !h) {
2964             return;
2965         }
2966         
2967         this.resizeTo(w,h);
2968     },
2969
2970     show : function() {
2971
2972         if (!this.rendered) {
2973             this.render();
2974         }
2975
2976         //this.el.setStyle('display', 'block');
2977         this.el.removeClass('hideing');
2978         this.el.dom.style.display='block';
2979         
2980         Roo.get(document.body).addClass('modal-open');
2981  
2982         if(this.animate){  // element has 'fade'  - so stuff happens after .3s ?- not sure why the delay?
2983             var _this = this;
2984             (function(){
2985                 this.el.addClass('show');
2986                 this.el.addClass('in');
2987             }).defer(50, this);
2988         }else{
2989             this.el.addClass('show');
2990             this.el.addClass('in');
2991         }
2992
2993         // not sure how we can show data in here..
2994         //if (this.tmpl) {
2995         //    this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2996         //}
2997
2998         Roo.get(document.body).addClass("x-body-masked");
2999         
3000         this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true),   Roo.lib.Dom.getViewHeight(true));
3001         this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
3002         this.maskEl.dom.style.display = 'block';
3003         this.maskEl.addClass('show');
3004         
3005         
3006         this.resize();
3007         
3008         this.fireEvent('show', this);
3009
3010         // set zindex here - otherwise it appears to be ignored...
3011         this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
3012
3013         (function () {
3014             this.items.forEach( function(e) {
3015                 e.layout ? e.layout() : false;
3016
3017             });
3018         }).defer(100,this);
3019
3020     },
3021     hide : function()
3022     {
3023         if(this.fireEvent("beforehide", this) !== false){
3024             
3025             this.maskEl.removeClass('show');
3026             
3027             this.maskEl.dom.style.display = '';
3028             Roo.get(document.body).removeClass("x-body-masked");
3029             this.el.removeClass('in');
3030             this.el.select('.modal-dialog', true).first().setStyle('transform','');
3031
3032             if(this.animate){ // why
3033                 this.el.addClass('hideing');
3034                 this.el.removeClass('show');
3035                 (function(){
3036                     if (!this.el.hasClass('hideing')) {
3037                         return; // it's been shown again...
3038                     }
3039                     
3040                     this.el.dom.style.display='';
3041
3042                     Roo.get(document.body).removeClass('modal-open');
3043                     this.el.removeClass('hideing');
3044                 }).defer(150,this);
3045                 
3046             }else{
3047                 this.el.removeClass('show');
3048                 this.el.dom.style.display='';
3049                 Roo.get(document.body).removeClass('modal-open');
3050
3051             }
3052             this.fireEvent('hide', this);
3053         }
3054     },
3055     isVisible : function()
3056     {
3057         
3058         return this.el.hasClass('show') && !this.el.hasClass('hideing');
3059         
3060     },
3061
3062     addButton : function(str, cb)
3063     {
3064
3065
3066         var b = Roo.apply({}, { html : str } );
3067         b.xns = b.xns || Roo.bootstrap;
3068         b.xtype = b.xtype || 'Button';
3069         if (typeof(b.listeners) == 'undefined') {
3070             b.listeners = { click : cb.createDelegate(this)  };
3071         }
3072
3073         var btn = Roo.factory(b);
3074
3075         btn.render(this.getButtonContainer());
3076
3077         return btn;
3078
3079     },
3080
3081     setDefaultButton : function(btn)
3082     {
3083         //this.el.select('.modal-footer').()
3084     },
3085     diff : false,
3086
3087     resizeTo: function(w,h)
3088     {
3089         // skip.. ?? why??
3090
3091         this.dialogEl.setWidth(w);
3092         if (this.diff === false) {
3093             this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
3094         }
3095
3096         this.bodyEl.setHeight(h - this.diff);
3097
3098         this.fireEvent('resize', this);
3099
3100     },
3101     setContentSize  : function(w, h)
3102     {
3103
3104     },
3105     onButtonClick: function(btn,e)
3106     {
3107         //Roo.log([a,b,c]);
3108         this.fireEvent('btnclick', btn.name, e);
3109     },
3110      /**
3111      * Set the title of the Dialog
3112      * @param {String} str new Title
3113      */
3114     setTitle: function(str) {
3115         this.titleEl.dom.innerHTML = str;
3116     },
3117     /**
3118      * Set the body of the Dialog
3119      * @param {String} str new Title
3120      */
3121     setBody: function(str) {
3122         this.bodyEl.dom.innerHTML = str;
3123     },
3124     /**
3125      * Set the body of the Dialog using the template
3126      * @param {Obj} data - apply this data to the template and replace the body contents.
3127      */
3128     applyBody: function(obj)
3129     {
3130         if (!this.tmpl) {
3131             Roo.log("Error - using apply Body without a template");
3132             //code
3133         }
3134         this.tmpl.overwrite(this.bodyEl, obj);
3135     },
3136     
3137     getChildHeight : function(child_nodes)
3138     {
3139         if(
3140             !child_nodes ||
3141             child_nodes.length == 0
3142         ) {
3143             return;
3144         }
3145         
3146         var child_height = 0;
3147         
3148         for(var i = 0; i < child_nodes.length; i++) {
3149             
3150             /*
3151             * for modal with tabs...
3152             if(child_nodes[i].classList.contains('roo-layout-panel')) {
3153                 
3154                 var layout_childs = child_nodes[i].childNodes;
3155                 
3156                 for(var j = 0; j < layout_childs.length; j++) {
3157                     
3158                     if(layout_childs[j].classList.contains('roo-layout-panel-body')) {
3159                         
3160                         var layout_body_childs = layout_childs[j].childNodes;
3161                         
3162                         for(var k = 0; k < layout_body_childs.length; k++) {
3163                             
3164                             if(layout_body_childs[k].classList.contains('navbar')) {
3165                                 child_height += layout_body_childs[k].offsetHeight;
3166                                 continue;
3167                             }
3168                             
3169                             if(layout_body_childs[k].classList.contains('roo-layout-tabs-body')) {
3170                                 
3171                                 var layout_body_tab_childs = layout_body_childs[k].childNodes;
3172                                 
3173                                 for(var m = 0; m < layout_body_tab_childs.length; m++) {
3174                                     
3175                                     if(layout_body_tab_childs[m].classList.contains('roo-layout-active-content')) {
3176                                         child_height += this.getChildHeight(layout_body_tab_childs[m].childNodes);
3177                                         continue;
3178                                     }
3179                                     
3180                                 }
3181                                 
3182                             }
3183                             
3184                         }
3185                     }
3186                 }
3187                 continue;
3188             }
3189             */
3190             
3191             child_height += child_nodes[i].offsetHeight;
3192             // Roo.log(child_nodes[i].offsetHeight);
3193         }
3194         
3195         return child_height;
3196     }
3197
3198 });
3199
3200
3201 Roo.apply(Roo.bootstrap.Modal,  {
3202     /**
3203          * Button config that displays a single OK button
3204          * @type Object
3205          */
3206         OK :  [{
3207             name : 'ok',
3208             weight : 'primary',
3209             html : 'OK'
3210         }],
3211         /**
3212          * Button config that displays Yes and No buttons
3213          * @type Object
3214          */
3215         YESNO : [
3216             {
3217                 name  : 'no',
3218                 html : 'No'
3219             },
3220             {
3221                 name  :'yes',
3222                 weight : 'primary',
3223                 html : 'Yes'
3224             }
3225         ],
3226
3227         /**
3228          * Button config that displays OK and Cancel buttons
3229          * @type Object
3230          */
3231         OKCANCEL : [
3232             {
3233                name : 'cancel',
3234                 html : 'Cancel'
3235             },
3236             {
3237                 name : 'ok',
3238                 weight : 'primary',
3239                 html : 'OK'
3240             }
3241         ],
3242         /**
3243          * Button config that displays Yes, No and Cancel buttons
3244          * @type Object
3245          */
3246         YESNOCANCEL : [
3247             {
3248                 name : 'yes',
3249                 weight : 'primary',
3250                 html : 'Yes'
3251             },
3252             {
3253                 name : 'no',
3254                 html : 'No'
3255             },
3256             {
3257                 name : 'cancel',
3258                 html : 'Cancel'
3259             }
3260         ],
3261         
3262         zIndex : 10001
3263 });
3264 /*
3265  * - LGPL
3266  *
3267  * messagebox - can be used as a replace
3268  * 
3269  */
3270 /**
3271  * @class Roo.MessageBox
3272  * Utility class for generating different styles of message boxes.  The alias Roo.Msg can also be used.
3273  * Example usage:
3274  *<pre><code>
3275 // Basic alert:
3276 Roo.Msg.alert('Status', 'Changes saved successfully.');
3277
3278 // Prompt for user data:
3279 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
3280     if (btn == 'ok'){
3281         // process text value...
3282     }
3283 });
3284
3285 // Show a dialog using config options:
3286 Roo.Msg.show({
3287    title:'Save Changes?',
3288    msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
3289    buttons: Roo.Msg.YESNOCANCEL,
3290    fn: processResult,
3291    animEl: 'elId'
3292 });
3293 </code></pre>
3294  * @singleton
3295  */
3296 Roo.bootstrap.MessageBox = function(){
3297     var dlg, opt, mask, waitTimer;
3298     var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3299     var buttons, activeTextEl, bwidth;
3300
3301     
3302     // private
3303     var handleButton = function(button){
3304         dlg.hide();
3305         Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3306     };
3307
3308     // private
3309     var handleHide = function(){
3310         if(opt && opt.cls){
3311             dlg.el.removeClass(opt.cls);
3312         }
3313         //if(waitTimer){
3314         //    Roo.TaskMgr.stop(waitTimer);
3315         //    waitTimer = null;
3316         //}
3317     };
3318
3319     // private
3320     var updateButtons = function(b){
3321         var width = 0;
3322         if(!b){
3323             buttons["ok"].hide();
3324             buttons["cancel"].hide();
3325             buttons["yes"].hide();
3326             buttons["no"].hide();
3327             dlg.footerEl.hide();
3328             
3329             return width;
3330         }
3331         dlg.footerEl.show();
3332         for(var k in buttons){
3333             if(typeof buttons[k] != "function"){
3334                 if(b[k]){
3335                     buttons[k].show();
3336                     buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3337                     width += buttons[k].el.getWidth()+15;
3338                 }else{
3339                     buttons[k].hide();
3340                 }
3341             }
3342         }
3343         return width;
3344     };
3345
3346     // private
3347     var handleEsc = function(d, k, e){
3348         if(opt && opt.closable !== false){
3349             dlg.hide();
3350         }
3351         if(e){
3352             e.stopEvent();
3353         }
3354     };
3355
3356     return {
3357         /**
3358          * Returns a reference to the underlying {@link Roo.BasicDialog} element
3359          * @return {Roo.BasicDialog} The BasicDialog element
3360          */
3361         getDialog : function(){
3362            if(!dlg){
3363                 dlg = new Roo.bootstrap.Modal( {
3364                     //draggable: true,
3365                     //resizable:false,
3366                     //constraintoviewport:false,
3367                     //fixedcenter:true,
3368                     //collapsible : false,
3369                     //shim:true,
3370                     //modal: true,
3371                 //    width: 'auto',
3372                   //  height:100,
3373                     //buttonAlign:"center",
3374                     closeClick : function(){
3375                         if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3376                             handleButton("no");
3377                         }else{
3378                             handleButton("cancel");
3379                         }
3380                     }
3381                 });
3382                 dlg.render();
3383                 dlg.on("hide", handleHide);
3384                 mask = dlg.mask;
3385                 //dlg.addKeyListener(27, handleEsc);
3386                 buttons = {};
3387                 this.buttons = buttons;
3388                 var bt = this.buttonText;
3389                 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3390                 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3391                 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3392                 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3393                 //Roo.log(buttons);
3394                 bodyEl = dlg.bodyEl.createChild({
3395
3396                     html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3397                         '<textarea class="roo-mb-textarea"></textarea>' +
3398                         '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar">&#160;</div></div></div>'
3399                 });
3400                 msgEl = bodyEl.dom.firstChild;
3401                 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3402                 textboxEl.enableDisplayMode();
3403                 textboxEl.addKeyListener([10,13], function(){
3404                     if(dlg.isVisible() && opt && opt.buttons){
3405                         if(opt.buttons.ok){
3406                             handleButton("ok");
3407                         }else if(opt.buttons.yes){
3408                             handleButton("yes");
3409                         }
3410                     }
3411                 });
3412                 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3413                 textareaEl.enableDisplayMode();
3414                 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3415                 progressEl.enableDisplayMode();
3416                 
3417                 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3418                 var pf = progressEl.dom.firstChild;
3419                 if (pf) {
3420                     pp = Roo.get(pf.firstChild);
3421                     pp.setHeight(pf.offsetHeight);
3422                 }
3423                 
3424             }
3425             return dlg;
3426         },
3427
3428         /**
3429          * Updates the message box body text
3430          * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3431          * the XHTML-compliant non-breaking space character '&amp;#160;')
3432          * @return {Roo.MessageBox} This message box
3433          */
3434         updateText : function(text)
3435         {
3436             if(!dlg.isVisible() && !opt.width){
3437                 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
3438                 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3439             }
3440             msgEl.innerHTML = text || '&#160;';
3441       
3442             var cw =  Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3443             //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3444             var w = Math.max(
3445                     Math.min(opt.width || cw , this.maxWidth), 
3446                     Math.max(opt.minWidth || this.minWidth, bwidth)
3447             );
3448             if(opt.prompt){
3449                 activeTextEl.setWidth(w);
3450             }
3451             if(dlg.isVisible()){
3452                 dlg.fixedcenter = false;
3453             }
3454             // to big, make it scroll. = But as usual stupid IE does not support
3455             // !important..
3456             
3457             if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3458                 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3459                 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3460             } else {
3461                 bodyEl.dom.style.height = '';
3462                 bodyEl.dom.style.overflowY = '';
3463             }
3464             if (cw > w) {
3465                 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3466             } else {
3467                 bodyEl.dom.style.overflowX = '';
3468             }
3469             
3470             dlg.setContentSize(w, bodyEl.getHeight());
3471             if(dlg.isVisible()){
3472                 dlg.fixedcenter = true;
3473             }
3474             return this;
3475         },
3476
3477         /**
3478          * Updates a progress-style message box's text and progress bar.  Only relevant on message boxes
3479          * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3480          * @param {Number} value Any number between 0 and 1 (e.g., .5)
3481          * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3482          * @return {Roo.MessageBox} This message box
3483          */
3484         updateProgress : function(value, text){
3485             if(text){
3486                 this.updateText(text);
3487             }
3488             
3489             if (pp) { // weird bug on my firefox - for some reason this is not defined
3490                 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3491                 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
3492             }
3493             return this;
3494         },        
3495
3496         /**
3497          * Returns true if the message box is currently displayed
3498          * @return {Boolean} True if the message box is visible, else false
3499          */
3500         isVisible : function(){
3501             return dlg && dlg.isVisible();  
3502         },
3503
3504         /**
3505          * Hides the message box if it is displayed
3506          */
3507         hide : function(){
3508             if(this.isVisible()){
3509                 dlg.hide();
3510             }  
3511         },
3512
3513         /**
3514          * Displays a new message box, or reinitializes an existing message box, based on the config options
3515          * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3516          * The following config object properties are supported:
3517          * <pre>
3518 Property    Type             Description
3519 ----------  ---------------  ------------------------------------------------------------------------------------
3520 animEl            String/Element   An id or Element from which the message box should animate as it opens and
3521                                    closes (defaults to undefined)
3522 buttons           Object/Boolean   A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3523                                    cancel:'Bar'}), or false to not show any buttons (defaults to false)
3524 closable          Boolean          False to hide the top-right close button (defaults to true).  Note that
3525                                    progress and wait dialogs will ignore this property and always hide the
3526                                    close button as they can only be closed programmatically.
3527 cls               String           A custom CSS class to apply to the message box element
3528 defaultTextHeight Number           The default height in pixels of the message box's multiline textarea if
3529                                    displayed (defaults to 75)
3530 fn                Function         A callback function to execute after closing the dialog.  The arguments to the
3531                                    function will be btn (the name of the button that was clicked, if applicable,
3532                                    e.g. "ok"), and text (the value of the active text field, if applicable).
3533                                    Progress and wait dialogs will ignore this option since they do not respond to
3534                                    user actions and can only be closed programmatically, so any required function
3535                                    should be called by the same code after it closes the dialog.
3536 icon              String           A CSS class that provides a background image to be used as an icon for
3537                                    the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3538 maxWidth          Number           The maximum width in pixels of the message box (defaults to 600)
3539 minWidth          Number           The minimum width in pixels of the message box (defaults to 100)
3540 modal             Boolean          False to allow user interaction with the page while the message box is
3541                                    displayed (defaults to true)
3542 msg               String           A string that will replace the existing message box body text (defaults
3543                                    to the XHTML-compliant non-breaking space character '&#160;')
3544 multiline         Boolean          True to prompt the user to enter multi-line text (defaults to false)
3545 progress          Boolean          True to display a progress bar (defaults to false)
3546 progressText      String           The text to display inside the progress bar if progress = true (defaults to '')
3547 prompt            Boolean          True to prompt the user to enter single-line text (defaults to false)
3548 proxyDrag         Boolean          True to display a lightweight proxy while dragging (defaults to false)
3549 title             String           The title text
3550 value             String           The string value to set into the active textbox element if displayed
3551 wait              Boolean          True to display a progress bar (defaults to false)
3552 width             Number           The width of the dialog in pixels
3553 </pre>
3554          *
3555          * Example usage:
3556          * <pre><code>
3557 Roo.Msg.show({
3558    title: 'Address',
3559    msg: 'Please enter your address:',
3560    width: 300,
3561    buttons: Roo.MessageBox.OKCANCEL,
3562    multiline: true,
3563    fn: saveAddress,
3564    animEl: 'addAddressBtn'
3565 });
3566 </code></pre>
3567          * @param {Object} config Configuration options
3568          * @return {Roo.MessageBox} This message box
3569          */
3570         show : function(options)
3571         {
3572             
3573             // this causes nightmares if you show one dialog after another
3574             // especially on callbacks..
3575              
3576             if(this.isVisible()){
3577                 
3578                 this.hide();
3579                 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3580                 Roo.log("Old Dialog Message:" +  msgEl.innerHTML );
3581                 Roo.log("New Dialog Message:" +  options.msg )
3582                 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3583                 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3584                 
3585             }
3586             var d = this.getDialog();
3587             opt = options;
3588             d.setTitle(opt.title || "&#160;");
3589             d.closeEl.setDisplayed(opt.closable !== false);
3590             activeTextEl = textboxEl;
3591             opt.prompt = opt.prompt || (opt.multiline ? true : false);
3592             if(opt.prompt){
3593                 if(opt.multiline){
3594                     textboxEl.hide();
3595                     textareaEl.show();
3596                     textareaEl.setHeight(typeof opt.multiline == "number" ?
3597                         opt.multiline : this.defaultTextHeight);
3598                     activeTextEl = textareaEl;
3599                 }else{
3600                     textboxEl.show();
3601                     textareaEl.hide();
3602                 }
3603             }else{
3604                 textboxEl.hide();
3605                 textareaEl.hide();
3606             }
3607             progressEl.setDisplayed(opt.progress === true);
3608             if (opt.progress) {
3609                 d.animate = false; // do not animate progress, as it may not have finished animating before we close it..
3610             }
3611             this.updateProgress(0);
3612             activeTextEl.dom.value = opt.value || "";
3613             if(opt.prompt){
3614                 dlg.setDefaultButton(activeTextEl);
3615             }else{
3616                 var bs = opt.buttons;
3617                 var db = null;
3618                 if(bs && bs.ok){
3619                     db = buttons["ok"];
3620                 }else if(bs && bs.yes){
3621                     db = buttons["yes"];
3622                 }
3623                 dlg.setDefaultButton(db);
3624             }
3625             bwidth = updateButtons(opt.buttons);
3626             this.updateText(opt.msg);
3627             if(opt.cls){
3628                 d.el.addClass(opt.cls);
3629             }
3630             d.proxyDrag = opt.proxyDrag === true;
3631             d.modal = opt.modal !== false;
3632             d.mask = opt.modal !== false ? mask : false;
3633             if(!d.isVisible()){
3634                 // force it to the end of the z-index stack so it gets a cursor in FF
3635                 document.body.appendChild(dlg.el.dom);
3636                 d.animateTarget = null;
3637                 d.show(options.animEl);
3638             }
3639             return this;
3640         },
3641
3642         /**
3643          * Displays a message box with a progress bar.  This message box has no buttons and is not closeable by
3644          * the user.  You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3645          * and closing the message box when the process is complete.
3646          * @param {String} title The title bar text
3647          * @param {String} msg The message box body text
3648          * @return {Roo.MessageBox} This message box
3649          */
3650         progress : function(title, msg){
3651             this.show({
3652                 title : title,
3653                 msg : msg,
3654                 buttons: false,
3655                 progress:true,
3656                 closable:false,
3657                 minWidth: this.minProgressWidth,
3658                 modal : true
3659             });
3660             return this;
3661         },
3662
3663         /**
3664          * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3665          * If a callback function is passed it will be called after the user clicks the button, and the
3666          * id of the button that was clicked will be passed as the only parameter to the callback
3667          * (could also be the top-right close button).
3668          * @param {String} title The title bar text
3669          * @param {String} msg The message box body text
3670          * @param {Function} fn (optional) The callback function invoked after the message box is closed
3671          * @param {Object} scope (optional) The scope of the callback function
3672          * @return {Roo.MessageBox} This message box
3673          */
3674         alert : function(title, msg, fn, scope)
3675         {
3676             this.show({
3677                 title : title,
3678                 msg : msg,
3679                 buttons: this.OK,
3680                 fn: fn,
3681                 closable : false,
3682                 scope : scope,
3683                 modal : true
3684             });
3685             return this;
3686         },
3687
3688         /**
3689          * Displays a message box with an infinitely auto-updating progress bar.  This can be used to block user
3690          * interaction while waiting for a long-running process to complete that does not have defined intervals.
3691          * You are responsible for closing the message box when the process is complete.
3692          * @param {String} msg The message box body text
3693          * @param {String} title (optional) The title bar text
3694          * @return {Roo.MessageBox} This message box
3695          */
3696         wait : function(msg, title){
3697             this.show({
3698                 title : title,
3699                 msg : msg,
3700                 buttons: false,
3701                 closable:false,
3702                 progress:true,
3703                 modal:true,
3704                 width:300,
3705                 wait:true
3706             });
3707             waitTimer = Roo.TaskMgr.start({
3708                 run: function(i){
3709                     Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3710                 },
3711                 interval: 1000
3712             });
3713             return this;
3714         },
3715
3716         /**
3717          * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3718          * If a callback function is passed it will be called after the user clicks either button, and the id of the
3719          * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3720          * @param {String} title The title bar text
3721          * @param {String} msg The message box body text
3722          * @param {Function} fn (optional) The callback function invoked after the message box is closed
3723          * @param {Object} scope (optional) The scope of the callback function
3724          * @return {Roo.MessageBox} This message box
3725          */
3726         confirm : function(title, msg, fn, scope){
3727             this.show({
3728                 title : title,
3729                 msg : msg,
3730                 buttons: this.YESNO,
3731                 fn: fn,
3732                 scope : scope,
3733                 modal : true
3734             });
3735             return this;
3736         },
3737
3738         /**
3739          * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3740          * JavaScript's Window.prompt).  The prompt can be a single-line or multi-line textbox.  If a callback function
3741          * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3742          * (could also be the top-right close button) and the text that was entered will be passed as the two
3743          * parameters to the callback.
3744          * @param {String} title The title bar text
3745          * @param {String} msg The message box body text
3746          * @param {Function} fn (optional) The callback function invoked after the message box is closed
3747          * @param {Object} scope (optional) The scope of the callback function
3748          * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3749          * property, or the height in pixels to create the textbox (defaults to false / single-line)
3750          * @return {Roo.MessageBox} This message box
3751          */
3752         prompt : function(title, msg, fn, scope, multiline){
3753             this.show({
3754                 title : title,
3755                 msg : msg,
3756                 buttons: this.OKCANCEL,
3757                 fn: fn,
3758                 minWidth:250,
3759                 scope : scope,
3760                 prompt:true,
3761                 multiline: multiline,
3762                 modal : true
3763             });
3764             return this;
3765         },
3766
3767         /**
3768          * Button config that displays a single OK button
3769          * @type Object
3770          */
3771         OK : {ok:true},
3772         /**
3773          * Button config that displays Yes and No buttons
3774          * @type Object
3775          */
3776         YESNO : {yes:true, no:true},
3777         /**
3778          * Button config that displays OK and Cancel buttons
3779          * @type Object
3780          */
3781         OKCANCEL : {ok:true, cancel:true},
3782         /**
3783          * Button config that displays Yes, No and Cancel buttons
3784          * @type Object
3785          */
3786         YESNOCANCEL : {yes:true, no:true, cancel:true},
3787
3788         /**
3789          * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3790          * @type Number
3791          */
3792         defaultTextHeight : 75,
3793         /**
3794          * The maximum width in pixels of the message box (defaults to 600)
3795          * @type Number
3796          */
3797         maxWidth : 600,
3798         /**
3799          * The minimum width in pixels of the message box (defaults to 100)
3800          * @type Number
3801          */
3802         minWidth : 100,
3803         /**
3804          * The minimum width in pixels of the message box if it is a progress-style dialog.  This is useful
3805          * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3806          * @type Number
3807          */
3808         minProgressWidth : 250,
3809         /**
3810          * An object containing the default button text strings that can be overriden for localized language support.
3811          * Supported properties are: ok, cancel, yes and no.
3812          * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3813          * @type Object
3814          */
3815         buttonText : {
3816             ok : "OK",
3817             cancel : "Cancel",
3818             yes : "Yes",
3819             no : "No"
3820         }
3821     };
3822 }();
3823
3824 /**
3825  * Shorthand for {@link Roo.MessageBox}
3826  */
3827 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3828 Roo.Msg = Roo.Msg || Roo.MessageBox;
3829 /*
3830  * - LGPL
3831  *
3832  * navbar
3833  * 
3834  */
3835
3836 /**
3837  * @class Roo.bootstrap.Navbar
3838  * @extends Roo.bootstrap.Component
3839  * Bootstrap Navbar class
3840
3841  * @constructor
3842  * Create a new Navbar
3843  * @param {Object} config The config object
3844  */
3845
3846
3847 Roo.bootstrap.Navbar = function(config){
3848     Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3849     this.addEvents({
3850         // raw events
3851         /**
3852          * @event beforetoggle
3853          * Fire before toggle the menu
3854          * @param {Roo.EventObject} e
3855          */
3856         "beforetoggle" : true
3857     });
3858 };
3859
3860 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component,  {
3861     
3862     
3863    
3864     // private
3865     navItems : false,
3866     loadMask : false,
3867     
3868     
3869     getAutoCreate : function(){
3870         
3871         
3872         throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3873         
3874     },
3875     
3876     initEvents :function ()
3877     {
3878         //Roo.log(this.el.select('.navbar-toggle',true));
3879         this.el.select('.navbar-toggle',true).on('click', function() {
3880             if(this.fireEvent('beforetoggle', this) !== false){
3881                 var ce = this.el.select('.navbar-collapse',true).first();
3882                 ce.toggleClass('in'); // old...
3883                 if (ce.hasClass('collapse')) {
3884                     // show it...
3885                     ce.removeClass('collapse');
3886                     ce.addClass('show');
3887                     var h = ce.getHeight();
3888                     Roo.log(h);
3889                     ce.removeClass('show');
3890                     // at this point we should be able to see it..
3891                     ce.addClass('collapsing');
3892                     
3893                     ce.setHeight(0); // resize it ...
3894                     ce.on('transitionend', function() {
3895                         Roo.log('done transition');
3896                         ce.removeClass('collapsing');
3897                         ce.addClass('show');
3898                         ce.removeClass('collapse');
3899
3900                         ce.dom.style.height = '';
3901                     }, this, { single: true} );
3902                     ce.setHeight(h);
3903                     
3904                 } else {
3905                     ce.setHeight(ce.getHeight());
3906                     ce.removeClass('show');
3907                     ce.addClass('collapsing');
3908                     
3909                     ce.on('transitionend', function() {
3910                         ce.dom.style.height = '';
3911                         ce.removeClass('collapsing');
3912                         ce.addClass('collapse');
3913                     }, this, { single: true} );
3914                     ce.setHeight(0);
3915                 }
3916             }
3917             
3918         }, this);
3919         
3920         var mark = {
3921             tag: "div",
3922             cls:"x-dlg-mask"
3923         };
3924         
3925         this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3926         
3927         var size = this.el.getSize();
3928         this.maskEl.setSize(size.width, size.height);
3929         this.maskEl.enableDisplayMode("block");
3930         this.maskEl.hide();
3931         
3932         if(this.loadMask){
3933             this.maskEl.show();
3934         }
3935     },
3936     
3937     
3938     getChildContainer : function()
3939     {
3940         if (this.el.select('.collapse').getCount()) {
3941             return this.el.select('.collapse',true).first();
3942         }
3943         
3944         return this.el;
3945     },
3946     
3947     mask : function()
3948     {
3949         this.maskEl.show();
3950     },
3951     
3952     unmask : function()
3953     {
3954         this.maskEl.hide();
3955     } 
3956     
3957     
3958     
3959     
3960 });
3961
3962
3963
3964  
3965
3966  /*
3967  * - LGPL
3968  *
3969  * navbar
3970  * 
3971  */
3972
3973 /**
3974  * @class Roo.bootstrap.NavSimplebar
3975  * @extends Roo.bootstrap.Navbar
3976  * Bootstrap Sidebar class
3977  *
3978  * @cfg {Boolean} inverse is inverted color
3979  * 
3980  * @cfg {String} type (nav | pills | tabs)
3981  * @cfg {Boolean} arrangement stacked | justified
3982  * @cfg {String} align (left | right) alignment
3983  * 
3984  * @cfg {Boolean} main (true|false) main nav bar? default false
3985  * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3986  * 
3987  * @cfg {String} tag (header|footer|nav|div) default is nav 
3988
3989  * @cfg {String} weight (light|primary|secondary|success|danger|warning|info|dark|white) default is light.
3990  * 
3991  * 
3992  * @constructor
3993  * Create a new Sidebar
3994  * @param {Object} config The config object
3995  */
3996
3997
3998 Roo.bootstrap.NavSimplebar = function(config){
3999     Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
4000 };
4001
4002 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar,  {
4003     
4004     inverse: false,
4005     
4006     type: false,
4007     arrangement: '',
4008     align : false,
4009     
4010     weight : 'light',
4011     
4012     main : false,
4013     
4014     
4015     tag : false,
4016     
4017     
4018     getAutoCreate : function(){
4019         
4020         
4021         var cfg = {
4022             tag : this.tag || 'div',
4023             cls : 'navbar navbar-expand-lg roo-navbar-simple'
4024         };
4025         if (['light','white'].indexOf(this.weight) > -1) {
4026             cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
4027         }
4028         cfg.cls += ' bg-' + this.weight;
4029         
4030         if (this.inverse) {
4031             cfg.cls += ' navbar-inverse';
4032             
4033         }
4034         
4035         // i'm not actually sure these are really used - normally we add a navGroup to a navbar
4036         
4037         //if (Roo.bootstrap.version == 4) {
4038         //    return cfg;
4039         //}
4040         
4041         cfg.cn = [
4042             {
4043                 cls: 'nav',
4044                 tag : 'ul'
4045             }
4046         ];
4047         
4048          
4049         this.type = this.type || 'nav';
4050         if (['tabs','pills'].indexOf(this.type) != -1) {
4051             cfg.cn[0].cls += ' nav-' + this.type
4052         
4053         
4054         } else {
4055             if (this.type!=='nav') {
4056                 Roo.log('nav type must be nav/tabs/pills')
4057             }
4058             cfg.cn[0].cls += ' navbar-nav'
4059         }
4060         
4061         
4062         
4063         
4064         if (['stacked','justified'].indexOf(this.arrangement) != -1) {
4065             cfg.cn[0].cls += ' nav-' + this.arrangement;
4066         }
4067         
4068         
4069         if (this.align === 'right') {
4070             cfg.cn[0].cls += ' navbar-right';
4071         }
4072         
4073         
4074         
4075         
4076         return cfg;
4077     
4078         
4079     }
4080     
4081     
4082     
4083 });
4084
4085
4086
4087  
4088
4089  
4090        /*
4091  * - LGPL
4092  *
4093  * navbar
4094  * navbar-fixed-top
4095  * navbar-expand-md  fixed-top 
4096  */
4097
4098 /**
4099  * @class Roo.bootstrap.NavHeaderbar
4100  * @extends Roo.bootstrap.NavSimplebar
4101  * Bootstrap Sidebar class
4102  *
4103  * @cfg {String} brand what is brand
4104  * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
4105  * @cfg {String} brand_href href of the brand
4106  * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button   default true
4107  * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
4108  * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
4109  * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
4110  * 
4111  * @constructor
4112  * Create a new Sidebar
4113  * @param {Object} config The config object
4114  */
4115
4116
4117 Roo.bootstrap.NavHeaderbar = function(config){
4118     Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
4119       
4120 };
4121
4122 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar,  {
4123     
4124     position: '',
4125     brand: '',
4126     brand_href: false,
4127     srButton : true,
4128     autohide : false,
4129     desktopCenter : false,
4130    
4131     
4132     getAutoCreate : function(){
4133         
4134         var   cfg = {
4135             tag: this.nav || 'nav',
4136             cls: 'navbar navbar-expand-md',
4137             role: 'navigation',
4138             cn: []
4139         };
4140         
4141         var cn = cfg.cn;
4142         if (this.desktopCenter) {
4143             cn.push({cls : 'container', cn : []});
4144             cn = cn[0].cn;
4145         }
4146         
4147         if(this.srButton){
4148             var btn = {
4149                 tag: 'button',
4150                 type: 'button',
4151                 cls: 'navbar-toggle navbar-toggler',
4152                 'data-toggle': 'collapse',
4153                 cn: [
4154                     {
4155                         tag: 'span',
4156                         cls: 'sr-only',
4157                         html: 'Toggle navigation'
4158                     },
4159                     {
4160                         tag: 'span',
4161                         cls: 'icon-bar navbar-toggler-icon'
4162                     },
4163                     {
4164                         tag: 'span',
4165                         cls: 'icon-bar'
4166                     },
4167                     {
4168                         tag: 'span',
4169                         cls: 'icon-bar'
4170                     }
4171                 ]
4172             };
4173             
4174             cn.push( Roo.bootstrap.version == 4 ? btn : {
4175                 tag: 'div',
4176                 cls: 'navbar-header',
4177                 cn: [
4178                     btn
4179                 ]
4180             });
4181         }
4182         
4183         cn.push({
4184             tag: 'div',
4185             cls: 'collapse navbar-collapse',
4186             cn : []
4187         });
4188         
4189         cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
4190         
4191         if (['light','white'].indexOf(this.weight) > -1) {
4192             cfg.cls += ['light','white'].indexOf(this.weight) > -1 ? ' navbar-light' : ' navbar-dark';
4193         }
4194         cfg.cls += ' bg-' + this.weight;
4195         
4196         
4197         if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
4198             cfg.cls += ' navbar-' + this.position + ' ' + this.position ;
4199             
4200             // tag can override this..
4201             
4202             cfg.tag = this.tag || (this.position  == 'fixed-bottom' ? 'footer' : 'header');
4203         }
4204         
4205         if (this.brand !== '') {
4206             var cp =  Roo.bootstrap.version == 4 ? cn : cn[0].cn;
4207             cp.unshift({ // changed from push ?? BS4 needs it at the start? - does this break or exsiting?
4208                 tag: 'a',
4209                 href: this.brand_href ? this.brand_href : '#',
4210                 cls: 'navbar-brand',
4211                 cn: [
4212                 this.brand
4213                 ]
4214             });
4215         }
4216         
4217         if(this.main){
4218             cfg.cls += ' main-nav';
4219         }
4220         
4221         
4222         return cfg;
4223
4224         
4225     },
4226     getHeaderChildContainer : function()
4227     {
4228         if (this.srButton && this.el.select('.navbar-header').getCount()) {
4229             return this.el.select('.navbar-header',true).first();
4230         }
4231         
4232         return this.getChildContainer();
4233     },
4234     
4235     
4236     initEvents : function()
4237     {
4238         Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
4239         
4240         if (this.autohide) {
4241             
4242             var prevScroll = 0;
4243             var ft = this.el;
4244             
4245             Roo.get(document).on('scroll',function(e) {
4246                 var ns = Roo.get(document).getScroll().top;
4247                 var os = prevScroll;
4248                 prevScroll = ns;
4249                 
4250                 if(ns > os){
4251                     ft.removeClass('slideDown');
4252                     ft.addClass('slideUp');
4253                     return;
4254                 }
4255                 ft.removeClass('slideUp');
4256                 ft.addClass('slideDown');
4257                  
4258               
4259           },this);
4260         }
4261     }    
4262     
4263 });
4264
4265
4266
4267  
4268
4269  /*
4270  * - LGPL
4271  *
4272  * navbar
4273  * 
4274  */
4275
4276 /**
4277  * @class Roo.bootstrap.NavSidebar
4278  * @extends Roo.bootstrap.Navbar
4279  * Bootstrap Sidebar class
4280  * 
4281  * @constructor
4282  * Create a new Sidebar
4283  * @param {Object} config The config object
4284  */
4285
4286
4287 Roo.bootstrap.NavSidebar = function(config){
4288     Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
4289 };
4290
4291 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar,  {
4292     
4293     sidebar : true, // used by Navbar Item and NavbarGroup at present...
4294     
4295     getAutoCreate : function(){
4296         
4297         
4298         return  {
4299             tag: 'div',
4300             cls: 'sidebar sidebar-nav'
4301         };
4302     
4303         
4304     }
4305     
4306     
4307     
4308 });
4309
4310
4311
4312  
4313
4314  /*
4315  * - LGPL
4316  *
4317  * nav group
4318  * 
4319  */
4320
4321 /**
4322  * @class Roo.bootstrap.NavGroup
4323  * @extends Roo.bootstrap.Component
4324  * Bootstrap NavGroup class
4325  * @cfg {String} align (left|right)
4326  * @cfg {Boolean} inverse
4327  * @cfg {String} type (nav|pills|tab) default nav
4328  * @cfg {String} navId - reference Id for navbar.
4329
4330  * 
4331  * @constructor
4332  * Create a new nav group
4333  * @param {Object} config The config object
4334  */
4335
4336 Roo.bootstrap.NavGroup = function(config){
4337     Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
4338     this.navItems = [];
4339    
4340     Roo.bootstrap.NavGroup.register(this);
4341      this.addEvents({
4342         /**
4343              * @event changed
4344              * Fires when the active item changes
4345              * @param {Roo.bootstrap.NavGroup} this
4346              * @param {Roo.bootstrap.Navbar.Item} selected The item selected
4347              * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item 
4348          */
4349         'changed': true
4350      });
4351     
4352 };
4353
4354 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component,  {
4355     
4356     align: '',
4357     inverse: false,
4358     form: false,
4359     type: 'nav',
4360     navId : '',
4361     // private
4362     
4363     navItems : false, 
4364     
4365     getAutoCreate : function()
4366     {
4367         var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4368         
4369         cfg = {
4370             tag : 'ul',
4371             cls: 'nav' 
4372         };
4373         if (Roo.bootstrap.version == 4) {
4374             if (['tabs','pills'].indexOf(this.type) != -1) {
4375                 cfg.cls += ' nav-' + this.type; 
4376             } else {
4377                 cfg.cls += ' navbar-nav';
4378             }
4379         } else {
4380             if (['tabs','pills'].indexOf(this.type) != -1) {
4381                 cfg.cls += ' nav-' + this.type
4382             } else {
4383                 if (this.type !== 'nav') {
4384                     Roo.log('nav type must be nav/tabs/pills')
4385                 }
4386                 cfg.cls += ' navbar-nav'
4387             }
4388         }
4389         
4390         if (this.parent() && this.parent().sidebar) {
4391             cfg = {
4392                 tag: 'ul',
4393                 cls: 'dashboard-menu sidebar-menu'
4394             };
4395             
4396             return cfg;
4397         }
4398         
4399         if (this.form === true) {
4400             cfg = {
4401                 tag: 'form',
4402                 cls: 'navbar-form form-inline'
4403             };
4404             
4405             if (this.align === 'right') {
4406                 cfg.cls += ' navbar-right ml-md-auto';
4407             } else {
4408                 cfg.cls += ' navbar-left';
4409             }
4410         }
4411         
4412         if (this.align === 'right') {
4413             cfg.cls += ' navbar-right ml-md-auto';
4414         } else {
4415             cfg.cls += ' mr-auto';
4416         }
4417         
4418         if (this.inverse) {
4419             cfg.cls += ' navbar-inverse';
4420             
4421         }
4422         
4423         
4424         return cfg;
4425     },
4426     /**
4427     * sets the active Navigation item
4428     * @param {Roo.bootstrap.NavItem} the new current navitem
4429     */
4430     setActiveItem : function(item)
4431     {
4432         var prev = false;
4433         Roo.each(this.navItems, function(v){
4434             if (v == item) {
4435                 return ;
4436             }
4437             if (v.isActive()) {
4438                 v.setActive(false, true);
4439                 prev = v;
4440                 
4441             }
4442             
4443         });
4444
4445         item.setActive(true, true);
4446         this.fireEvent('changed', this, item, prev);
4447         
4448         
4449     },
4450     /**
4451     * gets the active Navigation item
4452     * @return {Roo.bootstrap.NavItem} the current navitem
4453     */
4454     getActive : function()
4455     {
4456         
4457         var prev = false;
4458         Roo.each(this.navItems, function(v){
4459             
4460             if (v.isActive()) {
4461                 prev = v;
4462                 
4463             }
4464             
4465         });
4466         return prev;
4467     },
4468     
4469     indexOfNav : function()
4470     {
4471         
4472         var prev = false;
4473         Roo.each(this.navItems, function(v,i){
4474             
4475             if (v.isActive()) {
4476                 prev = i;
4477                 
4478             }
4479             
4480         });
4481         return prev;
4482     },
4483     /**
4484     * adds a Navigation item
4485     * @param {Roo.bootstrap.NavItem} the navitem to add
4486     */
4487     addItem : function(cfg)
4488     {
4489         if (this.form && Roo.bootstrap.version == 4) {
4490             cfg.tag = 'div';
4491         }
4492         var cn = new Roo.bootstrap.NavItem(cfg);
4493         this.register(cn);
4494         cn.parentId = this.id;
4495         cn.onRender(this.el, null);
4496         return cn;
4497     },
4498     /**
4499     * register a Navigation item
4500     * @param {Roo.bootstrap.NavItem} the navitem to add
4501     */
4502     register : function(item)
4503     {
4504         this.navItems.push( item);
4505         item.navId = this.navId;
4506     
4507     },
4508     
4509     /**
4510     * clear all the Navigation item
4511     */
4512    
4513     clearAll : function()
4514     {
4515         this.navItems = [];
4516         this.el.dom.innerHTML = '';
4517     },
4518     
4519     getNavItem: function(tabId)
4520     {
4521         var ret = false;
4522         Roo.each(this.navItems, function(e) {
4523             if (e.tabId == tabId) {
4524                ret =  e;
4525                return false;
4526             }
4527             return true;
4528             
4529         });
4530         return ret;
4531     },
4532     
4533     setActiveNext : function()
4534     {
4535         var i = this.indexOfNav(this.getActive());
4536         if (i > this.navItems.length) {
4537             return;
4538         }
4539         this.setActiveItem(this.navItems[i+1]);
4540     },
4541     setActivePrev : function()
4542     {
4543         var i = this.indexOfNav(this.getActive());
4544         if (i  < 1) {
4545             return;
4546         }
4547         this.setActiveItem(this.navItems[i-1]);
4548     },
4549     clearWasActive : function(except) {
4550         Roo.each(this.navItems, function(e) {
4551             if (e.tabId != except.tabId && e.was_active) {
4552                e.was_active = false;
4553                return false;
4554             }
4555             return true;
4556             
4557         });
4558     },
4559     getWasActive : function ()
4560     {
4561         var r = false;
4562         Roo.each(this.navItems, function(e) {
4563             if (e.was_active) {
4564                r = e;
4565                return false;
4566             }
4567             return true;
4568             
4569         });
4570         return r;
4571     }
4572     
4573     
4574 });
4575
4576  
4577 Roo.apply(Roo.bootstrap.NavGroup, {
4578     
4579     groups: {},
4580      /**
4581     * register a Navigation Group
4582     * @param {Roo.bootstrap.NavGroup} the navgroup to add
4583     */
4584     register : function(navgrp)
4585     {
4586         this.groups[navgrp.navId] = navgrp;
4587         
4588     },
4589     /**
4590     * fetch a Navigation Group based on the navigation ID
4591     * @param {string} the navgroup to add
4592     * @returns {Roo.bootstrap.NavGroup} the navgroup 
4593     */
4594     get: function(navId) {
4595         if (typeof(this.groups[navId]) == 'undefined') {
4596             return false;
4597             //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4598         }
4599         return this.groups[navId] ;
4600     }
4601     
4602     
4603     
4604 });
4605
4606  /*
4607  * - LGPL
4608  *
4609  * row
4610  * 
4611  */
4612
4613 /**
4614  * @class Roo.bootstrap.NavItem
4615  * @extends Roo.bootstrap.Component
4616  * Bootstrap Navbar.NavItem class
4617  * @cfg {String} href  link to
4618  * @cfg {String} html content of button
4619  * @cfg {String} badge text inside badge
4620  * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4621  * @cfg {String} glyphicon DEPRICATED - use fa
4622  * @cfg {String} icon DEPRICATED - use fa
4623  * @cfg {String} fa - Fontawsome icon name (can add stuff to it like fa-2x)
4624  * @cfg {Boolean} active Is item active
4625  * @cfg {Boolean} disabled Is item disabled
4626  
4627  * @cfg {Boolean} preventDefault (true | false) default false
4628  * @cfg {String} tabId the tab that this item activates.
4629  * @cfg {String} tagtype (a|span) render as a href or span?
4630  * @cfg {Boolean} animateRef (true|false) link to element default false  
4631   
4632  * @constructor
4633  * Create a new Navbar Item
4634  * @param {Object} config The config object
4635  */
4636 Roo.bootstrap.NavItem = function(config){
4637     Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4638     this.addEvents({
4639         // raw events
4640         /**
4641          * @event click
4642          * The raw click event for the entire grid.
4643          * @param {Roo.EventObject} e
4644          */
4645         "click" : true,
4646          /**
4647             * @event changed
4648             * Fires when the active item active state changes
4649             * @param {Roo.bootstrap.NavItem} this
4650             * @param {boolean} state the new state
4651              
4652          */
4653         'changed': true,
4654         /**
4655             * @event scrollto
4656             * Fires when scroll to element
4657             * @param {Roo.bootstrap.NavItem} this
4658             * @param {Object} options
4659             * @param {Roo.EventObject} e
4660              
4661          */
4662         'scrollto': true
4663     });
4664    
4665 };
4666
4667 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component,  {
4668     
4669     href: false,
4670     html: '',
4671     badge: '',
4672     icon: false,
4673     fa : false,
4674     glyphicon: false,
4675     active: false,
4676     preventDefault : false,
4677     tabId : false,
4678     tagtype : 'a',
4679     tag: 'li',
4680     disabled : false,
4681     animateRef : false,
4682     was_active : false,
4683     
4684     navLink: false,
4685     
4686     getAutoCreate : function(){
4687          
4688         var cfg = {
4689             tag: this.tag,
4690             cls: 'nav-item'
4691             
4692         };
4693         
4694         if (this.active) {
4695             cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4696         }
4697         if (this.disabled) {
4698             cfg.cls += ' disabled';
4699         }
4700         
4701         if (this.href || this.html || this.glyphicon || this.icon || this.fa) {
4702             cfg.cn = [
4703                 {
4704                     tag: this.tagtype,
4705                     href : this.href || "#",
4706                     html: this.html || ''
4707                 }
4708             ];
4709             if (this.tagtype == 'a') {
4710                 cfg.cn[0].cls = 'nav-link';
4711             }
4712             if (this.icon) {
4713                 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4714             }
4715             if (this.fa) {
4716                 cfg.cn[0].html = '<i class="fa fas fa-'+this.fa+'"></i> <span>' + cfg.cn[0].html + '</span>'
4717             }
4718             if(this.glyphicon) {
4719                 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> '  + cfg.cn[0].html;
4720             }
4721             
4722             if (this.menu) {
4723                 
4724                 cfg.cn[0].html += " <span class='caret'></span>";
4725              
4726             }
4727             
4728             if (this.badge !== '') {
4729                  
4730                 cfg.cn[0].html += ' <span class="badge badge-secondary">' + this.badge + '</span>';
4731             }
4732         }
4733         
4734         
4735         
4736         return cfg;
4737     },
4738     onRender : function(ct, position)
4739     {
4740        // Roo.log("Call onRender: " + this.xtype);
4741         if (Roo.bootstrap.version == 4 && ct.dom.type != 'ul') {
4742             this.tag = 'div';
4743         }
4744         
4745         var ret = Roo.bootstrap.NavItem.superclass.onRender.call(this, ct, position);
4746         this.navLink = this.el.select('nav-link').first();
4747         return ret;
4748     },
4749       
4750     
4751     initEvents: function() 
4752     {
4753         if (typeof (this.menu) != 'undefined') {
4754             this.menu.parentType = this.xtype;
4755             this.menu.triggerEl = this.el;
4756             this.menu = this.addxtype(Roo.apply({}, this.menu));
4757         }
4758         
4759         this.el.select('a',true).on('click', this.onClick, this);
4760         
4761         if(this.tagtype == 'span'){
4762             this.el.select('span',true).on('click', this.onClick, this);
4763         }
4764        
4765         // at this point parent should be available..
4766         this.parent().register(this);
4767     },
4768     
4769     onClick : function(e)
4770     {
4771         if (e.getTarget('.dropdown-menu-item')) {
4772             // did you click on a menu itemm.... - then don't trigger onclick..
4773             return;
4774         }
4775         
4776         if(
4777                 this.preventDefault || 
4778                 this.href == '#' 
4779         ){
4780             Roo.log("NavItem - prevent Default?");
4781             e.preventDefault();
4782         }
4783         
4784         if (this.disabled) {
4785             return;
4786         }
4787         
4788         var tg = Roo.bootstrap.TabGroup.get(this.navId);
4789         if (tg && tg.transition) {
4790             Roo.log("waiting for the transitionend");
4791             return;
4792         }
4793         
4794         
4795         
4796         //Roo.log("fire event clicked");
4797         if(this.fireEvent('click', this, e) === false){
4798             return;
4799         };
4800         
4801         if(this.tagtype == 'span'){
4802             return;
4803         }
4804         
4805         //Roo.log(this.href);
4806         var ael = this.el.select('a',true).first();
4807         //Roo.log(ael);
4808         
4809         if(ael && this.animateRef && this.href.indexOf('#') > -1){
4810             //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4811             if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4812                 return; // ignore... - it's a 'hash' to another page.
4813             }
4814             Roo.log("NavItem - prevent Default?");
4815             e.preventDefault();
4816             this.scrollToElement(e);
4817         }
4818         
4819         
4820         var p =  this.parent();
4821    
4822         if (['tabs','pills'].indexOf(p.type)!==-1) {
4823             if (typeof(p.setActiveItem) !== 'undefined') {
4824                 p.setActiveItem(this);
4825             }
4826         }
4827         
4828         // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4829         if (p.parentType == 'NavHeaderbar' && !this.menu) {
4830             // remove the collapsed menu expand...
4831             p.parent().el.select('.navbar-collapse',true).removeClass('in');  
4832         }
4833     },
4834     
4835     isActive: function () {
4836         return this.active
4837     },
4838     setActive : function(state, fire, is_was_active)
4839     {
4840         if (this.active && !state && this.navId) {
4841             this.was_active = true;
4842             var nv = Roo.bootstrap.NavGroup.get(this.navId);
4843             if (nv) {
4844                 nv.clearWasActive(this);
4845             }
4846             
4847         }
4848         this.active = state;
4849         
4850         if (!state ) {
4851             this.el.removeClass('active');
4852             this.navLink ? this.navLink.removeClass('active') : false;
4853         } else if (!this.el.hasClass('active')) {
4854             
4855             this.el.addClass('active');
4856             if (Roo.bootstrap.version == 4 && this.navLink ) {
4857                 this.navLink.addClass('active');
4858             }
4859             
4860         }
4861         if (fire) {
4862             this.fireEvent('changed', this, state);
4863         }
4864         
4865         // show a panel if it's registered and related..
4866         
4867         if (!this.navId || !this.tabId || !state || is_was_active) {
4868             return;
4869         }
4870         
4871         var tg = Roo.bootstrap.TabGroup.get(this.navId);
4872         if (!tg) {
4873             return;
4874         }
4875         var pan = tg.getPanelByName(this.tabId);
4876         if (!pan) {
4877             return;
4878         }
4879         // if we can not flip to new panel - go back to old nav highlight..
4880         if (false == tg.showPanel(pan)) {
4881             var nv = Roo.bootstrap.NavGroup.get(this.navId);
4882             if (nv) {
4883                 var onav = nv.getWasActive();
4884                 if (onav) {
4885                     onav.setActive(true, false, true);
4886                 }
4887             }
4888             
4889         }
4890         
4891         
4892         
4893     },
4894      // this should not be here...
4895     setDisabled : function(state)
4896     {
4897         this.disabled = state;
4898         if (!state ) {
4899             this.el.removeClass('disabled');
4900         } else if (!this.el.hasClass('disabled')) {
4901             this.el.addClass('disabled');
4902         }
4903         
4904     },
4905     
4906     /**
4907      * Fetch the element to display the tooltip on.
4908      * @return {Roo.Element} defaults to this.el
4909      */
4910     tooltipEl : function()
4911     {
4912         return this.el.select('' + this.tagtype + '', true).first();
4913     },
4914     
4915     scrollToElement : function(e)
4916     {
4917         var c = document.body;
4918         
4919         /*
4920          * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4921          */
4922         if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4923             c = document.documentElement;
4924         }
4925         
4926         var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4927         
4928         if(!target){
4929             return;
4930         }
4931
4932         var o = target.calcOffsetsTo(c);
4933         
4934         var options = {
4935             target : target,
4936             value : o[1]
4937         };
4938         
4939         this.fireEvent('scrollto', this, options, e);
4940         
4941         Roo.get(c).scrollTo('top', options.value, true);
4942         
4943         return;
4944     }
4945 });
4946  
4947
4948  /*
4949  * - LGPL
4950  *
4951  * sidebar item
4952  *
4953  *  li
4954  *    <span> icon </span>
4955  *    <span> text </span>
4956  *    <span>badge </span>
4957  */
4958
4959 /**
4960  * @class Roo.bootstrap.NavSidebarItem
4961  * @extends Roo.bootstrap.NavItem
4962  * Bootstrap Navbar.NavSidebarItem class
4963  * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4964  * {Boolean} open is the menu open
4965  * {Boolean} buttonView use button as the tigger el rather that a (default false)
4966  * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
4967  * {String} buttonSize (sm|md|lg)the extra classes for the button
4968  * {Boolean} showArrow show arrow next to the text (default true)
4969  * @constructor
4970  * Create a new Navbar Button
4971  * @param {Object} config The config object
4972  */
4973 Roo.bootstrap.NavSidebarItem = function(config){
4974     Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4975     this.addEvents({
4976         // raw events
4977         /**
4978          * @event click
4979          * The raw click event for the entire grid.
4980          * @param {Roo.EventObject} e
4981          */
4982         "click" : true,
4983          /**
4984             * @event changed
4985             * Fires when the active item active state changes
4986             * @param {Roo.bootstrap.NavSidebarItem} this
4987             * @param {boolean} state the new state
4988              
4989          */
4990         'changed': true
4991     });
4992    
4993 };
4994
4995 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem,  {
4996     
4997     badgeWeight : 'default',
4998     
4999     open: false,
5000     
5001     buttonView : false,
5002     
5003     buttonWeight : 'default',
5004     
5005     buttonSize : 'md',
5006     
5007     showArrow : true,
5008     
5009     getAutoCreate : function(){
5010         
5011         
5012         var a = {
5013                 tag: 'a',
5014                 href : this.href || '#',
5015                 cls: '',
5016                 html : '',
5017                 cn : []
5018         };
5019         
5020         if(this.buttonView){
5021             a = {
5022                 tag: 'button',
5023                 href : this.href || '#',
5024                 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
5025                 html : this.html,
5026                 cn : []
5027             };
5028         }
5029         
5030         var cfg = {
5031             tag: 'li',
5032             cls: '',
5033             cn: [ a ]
5034         };
5035         
5036         if (this.active) {
5037             cfg.cls += ' active';
5038         }
5039         
5040         if (this.disabled) {
5041             cfg.cls += ' disabled';
5042         }
5043         if (this.open) {
5044             cfg.cls += ' open x-open';
5045         }
5046         // left icon..
5047         if (this.glyphicon || this.icon) {
5048             var c = this.glyphicon  ? ('glyphicon glyphicon-'+this.glyphicon)  : this.icon;
5049             a.cn.push({ tag : 'i', cls : c }) ;
5050         }
5051         
5052         if(!this.buttonView){
5053             var span = {
5054                 tag: 'span',
5055                 html : this.html || ''
5056             };
5057
5058             a.cn.push(span);
5059             
5060         }
5061         
5062         if (this.badge !== '') {
5063             a.cn.push({ tag: 'span',  cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge }); 
5064         }
5065         
5066         if (this.menu) {
5067             
5068             if(this.showArrow){
5069                 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
5070             }
5071             
5072             a.cls += ' dropdown-toggle treeview' ;
5073         }
5074         
5075         return cfg;
5076     },
5077     
5078     initEvents : function()
5079     { 
5080         if (typeof (this.menu) != 'undefined') {
5081             this.menu.parentType = this.xtype;
5082             this.menu.triggerEl = this.el;
5083             this.menu = this.addxtype(Roo.apply({}, this.menu));
5084         }
5085         
5086         this.el.on('click', this.onClick, this);
5087         
5088         if(this.badge !== ''){
5089             this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
5090         }
5091         
5092     },
5093     
5094     onClick : function(e)
5095     {
5096         if(this.disabled){
5097             e.preventDefault();
5098             return;
5099         }
5100         
5101         if(this.preventDefault){
5102             e.preventDefault();
5103         }
5104         
5105         this.fireEvent('click', this);
5106     },
5107     
5108     disable : function()
5109     {
5110         this.setDisabled(true);
5111     },
5112     
5113     enable : function()
5114     {
5115         this.setDisabled(false);
5116     },
5117     
5118     setDisabled : function(state)
5119     {
5120         if(this.disabled == state){
5121             return;
5122         }
5123         
5124         this.disabled = state;
5125         
5126         if (state) {
5127             this.el.addClass('disabled');
5128             return;
5129         }
5130         
5131         this.el.removeClass('disabled');
5132         
5133         return;
5134     },
5135     
5136     setActive : function(state)
5137     {
5138         if(this.active == state){
5139             return;
5140         }
5141         
5142         this.active = state;
5143         
5144         if (state) {
5145             this.el.addClass('active');
5146             return;
5147         }
5148         
5149         this.el.removeClass('active');
5150         
5151         return;
5152     },
5153     
5154     isActive: function () 
5155     {
5156         return this.active;
5157     },
5158     
5159     setBadge : function(str)
5160     {
5161         if(!this.badgeEl){
5162             return;
5163         }
5164         
5165         this.badgeEl.dom.innerHTML = str;
5166     }
5167     
5168    
5169      
5170  
5171 });
5172  
5173
5174  /*
5175  * - LGPL
5176  *
5177  * row
5178  * 
5179  */
5180
5181 /**
5182  * @class Roo.bootstrap.Row
5183  * @extends Roo.bootstrap.Component
5184  * Bootstrap Row class (contains columns...)
5185  * 
5186  * @constructor
5187  * Create a new Row
5188  * @param {Object} config The config object
5189  */
5190
5191 Roo.bootstrap.Row = function(config){
5192     Roo.bootstrap.Row.superclass.constructor.call(this, config);
5193 };
5194
5195 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component,  {
5196     
5197     getAutoCreate : function(){
5198        return {
5199             cls: 'row clearfix'
5200        };
5201     }
5202     
5203     
5204 });
5205
5206  
5207
5208  /*
5209  * - LGPL
5210  *
5211  * element
5212  * 
5213  */
5214
5215 /**
5216  * @class Roo.bootstrap.Element
5217  * @extends Roo.bootstrap.Component
5218  * Bootstrap Element class
5219  * @cfg {String} html contents of the element
5220  * @cfg {String} tag tag of the element
5221  * @cfg {String} cls class of the element
5222  * @cfg {Boolean} preventDefault (true|false) default false
5223  * @cfg {Boolean} clickable (true|false) default false
5224  * 
5225  * @constructor
5226  * Create a new Element
5227  * @param {Object} config The config object
5228  */
5229
5230 Roo.bootstrap.Element = function(config){
5231     Roo.bootstrap.Element.superclass.constructor.call(this, config);
5232     
5233     this.addEvents({
5234         // raw events
5235         /**
5236          * @event click
5237          * When a element is chick
5238          * @param {Roo.bootstrap.Element} this
5239          * @param {Roo.EventObject} e
5240          */
5241         "click" : true
5242     });
5243 };
5244
5245 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component,  {
5246     
5247     tag: 'div',
5248     cls: '',
5249     html: '',
5250     preventDefault: false, 
5251     clickable: false,
5252     
5253     getAutoCreate : function(){
5254         
5255         var cfg = {
5256             tag: this.tag,
5257             // cls: this.cls, double assign in parent class Component.js :: onRender
5258             html: this.html
5259         };
5260         
5261         return cfg;
5262     },
5263     
5264     initEvents: function() 
5265     {
5266         Roo.bootstrap.Element.superclass.initEvents.call(this);
5267         
5268         if(this.clickable){
5269             this.el.on('click', this.onClick, this);
5270         }
5271         
5272     },
5273     
5274     onClick : function(e)
5275     {
5276         if(this.preventDefault){
5277             e.preventDefault();
5278         }
5279         
5280         this.fireEvent('click', this, e);
5281     },
5282     
5283     getValue : function()
5284     {
5285         return this.el.dom.innerHTML;
5286     },
5287     
5288     setValue : function(value)
5289     {
5290         this.el.dom.innerHTML = value;
5291     }
5292    
5293 });
5294
5295  
5296
5297  /*
5298  * - LGPL
5299  *
5300  * pagination
5301  * 
5302  */
5303
5304 /**
5305  * @class Roo.bootstrap.Pagination
5306  * @extends Roo.bootstrap.Component
5307  * Bootstrap Pagination class
5308  * @cfg {String} size xs | sm | md | lg
5309  * @cfg {Boolean} inverse false | true
5310  * 
5311  * @constructor
5312  * Create a new Pagination
5313  * @param {Object} config The config object
5314  */
5315
5316 Roo.bootstrap.Pagination = function(config){
5317     Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
5318 };
5319
5320 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component,  {
5321     
5322     cls: false,
5323     size: false,
5324     inverse: false,
5325     
5326     getAutoCreate : function(){
5327         var cfg = {
5328             tag: 'ul',
5329                 cls: 'pagination'
5330         };
5331         if (this.inverse) {
5332             cfg.cls += ' inverse';
5333         }
5334         if (this.html) {
5335             cfg.html=this.html;
5336         }
5337         if (this.cls) {
5338             cfg.cls += " " + this.cls;
5339         }
5340         return cfg;
5341     }
5342    
5343 });
5344
5345  
5346
5347  /*
5348  * - LGPL
5349  *
5350  * Pagination item
5351  * 
5352  */
5353
5354
5355 /**
5356  * @class Roo.bootstrap.PaginationItem
5357  * @extends Roo.bootstrap.Component
5358  * Bootstrap PaginationItem class
5359  * @cfg {String} html text
5360  * @cfg {String} href the link
5361  * @cfg {Boolean} preventDefault (true | false) default true
5362  * @cfg {Boolean} active (true | false) default false
5363  * @cfg {Boolean} disabled default false
5364  * 
5365  * 
5366  * @constructor
5367  * Create a new PaginationItem
5368  * @param {Object} config The config object
5369  */
5370
5371
5372 Roo.bootstrap.PaginationItem = function(config){
5373     Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
5374     this.addEvents({
5375         // raw events
5376         /**
5377          * @event click
5378          * The raw click event for the entire grid.
5379          * @param {Roo.EventObject} e
5380          */
5381         "click" : true
5382     });
5383 };
5384
5385 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component,  {
5386     
5387     href : false,
5388     html : false,
5389     preventDefault: true,
5390     active : false,
5391     cls : false,
5392     disabled: false,
5393     
5394     getAutoCreate : function(){
5395         var cfg= {
5396             tag: 'li',
5397             cn: [
5398                 {
5399                     tag : 'a',
5400                     href : this.href ? this.href : '#',
5401                     html : this.html ? this.html : ''
5402                 }
5403             ]
5404         };
5405         
5406         if(this.cls){
5407             cfg.cls = this.cls;
5408         }
5409         
5410         if(this.disabled){
5411             cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
5412         }
5413         
5414         if(this.active){
5415             cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5416         }
5417         
5418         return cfg;
5419     },
5420     
5421     initEvents: function() {
5422         
5423         this.el.on('click', this.onClick, this);
5424         
5425     },
5426     onClick : function(e)
5427     {
5428         Roo.log('PaginationItem on click ');
5429         if(this.preventDefault){
5430             e.preventDefault();
5431         }
5432         
5433         if(this.disabled){
5434             return;
5435         }
5436         
5437         this.fireEvent('click', this, e);
5438     }
5439    
5440 });
5441
5442  
5443
5444  /*
5445  * - LGPL
5446  *
5447  * slider
5448  * 
5449  */
5450
5451
5452 /**
5453  * @class Roo.bootstrap.Slider
5454  * @extends Roo.bootstrap.Component
5455  * Bootstrap Slider class
5456  *    
5457  * @constructor
5458  * Create a new Slider
5459  * @param {Object} config The config object
5460  */
5461
5462 Roo.bootstrap.Slider = function(config){
5463     Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5464 };
5465
5466 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component,  {
5467     
5468     getAutoCreate : function(){
5469         
5470         var cfg = {
5471             tag: 'div',
5472             cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5473             cn: [
5474                 {
5475                     tag: 'a',
5476                     cls: 'ui-slider-handle ui-state-default ui-corner-all'
5477                 }
5478             ]
5479         };
5480         
5481         return cfg;
5482     }
5483    
5484 });
5485
5486  /*
5487  * Based on:
5488  * Ext JS Library 1.1.1
5489  * Copyright(c) 2006-2007, Ext JS, LLC.
5490  *
5491  * Originally Released Under LGPL - original licence link has changed is not relivant.
5492  *
5493  * Fork - LGPL
5494  * <script type="text/javascript">
5495  */
5496  
5497
5498 /**
5499  * @class Roo.grid.ColumnModel
5500  * @extends Roo.util.Observable
5501  * This is the default implementation of a ColumnModel used by the Grid. It defines
5502  * the columns in the grid.
5503  * <br>Usage:<br>
5504  <pre><code>
5505  var colModel = new Roo.grid.ColumnModel([
5506         {header: "Ticker", width: 60, sortable: true, locked: true},
5507         {header: "Company Name", width: 150, sortable: true},
5508         {header: "Market Cap.", width: 100, sortable: true},
5509         {header: "$ Sales", width: 100, sortable: true, renderer: money},
5510         {header: "Employees", width: 100, sortable: true, resizable: false}
5511  ]);
5512  </code></pre>
5513  * <p>
5514  
5515  * The config options listed for this class are options which may appear in each
5516  * individual column definition.
5517  * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5518  * @constructor
5519  * @param {Object} config An Array of column config objects. See this class's
5520  * config objects for details.
5521 */
5522 Roo.grid.ColumnModel = function(config){
5523         /**
5524      * The config passed into the constructor
5525      */
5526     this.config = config;
5527     this.lookup = {};
5528
5529     // if no id, create one
5530     // if the column does not have a dataIndex mapping,
5531     // map it to the order it is in the config
5532     for(var i = 0, len = config.length; i < len; i++){
5533         var c = config[i];
5534         if(typeof c.dataIndex == "undefined"){
5535             c.dataIndex = i;
5536         }
5537         if(typeof c.renderer == "string"){
5538             c.renderer = Roo.util.Format[c.renderer];
5539         }
5540         if(typeof c.id == "undefined"){
5541             c.id = Roo.id();
5542         }
5543         if(c.editor && c.editor.xtype){
5544             c.editor  = Roo.factory(c.editor, Roo.grid);
5545         }
5546         if(c.editor && c.editor.isFormField){
5547             c.editor = new Roo.grid.GridEditor(c.editor);
5548         }
5549         this.lookup[c.id] = c;
5550     }
5551
5552     /**
5553      * The width of columns which have no width specified (defaults to 100)
5554      * @type Number
5555      */
5556     this.defaultWidth = 100;
5557
5558     /**
5559      * Default sortable of columns which have no sortable specified (defaults to false)
5560      * @type Boolean
5561      */
5562     this.defaultSortable = false;
5563
5564     this.addEvents({
5565         /**
5566              * @event widthchange
5567              * Fires when the width of a column changes.
5568              * @param {ColumnModel} this
5569              * @param {Number} columnIndex The column index
5570              * @param {Number} newWidth The new width
5571              */
5572             "widthchange": true,
5573         /**
5574              * @event headerchange
5575              * Fires when the text of a header changes.
5576              * @param {ColumnModel} this
5577              * @param {Number} columnIndex The column index
5578              * @param {Number} newText The new header text
5579              */
5580             "headerchange": true,
5581         /**
5582              * @event hiddenchange
5583              * Fires when a column is hidden or "unhidden".
5584              * @param {ColumnModel} this
5585              * @param {Number} columnIndex The column index
5586              * @param {Boolean} hidden true if hidden, false otherwise
5587              */
5588             "hiddenchange": true,
5589             /**
5590          * @event columnmoved
5591          * Fires when a column is moved.
5592          * @param {ColumnModel} this
5593          * @param {Number} oldIndex
5594          * @param {Number} newIndex
5595          */
5596         "columnmoved" : true,
5597         /**
5598          * @event columlockchange
5599          * Fires when a column's locked state is changed
5600          * @param {ColumnModel} this
5601          * @param {Number} colIndex
5602          * @param {Boolean} locked true if locked
5603          */
5604         "columnlockchange" : true
5605     });
5606     Roo.grid.ColumnModel.superclass.constructor.call(this);
5607 };
5608 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5609     /**
5610      * @cfg {String} header The header text to display in the Grid view.
5611      */
5612     /**
5613      * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5614      * {@link Roo.data.Record} definition from which to draw the column's value. If not
5615      * specified, the column's index is used as an index into the Record's data Array.
5616      */
5617     /**
5618      * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5619      * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5620      */
5621     /**
5622      * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5623      * Defaults to the value of the {@link #defaultSortable} property.
5624      * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5625      */
5626     /**
5627      * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid.  Defaults to false.
5628      */
5629     /**
5630      * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed.  Defaults to false.
5631      */
5632     /**
5633      * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5634      */
5635     /**
5636      * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5637      */
5638     /**
5639      * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5640      * given the cell's data value. See {@link #setRenderer}. If not specified, the
5641      * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5642      * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5643      */
5644        /**
5645      * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor 
5646      */
5647     /**
5648      * @cfg {String} align (Optional) Set the CSS text-align property of the column.  Defaults to undefined.
5649      */
5650     /**
5651      * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc).  Defaults to undefined.
5652      */
5653     /**
5654      * @cfg {String} cursor (Optional)
5655      */
5656     /**
5657      * @cfg {String} tooltip (Optional)
5658      */
5659     /**
5660      * @cfg {Number} xs (Optional)
5661      */
5662     /**
5663      * @cfg {Number} sm (Optional)
5664      */
5665     /**
5666      * @cfg {Number} md (Optional)
5667      */
5668     /**
5669      * @cfg {Number} lg (Optional)
5670      */
5671     /**
5672      * Returns the id of the column at the specified index.
5673      * @param {Number} index The column index
5674      * @return {String} the id
5675      */
5676     getColumnId : function(index){
5677         return this.config[index].id;
5678     },
5679
5680     /**
5681      * Returns the column for a specified id.
5682      * @param {String} id The column id
5683      * @return {Object} the column
5684      */
5685     getColumnById : function(id){
5686         return this.lookup[id];
5687     },
5688
5689     
5690     /**
5691      * Returns the column for a specified dataIndex.
5692      * @param {String} dataIndex The column dataIndex
5693      * @return {Object|Boolean} the column or false if not found
5694      */
5695     getColumnByDataIndex: function(dataIndex){
5696         var index = this.findColumnIndex(dataIndex);
5697         return index > -1 ? this.config[index] : false;
5698     },
5699     
5700     /**
5701      * Returns the index for a specified column id.
5702      * @param {String} id The column id
5703      * @return {Number} the index, or -1 if not found
5704      */
5705     getIndexById : function(id){
5706         for(var i = 0, len = this.config.length; i < len; i++){
5707             if(this.config[i].id == id){
5708                 return i;
5709             }
5710         }
5711         return -1;
5712     },
5713     
5714     /**
5715      * Returns the index for a specified column dataIndex.
5716      * @param {String} dataIndex The column dataIndex
5717      * @return {Number} the index, or -1 if not found
5718      */
5719     
5720     findColumnIndex : function(dataIndex){
5721         for(var i = 0, len = this.config.length; i < len; i++){
5722             if(this.config[i].dataIndex == dataIndex){
5723                 return i;
5724             }
5725         }
5726         return -1;
5727     },
5728     
5729     
5730     moveColumn : function(oldIndex, newIndex){
5731         var c = this.config[oldIndex];
5732         this.config.splice(oldIndex, 1);
5733         this.config.splice(newIndex, 0, c);
5734         this.dataMap = null;
5735         this.fireEvent("columnmoved", this, oldIndex, newIndex);
5736     },
5737
5738     isLocked : function(colIndex){
5739         return this.config[colIndex].locked === true;
5740     },
5741
5742     setLocked : function(colIndex, value, suppressEvent){
5743         if(this.isLocked(colIndex) == value){
5744             return;
5745         }
5746         this.config[colIndex].locked = value;
5747         if(!suppressEvent){
5748             this.fireEvent("columnlockchange", this, colIndex, value);
5749         }
5750     },
5751
5752     getTotalLockedWidth : function(){
5753         var totalWidth = 0;
5754         for(var i = 0; i < this.config.length; i++){
5755             if(this.isLocked(i) && !this.isHidden(i)){
5756                 this.totalWidth += this.getColumnWidth(i);
5757             }
5758         }
5759         return totalWidth;
5760     },
5761
5762     getLockedCount : function(){
5763         for(var i = 0, len = this.config.length; i < len; i++){
5764             if(!this.isLocked(i)){
5765                 return i;
5766             }
5767         }
5768         
5769         return this.config.length;
5770     },
5771
5772     /**
5773      * Returns the number of columns.
5774      * @return {Number}
5775      */
5776     getColumnCount : function(visibleOnly){
5777         if(visibleOnly === true){
5778             var c = 0;
5779             for(var i = 0, len = this.config.length; i < len; i++){
5780                 if(!this.isHidden(i)){
5781                     c++;
5782                 }
5783             }
5784             return c;
5785         }
5786         return this.config.length;
5787     },
5788
5789     /**
5790      * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5791      * @param {Function} fn
5792      * @param {Object} scope (optional)
5793      * @return {Array} result
5794      */
5795     getColumnsBy : function(fn, scope){
5796         var r = [];
5797         for(var i = 0, len = this.config.length; i < len; i++){
5798             var c = this.config[i];
5799             if(fn.call(scope||this, c, i) === true){
5800                 r[r.length] = c;
5801             }
5802         }
5803         return r;
5804     },
5805
5806     /**
5807      * Returns true if the specified column is sortable.
5808      * @param {Number} col The column index
5809      * @return {Boolean}
5810      */
5811     isSortable : function(col){
5812         if(typeof this.config[col].sortable == "undefined"){
5813             return this.defaultSortable;
5814         }
5815         return this.config[col].sortable;
5816     },
5817
5818     /**
5819      * Returns the rendering (formatting) function defined for the column.
5820      * @param {Number} col The column index.
5821      * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5822      */
5823     getRenderer : function(col){
5824         if(!this.config[col].renderer){
5825             return Roo.grid.ColumnModel.defaultRenderer;
5826         }
5827         return this.config[col].renderer;
5828     },
5829
5830     /**
5831      * Sets the rendering (formatting) function for a column.
5832      * @param {Number} col The column index
5833      * @param {Function} fn The function to use to process the cell's raw data
5834      * to return HTML markup for the grid view. The render function is called with
5835      * the following parameters:<ul>
5836      * <li>Data value.</li>
5837      * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5838      * <li>css A CSS style string to apply to the table cell.</li>
5839      * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5840      * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5841      * <li>Row index</li>
5842      * <li>Column index</li>
5843      * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5844      */
5845     setRenderer : function(col, fn){
5846         this.config[col].renderer = fn;
5847     },
5848
5849     /**
5850      * Returns the width for the specified column.
5851      * @param {Number} col The column index
5852      * @return {Number}
5853      */
5854     getColumnWidth : function(col){
5855         return this.config[col].width * 1 || this.defaultWidth;
5856     },
5857
5858     /**
5859      * Sets the width for a column.
5860      * @param {Number} col The column index
5861      * @param {Number} width The new width
5862      */
5863     setColumnWidth : function(col, width, suppressEvent){
5864         this.config[col].width = width;
5865         this.totalWidth = null;
5866         if(!suppressEvent){
5867              this.fireEvent("widthchange", this, col, width);
5868         }
5869     },
5870
5871     /**
5872      * Returns the total width of all columns.
5873      * @param {Boolean} includeHidden True to include hidden column widths
5874      * @return {Number}
5875      */
5876     getTotalWidth : function(includeHidden){
5877         if(!this.totalWidth){
5878             this.totalWidth = 0;
5879             for(var i = 0, len = this.config.length; i < len; i++){
5880                 if(includeHidden || !this.isHidden(i)){
5881                     this.totalWidth += this.getColumnWidth(i);
5882                 }
5883             }
5884         }
5885         return this.totalWidth;
5886     },
5887
5888     /**
5889      * Returns the header for the specified column.
5890      * @param {Number} col The column index
5891      * @return {String}
5892      */
5893     getColumnHeader : function(col){
5894         return this.config[col].header;
5895     },
5896
5897     /**
5898      * Sets the header for a column.
5899      * @param {Number} col The column index
5900      * @param {String} header The new header
5901      */
5902     setColumnHeader : function(col, header){
5903         this.config[col].header = header;
5904         this.fireEvent("headerchange", this, col, header);
5905     },
5906
5907     /**
5908      * Returns the tooltip for the specified column.
5909      * @param {Number} col The column index
5910      * @return {String}
5911      */
5912     getColumnTooltip : function(col){
5913             return this.config[col].tooltip;
5914     },
5915     /**
5916      * Sets the tooltip for a column.
5917      * @param {Number} col The column index
5918      * @param {String} tooltip The new tooltip
5919      */
5920     setColumnTooltip : function(col, tooltip){
5921             this.config[col].tooltip = tooltip;
5922     },
5923
5924     /**
5925      * Returns the dataIndex for the specified column.
5926      * @param {Number} col The column index
5927      * @return {Number}
5928      */
5929     getDataIndex : function(col){
5930         return this.config[col].dataIndex;
5931     },
5932
5933     /**
5934      * Sets the dataIndex for a column.
5935      * @param {Number} col The column index
5936      * @param {Number} dataIndex The new dataIndex
5937      */
5938     setDataIndex : function(col, dataIndex){
5939         this.config[col].dataIndex = dataIndex;
5940     },
5941
5942     
5943     
5944     /**
5945      * Returns true if the cell is editable.
5946      * @param {Number} colIndex The column index
5947      * @param {Number} rowIndex The row index - this is nto actually used..?
5948      * @return {Boolean}
5949      */
5950     isCellEditable : function(colIndex, rowIndex){
5951         return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5952     },
5953
5954     /**
5955      * Returns the editor defined for the cell/column.
5956      * return false or null to disable editing.
5957      * @param {Number} colIndex The column index
5958      * @param {Number} rowIndex The row index
5959      * @return {Object}
5960      */
5961     getCellEditor : function(colIndex, rowIndex){
5962         return this.config[colIndex].editor;
5963     },
5964
5965     /**
5966      * Sets if a column is editable.
5967      * @param {Number} col The column index
5968      * @param {Boolean} editable True if the column is editable
5969      */
5970     setEditable : function(col, editable){
5971         this.config[col].editable = editable;
5972     },
5973
5974
5975     /**
5976      * Returns true if the column is hidden.
5977      * @param {Number} colIndex The column index
5978      * @return {Boolean}
5979      */
5980     isHidden : function(colIndex){
5981         return this.config[colIndex].hidden;
5982     },
5983
5984
5985     /**
5986      * Returns true if the column width cannot be changed
5987      */
5988     isFixed : function(colIndex){
5989         return this.config[colIndex].fixed;
5990     },
5991
5992     /**
5993      * Returns true if the column can be resized
5994      * @return {Boolean}
5995      */
5996     isResizable : function(colIndex){
5997         return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5998     },
5999     /**
6000      * Sets if a column is hidden.
6001      * @param {Number} colIndex The column index
6002      * @param {Boolean} hidden True if the column is hidden
6003      */
6004     setHidden : function(colIndex, hidden){
6005         this.config[colIndex].hidden = hidden;
6006         this.totalWidth = null;
6007         this.fireEvent("hiddenchange", this, colIndex, hidden);
6008     },
6009
6010     /**
6011      * Sets the editor for a column.
6012      * @param {Number} col The column index
6013      * @param {Object} editor The editor object
6014      */
6015     setEditor : function(col, editor){
6016         this.config[col].editor = editor;
6017     }
6018 });
6019
6020 Roo.grid.ColumnModel.defaultRenderer = function(value)
6021 {
6022     if(typeof value == "object") {
6023         return value;
6024     }
6025         if(typeof value == "string" && value.length < 1){
6026             return "&#160;";
6027         }
6028     
6029         return String.format("{0}", value);
6030 };
6031
6032 // Alias for backwards compatibility
6033 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
6034 /*
6035  * Based on:
6036  * Ext JS Library 1.1.1
6037  * Copyright(c) 2006-2007, Ext JS, LLC.
6038  *
6039  * Originally Released Under LGPL - original licence link has changed is not relivant.
6040  *
6041  * Fork - LGPL
6042  * <script type="text/javascript">
6043  */
6044  
6045 /**
6046  * @class Roo.LoadMask
6047  * A simple utility class for generically masking elements while loading data.  If the element being masked has
6048  * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
6049  * process and the mask element will be cached for reuse.  For all other elements, this mask will replace the
6050  * element's UpdateManager load indicator and will be destroyed after the initial load.
6051  * @constructor
6052  * Create a new LoadMask
6053  * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
6054  * @param {Object} config The config object
6055  */
6056 Roo.LoadMask = function(el, config){
6057     this.el = Roo.get(el);
6058     Roo.apply(this, config);
6059     if(this.store){
6060         this.store.on('beforeload', this.onBeforeLoad, this);
6061         this.store.on('load', this.onLoad, this);
6062         this.store.on('loadexception', this.onLoadException, this);
6063         this.removeMask = false;
6064     }else{
6065         var um = this.el.getUpdateManager();
6066         um.showLoadIndicator = false; // disable the default indicator
6067         um.on('beforeupdate', this.onBeforeLoad, this);
6068         um.on('update', this.onLoad, this);
6069         um.on('failure', this.onLoad, this);
6070         this.removeMask = true;
6071     }
6072 };
6073
6074 Roo.LoadMask.prototype = {
6075     /**
6076      * @cfg {Boolean} removeMask
6077      * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
6078      * False to persist the mask element reference for multiple uses (e.g., for paged data widgets).  Defaults to false.
6079      */
6080     /**
6081      * @cfg {String} msg
6082      * The text to display in a centered loading message box (defaults to 'Loading...')
6083      */
6084     msg : 'Loading...',
6085     /**
6086      * @cfg {String} msgCls
6087      * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
6088      */
6089     msgCls : 'x-mask-loading',
6090
6091     /**
6092      * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
6093      * @type Boolean
6094      */
6095     disabled: false,
6096
6097     /**
6098      * Disables the mask to prevent it from being displayed
6099      */
6100     disable : function(){
6101        this.disabled = true;
6102     },
6103
6104     /**
6105      * Enables the mask so that it can be displayed
6106      */
6107     enable : function(){
6108         this.disabled = false;
6109     },
6110     
6111     onLoadException : function()
6112     {
6113         Roo.log(arguments);
6114         
6115         if (typeof(arguments[3]) != 'undefined') {
6116             Roo.MessageBox.alert("Error loading",arguments[3]);
6117         } 
6118         /*
6119         try {
6120             if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
6121                 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
6122             }   
6123         } catch(e) {
6124             
6125         }
6126         */
6127     
6128         (function() { this.el.unmask(this.removeMask); }).defer(50, this);
6129     },
6130     // private
6131     onLoad : function()
6132     {
6133         (function() { this.el.unmask(this.removeMask); }).defer(50, this);
6134     },
6135
6136     // private
6137     onBeforeLoad : function(){
6138         if(!this.disabled){
6139             (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
6140         }
6141     },
6142
6143     // private
6144     destroy : function(){
6145         if(this.store){
6146             this.store.un('beforeload', this.onBeforeLoad, this);
6147             this.store.un('load', this.onLoad, this);
6148             this.store.un('loadexception', this.onLoadException, this);
6149         }else{
6150             var um = this.el.getUpdateManager();
6151             um.un('beforeupdate', this.onBeforeLoad, this);
6152             um.un('update', this.onLoad, this);
6153             um.un('failure', this.onLoad, this);
6154         }
6155     }
6156 };/*
6157  * - LGPL
6158  *
6159  * table
6160  * 
6161  */
6162
6163 /**
6164  * @class Roo.bootstrap.Table
6165  * @extends Roo.bootstrap.Component
6166  * Bootstrap Table class
6167  * @cfg {String} cls table class
6168  * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
6169  * @cfg {String} bgcolor Specifies the background color for a table
6170  * @cfg {Number} border Specifies whether the table cells should have borders or not
6171  * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
6172  * @cfg {Number} cellspacing Specifies the space between cells
6173  * @cfg {String} frame Specifies which parts of the outside borders that should be visible
6174  * @cfg {String} rules Specifies which parts of the inside borders that should be visible
6175  * @cfg {String} sortable Specifies that the table should be sortable
6176  * @cfg {String} summary Specifies a summary of the content of a table
6177  * @cfg {Number} width Specifies the width of a table
6178  * @cfg {String} layout table layout (auto | fixed | initial | inherit)
6179  * 
6180  * @cfg {boolean} striped Should the rows be alternative striped
6181  * @cfg {boolean} bordered Add borders to the table
6182  * @cfg {boolean} hover Add hover highlighting
6183  * @cfg {boolean} condensed Format condensed
6184  * @cfg {boolean} responsive Format condensed
6185  * @cfg {Boolean} loadMask (true|false) default false
6186  * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
6187  * @cfg {Boolean} headerShow (true|false) generate thead, default true
6188  * @cfg {Boolean} rowSelection (true|false) default false
6189  * @cfg {Boolean} cellSelection (true|false) default false
6190  * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
6191  * @cfg {Roo.bootstrap.PagingToolbar} footer  a paging toolbar
6192  * @cfg {Boolean} lazyLoad  auto load data while scrolling to the end (default false)
6193  * @cfg {Boolean} auto_hide_footer  auto hide footer if only one page (default false)
6194  
6195  * 
6196  * @constructor
6197  * Create a new Table
6198  * @param {Object} config The config object
6199  */
6200
6201 Roo.bootstrap.Table = function(config){
6202     Roo.bootstrap.Table.superclass.constructor.call(this, config);
6203     
6204   
6205     
6206     // BC...
6207     this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
6208     this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
6209     this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
6210     this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
6211     
6212     this.sm = this.sm || {xtype: 'RowSelectionModel'};
6213     if (this.sm) {
6214         this.sm.grid = this;
6215         this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
6216         this.sm = this.selModel;
6217         this.sm.xmodule = this.xmodule || false;
6218     }
6219     
6220     if (this.cm && typeof(this.cm.config) == 'undefined') {
6221         this.colModel = new Roo.grid.ColumnModel(this.cm);
6222         this.cm = this.colModel;
6223         this.cm.xmodule = this.xmodule || false;
6224     }
6225     if (this.store) {
6226         this.store= Roo.factory(this.store, Roo.data);
6227         this.ds = this.store;
6228         this.ds.xmodule = this.xmodule || false;
6229          
6230     }
6231     if (this.footer && this.store) {
6232         this.footer.dataSource = this.ds;
6233         this.footer = Roo.factory(this.footer);
6234     }
6235     
6236     /** @private */
6237     this.addEvents({
6238         /**
6239          * @event cellclick
6240          * Fires when a cell is clicked
6241          * @param {Roo.bootstrap.Table} this
6242          * @param {Roo.Element} el
6243          * @param {Number} rowIndex
6244          * @param {Number} columnIndex
6245          * @param {Roo.EventObject} e
6246          */
6247         "cellclick" : true,
6248         /**
6249          * @event celldblclick
6250          * Fires when a cell is double clicked
6251          * @param {Roo.bootstrap.Table} this
6252          * @param {Roo.Element} el
6253          * @param {Number} rowIndex
6254          * @param {Number} columnIndex
6255          * @param {Roo.EventObject} e
6256          */
6257         "celldblclick" : true,
6258         /**
6259          * @event rowclick
6260          * Fires when a row is clicked
6261          * @param {Roo.bootstrap.Table} this
6262          * @param {Roo.Element} el
6263          * @param {Number} rowIndex
6264          * @param {Roo.EventObject} e
6265          */
6266         "rowclick" : true,
6267         /**
6268          * @event rowdblclick
6269          * Fires when a row is double clicked
6270          * @param {Roo.bootstrap.Table} this
6271          * @param {Roo.Element} el
6272          * @param {Number} rowIndex
6273          * @param {Roo.EventObject} e
6274          */
6275         "rowdblclick" : true,
6276         /**
6277          * @event mouseover
6278          * Fires when a mouseover occur
6279          * @param {Roo.bootstrap.Table} this
6280          * @param {Roo.Element} el
6281          * @param {Number} rowIndex
6282          * @param {Number} columnIndex
6283          * @param {Roo.EventObject} e
6284          */
6285         "mouseover" : true,
6286         /**
6287          * @event mouseout
6288          * Fires when a mouseout occur
6289          * @param {Roo.bootstrap.Table} this
6290          * @param {Roo.Element} el
6291          * @param {Number} rowIndex
6292          * @param {Number} columnIndex
6293          * @param {Roo.EventObject} e
6294          */
6295         "mouseout" : true,
6296         /**
6297          * @event rowclass
6298          * Fires when a row is rendered, so you can change add a style to it.
6299          * @param {Roo.bootstrap.Table} this
6300          * @param {Object} rowcfg   contains record  rowIndex colIndex and rowClass - set rowClass to add a style.
6301          */
6302         'rowclass' : true,
6303           /**
6304          * @event rowsrendered
6305          * Fires when all the  rows have been rendered
6306          * @param {Roo.bootstrap.Table} this
6307          */
6308         'rowsrendered' : true,
6309         /**
6310          * @event contextmenu
6311          * The raw contextmenu event for the entire grid.
6312          * @param {Roo.EventObject} e
6313          */
6314         "contextmenu" : true,
6315         /**
6316          * @event rowcontextmenu
6317          * Fires when a row is right clicked
6318          * @param {Roo.bootstrap.Table} this
6319          * @param {Number} rowIndex
6320          * @param {Roo.EventObject} e
6321          */
6322         "rowcontextmenu" : true,
6323         /**
6324          * @event cellcontextmenu
6325          * Fires when a cell is right clicked
6326          * @param {Roo.bootstrap.Table} this
6327          * @param {Number} rowIndex
6328          * @param {Number} cellIndex
6329          * @param {Roo.EventObject} e
6330          */
6331          "cellcontextmenu" : true,
6332          /**
6333          * @event headercontextmenu
6334          * Fires when a header is right clicked
6335          * @param {Roo.bootstrap.Table} this
6336          * @param {Number} columnIndex
6337          * @param {Roo.EventObject} e
6338          */
6339         "headercontextmenu" : true
6340     });
6341 };
6342
6343 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component,  {
6344     
6345     cls: false,
6346     align: false,
6347     bgcolor: false,
6348     border: false,
6349     cellpadding: false,
6350     cellspacing: false,
6351     frame: false,
6352     rules: false,
6353     sortable: false,
6354     summary: false,
6355     width: false,
6356     striped : false,
6357     scrollBody : false,
6358     bordered: false,
6359     hover:  false,
6360     condensed : false,
6361     responsive : false,
6362     sm : false,
6363     cm : false,
6364     store : false,
6365     loadMask : false,
6366     footerShow : true,
6367     headerShow : true,
6368   
6369     rowSelection : false,
6370     cellSelection : false,
6371     layout : false,
6372     
6373     // Roo.Element - the tbody
6374     mainBody: false,
6375     // Roo.Element - thead element
6376     mainHead: false,
6377     
6378     container: false, // used by gridpanel...
6379     
6380     lazyLoad : false,
6381     
6382     CSS : Roo.util.CSS,
6383     
6384     auto_hide_footer : false,
6385     
6386     getAutoCreate : function()
6387     {
6388         var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
6389         
6390         cfg = {
6391             tag: 'table',
6392             cls : 'table',
6393             cn : []
6394         };
6395         if (this.scrollBody) {
6396             cfg.cls += ' table-body-fixed';
6397         }    
6398         if (this.striped) {
6399             cfg.cls += ' table-striped';
6400         }
6401         
6402         if (this.hover) {
6403             cfg.cls += ' table-hover';
6404         }
6405         if (this.bordered) {
6406             cfg.cls += ' table-bordered';
6407         }
6408         if (this.condensed) {
6409             cfg.cls += ' table-condensed';
6410         }
6411         if (this.responsive) {
6412             cfg.cls += ' table-responsive';
6413         }
6414         
6415         if (this.cls) {
6416             cfg.cls+=  ' ' +this.cls;
6417         }
6418         
6419         // this lot should be simplifed...
6420         var _t = this;
6421         var cp = [
6422             'align',
6423             'bgcolor',
6424             'border',
6425             'cellpadding',
6426             'cellspacing',
6427             'frame',
6428             'rules',
6429             'sortable',
6430             'summary',
6431             'width'
6432         ].forEach(function(k) {
6433             if (_t[k]) {
6434                 cfg[k] = _t[k];
6435             }
6436         });
6437         
6438         
6439         if (this.layout) {
6440             cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6441         }
6442         
6443         if(this.store || this.cm){
6444             if(this.headerShow){
6445                 cfg.cn.push(this.renderHeader());
6446             }
6447             
6448             cfg.cn.push(this.renderBody());
6449             
6450             if(this.footerShow){
6451                 cfg.cn.push(this.renderFooter());
6452             }
6453             // where does this come from?
6454             //cfg.cls+=  ' TableGrid';
6455         }
6456         
6457         return { cn : [ cfg ] };
6458     },
6459     
6460     initEvents : function()
6461     {   
6462         if(!this.store || !this.cm){
6463             return;
6464         }
6465         if (this.selModel) {
6466             this.selModel.initEvents();
6467         }
6468         
6469         
6470         //Roo.log('initEvents with ds!!!!');
6471         
6472         this.mainBody = this.el.select('tbody', true).first();
6473         this.mainHead = this.el.select('thead', true).first();
6474         this.mainFoot = this.el.select('tfoot', true).first();
6475         
6476         
6477         
6478         var _this = this;
6479         
6480         Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6481             e.on('click', _this.sort, _this);
6482         });
6483         
6484         this.mainBody.on("click", this.onClick, this);
6485         this.mainBody.on("dblclick", this.onDblClick, this);
6486         
6487         // why is this done????? = it breaks dialogs??
6488         //this.parent().el.setStyle('position', 'relative');
6489         
6490         
6491         if (this.footer) {
6492             this.footer.parentId = this.id;
6493             this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6494             
6495             if(this.lazyLoad){
6496                 this.el.select('tfoot tr td').first().addClass('hide');
6497             }
6498         } 
6499         
6500         if(this.loadMask) {
6501             this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6502         }
6503         
6504         this.store.on('load', this.onLoad, this);
6505         this.store.on('beforeload', this.onBeforeLoad, this);
6506         this.store.on('update', this.onUpdate, this);
6507         this.store.on('add', this.onAdd, this);
6508         this.store.on("clear", this.clear, this);
6509         
6510         this.el.on("contextmenu", this.onContextMenu, this);
6511         
6512         this.mainBody.on('scroll', this.onBodyScroll, this);
6513         
6514         this.cm.on("headerchange", this.onHeaderChange, this);
6515         
6516         this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
6517         
6518     },
6519     
6520     onContextMenu : function(e, t)
6521     {
6522         this.processEvent("contextmenu", e);
6523     },
6524     
6525     processEvent : function(name, e)
6526     {
6527         if (name != 'touchstart' ) {
6528             this.fireEvent(name, e);    
6529         }
6530         
6531         var t = e.getTarget();
6532         
6533         var cell = Roo.get(t);
6534         
6535         if(!cell){
6536             return;
6537         }
6538         
6539         if(cell.findParent('tfoot', false, true)){
6540             return;
6541         }
6542         
6543         if(cell.findParent('thead', false, true)){
6544             
6545             if(e.getTarget().nodeName.toLowerCase() != 'th'){
6546                 cell = Roo.get(t).findParent('th', false, true);
6547                 if (!cell) {
6548                     Roo.log("failed to find th in thead?");
6549                     Roo.log(e.getTarget());
6550                     return;
6551                 }
6552             }
6553             
6554             var cellIndex = cell.dom.cellIndex;
6555             
6556             var ename = name == 'touchstart' ? 'click' : name;
6557             this.fireEvent("header" + ename, this, cellIndex, e);
6558             
6559             return;
6560         }
6561         
6562         if(e.getTarget().nodeName.toLowerCase() != 'td'){
6563             cell = Roo.get(t).findParent('td', false, true);
6564             if (!cell) {
6565                 Roo.log("failed to find th in tbody?");
6566                 Roo.log(e.getTarget());
6567                 return;
6568             }
6569         }
6570         
6571         var row = cell.findParent('tr', false, true);
6572         var cellIndex = cell.dom.cellIndex;
6573         var rowIndex = row.dom.rowIndex - 1;
6574         
6575         if(row !== false){
6576             
6577             this.fireEvent("row" + name, this, rowIndex, e);
6578             
6579             if(cell !== false){
6580             
6581                 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6582             }
6583         }
6584         
6585     },
6586     
6587     onMouseover : function(e, el)
6588     {
6589         var cell = Roo.get(el);
6590         
6591         if(!cell){
6592             return;
6593         }
6594         
6595         if(e.getTarget().nodeName.toLowerCase() != 'td'){
6596             cell = cell.findParent('td', false, true);
6597         }
6598         
6599         var row = cell.findParent('tr', false, true);
6600         var cellIndex = cell.dom.cellIndex;
6601         var rowIndex = row.dom.rowIndex - 1; // start from 0
6602         
6603         this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6604         
6605     },
6606     
6607     onMouseout : function(e, el)
6608     {
6609         var cell = Roo.get(el);
6610         
6611         if(!cell){
6612             return;
6613         }
6614         
6615         if(e.getTarget().nodeName.toLowerCase() != 'td'){
6616             cell = cell.findParent('td', false, true);
6617         }
6618         
6619         var row = cell.findParent('tr', false, true);
6620         var cellIndex = cell.dom.cellIndex;
6621         var rowIndex = row.dom.rowIndex - 1; // start from 0
6622         
6623         this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6624         
6625     },
6626     
6627     onClick : function(e, el)
6628     {
6629         var cell = Roo.get(el);
6630         
6631         if(!cell || (!this.cellSelection && !this.rowSelection)){
6632             return;
6633         }
6634         
6635         if(e.getTarget().nodeName.toLowerCase() != 'td'){
6636             cell = cell.findParent('td', false, true);
6637         }
6638         
6639         if(!cell || typeof(cell) == 'undefined'){
6640             return;
6641         }
6642         
6643         var row = cell.findParent('tr', false, true);
6644         
6645         if(!row || typeof(row) == 'undefined'){
6646             return;
6647         }
6648         
6649         var cellIndex = cell.dom.cellIndex;
6650         var rowIndex = this.getRowIndex(row);
6651         
6652         // why??? - should these not be based on SelectionModel?
6653         if(this.cellSelection){
6654             this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6655         }
6656         
6657         if(this.rowSelection){
6658             this.fireEvent('rowclick', this, row, rowIndex, e);
6659         }
6660         
6661         
6662     },
6663         
6664     onDblClick : function(e,el)
6665     {
6666         var cell = Roo.get(el);
6667         
6668         if(!cell || (!this.cellSelection && !this.rowSelection)){
6669             return;
6670         }
6671         
6672         if(e.getTarget().nodeName.toLowerCase() != 'td'){
6673             cell = cell.findParent('td', false, true);
6674         }
6675         
6676         if(!cell || typeof(cell) == 'undefined'){
6677             return;
6678         }
6679         
6680         var row = cell.findParent('tr', false, true);
6681         
6682         if(!row || typeof(row) == 'undefined'){
6683             return;
6684         }
6685         
6686         var cellIndex = cell.dom.cellIndex;
6687         var rowIndex = this.getRowIndex(row);
6688         
6689         if(this.cellSelection){
6690             this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6691         }
6692         
6693         if(this.rowSelection){
6694             this.fireEvent('rowdblclick', this, row, rowIndex, e);
6695         }
6696     },
6697     
6698     sort : function(e,el)
6699     {
6700         var col = Roo.get(el);
6701         
6702         if(!col.hasClass('sortable')){
6703             return;
6704         }
6705         
6706         var sort = col.attr('sort');
6707         var dir = 'ASC';
6708         
6709         if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6710             dir = 'DESC';
6711         }
6712         
6713         this.store.sortInfo = {field : sort, direction : dir};
6714         
6715         if (this.footer) {
6716             Roo.log("calling footer first");
6717             this.footer.onClick('first');
6718         } else {
6719         
6720             this.store.load({ params : { start : 0 } });
6721         }
6722     },
6723     
6724     renderHeader : function()
6725     {
6726         var header = {
6727             tag: 'thead',
6728             cn : []
6729         };
6730         
6731         var cm = this.cm;
6732         this.totalWidth = 0;
6733         
6734         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6735             
6736             var config = cm.config[i];
6737             
6738             var c = {
6739                 tag: 'th',
6740                 cls : 'x-hcol-' + i,
6741                 style : '',
6742                 html: cm.getColumnHeader(i)
6743             };
6744             
6745             var hh = '';
6746             
6747             if(typeof(config.sortable) != 'undefined' && config.sortable){
6748                 c.cls = 'sortable';
6749                 c.html = '<i class="glyphicon"></i>' + c.html;
6750             }
6751             
6752             if(typeof(config.lgHeader) != 'undefined'){
6753                 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6754             }
6755             
6756             if(typeof(config.mdHeader) != 'undefined'){
6757                 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6758             }
6759             
6760             if(typeof(config.smHeader) != 'undefined'){
6761                 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6762             }
6763             
6764             if(typeof(config.xsHeader) != 'undefined'){
6765                 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6766             }
6767             
6768             if(hh.length){
6769                 c.html = hh;
6770             }
6771             
6772             if(typeof(config.tooltip) != 'undefined'){
6773                 c.tooltip = config.tooltip;
6774             }
6775             
6776             if(typeof(config.colspan) != 'undefined'){
6777                 c.colspan = config.colspan;
6778             }
6779             
6780             if(typeof(config.hidden) != 'undefined' && config.hidden){
6781                 c.style += ' display:none;';
6782             }
6783             
6784             if(typeof(config.dataIndex) != 'undefined'){
6785                 c.sort = config.dataIndex;
6786             }
6787             
6788            
6789             
6790             if(typeof(config.align) != 'undefined' && config.align.length){
6791                 c.style += ' text-align:' + config.align + ';';
6792             }
6793             
6794             if(typeof(config.width) != 'undefined'){
6795                 c.style += ' width:' + config.width + 'px;';
6796                 this.totalWidth += config.width;
6797             } else {
6798                 this.totalWidth += 100; // assume minimum of 100 per column?
6799             }
6800             
6801             if(typeof(config.cls) != 'undefined'){
6802                 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6803             }
6804             
6805             ['xs','sm','md','lg'].map(function(size){
6806                 
6807                 if(typeof(config[size]) == 'undefined'){
6808                     return;
6809                 }
6810                 
6811                 if (!config[size]) { // 0 = hidden
6812                     c.cls += ' hidden-' + size;
6813                     return;
6814                 }
6815                 
6816                 c.cls += ' col-' + size + '-' + config[size];
6817
6818             });
6819             
6820             header.cn.push(c)
6821         }
6822         
6823         return header;
6824     },
6825     
6826     renderBody : function()
6827     {
6828         var body = {
6829             tag: 'tbody',
6830             cn : [
6831                 {
6832                     tag: 'tr',
6833                     cn : [
6834                         {
6835                             tag : 'td',
6836                             colspan :  this.cm.getColumnCount()
6837                         }
6838                     ]
6839                 }
6840             ]
6841         };
6842         
6843         return body;
6844     },
6845     
6846     renderFooter : function()
6847     {
6848         var footer = {
6849             tag: 'tfoot',
6850             cn : [
6851                 {
6852                     tag: 'tr',
6853                     cn : [
6854                         {
6855                             tag : 'td',
6856                             colspan :  this.cm.getColumnCount()
6857                         }
6858                     ]
6859                 }
6860             ]
6861         };
6862         
6863         return footer;
6864     },
6865     
6866     
6867     
6868     onLoad : function()
6869     {
6870 //        Roo.log('ds onload');
6871         this.clear();
6872         
6873         var _this = this;
6874         var cm = this.cm;
6875         var ds = this.store;
6876         
6877         Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6878             e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6879             if (_this.store.sortInfo) {
6880                     
6881                 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6882                     e.select('i', true).addClass(['glyphicon-arrow-up']);
6883                 }
6884                 
6885                 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6886                     e.select('i', true).addClass(['glyphicon-arrow-down']);
6887                 }
6888             }
6889         });
6890         
6891         var tbody =  this.mainBody;
6892               
6893         if(ds.getCount() > 0){
6894             ds.data.each(function(d,rowIndex){
6895                 var row =  this.renderRow(cm, ds, rowIndex);
6896                 
6897                 tbody.createChild(row);
6898                 
6899                 var _this = this;
6900                 
6901                 if(row.cellObjects.length){
6902                     Roo.each(row.cellObjects, function(r){
6903                         _this.renderCellObject(r);
6904                     })
6905                 }
6906                 
6907             }, this);
6908         }
6909         
6910         var tfoot = this.el.select('tfoot', true).first();
6911         
6912         if(this.footerShow && this.auto_hide_footer && this.mainFoot){
6913             
6914             this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
6915             
6916             var total = this.ds.getTotalCount();
6917             
6918             if(this.footer.pageSize < total){
6919                 this.mainFoot.show();
6920             }
6921         }
6922         
6923         Roo.each(this.el.select('tbody td', true).elements, function(e){
6924             e.on('mouseover', _this.onMouseover, _this);
6925         });
6926         
6927         Roo.each(this.el.select('tbody td', true).elements, function(e){
6928             e.on('mouseout', _this.onMouseout, _this);
6929         });
6930         this.fireEvent('rowsrendered', this);
6931         
6932         this.autoSize();
6933     },
6934     
6935     
6936     onUpdate : function(ds,record)
6937     {
6938         this.refreshRow(record);
6939         this.autoSize();
6940     },
6941     
6942     onRemove : function(ds, record, index, isUpdate){
6943         if(isUpdate !== true){
6944             this.fireEvent("beforerowremoved", this, index, record);
6945         }
6946         var bt = this.mainBody.dom;
6947         
6948         var rows = this.el.select('tbody > tr', true).elements;
6949         
6950         if(typeof(rows[index]) != 'undefined'){
6951             bt.removeChild(rows[index].dom);
6952         }
6953         
6954 //        if(bt.rows[index]){
6955 //            bt.removeChild(bt.rows[index]);
6956 //        }
6957         
6958         if(isUpdate !== true){
6959             //this.stripeRows(index);
6960             //this.syncRowHeights(index, index);
6961             //this.layout();
6962             this.fireEvent("rowremoved", this, index, record);
6963         }
6964     },
6965     
6966     onAdd : function(ds, records, rowIndex)
6967     {
6968         //Roo.log('on Add called');
6969         // - note this does not handle multiple adding very well..
6970         var bt = this.mainBody.dom;
6971         for (var i =0 ; i < records.length;i++) {
6972             //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6973             //Roo.log(records[i]);
6974             //Roo.log(this.store.getAt(rowIndex+i));
6975             this.insertRow(this.store, rowIndex + i, false);
6976             return;
6977         }
6978         
6979     },
6980     
6981     
6982     refreshRow : function(record){
6983         var ds = this.store, index;
6984         if(typeof record == 'number'){
6985             index = record;
6986             record = ds.getAt(index);
6987         }else{
6988             index = ds.indexOf(record);
6989         }
6990         this.insertRow(ds, index, true);
6991         this.autoSize();
6992         this.onRemove(ds, record, index+1, true);
6993         this.autoSize();
6994         //this.syncRowHeights(index, index);
6995         //this.layout();
6996         this.fireEvent("rowupdated", this, index, record);
6997     },
6998     
6999     insertRow : function(dm, rowIndex, isUpdate){
7000         
7001         if(!isUpdate){
7002             this.fireEvent("beforerowsinserted", this, rowIndex);
7003         }
7004             //var s = this.getScrollState();
7005         var row = this.renderRow(this.cm, this.store, rowIndex);
7006         // insert before rowIndex..
7007         var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
7008         
7009         var _this = this;
7010                 
7011         if(row.cellObjects.length){
7012             Roo.each(row.cellObjects, function(r){
7013                 _this.renderCellObject(r);
7014             })
7015         }
7016             
7017         if(!isUpdate){
7018             this.fireEvent("rowsinserted", this, rowIndex);
7019             //this.syncRowHeights(firstRow, lastRow);
7020             //this.stripeRows(firstRow);
7021             //this.layout();
7022         }
7023         
7024     },
7025     
7026     
7027     getRowDom : function(rowIndex)
7028     {
7029         var rows = this.el.select('tbody > tr', true).elements;
7030         
7031         return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
7032         
7033     },
7034     // returns the object tree for a tr..
7035   
7036     
7037     renderRow : function(cm, ds, rowIndex) 
7038     {
7039         var d = ds.getAt(rowIndex);
7040         
7041         var row = {
7042             tag : 'tr',
7043             cls : 'x-row-' + rowIndex,
7044             cn : []
7045         };
7046             
7047         var cellObjects = [];
7048         
7049         for(var i = 0, len = cm.getColumnCount(); i < len; i++){
7050             var config = cm.config[i];
7051             
7052             var renderer = cm.getRenderer(i);
7053             var value = '';
7054             var id = false;
7055             
7056             if(typeof(renderer) !== 'undefined'){
7057                 value = renderer(d.data[cm.getDataIndex(i)], false, d);
7058             }
7059             // if object are returned, then they are expected to be Roo.bootstrap.Component instances
7060             // and are rendered into the cells after the row is rendered - using the id for the element.
7061             
7062             if(typeof(value) === 'object'){
7063                 id = Roo.id();
7064                 cellObjects.push({
7065                     container : id,
7066                     cfg : value 
7067                 })
7068             }
7069             
7070             var rowcfg = {
7071                 record: d,
7072                 rowIndex : rowIndex,
7073                 colIndex : i,
7074                 rowClass : ''
7075             };
7076
7077             this.fireEvent('rowclass', this, rowcfg);
7078             
7079             var td = {
7080                 tag: 'td',
7081                 cls : rowcfg.rowClass + ' x-col-' + i,
7082                 style: '',
7083                 html: (typeof(value) === 'object') ? '' : value
7084             };
7085             
7086             if (id) {
7087                 td.id = id;
7088             }
7089             
7090             if(typeof(config.colspan) != 'undefined'){
7091                 td.colspan = config.colspan;
7092             }
7093             
7094             if(typeof(config.hidden) != 'undefined' && config.hidden){
7095                 td.style += ' display:none;';
7096             }
7097             
7098             if(typeof(config.align) != 'undefined' && config.align.length){
7099                 td.style += ' text-align:' + config.align + ';';
7100             }
7101             if(typeof(config.valign) != 'undefined' && config.valign.length){
7102                 td.style += ' vertical-align:' + config.valign + ';';
7103             }
7104             
7105             if(typeof(config.width) != 'undefined'){
7106                 td.style += ' width:' +  config.width + 'px;';
7107             }
7108             
7109             if(typeof(config.cursor) != 'undefined'){
7110                 td.style += ' cursor:' +  config.cursor + ';';
7111             }
7112             
7113             if(typeof(config.cls) != 'undefined'){
7114                 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
7115             }
7116             
7117             ['xs','sm','md','lg'].map(function(size){
7118                 
7119                 if(typeof(config[size]) == 'undefined'){
7120                     return;
7121                 }
7122                 
7123                 if (!config[size]) { // 0 = hidden
7124                     td.cls += ' hidden-' + size;
7125                     return;
7126                 }
7127                 
7128                 td.cls += ' col-' + size + '-' + config[size];
7129
7130             });
7131             
7132             row.cn.push(td);
7133            
7134         }
7135         
7136         row.cellObjects = cellObjects;
7137         
7138         return row;
7139           
7140     },
7141     
7142     
7143     
7144     onBeforeLoad : function()
7145     {
7146         
7147     },
7148      /**
7149      * Remove all rows
7150      */
7151     clear : function()
7152     {
7153         this.el.select('tbody', true).first().dom.innerHTML = '';
7154     },
7155     /**
7156      * Show or hide a row.
7157      * @param {Number} rowIndex to show or hide
7158      * @param {Boolean} state hide
7159      */
7160     setRowVisibility : function(rowIndex, state)
7161     {
7162         var bt = this.mainBody.dom;
7163         
7164         var rows = this.el.select('tbody > tr', true).elements;
7165         
7166         if(typeof(rows[rowIndex]) == 'undefined'){
7167             return;
7168         }
7169         rows[rowIndex].dom.style.display = state ? '' : 'none';
7170     },
7171     
7172     
7173     getSelectionModel : function(){
7174         if(!this.selModel){
7175             this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
7176         }
7177         return this.selModel;
7178     },
7179     /*
7180      * Render the Roo.bootstrap object from renderder
7181      */
7182     renderCellObject : function(r)
7183     {
7184         var _this = this;
7185         
7186         r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
7187         
7188         var t = r.cfg.render(r.container);
7189         
7190         if(r.cfg.cn){
7191             Roo.each(r.cfg.cn, function(c){
7192                 var child = {
7193                     container: t.getChildContainer(),
7194                     cfg: c
7195                 };
7196                 _this.renderCellObject(child);
7197             })
7198         }
7199     },
7200     
7201     getRowIndex : function(row)
7202     {
7203         var rowIndex = -1;
7204         
7205         Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
7206             if(el != row){
7207                 return;
7208             }
7209             
7210             rowIndex = index;
7211         });
7212         
7213         return rowIndex;
7214     },
7215      /**
7216      * Returns the grid's underlying element = used by panel.Grid
7217      * @return {Element} The element
7218      */
7219     getGridEl : function(){
7220         return this.el;
7221     },
7222      /**
7223      * Forces a resize - used by panel.Grid
7224      * @return {Element} The element
7225      */
7226     autoSize : function()
7227     {
7228         //var ctr = Roo.get(this.container.dom.parentElement);
7229         var ctr = Roo.get(this.el.dom);
7230         
7231         var thd = this.getGridEl().select('thead',true).first();
7232         var tbd = this.getGridEl().select('tbody', true).first();
7233         var tfd = this.getGridEl().select('tfoot', true).first();
7234         
7235         var cw = ctr.getWidth();
7236         
7237         if (tbd) {
7238             
7239             tbd.setSize(ctr.getWidth(),
7240                         ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
7241             );
7242             var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
7243             cw -= barsize;
7244         }
7245         cw = Math.max(cw, this.totalWidth);
7246         this.getGridEl().select('tr',true).setWidth(cw);
7247         // resize 'expandable coloumn?
7248         
7249         return; // we doe not have a view in this design..
7250         
7251     },
7252     onBodyScroll: function()
7253     {
7254         //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
7255         if(this.mainHead){
7256             this.mainHead.setStyle({
7257                 'position' : 'relative',
7258                 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
7259             });
7260         }
7261         
7262         if(this.lazyLoad){
7263             
7264             var scrollHeight = this.mainBody.dom.scrollHeight;
7265             
7266             var scrollTop = Math.ceil(this.mainBody.getScroll().top);
7267             
7268             var height = this.mainBody.getHeight();
7269             
7270             if(scrollHeight - height == scrollTop) {
7271                 
7272                 var total = this.ds.getTotalCount();
7273                 
7274                 if(this.footer.cursor + this.footer.pageSize < total){
7275                     
7276                     this.footer.ds.load({
7277                         params : {
7278                             start : this.footer.cursor + this.footer.pageSize,
7279                             limit : this.footer.pageSize
7280                         },
7281                         add : true
7282                     });
7283                 }
7284             }
7285             
7286         }
7287     },
7288     
7289     onHeaderChange : function()
7290     {
7291         var header = this.renderHeader();
7292         var table = this.el.select('table', true).first();
7293         
7294         this.mainHead.remove();
7295         this.mainHead = table.createChild(header, this.mainBody, false);
7296     },
7297     
7298     onHiddenChange : function(colModel, colIndex, hidden)
7299     {
7300         var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
7301         var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
7302         
7303         this.CSS.updateRule(thSelector, "display", "");
7304         this.CSS.updateRule(tdSelector, "display", "");
7305         
7306         if(hidden){
7307             this.CSS.updateRule(thSelector, "display", "none");
7308             this.CSS.updateRule(tdSelector, "display", "none");
7309         }
7310         
7311         this.onHeaderChange();
7312         this.onLoad();
7313     },
7314     
7315     setColumnWidth: function(col_index, width)
7316     {
7317         // width = "md-2 xs-2..."
7318         if(!this.colModel.config[col_index]) {
7319             return;
7320         }
7321         
7322         var w = width.split(" ");
7323         
7324         var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
7325         
7326         var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
7327         
7328         
7329         for(var j = 0; j < w.length; j++) {
7330             
7331             if(!w[j]) {
7332                 continue;
7333             }
7334             
7335             var size_cls = w[j].split("-");
7336             
7337             if(!Number.isInteger(size_cls[1] * 1)) {
7338                 continue;
7339             }
7340             
7341             if(!this.colModel.config[col_index][size_cls[0]]) {
7342                 continue;
7343             }
7344             
7345             if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
7346                 continue;
7347             }
7348             
7349             h_row[0].classList.replace(
7350                 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
7351                 "col-"+size_cls[0]+"-"+size_cls[1]
7352             );
7353             
7354             for(var i = 0; i < rows.length; i++) {
7355                 
7356                 var size_cls = w[j].split("-");
7357                 
7358                 if(!Number.isInteger(size_cls[1] * 1)) {
7359                     continue;
7360                 }
7361                 
7362                 if(!this.colModel.config[col_index][size_cls[0]]) {
7363                     continue;
7364                 }
7365                 
7366                 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
7367                     continue;
7368                 }
7369                 
7370                 rows[i].classList.replace(
7371                     "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
7372                     "col-"+size_cls[0]+"-"+size_cls[1]
7373                 );
7374             }
7375             
7376             this.colModel.config[col_index][size_cls[0]] = size_cls[1];
7377         }
7378     }
7379 });
7380
7381  
7382
7383  /*
7384  * - LGPL
7385  *
7386  * table cell
7387  * 
7388  */
7389
7390 /**
7391  * @class Roo.bootstrap.TableCell
7392  * @extends Roo.bootstrap.Component
7393  * Bootstrap TableCell class
7394  * @cfg {String} html cell contain text
7395  * @cfg {String} cls cell class
7396  * @cfg {String} tag cell tag (td|th) default td
7397  * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
7398  * @cfg {String} align Aligns the content in a cell
7399  * @cfg {String} axis Categorizes cells
7400  * @cfg {String} bgcolor Specifies the background color of a cell
7401  * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7402  * @cfg {Number} colspan Specifies the number of columns a cell should span
7403  * @cfg {String} headers Specifies one or more header cells a cell is related to
7404  * @cfg {Number} height Sets the height of a cell
7405  * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
7406  * @cfg {Number} rowspan Sets the number of rows a cell should span
7407  * @cfg {String} scope Defines a way to associate header cells and data cells in a table
7408  * @cfg {String} valign Vertical aligns the content in a cell
7409  * @cfg {Number} width Specifies the width of a cell
7410  * 
7411  * @constructor
7412  * Create a new TableCell
7413  * @param {Object} config The config object
7414  */
7415
7416 Roo.bootstrap.TableCell = function(config){
7417     Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
7418 };
7419
7420 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component,  {
7421     
7422     html: false,
7423     cls: false,
7424     tag: false,
7425     abbr: false,
7426     align: false,
7427     axis: false,
7428     bgcolor: false,
7429     charoff: false,
7430     colspan: false,
7431     headers: false,
7432     height: false,
7433     nowrap: false,
7434     rowspan: false,
7435     scope: false,
7436     valign: false,
7437     width: false,
7438     
7439     
7440     getAutoCreate : function(){
7441         var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
7442         
7443         cfg = {
7444             tag: 'td'
7445         };
7446         
7447         if(this.tag){
7448             cfg.tag = this.tag;
7449         }
7450         
7451         if (this.html) {
7452             cfg.html=this.html
7453         }
7454         if (this.cls) {
7455             cfg.cls=this.cls
7456         }
7457         if (this.abbr) {
7458             cfg.abbr=this.abbr
7459         }
7460         if (this.align) {
7461             cfg.align=this.align
7462         }
7463         if (this.axis) {
7464             cfg.axis=this.axis
7465         }
7466         if (this.bgcolor) {
7467             cfg.bgcolor=this.bgcolor
7468         }
7469         if (this.charoff) {
7470             cfg.charoff=this.charoff
7471         }
7472         if (this.colspan) {
7473             cfg.colspan=this.colspan
7474         }
7475         if (this.headers) {
7476             cfg.headers=this.headers
7477         }
7478         if (this.height) {
7479             cfg.height=this.height
7480         }
7481         if (this.nowrap) {
7482             cfg.nowrap=this.nowrap
7483         }
7484         if (this.rowspan) {
7485             cfg.rowspan=this.rowspan
7486         }
7487         if (this.scope) {
7488             cfg.scope=this.scope
7489         }
7490         if (this.valign) {
7491             cfg.valign=this.valign
7492         }
7493         if (this.width) {
7494             cfg.width=this.width
7495         }
7496         
7497         
7498         return cfg;
7499     }
7500    
7501 });
7502
7503  
7504
7505  /*
7506  * - LGPL
7507  *
7508  * table row
7509  * 
7510  */
7511
7512 /**
7513  * @class Roo.bootstrap.TableRow
7514  * @extends Roo.bootstrap.Component
7515  * Bootstrap TableRow class
7516  * @cfg {String} cls row class
7517  * @cfg {String} align Aligns the content in a table row
7518  * @cfg {String} bgcolor Specifies a background color for a table row
7519  * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7520  * @cfg {String} valign Vertical aligns the content in a table row
7521  * 
7522  * @constructor
7523  * Create a new TableRow
7524  * @param {Object} config The config object
7525  */
7526
7527 Roo.bootstrap.TableRow = function(config){
7528     Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7529 };
7530
7531 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component,  {
7532     
7533     cls: false,
7534     align: false,
7535     bgcolor: false,
7536     charoff: false,
7537     valign: false,
7538     
7539     getAutoCreate : function(){
7540         var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7541         
7542         cfg = {
7543             tag: 'tr'
7544         };
7545             
7546         if(this.cls){
7547             cfg.cls = this.cls;
7548         }
7549         if(this.align){
7550             cfg.align = this.align;
7551         }
7552         if(this.bgcolor){
7553             cfg.bgcolor = this.bgcolor;
7554         }
7555         if(this.charoff){
7556             cfg.charoff = this.charoff;
7557         }
7558         if(this.valign){
7559             cfg.valign = this.valign;
7560         }
7561         
7562         return cfg;
7563     }
7564    
7565 });
7566
7567  
7568
7569  /*
7570  * - LGPL
7571  *
7572  * table body
7573  * 
7574  */
7575
7576 /**
7577  * @class Roo.bootstrap.TableBody
7578  * @extends Roo.bootstrap.Component
7579  * Bootstrap TableBody class
7580  * @cfg {String} cls element class
7581  * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7582  * @cfg {String} align Aligns the content inside the element
7583  * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7584  * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7585  * 
7586  * @constructor
7587  * Create a new TableBody
7588  * @param {Object} config The config object
7589  */
7590
7591 Roo.bootstrap.TableBody = function(config){
7592     Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7593 };
7594
7595 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component,  {
7596     
7597     cls: false,
7598     tag: false,
7599     align: false,
7600     charoff: false,
7601     valign: false,
7602     
7603     getAutoCreate : function(){
7604         var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7605         
7606         cfg = {
7607             tag: 'tbody'
7608         };
7609             
7610         if (this.cls) {
7611             cfg.cls=this.cls
7612         }
7613         if(this.tag){
7614             cfg.tag = this.tag;
7615         }
7616         
7617         if(this.align){
7618             cfg.align = this.align;
7619         }
7620         if(this.charoff){
7621             cfg.charoff = this.charoff;
7622         }
7623         if(this.valign){
7624             cfg.valign = this.valign;
7625         }
7626         
7627         return cfg;
7628     }
7629     
7630     
7631 //    initEvents : function()
7632 //    {
7633 //        
7634 //        if(!this.store){
7635 //            return;
7636 //        }
7637 //        
7638 //        this.store = Roo.factory(this.store, Roo.data);
7639 //        this.store.on('load', this.onLoad, this);
7640 //        
7641 //        this.store.load();
7642 //        
7643 //    },
7644 //    
7645 //    onLoad: function () 
7646 //    {   
7647 //        this.fireEvent('load', this);
7648 //    }
7649 //    
7650 //   
7651 });
7652
7653  
7654
7655  /*
7656  * Based on:
7657  * Ext JS Library 1.1.1
7658  * Copyright(c) 2006-2007, Ext JS, LLC.
7659  *
7660  * Originally Released Under LGPL - original licence link has changed is not relivant.
7661  *
7662  * Fork - LGPL
7663  * <script type="text/javascript">
7664  */
7665
7666 // as we use this in bootstrap.
7667 Roo.namespace('Roo.form');
7668  /**
7669  * @class Roo.form.Action
7670  * Internal Class used to handle form actions
7671  * @constructor
7672  * @param {Roo.form.BasicForm} el The form element or its id
7673  * @param {Object} config Configuration options
7674  */
7675
7676  
7677  
7678 // define the action interface
7679 Roo.form.Action = function(form, options){
7680     this.form = form;
7681     this.options = options || {};
7682 };
7683 /**
7684  * Client Validation Failed
7685  * @const 
7686  */
7687 Roo.form.Action.CLIENT_INVALID = 'client';
7688 /**
7689  * Server Validation Failed
7690  * @const 
7691  */
7692 Roo.form.Action.SERVER_INVALID = 'server';
7693  /**
7694  * Connect to Server Failed
7695  * @const 
7696  */
7697 Roo.form.Action.CONNECT_FAILURE = 'connect';
7698 /**
7699  * Reading Data from Server Failed
7700  * @const 
7701  */
7702 Roo.form.Action.LOAD_FAILURE = 'load';
7703
7704 Roo.form.Action.prototype = {
7705     type : 'default',
7706     failureType : undefined,
7707     response : undefined,
7708     result : undefined,
7709
7710     // interface method
7711     run : function(options){
7712
7713     },
7714
7715     // interface method
7716     success : function(response){
7717
7718     },
7719
7720     // interface method
7721     handleResponse : function(response){
7722
7723     },
7724
7725     // default connection failure
7726     failure : function(response){
7727         
7728         this.response = response;
7729         this.failureType = Roo.form.Action.CONNECT_FAILURE;
7730         this.form.afterAction(this, false);
7731     },
7732
7733     processResponse : function(response){
7734         this.response = response;
7735         if(!response.responseText){
7736             return true;
7737         }
7738         this.result = this.handleResponse(response);
7739         return this.result;
7740     },
7741
7742     // utility functions used internally
7743     getUrl : function(appendParams){
7744         var url = this.options.url || this.form.url || this.form.el.dom.action;
7745         if(appendParams){
7746             var p = this.getParams();
7747             if(p){
7748                 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7749             }
7750         }
7751         return url;
7752     },
7753
7754     getMethod : function(){
7755         return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7756     },
7757
7758     getParams : function(){
7759         var bp = this.form.baseParams;
7760         var p = this.options.params;
7761         if(p){
7762             if(typeof p == "object"){
7763                 p = Roo.urlEncode(Roo.applyIf(p, bp));
7764             }else if(typeof p == 'string' && bp){
7765                 p += '&' + Roo.urlEncode(bp);
7766             }
7767         }else if(bp){
7768             p = Roo.urlEncode(bp);
7769         }
7770         return p;
7771     },
7772
7773     createCallback : function(){
7774         return {
7775             success: this.success,
7776             failure: this.failure,
7777             scope: this,
7778             timeout: (this.form.timeout*1000),
7779             upload: this.form.fileUpload ? this.success : undefined
7780         };
7781     }
7782 };
7783
7784 Roo.form.Action.Submit = function(form, options){
7785     Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7786 };
7787
7788 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7789     type : 'submit',
7790
7791     haveProgress : false,
7792     uploadComplete : false,
7793     
7794     // uploadProgress indicator.
7795     uploadProgress : function()
7796     {
7797         if (!this.form.progressUrl) {
7798             return;
7799         }
7800         
7801         if (!this.haveProgress) {
7802             Roo.MessageBox.progress("Uploading", "Uploading");
7803         }
7804         if (this.uploadComplete) {
7805            Roo.MessageBox.hide();
7806            return;
7807         }
7808         
7809         this.haveProgress = true;
7810    
7811         var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7812         
7813         var c = new Roo.data.Connection();
7814         c.request({
7815             url : this.form.progressUrl,
7816             params: {
7817                 id : uid
7818             },
7819             method: 'GET',
7820             success : function(req){
7821                //console.log(data);
7822                 var rdata = false;
7823                 var edata;
7824                 try  {
7825                    rdata = Roo.decode(req.responseText)
7826                 } catch (e) {
7827                     Roo.log("Invalid data from server..");
7828                     Roo.log(edata);
7829                     return;
7830                 }
7831                 if (!rdata || !rdata.success) {
7832                     Roo.log(rdata);
7833                     Roo.MessageBox.alert(Roo.encode(rdata));
7834                     return;
7835                 }
7836                 var data = rdata.data;
7837                 
7838                 if (this.uploadComplete) {
7839                    Roo.MessageBox.hide();
7840                    return;
7841                 }
7842                    
7843                 if (data){
7844                     Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7845                        Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7846                     );
7847                 }
7848                 this.uploadProgress.defer(2000,this);
7849             },
7850        
7851             failure: function(data) {
7852                 Roo.log('progress url failed ');
7853                 Roo.log(data);
7854             },
7855             scope : this
7856         });
7857            
7858     },
7859     
7860     
7861     run : function()
7862     {
7863         // run get Values on the form, so it syncs any secondary forms.
7864         this.form.getValues();
7865         
7866         var o = this.options;
7867         var method = this.getMethod();
7868         var isPost = method == 'POST';
7869         if(o.clientValidation === false || this.form.isValid()){
7870             
7871             if (this.form.progressUrl) {
7872                 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7873                     (new Date() * 1) + '' + Math.random());
7874                     
7875             } 
7876             
7877             
7878             Roo.Ajax.request(Roo.apply(this.createCallback(), {
7879                 form:this.form.el.dom,
7880                 url:this.getUrl(!isPost),
7881                 method: method,
7882                 params:isPost ? this.getParams() : null,
7883                 isUpload: this.form.fileUpload
7884             }));
7885             
7886             this.uploadProgress();
7887
7888         }else if (o.clientValidation !== false){ // client validation failed
7889             this.failureType = Roo.form.Action.CLIENT_INVALID;
7890             this.form.afterAction(this, false);
7891         }
7892     },
7893
7894     success : function(response)
7895     {
7896         this.uploadComplete= true;
7897         if (this.haveProgress) {
7898             Roo.MessageBox.hide();
7899         }
7900         
7901         
7902         var result = this.processResponse(response);
7903         if(result === true || result.success){
7904             this.form.afterAction(this, true);
7905             return;
7906         }
7907         if(result.errors){
7908             this.form.markInvalid(result.errors);
7909             this.failureType = Roo.form.Action.SERVER_INVALID;
7910         }
7911         this.form.afterAction(this, false);
7912     },
7913     failure : function(response)
7914     {
7915         this.uploadComplete= true;
7916         if (this.haveProgress) {
7917             Roo.MessageBox.hide();
7918         }
7919         
7920         this.response = response;
7921         this.failureType = Roo.form.Action.CONNECT_FAILURE;
7922         this.form.afterAction(this, false);
7923     },
7924     
7925     handleResponse : function(response){
7926         if(this.form.errorReader){
7927             var rs = this.form.errorReader.read(response);
7928             var errors = [];
7929             if(rs.records){
7930                 for(var i = 0, len = rs.records.length; i < len; i++) {
7931                     var r = rs.records[i];
7932                     errors[i] = r.data;
7933                 }
7934             }
7935             if(errors.length < 1){
7936                 errors = null;
7937             }
7938             return {
7939                 success : rs.success,
7940                 errors : errors
7941             };
7942         }
7943         var ret = false;
7944         try {
7945             ret = Roo.decode(response.responseText);
7946         } catch (e) {
7947             ret = {
7948                 success: false,
7949                 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7950                 errors : []
7951             };
7952         }
7953         return ret;
7954         
7955     }
7956 });
7957
7958
7959 Roo.form.Action.Load = function(form, options){
7960     Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7961     this.reader = this.form.reader;
7962 };
7963
7964 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7965     type : 'load',
7966
7967     run : function(){
7968         
7969         Roo.Ajax.request(Roo.apply(
7970                 this.createCallback(), {
7971                     method:this.getMethod(),
7972                     url:this.getUrl(false),
7973                     params:this.getParams()
7974         }));
7975     },
7976
7977     success : function(response){
7978         
7979         var result = this.processResponse(response);
7980         if(result === true || !result.success || !result.data){
7981             this.failureType = Roo.form.Action.LOAD_FAILURE;
7982             this.form.afterAction(this, false);
7983             return;
7984         }
7985         this.form.clearInvalid();
7986         this.form.setValues(result.data);
7987         this.form.afterAction(this, true);
7988     },
7989
7990     handleResponse : function(response){
7991         if(this.form.reader){
7992             var rs = this.form.reader.read(response);
7993             var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7994             return {
7995                 success : rs.success,
7996                 data : data
7997             };
7998         }
7999         return Roo.decode(response.responseText);
8000     }
8001 });
8002
8003 Roo.form.Action.ACTION_TYPES = {
8004     'load' : Roo.form.Action.Load,
8005     'submit' : Roo.form.Action.Submit
8006 };/*
8007  * - LGPL
8008  *
8009  * form
8010  *
8011  */
8012
8013 /**
8014  * @class Roo.bootstrap.Form
8015  * @extends Roo.bootstrap.Component
8016  * Bootstrap Form class
8017  * @cfg {String} method  GET | POST (default POST)
8018  * @cfg {String} labelAlign top | left (default top)
8019  * @cfg {String} align left  | right - for navbars
8020  * @cfg {Boolean} loadMask load mask when submit (default true)
8021
8022  *
8023  * @constructor
8024  * Create a new Form
8025  * @param {Object} config The config object
8026  */
8027
8028
8029 Roo.bootstrap.Form = function(config){
8030     
8031     Roo.bootstrap.Form.superclass.constructor.call(this, config);
8032     
8033     Roo.bootstrap.Form.popover.apply();
8034     
8035     this.addEvents({
8036         /**
8037          * @event clientvalidation
8038          * If the monitorValid config option is true, this event fires repetitively to notify of valid state
8039          * @param {Form} this
8040          * @param {Boolean} valid true if the form has passed client-side validation
8041          */
8042         clientvalidation: true,
8043         /**
8044          * @event beforeaction
8045          * Fires before any action is performed. Return false to cancel the action.
8046          * @param {Form} this
8047          * @param {Action} action The action to be performed
8048          */
8049         beforeaction: true,
8050         /**
8051          * @event actionfailed
8052          * Fires when an action fails.
8053          * @param {Form} this
8054          * @param {Action} action The action that failed
8055          */
8056         actionfailed : true,
8057         /**
8058          * @event actioncomplete
8059          * Fires when an action is completed.
8060          * @param {Form} this
8061          * @param {Action} action The action that completed
8062          */
8063         actioncomplete : true
8064     });
8065 };
8066
8067 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component,  {
8068
8069      /**
8070      * @cfg {String} method
8071      * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
8072      */
8073     method : 'POST',
8074     /**
8075      * @cfg {String} url
8076      * The URL to use for form actions if one isn't supplied in the action options.
8077      */
8078     /**
8079      * @cfg {Boolean} fileUpload
8080      * Set to true if this form is a file upload.
8081      */
8082
8083     /**
8084      * @cfg {Object} baseParams
8085      * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
8086      */
8087
8088     /**
8089      * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
8090      */
8091     timeout: 30,
8092     /**
8093      * @cfg {Sting} align (left|right) for navbar forms
8094      */
8095     align : 'left',
8096
8097     // private
8098     activeAction : null,
8099
8100     /**
8101      * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
8102      * element by passing it or its id or mask the form itself by passing in true.
8103      * @type Mixed
8104      */
8105     waitMsgTarget : false,
8106
8107     loadMask : true,
8108     
8109     /**
8110      * @cfg {Boolean} errorMask (true|false) default false
8111      */
8112     errorMask : false,
8113     
8114     /**
8115      * @cfg {Number} maskOffset Default 100
8116      */
8117     maskOffset : 100,
8118     
8119     /**
8120      * @cfg {Boolean} maskBody
8121      */
8122     maskBody : false,
8123
8124     getAutoCreate : function(){
8125
8126         var cfg = {
8127             tag: 'form',
8128             method : this.method || 'POST',
8129             id : this.id || Roo.id(),
8130             cls : ''
8131         };
8132         if (this.parent().xtype.match(/^Nav/)) {
8133             cfg.cls = 'navbar-form form-inline navbar-' + this.align;
8134
8135         }
8136
8137         if (this.labelAlign == 'left' ) {
8138             cfg.cls += ' form-horizontal';
8139         }
8140
8141
8142         return cfg;
8143     },
8144     initEvents : function()
8145     {
8146         this.el.on('submit', this.onSubmit, this);
8147         // this was added as random key presses on the form where triggering form submit.
8148         this.el.on('keypress', function(e) {
8149             if (e.getCharCode() != 13) {
8150                 return true;
8151             }
8152             // we might need to allow it for textareas.. and some other items.
8153             // check e.getTarget().
8154
8155             if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
8156                 return true;
8157             }
8158
8159             Roo.log("keypress blocked");
8160
8161             e.preventDefault();
8162             return false;
8163         });
8164         
8165     },
8166     // private
8167     onSubmit : function(e){
8168         e.stopEvent();
8169     },
8170
8171      /**
8172      * Returns true if client-side validation on the form is successful.
8173      * @return Boolean
8174      */
8175     isValid : function(){
8176         var items = this.getItems();
8177         var valid = true;
8178         var target = false;
8179         
8180         items.each(function(f){
8181             
8182             if(f.validate()){
8183                 return;
8184             }
8185             
8186             Roo.log('invalid field: ' + f.name);
8187             
8188             valid = false;
8189
8190             if(!target && f.el.isVisible(true)){
8191                 target = f;
8192             }
8193            
8194         });
8195         
8196         if(this.errorMask && !valid){
8197             Roo.bootstrap.Form.popover.mask(this, target);
8198         }
8199         
8200         return valid;
8201     },
8202     
8203     /**
8204      * Returns true if any fields in this form have changed since their original load.
8205      * @return Boolean
8206      */
8207     isDirty : function(){
8208         var dirty = false;
8209         var items = this.getItems();
8210         items.each(function(f){
8211            if(f.isDirty()){
8212                dirty = true;
8213                return false;
8214            }
8215            return true;
8216         });
8217         return dirty;
8218     },
8219      /**
8220      * Performs a predefined action (submit or load) or custom actions you define on this form.
8221      * @param {String} actionName The name of the action type
8222      * @param {Object} options (optional) The options to pass to the action.  All of the config options listed
8223      * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
8224      * accept other config options):
8225      * <pre>
8226 Property          Type             Description
8227 ----------------  ---------------  ----------------------------------------------------------------------------------
8228 url               String           The url for the action (defaults to the form's url)
8229 method            String           The form method to use (defaults to the form's method, or POST if not defined)
8230 params            String/Object    The params to pass (defaults to the form's baseParams, or none if not defined)
8231 clientValidation  Boolean          Applies to submit only.  Pass true to call form.isValid() prior to posting to
8232                                    validate the form on the client (defaults to false)
8233      * </pre>
8234      * @return {BasicForm} this
8235      */
8236     doAction : function(action, options){
8237         if(typeof action == 'string'){
8238             action = new Roo.form.Action.ACTION_TYPES[action](this, options);
8239         }
8240         if(this.fireEvent('beforeaction', this, action) !== false){
8241             this.beforeAction(action);
8242             action.run.defer(100, action);
8243         }
8244         return this;
8245     },
8246
8247     // private
8248     beforeAction : function(action){
8249         var o = action.options;
8250         
8251         if(this.loadMask){
8252             
8253             if(this.maskBody){
8254                 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
8255             } else {
8256                 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
8257             }
8258         }
8259         // not really supported yet.. ??
8260
8261         //if(this.waitMsgTarget === true){
8262         //  this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
8263         //}else if(this.waitMsgTarget){
8264         //    this.waitMsgTarget = Roo.get(this.waitMsgTarget);
8265         //    this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
8266         //}else {
8267         //    Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
8268        // }
8269
8270     },
8271
8272     // private
8273     afterAction : function(action, success){
8274         this.activeAction = null;
8275         var o = action.options;
8276
8277         if(this.loadMask){
8278             
8279             if(this.maskBody){
8280                 Roo.get(document.body).unmask();
8281             } else {
8282                 this.el.unmask();
8283             }
8284         }
8285         
8286         //if(this.waitMsgTarget === true){
8287 //            this.el.unmask();
8288         //}else if(this.waitMsgTarget){
8289         //    this.waitMsgTarget.unmask();
8290         //}else{
8291         //    Roo.MessageBox.updateProgress(1);
8292         //    Roo.MessageBox.hide();
8293        // }
8294         //
8295         if(success){
8296             if(o.reset){
8297                 this.reset();
8298             }
8299             Roo.callback(o.success, o.scope, [this, action]);
8300             this.fireEvent('actioncomplete', this, action);
8301
8302         }else{
8303
8304             // failure condition..
8305             // we have a scenario where updates need confirming.
8306             // eg. if a locking scenario exists..
8307             // we look for { errors : { needs_confirm : true }} in the response.
8308             if (
8309                 (typeof(action.result) != 'undefined')  &&
8310                 (typeof(action.result.errors) != 'undefined')  &&
8311                 (typeof(action.result.errors.needs_confirm) != 'undefined')
8312            ){
8313                 var _t = this;
8314                 Roo.log("not supported yet");
8315                  /*
8316
8317                 Roo.MessageBox.confirm(
8318                     "Change requires confirmation",
8319                     action.result.errorMsg,
8320                     function(r) {
8321                         if (r != 'yes') {
8322                             return;
8323                         }
8324                         _t.doAction('submit', { params :  { _submit_confirmed : 1 } }  );
8325                     }
8326
8327                 );
8328                 */
8329
8330
8331                 return;
8332             }
8333
8334             Roo.callback(o.failure, o.scope, [this, action]);
8335             // show an error message if no failed handler is set..
8336             if (!this.hasListener('actionfailed')) {
8337                 Roo.log("need to add dialog support");
8338                 /*
8339                 Roo.MessageBox.alert("Error",
8340                     (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
8341                         action.result.errorMsg :
8342                         "Saving Failed, please check your entries or try again"
8343                 );
8344                 */
8345             }
8346
8347             this.fireEvent('actionfailed', this, action);
8348         }
8349
8350     },
8351     /**
8352      * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
8353      * @param {String} id The value to search for
8354      * @return Field
8355      */
8356     findField : function(id){
8357         var items = this.getItems();
8358         var field = items.get(id);
8359         if(!field){
8360              items.each(function(f){
8361                 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
8362                     field = f;
8363                     return false;
8364                 }
8365                 return true;
8366             });
8367         }
8368         return field || null;
8369     },
8370      /**
8371      * Mark fields in this form invalid in bulk.
8372      * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
8373      * @return {BasicForm} this
8374      */
8375     markInvalid : function(errors){
8376         if(errors instanceof Array){
8377             for(var i = 0, len = errors.length; i < len; i++){
8378                 var fieldError = errors[i];
8379                 var f = this.findField(fieldError.id);
8380                 if(f){
8381                     f.markInvalid(fieldError.msg);
8382                 }
8383             }
8384         }else{
8385             var field, id;
8386             for(id in errors){
8387                 if(typeof errors[id] != 'function' && (field = this.findField(id))){
8388                     field.markInvalid(errors[id]);
8389                 }
8390             }
8391         }
8392         //Roo.each(this.childForms || [], function (f) {
8393         //    f.markInvalid(errors);
8394         //});
8395
8396         return this;
8397     },
8398
8399     /**
8400      * Set values for fields in this form in bulk.
8401      * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
8402      * @return {BasicForm} this
8403      */
8404     setValues : function(values){
8405         if(values instanceof Array){ // array of objects
8406             for(var i = 0, len = values.length; i < len; i++){
8407                 var v = values[i];
8408                 var f = this.findField(v.id);
8409                 if(f){
8410                     f.setValue(v.value);
8411                     if(this.trackResetOnLoad){
8412                         f.originalValue = f.getValue();
8413                     }
8414                 }
8415             }
8416         }else{ // object hash
8417             var field, id;
8418             for(id in values){
8419                 if(typeof values[id] != 'function' && (field = this.findField(id))){
8420
8421                     if (field.setFromData &&
8422                         field.valueField &&
8423                         field.displayField &&
8424                         // combos' with local stores can
8425                         // be queried via setValue()
8426                         // to set their value..
8427                         (field.store && !field.store.isLocal)
8428                         ) {
8429                         // it's a combo
8430                         var sd = { };
8431                         sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
8432                         sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
8433                         field.setFromData(sd);
8434
8435                     } else if(field.setFromData && (field.store && !field.store.isLocal)) {
8436                         
8437                         field.setFromData(values);
8438                         
8439                     } else {
8440                         field.setValue(values[id]);
8441                     }
8442
8443
8444                     if(this.trackResetOnLoad){
8445                         field.originalValue = field.getValue();
8446                     }
8447                 }
8448             }
8449         }
8450
8451         //Roo.each(this.childForms || [], function (f) {
8452         //    f.setValues(values);
8453         //});
8454
8455         return this;
8456     },
8457
8458     /**
8459      * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
8460      * they are returned as an array.
8461      * @param {Boolean} asString
8462      * @return {Object}
8463      */
8464     getValues : function(asString){
8465         //if (this.childForms) {
8466             // copy values from the child forms
8467         //    Roo.each(this.childForms, function (f) {
8468         //        this.setValues(f.getValues());
8469         //    }, this);
8470         //}
8471
8472
8473
8474         var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
8475         if(asString === true){
8476             return fs;
8477         }
8478         return Roo.urlDecode(fs);
8479     },
8480
8481     /**
8482      * Returns the fields in this form as an object with key/value pairs.
8483      * This differs from getValues as it calls getValue on each child item, rather than using dom data.
8484      * @return {Object}
8485      */
8486     getFieldValues : function(with_hidden)
8487     {
8488         var items = this.getItems();
8489         var ret = {};
8490         items.each(function(f){
8491             
8492             if (!f.getName()) {
8493                 return;
8494             }
8495             
8496             var v = f.getValue();
8497             
8498             if (f.inputType =='radio') {
8499                 if (typeof(ret[f.getName()]) == 'undefined') {
8500                     ret[f.getName()] = ''; // empty..
8501                 }
8502
8503                 if (!f.el.dom.checked) {
8504                     return;
8505
8506                 }
8507                 v = f.el.dom.value;
8508
8509             }
8510             
8511             if(f.xtype == 'MoneyField'){
8512                 ret[f.currencyName] = f.getCurrency();
8513             }
8514
8515             // not sure if this supported any more..
8516             if ((typeof(v) == 'object') && f.getRawValue) {
8517                 v = f.getRawValue() ; // dates..
8518             }
8519             // combo boxes where name != hiddenName...
8520             if (f.name !== false && f.name != '' && f.name != f.getName()) {
8521                 ret[f.name] = f.getRawValue();
8522             }
8523             ret[f.getName()] = v;
8524         });
8525
8526         return ret;
8527     },
8528
8529     /**
8530      * Clears all invalid messages in this form.
8531      * @return {BasicForm} this
8532      */
8533     clearInvalid : function(){
8534         var items = this.getItems();
8535
8536         items.each(function(f){
8537            f.clearInvalid();
8538         });
8539
8540         return this;
8541     },
8542
8543     /**
8544      * Resets this form.
8545      * @return {BasicForm} this
8546      */
8547     reset : function(){
8548         var items = this.getItems();
8549         items.each(function(f){
8550             f.reset();
8551         });
8552
8553         Roo.each(this.childForms || [], function (f) {
8554             f.reset();
8555         });
8556
8557
8558         return this;
8559     },
8560     
8561     getItems : function()
8562     {
8563         var r=new Roo.util.MixedCollection(false, function(o){
8564             return o.id || (o.id = Roo.id());
8565         });
8566         var iter = function(el) {
8567             if (el.inputEl) {
8568                 r.add(el);
8569             }
8570             if (!el.items) {
8571                 return;
8572             }
8573             Roo.each(el.items,function(e) {
8574                 iter(e);
8575             });
8576         };
8577
8578         iter(this);
8579         return r;
8580     },
8581     
8582     hideFields : function(items)
8583     {
8584         Roo.each(items, function(i){
8585             
8586             var f = this.findField(i);
8587             
8588             if(!f){
8589                 return;
8590             }
8591             
8592             f.hide();
8593             
8594         }, this);
8595     },
8596     
8597     showFields : function(items)
8598     {
8599         Roo.each(items, function(i){
8600             
8601             var f = this.findField(i);
8602             
8603             if(!f){
8604                 return;
8605             }
8606             
8607             f.show();
8608             
8609         }, this);
8610     }
8611
8612 });
8613
8614 Roo.apply(Roo.bootstrap.Form, {
8615     
8616     popover : {
8617         
8618         padding : 5,
8619         
8620         isApplied : false,
8621         
8622         isMasked : false,
8623         
8624         form : false,
8625         
8626         target : false,
8627         
8628         toolTip : false,
8629         
8630         intervalID : false,
8631         
8632         maskEl : false,
8633         
8634         apply : function()
8635         {
8636             if(this.isApplied){
8637                 return;
8638             }
8639             
8640             this.maskEl = {
8641                 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8642                 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8643                 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8644                 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8645             };
8646             
8647             this.maskEl.top.enableDisplayMode("block");
8648             this.maskEl.left.enableDisplayMode("block");
8649             this.maskEl.bottom.enableDisplayMode("block");
8650             this.maskEl.right.enableDisplayMode("block");
8651             
8652             this.toolTip = new Roo.bootstrap.Tooltip({
8653                 cls : 'roo-form-error-popover',
8654                 alignment : {
8655                     'left' : ['r-l', [-2,0], 'right'],
8656                     'right' : ['l-r', [2,0], 'left'],
8657                     'bottom' : ['tl-bl', [0,2], 'top'],
8658                     'top' : [ 'bl-tl', [0,-2], 'bottom']
8659                 }
8660             });
8661             
8662             this.toolTip.render(Roo.get(document.body));
8663
8664             this.toolTip.el.enableDisplayMode("block");
8665             
8666             Roo.get(document.body).on('click', function(){
8667                 this.unmask();
8668             }, this);
8669             
8670             Roo.get(document.body).on('touchstart', function(){
8671                 this.unmask();
8672             }, this);
8673             
8674             this.isApplied = true
8675         },
8676         
8677         mask : function(form, target)
8678         {
8679             this.form = form;
8680             
8681             this.target = target;
8682             
8683             if(!this.form.errorMask || !target.el){
8684                 return;
8685             }
8686             
8687             var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8688             
8689             Roo.log(scrollable);
8690             
8691             var ot = this.target.el.calcOffsetsTo(scrollable);
8692             
8693             var scrollTo = ot[1] - this.form.maskOffset;
8694             
8695             scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
8696             
8697             scrollable.scrollTo('top', scrollTo);
8698             
8699             var box = this.target.el.getBox();
8700             Roo.log(box);
8701             var zIndex = Roo.bootstrap.Modal.zIndex++;
8702
8703             
8704             this.maskEl.top.setStyle('position', 'absolute');
8705             this.maskEl.top.setStyle('z-index', zIndex);
8706             this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8707             this.maskEl.top.setLeft(0);
8708             this.maskEl.top.setTop(0);
8709             this.maskEl.top.show();
8710             
8711             this.maskEl.left.setStyle('position', 'absolute');
8712             this.maskEl.left.setStyle('z-index', zIndex);
8713             this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
8714             this.maskEl.left.setLeft(0);
8715             this.maskEl.left.setTop(box.y - this.padding);
8716             this.maskEl.left.show();
8717
8718             this.maskEl.bottom.setStyle('position', 'absolute');
8719             this.maskEl.bottom.setStyle('z-index', zIndex);
8720             this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8721             this.maskEl.bottom.setLeft(0);
8722             this.maskEl.bottom.setTop(box.bottom + this.padding);
8723             this.maskEl.bottom.show();
8724
8725             this.maskEl.right.setStyle('position', 'absolute');
8726             this.maskEl.right.setStyle('z-index', zIndex);
8727             this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8728             this.maskEl.right.setLeft(box.right + this.padding);
8729             this.maskEl.right.setTop(box.y - this.padding);
8730             this.maskEl.right.show();
8731
8732             this.toolTip.bindEl = this.target.el;
8733
8734             this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8735
8736             var tip = this.target.blankText;
8737
8738             if(this.target.getValue() !== '' ) {
8739                 
8740                 if (this.target.invalidText.length) {
8741                     tip = this.target.invalidText;
8742                 } else if (this.target.regexText.length){
8743                     tip = this.target.regexText;
8744                 }
8745             }
8746
8747             this.toolTip.show(tip);
8748
8749             this.intervalID = window.setInterval(function() {
8750                 Roo.bootstrap.Form.popover.unmask();
8751             }, 10000);
8752
8753             window.onwheel = function(){ return false;};
8754             
8755             (function(){ this.isMasked = true; }).defer(500, this);
8756             
8757         },
8758         
8759         unmask : function()
8760         {
8761             if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8762                 return;
8763             }
8764             
8765             this.maskEl.top.setStyle('position', 'absolute');
8766             this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8767             this.maskEl.top.hide();
8768
8769             this.maskEl.left.setStyle('position', 'absolute');
8770             this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8771             this.maskEl.left.hide();
8772
8773             this.maskEl.bottom.setStyle('position', 'absolute');
8774             this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8775             this.maskEl.bottom.hide();
8776
8777             this.maskEl.right.setStyle('position', 'absolute');
8778             this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8779             this.maskEl.right.hide();
8780             
8781             this.toolTip.hide();
8782             
8783             this.toolTip.el.hide();
8784             
8785             window.onwheel = function(){ return true;};
8786             
8787             if(this.intervalID){
8788                 window.clearInterval(this.intervalID);
8789                 this.intervalID = false;
8790             }
8791             
8792             this.isMasked = false;
8793             
8794         }
8795         
8796     }
8797     
8798 });
8799
8800 /*
8801  * Based on:
8802  * Ext JS Library 1.1.1
8803  * Copyright(c) 2006-2007, Ext JS, LLC.
8804  *
8805  * Originally Released Under LGPL - original licence link has changed is not relivant.
8806  *
8807  * Fork - LGPL
8808  * <script type="text/javascript">
8809  */
8810 /**
8811  * @class Roo.form.VTypes
8812  * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8813  * @singleton
8814  */
8815 Roo.form.VTypes = function(){
8816     // closure these in so they are only created once.
8817     var alpha = /^[a-zA-Z_]+$/;
8818     var alphanum = /^[a-zA-Z0-9_]+$/;
8819     var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8820     var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8821
8822     // All these messages and functions are configurable
8823     return {
8824         /**
8825          * The function used to validate email addresses
8826          * @param {String} value The email address
8827          */
8828         'email' : function(v){
8829             return email.test(v);
8830         },
8831         /**
8832          * The error text to display when the email validation function returns false
8833          * @type String
8834          */
8835         'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8836         /**
8837          * The keystroke filter mask to be applied on email input
8838          * @type RegExp
8839          */
8840         'emailMask' : /[a-z0-9_\.\-@]/i,
8841
8842         /**
8843          * The function used to validate URLs
8844          * @param {String} value The URL
8845          */
8846         'url' : function(v){
8847             return url.test(v);
8848         },
8849         /**
8850          * The error text to display when the url validation function returns false
8851          * @type String
8852          */
8853         'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8854         
8855         /**
8856          * The function used to validate alpha values
8857          * @param {String} value The value
8858          */
8859         'alpha' : function(v){
8860             return alpha.test(v);
8861         },
8862         /**
8863          * The error text to display when the alpha validation function returns false
8864          * @type String
8865          */
8866         'alphaText' : 'This field should only contain letters and _',
8867         /**
8868          * The keystroke filter mask to be applied on alpha input
8869          * @type RegExp
8870          */
8871         'alphaMask' : /[a-z_]/i,
8872
8873         /**
8874          * The function used to validate alphanumeric values
8875          * @param {String} value The value
8876          */
8877         'alphanum' : function(v){
8878             return alphanum.test(v);
8879         },
8880         /**
8881          * The error text to display when the alphanumeric validation function returns false
8882          * @type String
8883          */
8884         'alphanumText' : 'This field should only contain letters, numbers and _',
8885         /**
8886          * The keystroke filter mask to be applied on alphanumeric input
8887          * @type RegExp
8888          */
8889         'alphanumMask' : /[a-z0-9_]/i
8890     };
8891 }();/*
8892  * - LGPL
8893  *
8894  * Input
8895  * 
8896  */
8897
8898 /**
8899  * @class Roo.bootstrap.Input
8900  * @extends Roo.bootstrap.Component
8901  * Bootstrap Input class
8902  * @cfg {Boolean} disabled is it disabled
8903  * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8904  * @cfg {String} name name of the input
8905  * @cfg {string} fieldLabel - the label associated
8906  * @cfg {string} placeholder - placeholder to put in text.
8907  * @cfg {string}  before - input group add on before
8908  * @cfg {string} after - input group add on after
8909  * @cfg {string} size - (lg|sm) or leave empty..
8910  * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8911  * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8912  * @cfg {Number} md colspan out of 12 for computer-sized screens
8913  * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8914  * @cfg {string} value default value of the input
8915  * @cfg {Number} labelWidth set the width of label 
8916  * @cfg {Number} labellg set the width of label (1-12)
8917  * @cfg {Number} labelmd set the width of label (1-12)
8918  * @cfg {Number} labelsm set the width of label (1-12)
8919  * @cfg {Number} labelxs set the width of label (1-12)
8920  * @cfg {String} labelAlign (top|left)
8921  * @cfg {Boolean} readOnly Specifies that the field should be read-only
8922  * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8923  * @cfg {String} indicatorpos (left|right) default left
8924  * @cfg {String} capture (user|camera) use for file input only. (default empty)
8925  * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
8926
8927  * @cfg {String} align (left|center|right) Default left
8928  * @cfg {Boolean} forceFeedback (true|false) Default false
8929  * 
8930  * @constructor
8931  * Create a new Input
8932  * @param {Object} config The config object
8933  */
8934
8935 Roo.bootstrap.Input = function(config){
8936     
8937     Roo.bootstrap.Input.superclass.constructor.call(this, config);
8938     
8939     this.addEvents({
8940         /**
8941          * @event focus
8942          * Fires when this field receives input focus.
8943          * @param {Roo.form.Field} this
8944          */
8945         focus : true,
8946         /**
8947          * @event blur
8948          * Fires when this field loses input focus.
8949          * @param {Roo.form.Field} this
8950          */
8951         blur : true,
8952         /**
8953          * @event specialkey
8954          * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed.  You can check
8955          * {@link Roo.EventObject#getKey} to determine which key was pressed.
8956          * @param {Roo.form.Field} this
8957          * @param {Roo.EventObject} e The event object
8958          */
8959         specialkey : true,
8960         /**
8961          * @event change
8962          * Fires just before the field blurs if the field value has changed.
8963          * @param {Roo.form.Field} this
8964          * @param {Mixed} newValue The new value
8965          * @param {Mixed} oldValue The original value
8966          */
8967         change : true,
8968         /**
8969          * @event invalid
8970          * Fires after the field has been marked as invalid.
8971          * @param {Roo.form.Field} this
8972          * @param {String} msg The validation message
8973          */
8974         invalid : true,
8975         /**
8976          * @event valid
8977          * Fires after the field has been validated with no errors.
8978          * @param {Roo.form.Field} this
8979          */
8980         valid : true,
8981          /**
8982          * @event keyup
8983          * Fires after the key up
8984          * @param {Roo.form.Field} this
8985          * @param {Roo.EventObject}  e The event Object
8986          */
8987         keyup : true
8988     });
8989 };
8990
8991 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component,  {
8992      /**
8993      * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8994       automatic validation (defaults to "keyup").
8995      */
8996     validationEvent : "keyup",
8997      /**
8998      * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8999      */
9000     validateOnBlur : true,
9001     /**
9002      * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
9003      */
9004     validationDelay : 250,
9005      /**
9006      * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
9007      */
9008     focusClass : "x-form-focus",  // not needed???
9009     
9010        
9011     /**
9012      * @cfg {String} invalidClass DEPRICATED - code uses BS4 - is-valid / is-invalid
9013      */
9014     invalidClass : "has-warning",
9015     
9016     /**
9017      * @cfg {String} validClass DEPRICATED - code uses BS4 - is-valid / is-invalid
9018      */
9019     validClass : "has-success",
9020     
9021     /**
9022      * @cfg {Boolean} hasFeedback (true|false) default true
9023      */
9024     hasFeedback : true,
9025     
9026     /**
9027      * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
9028      */
9029     invalidFeedbackClass : "glyphicon-warning-sign",
9030     
9031     /**
9032      * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
9033      */
9034     validFeedbackClass : "glyphicon-ok",
9035     
9036     /**
9037      * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
9038      */
9039     selectOnFocus : false,
9040     
9041      /**
9042      * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
9043      */
9044     maskRe : null,
9045        /**
9046      * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
9047      */
9048     vtype : null,
9049     
9050       /**
9051      * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
9052      */
9053     disableKeyFilter : false,
9054     
9055        /**
9056      * @cfg {Boolean} disabled True to disable the field (defaults to false).
9057      */
9058     disabled : false,
9059      /**
9060      * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
9061      */
9062     allowBlank : true,
9063     /**
9064      * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
9065      */
9066     blankText : "Please complete this mandatory field",
9067     
9068      /**
9069      * @cfg {Number} minLength Minimum input field length required (defaults to 0)
9070      */
9071     minLength : 0,
9072     /**
9073      * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
9074      */
9075     maxLength : Number.MAX_VALUE,
9076     /**
9077      * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
9078      */
9079     minLengthText : "The minimum length for this field is {0}",
9080     /**
9081      * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
9082      */
9083     maxLengthText : "The maximum length for this field is {0}",
9084   
9085     
9086     /**
9087      * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
9088      * If available, this function will be called only after the basic validators all return true, and will be passed the
9089      * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
9090      */
9091     validator : null,
9092     /**
9093      * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
9094      * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
9095      * current field value.  If the test fails, the field will be marked invalid using {@link #regexText}.
9096      */
9097     regex : null,
9098     /**
9099      * @cfg {String} regexText -- Depricated - use Invalid Text
9100      */
9101     regexText : "",
9102     
9103     /**
9104      * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
9105      */
9106     invalidText : "",
9107     
9108     
9109     
9110     autocomplete: false,
9111     
9112     
9113     fieldLabel : '',
9114     inputType : 'text',
9115     
9116     name : false,
9117     placeholder: false,
9118     before : false,
9119     after : false,
9120     size : false,
9121     hasFocus : false,
9122     preventMark: false,
9123     isFormField : true,
9124     value : '',
9125     labelWidth : 2,
9126     labelAlign : false,
9127     readOnly : false,
9128     align : false,
9129     formatedValue : false,
9130     forceFeedback : false,
9131     
9132     indicatorpos : 'left',
9133     
9134     labellg : 0,
9135     labelmd : 0,
9136     labelsm : 0,
9137     labelxs : 0,
9138     
9139     capture : '',
9140     accept : '',
9141     
9142     parentLabelAlign : function()
9143     {
9144         var parent = this;
9145         while (parent.parent()) {
9146             parent = parent.parent();
9147             if (typeof(parent.labelAlign) !='undefined') {
9148                 return parent.labelAlign;
9149             }
9150         }
9151         return 'left';
9152         
9153     },
9154     
9155     getAutoCreate : function()
9156     {
9157         var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9158         
9159         var id = Roo.id();
9160         
9161         var cfg = {};
9162         
9163         if(this.inputType != 'hidden'){
9164             cfg.cls = 'form-group' //input-group
9165         }
9166         
9167         var input =  {
9168             tag: 'input',
9169             id : id,
9170             type : this.inputType,
9171             value : this.value,
9172             cls : 'form-control',
9173             placeholder : this.placeholder || '',
9174             autocomplete : this.autocomplete || 'new-password'
9175         };
9176         
9177         if(this.capture.length){
9178             input.capture = this.capture;
9179         }
9180         
9181         if(this.accept.length){
9182             input.accept = this.accept + "/*";
9183         }
9184         
9185         if(this.align){
9186             input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
9187         }
9188         
9189         if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9190             input.maxLength = this.maxLength;
9191         }
9192         
9193         if (this.disabled) {
9194             input.disabled=true;
9195         }
9196         
9197         if (this.readOnly) {
9198             input.readonly=true;
9199         }
9200         
9201         if (this.name) {
9202             input.name = this.name;
9203         }
9204         
9205         if (this.size) {
9206             input.cls += ' input-' + this.size;
9207         }
9208         
9209         var settings=this;
9210         ['xs','sm','md','lg'].map(function(size){
9211             if (settings[size]) {
9212                 cfg.cls += ' col-' + size + '-' + settings[size];
9213             }
9214         });
9215         
9216         var inputblock = input;
9217         
9218         var feedback = {
9219             tag: 'span',
9220             cls: 'glyphicon form-control-feedback'
9221         };
9222             
9223         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9224             
9225             inputblock = {
9226                 cls : 'has-feedback',
9227                 cn :  [
9228                     input,
9229                     feedback
9230                 ] 
9231             };  
9232         }
9233         
9234         if (this.before || this.after) {
9235             
9236             inputblock = {
9237                 cls : 'input-group',
9238                 cn :  [] 
9239             };
9240             
9241             if (this.before && typeof(this.before) == 'string') {
9242                 
9243                 inputblock.cn.push({
9244                     tag :'span',
9245                     cls : 'roo-input-before input-group-addon input-group-prepend input-group-text',
9246                     html : this.before
9247                 });
9248             }
9249             if (this.before && typeof(this.before) == 'object') {
9250                 this.before = Roo.factory(this.before);
9251                 
9252                 inputblock.cn.push({
9253                     tag :'span',
9254                     cls : 'roo-input-before input-group-prepend input-group-text input-group-' +
9255                         (this.before.xtype == 'Button' ? 'btn' : 'addon')  //?? what about checkboxes - that looks like a bit of a hack thought? 
9256                 });
9257             }
9258             
9259             inputblock.cn.push(input);
9260             
9261             if (this.after && typeof(this.after) == 'string') {
9262                 inputblock.cn.push({
9263                     tag :'span',
9264                     cls : 'roo-input-after input-group-append input-group-text input-group-addon',
9265                     html : this.after
9266                 });
9267             }
9268             if (this.after && typeof(this.after) == 'object') {
9269                 this.after = Roo.factory(this.after);
9270                 
9271                 inputblock.cn.push({
9272                     tag :'span',
9273                     cls : 'roo-input-after input-group-append input-group-text input-group-' +
9274                         (this.after.xtype == 'Button' ? 'btn' : 'addon')  //?? what about checkboxes - that looks like a bit of a hack thought? 
9275                 });
9276             }
9277             
9278             if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9279                 inputblock.cls += ' has-feedback';
9280                 inputblock.cn.push(feedback);
9281             }
9282         };
9283         var indicator = {
9284             tag : 'i',
9285             cls : 'roo-required-indicator ' + (this.indicatorpos == 'right'  ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
9286             tooltip : 'This field is required'
9287         };
9288         if (Roo.bootstrap.version == 4) {
9289             indicator = {
9290                 tag : 'i',
9291                 style : 'display-none'
9292             };
9293         }
9294         if (align ==='left' && this.fieldLabel.length) {
9295             
9296             cfg.cls += ' roo-form-group-label-left'  + (Roo.bootstrap.version == 4 ? ' row' : '');
9297             
9298             cfg.cn = [
9299                 indicator,
9300                 {
9301                     tag: 'label',
9302                     'for' :  id,
9303                     cls : 'control-label col-form-label',
9304                     html : this.fieldLabel
9305
9306                 },
9307                 {
9308                     cls : "", 
9309                     cn: [
9310                         inputblock
9311                     ]
9312                 }
9313             ];
9314             
9315             var labelCfg = cfg.cn[1];
9316             var contentCfg = cfg.cn[2];
9317             
9318             if(this.indicatorpos == 'right'){
9319                 cfg.cn = [
9320                     {
9321                         tag: 'label',
9322                         'for' :  id,
9323                         cls : 'control-label col-form-label',
9324                         cn : [
9325                             {
9326                                 tag : 'span',
9327                                 html : this.fieldLabel
9328                             },
9329                             indicator
9330                         ]
9331                     },
9332                     {
9333                         cls : "",
9334                         cn: [
9335                             inputblock
9336                         ]
9337                     }
9338
9339                 ];
9340                 
9341                 labelCfg = cfg.cn[0];
9342                 contentCfg = cfg.cn[1];
9343             
9344             }
9345             
9346             if(this.labelWidth > 12){
9347                 labelCfg.style = "width: " + this.labelWidth + 'px';
9348             }
9349             
9350             if(this.labelWidth < 13 && this.labelmd == 0){
9351                 this.labelmd = this.labelWidth;
9352             }
9353             
9354             if(this.labellg > 0){
9355                 labelCfg.cls += ' col-lg-' + this.labellg;
9356                 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
9357             }
9358             
9359             if(this.labelmd > 0){
9360                 labelCfg.cls += ' col-md-' + this.labelmd;
9361                 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
9362             }
9363             
9364             if(this.labelsm > 0){
9365                 labelCfg.cls += ' col-sm-' + this.labelsm;
9366                 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
9367             }
9368             
9369             if(this.labelxs > 0){
9370                 labelCfg.cls += ' col-xs-' + this.labelxs;
9371                 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
9372             }
9373             
9374             
9375         } else if ( this.fieldLabel.length) {
9376                 
9377             cfg.cn = [
9378                 {
9379                     tag : 'i',
9380                     cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9381                     tooltip : 'This field is required'
9382                 },
9383                 {
9384                     tag: 'label',
9385                    //cls : 'input-group-addon',
9386                     html : this.fieldLabel
9387
9388                 },
9389
9390                inputblock
9391
9392            ];
9393            
9394            if(this.indicatorpos == 'right'){
9395                 
9396                 cfg.cn = [
9397                     {
9398                         tag: 'label',
9399                        //cls : 'input-group-addon',
9400                         html : this.fieldLabel
9401
9402                     },
9403                     {
9404                         tag : 'i',
9405                         cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9406                         tooltip : 'This field is required'
9407                     },
9408
9409                    inputblock
9410
9411                ];
9412
9413             }
9414
9415         } else {
9416             
9417             cfg.cn = [
9418
9419                     inputblock
9420
9421             ];
9422                 
9423                 
9424         };
9425         
9426         if (this.parentType === 'Navbar' &&  this.parent().bar) {
9427            cfg.cls += ' navbar-form';
9428         }
9429         
9430         if (this.parentType === 'NavGroup' && !(Roo.bootstrap.version == 4 && this.parent().form)) {
9431             // on BS4 we do this only if not form 
9432             cfg.cls += ' navbar-form';
9433             cfg.tag = 'li';
9434         }
9435         
9436         return cfg;
9437         
9438     },
9439     /**
9440      * return the real input element.
9441      */
9442     inputEl: function ()
9443     {
9444         return this.el.select('input.form-control',true).first();
9445     },
9446     
9447     tooltipEl : function()
9448     {
9449         return this.inputEl();
9450     },
9451     
9452     indicatorEl : function()
9453     {
9454         if (Roo.bootstrap.version == 4) {
9455             return false; // not enabled in v4 yet.
9456         }
9457         
9458         var indicator = this.el.select('i.roo-required-indicator',true).first();
9459         
9460         if(!indicator){
9461             return false;
9462         }
9463         
9464         return indicator;
9465         
9466     },
9467     
9468     setDisabled : function(v)
9469     {
9470         var i  = this.inputEl().dom;
9471         if (!v) {
9472             i.removeAttribute('disabled');
9473             return;
9474             
9475         }
9476         i.setAttribute('disabled','true');
9477     },
9478     initEvents : function()
9479     {
9480           
9481         this.inputEl().on("keydown" , this.fireKey,  this);
9482         this.inputEl().on("focus", this.onFocus,  this);
9483         this.inputEl().on("blur", this.onBlur,  this);
9484         
9485         this.inputEl().relayEvent('keyup', this);
9486         
9487         this.indicator = this.indicatorEl();
9488         
9489         if(this.indicator){
9490             this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? - 
9491         }
9492  
9493         // reference to original value for reset
9494         this.originalValue = this.getValue();
9495         //Roo.form.TextField.superclass.initEvents.call(this);
9496         if(this.validationEvent == 'keyup'){
9497             this.validationTask = new Roo.util.DelayedTask(this.validate, this);
9498             this.inputEl().on('keyup', this.filterValidation, this);
9499         }
9500         else if(this.validationEvent !== false){
9501             this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
9502         }
9503         
9504         if(this.selectOnFocus){
9505             this.on("focus", this.preFocus, this);
9506             
9507         }
9508         if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
9509             this.inputEl().on("keypress", this.filterKeys, this);
9510         } else {
9511             this.inputEl().relayEvent('keypress', this);
9512         }
9513        /* if(this.grow){
9514             this.el.on("keyup", this.onKeyUp,  this, {buffer:50});
9515             this.el.on("click", this.autoSize,  this);
9516         }
9517         */
9518         if(this.inputEl().is('input[type=password]') && Roo.isSafari){
9519             this.inputEl().on('keydown', this.SafariOnKeyDown, this);
9520         }
9521         
9522         if (typeof(this.before) == 'object') {
9523             this.before.render(this.el.select('.roo-input-before',true).first());
9524         }
9525         if (typeof(this.after) == 'object') {
9526             this.after.render(this.el.select('.roo-input-after',true).first());
9527         }
9528         
9529         this.inputEl().on('change', this.onChange, this);
9530         
9531     },
9532     filterValidation : function(e){
9533         if(!e.isNavKeyPress()){
9534             this.validationTask.delay(this.validationDelay);
9535         }
9536     },
9537      /**
9538      * Validates the field value
9539      * @return {Boolean} True if the value is valid, else false
9540      */
9541     validate : function(){
9542         //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
9543         if(this.disabled || this.validateValue(this.getRawValue())){
9544             this.markValid();
9545             return true;
9546         }
9547         
9548         this.markInvalid();
9549         return false;
9550     },
9551     
9552     
9553     /**
9554      * Validates a value according to the field's validation rules and marks the field as invalid
9555      * if the validation fails
9556      * @param {Mixed} value The value to validate
9557      * @return {Boolean} True if the value is valid, else false
9558      */
9559     validateValue : function(value)
9560     {
9561         if(this.getVisibilityEl().hasClass('hidden')){
9562             return true;
9563         }
9564         
9565         if(value.length < 1)  { // if it's blank
9566             if(this.allowBlank){
9567                 return true;
9568             }
9569             return false;
9570         }
9571         
9572         if(value.length < this.minLength){
9573             return false;
9574         }
9575         if(value.length > this.maxLength){
9576             return false;
9577         }
9578         if(this.vtype){
9579             var vt = Roo.form.VTypes;
9580             if(!vt[this.vtype](value, this)){
9581                 return false;
9582             }
9583         }
9584         if(typeof this.validator == "function"){
9585             var msg = this.validator(value);
9586             if(msg !== true){
9587                 return false;
9588             }
9589             if (typeof(msg) == 'string') {
9590                 this.invalidText = msg;
9591             }
9592         }
9593         
9594         if(this.regex && !this.regex.test(value)){
9595             return false;
9596         }
9597         
9598         return true;
9599     },
9600     
9601      // private
9602     fireKey : function(e){
9603         //Roo.log('field ' + e.getKey());
9604         if(e.isNavKeyPress()){
9605             this.fireEvent("specialkey", this, e);
9606         }
9607     },
9608     focus : function (selectText){
9609         if(this.rendered){
9610             this.inputEl().focus();
9611             if(selectText === true){
9612                 this.inputEl().dom.select();
9613             }
9614         }
9615         return this;
9616     } ,
9617     
9618     onFocus : function(){
9619         if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9620            // this.el.addClass(this.focusClass);
9621         }
9622         if(!this.hasFocus){
9623             this.hasFocus = true;
9624             this.startValue = this.getValue();
9625             this.fireEvent("focus", this);
9626         }
9627     },
9628     
9629     beforeBlur : Roo.emptyFn,
9630
9631     
9632     // private
9633     onBlur : function(){
9634         this.beforeBlur();
9635         if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9636             //this.el.removeClass(this.focusClass);
9637         }
9638         this.hasFocus = false;
9639         if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9640             this.validate();
9641         }
9642         var v = this.getValue();
9643         if(String(v) !== String(this.startValue)){
9644             this.fireEvent('change', this, v, this.startValue);
9645         }
9646         this.fireEvent("blur", this);
9647     },
9648     
9649     onChange : function(e)
9650     {
9651         var v = this.getValue();
9652         if(String(v) !== String(this.startValue)){
9653             this.fireEvent('change', this, v, this.startValue);
9654         }
9655         
9656     },
9657     
9658     /**
9659      * Resets the current field value to the originally loaded value and clears any validation messages
9660      */
9661     reset : function(){
9662         this.setValue(this.originalValue);
9663         this.validate();
9664     },
9665      /**
9666      * Returns the name of the field
9667      * @return {Mixed} name The name field
9668      */
9669     getName: function(){
9670         return this.name;
9671     },
9672      /**
9673      * Returns the normalized data value (undefined or emptyText will be returned as '').  To return the raw value see {@link #getRawValue}.
9674      * @return {Mixed} value The field value
9675      */
9676     getValue : function(){
9677         
9678         var v = this.inputEl().getValue();
9679         
9680         return v;
9681     },
9682     /**
9683      * Returns the raw data value which may or may not be a valid, defined value.  To return a normalized value see {@link #getValue}.
9684      * @return {Mixed} value The field value
9685      */
9686     getRawValue : function(){
9687         var v = this.inputEl().getValue();
9688         
9689         return v;
9690     },
9691     
9692     /**
9693      * Sets the underlying DOM field's value directly, bypassing validation.  To set the value with validation see {@link #setValue}.
9694      * @param {Mixed} value The value to set
9695      */
9696     setRawValue : function(v){
9697         return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9698     },
9699     
9700     selectText : function(start, end){
9701         var v = this.getRawValue();
9702         if(v.length > 0){
9703             start = start === undefined ? 0 : start;
9704             end = end === undefined ? v.length : end;
9705             var d = this.inputEl().dom;
9706             if(d.setSelectionRange){
9707                 d.setSelectionRange(start, end);
9708             }else if(d.createTextRange){
9709                 var range = d.createTextRange();
9710                 range.moveStart("character", start);
9711                 range.moveEnd("character", v.length-end);
9712                 range.select();
9713             }
9714         }
9715     },
9716     
9717     /**
9718      * Sets a data value into the field and validates it.  To set the value directly without validation see {@link #setRawValue}.
9719      * @param {Mixed} value The value to set
9720      */
9721     setValue : function(v){
9722         this.value = v;
9723         if(this.rendered){
9724             this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9725             this.validate();
9726         }
9727     },
9728     
9729     /*
9730     processValue : function(value){
9731         if(this.stripCharsRe){
9732             var newValue = value.replace(this.stripCharsRe, '');
9733             if(newValue !== value){
9734                 this.setRawValue(newValue);
9735                 return newValue;
9736             }
9737         }
9738         return value;
9739     },
9740   */
9741     preFocus : function(){
9742         
9743         if(this.selectOnFocus){
9744             this.inputEl().dom.select();
9745         }
9746     },
9747     filterKeys : function(e){
9748         var k = e.getKey();
9749         if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9750             return;
9751         }
9752         var c = e.getCharCode(), cc = String.fromCharCode(c);
9753         if(Roo.isIE && (e.isSpecialKey() || !cc)){
9754             return;
9755         }
9756         if(!this.maskRe.test(cc)){
9757             e.stopEvent();
9758         }
9759     },
9760      /**
9761      * Clear any invalid styles/messages for this field
9762      */
9763     clearInvalid : function(){
9764         
9765         if(!this.el || this.preventMark){ // not rendered
9766             return;
9767         }
9768         
9769         
9770         this.el.removeClass([this.invalidClass, 'is-invalid']);
9771         
9772         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9773             
9774             var feedback = this.el.select('.form-control-feedback', true).first();
9775             
9776             if(feedback){
9777                 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9778             }
9779             
9780         }
9781         
9782         if(this.indicator){
9783             this.indicator.removeClass('visible');
9784             this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9785         }
9786         
9787         this.fireEvent('valid', this);
9788     },
9789     
9790      /**
9791      * Mark this field as valid
9792      */
9793     markValid : function()
9794     {
9795         if(!this.el  || this.preventMark){ // not rendered...
9796             return;
9797         }
9798         
9799         this.el.removeClass([this.invalidClass, this.validClass]);
9800         this.inputEl().removeClass(['is-valid', 'is-invalid']);
9801
9802         var feedback = this.el.select('.form-control-feedback', true).first();
9803             
9804         if(feedback){
9805             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9806         }
9807         
9808         if(this.indicator){
9809             this.indicator.removeClass('visible');
9810             this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9811         }
9812         
9813         if(this.disabled){
9814             return;
9815         }
9816         
9817         if(this.allowBlank && !this.getRawValue().length){
9818             return;
9819         }
9820         if (Roo.bootstrap.version == 3) {
9821             this.el.addClass(this.validClass);
9822         } else {
9823             this.inputEl().addClass('is-valid');
9824         }
9825
9826         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9827             
9828             var feedback = this.el.select('.form-control-feedback', true).first();
9829             
9830             if(feedback){
9831                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9832                 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9833             }
9834             
9835         }
9836         
9837         this.fireEvent('valid', this);
9838     },
9839     
9840      /**
9841      * Mark this field as invalid
9842      * @param {String} msg The validation message
9843      */
9844     markInvalid : function(msg)
9845     {
9846         if(!this.el  || this.preventMark){ // not rendered
9847             return;
9848         }
9849         
9850         this.el.removeClass([this.invalidClass, this.validClass]);
9851         this.inputEl().removeClass(['is-valid', 'is-invalid']);
9852         
9853         var feedback = this.el.select('.form-control-feedback', true).first();
9854             
9855         if(feedback){
9856             this.el.select('.form-control-feedback', true).first().removeClass(
9857                     [this.invalidFeedbackClass, this.validFeedbackClass]);
9858         }
9859
9860         if(this.disabled){
9861             return;
9862         }
9863         
9864         if(this.allowBlank && !this.getRawValue().length){
9865             return;
9866         }
9867         
9868         if(this.indicator){
9869             this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9870             this.indicator.addClass('visible');
9871         }
9872         if (Roo.bootstrap.version == 3) {
9873             this.el.addClass(this.invalidClass);
9874         } else {
9875             this.inputEl().addClass('is-invalid');
9876         }
9877         
9878         
9879         
9880         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9881             
9882             var feedback = this.el.select('.form-control-feedback', true).first();
9883             
9884             if(feedback){
9885                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9886                 
9887                 if(this.getValue().length || this.forceFeedback){
9888                     this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9889                 }
9890                 
9891             }
9892             
9893         }
9894         
9895         this.fireEvent('invalid', this, msg);
9896     },
9897     // private
9898     SafariOnKeyDown : function(event)
9899     {
9900         // this is a workaround for a password hang bug on chrome/ webkit.
9901         if (this.inputEl().dom.type != 'password') {
9902             return;
9903         }
9904         
9905         var isSelectAll = false;
9906         
9907         if(this.inputEl().dom.selectionEnd > 0){
9908             isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9909         }
9910         if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9911             event.preventDefault();
9912             this.setValue('');
9913             return;
9914         }
9915         
9916         if(isSelectAll  && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9917             
9918             event.preventDefault();
9919             // this is very hacky as keydown always get's upper case.
9920             //
9921             var cc = String.fromCharCode(event.getCharCode());
9922             this.setValue( event.shiftKey ?  cc : cc.toLowerCase());
9923             
9924         }
9925     },
9926     adjustWidth : function(tag, w){
9927         tag = tag.toLowerCase();
9928         if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9929             if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9930                 if(tag == 'input'){
9931                     return w + 2;
9932                 }
9933                 if(tag == 'textarea'){
9934                     return w-2;
9935                 }
9936             }else if(Roo.isOpera){
9937                 if(tag == 'input'){
9938                     return w + 2;
9939                 }
9940                 if(tag == 'textarea'){
9941                     return w-2;
9942                 }
9943             }
9944         }
9945         return w;
9946     },
9947     
9948     setFieldLabel : function(v)
9949     {
9950         if(!this.rendered){
9951             return;
9952         }
9953         
9954         if(this.indicatorEl()){
9955             var ar = this.el.select('label > span',true);
9956             
9957             if (ar.elements.length) {
9958                 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9959                 this.fieldLabel = v;
9960                 return;
9961             }
9962             
9963             var br = this.el.select('label',true);
9964             
9965             if(br.elements.length) {
9966                 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9967                 this.fieldLabel = v;
9968                 return;
9969             }
9970             
9971             Roo.log('Cannot Found any of label > span || label in input');
9972             return;
9973         }
9974         
9975         this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9976         this.fieldLabel = v;
9977         
9978         
9979     }
9980 });
9981
9982  
9983 /*
9984  * - LGPL
9985  *
9986  * Input
9987  * 
9988  */
9989
9990 /**
9991  * @class Roo.bootstrap.TextArea
9992  * @extends Roo.bootstrap.Input
9993  * Bootstrap TextArea class
9994  * @cfg {Number} cols Specifies the visible width of a text area
9995  * @cfg {Number} rows Specifies the visible number of lines in a text area
9996  * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9997  * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9998  * @cfg {string} html text
9999  * 
10000  * @constructor
10001  * Create a new TextArea
10002  * @param {Object} config The config object
10003  */
10004
10005 Roo.bootstrap.TextArea = function(config){
10006     Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
10007    
10008 };
10009
10010 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input,  {
10011      
10012     cols : false,
10013     rows : 5,
10014     readOnly : false,
10015     warp : 'soft',
10016     resize : false,
10017     value: false,
10018     html: false,
10019     
10020     getAutoCreate : function(){
10021         
10022         var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
10023         
10024         var id = Roo.id();
10025         
10026         var cfg = {};
10027         
10028         if(this.inputType != 'hidden'){
10029             cfg.cls = 'form-group' //input-group
10030         }
10031         
10032         var input =  {
10033             tag: 'textarea',
10034             id : id,
10035             warp : this.warp,
10036             rows : this.rows,
10037             value : this.value || '',
10038             html: this.html || '',
10039             cls : 'form-control',
10040             placeholder : this.placeholder || '' 
10041             
10042         };
10043         
10044         if(this.maxLength && this.maxLength != Number.MAX_VALUE){
10045             input.maxLength = this.maxLength;
10046         }
10047         
10048         if(this.resize){
10049             input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
10050         }
10051         
10052         if(this.cols){
10053             input.cols = this.cols;
10054         }
10055         
10056         if (this.readOnly) {
10057             input.readonly = true;
10058         }
10059         
10060         if (this.name) {
10061             input.name = this.name;
10062         }
10063         
10064         if (this.size) {
10065             input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
10066         }
10067         
10068         var settings=this;
10069         ['xs','sm','md','lg'].map(function(size){
10070             if (settings[size]) {
10071                 cfg.cls += ' col-' + size + '-' + settings[size];
10072             }
10073         });
10074         
10075         var inputblock = input;
10076         
10077         if(this.hasFeedback && !this.allowBlank){
10078             
10079             var feedback = {
10080                 tag: 'span',
10081                 cls: 'glyphicon form-control-feedback'
10082             };
10083
10084             inputblock = {
10085                 cls : 'has-feedback',
10086                 cn :  [
10087                     input,
10088                     feedback
10089                 ] 
10090             };  
10091         }
10092         
10093         
10094         if (this.before || this.after) {
10095             
10096             inputblock = {
10097                 cls : 'input-group',
10098                 cn :  [] 
10099             };
10100             if (this.before) {
10101                 inputblock.cn.push({
10102                     tag :'span',
10103                     cls : 'input-group-addon',
10104                     html : this.before
10105                 });
10106             }
10107             
10108             inputblock.cn.push(input);
10109             
10110             if(this.hasFeedback && !this.allowBlank){
10111                 inputblock.cls += ' has-feedback';
10112                 inputblock.cn.push(feedback);
10113             }
10114             
10115             if (this.after) {
10116                 inputblock.cn.push({
10117                     tag :'span',
10118                     cls : 'input-group-addon',
10119                     html : this.after
10120                 });
10121             }
10122             
10123         }
10124         
10125         if (align ==='left' && this.fieldLabel.length) {
10126             cfg.cn = [
10127                 {
10128                     tag: 'label',
10129                     'for' :  id,
10130                     cls : 'control-label',
10131                     html : this.fieldLabel
10132                 },
10133                 {
10134                     cls : "",
10135                     cn: [
10136                         inputblock
10137                     ]
10138                 }
10139
10140             ];
10141             
10142             if(this.labelWidth > 12){
10143                 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
10144             }
10145
10146             if(this.labelWidth < 13 && this.labelmd == 0){
10147                 this.labelmd = this.labelWidth;
10148             }
10149
10150             if(this.labellg > 0){
10151                 cfg.cn[0].cls += ' col-lg-' + this.labellg;
10152                 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
10153             }
10154
10155             if(this.labelmd > 0){
10156                 cfg.cn[0].cls += ' col-md-' + this.labelmd;
10157                 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
10158             }
10159
10160             if(this.labelsm > 0){
10161                 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
10162                 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
10163             }
10164
10165             if(this.labelxs > 0){
10166                 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
10167                 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
10168             }
10169             
10170         } else if ( this.fieldLabel.length) {
10171             cfg.cn = [
10172
10173                {
10174                    tag: 'label',
10175                    //cls : 'input-group-addon',
10176                    html : this.fieldLabel
10177
10178                },
10179
10180                inputblock
10181
10182            ];
10183
10184         } else {
10185
10186             cfg.cn = [
10187
10188                 inputblock
10189
10190             ];
10191                 
10192         }
10193         
10194         if (this.disabled) {
10195             input.disabled=true;
10196         }
10197         
10198         return cfg;
10199         
10200     },
10201     /**
10202      * return the real textarea element.
10203      */
10204     inputEl: function ()
10205     {
10206         return this.el.select('textarea.form-control',true).first();
10207     },
10208     
10209     /**
10210      * Clear any invalid styles/messages for this field
10211      */
10212     clearInvalid : function()
10213     {
10214         
10215         if(!this.el || this.preventMark){ // not rendered
10216             return;
10217         }
10218         
10219         var label = this.el.select('label', true).first();
10220         var icon = this.el.select('i.fa-star', true).first();
10221         
10222         if(label && icon){
10223             icon.remove();
10224         }
10225         this.el.removeClass( this.validClass);
10226         this.inputEl().removeClass('is-invalid');
10227          
10228         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
10229             
10230             var feedback = this.el.select('.form-control-feedback', true).first();
10231             
10232             if(feedback){
10233                 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
10234             }
10235             
10236         }
10237         
10238         this.fireEvent('valid', this);
10239     },
10240     
10241      /**
10242      * Mark this field as valid
10243      */
10244     markValid : function()
10245     {
10246         if(!this.el  || this.preventMark){ // not rendered
10247             return;
10248         }
10249         
10250         this.el.removeClass([this.invalidClass, this.validClass]);
10251         this.inputEl().removeClass(['is-valid', 'is-invalid']);
10252         
10253         var feedback = this.el.select('.form-control-feedback', true).first();
10254             
10255         if(feedback){
10256             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10257         }
10258
10259         if(this.disabled || this.allowBlank){
10260             return;
10261         }
10262         
10263         var label = this.el.select('label', true).first();
10264         var icon = this.el.select('i.fa-star', true).first();
10265         
10266         if(label && icon){
10267             icon.remove();
10268         }
10269         if (Roo.bootstrap.version == 3) {
10270             this.el.addClass(this.validClass);
10271         } else {
10272             this.inputEl().addClass('is-valid');
10273         }
10274         
10275         
10276         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
10277             
10278             var feedback = this.el.select('.form-control-feedback', true).first();
10279             
10280             if(feedback){
10281                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10282                 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
10283             }
10284             
10285         }
10286         
10287         this.fireEvent('valid', this);
10288     },
10289     
10290      /**
10291      * Mark this field as invalid
10292      * @param {String} msg The validation message
10293      */
10294     markInvalid : function(msg)
10295     {
10296         if(!this.el  || this.preventMark){ // not rendered
10297             return;
10298         }
10299         
10300         this.el.removeClass([this.invalidClass, this.validClass]);
10301         this.inputEl().removeClass(['is-valid', 'is-invalid']);
10302         
10303         var feedback = this.el.select('.form-control-feedback', true).first();
10304             
10305         if(feedback){
10306             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10307         }
10308
10309         if(this.disabled || this.allowBlank){
10310             return;
10311         }
10312         
10313         var label = this.el.select('label', true).first();
10314         var icon = this.el.select('i.fa-star', true).first();
10315         
10316         if(!this.getValue().length && label && !icon){
10317             this.el.createChild({
10318                 tag : 'i',
10319                 cls : 'text-danger fa fa-lg fa-star',
10320                 tooltip : 'This field is required',
10321                 style : 'margin-right:5px;'
10322             }, label, true);
10323         }
10324         
10325         if (Roo.bootstrap.version == 3) {
10326             this.el.addClass(this.invalidClass);
10327         } else {
10328             this.inputEl().addClass('is-invalid');
10329         }
10330         
10331         // fixme ... this may be depricated need to test..
10332         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
10333             
10334             var feedback = this.el.select('.form-control-feedback', true).first();
10335             
10336             if(feedback){
10337                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10338                 
10339                 if(this.getValue().length || this.forceFeedback){
10340                     this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
10341                 }
10342                 
10343             }
10344             
10345         }
10346         
10347         this.fireEvent('invalid', this, msg);
10348     }
10349 });
10350
10351  
10352 /*
10353  * - LGPL
10354  *
10355  * trigger field - base class for combo..
10356  * 
10357  */
10358  
10359 /**
10360  * @class Roo.bootstrap.TriggerField
10361  * @extends Roo.bootstrap.Input
10362  * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
10363  * The trigger has no default action, so you must assign a function to implement the trigger click handler by
10364  * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
10365  * for which you can provide a custom implementation.  For example:
10366  * <pre><code>
10367 var trigger = new Roo.bootstrap.TriggerField();
10368 trigger.onTriggerClick = myTriggerFn;
10369 trigger.applyTo('my-field');
10370 </code></pre>
10371  *
10372  * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
10373  * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
10374  * @cfg {String} triggerClass An additional CSS class used to style the trigger button.  The trigger will always get the
10375  * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
10376  * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
10377
10378  * @constructor
10379  * Create a new TriggerField.
10380  * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
10381  * to the base TextField)
10382  */
10383 Roo.bootstrap.TriggerField = function(config){
10384     this.mimicing = false;
10385     Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
10386 };
10387
10388 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input,  {
10389     /**
10390      * @cfg {String} triggerClass A CSS class to apply to the trigger
10391      */
10392      /**
10393      * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
10394      */
10395     hideTrigger:false,
10396
10397     /**
10398      * @cfg {Boolean} removable (true|false) special filter default false
10399      */
10400     removable : false,
10401     
10402     /** @cfg {Boolean} grow @hide */
10403     /** @cfg {Number} growMin @hide */
10404     /** @cfg {Number} growMax @hide */
10405
10406     /**
10407      * @hide 
10408      * @method
10409      */
10410     autoSize: Roo.emptyFn,
10411     // private
10412     monitorTab : true,
10413     // private
10414     deferHeight : true,
10415
10416     
10417     actionMode : 'wrap',
10418     
10419     caret : false,
10420     
10421     
10422     getAutoCreate : function(){
10423        
10424         var align = this.labelAlign || this.parentLabelAlign();
10425         
10426         var id = Roo.id();
10427         
10428         var cfg = {
10429             cls: 'form-group' //input-group
10430         };
10431         
10432         
10433         var input =  {
10434             tag: 'input',
10435             id : id,
10436             type : this.inputType,
10437             cls : 'form-control',
10438             autocomplete: 'new-password',
10439             placeholder : this.placeholder || '' 
10440             
10441         };
10442         if (this.name) {
10443             input.name = this.name;
10444         }
10445         if (this.size) {
10446             input.cls += ' input-' + this.size;
10447         }
10448         
10449         if (this.disabled) {
10450             input.disabled=true;
10451         }
10452         
10453         var inputblock = input;
10454         
10455         if(this.hasFeedback && !this.allowBlank){
10456             
10457             var feedback = {
10458                 tag: 'span',
10459                 cls: 'glyphicon form-control-feedback'
10460             };
10461             
10462             if(this.removable && !this.editable && !this.tickable){
10463                 inputblock = {
10464                     cls : 'has-feedback',
10465                     cn :  [
10466                         inputblock,
10467                         {
10468                             tag: 'button',
10469                             html : 'x',
10470                             cls : 'roo-combo-removable-btn close'
10471                         },
10472                         feedback
10473                     ] 
10474                 };
10475             } else {
10476                 inputblock = {
10477                     cls : 'has-feedback',
10478                     cn :  [
10479                         inputblock,
10480                         feedback
10481                     ] 
10482                 };
10483             }
10484
10485         } else {
10486             if(this.removable && !this.editable && !this.tickable){
10487                 inputblock = {
10488                     cls : 'roo-removable',
10489                     cn :  [
10490                         inputblock,
10491                         {
10492                             tag: 'button',
10493                             html : 'x',
10494                             cls : 'roo-combo-removable-btn close'
10495                         }
10496                     ] 
10497                 };
10498             }
10499         }
10500         
10501         if (this.before || this.after) {
10502             
10503             inputblock = {
10504                 cls : 'input-group',
10505                 cn :  [] 
10506             };
10507             if (this.before) {
10508                 inputblock.cn.push({
10509                     tag :'span',
10510                     cls : 'input-group-addon input-group-prepend input-group-text',
10511                     html : this.before
10512                 });
10513             }
10514             
10515             inputblock.cn.push(input);
10516             
10517             if(this.hasFeedback && !this.allowBlank){
10518                 inputblock.cls += ' has-feedback';
10519                 inputblock.cn.push(feedback);
10520             }
10521             
10522             if (this.after) {
10523                 inputblock.cn.push({
10524                     tag :'span',
10525                     cls : 'input-group-addon input-group-append input-group-text',
10526                     html : this.after
10527                 });
10528             }
10529             
10530         };
10531         
10532       
10533         
10534         var ibwrap = inputblock;
10535         
10536         if(this.multiple){
10537             ibwrap = {
10538                 tag: 'ul',
10539                 cls: 'roo-select2-choices',
10540                 cn:[
10541                     {
10542                         tag: 'li',
10543                         cls: 'roo-select2-search-field',
10544                         cn: [
10545
10546                             inputblock
10547                         ]
10548                     }
10549                 ]
10550             };
10551                 
10552         }
10553         
10554         var combobox = {
10555             cls: 'roo-select2-container input-group',
10556             cn: [
10557                  {
10558                     tag: 'input',
10559                     type : 'hidden',
10560                     cls: 'form-hidden-field'
10561                 },
10562                 ibwrap
10563             ]
10564         };
10565         
10566         if(!this.multiple && this.showToggleBtn){
10567             
10568             var caret = {
10569                         tag: 'span',
10570                         cls: 'caret'
10571              };
10572             if (this.caret != false) {
10573                 caret = {
10574                      tag: 'i',
10575                      cls: 'fa fa-' + this.caret
10576                 };
10577                 
10578             }
10579             
10580             combobox.cn.push({
10581                 tag :'span',
10582                 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
10583                 cn : [
10584                     caret,
10585                     {
10586                         tag: 'span',
10587                         cls: 'combobox-clear',
10588                         cn  : [
10589                             {
10590                                 tag : 'i',
10591                                 cls: 'icon-remove'
10592                             }
10593                         ]
10594                     }
10595                 ]
10596
10597             })
10598         }
10599         
10600         if(this.multiple){
10601             combobox.cls += ' roo-select2-container-multi';
10602         }
10603          var indicator = {
10604             tag : 'i',
10605             cls : 'roo-required-indicator ' + (this.indicatorpos == 'right'  ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
10606             tooltip : 'This field is required'
10607         };
10608         if (Roo.bootstrap.version == 4) {
10609             indicator = {
10610                 tag : 'i',
10611                 style : 'display:none'
10612             };
10613         }
10614         
10615         
10616         if (align ==='left' && this.fieldLabel.length) {
10617             
10618             cfg.cls += ' roo-form-group-label-left'  + (Roo.bootstrap.version == 4 ? ' row' : '');
10619
10620             cfg.cn = [
10621                 indicator,
10622                 {
10623                     tag: 'label',
10624                     'for' :  id,
10625                     cls : 'control-label',
10626                     html : this.fieldLabel
10627
10628                 },
10629                 {
10630                     cls : "", 
10631                     cn: [
10632                         combobox
10633                     ]
10634                 }
10635
10636             ];
10637             
10638             var labelCfg = cfg.cn[1];
10639             var contentCfg = cfg.cn[2];
10640             
10641             if(this.indicatorpos == 'right'){
10642                 cfg.cn = [
10643                     {
10644                         tag: 'label',
10645                         'for' :  id,
10646                         cls : 'control-label',
10647                         cn : [
10648                             {
10649                                 tag : 'span',
10650                                 html : this.fieldLabel
10651                             },
10652                             indicator
10653                         ]
10654                     },
10655                     {
10656                         cls : "", 
10657                         cn: [
10658                             combobox
10659                         ]
10660                     }
10661
10662                 ];
10663                 
10664                 labelCfg = cfg.cn[0];
10665                 contentCfg = cfg.cn[1];
10666             }
10667             
10668             if(this.labelWidth > 12){
10669                 labelCfg.style = "width: " + this.labelWidth + 'px';
10670             }
10671             
10672             if(this.labelWidth < 13 && this.labelmd == 0){
10673                 this.labelmd = this.labelWidth;
10674             }
10675             
10676             if(this.labellg > 0){
10677                 labelCfg.cls += ' col-lg-' + this.labellg;
10678                 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
10679             }
10680             
10681             if(this.labelmd > 0){
10682                 labelCfg.cls += ' col-md-' + this.labelmd;
10683                 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
10684             }
10685             
10686             if(this.labelsm > 0){
10687                 labelCfg.cls += ' col-sm-' + this.labelsm;
10688                 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10689             }
10690             
10691             if(this.labelxs > 0){
10692                 labelCfg.cls += ' col-xs-' + this.labelxs;
10693                 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10694             }
10695             
10696         } else if ( this.fieldLabel.length) {
10697 //                Roo.log(" label");
10698             cfg.cn = [
10699                 indicator,
10700                {
10701                    tag: 'label',
10702                    //cls : 'input-group-addon',
10703                    html : this.fieldLabel
10704
10705                },
10706
10707                combobox
10708
10709             ];
10710             
10711             if(this.indicatorpos == 'right'){
10712                 
10713                 cfg.cn = [
10714                     {
10715                        tag: 'label',
10716                        cn : [
10717                            {
10718                                tag : 'span',
10719                                html : this.fieldLabel
10720                            },
10721                            indicator
10722                        ]
10723
10724                     },
10725                     combobox
10726
10727                 ];
10728
10729             }
10730
10731         } else {
10732             
10733 //                Roo.log(" no label && no align");
10734                 cfg = combobox
10735                      
10736                 
10737         }
10738         
10739         var settings=this;
10740         ['xs','sm','md','lg'].map(function(size){
10741             if (settings[size]) {
10742                 cfg.cls += ' col-' + size + '-' + settings[size];
10743             }
10744         });
10745         
10746         return cfg;
10747         
10748     },
10749     
10750     
10751     
10752     // private
10753     onResize : function(w, h){
10754 //        Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10755 //        if(typeof w == 'number'){
10756 //            var x = w - this.trigger.getWidth();
10757 //            this.inputEl().setWidth(this.adjustWidth('input', x));
10758 //            this.trigger.setStyle('left', x+'px');
10759 //        }
10760     },
10761
10762     // private
10763     adjustSize : Roo.BoxComponent.prototype.adjustSize,
10764
10765     // private
10766     getResizeEl : function(){
10767         return this.inputEl();
10768     },
10769
10770     // private
10771     getPositionEl : function(){
10772         return this.inputEl();
10773     },
10774
10775     // private
10776     alignErrorIcon : function(){
10777         this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10778     },
10779
10780     // private
10781     initEvents : function(){
10782         
10783         this.createList();
10784         
10785         Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10786         //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10787         if(!this.multiple && this.showToggleBtn){
10788             this.trigger = this.el.select('span.dropdown-toggle',true).first();
10789             if(this.hideTrigger){
10790                 this.trigger.setDisplayed(false);
10791             }
10792             this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10793         }
10794         
10795         if(this.multiple){
10796             this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10797         }
10798         
10799         if(this.removable && !this.editable && !this.tickable){
10800             var close = this.closeTriggerEl();
10801             
10802             if(close){
10803                 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10804                 close.on('click', this.removeBtnClick, this, close);
10805             }
10806         }
10807         
10808         //this.trigger.addClassOnOver('x-form-trigger-over');
10809         //this.trigger.addClassOnClick('x-form-trigger-click');
10810         
10811         //if(!this.width){
10812         //    this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10813         //}
10814     },
10815     
10816     closeTriggerEl : function()
10817     {
10818         var close = this.el.select('.roo-combo-removable-btn', true).first();
10819         return close ? close : false;
10820     },
10821     
10822     removeBtnClick : function(e, h, el)
10823     {
10824         e.preventDefault();
10825         
10826         if(this.fireEvent("remove", this) !== false){
10827             this.reset();
10828             this.fireEvent("afterremove", this)
10829         }
10830     },
10831     
10832     createList : function()
10833     {
10834         this.list = Roo.get(document.body).createChild({
10835             tag: Roo.bootstrap.version == 4 ? 'div' : 'ul',
10836             cls: 'typeahead typeahead-long dropdown-menu',
10837             style: 'display:none'
10838         });
10839         
10840         this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10841         
10842     },
10843
10844     // private
10845     initTrigger : function(){
10846        
10847     },
10848
10849     // private
10850     onDestroy : function(){
10851         if(this.trigger){
10852             this.trigger.removeAllListeners();
10853           //  this.trigger.remove();
10854         }
10855         //if(this.wrap){
10856         //    this.wrap.remove();
10857         //}
10858         Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10859     },
10860
10861     // private
10862     onFocus : function(){
10863         Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10864         /*
10865         if(!this.mimicing){
10866             this.wrap.addClass('x-trigger-wrap-focus');
10867             this.mimicing = true;
10868             Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10869             if(this.monitorTab){
10870                 this.el.on("keydown", this.checkTab, this);
10871             }
10872         }
10873         */
10874     },
10875
10876     // private
10877     checkTab : function(e){
10878         if(e.getKey() == e.TAB){
10879             this.triggerBlur();
10880         }
10881     },
10882
10883     // private
10884     onBlur : function(){
10885         // do nothing
10886     },
10887
10888     // private
10889     mimicBlur : function(e, t){
10890         /*
10891         if(!this.wrap.contains(t) && this.validateBlur()){
10892             this.triggerBlur();
10893         }
10894         */
10895     },
10896
10897     // private
10898     triggerBlur : function(){
10899         this.mimicing = false;
10900         Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10901         if(this.monitorTab){
10902             this.el.un("keydown", this.checkTab, this);
10903         }
10904         //this.wrap.removeClass('x-trigger-wrap-focus');
10905         Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10906     },
10907
10908     // private
10909     // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10910     validateBlur : function(e, t){
10911         return true;
10912     },
10913
10914     // private
10915     onDisable : function(){
10916         this.inputEl().dom.disabled = true;
10917         //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10918         //if(this.wrap){
10919         //    this.wrap.addClass('x-item-disabled');
10920         //}
10921     },
10922
10923     // private
10924     onEnable : function(){
10925         this.inputEl().dom.disabled = false;
10926         //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10927         //if(this.wrap){
10928         //    this.el.removeClass('x-item-disabled');
10929         //}
10930     },
10931
10932     // private
10933     onShow : function(){
10934         var ae = this.getActionEl();
10935         
10936         if(ae){
10937             ae.dom.style.display = '';
10938             ae.dom.style.visibility = 'visible';
10939         }
10940     },
10941
10942     // private
10943     
10944     onHide : function(){
10945         var ae = this.getActionEl();
10946         ae.dom.style.display = 'none';
10947     },
10948
10949     /**
10950      * The function that should handle the trigger's click event.  This method does nothing by default until overridden
10951      * by an implementing function.
10952      * @method
10953      * @param {EventObject} e
10954      */
10955     onTriggerClick : Roo.emptyFn
10956 });
10957  /*
10958  * Based on:
10959  * Ext JS Library 1.1.1
10960  * Copyright(c) 2006-2007, Ext JS, LLC.
10961  *
10962  * Originally Released Under LGPL - original licence link has changed is not relivant.
10963  *
10964  * Fork - LGPL
10965  * <script type="text/javascript">
10966  */
10967
10968
10969 /**
10970  * @class Roo.data.SortTypes
10971  * @singleton
10972  * Defines the default sorting (casting?) comparison functions used when sorting data.
10973  */
10974 Roo.data.SortTypes = {
10975     /**
10976      * Default sort that does nothing
10977      * @param {Mixed} s The value being converted
10978      * @return {Mixed} The comparison value
10979      */
10980     none : function(s){
10981         return s;
10982     },
10983     
10984     /**
10985      * The regular expression used to strip tags
10986      * @type {RegExp}
10987      * @property
10988      */
10989     stripTagsRE : /<\/?[^>]+>/gi,
10990     
10991     /**
10992      * Strips all HTML tags to sort on text only
10993      * @param {Mixed} s The value being converted
10994      * @return {String} The comparison value
10995      */
10996     asText : function(s){
10997         return String(s).replace(this.stripTagsRE, "");
10998     },
10999     
11000     /**
11001      * Strips all HTML tags to sort on text only - Case insensitive
11002      * @param {Mixed} s The value being converted
11003      * @return {String} The comparison value
11004      */
11005     asUCText : function(s){
11006         return String(s).toUpperCase().replace(this.stripTagsRE, "");
11007     },
11008     
11009     /**
11010      * Case insensitive string
11011      * @param {Mixed} s The value being converted
11012      * @return {String} The comparison value
11013      */
11014     asUCString : function(s) {
11015         return String(s).toUpperCase();
11016     },
11017     
11018     /**
11019      * Date sorting
11020      * @param {Mixed} s The value being converted
11021      * @return {Number} The comparison value
11022      */
11023     asDate : function(s) {
11024         if(!s){
11025             return 0;
11026         }
11027         if(s instanceof Date){
11028             return s.getTime();
11029         }
11030         return Date.parse(String(s));
11031     },
11032     
11033     /**
11034      * Float sorting
11035      * @param {Mixed} s The value being converted
11036      * @return {Float} The comparison value
11037      */
11038     asFloat : function(s) {
11039         var val = parseFloat(String(s).replace(/,/g, ""));
11040         if(isNaN(val)) {
11041             val = 0;
11042         }
11043         return val;
11044     },
11045     
11046     /**
11047      * Integer sorting
11048      * @param {Mixed} s The value being converted
11049      * @return {Number} The comparison value
11050      */
11051     asInt : function(s) {
11052         var val = parseInt(String(s).replace(/,/g, ""));
11053         if(isNaN(val)) {
11054             val = 0;
11055         }
11056         return val;
11057     }
11058 };/*
11059  * Based on:
11060  * Ext JS Library 1.1.1
11061  * Copyright(c) 2006-2007, Ext JS, LLC.
11062  *
11063  * Originally Released Under LGPL - original licence link has changed is not relivant.
11064  *
11065  * Fork - LGPL
11066  * <script type="text/javascript">
11067  */
11068
11069 /**
11070 * @class Roo.data.Record
11071  * Instances of this class encapsulate both record <em>definition</em> information, and record
11072  * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
11073  * to access Records cached in an {@link Roo.data.Store} object.<br>
11074  * <p>
11075  * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
11076  * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
11077  * objects.<br>
11078  * <p>
11079  * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
11080  * @constructor
11081  * This constructor should not be used to create Record objects. Instead, use the constructor generated by
11082  * {@link #create}. The parameters are the same.
11083  * @param {Array} data An associative Array of data values keyed by the field name.
11084  * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
11085  * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
11086  * not specified an integer id is generated.
11087  */
11088 Roo.data.Record = function(data, id){
11089     this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
11090     this.data = data;
11091 };
11092
11093 /**
11094  * Generate a constructor for a specific record layout.
11095  * @param {Array} o An Array of field definition objects which specify field names, and optionally,
11096  * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
11097  * Each field definition object may contain the following properties: <ul>
11098  * <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,
11099  * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
11100  * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
11101  * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
11102  * is being used, then this is a string containing the javascript expression to reference the data relative to 
11103  * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
11104  * to the data item relative to the record element. If the mapping expression is the same as the field name,
11105  * this may be omitted.</p></li>
11106  * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
11107  * <ul><li>auto (Default, implies no conversion)</li>
11108  * <li>string</li>
11109  * <li>int</li>
11110  * <li>float</li>
11111  * <li>boolean</li>
11112  * <li>date</li></ul></p></li>
11113  * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
11114  * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
11115  * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
11116  * by the Reader into an object that will be stored in the Record. It is passed the
11117  * following parameters:<ul>
11118  * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
11119  * </ul></p></li>
11120  * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
11121  * </ul>
11122  * <br>usage:<br><pre><code>
11123 var TopicRecord = Roo.data.Record.create(
11124     {name: 'title', mapping: 'topic_title'},
11125     {name: 'author', mapping: 'username'},
11126     {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
11127     {name: 'lastPost', mapping: 'post_time', type: 'date'},
11128     {name: 'lastPoster', mapping: 'user2'},
11129     {name: 'excerpt', mapping: 'post_text'}
11130 );
11131
11132 var myNewRecord = new TopicRecord({
11133     title: 'Do my job please',
11134     author: 'noobie',
11135     totalPosts: 1,
11136     lastPost: new Date(),
11137     lastPoster: 'Animal',
11138     excerpt: 'No way dude!'
11139 });
11140 myStore.add(myNewRecord);
11141 </code></pre>
11142  * @method create
11143  * @static
11144  */
11145 Roo.data.Record.create = function(o){
11146     var f = function(){
11147         f.superclass.constructor.apply(this, arguments);
11148     };
11149     Roo.extend(f, Roo.data.Record);
11150     var p = f.prototype;
11151     p.fields = new Roo.util.MixedCollection(false, function(field){
11152         return field.name;
11153     });
11154     for(var i = 0, len = o.length; i < len; i++){
11155         p.fields.add(new Roo.data.Field(o[i]));
11156     }
11157     f.getField = function(name){
11158         return p.fields.get(name);  
11159     };
11160     return f;
11161 };
11162
11163 Roo.data.Record.AUTO_ID = 1000;
11164 Roo.data.Record.EDIT = 'edit';
11165 Roo.data.Record.REJECT = 'reject';
11166 Roo.data.Record.COMMIT = 'commit';
11167
11168 Roo.data.Record.prototype = {
11169     /**
11170      * Readonly flag - true if this record has been modified.
11171      * @type Boolean
11172      */
11173     dirty : false,
11174     editing : false,
11175     error: null,
11176     modified: null,
11177
11178     // private
11179     join : function(store){
11180         this.store = store;
11181     },
11182
11183     /**
11184      * Set the named field to the specified value.
11185      * @param {String} name The name of the field to set.
11186      * @param {Object} value The value to set the field to.
11187      */
11188     set : function(name, value){
11189         if(this.data[name] == value){
11190             return;
11191         }
11192         this.dirty = true;
11193         if(!this.modified){
11194             this.modified = {};
11195         }
11196         if(typeof this.modified[name] == 'undefined'){
11197             this.modified[name] = this.data[name];
11198         }
11199         this.data[name] = value;
11200         if(!this.editing && this.store){
11201             this.store.afterEdit(this);
11202         }       
11203     },
11204
11205     /**
11206      * Get the value of the named field.
11207      * @param {String} name The name of the field to get the value of.
11208      * @return {Object} The value of the field.
11209      */
11210     get : function(name){
11211         return this.data[name]; 
11212     },
11213
11214     // private
11215     beginEdit : function(){
11216         this.editing = true;
11217         this.modified = {}; 
11218     },
11219
11220     // private
11221     cancelEdit : function(){
11222         this.editing = false;
11223         delete this.modified;
11224     },
11225
11226     // private
11227     endEdit : function(){
11228         this.editing = false;
11229         if(this.dirty && this.store){
11230             this.store.afterEdit(this);
11231         }
11232     },
11233
11234     /**
11235      * Usually called by the {@link Roo.data.Store} which owns the Record.
11236      * Rejects all changes made to the Record since either creation, or the last commit operation.
11237      * Modified fields are reverted to their original values.
11238      * <p>
11239      * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
11240      * of reject operations.
11241      */
11242     reject : function(){
11243         var m = this.modified;
11244         for(var n in m){
11245             if(typeof m[n] != "function"){
11246                 this.data[n] = m[n];
11247             }
11248         }
11249         this.dirty = false;
11250         delete this.modified;
11251         this.editing = false;
11252         if(this.store){
11253             this.store.afterReject(this);
11254         }
11255     },
11256
11257     /**
11258      * Usually called by the {@link Roo.data.Store} which owns the Record.
11259      * Commits all changes made to the Record since either creation, or the last commit operation.
11260      * <p>
11261      * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
11262      * of commit operations.
11263      */
11264     commit : function(){
11265         this.dirty = false;
11266         delete this.modified;
11267         this.editing = false;
11268         if(this.store){
11269             this.store.afterCommit(this);
11270         }
11271     },
11272
11273     // private
11274     hasError : function(){
11275         return this.error != null;
11276     },
11277
11278     // private
11279     clearError : function(){
11280         this.error = null;
11281     },
11282
11283     /**
11284      * Creates a copy of this record.
11285      * @param {String} id (optional) A new record id if you don't want to use this record's id
11286      * @return {Record}
11287      */
11288     copy : function(newId) {
11289         return new this.constructor(Roo.apply({}, this.data), newId || this.id);
11290     }
11291 };/*
11292  * Based on:
11293  * Ext JS Library 1.1.1
11294  * Copyright(c) 2006-2007, Ext JS, LLC.
11295  *
11296  * Originally Released Under LGPL - original licence link has changed is not relivant.
11297  *
11298  * Fork - LGPL
11299  * <script type="text/javascript">
11300  */
11301
11302
11303
11304 /**
11305  * @class Roo.data.Store
11306  * @extends Roo.util.Observable
11307  * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
11308  * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
11309  * <p>
11310  * 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
11311  * has no knowledge of the format of the data returned by the Proxy.<br>
11312  * <p>
11313  * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
11314  * instances from the data object. These records are cached and made available through accessor functions.
11315  * @constructor
11316  * Creates a new Store.
11317  * @param {Object} config A config object containing the objects needed for the Store to access data,
11318  * and read the data into Records.
11319  */
11320 Roo.data.Store = function(config){
11321     this.data = new Roo.util.MixedCollection(false);
11322     this.data.getKey = function(o){
11323         return o.id;
11324     };
11325     this.baseParams = {};
11326     // private
11327     this.paramNames = {
11328         "start" : "start",
11329         "limit" : "limit",
11330         "sort" : "sort",
11331         "dir" : "dir",
11332         "multisort" : "_multisort"
11333     };
11334
11335     if(config && config.data){
11336         this.inlineData = config.data;
11337         delete config.data;
11338     }
11339
11340     Roo.apply(this, config);
11341     
11342     if(this.reader){ // reader passed
11343         this.reader = Roo.factory(this.reader, Roo.data);
11344         this.reader.xmodule = this.xmodule || false;
11345         if(!this.recordType){
11346             this.recordType = this.reader.recordType;
11347         }
11348         if(this.reader.onMetaChange){
11349             this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
11350         }
11351     }
11352
11353     if(this.recordType){
11354         this.fields = this.recordType.prototype.fields;
11355     }
11356     this.modified = [];
11357
11358     this.addEvents({
11359         /**
11360          * @event datachanged
11361          * Fires when the data cache has changed, and a widget which is using this Store
11362          * as a Record cache should refresh its view.
11363          * @param {Store} this
11364          */
11365         datachanged : true,
11366         /**
11367          * @event metachange
11368          * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
11369          * @param {Store} this
11370          * @param {Object} meta The JSON metadata
11371          */
11372         metachange : true,
11373         /**
11374          * @event add
11375          * Fires when Records have been added to the Store
11376          * @param {Store} this
11377          * @param {Roo.data.Record[]} records The array of Records added
11378          * @param {Number} index The index at which the record(s) were added
11379          */
11380         add : true,
11381         /**
11382          * @event remove
11383          * Fires when a Record has been removed from the Store
11384          * @param {Store} this
11385          * @param {Roo.data.Record} record The Record that was removed
11386          * @param {Number} index The index at which the record was removed
11387          */
11388         remove : true,
11389         /**
11390          * @event update
11391          * Fires when a Record has been updated
11392          * @param {Store} this
11393          * @param {Roo.data.Record} record The Record that was updated
11394          * @param {String} operation The update operation being performed.  Value may be one of:
11395          * <pre><code>
11396  Roo.data.Record.EDIT
11397  Roo.data.Record.REJECT
11398  Roo.data.Record.COMMIT
11399          * </code></pre>
11400          */
11401         update : true,
11402         /**
11403          * @event clear
11404          * Fires when the data cache has been cleared.
11405          * @param {Store} this
11406          */
11407         clear : true,
11408         /**
11409          * @event beforeload
11410          * Fires before a request is made for a new data object.  If the beforeload handler returns false
11411          * the load action will be canceled.
11412          * @param {Store} this
11413          * @param {Object} options The loading options that were specified (see {@link #load} for details)
11414          */
11415         beforeload : true,
11416         /**
11417          * @event beforeloadadd
11418          * Fires after a new set of Records has been loaded.
11419          * @param {Store} this
11420          * @param {Roo.data.Record[]} records The Records that were loaded
11421          * @param {Object} options The loading options that were specified (see {@link #load} for details)
11422          */
11423         beforeloadadd : true,
11424         /**
11425          * @event load
11426          * Fires after a new set of Records has been loaded, before they are added to the store.
11427          * @param {Store} this
11428          * @param {Roo.data.Record[]} records The Records that were loaded
11429          * @param {Object} options The loading options that were specified (see {@link #load} for details)
11430          * @params {Object} return from reader
11431          */
11432         load : true,
11433         /**
11434          * @event loadexception
11435          * Fires if an exception occurs in the Proxy during loading.
11436          * Called with the signature of the Proxy's "loadexception" event.
11437          * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
11438          * 
11439          * @param {Proxy} 
11440          * @param {Object} return from JsonData.reader() - success, totalRecords, records
11441          * @param {Object} load options 
11442          * @param {Object} jsonData from your request (normally this contains the Exception)
11443          */
11444         loadexception : true
11445     });
11446     
11447     if(this.proxy){
11448         this.proxy = Roo.factory(this.proxy, Roo.data);
11449         this.proxy.xmodule = this.xmodule || false;
11450         this.relayEvents(this.proxy,  ["loadexception"]);
11451     }
11452     this.sortToggle = {};
11453     this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
11454
11455     Roo.data.Store.superclass.constructor.call(this);
11456
11457     if(this.inlineData){
11458         this.loadData(this.inlineData);
11459         delete this.inlineData;
11460     }
11461 };
11462
11463 Roo.extend(Roo.data.Store, Roo.util.Observable, {
11464      /**
11465     * @cfg {boolean} isLocal   flag if data is locally available (and can be always looked up
11466     * without a remote query - used by combo/forms at present.
11467     */
11468     
11469     /**
11470     * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
11471     */
11472     /**
11473     * @cfg {Array} data Inline data to be loaded when the store is initialized.
11474     */
11475     /**
11476     * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
11477     * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
11478     */
11479     /**
11480     * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
11481     * on any HTTP request
11482     */
11483     /**
11484     * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
11485     */
11486     /**
11487     * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
11488     */
11489     multiSort: false,
11490     /**
11491     * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
11492     * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
11493     */
11494     remoteSort : false,
11495
11496     /**
11497     * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
11498      * loaded or when a record is removed. (defaults to false).
11499     */
11500     pruneModifiedRecords : false,
11501
11502     // private
11503     lastOptions : null,
11504
11505     /**
11506      * Add Records to the Store and fires the add event.
11507      * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11508      */
11509     add : function(records){
11510         records = [].concat(records);
11511         for(var i = 0, len = records.length; i < len; i++){
11512             records[i].join(this);
11513         }
11514         var index = this.data.length;
11515         this.data.addAll(records);
11516         this.fireEvent("add", this, records, index);
11517     },
11518
11519     /**
11520      * Remove a Record from the Store and fires the remove event.
11521      * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
11522      */
11523     remove : function(record){
11524         var index = this.data.indexOf(record);
11525         this.data.removeAt(index);
11526  
11527         if(this.pruneModifiedRecords){
11528             this.modified.remove(record);
11529         }
11530         this.fireEvent("remove", this, record, index);
11531     },
11532
11533     /**
11534      * Remove all Records from the Store and fires the clear event.
11535      */
11536     removeAll : function(){
11537         this.data.clear();
11538         if(this.pruneModifiedRecords){
11539             this.modified = [];
11540         }
11541         this.fireEvent("clear", this);
11542     },
11543
11544     /**
11545      * Inserts Records to the Store at the given index and fires the add event.
11546      * @param {Number} index The start index at which to insert the passed Records.
11547      * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11548      */
11549     insert : function(index, records){
11550         records = [].concat(records);
11551         for(var i = 0, len = records.length; i < len; i++){
11552             this.data.insert(index, records[i]);
11553             records[i].join(this);
11554         }
11555         this.fireEvent("add", this, records, index);
11556     },
11557
11558     /**
11559      * Get the index within the cache of the passed Record.
11560      * @param {Roo.data.Record} record The Roo.data.Record object to to find.
11561      * @return {Number} The index of the passed Record. Returns -1 if not found.
11562      */
11563     indexOf : function(record){
11564         return this.data.indexOf(record);
11565     },
11566
11567     /**
11568      * Get the index within the cache of the Record with the passed id.
11569      * @param {String} id The id of the Record to find.
11570      * @return {Number} The index of the Record. Returns -1 if not found.
11571      */
11572     indexOfId : function(id){
11573         return this.data.indexOfKey(id);
11574     },
11575
11576     /**
11577      * Get the Record with the specified id.
11578      * @param {String} id The id of the Record to find.
11579      * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
11580      */
11581     getById : function(id){
11582         return this.data.key(id);
11583     },
11584
11585     /**
11586      * Get the Record at the specified index.
11587      * @param {Number} index The index of the Record to find.
11588      * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
11589      */
11590     getAt : function(index){
11591         return this.data.itemAt(index);
11592     },
11593
11594     /**
11595      * Returns a range of Records between specified indices.
11596      * @param {Number} startIndex (optional) The starting index (defaults to 0)
11597      * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
11598      * @return {Roo.data.Record[]} An array of Records
11599      */
11600     getRange : function(start, end){
11601         return this.data.getRange(start, end);
11602     },
11603
11604     // private
11605     storeOptions : function(o){
11606         o = Roo.apply({}, o);
11607         delete o.callback;
11608         delete o.scope;
11609         this.lastOptions = o;
11610     },
11611
11612     /**
11613      * Loads the Record cache from the configured Proxy using the configured Reader.
11614      * <p>
11615      * If using remote paging, then the first load call must specify the <em>start</em>
11616      * and <em>limit</em> properties in the options.params property to establish the initial
11617      * position within the dataset, and the number of Records to cache on each read from the Proxy.
11618      * <p>
11619      * <strong>It is important to note that for remote data sources, loading is asynchronous,
11620      * and this call will return before the new data has been loaded. Perform any post-processing
11621      * in a callback function, or in a "load" event handler.</strong>
11622      * <p>
11623      * @param {Object} options An object containing properties which control loading options:<ul>
11624      * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
11625      * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
11626      * passed the following arguments:<ul>
11627      * <li>r : Roo.data.Record[]</li>
11628      * <li>options: Options object from the load call</li>
11629      * <li>success: Boolean success indicator</li></ul></li>
11630      * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
11631      * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
11632      * </ul>
11633      */
11634     load : function(options){
11635         options = options || {};
11636         if(this.fireEvent("beforeload", this, options) !== false){
11637             this.storeOptions(options);
11638             var p = Roo.apply(options.params || {}, this.baseParams);
11639             // if meta was not loaded from remote source.. try requesting it.
11640             if (!this.reader.metaFromRemote) {
11641                 p._requestMeta = 1;
11642             }
11643             if(this.sortInfo && this.remoteSort){
11644                 var pn = this.paramNames;
11645                 p[pn["sort"]] = this.sortInfo.field;
11646                 p[pn["dir"]] = this.sortInfo.direction;
11647             }
11648             if (this.multiSort) {
11649                 var pn = this.paramNames;
11650                 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
11651             }
11652             
11653             this.proxy.load(p, this.reader, this.loadRecords, this, options);
11654         }
11655     },
11656
11657     /**
11658      * Reloads the Record cache from the configured Proxy using the configured Reader and
11659      * the options from the last load operation performed.
11660      * @param {Object} options (optional) An object containing properties which may override the options
11661      * used in the last load operation. See {@link #load} for details (defaults to null, in which case
11662      * the most recently used options are reused).
11663      */
11664     reload : function(options){
11665         this.load(Roo.applyIf(options||{}, this.lastOptions));
11666     },
11667
11668     // private
11669     // Called as a callback by the Reader during a load operation.
11670     loadRecords : function(o, options, success){
11671         if(!o || success === false){
11672             if(success !== false){
11673                 this.fireEvent("load", this, [], options, o);
11674             }
11675             if(options.callback){
11676                 options.callback.call(options.scope || this, [], options, false);
11677             }
11678             return;
11679         }
11680         // if data returned failure - throw an exception.
11681         if (o.success === false) {
11682             // show a message if no listener is registered.
11683             if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11684                     Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11685             }
11686             // loadmask wil be hooked into this..
11687             this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11688             return;
11689         }
11690         var r = o.records, t = o.totalRecords || r.length;
11691         
11692         this.fireEvent("beforeloadadd", this, r, options, o);
11693         
11694         if(!options || options.add !== true){
11695             if(this.pruneModifiedRecords){
11696                 this.modified = [];
11697             }
11698             for(var i = 0, len = r.length; i < len; i++){
11699                 r[i].join(this);
11700             }
11701             if(this.snapshot){
11702                 this.data = this.snapshot;
11703                 delete this.snapshot;
11704             }
11705             this.data.clear();
11706             this.data.addAll(r);
11707             this.totalLength = t;
11708             this.applySort();
11709             this.fireEvent("datachanged", this);
11710         }else{
11711             this.totalLength = Math.max(t, this.data.length+r.length);
11712             this.add(r);
11713         }
11714         
11715         if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11716                 
11717             var e = new Roo.data.Record({});
11718
11719             e.set(this.parent.displayField, this.parent.emptyTitle);
11720             e.set(this.parent.valueField, '');
11721
11722             this.insert(0, e);
11723         }
11724             
11725         this.fireEvent("load", this, r, options, o);
11726         if(options.callback){
11727             options.callback.call(options.scope || this, r, options, true);
11728         }
11729     },
11730
11731
11732     /**
11733      * Loads data from a passed data block. A Reader which understands the format of the data
11734      * must have been configured in the constructor.
11735      * @param {Object} data The data block from which to read the Records.  The format of the data expected
11736      * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11737      * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11738      */
11739     loadData : function(o, append){
11740         var r = this.reader.readRecords(o);
11741         this.loadRecords(r, {add: append}, true);
11742     },
11743
11744     /**
11745      * Gets the number of cached records.
11746      * <p>
11747      * <em>If using paging, this may not be the total size of the dataset. If the data object
11748      * used by the Reader contains the dataset size, then the getTotalCount() function returns
11749      * the data set size</em>
11750      */
11751     getCount : function(){
11752         return this.data.length || 0;
11753     },
11754
11755     /**
11756      * Gets the total number of records in the dataset as returned by the server.
11757      * <p>
11758      * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11759      * the dataset size</em>
11760      */
11761     getTotalCount : function(){
11762         return this.totalLength || 0;
11763     },
11764
11765     /**
11766      * Returns the sort state of the Store as an object with two properties:
11767      * <pre><code>
11768  field {String} The name of the field by which the Records are sorted
11769  direction {String} The sort order, "ASC" or "DESC"
11770      * </code></pre>
11771      */
11772     getSortState : function(){
11773         return this.sortInfo;
11774     },
11775
11776     // private
11777     applySort : function(){
11778         if(this.sortInfo && !this.remoteSort){
11779             var s = this.sortInfo, f = s.field;
11780             var st = this.fields.get(f).sortType;
11781             var fn = function(r1, r2){
11782                 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11783                 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11784             };
11785             this.data.sort(s.direction, fn);
11786             if(this.snapshot && this.snapshot != this.data){
11787                 this.snapshot.sort(s.direction, fn);
11788             }
11789         }
11790     },
11791
11792     /**
11793      * Sets the default sort column and order to be used by the next load operation.
11794      * @param {String} fieldName The name of the field to sort by.
11795      * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11796      */
11797     setDefaultSort : function(field, dir){
11798         this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11799     },
11800
11801     /**
11802      * Sort the Records.
11803      * If remote sorting is used, the sort is performed on the server, and the cache is
11804      * reloaded. If local sorting is used, the cache is sorted internally.
11805      * @param {String} fieldName The name of the field to sort by.
11806      * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11807      */
11808     sort : function(fieldName, dir){
11809         var f = this.fields.get(fieldName);
11810         if(!dir){
11811             this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11812             
11813             if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11814                 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11815             }else{
11816                 dir = f.sortDir;
11817             }
11818         }
11819         this.sortToggle[f.name] = dir;
11820         this.sortInfo = {field: f.name, direction: dir};
11821         if(!this.remoteSort){
11822             this.applySort();
11823             this.fireEvent("datachanged", this);
11824         }else{
11825             this.load(this.lastOptions);
11826         }
11827     },
11828
11829     /**
11830      * Calls the specified function for each of the Records in the cache.
11831      * @param {Function} fn The function to call. The Record is passed as the first parameter.
11832      * Returning <em>false</em> aborts and exits the iteration.
11833      * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11834      */
11835     each : function(fn, scope){
11836         this.data.each(fn, scope);
11837     },
11838
11839     /**
11840      * Gets all records modified since the last commit.  Modified records are persisted across load operations
11841      * (e.g., during paging).
11842      * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11843      */
11844     getModifiedRecords : function(){
11845         return this.modified;
11846     },
11847
11848     // private
11849     createFilterFn : function(property, value, anyMatch){
11850         if(!value.exec){ // not a regex
11851             value = String(value);
11852             if(value.length == 0){
11853                 return false;
11854             }
11855             value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11856         }
11857         return function(r){
11858             return value.test(r.data[property]);
11859         };
11860     },
11861
11862     /**
11863      * Sums the value of <i>property</i> for each record between start and end and returns the result.
11864      * @param {String} property A field on your records
11865      * @param {Number} start The record index to start at (defaults to 0)
11866      * @param {Number} end The last record index to include (defaults to length - 1)
11867      * @return {Number} The sum
11868      */
11869     sum : function(property, start, end){
11870         var rs = this.data.items, v = 0;
11871         start = start || 0;
11872         end = (end || end === 0) ? end : rs.length-1;
11873
11874         for(var i = start; i <= end; i++){
11875             v += (rs[i].data[property] || 0);
11876         }
11877         return v;
11878     },
11879
11880     /**
11881      * Filter the records by a specified property.
11882      * @param {String} field A field on your records
11883      * @param {String/RegExp} value Either a string that the field
11884      * should start with or a RegExp to test against the field
11885      * @param {Boolean} anyMatch True to match any part not just the beginning
11886      */
11887     filter : function(property, value, anyMatch){
11888         var fn = this.createFilterFn(property, value, anyMatch);
11889         return fn ? this.filterBy(fn) : this.clearFilter();
11890     },
11891
11892     /**
11893      * Filter by a function. The specified function will be called with each
11894      * record in this data source. If the function returns true the record is included,
11895      * otherwise it is filtered.
11896      * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11897      * @param {Object} scope (optional) The scope of the function (defaults to this)
11898      */
11899     filterBy : function(fn, scope){
11900         this.snapshot = this.snapshot || this.data;
11901         this.data = this.queryBy(fn, scope||this);
11902         this.fireEvent("datachanged", this);
11903     },
11904
11905     /**
11906      * Query the records by a specified property.
11907      * @param {String} field A field on your records
11908      * @param {String/RegExp} value Either a string that the field
11909      * should start with or a RegExp to test against the field
11910      * @param {Boolean} anyMatch True to match any part not just the beginning
11911      * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11912      */
11913     query : function(property, value, anyMatch){
11914         var fn = this.createFilterFn(property, value, anyMatch);
11915         return fn ? this.queryBy(fn) : this.data.clone();
11916     },
11917
11918     /**
11919      * Query by a function. The specified function will be called with each
11920      * record in this data source. If the function returns true the record is included
11921      * in the results.
11922      * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11923      * @param {Object} scope (optional) The scope of the function (defaults to this)
11924       @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11925      **/
11926     queryBy : function(fn, scope){
11927         var data = this.snapshot || this.data;
11928         return data.filterBy(fn, scope||this);
11929     },
11930
11931     /**
11932      * Collects unique values for a particular dataIndex from this store.
11933      * @param {String} dataIndex The property to collect
11934      * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11935      * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11936      * @return {Array} An array of the unique values
11937      **/
11938     collect : function(dataIndex, allowNull, bypassFilter){
11939         var d = (bypassFilter === true && this.snapshot) ?
11940                 this.snapshot.items : this.data.items;
11941         var v, sv, r = [], l = {};
11942         for(var i = 0, len = d.length; i < len; i++){
11943             v = d[i].data[dataIndex];
11944             sv = String(v);
11945             if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11946                 l[sv] = true;
11947                 r[r.length] = v;
11948             }
11949         }
11950         return r;
11951     },
11952
11953     /**
11954      * Revert to a view of the Record cache with no filtering applied.
11955      * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11956      */
11957     clearFilter : function(suppressEvent){
11958         if(this.snapshot && this.snapshot != this.data){
11959             this.data = this.snapshot;
11960             delete this.snapshot;
11961             if(suppressEvent !== true){
11962                 this.fireEvent("datachanged", this);
11963             }
11964         }
11965     },
11966
11967     // private
11968     afterEdit : function(record){
11969         if(this.modified.indexOf(record) == -1){
11970             this.modified.push(record);
11971         }
11972         this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11973     },
11974     
11975     // private
11976     afterReject : function(record){
11977         this.modified.remove(record);
11978         this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11979     },
11980
11981     // private
11982     afterCommit : function(record){
11983         this.modified.remove(record);
11984         this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11985     },
11986
11987     /**
11988      * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11989      * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11990      */
11991     commitChanges : function(){
11992         var m = this.modified.slice(0);
11993         this.modified = [];
11994         for(var i = 0, len = m.length; i < len; i++){
11995             m[i].commit();
11996         }
11997     },
11998
11999     /**
12000      * Cancel outstanding changes on all changed records.
12001      */
12002     rejectChanges : function(){
12003         var m = this.modified.slice(0);
12004         this.modified = [];
12005         for(var i = 0, len = m.length; i < len; i++){
12006             m[i].reject();
12007         }
12008     },
12009
12010     onMetaChange : function(meta, rtype, o){
12011         this.recordType = rtype;
12012         this.fields = rtype.prototype.fields;
12013         delete this.snapshot;
12014         this.sortInfo = meta.sortInfo || this.sortInfo;
12015         this.modified = [];
12016         this.fireEvent('metachange', this, this.reader.meta);
12017     },
12018     
12019     moveIndex : function(data, type)
12020     {
12021         var index = this.indexOf(data);
12022         
12023         var newIndex = index + type;
12024         
12025         this.remove(data);
12026         
12027         this.insert(newIndex, data);
12028         
12029     }
12030 });/*
12031  * Based on:
12032  * Ext JS Library 1.1.1
12033  * Copyright(c) 2006-2007, Ext JS, LLC.
12034  *
12035  * Originally Released Under LGPL - original licence link has changed is not relivant.
12036  *
12037  * Fork - LGPL
12038  * <script type="text/javascript">
12039  */
12040
12041 /**
12042  * @class Roo.data.SimpleStore
12043  * @extends Roo.data.Store
12044  * Small helper class to make creating Stores from Array data easier.
12045  * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
12046  * @cfg {Array} fields An array of field definition objects, or field name strings.
12047  * @cfg {Array} data The multi-dimensional array of data
12048  * @constructor
12049  * @param {Object} config
12050  */
12051 Roo.data.SimpleStore = function(config){
12052     Roo.data.SimpleStore.superclass.constructor.call(this, {
12053         isLocal : true,
12054         reader: new Roo.data.ArrayReader({
12055                 id: config.id
12056             },
12057             Roo.data.Record.create(config.fields)
12058         ),
12059         proxy : new Roo.data.MemoryProxy(config.data)
12060     });
12061     this.load();
12062 };
12063 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
12064  * Based on:
12065  * Ext JS Library 1.1.1
12066  * Copyright(c) 2006-2007, Ext JS, LLC.
12067  *
12068  * Originally Released Under LGPL - original licence link has changed is not relivant.
12069  *
12070  * Fork - LGPL
12071  * <script type="text/javascript">
12072  */
12073
12074 /**
12075 /**
12076  * @extends Roo.data.Store
12077  * @class Roo.data.JsonStore
12078  * Small helper class to make creating Stores for JSON data easier. <br/>
12079 <pre><code>
12080 var store = new Roo.data.JsonStore({
12081     url: 'get-images.php',
12082     root: 'images',
12083     fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
12084 });
12085 </code></pre>
12086  * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
12087  * JsonReader and HttpProxy (unless inline data is provided).</b>
12088  * @cfg {Array} fields An array of field definition objects, or field name strings.
12089  * @constructor
12090  * @param {Object} config
12091  */
12092 Roo.data.JsonStore = function(c){
12093     Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
12094         proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
12095         reader: new Roo.data.JsonReader(c, c.fields)
12096     }));
12097 };
12098 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
12099  * Based on:
12100  * Ext JS Library 1.1.1
12101  * Copyright(c) 2006-2007, Ext JS, LLC.
12102  *
12103  * Originally Released Under LGPL - original licence link has changed is not relivant.
12104  *
12105  * Fork - LGPL
12106  * <script type="text/javascript">
12107  */
12108
12109  
12110 Roo.data.Field = function(config){
12111     if(typeof config == "string"){
12112         config = {name: config};
12113     }
12114     Roo.apply(this, config);
12115     
12116     if(!this.type){
12117         this.type = "auto";
12118     }
12119     
12120     var st = Roo.data.SortTypes;
12121     // named sortTypes are supported, here we look them up
12122     if(typeof this.sortType == "string"){
12123         this.sortType = st[this.sortType];
12124     }
12125     
12126     // set default sortType for strings and dates
12127     if(!this.sortType){
12128         switch(this.type){
12129             case "string":
12130                 this.sortType = st.asUCString;
12131                 break;
12132             case "date":
12133                 this.sortType = st.asDate;
12134                 break;
12135             default:
12136                 this.sortType = st.none;
12137         }
12138     }
12139
12140     // define once
12141     var stripRe = /[\$,%]/g;
12142
12143     // prebuilt conversion function for this field, instead of
12144     // switching every time we're reading a value
12145     if(!this.convert){
12146         var cv, dateFormat = this.dateFormat;
12147         switch(this.type){
12148             case "":
12149             case "auto":
12150             case undefined:
12151                 cv = function(v){ return v; };
12152                 break;
12153             case "string":
12154                 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
12155                 break;
12156             case "int":
12157                 cv = function(v){
12158                     return v !== undefined && v !== null && v !== '' ?
12159                            parseInt(String(v).replace(stripRe, ""), 10) : '';
12160                     };
12161                 break;
12162             case "float":
12163                 cv = function(v){
12164                     return v !== undefined && v !== null && v !== '' ?
12165                            parseFloat(String(v).replace(stripRe, ""), 10) : ''; 
12166                     };
12167                 break;
12168             case "bool":
12169             case "boolean":
12170                 cv = function(v){ return v === true || v === "true" || v == 1; };
12171                 break;
12172             case "date":
12173                 cv = function(v){
12174                     if(!v){
12175                         return '';
12176                     }
12177                     if(v instanceof Date){
12178                         return v;
12179                     }
12180                     if(dateFormat){
12181                         if(dateFormat == "timestamp"){
12182                             return new Date(v*1000);
12183                         }
12184                         return Date.parseDate(v, dateFormat);
12185                     }
12186                     var parsed = Date.parse(v);
12187                     return parsed ? new Date(parsed) : null;
12188                 };
12189              break;
12190             
12191         }
12192         this.convert = cv;
12193     }
12194 };
12195
12196 Roo.data.Field.prototype = {
12197     dateFormat: null,
12198     defaultValue: "",
12199     mapping: null,
12200     sortType : null,
12201     sortDir : "ASC"
12202 };/*
12203  * Based on:
12204  * Ext JS Library 1.1.1
12205  * Copyright(c) 2006-2007, Ext JS, LLC.
12206  *
12207  * Originally Released Under LGPL - original licence link has changed is not relivant.
12208  *
12209  * Fork - LGPL
12210  * <script type="text/javascript">
12211  */
12212  
12213 // Base class for reading structured data from a data source.  This class is intended to be
12214 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
12215
12216 /**
12217  * @class Roo.data.DataReader
12218  * Base class for reading structured data from a data source.  This class is intended to be
12219  * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
12220  */
12221
12222 Roo.data.DataReader = function(meta, recordType){
12223     
12224     this.meta = meta;
12225     
12226     this.recordType = recordType instanceof Array ? 
12227         Roo.data.Record.create(recordType) : recordType;
12228 };
12229
12230 Roo.data.DataReader.prototype = {
12231      /**
12232      * Create an empty record
12233      * @param {Object} data (optional) - overlay some values
12234      * @return {Roo.data.Record} record created.
12235      */
12236     newRow :  function(d) {
12237         var da =  {};
12238         this.recordType.prototype.fields.each(function(c) {
12239             switch( c.type) {
12240                 case 'int' : da[c.name] = 0; break;
12241                 case 'date' : da[c.name] = new Date(); break;
12242                 case 'float' : da[c.name] = 0.0; break;
12243                 case 'boolean' : da[c.name] = false; break;
12244                 default : da[c.name] = ""; break;
12245             }
12246             
12247         });
12248         return new this.recordType(Roo.apply(da, d));
12249     }
12250     
12251 };/*
12252  * Based on:
12253  * Ext JS Library 1.1.1
12254  * Copyright(c) 2006-2007, Ext JS, LLC.
12255  *
12256  * Originally Released Under LGPL - original licence link has changed is not relivant.
12257  *
12258  * Fork - LGPL
12259  * <script type="text/javascript">
12260  */
12261
12262 /**
12263  * @class Roo.data.DataProxy
12264  * @extends Roo.data.Observable
12265  * This class is an abstract base class for implementations which provide retrieval of
12266  * unformatted data objects.<br>
12267  * <p>
12268  * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
12269  * (of the appropriate type which knows how to parse the data object) to provide a block of
12270  * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
12271  * <p>
12272  * Custom implementations must implement the load method as described in
12273  * {@link Roo.data.HttpProxy#load}.
12274  */
12275 Roo.data.DataProxy = function(){
12276     this.addEvents({
12277         /**
12278          * @event beforeload
12279          * Fires before a network request is made to retrieve a data object.
12280          * @param {Object} This DataProxy object.
12281          * @param {Object} params The params parameter to the load function.
12282          */
12283         beforeload : true,
12284         /**
12285          * @event load
12286          * Fires before the load method's callback is called.
12287          * @param {Object} This DataProxy object.
12288          * @param {Object} o The data object.
12289          * @param {Object} arg The callback argument object passed to the load function.
12290          */
12291         load : true,
12292         /**
12293          * @event loadexception
12294          * Fires if an Exception occurs during data retrieval.
12295          * @param {Object} This DataProxy object.
12296          * @param {Object} o The data object.
12297          * @param {Object} arg The callback argument object passed to the load function.
12298          * @param {Object} e The Exception.
12299          */
12300         loadexception : true
12301     });
12302     Roo.data.DataProxy.superclass.constructor.call(this);
12303 };
12304
12305 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
12306
12307     /**
12308      * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
12309      */
12310 /*
12311  * Based on:
12312  * Ext JS Library 1.1.1
12313  * Copyright(c) 2006-2007, Ext JS, LLC.
12314  *
12315  * Originally Released Under LGPL - original licence link has changed is not relivant.
12316  *
12317  * Fork - LGPL
12318  * <script type="text/javascript">
12319  */
12320 /**
12321  * @class Roo.data.MemoryProxy
12322  * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
12323  * to the Reader when its load method is called.
12324  * @constructor
12325  * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
12326  */
12327 Roo.data.MemoryProxy = function(data){
12328     if (data.data) {
12329         data = data.data;
12330     }
12331     Roo.data.MemoryProxy.superclass.constructor.call(this);
12332     this.data = data;
12333 };
12334
12335 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
12336     
12337     /**
12338      * Load data from the requested source (in this case an in-memory
12339      * data object passed to the constructor), read the data object into
12340      * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12341      * process that block using the passed callback.
12342      * @param {Object} params This parameter is not used by the MemoryProxy class.
12343      * @param {Roo.data.DataReader} reader The Reader object which converts the data
12344      * object into a block of Roo.data.Records.
12345      * @param {Function} callback The function into which to pass the block of Roo.data.records.
12346      * The function must be passed <ul>
12347      * <li>The Record block object</li>
12348      * <li>The "arg" argument from the load function</li>
12349      * <li>A boolean success indicator</li>
12350      * </ul>
12351      * @param {Object} scope The scope in which to call the callback
12352      * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12353      */
12354     load : function(params, reader, callback, scope, arg){
12355         params = params || {};
12356         var result;
12357         try {
12358             result = reader.readRecords(this.data);
12359         }catch(e){
12360             this.fireEvent("loadexception", this, arg, null, e);
12361             callback.call(scope, null, arg, false);
12362             return;
12363         }
12364         callback.call(scope, result, arg, true);
12365     },
12366     
12367     // private
12368     update : function(params, records){
12369         
12370     }
12371 });/*
12372  * Based on:
12373  * Ext JS Library 1.1.1
12374  * Copyright(c) 2006-2007, Ext JS, LLC.
12375  *
12376  * Originally Released Under LGPL - original licence link has changed is not relivant.
12377  *
12378  * Fork - LGPL
12379  * <script type="text/javascript">
12380  */
12381 /**
12382  * @class Roo.data.HttpProxy
12383  * @extends Roo.data.DataProxy
12384  * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
12385  * configured to reference a certain URL.<br><br>
12386  * <p>
12387  * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
12388  * from which the running page was served.<br><br>
12389  * <p>
12390  * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
12391  * <p>
12392  * Be aware that to enable the browser to parse an XML document, the server must set
12393  * the Content-Type header in the HTTP response to "text/xml".
12394  * @constructor
12395  * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
12396  * an {@link Roo.data.Connection} object.  If a Connection config is passed, the singleton {@link Roo.Ajax} object
12397  * will be used to make the request.
12398  */
12399 Roo.data.HttpProxy = function(conn){
12400     Roo.data.HttpProxy.superclass.constructor.call(this);
12401     // is conn a conn config or a real conn?
12402     this.conn = conn;
12403     this.useAjax = !conn || !conn.events;
12404   
12405 };
12406
12407 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
12408     // thse are take from connection...
12409     
12410     /**
12411      * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
12412      */
12413     /**
12414      * @cfg {Object} extraParams (Optional) An object containing properties which are used as
12415      * extra parameters to each request made by this object. (defaults to undefined)
12416      */
12417     /**
12418      * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
12419      *  to each request made by this object. (defaults to undefined)
12420      */
12421     /**
12422      * @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)
12423      */
12424     /**
12425      * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
12426      */
12427      /**
12428      * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
12429      * @type Boolean
12430      */
12431   
12432
12433     /**
12434      * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
12435      * @type Boolean
12436      */
12437     /**
12438      * Return the {@link Roo.data.Connection} object being used by this Proxy.
12439      * @return {Connection} The Connection object. This object may be used to subscribe to events on
12440      * a finer-grained basis than the DataProxy events.
12441      */
12442     getConnection : function(){
12443         return this.useAjax ? Roo.Ajax : this.conn;
12444     },
12445
12446     /**
12447      * Load data from the configured {@link Roo.data.Connection}, read the data object into
12448      * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
12449      * process that block using the passed callback.
12450      * @param {Object} params An object containing properties which are to be used as HTTP parameters
12451      * for the request to the remote server.
12452      * @param {Roo.data.DataReader} reader The Reader object which converts the data
12453      * object into a block of Roo.data.Records.
12454      * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12455      * The function must be passed <ul>
12456      * <li>The Record block object</li>
12457      * <li>The "arg" argument from the load function</li>
12458      * <li>A boolean success indicator</li>
12459      * </ul>
12460      * @param {Object} scope The scope in which to call the callback
12461      * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12462      */
12463     load : function(params, reader, callback, scope, arg){
12464         if(this.fireEvent("beforeload", this, params) !== false){
12465             var  o = {
12466                 params : params || {},
12467                 request: {
12468                     callback : callback,
12469                     scope : scope,
12470                     arg : arg
12471                 },
12472                 reader: reader,
12473                 callback : this.loadResponse,
12474                 scope: this
12475             };
12476             if(this.useAjax){
12477                 Roo.applyIf(o, this.conn);
12478                 if(this.activeRequest){
12479                     Roo.Ajax.abort(this.activeRequest);
12480                 }
12481                 this.activeRequest = Roo.Ajax.request(o);
12482             }else{
12483                 this.conn.request(o);
12484             }
12485         }else{
12486             callback.call(scope||this, null, arg, false);
12487         }
12488     },
12489
12490     // private
12491     loadResponse : function(o, success, response){
12492         delete this.activeRequest;
12493         if(!success){
12494             this.fireEvent("loadexception", this, o, response);
12495             o.request.callback.call(o.request.scope, null, o.request.arg, false);
12496             return;
12497         }
12498         var result;
12499         try {
12500             result = o.reader.read(response);
12501         }catch(e){
12502             this.fireEvent("loadexception", this, o, response, e);
12503             o.request.callback.call(o.request.scope, null, o.request.arg, false);
12504             return;
12505         }
12506         
12507         this.fireEvent("load", this, o, o.request.arg);
12508         o.request.callback.call(o.request.scope, result, o.request.arg, true);
12509     },
12510
12511     // private
12512     update : function(dataSet){
12513
12514     },
12515
12516     // private
12517     updateResponse : function(dataSet){
12518
12519     }
12520 });/*
12521  * Based on:
12522  * Ext JS Library 1.1.1
12523  * Copyright(c) 2006-2007, Ext JS, LLC.
12524  *
12525  * Originally Released Under LGPL - original licence link has changed is not relivant.
12526  *
12527  * Fork - LGPL
12528  * <script type="text/javascript">
12529  */
12530
12531 /**
12532  * @class Roo.data.ScriptTagProxy
12533  * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
12534  * other than the originating domain of the running page.<br><br>
12535  * <p>
12536  * <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
12537  * of the running page, you must use this class, rather than DataProxy.</em><br><br>
12538  * <p>
12539  * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
12540  * source code that is used as the source inside a &lt;script> tag.<br><br>
12541  * <p>
12542  * In order for the browser to process the returned data, the server must wrap the data object
12543  * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
12544  * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
12545  * depending on whether the callback name was passed:
12546  * <p>
12547  * <pre><code>
12548 boolean scriptTag = false;
12549 String cb = request.getParameter("callback");
12550 if (cb != null) {
12551     scriptTag = true;
12552     response.setContentType("text/javascript");
12553 } else {
12554     response.setContentType("application/x-json");
12555 }
12556 Writer out = response.getWriter();
12557 if (scriptTag) {
12558     out.write(cb + "(");
12559 }
12560 out.print(dataBlock.toJsonString());
12561 if (scriptTag) {
12562     out.write(");");
12563 }
12564 </pre></code>
12565  *
12566  * @constructor
12567  * @param {Object} config A configuration object.
12568  */
12569 Roo.data.ScriptTagProxy = function(config){
12570     Roo.data.ScriptTagProxy.superclass.constructor.call(this);
12571     Roo.apply(this, config);
12572     this.head = document.getElementsByTagName("head")[0];
12573 };
12574
12575 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
12576
12577 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
12578     /**
12579      * @cfg {String} url The URL from which to request the data object.
12580      */
12581     /**
12582      * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
12583      */
12584     timeout : 30000,
12585     /**
12586      * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
12587      * the server the name of the callback function set up by the load call to process the returned data object.
12588      * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
12589      * javascript output which calls this named function passing the data object as its only parameter.
12590      */
12591     callbackParam : "callback",
12592     /**
12593      *  @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
12594      * name to the request.
12595      */
12596     nocache : true,
12597
12598     /**
12599      * Load data from the configured URL, read the data object into
12600      * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12601      * process that block using the passed callback.
12602      * @param {Object} params An object containing properties which are to be used as HTTP parameters
12603      * for the request to the remote server.
12604      * @param {Roo.data.DataReader} reader The Reader object which converts the data
12605      * object into a block of Roo.data.Records.
12606      * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12607      * The function must be passed <ul>
12608      * <li>The Record block object</li>
12609      * <li>The "arg" argument from the load function</li>
12610      * <li>A boolean success indicator</li>
12611      * </ul>
12612      * @param {Object} scope The scope in which to call the callback
12613      * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12614      */
12615     load : function(params, reader, callback, scope, arg){
12616         if(this.fireEvent("beforeload", this, params) !== false){
12617
12618             var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
12619
12620             var url = this.url;
12621             url += (url.indexOf("?") != -1 ? "&" : "?") + p;
12622             if(this.nocache){
12623                 url += "&_dc=" + (new Date().getTime());
12624             }
12625             var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
12626             var trans = {
12627                 id : transId,
12628                 cb : "stcCallback"+transId,
12629                 scriptId : "stcScript"+transId,
12630                 params : params,
12631                 arg : arg,
12632                 url : url,
12633                 callback : callback,
12634                 scope : scope,
12635                 reader : reader
12636             };
12637             var conn = this;
12638
12639             window[trans.cb] = function(o){
12640                 conn.handleResponse(o, trans);
12641             };
12642
12643             url += String.format("&{0}={1}", this.callbackParam, trans.cb);
12644
12645             if(this.autoAbort !== false){
12646                 this.abort();
12647             }
12648
12649             trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
12650
12651             var script = document.createElement("script");
12652             script.setAttribute("src", url);
12653             script.setAttribute("type", "text/javascript");
12654             script.setAttribute("id", trans.scriptId);
12655             this.head.appendChild(script);
12656
12657             this.trans = trans;
12658         }else{
12659             callback.call(scope||this, null, arg, false);
12660         }
12661     },
12662
12663     // private
12664     isLoading : function(){
12665         return this.trans ? true : false;
12666     },
12667
12668     /**
12669      * Abort the current server request.
12670      */
12671     abort : function(){
12672         if(this.isLoading()){
12673             this.destroyTrans(this.trans);
12674         }
12675     },
12676
12677     // private
12678     destroyTrans : function(trans, isLoaded){
12679         this.head.removeChild(document.getElementById(trans.scriptId));
12680         clearTimeout(trans.timeoutId);
12681         if(isLoaded){
12682             window[trans.cb] = undefined;
12683             try{
12684                 delete window[trans.cb];
12685             }catch(e){}
12686         }else{
12687             // if hasn't been loaded, wait for load to remove it to prevent script error
12688             window[trans.cb] = function(){
12689                 window[trans.cb] = undefined;
12690                 try{
12691                     delete window[trans.cb];
12692                 }catch(e){}
12693             };
12694         }
12695     },
12696
12697     // private
12698     handleResponse : function(o, trans){
12699         this.trans = false;
12700         this.destroyTrans(trans, true);
12701         var result;
12702         try {
12703             result = trans.reader.readRecords(o);
12704         }catch(e){
12705             this.fireEvent("loadexception", this, o, trans.arg, e);
12706             trans.callback.call(trans.scope||window, null, trans.arg, false);
12707             return;
12708         }
12709         this.fireEvent("load", this, o, trans.arg);
12710         trans.callback.call(trans.scope||window, result, trans.arg, true);
12711     },
12712
12713     // private
12714     handleFailure : function(trans){
12715         this.trans = false;
12716         this.destroyTrans(trans, false);
12717         this.fireEvent("loadexception", this, null, trans.arg);
12718         trans.callback.call(trans.scope||window, null, trans.arg, false);
12719     }
12720 });/*
12721  * Based on:
12722  * Ext JS Library 1.1.1
12723  * Copyright(c) 2006-2007, Ext JS, LLC.
12724  *
12725  * Originally Released Under LGPL - original licence link has changed is not relivant.
12726  *
12727  * Fork - LGPL
12728  * <script type="text/javascript">
12729  */
12730
12731 /**
12732  * @class Roo.data.JsonReader
12733  * @extends Roo.data.DataReader
12734  * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12735  * based on mappings in a provided Roo.data.Record constructor.
12736  * 
12737  * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12738  * in the reply previously. 
12739  * 
12740  * <p>
12741  * Example code:
12742  * <pre><code>
12743 var RecordDef = Roo.data.Record.create([
12744     {name: 'name', mapping: 'name'},     // "mapping" property not needed if it's the same as "name"
12745     {name: 'occupation'}                 // This field will use "occupation" as the mapping.
12746 ]);
12747 var myReader = new Roo.data.JsonReader({
12748     totalProperty: "results",    // The property which contains the total dataset size (optional)
12749     root: "rows",                // The property which contains an Array of row objects
12750     id: "id"                     // The property within each row object that provides an ID for the record (optional)
12751 }, RecordDef);
12752 </code></pre>
12753  * <p>
12754  * This would consume a JSON file like this:
12755  * <pre><code>
12756 { 'results': 2, 'rows': [
12757     { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12758     { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12759 }
12760 </code></pre>
12761  * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12762  * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12763  * paged from the remote server.
12764  * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12765  * @cfg {String} root name of the property which contains the Array of row objects.
12766  * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12767  * @cfg {Array} fields Array of field definition objects
12768  * @constructor
12769  * Create a new JsonReader
12770  * @param {Object} meta Metadata configuration options
12771  * @param {Object} recordType Either an Array of field definition objects,
12772  * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12773  */
12774 Roo.data.JsonReader = function(meta, recordType){
12775     
12776     meta = meta || {};
12777     // set some defaults:
12778     Roo.applyIf(meta, {
12779         totalProperty: 'total',
12780         successProperty : 'success',
12781         root : 'data',
12782         id : 'id'
12783     });
12784     
12785     Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12786 };
12787 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12788     
12789     /**
12790      * @prop {Boolean} metaFromRemote  - if the meta data was loaded from the remote source.
12791      * Used by Store query builder to append _requestMeta to params.
12792      * 
12793      */
12794     metaFromRemote : false,
12795     /**
12796      * This method is only used by a DataProxy which has retrieved data from a remote server.
12797      * @param {Object} response The XHR object which contains the JSON data in its responseText.
12798      * @return {Object} data A data block which is used by an Roo.data.Store object as
12799      * a cache of Roo.data.Records.
12800      */
12801     read : function(response){
12802         var json = response.responseText;
12803        
12804         var o = /* eval:var:o */ eval("("+json+")");
12805         if(!o) {
12806             throw {message: "JsonReader.read: Json object not found"};
12807         }
12808         
12809         if(o.metaData){
12810             
12811             delete this.ef;
12812             this.metaFromRemote = true;
12813             this.meta = o.metaData;
12814             this.recordType = Roo.data.Record.create(o.metaData.fields);
12815             this.onMetaChange(this.meta, this.recordType, o);
12816         }
12817         return this.readRecords(o);
12818     },
12819
12820     // private function a store will implement
12821     onMetaChange : function(meta, recordType, o){
12822
12823     },
12824
12825     /**
12826          * @ignore
12827          */
12828     simpleAccess: function(obj, subsc) {
12829         return obj[subsc];
12830     },
12831
12832         /**
12833          * @ignore
12834          */
12835     getJsonAccessor: function(){
12836         var re = /[\[\.]/;
12837         return function(expr) {
12838             try {
12839                 return(re.test(expr))
12840                     ? new Function("obj", "return obj." + expr)
12841                     : function(obj){
12842                         return obj[expr];
12843                     };
12844             } catch(e){}
12845             return Roo.emptyFn;
12846         };
12847     }(),
12848
12849     /**
12850      * Create a data block containing Roo.data.Records from an XML document.
12851      * @param {Object} o An object which contains an Array of row objects in the property specified
12852      * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12853      * which contains the total size of the dataset.
12854      * @return {Object} data A data block which is used by an Roo.data.Store object as
12855      * a cache of Roo.data.Records.
12856      */
12857     readRecords : function(o){
12858         /**
12859          * After any data loads, the raw JSON data is available for further custom processing.
12860          * @type Object
12861          */
12862         this.o = o;
12863         var s = this.meta, Record = this.recordType,
12864             f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12865
12866 //      Generate extraction functions for the totalProperty, the root, the id, and for each field
12867         if (!this.ef) {
12868             if(s.totalProperty) {
12869                     this.getTotal = this.getJsonAccessor(s.totalProperty);
12870                 }
12871                 if(s.successProperty) {
12872                     this.getSuccess = this.getJsonAccessor(s.successProperty);
12873                 }
12874                 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12875                 if (s.id) {
12876                         var g = this.getJsonAccessor(s.id);
12877                         this.getId = function(rec) {
12878                                 var r = g(rec);  
12879                                 return (r === undefined || r === "") ? null : r;
12880                         };
12881                 } else {
12882                         this.getId = function(){return null;};
12883                 }
12884             this.ef = [];
12885             for(var jj = 0; jj < fl; jj++){
12886                 f = fi[jj];
12887                 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12888                 this.ef[jj] = this.getJsonAccessor(map);
12889             }
12890         }
12891
12892         var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12893         if(s.totalProperty){
12894             var vt = parseInt(this.getTotal(o), 10);
12895             if(!isNaN(vt)){
12896                 totalRecords = vt;
12897             }
12898         }
12899         if(s.successProperty){
12900             var vs = this.getSuccess(o);
12901             if(vs === false || vs === 'false'){
12902                 success = false;
12903             }
12904         }
12905         var records = [];
12906         for(var i = 0; i < c; i++){
12907                 var n = root[i];
12908             var values = {};
12909             var id = this.getId(n);
12910             for(var j = 0; j < fl; j++){
12911                 f = fi[j];
12912             var v = this.ef[j](n);
12913             if (!f.convert) {
12914                 Roo.log('missing convert for ' + f.name);
12915                 Roo.log(f);
12916                 continue;
12917             }
12918             values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12919             }
12920             var record = new Record(values, id);
12921             record.json = n;
12922             records[i] = record;
12923         }
12924         return {
12925             raw : o,
12926             success : success,
12927             records : records,
12928             totalRecords : totalRecords
12929         };
12930     }
12931 });/*
12932  * Based on:
12933  * Ext JS Library 1.1.1
12934  * Copyright(c) 2006-2007, Ext JS, LLC.
12935  *
12936  * Originally Released Under LGPL - original licence link has changed is not relivant.
12937  *
12938  * Fork - LGPL
12939  * <script type="text/javascript">
12940  */
12941
12942 /**
12943  * @class Roo.data.ArrayReader
12944  * @extends Roo.data.DataReader
12945  * Data reader class to create an Array of Roo.data.Record objects from an Array.
12946  * Each element of that Array represents a row of data fields. The
12947  * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12948  * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12949  * <p>
12950  * Example code:.
12951  * <pre><code>
12952 var RecordDef = Roo.data.Record.create([
12953     {name: 'name', mapping: 1},         // "mapping" only needed if an "id" field is present which
12954     {name: 'occupation', mapping: 2}    // precludes using the ordinal position as the index.
12955 ]);
12956 var myReader = new Roo.data.ArrayReader({
12957     id: 0                     // The subscript within row Array that provides an ID for the Record (optional)
12958 }, RecordDef);
12959 </code></pre>
12960  * <p>
12961  * This would consume an Array like this:
12962  * <pre><code>
12963 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12964   </code></pre>
12965  * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12966  * @constructor
12967  * Create a new JsonReader
12968  * @param {Object} meta Metadata configuration options.
12969  * @param {Object} recordType Either an Array of field definition objects
12970  * as specified to {@link Roo.data.Record#create},
12971  * or an {@link Roo.data.Record} object
12972  * created using {@link Roo.data.Record#create}.
12973  */
12974 Roo.data.ArrayReader = function(meta, recordType){
12975     Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12976 };
12977
12978 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12979     /**
12980      * Create a data block containing Roo.data.Records from an XML document.
12981      * @param {Object} o An Array of row objects which represents the dataset.
12982      * @return {Object} data A data block which is used by an Roo.data.Store object as
12983      * a cache of Roo.data.Records.
12984      */
12985     readRecords : function(o){
12986         var sid = this.meta ? this.meta.id : null;
12987         var recordType = this.recordType, fields = recordType.prototype.fields;
12988         var records = [];
12989         var root = o;
12990             for(var i = 0; i < root.length; i++){
12991                     var n = root[i];
12992                 var values = {};
12993                 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12994                 for(var j = 0, jlen = fields.length; j < jlen; j++){
12995                 var f = fields.items[j];
12996                 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12997                 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12998                 v = f.convert(v);
12999                 values[f.name] = v;
13000             }
13001                 var record = new recordType(values, id);
13002                 record.json = n;
13003                 records[records.length] = record;
13004             }
13005             return {
13006                 records : records,
13007                 totalRecords : records.length
13008             };
13009     }
13010 });/*
13011  * - LGPL
13012  * * 
13013  */
13014
13015 /**
13016  * @class Roo.bootstrap.ComboBox
13017  * @extends Roo.bootstrap.TriggerField
13018  * A combobox control with support for autocomplete, remote-loading, paging and many other features.
13019  * @cfg {Boolean} append (true|false) default false
13020  * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
13021  * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13022  * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
13023  * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
13024  * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
13025  * @cfg {Boolean} animate default true
13026  * @cfg {Boolean} emptyResultText only for touch device
13027  * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
13028  * @cfg {String} emptyTitle default ''
13029  * @constructor
13030  * Create a new ComboBox.
13031  * @param {Object} config Configuration options
13032  */
13033 Roo.bootstrap.ComboBox = function(config){
13034     Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
13035     this.addEvents({
13036         /**
13037          * @event expand
13038          * Fires when the dropdown list is expanded
13039         * @param {Roo.bootstrap.ComboBox} combo This combo box
13040         */
13041         'expand' : true,
13042         /**
13043          * @event collapse
13044          * Fires when the dropdown list is collapsed
13045         * @param {Roo.bootstrap.ComboBox} combo This combo box
13046         */
13047         'collapse' : true,
13048         /**
13049          * @event beforeselect
13050          * Fires before a list item is selected. Return false to cancel the selection.
13051         * @param {Roo.bootstrap.ComboBox} combo This combo box
13052         * @param {Roo.data.Record} record The data record returned from the underlying store
13053         * @param {Number} index The index of the selected item in the dropdown list
13054         */
13055         'beforeselect' : true,
13056         /**
13057          * @event select
13058          * Fires when a list item is selected
13059         * @param {Roo.bootstrap.ComboBox} combo This combo box
13060         * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
13061         * @param {Number} index The index of the selected item in the dropdown list
13062         */
13063         'select' : true,
13064         /**
13065          * @event beforequery
13066          * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
13067          * The event object passed has these properties:
13068         * @param {Roo.bootstrap.ComboBox} combo This combo box
13069         * @param {String} query The query
13070         * @param {Boolean} forceAll true to force "all" query
13071         * @param {Boolean} cancel true to cancel the query
13072         * @param {Object} e The query event object
13073         */
13074         'beforequery': true,
13075          /**
13076          * @event add
13077          * Fires when the 'add' icon is pressed (add a listener to enable add button)
13078         * @param {Roo.bootstrap.ComboBox} combo This combo box
13079         */
13080         'add' : true,
13081         /**
13082          * @event edit
13083          * Fires when the 'edit' icon is pressed (add a listener to enable add button)
13084         * @param {Roo.bootstrap.ComboBox} combo This combo box
13085         * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
13086         */
13087         'edit' : true,
13088         /**
13089          * @event remove
13090          * Fires when the remove value from the combobox array
13091         * @param {Roo.bootstrap.ComboBox} combo This combo box
13092         */
13093         'remove' : true,
13094         /**
13095          * @event afterremove
13096          * Fires when the remove value from the combobox array
13097         * @param {Roo.bootstrap.ComboBox} combo This combo box
13098         */
13099         'afterremove' : true,
13100         /**
13101          * @event specialfilter
13102          * Fires when specialfilter
13103             * @param {Roo.bootstrap.ComboBox} combo This combo box
13104             */
13105         'specialfilter' : true,
13106         /**
13107          * @event tick
13108          * Fires when tick the element
13109             * @param {Roo.bootstrap.ComboBox} combo This combo box
13110             */
13111         'tick' : true,
13112         /**
13113          * @event touchviewdisplay
13114          * Fires when touch view require special display (default is using displayField)
13115             * @param {Roo.bootstrap.ComboBox} combo This combo box
13116             * @param {Object} cfg set html .
13117             */
13118         'touchviewdisplay' : true
13119         
13120     });
13121     
13122     this.item = [];
13123     this.tickItems = [];
13124     
13125     this.selectedIndex = -1;
13126     if(this.mode == 'local'){
13127         if(config.queryDelay === undefined){
13128             this.queryDelay = 10;
13129         }
13130         if(config.minChars === undefined){
13131             this.minChars = 0;
13132         }
13133     }
13134 };
13135
13136 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
13137      
13138     /**
13139      * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
13140      * rendering into an Roo.Editor, defaults to false)
13141      */
13142     /**
13143      * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
13144      * {tag: "input", type: "text", size: "24", autocomplete: "off"})
13145      */
13146     /**
13147      * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
13148      */
13149     /**
13150      * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
13151      * the dropdown list (defaults to undefined, with no header element)
13152      */
13153
13154      /**
13155      * @cfg {String/Roo.Template} tpl The template to use to render the output
13156      */
13157      
13158      /**
13159      * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
13160      */
13161     listWidth: undefined,
13162     /**
13163      * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
13164      * mode = 'remote' or 'text' if mode = 'local')
13165      */
13166     displayField: undefined,
13167     
13168     /**
13169      * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
13170      * mode = 'remote' or 'value' if mode = 'local'). 
13171      * Note: use of a valueField requires the user make a selection
13172      * in order for a value to be mapped.
13173      */
13174     valueField: undefined,
13175     /**
13176      * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
13177      */
13178     modalTitle : '',
13179     
13180     /**
13181      * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
13182      * field's data value (defaults to the underlying DOM element's name)
13183      */
13184     hiddenName: undefined,
13185     /**
13186      * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
13187      */
13188     listClass: '',
13189     /**
13190      * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
13191      */
13192     selectedClass: 'active',
13193     
13194     /**
13195      * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
13196      */
13197     shadow:'sides',
13198     /**
13199      * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
13200      * anchor positions (defaults to 'tl-bl')
13201      */
13202     listAlign: 'tl-bl?',
13203     /**
13204      * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
13205      */
13206     maxHeight: 300,
13207     /**
13208      * @cfg {String} triggerAction The action to execute when the trigger field is activated.  Use 'all' to run the
13209      * query specified by the allQuery config option (defaults to 'query')
13210      */
13211     triggerAction: 'query',
13212     /**
13213      * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
13214      * (defaults to 4, does not apply if editable = false)
13215      */
13216     minChars : 4,
13217     /**
13218      * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
13219      * delay (typeAheadDelay) if it matches a known value (defaults to false)
13220      */
13221     typeAhead: false,
13222     /**
13223      * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
13224      * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
13225      */
13226     queryDelay: 500,
13227     /**
13228      * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
13229      * filter queries will execute with page start and limit parameters.  Only applies when mode = 'remote' (defaults to 0)
13230      */
13231     pageSize: 0,
13232     /**
13233      * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus.  Only applies
13234      * when editable = true (defaults to false)
13235      */
13236     selectOnFocus:false,
13237     /**
13238      * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
13239      */
13240     queryParam: 'query',
13241     /**
13242      * @cfg {String} loadingText The text to display in the dropdown list while data is loading.  Only applies
13243      * when mode = 'remote' (defaults to 'Loading...')
13244      */
13245     loadingText: 'Loading...',
13246     /**
13247      * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
13248      */
13249     resizable: false,
13250     /**
13251      * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
13252      */
13253     handleHeight : 8,
13254     /**
13255      * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
13256      * traditional select (defaults to true)
13257      */
13258     editable: true,
13259     /**
13260      * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
13261      */
13262     allQuery: '',
13263     /**
13264      * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
13265      */
13266     mode: 'remote',
13267     /**
13268      * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
13269      * listWidth has a higher value)
13270      */
13271     minListWidth : 70,
13272     /**
13273      * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
13274      * allow the user to set arbitrary text into the field (defaults to false)
13275      */
13276     forceSelection:false,
13277     /**
13278      * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
13279      * if typeAhead = true (defaults to 250)
13280      */
13281     typeAheadDelay : 250,
13282     /**
13283      * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
13284      * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
13285      */
13286     valueNotFoundText : undefined,
13287     /**
13288      * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
13289      */
13290     blockFocus : false,
13291     
13292     /**
13293      * @cfg {Boolean} disableClear Disable showing of clear button.
13294      */
13295     disableClear : false,
13296     /**
13297      * @cfg {Boolean} alwaysQuery  Disable caching of results, and always send query
13298      */
13299     alwaysQuery : false,
13300     
13301     /**
13302      * @cfg {Boolean} multiple  (true|false) ComboBobArray, default false
13303      */
13304     multiple : false,
13305     
13306     /**
13307      * @cfg {String} invalidClass DEPRICATED - uses BS4 is-valid now
13308      */
13309     invalidClass : "has-warning",
13310     
13311     /**
13312      * @cfg {String} validClass DEPRICATED - uses BS4 is-valid now
13313      */
13314     validClass : "has-success",
13315     
13316     /**
13317      * @cfg {Boolean} specialFilter (true|false) special filter default false
13318      */
13319     specialFilter : false,
13320     
13321     /**
13322      * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
13323      */
13324     mobileTouchView : true,
13325     
13326     /**
13327      * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
13328      */
13329     useNativeIOS : false,
13330     
13331     /**
13332      * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
13333      */
13334     mobile_restrict_height : false,
13335     
13336     ios_options : false,
13337     
13338     //private
13339     addicon : false,
13340     editicon: false,
13341     
13342     page: 0,
13343     hasQuery: false,
13344     append: false,
13345     loadNext: false,
13346     autoFocus : true,
13347     tickable : false,
13348     btnPosition : 'right',
13349     triggerList : true,
13350     showToggleBtn : true,
13351     animate : true,
13352     emptyResultText: 'Empty',
13353     triggerText : 'Select',
13354     emptyTitle : '',
13355     
13356     // element that contains real text value.. (when hidden is used..)
13357     
13358     getAutoCreate : function()
13359     {   
13360         var cfg = false;
13361         //render
13362         /*
13363          * Render classic select for iso
13364          */
13365         
13366         if(Roo.isIOS && this.useNativeIOS){
13367             cfg = this.getAutoCreateNativeIOS();
13368             return cfg;
13369         }
13370         
13371         /*
13372          * Touch Devices
13373          */
13374         
13375         if(Roo.isTouch && this.mobileTouchView){
13376             cfg = this.getAutoCreateTouchView();
13377             return cfg;;
13378         }
13379         
13380         /*
13381          *  Normal ComboBox
13382          */
13383         if(!this.tickable){
13384             cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
13385             return cfg;
13386         }
13387         
13388         /*
13389          *  ComboBox with tickable selections
13390          */
13391              
13392         var align = this.labelAlign || this.parentLabelAlign();
13393         
13394         cfg = {
13395             cls : 'form-group roo-combobox-tickable' //input-group
13396         };
13397         
13398         var btn_text_select = '';
13399         var btn_text_done = '';
13400         var btn_text_cancel = '';
13401         
13402         if (this.btn_text_show) {
13403             btn_text_select = 'Select';
13404             btn_text_done = 'Done';
13405             btn_text_cancel = 'Cancel'; 
13406         }
13407         
13408         var buttons = {
13409             tag : 'div',
13410             cls : 'tickable-buttons',
13411             cn : [
13412                 {
13413                     tag : 'button',
13414                     type : 'button',
13415                     cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
13416                     //html : this.triggerText
13417                     html: btn_text_select
13418                 },
13419                 {
13420                     tag : 'button',
13421                     type : 'button',
13422                     name : 'ok',
13423                     cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
13424                     //html : 'Done'
13425                     html: btn_text_done
13426                 },
13427                 {
13428                     tag : 'button',
13429                     type : 'button',
13430                     name : 'cancel',
13431                     cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
13432                     //html : 'Cancel'
13433                     html: btn_text_cancel
13434                 }
13435             ]
13436         };
13437         
13438         if(this.editable){
13439             buttons.cn.unshift({
13440                 tag: 'input',
13441                 cls: 'roo-select2-search-field-input'
13442             });
13443         }
13444         
13445         var _this = this;
13446         
13447         Roo.each(buttons.cn, function(c){
13448             if (_this.size) {
13449                 c.cls += ' btn-' + _this.size;
13450             }
13451
13452             if (_this.disabled) {
13453                 c.disabled = true;
13454             }
13455         });
13456         
13457         var box = {
13458             tag: 'div',
13459             style : 'display: contents',
13460             cn: [
13461                 {
13462                     tag: 'input',
13463                     type : 'hidden',
13464                     cls: 'form-hidden-field'
13465                 },
13466                 {
13467                     tag: 'ul',
13468                     cls: 'roo-select2-choices',
13469                     cn:[
13470                         {
13471                             tag: 'li',
13472                             cls: 'roo-select2-search-field',
13473                             cn: [
13474                                 buttons
13475                             ]
13476                         }
13477                     ]
13478                 }
13479             ]
13480         };
13481         
13482         var combobox = {
13483             cls: 'roo-select2-container input-group roo-select2-container-multi',
13484             cn: [
13485                 
13486                 box
13487 //                {
13488 //                    tag: 'ul',
13489 //                    cls: 'typeahead typeahead-long dropdown-menu',
13490 //                    style: 'display:none; max-height:' + this.maxHeight + 'px;'
13491 //                }
13492             ]
13493         };
13494         
13495         if(this.hasFeedback && !this.allowBlank){
13496             
13497             var feedback = {
13498                 tag: 'span',
13499                 cls: 'glyphicon form-control-feedback'
13500             };
13501
13502             combobox.cn.push(feedback);
13503         }
13504         
13505         var indicator = {
13506             tag : 'i',
13507             cls : 'roo-required-indicator ' + (this.indicatorpos == 'right'  ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
13508             tooltip : 'This field is required'
13509         };
13510         if (Roo.bootstrap.version == 4) {
13511             indicator = {
13512                 tag : 'i',
13513                 style : 'display:none'
13514             };
13515         }
13516         if (align ==='left' && this.fieldLabel.length) {
13517             
13518             cfg.cls += ' roo-form-group-label-left'  + (Roo.bootstrap.version == 4 ? ' row' : '');
13519             
13520             cfg.cn = [
13521                 indicator,
13522                 {
13523                     tag: 'label',
13524                     'for' :  id,
13525                     cls : 'control-label col-form-label',
13526                     html : this.fieldLabel
13527
13528                 },
13529                 {
13530                     cls : "", 
13531                     cn: [
13532                         combobox
13533                     ]
13534                 }
13535
13536             ];
13537             
13538             var labelCfg = cfg.cn[1];
13539             var contentCfg = cfg.cn[2];
13540             
13541
13542             if(this.indicatorpos == 'right'){
13543                 
13544                 cfg.cn = [
13545                     {
13546                         tag: 'label',
13547                         'for' :  id,
13548                         cls : 'control-label col-form-label',
13549                         cn : [
13550                             {
13551                                 tag : 'span',
13552                                 html : this.fieldLabel
13553                             },
13554                             indicator
13555                         ]
13556                     },
13557                     {
13558                         cls : "",
13559                         cn: [
13560                             combobox
13561                         ]
13562                     }
13563
13564                 ];
13565                 
13566                 
13567                 
13568                 labelCfg = cfg.cn[0];
13569                 contentCfg = cfg.cn[1];
13570             
13571             }
13572             
13573             if(this.labelWidth > 12){
13574                 labelCfg.style = "width: " + this.labelWidth + 'px';
13575             }
13576             
13577             if(this.labelWidth < 13 && this.labelmd == 0){
13578                 this.labelmd = this.labelWidth;
13579             }
13580             
13581             if(this.labellg > 0){
13582                 labelCfg.cls += ' col-lg-' + this.labellg;
13583                 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
13584             }
13585             
13586             if(this.labelmd > 0){
13587                 labelCfg.cls += ' col-md-' + this.labelmd;
13588                 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
13589             }
13590             
13591             if(this.labelsm > 0){
13592                 labelCfg.cls += ' col-sm-' + this.labelsm;
13593                 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
13594             }
13595             
13596             if(this.labelxs > 0){
13597                 labelCfg.cls += ' col-xs-' + this.labelxs;
13598                 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
13599             }
13600                 
13601                 
13602         } else if ( this.fieldLabel.length) {
13603 //                Roo.log(" label");
13604                  cfg.cn = [
13605                    indicator,
13606                     {
13607                         tag: 'label',
13608                         //cls : 'input-group-addon',
13609                         html : this.fieldLabel
13610                     },
13611                     combobox
13612                 ];
13613                 
13614                 if(this.indicatorpos == 'right'){
13615                     cfg.cn = [
13616                         {
13617                             tag: 'label',
13618                             //cls : 'input-group-addon',
13619                             html : this.fieldLabel
13620                         },
13621                         indicator,
13622                         combobox
13623                     ];
13624                     
13625                 }
13626
13627         } else {
13628             
13629 //                Roo.log(" no label && no align");
13630                 cfg = combobox
13631                      
13632                 
13633         }
13634          
13635         var settings=this;
13636         ['xs','sm','md','lg'].map(function(size){
13637             if (settings[size]) {
13638                 cfg.cls += ' col-' + size + '-' + settings[size];
13639             }
13640         });
13641         
13642         return cfg;
13643         
13644     },
13645     
13646     _initEventsCalled : false,
13647     
13648     // private
13649     initEvents: function()
13650     {   
13651         if (this._initEventsCalled) { // as we call render... prevent looping...
13652             return;
13653         }
13654         this._initEventsCalled = true;
13655         
13656         if (!this.store) {
13657             throw "can not find store for combo";
13658         }
13659         
13660         this.indicator = this.indicatorEl();
13661         
13662         this.store = Roo.factory(this.store, Roo.data);
13663         this.store.parent = this;
13664         
13665         // if we are building from html. then this element is so complex, that we can not really
13666         // use the rendered HTML.
13667         // so we have to trash and replace the previous code.
13668         if (Roo.XComponent.build_from_html) {
13669             // remove this element....
13670             var e = this.el.dom, k=0;
13671             while (e ) { e = e.previousSibling;  ++k;}
13672
13673             this.el.remove();
13674             
13675             this.el=false;
13676             this.rendered = false;
13677             
13678             this.render(this.parent().getChildContainer(true), k);
13679         }
13680         
13681         if(Roo.isIOS && this.useNativeIOS){
13682             this.initIOSView();
13683             return;
13684         }
13685         
13686         /*
13687          * Touch Devices
13688          */
13689         
13690         if(Roo.isTouch && this.mobileTouchView){
13691             this.initTouchView();
13692             return;
13693         }
13694         
13695         if(this.tickable){
13696             this.initTickableEvents();
13697             return;
13698         }
13699         
13700         Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13701         
13702         if(this.hiddenName){
13703             
13704             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13705             
13706             this.hiddenField.dom.value =
13707                 this.hiddenValue !== undefined ? this.hiddenValue :
13708                 this.value !== undefined ? this.value : '';
13709
13710             // prevent input submission
13711             this.el.dom.removeAttribute('name');
13712             this.hiddenField.dom.setAttribute('name', this.hiddenName);
13713              
13714              
13715         }
13716         //if(Roo.isGecko){
13717         //    this.el.dom.setAttribute('autocomplete', 'off');
13718         //}
13719         
13720         var cls = 'x-combo-list';
13721         
13722         //this.list = new Roo.Layer({
13723         //    shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13724         //});
13725         
13726         var _this = this;
13727         
13728         (function(){
13729             var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13730             _this.list.setWidth(lw);
13731         }).defer(100);
13732         
13733         this.list.on('mouseover', this.onViewOver, this);
13734         this.list.on('mousemove', this.onViewMove, this);
13735         this.list.on('scroll', this.onViewScroll, this);
13736         
13737         /*
13738         this.list.swallowEvent('mousewheel');
13739         this.assetHeight = 0;
13740
13741         if(this.title){
13742             this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13743             this.assetHeight += this.header.getHeight();
13744         }
13745
13746         this.innerList = this.list.createChild({cls:cls+'-inner'});
13747         this.innerList.on('mouseover', this.onViewOver, this);
13748         this.innerList.on('mousemove', this.onViewMove, this);
13749         this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13750         
13751         if(this.allowBlank && !this.pageSize && !this.disableClear){
13752             this.footer = this.list.createChild({cls:cls+'-ft'});
13753             this.pageTb = new Roo.Toolbar(this.footer);
13754            
13755         }
13756         if(this.pageSize){
13757             this.footer = this.list.createChild({cls:cls+'-ft'});
13758             this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13759                     {pageSize: this.pageSize});
13760             
13761         }
13762         
13763         if (this.pageTb && this.allowBlank && !this.disableClear) {
13764             var _this = this;
13765             this.pageTb.add(new Roo.Toolbar.Fill(), {
13766                 cls: 'x-btn-icon x-btn-clear',
13767                 text: '&#160;',
13768                 handler: function()
13769                 {
13770                     _this.collapse();
13771                     _this.clearValue();
13772                     _this.onSelect(false, -1);
13773                 }
13774             });
13775         }
13776         if (this.footer) {
13777             this.assetHeight += this.footer.getHeight();
13778         }
13779         */
13780             
13781         if(!this.tpl){
13782             this.tpl = Roo.bootstrap.version == 4 ?
13783                 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' :  // 4 does not need <li> and it get's really confisued.
13784                 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
13785         }
13786
13787         this.view = new Roo.View(this.list, this.tpl, {
13788             singleSelect:true, store: this.store, selectedClass: this.selectedClass
13789         });
13790         //this.view.wrapEl.setDisplayed(false);
13791         this.view.on('click', this.onViewClick, this);
13792         
13793         
13794         this.store.on('beforeload', this.onBeforeLoad, this);
13795         this.store.on('load', this.onLoad, this);
13796         this.store.on('loadexception', this.onLoadException, this);
13797         /*
13798         if(this.resizable){
13799             this.resizer = new Roo.Resizable(this.list,  {
13800                pinned:true, handles:'se'
13801             });
13802             this.resizer.on('resize', function(r, w, h){
13803                 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13804                 this.listWidth = w;
13805                 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13806                 this.restrictHeight();
13807             }, this);
13808             this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13809         }
13810         */
13811         if(!this.editable){
13812             this.editable = true;
13813             this.setEditable(false);
13814         }
13815         
13816         /*
13817         
13818         if (typeof(this.events.add.listeners) != 'undefined') {
13819             
13820             this.addicon = this.wrap.createChild(
13821                 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });  
13822        
13823             this.addicon.on('click', function(e) {
13824                 this.fireEvent('add', this);
13825             }, this);
13826         }
13827         if (typeof(this.events.edit.listeners) != 'undefined') {
13828             
13829             this.editicon = this.wrap.createChild(
13830                 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });  
13831             if (this.addicon) {
13832                 this.editicon.setStyle('margin-left', '40px');
13833             }
13834             this.editicon.on('click', function(e) {
13835                 
13836                 // we fire even  if inothing is selected..
13837                 this.fireEvent('edit', this, this.lastData );
13838                 
13839             }, this);
13840         }
13841         */
13842         
13843         this.keyNav = new Roo.KeyNav(this.inputEl(), {
13844             "up" : function(e){
13845                 this.inKeyMode = true;
13846                 this.selectPrev();
13847             },
13848
13849             "down" : function(e){
13850                 if(!this.isExpanded()){
13851                     this.onTriggerClick();
13852                 }else{
13853                     this.inKeyMode = true;
13854                     this.selectNext();
13855                 }
13856             },
13857
13858             "enter" : function(e){
13859 //                this.onViewClick();
13860                 //return true;
13861                 this.collapse();
13862                 
13863                 if(this.fireEvent("specialkey", this, e)){
13864                     this.onViewClick(false);
13865                 }
13866                 
13867                 return true;
13868             },
13869
13870             "esc" : function(e){
13871                 this.collapse();
13872             },
13873
13874             "tab" : function(e){
13875                 this.collapse();
13876                 
13877                 if(this.fireEvent("specialkey", this, e)){
13878                     this.onViewClick(false);
13879                 }
13880                 
13881                 return true;
13882             },
13883
13884             scope : this,
13885
13886             doRelay : function(foo, bar, hname){
13887                 if(hname == 'down' || this.scope.isExpanded()){
13888                    return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13889                 }
13890                 return true;
13891             },
13892
13893             forceKeyDown: true
13894         });
13895         
13896         
13897         this.queryDelay = Math.max(this.queryDelay || 10,
13898                 this.mode == 'local' ? 10 : 250);
13899         
13900         
13901         this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13902         
13903         if(this.typeAhead){
13904             this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13905         }
13906         if(this.editable !== false){
13907             this.inputEl().on("keyup", this.onKeyUp, this);
13908         }
13909         if(this.forceSelection){
13910             this.inputEl().on('blur', this.doForce, this);
13911         }
13912         
13913         if(this.multiple){
13914             this.choices = this.el.select('ul.roo-select2-choices', true).first();
13915             this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13916         }
13917     },
13918     
13919     initTickableEvents: function()
13920     {   
13921         this.createList();
13922         
13923         if(this.hiddenName){
13924             
13925             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13926             
13927             this.hiddenField.dom.value =
13928                 this.hiddenValue !== undefined ? this.hiddenValue :
13929                 this.value !== undefined ? this.value : '';
13930
13931             // prevent input submission
13932             this.el.dom.removeAttribute('name');
13933             this.hiddenField.dom.setAttribute('name', this.hiddenName);
13934              
13935              
13936         }
13937         
13938 //        this.list = this.el.select('ul.dropdown-menu',true).first();
13939         
13940         this.choices = this.el.select('ul.roo-select2-choices', true).first();
13941         this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13942         if(this.triggerList){
13943             this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13944         }
13945          
13946         this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13947         this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13948         
13949         this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13950         this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13951         
13952         this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13953         this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13954         
13955         this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13956         this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13957         this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13958         
13959         this.okBtn.hide();
13960         this.cancelBtn.hide();
13961         
13962         var _this = this;
13963         
13964         (function(){
13965             var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13966             _this.list.setWidth(lw);
13967         }).defer(100);
13968         
13969         this.list.on('mouseover', this.onViewOver, this);
13970         this.list.on('mousemove', this.onViewMove, this);
13971         
13972         this.list.on('scroll', this.onViewScroll, this);
13973         
13974         if(!this.tpl){
13975             this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' + 
13976                 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
13977         }
13978
13979         this.view = new Roo.View(this.list, this.tpl, {
13980             singleSelect:true,
13981             tickable:true,
13982             parent:this,
13983             store: this.store,
13984             selectedClass: this.selectedClass
13985         });
13986         
13987         //this.view.wrapEl.setDisplayed(false);
13988         this.view.on('click', this.onViewClick, this);
13989         
13990         
13991         
13992         this.store.on('beforeload', this.onBeforeLoad, this);
13993         this.store.on('load', this.onLoad, this);
13994         this.store.on('loadexception', this.onLoadException, this);
13995         
13996         if(this.editable){
13997             this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13998                 "up" : function(e){
13999                     this.inKeyMode = true;
14000                     this.selectPrev();
14001                 },
14002
14003                 "down" : function(e){
14004                     this.inKeyMode = true;
14005                     this.selectNext();
14006                 },
14007
14008                 "enter" : function(e){
14009                     if(this.fireEvent("specialkey", this, e)){
14010                         this.onViewClick(false);
14011                     }
14012                     
14013                     return true;
14014                 },
14015
14016                 "esc" : function(e){
14017                     this.onTickableFooterButtonClick(e, false, false);
14018                 },
14019
14020                 "tab" : function(e){
14021                     this.fireEvent("specialkey", this, e);
14022                     
14023                     this.onTickableFooterButtonClick(e, false, false);
14024                     
14025                     return true;
14026                 },
14027
14028                 scope : this,
14029
14030                 doRelay : function(e, fn, key){
14031                     if(this.scope.isExpanded()){
14032                        return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
14033                     }
14034                     return true;
14035                 },
14036
14037                 forceKeyDown: true
14038             });
14039         }
14040         
14041         this.queryDelay = Math.max(this.queryDelay || 10,
14042                 this.mode == 'local' ? 10 : 250);
14043         
14044         
14045         this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
14046         
14047         if(this.typeAhead){
14048             this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
14049         }
14050         
14051         if(this.editable !== false){
14052             this.tickableInputEl().on("keyup", this.onKeyUp, this);
14053         }
14054         
14055         this.indicator = this.indicatorEl();
14056         
14057         if(this.indicator){
14058             this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
14059             this.indicator.hide();
14060         }
14061         
14062     },
14063
14064     onDestroy : function(){
14065         if(this.view){
14066             this.view.setStore(null);
14067             this.view.el.removeAllListeners();
14068             this.view.el.remove();
14069             this.view.purgeListeners();
14070         }
14071         if(this.list){
14072             this.list.dom.innerHTML  = '';
14073         }
14074         
14075         if(this.store){
14076             this.store.un('beforeload', this.onBeforeLoad, this);
14077             this.store.un('load', this.onLoad, this);
14078             this.store.un('loadexception', this.onLoadException, this);
14079         }
14080         Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
14081     },
14082
14083     // private
14084     fireKey : function(e){
14085         if(e.isNavKeyPress() && !this.list.isVisible()){
14086             this.fireEvent("specialkey", this, e);
14087         }
14088     },
14089
14090     // private
14091     onResize: function(w, h){
14092 //        Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
14093 //        
14094 //        if(typeof w != 'number'){
14095 //            // we do not handle it!?!?
14096 //            return;
14097 //        }
14098 //        var tw = this.trigger.getWidth();
14099 //       // tw += this.addicon ? this.addicon.getWidth() : 0;
14100 //       // tw += this.editicon ? this.editicon.getWidth() : 0;
14101 //        var x = w - tw;
14102 //        this.inputEl().setWidth( this.adjustWidth('input', x));
14103 //            
14104 //        //this.trigger.setStyle('left', x+'px');
14105 //        
14106 //        if(this.list && this.listWidth === undefined){
14107 //            var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
14108 //            this.list.setWidth(lw);
14109 //            this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
14110 //        }
14111         
14112     
14113         
14114     },
14115
14116     /**
14117      * Allow or prevent the user from directly editing the field text.  If false is passed,
14118      * the user will only be able to select from the items defined in the dropdown list.  This method
14119      * is the runtime equivalent of setting the 'editable' config option at config time.
14120      * @param {Boolean} value True to allow the user to directly edit the field text
14121      */
14122     setEditable : function(value){
14123         if(value == this.editable){
14124             return;
14125         }
14126         this.editable = value;
14127         if(!value){
14128             this.inputEl().dom.setAttribute('readOnly', true);
14129             this.inputEl().on('mousedown', this.onTriggerClick,  this);
14130             this.inputEl().addClass('x-combo-noedit');
14131         }else{
14132             this.inputEl().dom.setAttribute('readOnly', false);
14133             this.inputEl().un('mousedown', this.onTriggerClick,  this);
14134             this.inputEl().removeClass('x-combo-noedit');
14135         }
14136     },
14137
14138     // private
14139     
14140     onBeforeLoad : function(combo,opts){
14141         if(!this.hasFocus){
14142             return;
14143         }
14144          if (!opts.add) {
14145             this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
14146          }
14147         this.restrictHeight();
14148         this.selectedIndex = -1;
14149     },
14150
14151     // private
14152     onLoad : function(){
14153         
14154         this.hasQuery = false;
14155         
14156         if(!this.hasFocus){
14157             return;
14158         }
14159         
14160         if(typeof(this.loading) !== 'undefined' && this.loading !== null){
14161             this.loading.hide();
14162         }
14163         
14164         if(this.store.getCount() > 0){
14165             
14166             this.expand();
14167             this.restrictHeight();
14168             if(this.lastQuery == this.allQuery){
14169                 if(this.editable && !this.tickable){
14170                     this.inputEl().dom.select();
14171                 }
14172                 
14173                 if(
14174                     !this.selectByValue(this.value, true) &&
14175                     this.autoFocus && 
14176                     (
14177                         !this.store.lastOptions ||
14178                         typeof(this.store.lastOptions.add) == 'undefined' || 
14179                         this.store.lastOptions.add != true
14180                     )
14181                 ){
14182                     this.select(0, true);
14183                 }
14184             }else{
14185                 if(this.autoFocus){
14186                     this.selectNext();
14187                 }
14188                 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
14189                     this.taTask.delay(this.typeAheadDelay);
14190                 }
14191             }
14192         }else{
14193             this.onEmptyResults();
14194         }
14195         
14196         //this.el.focus();
14197     },
14198     // private
14199     onLoadException : function()
14200     {
14201         this.hasQuery = false;
14202         
14203         if(typeof(this.loading) !== 'undefined' && this.loading !== null){
14204             this.loading.hide();
14205         }
14206         
14207         if(this.tickable && this.editable){
14208             return;
14209         }
14210         
14211         this.collapse();
14212         // only causes errors at present
14213         //Roo.log(this.store.reader.jsonData);
14214         //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
14215             // fixme
14216             //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
14217         //}
14218         
14219         
14220     },
14221     // private
14222     onTypeAhead : function(){
14223         if(this.store.getCount() > 0){
14224             var r = this.store.getAt(0);
14225             var newValue = r.data[this.displayField];
14226             var len = newValue.length;
14227             var selStart = this.getRawValue().length;
14228             
14229             if(selStart != len){
14230                 this.setRawValue(newValue);
14231                 this.selectText(selStart, newValue.length);
14232             }
14233         }
14234     },
14235
14236     // private
14237     onSelect : function(record, index){
14238         
14239         if(this.fireEvent('beforeselect', this, record, index) !== false){
14240         
14241             this.setFromData(index > -1 ? record.data : false);
14242             
14243             this.collapse();
14244             this.fireEvent('select', this, record, index);
14245         }
14246     },
14247
14248     /**
14249      * Returns the currently selected field value or empty string if no value is set.
14250      * @return {String} value The selected value
14251      */
14252     getValue : function()
14253     {
14254         if(Roo.isIOS && this.useNativeIOS){
14255             return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
14256         }
14257         
14258         if(this.multiple){
14259             return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
14260         }
14261         
14262         if(this.valueField){
14263             return typeof this.value != 'undefined' ? this.value : '';
14264         }else{
14265             return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
14266         }
14267     },
14268     
14269     getRawValue : function()
14270     {
14271         if(Roo.isIOS && this.useNativeIOS){
14272             return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
14273         }
14274         
14275         var v = this.inputEl().getValue();
14276         
14277         return v;
14278     },
14279
14280     /**
14281      * Clears any text/value currently set in the field
14282      */
14283     clearValue : function(){
14284         
14285         if(this.hiddenField){
14286             this.hiddenField.dom.value = '';
14287         }
14288         this.value = '';
14289         this.setRawValue('');
14290         this.lastSelectionText = '';
14291         this.lastData = false;
14292         
14293         var close = this.closeTriggerEl();
14294         
14295         if(close){
14296             close.hide();
14297         }
14298         
14299         this.validate();
14300         
14301     },
14302
14303     /**
14304      * Sets the specified value into the field.  If the value finds a match, the corresponding record text
14305      * will be displayed in the field.  If the value does not match the data value of an existing item,
14306      * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
14307      * Otherwise the field will be blank (although the value will still be set).
14308      * @param {String} value The value to match
14309      */
14310     setValue : function(v)
14311     {
14312         if(Roo.isIOS && this.useNativeIOS){
14313             this.setIOSValue(v);
14314             return;
14315         }
14316         
14317         if(this.multiple){
14318             this.syncValue();
14319             return;
14320         }
14321         
14322         var text = v;
14323         if(this.valueField){
14324             var r = this.findRecord(this.valueField, v);
14325             if(r){
14326                 text = r.data[this.displayField];
14327             }else if(this.valueNotFoundText !== undefined){
14328                 text = this.valueNotFoundText;
14329             }
14330         }
14331         this.lastSelectionText = text;
14332         if(this.hiddenField){
14333             this.hiddenField.dom.value = v;
14334         }
14335         Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
14336         this.value = v;
14337         
14338         var close = this.closeTriggerEl();
14339         
14340         if(close){
14341             (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
14342         }
14343         
14344         this.validate();
14345     },
14346     /**
14347      * @property {Object} the last set data for the element
14348      */
14349     
14350     lastData : false,
14351     /**
14352      * Sets the value of the field based on a object which is related to the record format for the store.
14353      * @param {Object} value the value to set as. or false on reset?
14354      */
14355     setFromData : function(o){
14356         
14357         if(this.multiple){
14358             this.addItem(o);
14359             return;
14360         }
14361             
14362         var dv = ''; // display value
14363         var vv = ''; // value value..
14364         this.lastData = o;
14365         if (this.displayField) {
14366             dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14367         } else {
14368             // this is an error condition!!!
14369             Roo.log('no  displayField value set for '+ (this.name ? this.name : this.id));
14370         }
14371         
14372         if(this.valueField){
14373             vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
14374         }
14375         
14376         var close = this.closeTriggerEl();
14377         
14378         if(close){
14379             if(dv.length || vv * 1 > 0){
14380                 close.show() ;
14381                 this.blockFocus=true;
14382             } else {
14383                 close.hide();
14384             }             
14385         }
14386         
14387         if(this.hiddenField){
14388             this.hiddenField.dom.value = vv;
14389             
14390             this.lastSelectionText = dv;
14391             Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14392             this.value = vv;
14393             return;
14394         }
14395         // no hidden field.. - we store the value in 'value', but still display
14396         // display field!!!!
14397         this.lastSelectionText = dv;
14398         Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14399         this.value = vv;
14400         
14401         
14402         
14403     },
14404     // private
14405     reset : function(){
14406         // overridden so that last data is reset..
14407         
14408         if(this.multiple){
14409             this.clearItem();
14410             return;
14411         }
14412         
14413         this.setValue(this.originalValue);
14414         //this.clearInvalid();
14415         this.lastData = false;
14416         if (this.view) {
14417             this.view.clearSelections();
14418         }
14419         
14420         this.validate();
14421     },
14422     // private
14423     findRecord : function(prop, value){
14424         var record;
14425         if(this.store.getCount() > 0){
14426             this.store.each(function(r){
14427                 if(r.data[prop] == value){
14428                     record = r;
14429                     return false;
14430                 }
14431                 return true;
14432             });
14433         }
14434         return record;
14435     },
14436     
14437     getName: function()
14438     {
14439         // returns hidden if it's set..
14440         if (!this.rendered) {return ''};
14441         return !this.hiddenName && this.inputEl().dom.name  ? this.inputEl().dom.name : (this.hiddenName || '');
14442         
14443     },
14444     // private
14445     onViewMove : function(e, t){
14446         this.inKeyMode = false;
14447     },
14448
14449     // private
14450     onViewOver : function(e, t){
14451         if(this.inKeyMode){ // prevent key nav and mouse over conflicts
14452             return;
14453         }
14454         var item = this.view.findItemFromChild(t);
14455         
14456         if(item){
14457             var index = this.view.indexOf(item);
14458             this.select(index, false);
14459         }
14460     },
14461
14462     // private
14463     onViewClick : function(view, doFocus, el, e)
14464     {
14465         var index = this.view.getSelectedIndexes()[0];
14466         
14467         var r = this.store.getAt(index);
14468         
14469         if(this.tickable){
14470             
14471             if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
14472                 return;
14473             }
14474             
14475             var rm = false;
14476             var _this = this;
14477             
14478             Roo.each(this.tickItems, function(v,k){
14479                 
14480                 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
14481                     Roo.log(v);
14482                     _this.tickItems.splice(k, 1);
14483                     
14484                     if(typeof(e) == 'undefined' && view == false){
14485                         Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
14486                     }
14487                     
14488                     rm = true;
14489                     return;
14490                 }
14491             });
14492             
14493             if(rm){
14494                 return;
14495             }
14496             
14497             if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
14498                 this.tickItems.push(r.data);
14499             }
14500             
14501             if(typeof(e) == 'undefined' && view == false){
14502                 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
14503             }
14504                     
14505             return;
14506         }
14507         
14508         if(r){
14509             this.onSelect(r, index);
14510         }
14511         if(doFocus !== false && !this.blockFocus){
14512             this.inputEl().focus();
14513         }
14514     },
14515
14516     // private
14517     restrictHeight : function(){
14518         //this.innerList.dom.style.height = '';
14519         //var inner = this.innerList.dom;
14520         //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
14521         //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
14522         //this.list.beginUpdate();
14523         //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
14524         this.list.alignTo(this.inputEl(), this.listAlign);
14525         this.list.alignTo(this.inputEl(), this.listAlign);
14526         //this.list.endUpdate();
14527     },
14528
14529     // private
14530     onEmptyResults : function(){
14531         
14532         if(this.tickable && this.editable){
14533             this.hasFocus = false;
14534             this.restrictHeight();
14535             return;
14536         }
14537         
14538         this.collapse();
14539     },
14540
14541     /**
14542      * Returns true if the dropdown list is expanded, else false.
14543      */
14544     isExpanded : function(){
14545         return this.list.isVisible();
14546     },
14547
14548     /**
14549      * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
14550      * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14551      * @param {String} value The data value of the item to select
14552      * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14553      * selected item if it is not currently in view (defaults to true)
14554      * @return {Boolean} True if the value matched an item in the list, else false
14555      */
14556     selectByValue : function(v, scrollIntoView){
14557         if(v !== undefined && v !== null){
14558             var r = this.findRecord(this.valueField || this.displayField, v);
14559             if(r){
14560                 this.select(this.store.indexOf(r), scrollIntoView);
14561                 return true;
14562             }
14563         }
14564         return false;
14565     },
14566
14567     /**
14568      * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
14569      * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14570      * @param {Number} index The zero-based index of the list item to select
14571      * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14572      * selected item if it is not currently in view (defaults to true)
14573      */
14574     select : function(index, scrollIntoView){
14575         this.selectedIndex = index;
14576         this.view.select(index);
14577         if(scrollIntoView !== false){
14578             var el = this.view.getNode(index);
14579             /*
14580              * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
14581              */
14582             if(el){
14583                 this.list.scrollChildIntoView(el, false);
14584             }
14585         }
14586     },
14587
14588     // private
14589     selectNext : function(){
14590         var ct = this.store.getCount();
14591         if(ct > 0){
14592             if(this.selectedIndex == -1){
14593                 this.select(0);
14594             }else if(this.selectedIndex < ct-1){
14595                 this.select(this.selectedIndex+1);
14596             }
14597         }
14598     },
14599
14600     // private
14601     selectPrev : function(){
14602         var ct = this.store.getCount();
14603         if(ct > 0){
14604             if(this.selectedIndex == -1){
14605                 this.select(0);
14606             }else if(this.selectedIndex != 0){
14607                 this.select(this.selectedIndex-1);
14608             }
14609         }
14610     },
14611
14612     // private
14613     onKeyUp : function(e){
14614         if(this.editable !== false && !e.isSpecialKey()){
14615             this.lastKey = e.getKey();
14616             this.dqTask.delay(this.queryDelay);
14617         }
14618     },
14619
14620     // private
14621     validateBlur : function(){
14622         return !this.list || !this.list.isVisible();   
14623     },
14624
14625     // private
14626     initQuery : function(){
14627         
14628         var v = this.getRawValue();
14629         
14630         if(this.tickable && this.editable){
14631             v = this.tickableInputEl().getValue();
14632         }
14633         
14634         this.doQuery(v);
14635     },
14636
14637     // private
14638     doForce : function(){
14639         if(this.inputEl().dom.value.length > 0){
14640             this.inputEl().dom.value =
14641                 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
14642              
14643         }
14644     },
14645
14646     /**
14647      * Execute a query to filter the dropdown list.  Fires the beforequery event prior to performing the
14648      * query allowing the query action to be canceled if needed.
14649      * @param {String} query The SQL query to execute
14650      * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
14651      * in the field than the minimum specified by the minChars config option.  It also clears any filter previously
14652      * saved in the current store (defaults to false)
14653      */
14654     doQuery : function(q, forceAll){
14655         
14656         if(q === undefined || q === null){
14657             q = '';
14658         }
14659         var qe = {
14660             query: q,
14661             forceAll: forceAll,
14662             combo: this,
14663             cancel:false
14664         };
14665         if(this.fireEvent('beforequery', qe)===false || qe.cancel){
14666             return false;
14667         }
14668         q = qe.query;
14669         
14670         forceAll = qe.forceAll;
14671         if(forceAll === true || (q.length >= this.minChars)){
14672             
14673             this.hasQuery = true;
14674             
14675             if(this.lastQuery != q || this.alwaysQuery){
14676                 this.lastQuery = q;
14677                 if(this.mode == 'local'){
14678                     this.selectedIndex = -1;
14679                     if(forceAll){
14680                         this.store.clearFilter();
14681                     }else{
14682                         
14683                         if(this.specialFilter){
14684                             this.fireEvent('specialfilter', this);
14685                             this.onLoad();
14686                             return;
14687                         }
14688                         
14689                         this.store.filter(this.displayField, q);
14690                     }
14691                     
14692                     this.store.fireEvent("datachanged", this.store);
14693                     
14694                     this.onLoad();
14695                     
14696                     
14697                 }else{
14698                     
14699                     this.store.baseParams[this.queryParam] = q;
14700                     
14701                     var options = {params : this.getParams(q)};
14702                     
14703                     if(this.loadNext){
14704                         options.add = true;
14705                         options.params.start = this.page * this.pageSize;
14706                     }
14707                     
14708                     this.store.load(options);
14709                     
14710                     /*
14711                      *  this code will make the page width larger, at the beginning, the list not align correctly, 
14712                      *  we should expand the list on onLoad
14713                      *  so command out it
14714                      */
14715 //                    this.expand();
14716                 }
14717             }else{
14718                 this.selectedIndex = -1;
14719                 this.onLoad();   
14720             }
14721         }
14722         
14723         this.loadNext = false;
14724     },
14725     
14726     // private
14727     getParams : function(q){
14728         var p = {};
14729         //p[this.queryParam] = q;
14730         
14731         if(this.pageSize){
14732             p.start = 0;
14733             p.limit = this.pageSize;
14734         }
14735         return p;
14736     },
14737
14738     /**
14739      * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14740      */
14741     collapse : function(){
14742         if(!this.isExpanded()){
14743             return;
14744         }
14745         
14746         this.list.hide();
14747         
14748         this.hasFocus = false;
14749         
14750         if(this.tickable){
14751             this.okBtn.hide();
14752             this.cancelBtn.hide();
14753             this.trigger.show();
14754             
14755             if(this.editable){
14756                 this.tickableInputEl().dom.value = '';
14757                 this.tickableInputEl().blur();
14758             }
14759             
14760         }
14761         
14762         Roo.get(document).un('mousedown', this.collapseIf, this);
14763         Roo.get(document).un('mousewheel', this.collapseIf, this);
14764         if (!this.editable) {
14765             Roo.get(document).un('keydown', this.listKeyPress, this);
14766         }
14767         this.fireEvent('collapse', this);
14768         
14769         this.validate();
14770     },
14771
14772     // private
14773     collapseIf : function(e){
14774         var in_combo  = e.within(this.el);
14775         var in_list =  e.within(this.list);
14776         var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14777         
14778         if (in_combo || in_list || is_list) {
14779             //e.stopPropagation();
14780             return;
14781         }
14782         
14783         if(this.tickable){
14784             this.onTickableFooterButtonClick(e, false, false);
14785         }
14786
14787         this.collapse();
14788         
14789     },
14790
14791     /**
14792      * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14793      */
14794     expand : function(){
14795        
14796         if(this.isExpanded() || !this.hasFocus){
14797             return;
14798         }
14799         
14800         var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14801         this.list.setWidth(lw);
14802         
14803         Roo.log('expand');
14804         
14805         this.list.show();
14806         
14807         this.restrictHeight();
14808         
14809         if(this.tickable){
14810             
14811             this.tickItems = Roo.apply([], this.item);
14812             
14813             this.okBtn.show();
14814             this.cancelBtn.show();
14815             this.trigger.hide();
14816             
14817             if(this.editable){
14818                 this.tickableInputEl().focus();
14819             }
14820             
14821         }
14822         
14823         Roo.get(document).on('mousedown', this.collapseIf, this);
14824         Roo.get(document).on('mousewheel', this.collapseIf, this);
14825         if (!this.editable) {
14826             Roo.get(document).on('keydown', this.listKeyPress, this);
14827         }
14828         
14829         this.fireEvent('expand', this);
14830     },
14831
14832     // private
14833     // Implements the default empty TriggerField.onTriggerClick function
14834     onTriggerClick : function(e)
14835     {
14836         Roo.log('trigger click');
14837         
14838         if(this.disabled || !this.triggerList){
14839             return;
14840         }
14841         
14842         this.page = 0;
14843         this.loadNext = false;
14844         
14845         if(this.isExpanded()){
14846             this.collapse();
14847             if (!this.blockFocus) {
14848                 this.inputEl().focus();
14849             }
14850             
14851         }else {
14852             this.hasFocus = true;
14853             if(this.triggerAction == 'all') {
14854                 this.doQuery(this.allQuery, true);
14855             } else {
14856                 this.doQuery(this.getRawValue());
14857             }
14858             if (!this.blockFocus) {
14859                 this.inputEl().focus();
14860             }
14861         }
14862     },
14863     
14864     onTickableTriggerClick : function(e)
14865     {
14866         if(this.disabled){
14867             return;
14868         }
14869         
14870         this.page = 0;
14871         this.loadNext = false;
14872         this.hasFocus = true;
14873         
14874         if(this.triggerAction == 'all') {
14875             this.doQuery(this.allQuery, true);
14876         } else {
14877             this.doQuery(this.getRawValue());
14878         }
14879     },
14880     
14881     onSearchFieldClick : function(e)
14882     {
14883         if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14884             this.onTickableFooterButtonClick(e, false, false);
14885             return;
14886         }
14887         
14888         if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14889             return;
14890         }
14891         
14892         this.page = 0;
14893         this.loadNext = false;
14894         this.hasFocus = true;
14895         
14896         if(this.triggerAction == 'all') {
14897             this.doQuery(this.allQuery, true);
14898         } else {
14899             this.doQuery(this.getRawValue());
14900         }
14901     },
14902     
14903     listKeyPress : function(e)
14904     {
14905         //Roo.log('listkeypress');
14906         // scroll to first matching element based on key pres..
14907         if (e.isSpecialKey()) {
14908             return false;
14909         }
14910         var k = String.fromCharCode(e.getKey()).toUpperCase();
14911         //Roo.log(k);
14912         var match  = false;
14913         var csel = this.view.getSelectedNodes();
14914         var cselitem = false;
14915         if (csel.length) {
14916             var ix = this.view.indexOf(csel[0]);
14917             cselitem  = this.store.getAt(ix);
14918             if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14919                 cselitem = false;
14920             }
14921             
14922         }
14923         
14924         this.store.each(function(v) { 
14925             if (cselitem) {
14926                 // start at existing selection.
14927                 if (cselitem.id == v.id) {
14928                     cselitem = false;
14929                 }
14930                 return true;
14931             }
14932                 
14933             if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14934                 match = this.store.indexOf(v);
14935                 return false;
14936             }
14937             return true;
14938         }, this);
14939         
14940         if (match === false) {
14941             return true; // no more action?
14942         }
14943         // scroll to?
14944         this.view.select(match);
14945         var sn = Roo.get(this.view.getSelectedNodes()[0]);
14946         sn.scrollIntoView(sn.dom.parentNode, false);
14947     },
14948     
14949     onViewScroll : function(e, t){
14950         
14951         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){
14952             return;
14953         }
14954         
14955         this.hasQuery = true;
14956         
14957         this.loading = this.list.select('.loading', true).first();
14958         
14959         if(this.loading === null){
14960             this.list.createChild({
14961                 tag: 'div',
14962                 cls: 'loading roo-select2-more-results roo-select2-active',
14963                 html: 'Loading more results...'
14964             });
14965             
14966             this.loading = this.list.select('.loading', true).first();
14967             
14968             this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14969             
14970             this.loading.hide();
14971         }
14972         
14973         this.loading.show();
14974         
14975         var _combo = this;
14976         
14977         this.page++;
14978         this.loadNext = true;
14979         
14980         (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14981         
14982         return;
14983     },
14984     
14985     addItem : function(o)
14986     {   
14987         var dv = ''; // display value
14988         
14989         if (this.displayField) {
14990             dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14991         } else {
14992             // this is an error condition!!!
14993             Roo.log('no  displayField value set for '+ (this.name ? this.name : this.id));
14994         }
14995         
14996         if(!dv.length){
14997             return;
14998         }
14999         
15000         var choice = this.choices.createChild({
15001             tag: 'li',
15002             cls: 'roo-select2-search-choice',
15003             cn: [
15004                 {
15005                     tag: 'div',
15006                     html: dv
15007                 },
15008                 {
15009                     tag: 'a',
15010                     href: '#',
15011                     cls: 'roo-select2-search-choice-close fa fa-times',
15012                     tabindex: '-1'
15013                 }
15014             ]
15015             
15016         }, this.searchField);
15017         
15018         var close = choice.select('a.roo-select2-search-choice-close', true).first();
15019         
15020         close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
15021         
15022         this.item.push(o);
15023         
15024         this.lastData = o;
15025         
15026         this.syncValue();
15027         
15028         this.inputEl().dom.value = '';
15029         
15030         this.validate();
15031     },
15032     
15033     onRemoveItem : function(e, _self, o)
15034     {
15035         e.preventDefault();
15036         
15037         this.lastItem = Roo.apply([], this.item);
15038         
15039         var index = this.item.indexOf(o.data) * 1;
15040         
15041         if( index < 0){
15042             Roo.log('not this item?!');
15043             return;
15044         }
15045         
15046         this.item.splice(index, 1);
15047         o.item.remove();
15048         
15049         this.syncValue();
15050         
15051         this.fireEvent('remove', this, e);
15052         
15053         this.validate();
15054         
15055     },
15056     
15057     syncValue : function()
15058     {
15059         if(!this.item.length){
15060             this.clearValue();
15061             return;
15062         }
15063             
15064         var value = [];
15065         var _this = this;
15066         Roo.each(this.item, function(i){
15067             if(_this.valueField){
15068                 value.push(i[_this.valueField]);
15069                 return;
15070             }
15071
15072             value.push(i);
15073         });
15074
15075         this.value = value.join(',');
15076
15077         if(this.hiddenField){
15078             this.hiddenField.dom.value = this.value;
15079         }
15080         
15081         this.store.fireEvent("datachanged", this.store);
15082         
15083         this.validate();
15084     },
15085     
15086     clearItem : function()
15087     {
15088         if(!this.multiple){
15089             return;
15090         }
15091         
15092         this.item = [];
15093         
15094         Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
15095            c.remove();
15096         });
15097         
15098         this.syncValue();
15099         
15100         this.validate();
15101         
15102         if(this.tickable && !Roo.isTouch){
15103             this.view.refresh();
15104         }
15105     },
15106     
15107     inputEl: function ()
15108     {
15109         if(Roo.isIOS && this.useNativeIOS){
15110             return this.el.select('select.roo-ios-select', true).first();
15111         }
15112         
15113         if(Roo.isTouch && this.mobileTouchView){
15114             return this.el.select('input.form-control',true).first();
15115         }
15116         
15117         if(this.tickable){
15118             return this.searchField;
15119         }
15120         
15121         return this.el.select('input.form-control',true).first();
15122     },
15123     
15124     onTickableFooterButtonClick : function(e, btn, el)
15125     {
15126         e.preventDefault();
15127         
15128         this.lastItem = Roo.apply([], this.item);
15129         
15130         if(btn && btn.name == 'cancel'){
15131             this.tickItems = Roo.apply([], this.item);
15132             this.collapse();
15133             return;
15134         }
15135         
15136         this.clearItem();
15137         
15138         var _this = this;
15139         
15140         Roo.each(this.tickItems, function(o){
15141             _this.addItem(o);
15142         });
15143         
15144         this.collapse();
15145         
15146     },
15147     
15148     validate : function()
15149     {
15150         if(this.getVisibilityEl().hasClass('hidden')){
15151             return true;
15152         }
15153         
15154         var v = this.getRawValue();
15155         
15156         if(this.multiple){
15157             v = this.getValue();
15158         }
15159         
15160         if(this.disabled || this.allowBlank || v.length){
15161             this.markValid();
15162             return true;
15163         }
15164         
15165         this.markInvalid();
15166         return false;
15167     },
15168     
15169     tickableInputEl : function()
15170     {
15171         if(!this.tickable || !this.editable){
15172             return this.inputEl();
15173         }
15174         
15175         return this.inputEl().select('.roo-select2-search-field-input', true).first();
15176     },
15177     
15178     
15179     getAutoCreateTouchView : function()
15180     {
15181         var id = Roo.id();
15182         
15183         var cfg = {
15184             cls: 'form-group' //input-group
15185         };
15186         
15187         var input =  {
15188             tag: 'input',
15189             id : id,
15190             type : this.inputType,
15191             cls : 'form-control x-combo-noedit',
15192             autocomplete: 'new-password',
15193             placeholder : this.placeholder || '',
15194             readonly : true
15195         };
15196         
15197         if (this.name) {
15198             input.name = this.name;
15199         }
15200         
15201         if (this.size) {
15202             input.cls += ' input-' + this.size;
15203         }
15204         
15205         if (this.disabled) {
15206             input.disabled = true;
15207         }
15208         
15209         var inputblock = {
15210             cls : '',
15211             cn : [
15212                 input
15213             ]
15214         };
15215         
15216         if(this.before){
15217             inputblock.cls += ' input-group';
15218             
15219             inputblock.cn.unshift({
15220                 tag :'span',
15221                 cls : 'input-group-addon input-group-prepend input-group-text',
15222                 html : this.before
15223             });
15224         }
15225         
15226         if(this.removable && !this.multiple){
15227             inputblock.cls += ' roo-removable';
15228             
15229             inputblock.cn.push({
15230                 tag: 'button',
15231                 html : 'x',
15232                 cls : 'roo-combo-removable-btn close'
15233             });
15234         }
15235
15236         if(this.hasFeedback && !this.allowBlank){
15237             
15238             inputblock.cls += ' has-feedback';
15239             
15240             inputblock.cn.push({
15241                 tag: 'span',
15242                 cls: 'glyphicon form-control-feedback'
15243             });
15244             
15245         }
15246         
15247         if (this.after) {
15248             
15249             inputblock.cls += (this.before) ? '' : ' input-group';
15250             
15251             inputblock.cn.push({
15252                 tag :'span',
15253                 cls : 'input-group-addon input-group-append input-group-text',
15254                 html : this.after
15255             });
15256         }
15257
15258         
15259         var ibwrap = inputblock;
15260         
15261         if(this.multiple){
15262             ibwrap = {
15263                 tag: 'ul',
15264                 cls: 'roo-select2-choices',
15265                 cn:[
15266                     {
15267                         tag: 'li',
15268                         cls: 'roo-select2-search-field',
15269                         cn: [
15270
15271                             inputblock
15272                         ]
15273                     }
15274                 ]
15275             };
15276         
15277             
15278         }
15279         
15280         var combobox = {
15281             cls: 'roo-select2-container input-group roo-touchview-combobox ',
15282             cn: [
15283                 {
15284                     tag: 'input',
15285                     type : 'hidden',
15286                     cls: 'form-hidden-field'
15287                 },
15288                 ibwrap
15289             ]
15290         };
15291         
15292         if(!this.multiple && this.showToggleBtn){
15293             
15294             var caret = {
15295                         tag: 'span',
15296                         cls: 'caret'
15297             };
15298             
15299             if (this.caret != false) {
15300                 caret = {
15301                      tag: 'i',
15302                      cls: 'fa fa-' + this.caret
15303                 };
15304                 
15305             }
15306             
15307             combobox.cn.push({
15308                 tag :'span',
15309                 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
15310                 cn : [
15311                     caret,
15312                     {
15313                         tag: 'span',
15314                         cls: 'combobox-clear',
15315                         cn  : [
15316                             {
15317                                 tag : 'i',
15318                                 cls: 'icon-remove'
15319                             }
15320                         ]
15321                     }
15322                 ]
15323
15324             })
15325         }
15326         
15327         if(this.multiple){
15328             combobox.cls += ' roo-select2-container-multi';
15329         }
15330         
15331         var align = this.labelAlign || this.parentLabelAlign();
15332         
15333         if (align ==='left' && this.fieldLabel.length) {
15334
15335             cfg.cn = [
15336                 {
15337                    tag : 'i',
15338                    cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15339                    tooltip : 'This field is required'
15340                 },
15341                 {
15342                     tag: 'label',
15343                     cls : 'control-label col-form-label',
15344                     html : this.fieldLabel
15345
15346                 },
15347                 {
15348                     cls : '', 
15349                     cn: [
15350                         combobox
15351                     ]
15352                 }
15353             ];
15354             
15355             var labelCfg = cfg.cn[1];
15356             var contentCfg = cfg.cn[2];
15357             
15358
15359             if(this.indicatorpos == 'right'){
15360                 cfg.cn = [
15361                     {
15362                         tag: 'label',
15363                         'for' :  id,
15364                         cls : 'control-label col-form-label',
15365                         cn : [
15366                             {
15367                                 tag : 'span',
15368                                 html : this.fieldLabel
15369                             },
15370                             {
15371                                 tag : 'i',
15372                                 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15373                                 tooltip : 'This field is required'
15374                             }
15375                         ]
15376                     },
15377                     {
15378                         cls : "",
15379                         cn: [
15380                             combobox
15381                         ]
15382                     }
15383
15384                 ];
15385                 
15386                 labelCfg = cfg.cn[0];
15387                 contentCfg = cfg.cn[1];
15388             }
15389             
15390            
15391             
15392             if(this.labelWidth > 12){
15393                 labelCfg.style = "width: " + this.labelWidth + 'px';
15394             }
15395             
15396             if(this.labelWidth < 13 && this.labelmd == 0){
15397                 this.labelmd = this.labelWidth;
15398             }
15399             
15400             if(this.labellg > 0){
15401                 labelCfg.cls += ' col-lg-' + this.labellg;
15402                 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
15403             }
15404             
15405             if(this.labelmd > 0){
15406                 labelCfg.cls += ' col-md-' + this.labelmd;
15407                 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
15408             }
15409             
15410             if(this.labelsm > 0){
15411                 labelCfg.cls += ' col-sm-' + this.labelsm;
15412                 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
15413             }
15414             
15415             if(this.labelxs > 0){
15416                 labelCfg.cls += ' col-xs-' + this.labelxs;
15417                 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
15418             }
15419                 
15420                 
15421         } else if ( this.fieldLabel.length) {
15422             cfg.cn = [
15423                 {
15424                    tag : 'i',
15425                    cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15426                    tooltip : 'This field is required'
15427                 },
15428                 {
15429                     tag: 'label',
15430                     cls : 'control-label',
15431                     html : this.fieldLabel
15432
15433                 },
15434                 {
15435                     cls : '', 
15436                     cn: [
15437                         combobox
15438                     ]
15439                 }
15440             ];
15441             
15442             if(this.indicatorpos == 'right'){
15443                 cfg.cn = [
15444                     {
15445                         tag: 'label',
15446                         cls : 'control-label',
15447                         html : this.fieldLabel,
15448                         cn : [
15449                             {
15450                                tag : 'i',
15451                                cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15452                                tooltip : 'This field is required'
15453                             }
15454                         ]
15455                     },
15456                     {
15457                         cls : '', 
15458                         cn: [
15459                             combobox
15460                         ]
15461                     }
15462                 ];
15463             }
15464         } else {
15465             cfg.cn = combobox;    
15466         }
15467         
15468         
15469         var settings = this;
15470         
15471         ['xs','sm','md','lg'].map(function(size){
15472             if (settings[size]) {
15473                 cfg.cls += ' col-' + size + '-' + settings[size];
15474             }
15475         });
15476         
15477         return cfg;
15478     },
15479     
15480     initTouchView : function()
15481     {
15482         this.renderTouchView();
15483         
15484         this.touchViewEl.on('scroll', function(){
15485             this.el.dom.scrollTop = 0;
15486         }, this);
15487         
15488         this.originalValue = this.getValue();
15489         
15490         this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
15491         
15492         this.inputEl().on("click", this.showTouchView, this);
15493         if (this.triggerEl) {
15494             this.triggerEl.on("click", this.showTouchView, this);
15495         }
15496         
15497         
15498         this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
15499         this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
15500         
15501         this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
15502         
15503         this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
15504         this.store.on('load', this.onTouchViewLoad, this);
15505         this.store.on('loadexception', this.onTouchViewLoadException, this);
15506         
15507         if(this.hiddenName){
15508             
15509             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
15510             
15511             this.hiddenField.dom.value =
15512                 this.hiddenValue !== undefined ? this.hiddenValue :
15513                 this.value !== undefined ? this.value : '';
15514         
15515             this.el.dom.removeAttribute('name');
15516             this.hiddenField.dom.setAttribute('name', this.hiddenName);
15517         }
15518         
15519         if(this.multiple){
15520             this.choices = this.el.select('ul.roo-select2-choices', true).first();
15521             this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
15522         }
15523         
15524         if(this.removable && !this.multiple){
15525             var close = this.closeTriggerEl();
15526             if(close){
15527                 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
15528                 close.on('click', this.removeBtnClick, this, close);
15529             }
15530         }
15531         /*
15532          * fix the bug in Safari iOS8
15533          */
15534         this.inputEl().on("focus", function(e){
15535             document.activeElement.blur();
15536         }, this);
15537         
15538         this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
15539         
15540         return;
15541         
15542         
15543     },
15544     
15545     renderTouchView : function()
15546     {
15547         this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
15548         this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15549         
15550         this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
15551         this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15552         
15553         this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
15554         this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15555         this.touchViewBodyEl.setStyle('overflow', 'auto');
15556         
15557         this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
15558         this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15559         
15560         this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
15561         this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15562         
15563     },
15564     
15565     showTouchView : function()
15566     {
15567         if(this.disabled){
15568             return;
15569         }
15570         
15571         this.touchViewHeaderEl.hide();
15572
15573         if(this.modalTitle.length){
15574             this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
15575             this.touchViewHeaderEl.show();
15576         }
15577
15578         this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
15579         this.touchViewEl.show();
15580
15581         this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
15582         
15583         //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
15584         //        Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15585
15586         var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15587
15588         if(this.modalTitle.length){
15589             bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15590         }
15591         
15592         this.touchViewBodyEl.setHeight(bodyHeight);
15593
15594         if(this.animate){
15595             var _this = this;
15596             (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
15597         }else{
15598             this.touchViewEl.addClass('in');
15599         }
15600         
15601         if(this._touchViewMask){
15602             Roo.get(document.body).addClass("x-body-masked");
15603             this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true),   Roo.lib.Dom.getViewHeight(true));
15604             this._touchViewMask.setStyle('z-index', 10000);
15605             this._touchViewMask.addClass('show');
15606         }
15607         
15608         this.doTouchViewQuery();
15609         
15610     },
15611     
15612     hideTouchView : function()
15613     {
15614         this.touchViewEl.removeClass('in');
15615
15616         if(this.animate){
15617             var _this = this;
15618             (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
15619         }else{
15620             this.touchViewEl.setStyle('display', 'none');
15621         }
15622         
15623         if(this._touchViewMask){
15624             this._touchViewMask.removeClass('show');
15625             Roo.get(document.body).removeClass("x-body-masked");
15626         }
15627     },
15628     
15629     setTouchViewValue : function()
15630     {
15631         if(this.multiple){
15632             this.clearItem();
15633         
15634             var _this = this;
15635
15636             Roo.each(this.tickItems, function(o){
15637                 this.addItem(o);
15638             }, this);
15639         }
15640         
15641         this.hideTouchView();
15642     },
15643     
15644     doTouchViewQuery : function()
15645     {
15646         var qe = {
15647             query: '',
15648             forceAll: true,
15649             combo: this,
15650             cancel:false
15651         };
15652         
15653         if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
15654             return false;
15655         }
15656         
15657         if(!this.alwaysQuery || this.mode == 'local'){
15658             this.onTouchViewLoad();
15659             return;
15660         }
15661         
15662         this.store.load();
15663     },
15664     
15665     onTouchViewBeforeLoad : function(combo,opts)
15666     {
15667         return;
15668     },
15669
15670     // private
15671     onTouchViewLoad : function()
15672     {
15673         if(this.store.getCount() < 1){
15674             this.onTouchViewEmptyResults();
15675             return;
15676         }
15677         
15678         this.clearTouchView();
15679         
15680         var rawValue = this.getRawValue();
15681         
15682         var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
15683         
15684         this.tickItems = [];
15685         
15686         this.store.data.each(function(d, rowIndex){
15687             var row = this.touchViewListGroup.createChild(template);
15688             
15689             if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15690                 row.addClass(d.data.cls);
15691             }
15692             
15693             if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15694                 var cfg = {
15695                     data : d.data,
15696                     html : d.data[this.displayField]
15697                 };
15698                 
15699                 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15700                     row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15701                 }
15702             }
15703             row.removeClass('selected');
15704             if(!this.multiple && this.valueField &&
15705                     typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15706             {
15707                 // radio buttons..
15708                 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15709                 row.addClass('selected');
15710             }
15711             
15712             if(this.multiple && this.valueField &&
15713                     typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15714             {
15715                 
15716                 // checkboxes...
15717                 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15718                 this.tickItems.push(d.data);
15719             }
15720             
15721             row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15722             
15723         }, this);
15724         
15725         var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15726         
15727         var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15728
15729         if(this.modalTitle.length){
15730             bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15731         }
15732
15733         var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
15734         
15735         if(this.mobile_restrict_height && listHeight < bodyHeight){
15736             this.touchViewBodyEl.setHeight(listHeight);
15737         }
15738         
15739         var _this = this;
15740         
15741         if(firstChecked && listHeight > bodyHeight){
15742             (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15743         }
15744         
15745     },
15746     
15747     onTouchViewLoadException : function()
15748     {
15749         this.hideTouchView();
15750     },
15751     
15752     onTouchViewEmptyResults : function()
15753     {
15754         this.clearTouchView();
15755         
15756         this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15757         
15758         this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15759         
15760     },
15761     
15762     clearTouchView : function()
15763     {
15764         this.touchViewListGroup.dom.innerHTML = '';
15765     },
15766     
15767     onTouchViewClick : function(e, el, o)
15768     {
15769         e.preventDefault();
15770         
15771         var row = o.row;
15772         var rowIndex = o.rowIndex;
15773         
15774         var r = this.store.getAt(rowIndex);
15775         
15776         if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15777             
15778             if(!this.multiple){
15779                 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15780                     c.dom.removeAttribute('checked');
15781                 }, this);
15782
15783                 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15784
15785                 this.setFromData(r.data);
15786
15787                 var close = this.closeTriggerEl();
15788
15789                 if(close){
15790                     close.show();
15791                 }
15792
15793                 this.hideTouchView();
15794
15795                 this.fireEvent('select', this, r, rowIndex);
15796
15797                 return;
15798             }
15799
15800             if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15801                 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15802                 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15803                 return;
15804             }
15805
15806             row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15807             this.addItem(r.data);
15808             this.tickItems.push(r.data);
15809         }
15810     },
15811     
15812     getAutoCreateNativeIOS : function()
15813     {
15814         var cfg = {
15815             cls: 'form-group' //input-group,
15816         };
15817         
15818         var combobox =  {
15819             tag: 'select',
15820             cls : 'roo-ios-select'
15821         };
15822         
15823         if (this.name) {
15824             combobox.name = this.name;
15825         }
15826         
15827         if (this.disabled) {
15828             combobox.disabled = true;
15829         }
15830         
15831         var settings = this;
15832         
15833         ['xs','sm','md','lg'].map(function(size){
15834             if (settings[size]) {
15835                 cfg.cls += ' col-' + size + '-' + settings[size];
15836             }
15837         });
15838         
15839         cfg.cn = combobox;
15840         
15841         return cfg;
15842         
15843     },
15844     
15845     initIOSView : function()
15846     {
15847         this.store.on('load', this.onIOSViewLoad, this);
15848         
15849         return;
15850     },
15851     
15852     onIOSViewLoad : function()
15853     {
15854         if(this.store.getCount() < 1){
15855             return;
15856         }
15857         
15858         this.clearIOSView();
15859         
15860         if(this.allowBlank) {
15861             
15862             var default_text = '-- SELECT --';
15863             
15864             if(this.placeholder.length){
15865                 default_text = this.placeholder;
15866             }
15867             
15868             if(this.emptyTitle.length){
15869                 default_text += ' - ' + this.emptyTitle + ' -';
15870             }
15871             
15872             var opt = this.inputEl().createChild({
15873                 tag: 'option',
15874                 value : 0,
15875                 html : default_text
15876             });
15877             
15878             var o = {};
15879             o[this.valueField] = 0;
15880             o[this.displayField] = default_text;
15881             
15882             this.ios_options.push({
15883                 data : o,
15884                 el : opt
15885             });
15886             
15887         }
15888         
15889         this.store.data.each(function(d, rowIndex){
15890             
15891             var html = '';
15892             
15893             if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15894                 html = d.data[this.displayField];
15895             }
15896             
15897             var value = '';
15898             
15899             if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15900                 value = d.data[this.valueField];
15901             }
15902             
15903             var option = {
15904                 tag: 'option',
15905                 value : value,
15906                 html : html
15907             };
15908             
15909             if(this.value == d.data[this.valueField]){
15910                 option['selected'] = true;
15911             }
15912             
15913             var opt = this.inputEl().createChild(option);
15914             
15915             this.ios_options.push({
15916                 data : d.data,
15917                 el : opt
15918             });
15919             
15920         }, this);
15921         
15922         this.inputEl().on('change', function(){
15923            this.fireEvent('select', this);
15924         }, this);
15925         
15926     },
15927     
15928     clearIOSView: function()
15929     {
15930         this.inputEl().dom.innerHTML = '';
15931         
15932         this.ios_options = [];
15933     },
15934     
15935     setIOSValue: function(v)
15936     {
15937         this.value = v;
15938         
15939         if(!this.ios_options){
15940             return;
15941         }
15942         
15943         Roo.each(this.ios_options, function(opts){
15944            
15945            opts.el.dom.removeAttribute('selected');
15946            
15947            if(opts.data[this.valueField] != v){
15948                return;
15949            }
15950            
15951            opts.el.dom.setAttribute('selected', true);
15952            
15953         }, this);
15954     }
15955
15956     /** 
15957     * @cfg {Boolean} grow 
15958     * @hide 
15959     */
15960     /** 
15961     * @cfg {Number} growMin 
15962     * @hide 
15963     */
15964     /** 
15965     * @cfg {Number} growMax 
15966     * @hide 
15967     */
15968     /**
15969      * @hide
15970      * @method autoSize
15971      */
15972 });
15973
15974 Roo.apply(Roo.bootstrap.ComboBox,  {
15975     
15976     header : {
15977         tag: 'div',
15978         cls: 'modal-header',
15979         cn: [
15980             {
15981                 tag: 'h4',
15982                 cls: 'modal-title'
15983             }
15984         ]
15985     },
15986     
15987     body : {
15988         tag: 'div',
15989         cls: 'modal-body',
15990         cn: [
15991             {
15992                 tag: 'ul',
15993                 cls: 'list-group'
15994             }
15995         ]
15996     },
15997     
15998     listItemRadio : {
15999         tag: 'li',
16000         cls: 'list-group-item',
16001         cn: [
16002             {
16003                 tag: 'span',
16004                 cls: 'roo-combobox-list-group-item-value'
16005             },
16006             {
16007                 tag: 'div',
16008                 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
16009                 cn: [
16010                     {
16011                         tag: 'input',
16012                         type: 'radio'
16013                     },
16014                     {
16015                         tag: 'label'
16016                     }
16017                 ]
16018             }
16019         ]
16020     },
16021     
16022     listItemCheckbox : {
16023         tag: 'li',
16024         cls: 'list-group-item',
16025         cn: [
16026             {
16027                 tag: 'span',
16028                 cls: 'roo-combobox-list-group-item-value'
16029             },
16030             {
16031                 tag: 'div',
16032                 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
16033                 cn: [
16034                     {
16035                         tag: 'input',
16036                         type: 'checkbox'
16037                     },
16038                     {
16039                         tag: 'label'
16040                     }
16041                 ]
16042             }
16043         ]
16044     },
16045     
16046     emptyResult : {
16047         tag: 'div',
16048         cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
16049     },
16050     
16051     footer : {
16052         tag: 'div',
16053         cls: 'modal-footer',
16054         cn: [
16055             {
16056                 tag: 'div',
16057                 cls: 'row',
16058                 cn: [
16059                     {
16060                         tag: 'div',
16061                         cls: 'col-xs-6 text-left',
16062                         cn: {
16063                             tag: 'button',
16064                             cls: 'btn btn-danger roo-touch-view-cancel',
16065                             html: 'Cancel'
16066                         }
16067                     },
16068                     {
16069                         tag: 'div',
16070                         cls: 'col-xs-6 text-right',
16071                         cn: {
16072                             tag: 'button',
16073                             cls: 'btn btn-success roo-touch-view-ok',
16074                             html: 'OK'
16075                         }
16076                     }
16077                 ]
16078             }
16079         ]
16080         
16081     }
16082 });
16083
16084 Roo.apply(Roo.bootstrap.ComboBox,  {
16085     
16086     touchViewTemplate : {
16087         tag: 'div',
16088         cls: 'modal fade roo-combobox-touch-view',
16089         cn: [
16090             {
16091                 tag: 'div',
16092                 cls: 'modal-dialog',
16093                 style : 'position:fixed', // we have to fix position....
16094                 cn: [
16095                     {
16096                         tag: 'div',
16097                         cls: 'modal-content',
16098                         cn: [
16099                             Roo.bootstrap.ComboBox.header,
16100                             Roo.bootstrap.ComboBox.body,
16101                             Roo.bootstrap.ComboBox.footer
16102                         ]
16103                     }
16104                 ]
16105             }
16106         ]
16107     }
16108 });/*
16109  * Based on:
16110  * Ext JS Library 1.1.1
16111  * Copyright(c) 2006-2007, Ext JS, LLC.
16112  *
16113  * Originally Released Under LGPL - original licence link has changed is not relivant.
16114  *
16115  * Fork - LGPL
16116  * <script type="text/javascript">
16117  */
16118
16119 /**
16120  * @class Roo.View
16121  * @extends Roo.util.Observable
16122  * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template. 
16123  * This class also supports single and multi selection modes. <br>
16124  * Create a data model bound view:
16125  <pre><code>
16126  var store = new Roo.data.Store(...);
16127
16128  var view = new Roo.View({
16129     el : "my-element",
16130     tpl : '&lt;div id="{0}"&gt;{2} - {1}&lt;/div&gt;', // auto create template
16131  
16132     singleSelect: true,
16133     selectedClass: "ydataview-selected",
16134     store: store
16135  });
16136
16137  // listen for node click?
16138  view.on("click", function(vw, index, node, e){
16139  alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
16140  });
16141
16142  // load XML data
16143  dataModel.load("foobar.xml");
16144  </code></pre>
16145  For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
16146  * <br><br>
16147  * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
16148  * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
16149  * 
16150  * Note: old style constructor is still suported (container, template, config)
16151  * 
16152  * @constructor
16153  * Create a new View
16154  * @param {Object} config The config object
16155  * 
16156  */
16157 Roo.View = function(config, depreciated_tpl, depreciated_config){
16158     
16159     this.parent = false;
16160     
16161     if (typeof(depreciated_tpl) == 'undefined') {
16162         // new way.. - universal constructor.
16163         Roo.apply(this, config);
16164         this.el  = Roo.get(this.el);
16165     } else {
16166         // old format..
16167         this.el  = Roo.get(config);
16168         this.tpl = depreciated_tpl;
16169         Roo.apply(this, depreciated_config);
16170     }
16171     this.wrapEl  = this.el.wrap().wrap();
16172     ///this.el = this.wrapEla.appendChild(document.createElement("div"));
16173     
16174     
16175     if(typeof(this.tpl) == "string"){
16176         this.tpl = new Roo.Template(this.tpl);
16177     } else {
16178         // support xtype ctors..
16179         this.tpl = new Roo.factory(this.tpl, Roo);
16180     }
16181     
16182     
16183     this.tpl.compile();
16184     
16185     /** @private */
16186     this.addEvents({
16187         /**
16188          * @event beforeclick
16189          * Fires before a click is processed. Returns false to cancel the default action.
16190          * @param {Roo.View} this
16191          * @param {Number} index The index of the target node
16192          * @param {HTMLElement} node The target node
16193          * @param {Roo.EventObject} e The raw event object
16194          */
16195             "beforeclick" : true,
16196         /**
16197          * @event click
16198          * Fires when a template node is clicked.
16199          * @param {Roo.View} this
16200          * @param {Number} index The index of the target node
16201          * @param {HTMLElement} node The target node
16202          * @param {Roo.EventObject} e The raw event object
16203          */
16204             "click" : true,
16205         /**
16206          * @event dblclick
16207          * Fires when a template node is double clicked.
16208          * @param {Roo.View} this
16209          * @param {Number} index The index of the target node
16210          * @param {HTMLElement} node The target node
16211          * @param {Roo.EventObject} e The raw event object
16212          */
16213             "dblclick" : true,
16214         /**
16215          * @event contextmenu
16216          * Fires when a template node is right clicked.
16217          * @param {Roo.View} this
16218          * @param {Number} index The index of the target node
16219          * @param {HTMLElement} node The target node
16220          * @param {Roo.EventObject} e The raw event object
16221          */
16222             "contextmenu" : true,
16223         /**
16224          * @event selectionchange
16225          * Fires when the selected nodes change.
16226          * @param {Roo.View} this
16227          * @param {Array} selections Array of the selected nodes
16228          */
16229             "selectionchange" : true,
16230     
16231         /**
16232          * @event beforeselect
16233          * Fires before a selection is made. If any handlers return false, the selection is cancelled.
16234          * @param {Roo.View} this
16235          * @param {HTMLElement} node The node to be selected
16236          * @param {Array} selections Array of currently selected nodes
16237          */
16238             "beforeselect" : true,
16239         /**
16240          * @event preparedata
16241          * Fires on every row to render, to allow you to change the data.
16242          * @param {Roo.View} this
16243          * @param {Object} data to be rendered (change this)
16244          */
16245           "preparedata" : true
16246           
16247           
16248         });
16249
16250
16251
16252     this.el.on({
16253         "click": this.onClick,
16254         "dblclick": this.onDblClick,
16255         "contextmenu": this.onContextMenu,
16256         scope:this
16257     });
16258
16259     this.selections = [];
16260     this.nodes = [];
16261     this.cmp = new Roo.CompositeElementLite([]);
16262     if(this.store){
16263         this.store = Roo.factory(this.store, Roo.data);
16264         this.setStore(this.store, true);
16265     }
16266     
16267     if ( this.footer && this.footer.xtype) {
16268            
16269          var fctr = this.wrapEl.appendChild(document.createElement("div"));
16270         
16271         this.footer.dataSource = this.store;
16272         this.footer.container = fctr;
16273         this.footer = Roo.factory(this.footer, Roo);
16274         fctr.insertFirst(this.el);
16275         
16276         // this is a bit insane - as the paging toolbar seems to detach the el..
16277 //        dom.parentNode.parentNode.parentNode
16278          // they get detached?
16279     }
16280     
16281     
16282     Roo.View.superclass.constructor.call(this);
16283     
16284     
16285 };
16286
16287 Roo.extend(Roo.View, Roo.util.Observable, {
16288     
16289      /**
16290      * @cfg {Roo.data.Store} store Data store to load data from.
16291      */
16292     store : false,
16293     
16294     /**
16295      * @cfg {String|Roo.Element} el The container element.
16296      */
16297     el : '',
16298     
16299     /**
16300      * @cfg {String|Roo.Template} tpl The template used by this View 
16301      */
16302     tpl : false,
16303     /**
16304      * @cfg {String} dataName the named area of the template to use as the data area
16305      *                          Works with domtemplates roo-name="name"
16306      */
16307     dataName: false,
16308     /**
16309      * @cfg {String} selectedClass The css class to add to selected nodes
16310      */
16311     selectedClass : "x-view-selected",
16312      /**
16313      * @cfg {String} emptyText The empty text to show when nothing is loaded.
16314      */
16315     emptyText : "",
16316     
16317     /**
16318      * @cfg {String} text to display on mask (default Loading)
16319      */
16320     mask : false,
16321     /**
16322      * @cfg {Boolean} multiSelect Allow multiple selection
16323      */
16324     multiSelect : false,
16325     /**
16326      * @cfg {Boolean} singleSelect Allow single selection
16327      */
16328     singleSelect:  false,
16329     
16330     /**
16331      * @cfg {Boolean} toggleSelect - selecting 
16332      */
16333     toggleSelect : false,
16334     
16335     /**
16336      * @cfg {Boolean} tickable - selecting 
16337      */
16338     tickable : false,
16339     
16340     /**
16341      * Returns the element this view is bound to.
16342      * @return {Roo.Element}
16343      */
16344     getEl : function(){
16345         return this.wrapEl;
16346     },
16347     
16348     
16349
16350     /**
16351      * Refreshes the view. - called by datachanged on the store. - do not call directly.
16352      */
16353     refresh : function(){
16354         //Roo.log('refresh');
16355         var t = this.tpl;
16356         
16357         // if we are using something like 'domtemplate', then
16358         // the what gets used is:
16359         // t.applySubtemplate(NAME, data, wrapping data..)
16360         // the outer template then get' applied with
16361         //     the store 'extra data'
16362         // and the body get's added to the
16363         //      roo-name="data" node?
16364         //      <span class='roo-tpl-{name}'></span> ?????
16365         
16366         
16367         
16368         this.clearSelections();
16369         this.el.update("");
16370         var html = [];
16371         var records = this.store.getRange();
16372         if(records.length < 1) {
16373             
16374             // is this valid??  = should it render a template??
16375             
16376             this.el.update(this.emptyText);
16377             return;
16378         }
16379         var el = this.el;
16380         if (this.dataName) {
16381             this.el.update(t.apply(this.store.meta)); //????
16382             el = this.el.child('.roo-tpl-' + this.dataName);
16383         }
16384         
16385         for(var i = 0, len = records.length; i < len; i++){
16386             var data = this.prepareData(records[i].data, i, records[i]);
16387             this.fireEvent("preparedata", this, data, i, records[i]);
16388             
16389             var d = Roo.apply({}, data);
16390             
16391             if(this.tickable){
16392                 Roo.apply(d, {'roo-id' : Roo.id()});
16393                 
16394                 var _this = this;
16395             
16396                 Roo.each(this.parent.item, function(item){
16397                     if(item[_this.parent.valueField] != data[_this.parent.valueField]){
16398                         return;
16399                     }
16400                     Roo.apply(d, {'roo-data-checked' : 'checked'});
16401                 });
16402             }
16403             
16404             html[html.length] = Roo.util.Format.trim(
16405                 this.dataName ?
16406                     t.applySubtemplate(this.dataName, d, this.store.meta) :
16407                     t.apply(d)
16408             );
16409         }
16410         
16411         
16412         
16413         el.update(html.join(""));
16414         this.nodes = el.dom.childNodes;
16415         this.updateIndexes(0);
16416     },
16417     
16418
16419     /**
16420      * Function to override to reformat the data that is sent to
16421      * the template for each node.
16422      * DEPRICATED - use the preparedata event handler.
16423      * @param {Array/Object} data The raw data (array of colData for a data model bound view or
16424      * a JSON object for an UpdateManager bound view).
16425      */
16426     prepareData : function(data, index, record)
16427     {
16428         this.fireEvent("preparedata", this, data, index, record);
16429         return data;
16430     },
16431
16432     onUpdate : function(ds, record){
16433         // Roo.log('on update');   
16434         this.clearSelections();
16435         var index = this.store.indexOf(record);
16436         var n = this.nodes[index];
16437         this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
16438         n.parentNode.removeChild(n);
16439         this.updateIndexes(index, index);
16440     },
16441
16442     
16443     
16444 // --------- FIXME     
16445     onAdd : function(ds, records, index)
16446     {
16447         //Roo.log(['on Add', ds, records, index] );        
16448         this.clearSelections();
16449         if(this.nodes.length == 0){
16450             this.refresh();
16451             return;
16452         }
16453         var n = this.nodes[index];
16454         for(var i = 0, len = records.length; i < len; i++){
16455             var d = this.prepareData(records[i].data, i, records[i]);
16456             if(n){
16457                 this.tpl.insertBefore(n, d);
16458             }else{
16459                 
16460                 this.tpl.append(this.el, d);
16461             }
16462         }
16463         this.updateIndexes(index);
16464     },
16465
16466     onRemove : function(ds, record, index){
16467        // Roo.log('onRemove');
16468         this.clearSelections();
16469         var el = this.dataName  ?
16470             this.el.child('.roo-tpl-' + this.dataName) :
16471             this.el; 
16472         
16473         el.dom.removeChild(this.nodes[index]);
16474         this.updateIndexes(index);
16475     },
16476
16477     /**
16478      * Refresh an individual node.
16479      * @param {Number} index
16480      */
16481     refreshNode : function(index){
16482         this.onUpdate(this.store, this.store.getAt(index));
16483     },
16484
16485     updateIndexes : function(startIndex, endIndex){
16486         var ns = this.nodes;
16487         startIndex = startIndex || 0;
16488         endIndex = endIndex || ns.length - 1;
16489         for(var i = startIndex; i <= endIndex; i++){
16490             ns[i].nodeIndex = i;
16491         }
16492     },
16493
16494     /**
16495      * Changes the data store this view uses and refresh the view.
16496      * @param {Store} store
16497      */
16498     setStore : function(store, initial){
16499         if(!initial && this.store){
16500             this.store.un("datachanged", this.refresh);
16501             this.store.un("add", this.onAdd);
16502             this.store.un("remove", this.onRemove);
16503             this.store.un("update", this.onUpdate);
16504             this.store.un("clear", this.refresh);
16505             this.store.un("beforeload", this.onBeforeLoad);
16506             this.store.un("load", this.onLoad);
16507             this.store.un("loadexception", this.onLoad);
16508         }
16509         if(store){
16510           
16511             store.on("datachanged", this.refresh, this);
16512             store.on("add", this.onAdd, this);
16513             store.on("remove", this.onRemove, this);
16514             store.on("update", this.onUpdate, this);
16515             store.on("clear", this.refresh, this);
16516             store.on("beforeload", this.onBeforeLoad, this);
16517             store.on("load", this.onLoad, this);
16518             store.on("loadexception", this.onLoad, this);
16519         }
16520         
16521         if(store){
16522             this.refresh();
16523         }
16524     },
16525     /**
16526      * onbeforeLoad - masks the loading area.
16527      *
16528      */
16529     onBeforeLoad : function(store,opts)
16530     {
16531          //Roo.log('onBeforeLoad');   
16532         if (!opts.add) {
16533             this.el.update("");
16534         }
16535         this.el.mask(this.mask ? this.mask : "Loading" ); 
16536     },
16537     onLoad : function ()
16538     {
16539         this.el.unmask();
16540     },
16541     
16542
16543     /**
16544      * Returns the template node the passed child belongs to or null if it doesn't belong to one.
16545      * @param {HTMLElement} node
16546      * @return {HTMLElement} The template node
16547      */
16548     findItemFromChild : function(node){
16549         var el = this.dataName  ?
16550             this.el.child('.roo-tpl-' + this.dataName,true) :
16551             this.el.dom; 
16552         
16553         if(!node || node.parentNode == el){
16554                     return node;
16555             }
16556             var p = node.parentNode;
16557             while(p && p != el){
16558             if(p.parentNode == el){
16559                 return p;
16560             }
16561             p = p.parentNode;
16562         }
16563             return null;
16564     },
16565
16566     /** @ignore */
16567     onClick : function(e){
16568         var item = this.findItemFromChild(e.getTarget());
16569         if(item){
16570             var index = this.indexOf(item);
16571             if(this.onItemClick(item, index, e) !== false){
16572                 this.fireEvent("click", this, index, item, e);
16573             }
16574         }else{
16575             this.clearSelections();
16576         }
16577     },
16578
16579     /** @ignore */
16580     onContextMenu : function(e){
16581         var item = this.findItemFromChild(e.getTarget());
16582         if(item){
16583             this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
16584         }
16585     },
16586
16587     /** @ignore */
16588     onDblClick : function(e){
16589         var item = this.findItemFromChild(e.getTarget());
16590         if(item){
16591             this.fireEvent("dblclick", this, this.indexOf(item), item, e);
16592         }
16593     },
16594
16595     onItemClick : function(item, index, e)
16596     {
16597         if(this.fireEvent("beforeclick", this, index, item, e) === false){
16598             return false;
16599         }
16600         if (this.toggleSelect) {
16601             var m = this.isSelected(item) ? 'unselect' : 'select';
16602             //Roo.log(m);
16603             var _t = this;
16604             _t[m](item, true, false);
16605             return true;
16606         }
16607         if(this.multiSelect || this.singleSelect){
16608             if(this.multiSelect && e.shiftKey && this.lastSelection){
16609                 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
16610             }else{
16611                 this.select(item, this.multiSelect && e.ctrlKey);
16612                 this.lastSelection = item;
16613             }
16614             
16615             if(!this.tickable){
16616                 e.preventDefault();
16617             }
16618             
16619         }
16620         return true;
16621     },
16622
16623     /**
16624      * Get the number of selected nodes.
16625      * @return {Number}
16626      */
16627     getSelectionCount : function(){
16628         return this.selections.length;
16629     },
16630
16631     /**
16632      * Get the currently selected nodes.
16633      * @return {Array} An array of HTMLElements
16634      */
16635     getSelectedNodes : function(){
16636         return this.selections;
16637     },
16638
16639     /**
16640      * Get the indexes of the selected nodes.
16641      * @return {Array}
16642      */
16643     getSelectedIndexes : function(){
16644         var indexes = [], s = this.selections;
16645         for(var i = 0, len = s.length; i < len; i++){
16646             indexes.push(s[i].nodeIndex);
16647         }
16648         return indexes;
16649     },
16650
16651     /**
16652      * Clear all selections
16653      * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
16654      */
16655     clearSelections : function(suppressEvent){
16656         if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
16657             this.cmp.elements = this.selections;
16658             this.cmp.removeClass(this.selectedClass);
16659             this.selections = [];
16660             if(!suppressEvent){
16661                 this.fireEvent("selectionchange", this, this.selections);
16662             }
16663         }
16664     },
16665
16666     /**
16667      * Returns true if the passed node is selected
16668      * @param {HTMLElement/Number} node The node or node index
16669      * @return {Boolean}
16670      */
16671     isSelected : function(node){
16672         var s = this.selections;
16673         if(s.length < 1){
16674             return false;
16675         }
16676         node = this.getNode(node);
16677         return s.indexOf(node) !== -1;
16678     },
16679
16680     /**
16681      * Selects nodes.
16682      * @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
16683      * @param {Boolean} keepExisting (optional) true to keep existing selections
16684      * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16685      */
16686     select : function(nodeInfo, keepExisting, suppressEvent){
16687         if(nodeInfo instanceof Array){
16688             if(!keepExisting){
16689                 this.clearSelections(true);
16690             }
16691             for(var i = 0, len = nodeInfo.length; i < len; i++){
16692                 this.select(nodeInfo[i], true, true);
16693             }
16694             return;
16695         } 
16696         var node = this.getNode(nodeInfo);
16697         if(!node || this.isSelected(node)){
16698             return; // already selected.
16699         }
16700         if(!keepExisting){
16701             this.clearSelections(true);
16702         }
16703         
16704         if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16705             Roo.fly(node).addClass(this.selectedClass);
16706             this.selections.push(node);
16707             if(!suppressEvent){
16708                 this.fireEvent("selectionchange", this, this.selections);
16709             }
16710         }
16711         
16712         
16713     },
16714       /**
16715      * Unselects nodes.
16716      * @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
16717      * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16718      * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16719      */
16720     unselect : function(nodeInfo, keepExisting, suppressEvent)
16721     {
16722         if(nodeInfo instanceof Array){
16723             Roo.each(this.selections, function(s) {
16724                 this.unselect(s, nodeInfo);
16725             }, this);
16726             return;
16727         }
16728         var node = this.getNode(nodeInfo);
16729         if(!node || !this.isSelected(node)){
16730             //Roo.log("not selected");
16731             return; // not selected.
16732         }
16733         // fireevent???
16734         var ns = [];
16735         Roo.each(this.selections, function(s) {
16736             if (s == node ) {
16737                 Roo.fly(node).removeClass(this.selectedClass);
16738
16739                 return;
16740             }
16741             ns.push(s);
16742         },this);
16743         
16744         this.selections= ns;
16745         this.fireEvent("selectionchange", this, this.selections);
16746     },
16747
16748     /**
16749      * Gets a template node.
16750      * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16751      * @return {HTMLElement} The node or null if it wasn't found
16752      */
16753     getNode : function(nodeInfo){
16754         if(typeof nodeInfo == "string"){
16755             return document.getElementById(nodeInfo);
16756         }else if(typeof nodeInfo == "number"){
16757             return this.nodes[nodeInfo];
16758         }
16759         return nodeInfo;
16760     },
16761
16762     /**
16763      * Gets a range template nodes.
16764      * @param {Number} startIndex
16765      * @param {Number} endIndex
16766      * @return {Array} An array of nodes
16767      */
16768     getNodes : function(start, end){
16769         var ns = this.nodes;
16770         start = start || 0;
16771         end = typeof end == "undefined" ? ns.length - 1 : end;
16772         var nodes = [];
16773         if(start <= end){
16774             for(var i = start; i <= end; i++){
16775                 nodes.push(ns[i]);
16776             }
16777         } else{
16778             for(var i = start; i >= end; i--){
16779                 nodes.push(ns[i]);
16780             }
16781         }
16782         return nodes;
16783     },
16784
16785     /**
16786      * Finds the index of the passed node
16787      * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16788      * @return {Number} The index of the node or -1
16789      */
16790     indexOf : function(node){
16791         node = this.getNode(node);
16792         if(typeof node.nodeIndex == "number"){
16793             return node.nodeIndex;
16794         }
16795         var ns = this.nodes;
16796         for(var i = 0, len = ns.length; i < len; i++){
16797             if(ns[i] == node){
16798                 return i;
16799             }
16800         }
16801         return -1;
16802     }
16803 });
16804 /*
16805  * - LGPL
16806  *
16807  * based on jquery fullcalendar
16808  * 
16809  */
16810
16811 Roo.bootstrap = Roo.bootstrap || {};
16812 /**
16813  * @class Roo.bootstrap.Calendar
16814  * @extends Roo.bootstrap.Component
16815  * Bootstrap Calendar class
16816  * @cfg {Boolean} loadMask (true|false) default false
16817  * @cfg {Object} header generate the user specific header of the calendar, default false
16818
16819  * @constructor
16820  * Create a new Container
16821  * @param {Object} config The config object
16822  */
16823
16824
16825
16826 Roo.bootstrap.Calendar = function(config){
16827     Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16828      this.addEvents({
16829         /**
16830              * @event select
16831              * Fires when a date is selected
16832              * @param {DatePicker} this
16833              * @param {Date} date The selected date
16834              */
16835         'select': true,
16836         /**
16837              * @event monthchange
16838              * Fires when the displayed month changes 
16839              * @param {DatePicker} this
16840              * @param {Date} date The selected month
16841              */
16842         'monthchange': true,
16843         /**
16844              * @event evententer
16845              * Fires when mouse over an event
16846              * @param {Calendar} this
16847              * @param {event} Event
16848              */
16849         'evententer': true,
16850         /**
16851              * @event eventleave
16852              * Fires when the mouse leaves an
16853              * @param {Calendar} this
16854              * @param {event}
16855              */
16856         'eventleave': true,
16857         /**
16858              * @event eventclick
16859              * Fires when the mouse click an
16860              * @param {Calendar} this
16861              * @param {event}
16862              */
16863         'eventclick': true
16864         
16865     });
16866
16867 };
16868
16869 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component,  {
16870     
16871      /**
16872      * @cfg {Number} startDay
16873      * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16874      */
16875     startDay : 0,
16876     
16877     loadMask : false,
16878     
16879     header : false,
16880       
16881     getAutoCreate : function(){
16882         
16883         
16884         var fc_button = function(name, corner, style, content ) {
16885             return Roo.apply({},{
16886                 tag : 'span',
16887                 cls : 'fc-button fc-button-'+name+' fc-state-default ' + 
16888                          (corner.length ?
16889                             'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16890                             ''
16891                         ),
16892                 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16893                 unselectable: 'on'
16894             });
16895         };
16896         
16897         var header = {};
16898         
16899         if(!this.header){
16900             header = {
16901                 tag : 'table',
16902                 cls : 'fc-header',
16903                 style : 'width:100%',
16904                 cn : [
16905                     {
16906                         tag: 'tr',
16907                         cn : [
16908                             {
16909                                 tag : 'td',
16910                                 cls : 'fc-header-left',
16911                                 cn : [
16912                                     fc_button('prev', 'left', 'arrow', '&#8249;' ),
16913                                     fc_button('next', 'right', 'arrow', '&#8250;' ),
16914                                     { tag: 'span', cls: 'fc-header-space' },
16915                                     fc_button('today', 'left right', '', 'today' )  // neds state disabled..
16916
16917
16918                                 ]
16919                             },
16920
16921                             {
16922                                 tag : 'td',
16923                                 cls : 'fc-header-center',
16924                                 cn : [
16925                                     {
16926                                         tag: 'span',
16927                                         cls: 'fc-header-title',
16928                                         cn : {
16929                                             tag: 'H2',
16930                                             html : 'month / year'
16931                                         }
16932                                     }
16933
16934                                 ]
16935                             },
16936                             {
16937                                 tag : 'td',
16938                                 cls : 'fc-header-right',
16939                                 cn : [
16940                               /*      fc_button('month', 'left', '', 'month' ),
16941                                     fc_button('week', '', '', 'week' ),
16942                                     fc_button('day', 'right', '', 'day' )
16943                                 */    
16944
16945                                 ]
16946                             }
16947
16948                         ]
16949                     }
16950                 ]
16951             };
16952         }
16953         
16954         header = this.header;
16955         
16956        
16957         var cal_heads = function() {
16958             var ret = [];
16959             // fixme - handle this.
16960             
16961             for (var i =0; i < Date.dayNames.length; i++) {
16962                 var d = Date.dayNames[i];
16963                 ret.push({
16964                     tag: 'th',
16965                     cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16966                     html : d.substring(0,3)
16967                 });
16968                 
16969             }
16970             ret[0].cls += ' fc-first';
16971             ret[6].cls += ' fc-last';
16972             return ret;
16973         };
16974         var cal_cell = function(n) {
16975             return  {
16976                 tag: 'td',
16977                 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16978                 cn : [
16979                     {
16980                         cn : [
16981                             {
16982                                 cls: 'fc-day-number',
16983                                 html: 'D'
16984                             },
16985                             {
16986                                 cls: 'fc-day-content',
16987                              
16988                                 cn : [
16989                                      {
16990                                         style: 'position: relative;' // height: 17px;
16991                                     }
16992                                 ]
16993                             }
16994                             
16995                             
16996                         ]
16997                     }
16998                 ]
16999                 
17000             }
17001         };
17002         var cal_rows = function() {
17003             
17004             var ret = [];
17005             for (var r = 0; r < 6; r++) {
17006                 var row= {
17007                     tag : 'tr',
17008                     cls : 'fc-week',
17009                     cn : []
17010                 };
17011                 
17012                 for (var i =0; i < Date.dayNames.length; i++) {
17013                     var d = Date.dayNames[i];
17014                     row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
17015
17016                 }
17017                 row.cn[0].cls+=' fc-first';
17018                 row.cn[0].cn[0].style = 'min-height:90px';
17019                 row.cn[6].cls+=' fc-last';
17020                 ret.push(row);
17021                 
17022             }
17023             ret[0].cls += ' fc-first';
17024             ret[4].cls += ' fc-prev-last';
17025             ret[5].cls += ' fc-last';
17026             return ret;
17027             
17028         };
17029         
17030         var cal_table = {
17031             tag: 'table',
17032             cls: 'fc-border-separate',
17033             style : 'width:100%',
17034             cellspacing  : 0,
17035             cn : [
17036                 { 
17037                     tag: 'thead',
17038                     cn : [
17039                         { 
17040                             tag: 'tr',
17041                             cls : 'fc-first fc-last',
17042                             cn : cal_heads()
17043                         }
17044                     ]
17045                 },
17046                 { 
17047                     tag: 'tbody',
17048                     cn : cal_rows()
17049                 }
17050                   
17051             ]
17052         };
17053          
17054          var cfg = {
17055             cls : 'fc fc-ltr',
17056             cn : [
17057                 header,
17058                 {
17059                     cls : 'fc-content',
17060                     style : "position: relative;",
17061                     cn : [
17062                         {
17063                             cls : 'fc-view fc-view-month fc-grid',
17064                             style : 'position: relative',
17065                             unselectable : 'on',
17066                             cn : [
17067                                 {
17068                                     cls : 'fc-event-container',
17069                                     style : 'position:absolute;z-index:8;top:0;left:0;'
17070                                 },
17071                                 cal_table
17072                             ]
17073                         }
17074                     ]
17075     
17076                 }
17077            ] 
17078             
17079         };
17080         
17081          
17082         
17083         return cfg;
17084     },
17085     
17086     
17087     initEvents : function()
17088     {
17089         if(!this.store){
17090             throw "can not find store for calendar";
17091         }
17092         
17093         var mark = {
17094             tag: "div",
17095             cls:"x-dlg-mask",
17096             style: "text-align:center",
17097             cn: [
17098                 {
17099                     tag: "div",
17100                     style: "background-color:white;width:50%;margin:250 auto",
17101                     cn: [
17102                         {
17103                             tag: "img",
17104                             src: Roo.rootURL + '/images/ux/lightbox/loading.gif' 
17105                         },
17106                         {
17107                             tag: "span",
17108                             html: "Loading"
17109                         }
17110                         
17111                     ]
17112                 }
17113             ]
17114         };
17115         this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
17116         
17117         var size = this.el.select('.fc-content', true).first().getSize();
17118         this.maskEl.setSize(size.width, size.height);
17119         this.maskEl.enableDisplayMode("block");
17120         if(!this.loadMask){
17121             this.maskEl.hide();
17122         }
17123         
17124         this.store = Roo.factory(this.store, Roo.data);
17125         this.store.on('load', this.onLoad, this);
17126         this.store.on('beforeload', this.onBeforeLoad, this);
17127         
17128         this.resize();
17129         
17130         this.cells = this.el.select('.fc-day',true);
17131         //Roo.log(this.cells);
17132         this.textNodes = this.el.query('.fc-day-number');
17133         this.cells.addClassOnOver('fc-state-hover');
17134         
17135         this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
17136         this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
17137         this.el.select('.fc-button-today',true).on('click', this.showToday, this);
17138         this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
17139         
17140         this.on('monthchange', this.onMonthChange, this);
17141         
17142         this.update(new Date().clearTime());
17143     },
17144     
17145     resize : function() {
17146         var sz  = this.el.getSize();
17147         
17148         this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
17149         this.el.select('.fc-day-content div',true).setHeight(34);
17150     },
17151     
17152     
17153     // private
17154     showPrevMonth : function(e){
17155         this.update(this.activeDate.add("mo", -1));
17156     },
17157     showToday : function(e){
17158         this.update(new Date().clearTime());
17159     },
17160     // private
17161     showNextMonth : function(e){
17162         this.update(this.activeDate.add("mo", 1));
17163     },
17164
17165     // private
17166     showPrevYear : function(){
17167         this.update(this.activeDate.add("y", -1));
17168     },
17169
17170     // private
17171     showNextYear : function(){
17172         this.update(this.activeDate.add("y", 1));
17173     },
17174
17175     
17176    // private
17177     update : function(date)
17178     {
17179         var vd = this.activeDate;
17180         this.activeDate = date;
17181 //        if(vd && this.el){
17182 //            var t = date.getTime();
17183 //            if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
17184 //                Roo.log('using add remove');
17185 //                
17186 //                this.fireEvent('monthchange', this, date);
17187 //                
17188 //                this.cells.removeClass("fc-state-highlight");
17189 //                this.cells.each(function(c){
17190 //                   if(c.dateValue == t){
17191 //                       c.addClass("fc-state-highlight");
17192 //                       setTimeout(function(){
17193 //                            try{c.dom.firstChild.focus();}catch(e){}
17194 //                       }, 50);
17195 //                       return false;
17196 //                   }
17197 //                   return true;
17198 //                });
17199 //                return;
17200 //            }
17201 //        }
17202         
17203         var days = date.getDaysInMonth();
17204         
17205         var firstOfMonth = date.getFirstDateOfMonth();
17206         var startingPos = firstOfMonth.getDay()-this.startDay;
17207         
17208         if(startingPos < this.startDay){
17209             startingPos += 7;
17210         }
17211         
17212         var pm = date.add(Date.MONTH, -1);
17213         var prevStart = pm.getDaysInMonth()-startingPos;
17214 //        
17215         this.cells = this.el.select('.fc-day',true);
17216         this.textNodes = this.el.query('.fc-day-number');
17217         this.cells.addClassOnOver('fc-state-hover');
17218         
17219         var cells = this.cells.elements;
17220         var textEls = this.textNodes;
17221         
17222         Roo.each(cells, function(cell){
17223             cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
17224         });
17225         
17226         days += startingPos;
17227
17228         // convert everything to numbers so it's fast
17229         var day = 86400000;
17230         var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
17231         //Roo.log(d);
17232         //Roo.log(pm);
17233         //Roo.log(prevStart);
17234         
17235         var today = new Date().clearTime().getTime();
17236         var sel = date.clearTime().getTime();
17237         var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
17238         var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
17239         var ddMatch = this.disabledDatesRE;
17240         var ddText = this.disabledDatesText;
17241         var ddays = this.disabledDays ? this.disabledDays.join("") : false;
17242         var ddaysText = this.disabledDaysText;
17243         var format = this.format;
17244         
17245         var setCellClass = function(cal, cell){
17246             cell.row = 0;
17247             cell.events = [];
17248             cell.more = [];
17249             //Roo.log('set Cell Class');
17250             cell.title = "";
17251             var t = d.getTime();
17252             
17253             //Roo.log(d);
17254             
17255             cell.dateValue = t;
17256             if(t == today){
17257                 cell.className += " fc-today";
17258                 cell.className += " fc-state-highlight";
17259                 cell.title = cal.todayText;
17260             }
17261             if(t == sel){
17262                 // disable highlight in other month..
17263                 //cell.className += " fc-state-highlight";
17264                 
17265             }
17266             // disabling
17267             if(t < min) {
17268                 cell.className = " fc-state-disabled";
17269                 cell.title = cal.minText;
17270                 return;
17271             }
17272             if(t > max) {
17273                 cell.className = " fc-state-disabled";
17274                 cell.title = cal.maxText;
17275                 return;
17276             }
17277             if(ddays){
17278                 if(ddays.indexOf(d.getDay()) != -1){
17279                     cell.title = ddaysText;
17280                     cell.className = " fc-state-disabled";
17281                 }
17282             }
17283             if(ddMatch && format){
17284                 var fvalue = d.dateFormat(format);
17285                 if(ddMatch.test(fvalue)){
17286                     cell.title = ddText.replace("%0", fvalue);
17287                     cell.className = " fc-state-disabled";
17288                 }
17289             }
17290             
17291             if (!cell.initialClassName) {
17292                 cell.initialClassName = cell.dom.className;
17293             }
17294             
17295             cell.dom.className = cell.initialClassName  + ' ' +  cell.className;
17296         };
17297
17298         var i = 0;
17299         
17300         for(; i < startingPos; i++) {
17301             textEls[i].innerHTML = (++prevStart);
17302             d.setDate(d.getDate()+1);
17303             
17304             cells[i].className = "fc-past fc-other-month";
17305             setCellClass(this, cells[i]);
17306         }
17307         
17308         var intDay = 0;
17309         
17310         for(; i < days; i++){
17311             intDay = i - startingPos + 1;
17312             textEls[i].innerHTML = (intDay);
17313             d.setDate(d.getDate()+1);
17314             
17315             cells[i].className = ''; // "x-date-active";
17316             setCellClass(this, cells[i]);
17317         }
17318         var extraDays = 0;
17319         
17320         for(; i < 42; i++) {
17321             textEls[i].innerHTML = (++extraDays);
17322             d.setDate(d.getDate()+1);
17323             
17324             cells[i].className = "fc-future fc-other-month";
17325             setCellClass(this, cells[i]);
17326         }
17327         
17328         this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
17329         
17330         var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
17331         
17332         this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
17333         this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
17334         
17335         if(totalRows != 6){
17336             this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
17337             this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
17338         }
17339         
17340         this.fireEvent('monthchange', this, date);
17341         
17342         
17343         /*
17344         if(!this.internalRender){
17345             var main = this.el.dom.firstChild;
17346             var w = main.offsetWidth;
17347             this.el.setWidth(w + this.el.getBorderWidth("lr"));
17348             Roo.fly(main).setWidth(w);
17349             this.internalRender = true;
17350             // opera does not respect the auto grow header center column
17351             // then, after it gets a width opera refuses to recalculate
17352             // without a second pass
17353             if(Roo.isOpera && !this.secondPass){
17354                 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
17355                 this.secondPass = true;
17356                 this.update.defer(10, this, [date]);
17357             }
17358         }
17359         */
17360         
17361     },
17362     
17363     findCell : function(dt) {
17364         dt = dt.clearTime().getTime();
17365         var ret = false;
17366         this.cells.each(function(c){
17367             //Roo.log("check " +c.dateValue + '?=' + dt);
17368             if(c.dateValue == dt){
17369                 ret = c;
17370                 return false;
17371             }
17372             return true;
17373         });
17374         
17375         return ret;
17376     },
17377     
17378     findCells : function(ev) {
17379         var s = ev.start.clone().clearTime().getTime();
17380        // Roo.log(s);
17381         var e= ev.end.clone().clearTime().getTime();
17382        // Roo.log(e);
17383         var ret = [];
17384         this.cells.each(function(c){
17385              ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
17386             
17387             if(c.dateValue > e){
17388                 return ;
17389             }
17390             if(c.dateValue < s){
17391                 return ;
17392             }
17393             ret.push(c);
17394         });
17395         
17396         return ret;    
17397     },
17398     
17399 //    findBestRow: function(cells)
17400 //    {
17401 //        var ret = 0;
17402 //        
17403 //        for (var i =0 ; i < cells.length;i++) {
17404 //            ret  = Math.max(cells[i].rows || 0,ret);
17405 //        }
17406 //        return ret;
17407 //        
17408 //    },
17409     
17410     
17411     addItem : function(ev)
17412     {
17413         // look for vertical location slot in
17414         var cells = this.findCells(ev);
17415         
17416 //        ev.row = this.findBestRow(cells);
17417         
17418         // work out the location.
17419         
17420         var crow = false;
17421         var rows = [];
17422         for(var i =0; i < cells.length; i++) {
17423             
17424             cells[i].row = cells[0].row;
17425             
17426             if(i == 0){
17427                 cells[i].row = cells[i].row + 1;
17428             }
17429             
17430             if (!crow) {
17431                 crow = {
17432                     start : cells[i],
17433                     end :  cells[i]
17434                 };
17435                 continue;
17436             }
17437             if (crow.start.getY() == cells[i].getY()) {
17438                 // on same row.
17439                 crow.end = cells[i];
17440                 continue;
17441             }
17442             // different row.
17443             rows.push(crow);
17444             crow = {
17445                 start: cells[i],
17446                 end : cells[i]
17447             };
17448             
17449         }
17450         
17451         rows.push(crow);
17452         ev.els = [];
17453         ev.rows = rows;
17454         ev.cells = cells;
17455         
17456         cells[0].events.push(ev);
17457         
17458         this.calevents.push(ev);
17459     },
17460     
17461     clearEvents: function() {
17462         
17463         if(!this.calevents){
17464             return;
17465         }
17466         
17467         Roo.each(this.cells.elements, function(c){
17468             c.row = 0;
17469             c.events = [];
17470             c.more = [];
17471         });
17472         
17473         Roo.each(this.calevents, function(e) {
17474             Roo.each(e.els, function(el) {
17475                 el.un('mouseenter' ,this.onEventEnter, this);
17476                 el.un('mouseleave' ,this.onEventLeave, this);
17477                 el.remove();
17478             },this);
17479         },this);
17480         
17481         Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
17482             e.remove();
17483         });
17484         
17485     },
17486     
17487     renderEvents: function()
17488     {   
17489         var _this = this;
17490         
17491         this.cells.each(function(c) {
17492             
17493             if(c.row < 5){
17494                 return;
17495             }
17496             
17497             var ev = c.events;
17498             
17499             var r = 4;
17500             if(c.row != c.events.length){
17501                 r = 4 - (4 - (c.row - c.events.length));
17502             }
17503             
17504             c.events = ev.slice(0, r);
17505             c.more = ev.slice(r);
17506             
17507             if(c.more.length && c.more.length == 1){
17508                 c.events.push(c.more.pop());
17509             }
17510             
17511             c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
17512             
17513         });
17514             
17515         this.cells.each(function(c) {
17516             
17517             c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
17518             
17519             
17520             for (var e = 0; e < c.events.length; e++){
17521                 var ev = c.events[e];
17522                 var rows = ev.rows;
17523                 
17524                 for(var i = 0; i < rows.length; i++) {
17525                 
17526                     // how many rows should it span..
17527
17528                     var  cfg = {
17529                         cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
17530                         style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
17531
17532                         unselectable : "on",
17533                         cn : [
17534                             {
17535                                 cls: 'fc-event-inner',
17536                                 cn : [
17537     //                                {
17538     //                                  tag:'span',
17539     //                                  cls: 'fc-event-time',
17540     //                                  html : cells.length > 1 ? '' : ev.time
17541     //                                },
17542                                     {
17543                                       tag:'span',
17544                                       cls: 'fc-event-title',
17545                                       html : String.format('{0}', ev.title)
17546                                     }
17547
17548
17549                                 ]
17550                             },
17551                             {
17552                                 cls: 'ui-resizable-handle ui-resizable-e',
17553                                 html : '&nbsp;&nbsp;&nbsp'
17554                             }
17555
17556                         ]
17557                     };
17558
17559                     if (i == 0) {
17560                         cfg.cls += ' fc-event-start';
17561                     }
17562                     if ((i+1) == rows.length) {
17563                         cfg.cls += ' fc-event-end';
17564                     }
17565
17566                     var ctr = _this.el.select('.fc-event-container',true).first();
17567                     var cg = ctr.createChild(cfg);
17568
17569                     var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
17570                     var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
17571
17572                     var r = (c.more.length) ? 1 : 0;
17573                     cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);    
17574                     cg.setWidth(ebox.right - sbox.x -2);
17575
17576                     cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
17577                     cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
17578                     cg.on('click', _this.onEventClick, _this, ev);
17579
17580                     ev.els.push(cg);
17581                     
17582                 }
17583                 
17584             }
17585             
17586             
17587             if(c.more.length){
17588                 var  cfg = {
17589                     cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
17590                     style : 'position: absolute',
17591                     unselectable : "on",
17592                     cn : [
17593                         {
17594                             cls: 'fc-event-inner',
17595                             cn : [
17596                                 {
17597                                   tag:'span',
17598                                   cls: 'fc-event-title',
17599                                   html : 'More'
17600                                 }
17601
17602
17603                             ]
17604                         },
17605                         {
17606                             cls: 'ui-resizable-handle ui-resizable-e',
17607                             html : '&nbsp;&nbsp;&nbsp'
17608                         }
17609
17610                     ]
17611                 };
17612
17613                 var ctr = _this.el.select('.fc-event-container',true).first();
17614                 var cg = ctr.createChild(cfg);
17615
17616                 var sbox = c.select('.fc-day-content',true).first().getBox();
17617                 var ebox = c.select('.fc-day-content',true).first().getBox();
17618                 //Roo.log(cg);
17619                 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);    
17620                 cg.setWidth(ebox.right - sbox.x -2);
17621
17622                 cg.on('click', _this.onMoreEventClick, _this, c.more);
17623                 
17624             }
17625             
17626         });
17627         
17628         
17629         
17630     },
17631     
17632     onEventEnter: function (e, el,event,d) {
17633         this.fireEvent('evententer', this, el, event);
17634     },
17635     
17636     onEventLeave: function (e, el,event,d) {
17637         this.fireEvent('eventleave', this, el, event);
17638     },
17639     
17640     onEventClick: function (e, el,event,d) {
17641         this.fireEvent('eventclick', this, el, event);
17642     },
17643     
17644     onMonthChange: function () {
17645         this.store.load();
17646     },
17647     
17648     onMoreEventClick: function(e, el, more)
17649     {
17650         var _this = this;
17651         
17652         this.calpopover.placement = 'right';
17653         this.calpopover.setTitle('More');
17654         
17655         this.calpopover.setContent('');
17656         
17657         var ctr = this.calpopover.el.select('.popover-content', true).first();
17658         
17659         Roo.each(more, function(m){
17660             var cfg = {
17661                 cls : 'fc-event-hori fc-event-draggable',
17662                 html : m.title
17663             };
17664             var cg = ctr.createChild(cfg);
17665             
17666             cg.on('click', _this.onEventClick, _this, m);
17667         });
17668         
17669         this.calpopover.show(el);
17670         
17671         
17672     },
17673     
17674     onLoad: function () 
17675     {   
17676         this.calevents = [];
17677         var cal = this;
17678         
17679         if(this.store.getCount() > 0){
17680             this.store.data.each(function(d){
17681                cal.addItem({
17682                     id : d.data.id,
17683                     start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
17684                     end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
17685                     time : d.data.start_time,
17686                     title : d.data.title,
17687                     description : d.data.description,
17688                     venue : d.data.venue
17689                 });
17690             });
17691         }
17692         
17693         this.renderEvents();
17694         
17695         if(this.calevents.length && this.loadMask){
17696             this.maskEl.hide();
17697         }
17698     },
17699     
17700     onBeforeLoad: function()
17701     {
17702         this.clearEvents();
17703         if(this.loadMask){
17704             this.maskEl.show();
17705         }
17706     }
17707 });
17708
17709  
17710  /*
17711  * - LGPL
17712  *
17713  * element
17714  * 
17715  */
17716
17717 /**
17718  * @class Roo.bootstrap.Popover
17719  * @extends Roo.bootstrap.Component
17720  * Bootstrap Popover class
17721  * @cfg {String} html contents of the popover   (or false to use children..)
17722  * @cfg {String} title of popover (or false to hide)
17723  * @cfg {String} placement how it is placed
17724  * @cfg {String} trigger click || hover (or false to trigger manually)
17725  * @cfg {String} over what (parent or false to trigger manually.)
17726  * @cfg {Number} delay - delay before showing
17727  
17728  * @constructor
17729  * Create a new Popover
17730  * @param {Object} config The config object
17731  */
17732
17733 Roo.bootstrap.Popover = function(config){
17734     Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17735     
17736     this.addEvents({
17737         // raw events
17738          /**
17739          * @event show
17740          * After the popover show
17741          * 
17742          * @param {Roo.bootstrap.Popover} this
17743          */
17744         "show" : true,
17745         /**
17746          * @event hide
17747          * After the popover hide
17748          * 
17749          * @param {Roo.bootstrap.Popover} this
17750          */
17751         "hide" : true
17752     });
17753 };
17754
17755 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component,  {
17756     
17757     title: 'Fill in a title',
17758     html: false,
17759     
17760     placement : 'right',
17761     trigger : 'hover', // hover
17762     
17763     delay : 0,
17764     
17765     over: 'parent',
17766     
17767     can_build_overlaid : false,
17768     
17769     getChildContainer : function()
17770     {
17771         return this.el.select('.popover-content',true).first();
17772     },
17773     
17774     getAutoCreate : function(){
17775          
17776         var cfg = {
17777            cls : 'popover roo-dynamic',
17778            style: 'display:block',
17779            cn : [
17780                 {
17781                     cls : 'arrow'
17782                 },
17783                 {
17784                     cls : 'popover-inner',
17785                     cn : [
17786                         {
17787                             tag: 'h3',
17788                             cls: 'popover-title popover-header',
17789                             html : this.title
17790                         },
17791                         {
17792                             cls : 'popover-content popover-body',
17793                             html : this.html
17794                         }
17795                     ]
17796                     
17797                 }
17798            ]
17799         };
17800         
17801         return cfg;
17802     },
17803     setTitle: function(str)
17804     {
17805         this.title = str;
17806         this.el.select('.popover-title',true).first().dom.innerHTML = str;
17807     },
17808     setContent: function(str)
17809     {
17810         this.html = str;
17811         this.el.select('.popover-content',true).first().dom.innerHTML = str;
17812     },
17813     // as it get's added to the bottom of the page.
17814     onRender : function(ct, position)
17815     {
17816         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17817         if(!this.el){
17818             var cfg = Roo.apply({},  this.getAutoCreate());
17819             cfg.id = Roo.id();
17820             
17821             if (this.cls) {
17822                 cfg.cls += ' ' + this.cls;
17823             }
17824             if (this.style) {
17825                 cfg.style = this.style;
17826             }
17827             //Roo.log("adding to ");
17828             this.el = Roo.get(document.body).createChild(cfg, position);
17829 //            Roo.log(this.el);
17830         }
17831         this.initEvents();
17832     },
17833     
17834     initEvents : function()
17835     {
17836         this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17837         this.el.enableDisplayMode('block');
17838         this.el.hide();
17839         if (this.over === false) {
17840             return; 
17841         }
17842         if (this.triggers === false) {
17843             return;
17844         }
17845         var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17846         var triggers = this.trigger ? this.trigger.split(' ') : [];
17847         Roo.each(triggers, function(trigger) {
17848         
17849             if (trigger == 'click') {
17850                 on_el.on('click', this.toggle, this);
17851             } else if (trigger != 'manual') {
17852                 var eventIn  = trigger == 'hover' ? 'mouseenter' : 'focusin';
17853                 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17854       
17855                 on_el.on(eventIn  ,this.enter, this);
17856                 on_el.on(eventOut, this.leave, this);
17857             }
17858         }, this);
17859         
17860     },
17861     
17862     
17863     // private
17864     timeout : null,
17865     hoverState : null,
17866     
17867     toggle : function () {
17868         this.hoverState == 'in' ? this.leave() : this.enter();
17869     },
17870     
17871     enter : function () {
17872         
17873         clearTimeout(this.timeout);
17874     
17875         this.hoverState = 'in';
17876     
17877         if (!this.delay || !this.delay.show) {
17878             this.show();
17879             return;
17880         }
17881         var _t = this;
17882         this.timeout = setTimeout(function () {
17883             if (_t.hoverState == 'in') {
17884                 _t.show();
17885             }
17886         }, this.delay.show)
17887     },
17888     
17889     leave : function() {
17890         clearTimeout(this.timeout);
17891     
17892         this.hoverState = 'out';
17893     
17894         if (!this.delay || !this.delay.hide) {
17895             this.hide();
17896             return;
17897         }
17898         var _t = this;
17899         this.timeout = setTimeout(function () {
17900             if (_t.hoverState == 'out') {
17901                 _t.hide();
17902             }
17903         }, this.delay.hide)
17904     },
17905     
17906     show : function (on_el)
17907     {
17908         if (!on_el) {
17909             on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17910         }
17911         
17912         // set content.
17913         this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17914         if (this.html !== false) {
17915             this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17916         }
17917         this.el.removeClass([
17918             'fade','top','bottom', 'left', 'right','in',
17919             'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
17920         ]);
17921         if (!this.title.length) {
17922             this.el.select('.popover-title',true).hide();
17923         }
17924         
17925         var placement = typeof this.placement == 'function' ?
17926             this.placement.call(this, this.el, on_el) :
17927             this.placement;
17928             
17929         var autoToken = /\s?auto?\s?/i;
17930         var autoPlace = autoToken.test(placement);
17931         if (autoPlace) {
17932             placement = placement.replace(autoToken, '') || 'top';
17933         }
17934         
17935         //this.el.detach()
17936         //this.el.setXY([0,0]);
17937         this.el.show();
17938         this.el.dom.style.display='block';
17939         this.el.addClass(placement);
17940         
17941         //this.el.appendTo(on_el);
17942         
17943         var p = this.getPosition();
17944         var box = this.el.getBox();
17945         
17946         if (autoPlace) {
17947             // fixme..
17948         }
17949         var align = Roo.bootstrap.Popover.alignment[placement];
17950         
17951 //        Roo.log(align);
17952         this.el.alignTo(on_el, align[0],align[1]);
17953         //var arrow = this.el.select('.arrow',true).first();
17954         //arrow.set(align[2], 
17955         
17956         this.el.addClass('in');
17957         
17958         
17959         if (this.el.hasClass('fade')) {
17960             // fade it?
17961         }
17962         
17963         this.hoverState = 'in';
17964         
17965         this.fireEvent('show', this);
17966         
17967     },
17968     hide : function()
17969     {
17970         this.el.setXY([0,0]);
17971         this.el.removeClass('in');
17972         this.el.hide();
17973         this.hoverState = null;
17974         
17975         this.fireEvent('hide', this);
17976     }
17977     
17978 });
17979
17980 Roo.bootstrap.Popover.alignment = {
17981     'left' : ['r-l', [-10,0], 'right bs-popover-right'],
17982     'right' : ['l-r', [10,0], 'left bs-popover-left'],
17983     'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
17984     'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
17985 };
17986
17987  /*
17988  * - LGPL
17989  *
17990  * Progress
17991  * 
17992  */
17993
17994 /**
17995  * @class Roo.bootstrap.Progress
17996  * @extends Roo.bootstrap.Component
17997  * Bootstrap Progress class
17998  * @cfg {Boolean} striped striped of the progress bar
17999  * @cfg {Boolean} active animated of the progress bar
18000  * 
18001  * 
18002  * @constructor
18003  * Create a new Progress
18004  * @param {Object} config The config object
18005  */
18006
18007 Roo.bootstrap.Progress = function(config){
18008     Roo.bootstrap.Progress.superclass.constructor.call(this, config);
18009 };
18010
18011 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component,  {
18012     
18013     striped : false,
18014     active: false,
18015     
18016     getAutoCreate : function(){
18017         var cfg = {
18018             tag: 'div',
18019             cls: 'progress'
18020         };
18021         
18022         
18023         if(this.striped){
18024             cfg.cls += ' progress-striped';
18025         }
18026       
18027         if(this.active){
18028             cfg.cls += ' active';
18029         }
18030         
18031         
18032         return cfg;
18033     }
18034    
18035 });
18036
18037  
18038
18039  /*
18040  * - LGPL
18041  *
18042  * ProgressBar
18043  * 
18044  */
18045
18046 /**
18047  * @class Roo.bootstrap.ProgressBar
18048  * @extends Roo.bootstrap.Component
18049  * Bootstrap ProgressBar class
18050  * @cfg {Number} aria_valuenow aria-value now
18051  * @cfg {Number} aria_valuemin aria-value min
18052  * @cfg {Number} aria_valuemax aria-value max
18053  * @cfg {String} label label for the progress bar
18054  * @cfg {String} panel (success | info | warning | danger )
18055  * @cfg {String} role role of the progress bar
18056  * @cfg {String} sr_only text
18057  * 
18058  * 
18059  * @constructor
18060  * Create a new ProgressBar
18061  * @param {Object} config The config object
18062  */
18063
18064 Roo.bootstrap.ProgressBar = function(config){
18065     Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
18066 };
18067
18068 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component,  {
18069     
18070     aria_valuenow : 0,
18071     aria_valuemin : 0,
18072     aria_valuemax : 100,
18073     label : false,
18074     panel : false,
18075     role : false,
18076     sr_only: false,
18077     
18078     getAutoCreate : function()
18079     {
18080         
18081         var cfg = {
18082             tag: 'div',
18083             cls: 'progress-bar',
18084             style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
18085         };
18086         
18087         if(this.sr_only){
18088             cfg.cn = {
18089                 tag: 'span',
18090                 cls: 'sr-only',
18091                 html: this.sr_only
18092             }
18093         }
18094         
18095         if(this.role){
18096             cfg.role = this.role;
18097         }
18098         
18099         if(this.aria_valuenow){
18100             cfg['aria-valuenow'] = this.aria_valuenow;
18101         }
18102         
18103         if(this.aria_valuemin){
18104             cfg['aria-valuemin'] = this.aria_valuemin;
18105         }
18106         
18107         if(this.aria_valuemax){
18108             cfg['aria-valuemax'] = this.aria_valuemax;
18109         }
18110         
18111         if(this.label && !this.sr_only){
18112             cfg.html = this.label;
18113         }
18114         
18115         if(this.panel){
18116             cfg.cls += ' progress-bar-' + this.panel;
18117         }
18118         
18119         return cfg;
18120     },
18121     
18122     update : function(aria_valuenow)
18123     {
18124         this.aria_valuenow = aria_valuenow;
18125         
18126         this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
18127     }
18128    
18129 });
18130
18131  
18132
18133  /*
18134  * - LGPL
18135  *
18136  * column
18137  * 
18138  */
18139
18140 /**
18141  * @class Roo.bootstrap.TabGroup
18142  * @extends Roo.bootstrap.Column
18143  * Bootstrap Column class
18144  * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
18145  * @cfg {Boolean} carousel true to make the group behave like a carousel
18146  * @cfg {Boolean} bullets show bullets for the panels
18147  * @cfg {Boolean} autoslide (true|false) auto slide .. default false
18148  * @cfg {Number} timer auto slide timer .. default 0 millisecond
18149  * @cfg {Boolean} showarrow (true|false) show arrow default true
18150  * 
18151  * @constructor
18152  * Create a new TabGroup
18153  * @param {Object} config The config object
18154  */
18155
18156 Roo.bootstrap.TabGroup = function(config){
18157     Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
18158     if (!this.navId) {
18159         this.navId = Roo.id();
18160     }
18161     this.tabs = [];
18162     Roo.bootstrap.TabGroup.register(this);
18163     
18164 };
18165
18166 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column,  {
18167     
18168     carousel : false,
18169     transition : false,
18170     bullets : 0,
18171     timer : 0,
18172     autoslide : false,
18173     slideFn : false,
18174     slideOnTouch : false,
18175     showarrow : true,
18176     
18177     getAutoCreate : function()
18178     {
18179         var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
18180         
18181         cfg.cls += ' tab-content';
18182         
18183         if (this.carousel) {
18184             cfg.cls += ' carousel slide';
18185             
18186             cfg.cn = [{
18187                cls : 'carousel-inner',
18188                cn : []
18189             }];
18190         
18191             if(this.bullets  && !Roo.isTouch){
18192                 
18193                 var bullets = {
18194                     cls : 'carousel-bullets',
18195                     cn : []
18196                 };
18197                
18198                 if(this.bullets_cls){
18199                     bullets.cls = bullets.cls + ' ' + this.bullets_cls;
18200                 }
18201                 
18202                 bullets.cn.push({
18203                     cls : 'clear'
18204                 });
18205                 
18206                 cfg.cn[0].cn.push(bullets);
18207             }
18208             
18209             if(this.showarrow){
18210                 cfg.cn[0].cn.push({
18211                     tag : 'div',
18212                     class : 'carousel-arrow',
18213                     cn : [
18214                         {
18215                             tag : 'div',
18216                             class : 'carousel-prev',
18217                             cn : [
18218                                 {
18219                                     tag : 'i',
18220                                     class : 'fa fa-chevron-left'
18221                                 }
18222                             ]
18223                         },
18224                         {
18225                             tag : 'div',
18226                             class : 'carousel-next',
18227                             cn : [
18228                                 {
18229                                     tag : 'i',
18230                                     class : 'fa fa-chevron-right'
18231                                 }
18232                             ]
18233                         }
18234                     ]
18235                 });
18236             }
18237             
18238         }
18239         
18240         return cfg;
18241     },
18242     
18243     initEvents:  function()
18244     {
18245 //        if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
18246 //            this.el.on("touchstart", this.onTouchStart, this);
18247 //        }
18248         
18249         if(this.autoslide){
18250             var _this = this;
18251             
18252             this.slideFn = window.setInterval(function() {
18253                 _this.showPanelNext();
18254             }, this.timer);
18255         }
18256         
18257         if(this.showarrow){
18258             this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
18259             this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
18260         }
18261         
18262         
18263     },
18264     
18265 //    onTouchStart : function(e, el, o)
18266 //    {
18267 //        if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
18268 //            return;
18269 //        }
18270 //        
18271 //        this.showPanelNext();
18272 //    },
18273     
18274     
18275     getChildContainer : function()
18276     {
18277         return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
18278     },
18279     
18280     /**
18281     * register a Navigation item
18282     * @param {Roo.bootstrap.NavItem} the navitem to add
18283     */
18284     register : function(item)
18285     {
18286         this.tabs.push( item);
18287         item.navId = this.navId; // not really needed..
18288         this.addBullet();
18289     
18290     },
18291     
18292     getActivePanel : function()
18293     {
18294         var r = false;
18295         Roo.each(this.tabs, function(t) {
18296             if (t.active) {
18297                 r = t;
18298                 return false;
18299             }
18300             return null;
18301         });
18302         return r;
18303         
18304     },
18305     getPanelByName : function(n)
18306     {
18307         var r = false;
18308         Roo.each(this.tabs, function(t) {
18309             if (t.tabId == n) {
18310                 r = t;
18311                 return false;
18312             }
18313             return null;
18314         });
18315         return r;
18316     },
18317     indexOfPanel : function(p)
18318     {
18319         var r = false;
18320         Roo.each(this.tabs, function(t,i) {
18321             if (t.tabId == p.tabId) {
18322                 r = i;
18323                 return false;
18324             }
18325             return null;
18326         });
18327         return r;
18328     },
18329     /**
18330      * show a specific panel
18331      * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
18332      * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
18333      */
18334     showPanel : function (pan)
18335     {
18336         if(this.transition || typeof(pan) == 'undefined'){
18337             Roo.log("waiting for the transitionend");
18338             return false;
18339         }
18340         
18341         if (typeof(pan) == 'number') {
18342             pan = this.tabs[pan];
18343         }
18344         
18345         if (typeof(pan) == 'string') {
18346             pan = this.getPanelByName(pan);
18347         }
18348         
18349         var cur = this.getActivePanel();
18350         
18351         if(!pan || !cur){
18352             Roo.log('pan or acitve pan is undefined');
18353             return false;
18354         }
18355         
18356         if (pan.tabId == this.getActivePanel().tabId) {
18357             return true;
18358         }
18359         
18360         if (false === cur.fireEvent('beforedeactivate')) {
18361             return false;
18362         }
18363         
18364         if(this.bullets > 0 && !Roo.isTouch){
18365             this.setActiveBullet(this.indexOfPanel(pan));
18366         }
18367         
18368         if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
18369             
18370             //class="carousel-item carousel-item-next carousel-item-left"
18371             
18372             this.transition = true;
18373             var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur)  ? 'next' : 'prev';
18374             var lr = dir == 'next' ? 'left' : 'right';
18375             pan.el.addClass(dir); // or prev
18376             pan.el.addClass('carousel-item-' + dir); // or prev
18377             pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
18378             cur.el.addClass(lr); // or right
18379             pan.el.addClass(lr);
18380             cur.el.addClass('carousel-item-' +lr); // or right
18381             pan.el.addClass('carousel-item-' +lr);
18382             
18383             
18384             var _this = this;
18385             cur.el.on('transitionend', function() {
18386                 Roo.log("trans end?");
18387                 
18388                 pan.el.removeClass([lr,dir, 'carousel-item-' + lr, 'carousel-item-' + dir]);
18389                 pan.setActive(true);
18390                 
18391                 cur.el.removeClass([lr, 'carousel-item-' + lr]);
18392                 cur.setActive(false);
18393                 
18394                 _this.transition = false;
18395                 
18396             }, this, { single:  true } );
18397             
18398             return true;
18399         }
18400         
18401         cur.setActive(false);
18402         pan.setActive(true);
18403         
18404         return true;
18405         
18406     },
18407     showPanelNext : function()
18408     {
18409         var i = this.indexOfPanel(this.getActivePanel());
18410         
18411         if (i >= this.tabs.length - 1 && !this.autoslide) {
18412             return;
18413         }
18414         
18415         if (i >= this.tabs.length - 1 && this.autoslide) {
18416             i = -1;
18417         }
18418         
18419         this.showPanel(this.tabs[i+1]);
18420     },
18421     
18422     showPanelPrev : function()
18423     {
18424         var i = this.indexOfPanel(this.getActivePanel());
18425         
18426         if (i  < 1 && !this.autoslide) {
18427             return;
18428         }
18429         
18430         if (i < 1 && this.autoslide) {
18431             i = this.tabs.length;
18432         }
18433         
18434         this.showPanel(this.tabs[i-1]);
18435     },
18436     
18437     
18438     addBullet: function()
18439     {
18440         if(!this.bullets || Roo.isTouch){
18441             return;
18442         }
18443         var ctr = this.el.select('.carousel-bullets',true).first();
18444         var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
18445         var bullet = ctr.createChild({
18446             cls : 'bullet bullet-' + i
18447         },ctr.dom.lastChild);
18448         
18449         
18450         var _this = this;
18451         
18452         bullet.on('click', (function(e, el, o, ii, t){
18453
18454             e.preventDefault();
18455
18456             this.showPanel(ii);
18457
18458             if(this.autoslide && this.slideFn){
18459                 clearInterval(this.slideFn);
18460                 this.slideFn = window.setInterval(function() {
18461                     _this.showPanelNext();
18462                 }, this.timer);
18463             }
18464
18465         }).createDelegate(this, [i, bullet], true));
18466                 
18467         
18468     },
18469      
18470     setActiveBullet : function(i)
18471     {
18472         if(Roo.isTouch){
18473             return;
18474         }
18475         
18476         Roo.each(this.el.select('.bullet', true).elements, function(el){
18477             el.removeClass('selected');
18478         });
18479
18480         var bullet = this.el.select('.bullet-' + i, true).first();
18481         
18482         if(!bullet){
18483             return;
18484         }
18485         
18486         bullet.addClass('selected');
18487     }
18488     
18489     
18490   
18491 });
18492
18493  
18494
18495  
18496  
18497 Roo.apply(Roo.bootstrap.TabGroup, {
18498     
18499     groups: {},
18500      /**
18501     * register a Navigation Group
18502     * @param {Roo.bootstrap.NavGroup} the navgroup to add
18503     */
18504     register : function(navgrp)
18505     {
18506         this.groups[navgrp.navId] = navgrp;
18507         
18508     },
18509     /**
18510     * fetch a Navigation Group based on the navigation ID
18511     * if one does not exist , it will get created.
18512     * @param {string} the navgroup to add
18513     * @returns {Roo.bootstrap.NavGroup} the navgroup 
18514     */
18515     get: function(navId) {
18516         if (typeof(this.groups[navId]) == 'undefined') {
18517             this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
18518         }
18519         return this.groups[navId] ;
18520     }
18521     
18522     
18523     
18524 });
18525
18526  /*
18527  * - LGPL
18528  *
18529  * TabPanel
18530  * 
18531  */
18532
18533 /**
18534  * @class Roo.bootstrap.TabPanel
18535  * @extends Roo.bootstrap.Component
18536  * Bootstrap TabPanel class
18537  * @cfg {Boolean} active panel active
18538  * @cfg {String} html panel content
18539  * @cfg {String} tabId  unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
18540  * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
18541  * @cfg {String} href click to link..
18542  * 
18543  * 
18544  * @constructor
18545  * Create a new TabPanel
18546  * @param {Object} config The config object
18547  */
18548
18549 Roo.bootstrap.TabPanel = function(config){
18550     Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
18551     this.addEvents({
18552         /**
18553              * @event changed
18554              * Fires when the active status changes
18555              * @param {Roo.bootstrap.TabPanel} this
18556              * @param {Boolean} state the new state
18557             
18558          */
18559         'changed': true,
18560         /**
18561              * @event beforedeactivate
18562              * Fires before a tab is de-activated - can be used to do validation on a form.
18563              * @param {Roo.bootstrap.TabPanel} this
18564              * @return {Boolean} false if there is an error
18565             
18566          */
18567         'beforedeactivate': true
18568      });
18569     
18570     this.tabId = this.tabId || Roo.id();
18571   
18572 };
18573
18574 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component,  {
18575     
18576     active: false,
18577     html: false,
18578     tabId: false,
18579     navId : false,
18580     href : '',
18581     
18582     getAutoCreate : function(){
18583         
18584         
18585         var cfg = {
18586             tag: 'div',
18587             // item is needed for carousel - not sure if it has any effect otherwise
18588             cls: 'carousel-item tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
18589             html: this.html || ''
18590         };
18591         
18592         if(this.active){
18593             cfg.cls += ' active';
18594         }
18595         
18596         if(this.tabId){
18597             cfg.tabId = this.tabId;
18598         }
18599         
18600         
18601         
18602         return cfg;
18603     },
18604     
18605     initEvents:  function()
18606     {
18607         var p = this.parent();
18608         
18609         this.navId = this.navId || p.navId;
18610         
18611         if (typeof(this.navId) != 'undefined') {
18612             // not really needed.. but just in case.. parent should be a NavGroup.
18613             var tg = Roo.bootstrap.TabGroup.get(this.navId);
18614             
18615             tg.register(this);
18616             
18617             var i = tg.tabs.length - 1;
18618             
18619             if(this.active && tg.bullets > 0 && i < tg.bullets){
18620                 tg.setActiveBullet(i);
18621             }
18622         }
18623         
18624         this.el.on('click', this.onClick, this);
18625         
18626         if(Roo.isTouch){
18627             this.el.on("touchstart", this.onTouchStart, this);
18628             this.el.on("touchmove", this.onTouchMove, this);
18629             this.el.on("touchend", this.onTouchEnd, this);
18630         }
18631         
18632     },
18633     
18634     onRender : function(ct, position)
18635     {
18636         Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
18637     },
18638     
18639     setActive : function(state)
18640     {
18641         Roo.log("panel - set active " + this.tabId + "=" + state);
18642         
18643         this.active = state;
18644         if (!state) {
18645             this.el.removeClass('active');
18646             
18647         } else  if (!this.el.hasClass('active')) {
18648             this.el.addClass('active');
18649         }
18650         
18651         this.fireEvent('changed', this, state);
18652     },
18653     
18654     onClick : function(e)
18655     {
18656         e.preventDefault();
18657         
18658         if(!this.href.length){
18659             return;
18660         }
18661         
18662         window.location.href = this.href;
18663     },
18664     
18665     startX : 0,
18666     startY : 0,
18667     endX : 0,
18668     endY : 0,
18669     swiping : false,
18670     
18671     onTouchStart : function(e)
18672     {
18673         this.swiping = false;
18674         
18675         this.startX = e.browserEvent.touches[0].clientX;
18676         this.startY = e.browserEvent.touches[0].clientY;
18677     },
18678     
18679     onTouchMove : function(e)
18680     {
18681         this.swiping = true;
18682         
18683         this.endX = e.browserEvent.touches[0].clientX;
18684         this.endY = e.browserEvent.touches[0].clientY;
18685     },
18686     
18687     onTouchEnd : function(e)
18688     {
18689         if(!this.swiping){
18690             this.onClick(e);
18691             return;
18692         }
18693         
18694         var tabGroup = this.parent();
18695         
18696         if(this.endX > this.startX){ // swiping right
18697             tabGroup.showPanelPrev();
18698             return;
18699         }
18700         
18701         if(this.startX > this.endX){ // swiping left
18702             tabGroup.showPanelNext();
18703             return;
18704         }
18705     }
18706     
18707     
18708 });
18709  
18710
18711  
18712
18713  /*
18714  * - LGPL
18715  *
18716  * DateField
18717  * 
18718  */
18719
18720 /**
18721  * @class Roo.bootstrap.DateField
18722  * @extends Roo.bootstrap.Input
18723  * Bootstrap DateField class
18724  * @cfg {Number} weekStart default 0
18725  * @cfg {String} viewMode default empty, (months|years)
18726  * @cfg {String} minViewMode default empty, (months|years)
18727  * @cfg {Number} startDate default -Infinity
18728  * @cfg {Number} endDate default Infinity
18729  * @cfg {Boolean} todayHighlight default false
18730  * @cfg {Boolean} todayBtn default false
18731  * @cfg {Boolean} calendarWeeks default false
18732  * @cfg {Object} daysOfWeekDisabled default empty
18733  * @cfg {Boolean} singleMode default false (true | false)
18734  * 
18735  * @cfg {Boolean} keyboardNavigation default true
18736  * @cfg {String} language default en
18737  * 
18738  * @constructor
18739  * Create a new DateField
18740  * @param {Object} config The config object
18741  */
18742
18743 Roo.bootstrap.DateField = function(config){
18744     Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18745      this.addEvents({
18746             /**
18747              * @event show
18748              * Fires when this field show.
18749              * @param {Roo.bootstrap.DateField} this
18750              * @param {Mixed} date The date value
18751              */
18752             show : true,
18753             /**
18754              * @event show
18755              * Fires when this field hide.
18756              * @param {Roo.bootstrap.DateField} this
18757              * @param {Mixed} date The date value
18758              */
18759             hide : true,
18760             /**
18761              * @event select
18762              * Fires when select a date.
18763              * @param {Roo.bootstrap.DateField} this
18764              * @param {Mixed} date The date value
18765              */
18766             select : true,
18767             /**
18768              * @event beforeselect
18769              * Fires when before select a date.
18770              * @param {Roo.bootstrap.DateField} this
18771              * @param {Mixed} date The date value
18772              */
18773             beforeselect : true
18774         });
18775 };
18776
18777 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input,  {
18778     
18779     /**
18780      * @cfg {String} format
18781      * The default date format string which can be overriden for localization support.  The format must be
18782      * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18783      */
18784     format : "m/d/y",
18785     /**
18786      * @cfg {String} altFormats
18787      * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18788      * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18789      */
18790     altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18791     
18792     weekStart : 0,
18793     
18794     viewMode : '',
18795     
18796     minViewMode : '',
18797     
18798     todayHighlight : false,
18799     
18800     todayBtn: false,
18801     
18802     language: 'en',
18803     
18804     keyboardNavigation: true,
18805     
18806     calendarWeeks: false,
18807     
18808     startDate: -Infinity,
18809     
18810     endDate: Infinity,
18811     
18812     daysOfWeekDisabled: [],
18813     
18814     _events: [],
18815     
18816     singleMode : false,
18817     
18818     UTCDate: function()
18819     {
18820         return new Date(Date.UTC.apply(Date, arguments));
18821     },
18822     
18823     UTCToday: function()
18824     {
18825         var today = new Date();
18826         return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18827     },
18828     
18829     getDate: function() {
18830             var d = this.getUTCDate();
18831             return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18832     },
18833     
18834     getUTCDate: function() {
18835             return this.date;
18836     },
18837     
18838     setDate: function(d) {
18839             this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18840     },
18841     
18842     setUTCDate: function(d) {
18843             this.date = d;
18844             this.setValue(this.formatDate(this.date));
18845     },
18846         
18847     onRender: function(ct, position)
18848     {
18849         
18850         Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18851         
18852         this.language = this.language || 'en';
18853         this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18854         this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18855         
18856         this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18857         this.format = this.format || 'm/d/y';
18858         this.isInline = false;
18859         this.isInput = true;
18860         this.component = this.el.select('.add-on', true).first() || false;
18861         this.component = (this.component && this.component.length === 0) ? false : this.component;
18862         this.hasInput = this.component && this.inputEl().length;
18863         
18864         if (typeof(this.minViewMode === 'string')) {
18865             switch (this.minViewMode) {
18866                 case 'months':
18867                     this.minViewMode = 1;
18868                     break;
18869                 case 'years':
18870                     this.minViewMode = 2;
18871                     break;
18872                 default:
18873                     this.minViewMode = 0;
18874                     break;
18875             }
18876         }
18877         
18878         if (typeof(this.viewMode === 'string')) {
18879             switch (this.viewMode) {
18880                 case 'months':
18881                     this.viewMode = 1;
18882                     break;
18883                 case 'years':
18884                     this.viewMode = 2;
18885                     break;
18886                 default:
18887                     this.viewMode = 0;
18888                     break;
18889             }
18890         }
18891                 
18892         this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18893         
18894 //        this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18895         
18896         this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18897         
18898         this.picker().on('mousedown', this.onMousedown, this);
18899         this.picker().on('click', this.onClick, this);
18900         
18901         this.picker().addClass('datepicker-dropdown');
18902         
18903         this.startViewMode = this.viewMode;
18904         
18905         if(this.singleMode){
18906             Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18907                 v.setVisibilityMode(Roo.Element.DISPLAY);
18908                 v.hide();
18909             });
18910             
18911             Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18912                 v.setStyle('width', '189px');
18913             });
18914         }
18915         
18916         Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18917             if(!this.calendarWeeks){
18918                 v.remove();
18919                 return;
18920             }
18921             
18922             v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18923             v.attr('colspan', function(i, val){
18924                 return parseInt(val) + 1;
18925             });
18926         });
18927                         
18928         
18929         this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18930         
18931         this.setStartDate(this.startDate);
18932         this.setEndDate(this.endDate);
18933         
18934         this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18935         
18936         this.fillDow();
18937         this.fillMonths();
18938         this.update();
18939         this.showMode();
18940         
18941         if(this.isInline) {
18942             this.showPopup();
18943         }
18944     },
18945     
18946     picker : function()
18947     {
18948         return this.pickerEl;
18949 //        return this.el.select('.datepicker', true).first();
18950     },
18951     
18952     fillDow: function()
18953     {
18954         var dowCnt = this.weekStart;
18955         
18956         var dow = {
18957             tag: 'tr',
18958             cn: [
18959                 
18960             ]
18961         };
18962         
18963         if(this.calendarWeeks){
18964             dow.cn.push({
18965                 tag: 'th',
18966                 cls: 'cw',
18967                 html: '&nbsp;'
18968             })
18969         }
18970         
18971         while (dowCnt < this.weekStart + 7) {
18972             dow.cn.push({
18973                 tag: 'th',
18974                 cls: 'dow',
18975                 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18976             });
18977         }
18978         
18979         this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18980     },
18981     
18982     fillMonths: function()
18983     {    
18984         var i = 0;
18985         var months = this.picker().select('>.datepicker-months td', true).first();
18986         
18987         months.dom.innerHTML = '';
18988         
18989         while (i < 12) {
18990             var month = {
18991                 tag: 'span',
18992                 cls: 'month',
18993                 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18994             };
18995             
18996             months.createChild(month);
18997         }
18998         
18999     },
19000     
19001     update: function()
19002     {
19003         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;
19004         
19005         if (this.date < this.startDate) {
19006             this.viewDate = new Date(this.startDate);
19007         } else if (this.date > this.endDate) {
19008             this.viewDate = new Date(this.endDate);
19009         } else {
19010             this.viewDate = new Date(this.date);
19011         }
19012         
19013         this.fill();
19014     },
19015     
19016     fill: function() 
19017     {
19018         var d = new Date(this.viewDate),
19019                 year = d.getUTCFullYear(),
19020                 month = d.getUTCMonth(),
19021                 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
19022                 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
19023                 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
19024                 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
19025                 currentDate = this.date && this.date.valueOf(),
19026                 today = this.UTCToday();
19027         
19028         this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
19029         
19030 //        this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
19031         
19032 //        this.picker.select('>tfoot th.today').
19033 //                                              .text(dates[this.language].today)
19034 //                                              .toggle(this.todayBtn !== false);
19035     
19036         this.updateNavArrows();
19037         this.fillMonths();
19038                                                 
19039         var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
19040         
19041         day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
19042          
19043         prevMonth.setUTCDate(day);
19044         
19045         prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
19046         
19047         var nextMonth = new Date(prevMonth);
19048         
19049         nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
19050         
19051         nextMonth = nextMonth.valueOf();
19052         
19053         var fillMonths = false;
19054         
19055         this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
19056         
19057         while(prevMonth.valueOf() <= nextMonth) {
19058             var clsName = '';
19059             
19060             if (prevMonth.getUTCDay() === this.weekStart) {
19061                 if(fillMonths){
19062                     this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
19063                 }
19064                     
19065                 fillMonths = {
19066                     tag: 'tr',
19067                     cn: []
19068                 };
19069                 
19070                 if(this.calendarWeeks){
19071                     // ISO 8601: First week contains first thursday.
19072                     // ISO also states week starts on Monday, but we can be more abstract here.
19073                     var
19074                     // Start of current week: based on weekstart/current date
19075                     ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
19076                     // Thursday of this week
19077                     th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
19078                     // First Thursday of year, year from thursday
19079                     yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
19080                     // Calendar week: ms between thursdays, div ms per day, div 7 days
19081                     calWeek =  (th - yth) / 864e5 / 7 + 1;
19082                     
19083                     fillMonths.cn.push({
19084                         tag: 'td',
19085                         cls: 'cw',
19086                         html: calWeek
19087                     });
19088                 }
19089             }
19090             
19091             if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
19092                 clsName += ' old';
19093             } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
19094                 clsName += ' new';
19095             }
19096             if (this.todayHighlight &&
19097                 prevMonth.getUTCFullYear() == today.getFullYear() &&
19098                 prevMonth.getUTCMonth() == today.getMonth() &&
19099                 prevMonth.getUTCDate() == today.getDate()) {
19100                 clsName += ' today';
19101             }
19102             
19103             if (currentDate && prevMonth.valueOf() === currentDate) {
19104                 clsName += ' active';
19105             }
19106             
19107             if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
19108                     this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
19109                     clsName += ' disabled';
19110             }
19111             
19112             fillMonths.cn.push({
19113                 tag: 'td',
19114                 cls: 'day ' + clsName,
19115                 html: prevMonth.getDate()
19116             });
19117             
19118             prevMonth.setDate(prevMonth.getDate()+1);
19119         }
19120           
19121         var currentYear = this.date && this.date.getUTCFullYear();
19122         var currentMonth = this.date && this.date.getUTCMonth();
19123         
19124         this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
19125         
19126         Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
19127             v.removeClass('active');
19128             
19129             if(currentYear === year && k === currentMonth){
19130                 v.addClass('active');
19131             }
19132             
19133             if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
19134                 v.addClass('disabled');
19135             }
19136             
19137         });
19138         
19139         
19140         year = parseInt(year/10, 10) * 10;
19141         
19142         this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
19143         
19144         this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
19145         
19146         year -= 1;
19147         for (var i = -1; i < 11; i++) {
19148             this.picker().select('>.datepicker-years tbody td',true).first().createChild({
19149                 tag: 'span',
19150                 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
19151                 html: year
19152             });
19153             
19154             year += 1;
19155         }
19156     },
19157     
19158     showMode: function(dir) 
19159     {
19160         if (dir) {
19161             this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
19162         }
19163         
19164         Roo.each(this.picker().select('>div',true).elements, function(v){
19165             v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19166             v.hide();
19167         });
19168         this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
19169     },
19170     
19171     place: function()
19172     {
19173         if(this.isInline) {
19174             return;
19175         }
19176         
19177         this.picker().removeClass(['bottom', 'top']);
19178         
19179         if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
19180             /*
19181              * place to the top of element!
19182              *
19183              */
19184             
19185             this.picker().addClass('top');
19186             this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
19187             
19188             return;
19189         }
19190         
19191         this.picker().addClass('bottom');
19192         
19193         this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
19194     },
19195     
19196     parseDate : function(value)
19197     {
19198         if(!value || value instanceof Date){
19199             return value;
19200         }
19201         var v = Date.parseDate(value, this.format);
19202         if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
19203             v = Date.parseDate(value, 'Y-m-d');
19204         }
19205         if(!v && this.altFormats){
19206             if(!this.altFormatsArray){
19207                 this.altFormatsArray = this.altFormats.split("|");
19208             }
19209             for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
19210                 v = Date.parseDate(value, this.altFormatsArray[i]);
19211             }
19212         }
19213         return v;
19214     },
19215     
19216     formatDate : function(date, fmt)
19217     {   
19218         return (!date || !(date instanceof Date)) ?
19219         date : date.dateFormat(fmt || this.format);
19220     },
19221     
19222     onFocus : function()
19223     {
19224         Roo.bootstrap.DateField.superclass.onFocus.call(this);
19225         this.showPopup();
19226     },
19227     
19228     onBlur : function()
19229     {
19230         Roo.bootstrap.DateField.superclass.onBlur.call(this);
19231         
19232         var d = this.inputEl().getValue();
19233         
19234         this.setValue(d);
19235                 
19236         this.hidePopup();
19237     },
19238     
19239     showPopup : function()
19240     {
19241         this.picker().show();
19242         this.update();
19243         this.place();
19244         
19245         this.fireEvent('showpopup', this, this.date);
19246     },
19247     
19248     hidePopup : function()
19249     {
19250         if(this.isInline) {
19251             return;
19252         }
19253         this.picker().hide();
19254         this.viewMode = this.startViewMode;
19255         this.showMode();
19256         
19257         this.fireEvent('hidepopup', this, this.date);
19258         
19259     },
19260     
19261     onMousedown: function(e)
19262     {
19263         e.stopPropagation();
19264         e.preventDefault();
19265     },
19266     
19267     keyup: function(e)
19268     {
19269         Roo.bootstrap.DateField.superclass.keyup.call(this);
19270         this.update();
19271     },
19272
19273     setValue: function(v)
19274     {
19275         if(this.fireEvent('beforeselect', this, v) !== false){
19276             var d = new Date(this.parseDate(v) ).clearTime();
19277         
19278             if(isNaN(d.getTime())){
19279                 this.date = this.viewDate = '';
19280                 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19281                 return;
19282             }
19283
19284             v = this.formatDate(d);
19285
19286             Roo.bootstrap.DateField.superclass.setValue.call(this, v);
19287
19288             this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
19289
19290             this.update();
19291
19292             this.fireEvent('select', this, this.date);
19293         }
19294     },
19295     
19296     getValue: function()
19297     {
19298         return this.formatDate(this.date);
19299     },
19300     
19301     fireKey: function(e)
19302     {
19303         if (!this.picker().isVisible()){
19304             if (e.keyCode == 27) { // allow escape to hide and re-show picker
19305                 this.showPopup();
19306             }
19307             return;
19308         }
19309         
19310         var dateChanged = false,
19311         dir, day, month,
19312         newDate, newViewDate;
19313         
19314         switch(e.keyCode){
19315             case 27: // escape
19316                 this.hidePopup();
19317                 e.preventDefault();
19318                 break;
19319             case 37: // left
19320             case 39: // right
19321                 if (!this.keyboardNavigation) {
19322                     break;
19323                 }
19324                 dir = e.keyCode == 37 ? -1 : 1;
19325                 
19326                 if (e.ctrlKey){
19327                     newDate = this.moveYear(this.date, dir);
19328                     newViewDate = this.moveYear(this.viewDate, dir);
19329                 } else if (e.shiftKey){
19330                     newDate = this.moveMonth(this.date, dir);
19331                     newViewDate = this.moveMonth(this.viewDate, dir);
19332                 } else {
19333                     newDate = new Date(this.date);
19334                     newDate.setUTCDate(this.date.getUTCDate() + dir);
19335                     newViewDate = new Date(this.viewDate);
19336                     newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
19337                 }
19338                 if (this.dateWithinRange(newDate)){
19339                     this.date = newDate;
19340                     this.viewDate = newViewDate;
19341                     this.setValue(this.formatDate(this.date));
19342 //                    this.update();
19343                     e.preventDefault();
19344                     dateChanged = true;
19345                 }
19346                 break;
19347             case 38: // up
19348             case 40: // down
19349                 if (!this.keyboardNavigation) {
19350                     break;
19351                 }
19352                 dir = e.keyCode == 38 ? -1 : 1;
19353                 if (e.ctrlKey){
19354                     newDate = this.moveYear(this.date, dir);
19355                     newViewDate = this.moveYear(this.viewDate, dir);
19356                 } else if (e.shiftKey){
19357                     newDate = this.moveMonth(this.date, dir);
19358                     newViewDate = this.moveMonth(this.viewDate, dir);
19359                 } else {
19360                     newDate = new Date(this.date);
19361                     newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
19362                     newViewDate = new Date(this.viewDate);
19363                     newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
19364                 }
19365                 if (this.dateWithinRange(newDate)){
19366                     this.date = newDate;
19367                     this.viewDate = newViewDate;
19368                     this.setValue(this.formatDate(this.date));
19369 //                    this.update();
19370                     e.preventDefault();
19371                     dateChanged = true;
19372                 }
19373                 break;
19374             case 13: // enter
19375                 this.setValue(this.formatDate(this.date));
19376                 this.hidePopup();
19377                 e.preventDefault();
19378                 break;
19379             case 9: // tab
19380                 this.setValue(this.formatDate(this.date));
19381                 this.hidePopup();
19382                 break;
19383             case 16: // shift
19384             case 17: // ctrl
19385             case 18: // alt
19386                 break;
19387             default :
19388                 this.hidePopup();
19389                 
19390         }
19391     },
19392     
19393     
19394     onClick: function(e) 
19395     {
19396         e.stopPropagation();
19397         e.preventDefault();
19398         
19399         var target = e.getTarget();
19400         
19401         if(target.nodeName.toLowerCase() === 'i'){
19402             target = Roo.get(target).dom.parentNode;
19403         }
19404         
19405         var nodeName = target.nodeName;
19406         var className = target.className;
19407         var html = target.innerHTML;
19408         //Roo.log(nodeName);
19409         
19410         switch(nodeName.toLowerCase()) {
19411             case 'th':
19412                 switch(className) {
19413                     case 'switch':
19414                         this.showMode(1);
19415                         break;
19416                     case 'prev':
19417                     case 'next':
19418                         var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
19419                         switch(this.viewMode){
19420                                 case 0:
19421                                         this.viewDate = this.moveMonth(this.viewDate, dir);
19422                                         break;
19423                                 case 1:
19424                                 case 2:
19425                                         this.viewDate = this.moveYear(this.viewDate, dir);
19426                                         break;
19427                         }
19428                         this.fill();
19429                         break;
19430                     case 'today':
19431                         var date = new Date();
19432                         this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
19433 //                        this.fill()
19434                         this.setValue(this.formatDate(this.date));
19435                         
19436                         this.hidePopup();
19437                         break;
19438                 }
19439                 break;
19440             case 'span':
19441                 if (className.indexOf('disabled') < 0) {
19442                     this.viewDate.setUTCDate(1);
19443                     if (className.indexOf('month') > -1) {
19444                         this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
19445                     } else {
19446                         var year = parseInt(html, 10) || 0;
19447                         this.viewDate.setUTCFullYear(year);
19448                         
19449                     }
19450                     
19451                     if(this.singleMode){
19452                         this.setValue(this.formatDate(this.viewDate));
19453                         this.hidePopup();
19454                         return;
19455                     }
19456                     
19457                     this.showMode(-1);
19458                     this.fill();
19459                 }
19460                 break;
19461                 
19462             case 'td':
19463                 //Roo.log(className);
19464                 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
19465                     var day = parseInt(html, 10) || 1;
19466                     var year = this.viewDate.getUTCFullYear(),
19467                         month = this.viewDate.getUTCMonth();
19468
19469                     if (className.indexOf('old') > -1) {
19470                         if(month === 0 ){
19471                             month = 11;
19472                             year -= 1;
19473                         }else{
19474                             month -= 1;
19475                         }
19476                     } else if (className.indexOf('new') > -1) {
19477                         if (month == 11) {
19478                             month = 0;
19479                             year += 1;
19480                         } else {
19481                             month += 1;
19482                         }
19483                     }
19484                     //Roo.log([year,month,day]);
19485                     this.date = this.UTCDate(year, month, day,0,0,0,0);
19486                     this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
19487 //                    this.fill();
19488                     //Roo.log(this.formatDate(this.date));
19489                     this.setValue(this.formatDate(this.date));
19490                     this.hidePopup();
19491                 }
19492                 break;
19493         }
19494     },
19495     
19496     setStartDate: function(startDate)
19497     {
19498         this.startDate = startDate || -Infinity;
19499         if (this.startDate !== -Infinity) {
19500             this.startDate = this.parseDate(this.startDate);
19501         }
19502         this.update();
19503         this.updateNavArrows();
19504     },
19505
19506     setEndDate: function(endDate)
19507     {
19508         this.endDate = endDate || Infinity;
19509         if (this.endDate !== Infinity) {
19510             this.endDate = this.parseDate(this.endDate);
19511         }
19512         this.update();
19513         this.updateNavArrows();
19514     },
19515     
19516     setDaysOfWeekDisabled: function(daysOfWeekDisabled)
19517     {
19518         this.daysOfWeekDisabled = daysOfWeekDisabled || [];
19519         if (typeof(this.daysOfWeekDisabled) !== 'object') {
19520             this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
19521         }
19522         this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
19523             return parseInt(d, 10);
19524         });
19525         this.update();
19526         this.updateNavArrows();
19527     },
19528     
19529     updateNavArrows: function() 
19530     {
19531         if(this.singleMode){
19532             return;
19533         }
19534         
19535         var d = new Date(this.viewDate),
19536         year = d.getUTCFullYear(),
19537         month = d.getUTCMonth();
19538         
19539         Roo.each(this.picker().select('.prev', true).elements, function(v){
19540             v.show();
19541             switch (this.viewMode) {
19542                 case 0:
19543
19544                     if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
19545                         v.hide();
19546                     }
19547                     break;
19548                 case 1:
19549                 case 2:
19550                     if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
19551                         v.hide();
19552                     }
19553                     break;
19554             }
19555         });
19556         
19557         Roo.each(this.picker().select('.next', true).elements, function(v){
19558             v.show();
19559             switch (this.viewMode) {
19560                 case 0:
19561
19562                     if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
19563                         v.hide();
19564                     }
19565                     break;
19566                 case 1:
19567                 case 2:
19568                     if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
19569                         v.hide();
19570                     }
19571                     break;
19572             }
19573         })
19574     },
19575     
19576     moveMonth: function(date, dir)
19577     {
19578         if (!dir) {
19579             return date;
19580         }
19581         var new_date = new Date(date.valueOf()),
19582         day = new_date.getUTCDate(),
19583         month = new_date.getUTCMonth(),
19584         mag = Math.abs(dir),
19585         new_month, test;
19586         dir = dir > 0 ? 1 : -1;
19587         if (mag == 1){
19588             test = dir == -1
19589             // If going back one month, make sure month is not current month
19590             // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
19591             ? function(){
19592                 return new_date.getUTCMonth() == month;
19593             }
19594             // If going forward one month, make sure month is as expected
19595             // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
19596             : function(){
19597                 return new_date.getUTCMonth() != new_month;
19598             };
19599             new_month = month + dir;
19600             new_date.setUTCMonth(new_month);
19601             // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
19602             if (new_month < 0 || new_month > 11) {
19603                 new_month = (new_month + 12) % 12;
19604             }
19605         } else {
19606             // For magnitudes >1, move one month at a time...
19607             for (var i=0; i<mag; i++) {
19608                 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
19609                 new_date = this.moveMonth(new_date, dir);
19610             }
19611             // ...then reset the day, keeping it in the new month
19612             new_month = new_date.getUTCMonth();
19613             new_date.setUTCDate(day);
19614             test = function(){
19615                 return new_month != new_date.getUTCMonth();
19616             };
19617         }
19618         // Common date-resetting loop -- if date is beyond end of month, make it
19619         // end of month
19620         while (test()){
19621             new_date.setUTCDate(--day);
19622             new_date.setUTCMonth(new_month);
19623         }
19624         return new_date;
19625     },
19626
19627     moveYear: function(date, dir)
19628     {
19629         return this.moveMonth(date, dir*12);
19630     },
19631
19632     dateWithinRange: function(date)
19633     {
19634         return date >= this.startDate && date <= this.endDate;
19635     },
19636
19637     
19638     remove: function() 
19639     {
19640         this.picker().remove();
19641     },
19642     
19643     validateValue : function(value)
19644     {
19645         if(this.getVisibilityEl().hasClass('hidden')){
19646             return true;
19647         }
19648         
19649         if(value.length < 1)  {
19650             if(this.allowBlank){
19651                 return true;
19652             }
19653             return false;
19654         }
19655         
19656         if(value.length < this.minLength){
19657             return false;
19658         }
19659         if(value.length > this.maxLength){
19660             return false;
19661         }
19662         if(this.vtype){
19663             var vt = Roo.form.VTypes;
19664             if(!vt[this.vtype](value, this)){
19665                 return false;
19666             }
19667         }
19668         if(typeof this.validator == "function"){
19669             var msg = this.validator(value);
19670             if(msg !== true){
19671                 return false;
19672             }
19673         }
19674         
19675         if(this.regex && !this.regex.test(value)){
19676             return false;
19677         }
19678         
19679         if(typeof(this.parseDate(value)) == 'undefined'){
19680             return false;
19681         }
19682         
19683         if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
19684             return false;
19685         }      
19686         
19687         if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
19688             return false;
19689         } 
19690         
19691         
19692         return true;
19693     },
19694     
19695     reset : function()
19696     {
19697         this.date = this.viewDate = '';
19698         
19699         Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19700     }
19701    
19702 });
19703
19704 Roo.apply(Roo.bootstrap.DateField,  {
19705     
19706     head : {
19707         tag: 'thead',
19708         cn: [
19709         {
19710             tag: 'tr',
19711             cn: [
19712             {
19713                 tag: 'th',
19714                 cls: 'prev',
19715                 html: '<i class="fa fa-arrow-left"/>'
19716             },
19717             {
19718                 tag: 'th',
19719                 cls: 'switch',
19720                 colspan: '5'
19721             },
19722             {
19723                 tag: 'th',
19724                 cls: 'next',
19725                 html: '<i class="fa fa-arrow-right"/>'
19726             }
19727
19728             ]
19729         }
19730         ]
19731     },
19732     
19733     content : {
19734         tag: 'tbody',
19735         cn: [
19736         {
19737             tag: 'tr',
19738             cn: [
19739             {
19740                 tag: 'td',
19741                 colspan: '7'
19742             }
19743             ]
19744         }
19745         ]
19746     },
19747     
19748     footer : {
19749         tag: 'tfoot',
19750         cn: [
19751         {
19752             tag: 'tr',
19753             cn: [
19754             {
19755                 tag: 'th',
19756                 colspan: '7',
19757                 cls: 'today'
19758             }
19759                     
19760             ]
19761         }
19762         ]
19763     },
19764     
19765     dates:{
19766         en: {
19767             days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19768             daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19769             daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19770             months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19771             monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19772             today: "Today"
19773         }
19774     },
19775     
19776     modes: [
19777     {
19778         clsName: 'days',
19779         navFnc: 'Month',
19780         navStep: 1
19781     },
19782     {
19783         clsName: 'months',
19784         navFnc: 'FullYear',
19785         navStep: 1
19786     },
19787     {
19788         clsName: 'years',
19789         navFnc: 'FullYear',
19790         navStep: 10
19791     }]
19792 });
19793
19794 Roo.apply(Roo.bootstrap.DateField,  {
19795   
19796     template : {
19797         tag: 'div',
19798         cls: 'datepicker dropdown-menu roo-dynamic',
19799         cn: [
19800         {
19801             tag: 'div',
19802             cls: 'datepicker-days',
19803             cn: [
19804             {
19805                 tag: 'table',
19806                 cls: 'table-condensed',
19807                 cn:[
19808                 Roo.bootstrap.DateField.head,
19809                 {
19810                     tag: 'tbody'
19811                 },
19812                 Roo.bootstrap.DateField.footer
19813                 ]
19814             }
19815             ]
19816         },
19817         {
19818             tag: 'div',
19819             cls: 'datepicker-months',
19820             cn: [
19821             {
19822                 tag: 'table',
19823                 cls: 'table-condensed',
19824                 cn:[
19825                 Roo.bootstrap.DateField.head,
19826                 Roo.bootstrap.DateField.content,
19827                 Roo.bootstrap.DateField.footer
19828                 ]
19829             }
19830             ]
19831         },
19832         {
19833             tag: 'div',
19834             cls: 'datepicker-years',
19835             cn: [
19836             {
19837                 tag: 'table',
19838                 cls: 'table-condensed',
19839                 cn:[
19840                 Roo.bootstrap.DateField.head,
19841                 Roo.bootstrap.DateField.content,
19842                 Roo.bootstrap.DateField.footer
19843                 ]
19844             }
19845             ]
19846         }
19847         ]
19848     }
19849 });
19850
19851  
19852
19853  /*
19854  * - LGPL
19855  *
19856  * TimeField
19857  * 
19858  */
19859
19860 /**
19861  * @class Roo.bootstrap.TimeField
19862  * @extends Roo.bootstrap.Input
19863  * Bootstrap DateField class
19864  * 
19865  * 
19866  * @constructor
19867  * Create a new TimeField
19868  * @param {Object} config The config object
19869  */
19870
19871 Roo.bootstrap.TimeField = function(config){
19872     Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19873     this.addEvents({
19874             /**
19875              * @event show
19876              * Fires when this field show.
19877              * @param {Roo.bootstrap.DateField} thisthis
19878              * @param {Mixed} date The date value
19879              */
19880             show : true,
19881             /**
19882              * @event show
19883              * Fires when this field hide.
19884              * @param {Roo.bootstrap.DateField} this
19885              * @param {Mixed} date The date value
19886              */
19887             hide : true,
19888             /**
19889              * @event select
19890              * Fires when select a date.
19891              * @param {Roo.bootstrap.DateField} this
19892              * @param {Mixed} date The date value
19893              */
19894             select : true
19895         });
19896 };
19897
19898 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input,  {
19899     
19900     /**
19901      * @cfg {String} format
19902      * The default time format string which can be overriden for localization support.  The format must be
19903      * valid according to {@link Date#parseDate} (defaults to 'H:i').
19904      */
19905     format : "H:i",
19906        
19907     onRender: function(ct, position)
19908     {
19909         
19910         Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19911                 
19912         this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19913         
19914         this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19915         
19916         this.pop = this.picker().select('>.datepicker-time',true).first();
19917         this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19918         
19919         this.picker().on('mousedown', this.onMousedown, this);
19920         this.picker().on('click', this.onClick, this);
19921         
19922         this.picker().addClass('datepicker-dropdown');
19923     
19924         this.fillTime();
19925         this.update();
19926             
19927         this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19928         this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19929         this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19930         this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19931         this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19932         this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19933
19934     },
19935     
19936     fireKey: function(e){
19937         if (!this.picker().isVisible()){
19938             if (e.keyCode == 27) { // allow escape to hide and re-show picker
19939                 this.show();
19940             }
19941             return;
19942         }
19943
19944         e.preventDefault();
19945         
19946         switch(e.keyCode){
19947             case 27: // escape
19948                 this.hide();
19949                 break;
19950             case 37: // left
19951             case 39: // right
19952                 this.onTogglePeriod();
19953                 break;
19954             case 38: // up
19955                 this.onIncrementMinutes();
19956                 break;
19957             case 40: // down
19958                 this.onDecrementMinutes();
19959                 break;
19960             case 13: // enter
19961             case 9: // tab
19962                 this.setTime();
19963                 break;
19964         }
19965     },
19966     
19967     onClick: function(e) {
19968         e.stopPropagation();
19969         e.preventDefault();
19970     },
19971     
19972     picker : function()
19973     {
19974         return this.el.select('.datepicker', true).first();
19975     },
19976     
19977     fillTime: function()
19978     {    
19979         var time = this.pop.select('tbody', true).first();
19980         
19981         time.dom.innerHTML = '';
19982         
19983         time.createChild({
19984             tag: 'tr',
19985             cn: [
19986                 {
19987                     tag: 'td',
19988                     cn: [
19989                         {
19990                             tag: 'a',
19991                             href: '#',
19992                             cls: 'btn',
19993                             cn: [
19994                                 {
19995                                     tag: 'span',
19996                                     cls: 'hours-up glyphicon glyphicon-chevron-up'
19997                                 }
19998                             ]
19999                         } 
20000                     ]
20001                 },
20002                 {
20003                     tag: 'td',
20004                     cls: 'separator'
20005                 },
20006                 {
20007                     tag: 'td',
20008                     cn: [
20009                         {
20010                             tag: 'a',
20011                             href: '#',
20012                             cls: 'btn',
20013                             cn: [
20014                                 {
20015                                     tag: 'span',
20016                                     cls: 'minutes-up glyphicon glyphicon-chevron-up'
20017                                 }
20018                             ]
20019                         }
20020                     ]
20021                 },
20022                 {
20023                     tag: 'td',
20024                     cls: 'separator'
20025                 }
20026             ]
20027         });
20028         
20029         time.createChild({
20030             tag: 'tr',
20031             cn: [
20032                 {
20033                     tag: 'td',
20034                     cn: [
20035                         {
20036                             tag: 'span',
20037                             cls: 'timepicker-hour',
20038                             html: '00'
20039                         }  
20040                     ]
20041                 },
20042                 {
20043                     tag: 'td',
20044                     cls: 'separator',
20045                     html: ':'
20046                 },
20047                 {
20048                     tag: 'td',
20049                     cn: [
20050                         {
20051                             tag: 'span',
20052                             cls: 'timepicker-minute',
20053                             html: '00'
20054                         }  
20055                     ]
20056                 },
20057                 {
20058                     tag: 'td',
20059                     cls: 'separator'
20060                 },
20061                 {
20062                     tag: 'td',
20063                     cn: [
20064                         {
20065                             tag: 'button',
20066                             type: 'button',
20067                             cls: 'btn btn-primary period',
20068                             html: 'AM'
20069                             
20070                         }
20071                     ]
20072                 }
20073             ]
20074         });
20075         
20076         time.createChild({
20077             tag: 'tr',
20078             cn: [
20079                 {
20080                     tag: 'td',
20081                     cn: [
20082                         {
20083                             tag: 'a',
20084                             href: '#',
20085                             cls: 'btn',
20086                             cn: [
20087                                 {
20088                                     tag: 'span',
20089                                     cls: 'hours-down glyphicon glyphicon-chevron-down'
20090                                 }
20091                             ]
20092                         }
20093                     ]
20094                 },
20095                 {
20096                     tag: 'td',
20097                     cls: 'separator'
20098                 },
20099                 {
20100                     tag: 'td',
20101                     cn: [
20102                         {
20103                             tag: 'a',
20104                             href: '#',
20105                             cls: 'btn',
20106                             cn: [
20107                                 {
20108                                     tag: 'span',
20109                                     cls: 'minutes-down glyphicon glyphicon-chevron-down'
20110                                 }
20111                             ]
20112                         }
20113                     ]
20114                 },
20115                 {
20116                     tag: 'td',
20117                     cls: 'separator'
20118                 }
20119             ]
20120         });
20121         
20122     },
20123     
20124     update: function()
20125     {
20126         
20127         this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
20128         
20129         this.fill();
20130     },
20131     
20132     fill: function() 
20133     {
20134         var hours = this.time.getHours();
20135         var minutes = this.time.getMinutes();
20136         var period = 'AM';
20137         
20138         if(hours > 11){
20139             period = 'PM';
20140         }
20141         
20142         if(hours == 0){
20143             hours = 12;
20144         }
20145         
20146         
20147         if(hours > 12){
20148             hours = hours - 12;
20149         }
20150         
20151         if(hours < 10){
20152             hours = '0' + hours;
20153         }
20154         
20155         if(minutes < 10){
20156             minutes = '0' + minutes;
20157         }
20158         
20159         this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
20160         this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
20161         this.pop.select('button', true).first().dom.innerHTML = period;
20162         
20163     },
20164     
20165     place: function()
20166     {   
20167         this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
20168         
20169         var cls = ['bottom'];
20170         
20171         if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
20172             cls.pop();
20173             cls.push('top');
20174         }
20175         
20176         cls.push('right');
20177         
20178         if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
20179             cls.pop();
20180             cls.push('left');
20181         }
20182         
20183         this.picker().addClass(cls.join('-'));
20184         
20185         var _this = this;
20186         
20187         Roo.each(cls, function(c){
20188             if(c == 'bottom'){
20189                 _this.picker().setTop(_this.inputEl().getHeight());
20190                 return;
20191             }
20192             if(c == 'top'){
20193                 _this.picker().setTop(0 - _this.picker().getHeight());
20194                 return;
20195             }
20196             
20197             if(c == 'left'){
20198                 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
20199                 return;
20200             }
20201             if(c == 'right'){
20202                 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
20203                 return;
20204             }
20205         });
20206         
20207     },
20208   
20209     onFocus : function()
20210     {
20211         Roo.bootstrap.TimeField.superclass.onFocus.call(this);
20212         this.show();
20213     },
20214     
20215     onBlur : function()
20216     {
20217         Roo.bootstrap.TimeField.superclass.onBlur.call(this);
20218         this.hide();
20219     },
20220     
20221     show : function()
20222     {
20223         this.picker().show();
20224         this.pop.show();
20225         this.update();
20226         this.place();
20227         
20228         this.fireEvent('show', this, this.date);
20229     },
20230     
20231     hide : function()
20232     {
20233         this.picker().hide();
20234         this.pop.hide();
20235         
20236         this.fireEvent('hide', this, this.date);
20237     },
20238     
20239     setTime : function()
20240     {
20241         this.hide();
20242         this.setValue(this.time.format(this.format));
20243         
20244         this.fireEvent('select', this, this.date);
20245         
20246         
20247     },
20248     
20249     onMousedown: function(e){
20250         e.stopPropagation();
20251         e.preventDefault();
20252     },
20253     
20254     onIncrementHours: function()
20255     {
20256         Roo.log('onIncrementHours');
20257         this.time = this.time.add(Date.HOUR, 1);
20258         this.update();
20259         
20260     },
20261     
20262     onDecrementHours: function()
20263     {
20264         Roo.log('onDecrementHours');
20265         this.time = this.time.add(Date.HOUR, -1);
20266         this.update();
20267     },
20268     
20269     onIncrementMinutes: function()
20270     {
20271         Roo.log('onIncrementMinutes');
20272         this.time = this.time.add(Date.MINUTE, 1);
20273         this.update();
20274     },
20275     
20276     onDecrementMinutes: function()
20277     {
20278         Roo.log('onDecrementMinutes');
20279         this.time = this.time.add(Date.MINUTE, -1);
20280         this.update();
20281     },
20282     
20283     onTogglePeriod: function()
20284     {
20285         Roo.log('onTogglePeriod');
20286         this.time = this.time.add(Date.HOUR, 12);
20287         this.update();
20288     }
20289     
20290    
20291 });
20292
20293 Roo.apply(Roo.bootstrap.TimeField,  {
20294     
20295     content : {
20296         tag: 'tbody',
20297         cn: [
20298             {
20299                 tag: 'tr',
20300                 cn: [
20301                 {
20302                     tag: 'td',
20303                     colspan: '7'
20304                 }
20305                 ]
20306             }
20307         ]
20308     },
20309     
20310     footer : {
20311         tag: 'tfoot',
20312         cn: [
20313             {
20314                 tag: 'tr',
20315                 cn: [
20316                 {
20317                     tag: 'th',
20318                     colspan: '7',
20319                     cls: '',
20320                     cn: [
20321                         {
20322                             tag: 'button',
20323                             cls: 'btn btn-info ok',
20324                             html: 'OK'
20325                         }
20326                     ]
20327                 }
20328
20329                 ]
20330             }
20331         ]
20332     }
20333 });
20334
20335 Roo.apply(Roo.bootstrap.TimeField,  {
20336   
20337     template : {
20338         tag: 'div',
20339         cls: 'datepicker dropdown-menu',
20340         cn: [
20341             {
20342                 tag: 'div',
20343                 cls: 'datepicker-time',
20344                 cn: [
20345                 {
20346                     tag: 'table',
20347                     cls: 'table-condensed',
20348                     cn:[
20349                     Roo.bootstrap.TimeField.content,
20350                     Roo.bootstrap.TimeField.footer
20351                     ]
20352                 }
20353                 ]
20354             }
20355         ]
20356     }
20357 });
20358
20359  
20360
20361  /*
20362  * - LGPL
20363  *
20364  * MonthField
20365  * 
20366  */
20367
20368 /**
20369  * @class Roo.bootstrap.MonthField
20370  * @extends Roo.bootstrap.Input
20371  * Bootstrap MonthField class
20372  * 
20373  * @cfg {String} language default en
20374  * 
20375  * @constructor
20376  * Create a new MonthField
20377  * @param {Object} config The config object
20378  */
20379
20380 Roo.bootstrap.MonthField = function(config){
20381     Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
20382     
20383     this.addEvents({
20384         /**
20385          * @event show
20386          * Fires when this field show.
20387          * @param {Roo.bootstrap.MonthField} this
20388          * @param {Mixed} date The date value
20389          */
20390         show : true,
20391         /**
20392          * @event show
20393          * Fires when this field hide.
20394          * @param {Roo.bootstrap.MonthField} this
20395          * @param {Mixed} date The date value
20396          */
20397         hide : true,
20398         /**
20399          * @event select
20400          * Fires when select a date.
20401          * @param {Roo.bootstrap.MonthField} this
20402          * @param {String} oldvalue The old value
20403          * @param {String} newvalue The new value
20404          */
20405         select : true
20406     });
20407 };
20408
20409 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input,  {
20410     
20411     onRender: function(ct, position)
20412     {
20413         
20414         Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
20415         
20416         this.language = this.language || 'en';
20417         this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
20418         this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
20419         
20420         this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
20421         this.isInline = false;
20422         this.isInput = true;
20423         this.component = this.el.select('.add-on', true).first() || false;
20424         this.component = (this.component && this.component.length === 0) ? false : this.component;
20425         this.hasInput = this.component && this.inputEL().length;
20426         
20427         this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
20428         
20429         this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
20430         
20431         this.picker().on('mousedown', this.onMousedown, this);
20432         this.picker().on('click', this.onClick, this);
20433         
20434         this.picker().addClass('datepicker-dropdown');
20435         
20436         Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
20437             v.setStyle('width', '189px');
20438         });
20439         
20440         this.fillMonths();
20441         
20442         this.update();
20443         
20444         if(this.isInline) {
20445             this.show();
20446         }
20447         
20448     },
20449     
20450     setValue: function(v, suppressEvent)
20451     {   
20452         var o = this.getValue();
20453         
20454         Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
20455         
20456         this.update();
20457
20458         if(suppressEvent !== true){
20459             this.fireEvent('select', this, o, v);
20460         }
20461         
20462     },
20463     
20464     getValue: function()
20465     {
20466         return this.value;
20467     },
20468     
20469     onClick: function(e) 
20470     {
20471         e.stopPropagation();
20472         e.preventDefault();
20473         
20474         var target = e.getTarget();
20475         
20476         if(target.nodeName.toLowerCase() === 'i'){
20477             target = Roo.get(target).dom.parentNode;
20478         }
20479         
20480         var nodeName = target.nodeName;
20481         var className = target.className;
20482         var html = target.innerHTML;
20483         
20484         if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
20485             return;
20486         }
20487         
20488         this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
20489         
20490         this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20491         
20492         this.hide();
20493                         
20494     },
20495     
20496     picker : function()
20497     {
20498         return this.pickerEl;
20499     },
20500     
20501     fillMonths: function()
20502     {    
20503         var i = 0;
20504         var months = this.picker().select('>.datepicker-months td', true).first();
20505         
20506         months.dom.innerHTML = '';
20507         
20508         while (i < 12) {
20509             var month = {
20510                 tag: 'span',
20511                 cls: 'month',
20512                 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
20513             };
20514             
20515             months.createChild(month);
20516         }
20517         
20518     },
20519     
20520     update: function()
20521     {
20522         var _this = this;
20523         
20524         if(typeof(this.vIndex) == 'undefined' && this.value.length){
20525             this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
20526         }
20527         
20528         Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
20529             e.removeClass('active');
20530             
20531             if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
20532                 e.addClass('active');
20533             }
20534         })
20535     },
20536     
20537     place: function()
20538     {
20539         if(this.isInline) {
20540             return;
20541         }
20542         
20543         this.picker().removeClass(['bottom', 'top']);
20544         
20545         if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
20546             /*
20547              * place to the top of element!
20548              *
20549              */
20550             
20551             this.picker().addClass('top');
20552             this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
20553             
20554             return;
20555         }
20556         
20557         this.picker().addClass('bottom');
20558         
20559         this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
20560     },
20561     
20562     onFocus : function()
20563     {
20564         Roo.bootstrap.MonthField.superclass.onFocus.call(this);
20565         this.show();
20566     },
20567     
20568     onBlur : function()
20569     {
20570         Roo.bootstrap.MonthField.superclass.onBlur.call(this);
20571         
20572         var d = this.inputEl().getValue();
20573         
20574         this.setValue(d);
20575                 
20576         this.hide();
20577     },
20578     
20579     show : function()
20580     {
20581         this.picker().show();
20582         this.picker().select('>.datepicker-months', true).first().show();
20583         this.update();
20584         this.place();
20585         
20586         this.fireEvent('show', this, this.date);
20587     },
20588     
20589     hide : function()
20590     {
20591         if(this.isInline) {
20592             return;
20593         }
20594         this.picker().hide();
20595         this.fireEvent('hide', this, this.date);
20596         
20597     },
20598     
20599     onMousedown: function(e)
20600     {
20601         e.stopPropagation();
20602         e.preventDefault();
20603     },
20604     
20605     keyup: function(e)
20606     {
20607         Roo.bootstrap.MonthField.superclass.keyup.call(this);
20608         this.update();
20609     },
20610
20611     fireKey: function(e)
20612     {
20613         if (!this.picker().isVisible()){
20614             if (e.keyCode == 27)   {// allow escape to hide and re-show picker
20615                 this.show();
20616             }
20617             return;
20618         }
20619         
20620         var dir;
20621         
20622         switch(e.keyCode){
20623             case 27: // escape
20624                 this.hide();
20625                 e.preventDefault();
20626                 break;
20627             case 37: // left
20628             case 39: // right
20629                 dir = e.keyCode == 37 ? -1 : 1;
20630                 
20631                 this.vIndex = this.vIndex + dir;
20632                 
20633                 if(this.vIndex < 0){
20634                     this.vIndex = 0;
20635                 }
20636                 
20637                 if(this.vIndex > 11){
20638                     this.vIndex = 11;
20639                 }
20640                 
20641                 if(isNaN(this.vIndex)){
20642                     this.vIndex = 0;
20643                 }
20644                 
20645                 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20646                 
20647                 break;
20648             case 38: // up
20649             case 40: // down
20650                 
20651                 dir = e.keyCode == 38 ? -1 : 1;
20652                 
20653                 this.vIndex = this.vIndex + dir * 4;
20654                 
20655                 if(this.vIndex < 0){
20656                     this.vIndex = 0;
20657                 }
20658                 
20659                 if(this.vIndex > 11){
20660                     this.vIndex = 11;
20661                 }
20662                 
20663                 if(isNaN(this.vIndex)){
20664                     this.vIndex = 0;
20665                 }
20666                 
20667                 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20668                 break;
20669                 
20670             case 13: // enter
20671                 
20672                 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20673                     this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20674                 }
20675                 
20676                 this.hide();
20677                 e.preventDefault();
20678                 break;
20679             case 9: // tab
20680                 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20681                     this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20682                 }
20683                 this.hide();
20684                 break;
20685             case 16: // shift
20686             case 17: // ctrl
20687             case 18: // alt
20688                 break;
20689             default :
20690                 this.hide();
20691                 
20692         }
20693     },
20694     
20695     remove: function() 
20696     {
20697         this.picker().remove();
20698     }
20699    
20700 });
20701
20702 Roo.apply(Roo.bootstrap.MonthField,  {
20703     
20704     content : {
20705         tag: 'tbody',
20706         cn: [
20707         {
20708             tag: 'tr',
20709             cn: [
20710             {
20711                 tag: 'td',
20712                 colspan: '7'
20713             }
20714             ]
20715         }
20716         ]
20717     },
20718     
20719     dates:{
20720         en: {
20721             months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
20722             monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20723         }
20724     }
20725 });
20726
20727 Roo.apply(Roo.bootstrap.MonthField,  {
20728   
20729     template : {
20730         tag: 'div',
20731         cls: 'datepicker dropdown-menu roo-dynamic',
20732         cn: [
20733             {
20734                 tag: 'div',
20735                 cls: 'datepicker-months',
20736                 cn: [
20737                 {
20738                     tag: 'table',
20739                     cls: 'table-condensed',
20740                     cn:[
20741                         Roo.bootstrap.DateField.content
20742                     ]
20743                 }
20744                 ]
20745             }
20746         ]
20747     }
20748 });
20749
20750  
20751
20752  
20753  /*
20754  * - LGPL
20755  *
20756  * CheckBox
20757  * 
20758  */
20759
20760 /**
20761  * @class Roo.bootstrap.CheckBox
20762  * @extends Roo.bootstrap.Input
20763  * Bootstrap CheckBox class
20764  * 
20765  * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20766  * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20767  * @cfg {String} boxLabel The text that appears beside the checkbox
20768  * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20769  * @cfg {Boolean} checked initnal the element
20770  * @cfg {Boolean} inline inline the element (default false)
20771  * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20772  * @cfg {String} tooltip label tooltip
20773  * 
20774  * @constructor
20775  * Create a new CheckBox
20776  * @param {Object} config The config object
20777  */
20778
20779 Roo.bootstrap.CheckBox = function(config){
20780     Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20781    
20782     this.addEvents({
20783         /**
20784         * @event check
20785         * Fires when the element is checked or unchecked.
20786         * @param {Roo.bootstrap.CheckBox} this This input
20787         * @param {Boolean} checked The new checked value
20788         */
20789        check : true,
20790        /**
20791         * @event click
20792         * Fires when the element is click.
20793         * @param {Roo.bootstrap.CheckBox} this This input
20794         */
20795        click : true
20796     });
20797     
20798 };
20799
20800 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
20801   
20802     inputType: 'checkbox',
20803     inputValue: 1,
20804     valueOff: 0,
20805     boxLabel: false,
20806     checked: false,
20807     weight : false,
20808     inline: false,
20809     tooltip : '',
20810     
20811     getAutoCreate : function()
20812     {
20813         var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20814         
20815         var id = Roo.id();
20816         
20817         var cfg = {};
20818         
20819         cfg.cls = 'form-group ' + this.inputType; //input-group
20820         
20821         if(this.inline){
20822             cfg.cls += ' ' + this.inputType + '-inline';
20823         }
20824         
20825         var input =  {
20826             tag: 'input',
20827             id : id,
20828             type : this.inputType,
20829             value : this.inputValue,
20830             cls : 'roo-' + this.inputType, //'form-box',
20831             placeholder : this.placeholder || ''
20832             
20833         };
20834         
20835         if(this.inputType != 'radio'){
20836             var hidden =  {
20837                 tag: 'input',
20838                 type : 'hidden',
20839                 cls : 'roo-hidden-value',
20840                 value : this.checked ? this.inputValue : this.valueOff
20841             };
20842         }
20843         
20844             
20845         if (this.weight) { // Validity check?
20846             cfg.cls += " " + this.inputType + "-" + this.weight;
20847         }
20848         
20849         if (this.disabled) {
20850             input.disabled=true;
20851         }
20852         
20853         if(this.checked){
20854             input.checked = this.checked;
20855         }
20856         
20857         if (this.name) {
20858             
20859             input.name = this.name;
20860             
20861             if(this.inputType != 'radio'){
20862                 hidden.name = this.name;
20863                 input.name = '_hidden_' + this.name;
20864             }
20865         }
20866         
20867         if (this.size) {
20868             input.cls += ' input-' + this.size;
20869         }
20870         
20871         var settings=this;
20872         
20873         ['xs','sm','md','lg'].map(function(size){
20874             if (settings[size]) {
20875                 cfg.cls += ' col-' + size + '-' + settings[size];
20876             }
20877         });
20878         
20879         var inputblock = input;
20880          
20881         if (this.before || this.after) {
20882             
20883             inputblock = {
20884                 cls : 'input-group',
20885                 cn :  [] 
20886             };
20887             
20888             if (this.before) {
20889                 inputblock.cn.push({
20890                     tag :'span',
20891                     cls : 'input-group-addon',
20892                     html : this.before
20893                 });
20894             }
20895             
20896             inputblock.cn.push(input);
20897             
20898             if(this.inputType != 'radio'){
20899                 inputblock.cn.push(hidden);
20900             }
20901             
20902             if (this.after) {
20903                 inputblock.cn.push({
20904                     tag :'span',
20905                     cls : 'input-group-addon',
20906                     html : this.after
20907                 });
20908             }
20909             
20910         }
20911         
20912         if (align ==='left' && this.fieldLabel.length) {
20913 //                Roo.log("left and has label");
20914             cfg.cn = [
20915                 {
20916                     tag: 'label',
20917                     'for' :  id,
20918                     cls : 'control-label',
20919                     html : this.fieldLabel
20920                 },
20921                 {
20922                     cls : "", 
20923                     cn: [
20924                         inputblock
20925                     ]
20926                 }
20927             ];
20928             
20929             if(this.labelWidth > 12){
20930                 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20931             }
20932             
20933             if(this.labelWidth < 13 && this.labelmd == 0){
20934                 this.labelmd = this.labelWidth;
20935             }
20936             
20937             if(this.labellg > 0){
20938                 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20939                 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20940             }
20941             
20942             if(this.labelmd > 0){
20943                 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20944                 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20945             }
20946             
20947             if(this.labelsm > 0){
20948                 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20949                 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20950             }
20951             
20952             if(this.labelxs > 0){
20953                 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20954                 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20955             }
20956             
20957         } else if ( this.fieldLabel.length) {
20958 //                Roo.log(" label");
20959                 cfg.cn = [
20960                    
20961                     {
20962                         tag: this.boxLabel ? 'span' : 'label',
20963                         'for': id,
20964                         cls: 'control-label box-input-label',
20965                         //cls : 'input-group-addon',
20966                         html : this.fieldLabel
20967                     },
20968                     
20969                     inputblock
20970                     
20971                 ];
20972
20973         } else {
20974             
20975 //                Roo.log(" no label && no align");
20976                 cfg.cn = [  inputblock ] ;
20977                 
20978                 
20979         }
20980         
20981         if(this.boxLabel){
20982              var boxLabelCfg = {
20983                 tag: 'label',
20984                 //'for': id, // box label is handled by onclick - so no for...
20985                 cls: 'box-label',
20986                 html: this.boxLabel
20987             };
20988             
20989             if(this.tooltip){
20990                 boxLabelCfg.tooltip = this.tooltip;
20991             }
20992              
20993             cfg.cn.push(boxLabelCfg);
20994         }
20995         
20996         if(this.inputType != 'radio'){
20997             cfg.cn.push(hidden);
20998         }
20999         
21000         return cfg;
21001         
21002     },
21003     
21004     /**
21005      * return the real input element.
21006      */
21007     inputEl: function ()
21008     {
21009         return this.el.select('input.roo-' + this.inputType,true).first();
21010     },
21011     hiddenEl: function ()
21012     {
21013         return this.el.select('input.roo-hidden-value',true).first();
21014     },
21015     
21016     labelEl: function()
21017     {
21018         return this.el.select('label.control-label',true).first();
21019     },
21020     /* depricated... */
21021     
21022     label: function()
21023     {
21024         return this.labelEl();
21025     },
21026     
21027     boxLabelEl: function()
21028     {
21029         return this.el.select('label.box-label',true).first();
21030     },
21031     
21032     initEvents : function()
21033     {
21034 //        Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
21035         
21036         this.inputEl().on('click', this.onClick,  this);
21037         
21038         if (this.boxLabel) { 
21039             this.el.select('label.box-label',true).first().on('click', this.onClick,  this);
21040         }
21041         
21042         this.startValue = this.getValue();
21043         
21044         if(this.groupId){
21045             Roo.bootstrap.CheckBox.register(this);
21046         }
21047     },
21048     
21049     onClick : function(e)
21050     {   
21051         if(this.fireEvent('click', this, e) !== false){
21052             this.setChecked(!this.checked);
21053         }
21054         
21055     },
21056     
21057     setChecked : function(state,suppressEvent)
21058     {
21059         this.startValue = this.getValue();
21060
21061         if(this.inputType == 'radio'){
21062             
21063             Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21064                 e.dom.checked = false;
21065             });
21066             
21067             this.inputEl().dom.checked = true;
21068             
21069             this.inputEl().dom.value = this.inputValue;
21070             
21071             if(suppressEvent !== true){
21072                 this.fireEvent('check', this, true);
21073             }
21074             
21075             this.validate();
21076             
21077             return;
21078         }
21079         
21080         this.checked = state;
21081         
21082         this.inputEl().dom.checked = state;
21083         
21084         
21085         this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
21086         
21087         if(suppressEvent !== true){
21088             this.fireEvent('check', this, state);
21089         }
21090         
21091         this.validate();
21092     },
21093     
21094     getValue : function()
21095     {
21096         if(this.inputType == 'radio'){
21097             return this.getGroupValue();
21098         }
21099         
21100         return this.hiddenEl().dom.value;
21101         
21102     },
21103     
21104     getGroupValue : function()
21105     {
21106         if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
21107             return '';
21108         }
21109         
21110         return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
21111     },
21112     
21113     setValue : function(v,suppressEvent)
21114     {
21115         if(this.inputType == 'radio'){
21116             this.setGroupValue(v, suppressEvent);
21117             return;
21118         }
21119         
21120         this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
21121         
21122         this.validate();
21123     },
21124     
21125     setGroupValue : function(v, suppressEvent)
21126     {
21127         this.startValue = this.getValue();
21128         
21129         Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21130             e.dom.checked = false;
21131             
21132             if(e.dom.value == v){
21133                 e.dom.checked = true;
21134             }
21135         });
21136         
21137         if(suppressEvent !== true){
21138             this.fireEvent('check', this, true);
21139         }
21140
21141         this.validate();
21142         
21143         return;
21144     },
21145     
21146     validate : function()
21147     {
21148         if(this.getVisibilityEl().hasClass('hidden')){
21149             return true;
21150         }
21151         
21152         if(
21153                 this.disabled || 
21154                 (this.inputType == 'radio' && this.validateRadio()) ||
21155                 (this.inputType == 'checkbox' && this.validateCheckbox())
21156         ){
21157             this.markValid();
21158             return true;
21159         }
21160         
21161         this.markInvalid();
21162         return false;
21163     },
21164     
21165     validateRadio : function()
21166     {
21167         if(this.getVisibilityEl().hasClass('hidden')){
21168             return true;
21169         }
21170         
21171         if(this.allowBlank){
21172             return true;
21173         }
21174         
21175         var valid = false;
21176         
21177         Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21178             if(!e.dom.checked){
21179                 return;
21180             }
21181             
21182             valid = true;
21183             
21184             return false;
21185         });
21186         
21187         return valid;
21188     },
21189     
21190     validateCheckbox : function()
21191     {
21192         if(!this.groupId){
21193             return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
21194             //return (this.getValue() == this.inputValue) ? true : false;
21195         }
21196         
21197         var group = Roo.bootstrap.CheckBox.get(this.groupId);
21198         
21199         if(!group){
21200             return false;
21201         }
21202         
21203         var r = false;
21204         
21205         for(var i in group){
21206             if(group[i].el.isVisible(true)){
21207                 r = false;
21208                 break;
21209             }
21210             
21211             r = true;
21212         }
21213         
21214         for(var i in group){
21215             if(r){
21216                 break;
21217             }
21218             
21219             r = (group[i].getValue() == group[i].inputValue) ? true : false;
21220         }
21221         
21222         return r;
21223     },
21224     
21225     /**
21226      * Mark this field as valid
21227      */
21228     markValid : function()
21229     {
21230         var _this = this;
21231         
21232         this.fireEvent('valid', this);
21233         
21234         var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21235         
21236         if(this.groupId){
21237             label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
21238         }
21239         
21240         if(label){
21241             label.markValid();
21242         }
21243
21244         if(this.inputType == 'radio'){
21245             Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21246                 var fg = e.findParent('.form-group', false, true);
21247                 if (Roo.bootstrap.version == 3) {
21248                     fg.removeClass([_this.invalidClass, _this.validClass]);
21249                     fg.addClass(_this.validClass);
21250                 } else {
21251                     fg.removeClass(['is-valid', 'is-invalid']);
21252                     fg.addClass('is-valid');
21253                 }
21254             });
21255             
21256             return;
21257         }
21258
21259         if(!this.groupId){
21260             var fg = this.el.findParent('.form-group', false, true);
21261             if (Roo.bootstrap.version == 3) {
21262                 fg.removeClass([this.invalidClass, this.validClass]);
21263                 fg.addClass(this.validClass);
21264             } else {
21265                 fg.removeClass(['is-valid', 'is-invalid']);
21266                 fg.addClass('is-valid');
21267             }
21268             return;
21269         }
21270         
21271         var group = Roo.bootstrap.CheckBox.get(this.groupId);
21272         
21273         if(!group){
21274             return;
21275         }
21276         
21277         for(var i in group){
21278             var fg = group[i].el.findParent('.form-group', false, true);
21279             if (Roo.bootstrap.version == 3) {
21280                 fg.removeClass([this.invalidClass, this.validClass]);
21281                 fg.addClass(this.validClass);
21282             } else {
21283                 fg.removeClass(['is-valid', 'is-invalid']);
21284                 fg.addClass('is-valid');
21285             }
21286         }
21287     },
21288     
21289      /**
21290      * Mark this field as invalid
21291      * @param {String} msg The validation message
21292      */
21293     markInvalid : function(msg)
21294     {
21295         if(this.allowBlank){
21296             return;
21297         }
21298         
21299         var _this = this;
21300         
21301         this.fireEvent('invalid', this, msg);
21302         
21303         var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21304         
21305         if(this.groupId){
21306             label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
21307         }
21308         
21309         if(label){
21310             label.markInvalid();
21311         }
21312             
21313         if(this.inputType == 'radio'){
21314             
21315             Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21316                 var fg = e.findParent('.form-group', false, true);
21317                 if (Roo.bootstrap.version == 3) {
21318                     fg.removeClass([_this.invalidClass, _this.validClass]);
21319                     fg.addClass(_this.invalidClass);
21320                 } else {
21321                     fg.removeClass(['is-invalid', 'is-valid']);
21322                     fg.addClass('is-invalid');
21323                 }
21324             });
21325             
21326             return;
21327         }
21328         
21329         if(!this.groupId){
21330             var fg = this.el.findParent('.form-group', false, true);
21331             if (Roo.bootstrap.version == 3) {
21332                 fg.removeClass([_this.invalidClass, _this.validClass]);
21333                 fg.addClass(_this.invalidClass);
21334             } else {
21335                 fg.removeClass(['is-invalid', 'is-valid']);
21336                 fg.addClass('is-invalid');
21337             }
21338             return;
21339         }
21340         
21341         var group = Roo.bootstrap.CheckBox.get(this.groupId);
21342         
21343         if(!group){
21344             return;
21345         }
21346         
21347         for(var i in group){
21348             var fg = group[i].el.findParent('.form-group', false, true);
21349             if (Roo.bootstrap.version == 3) {
21350                 fg.removeClass([_this.invalidClass, _this.validClass]);
21351                 fg.addClass(_this.invalidClass);
21352             } else {
21353                 fg.removeClass(['is-invalid', 'is-valid']);
21354                 fg.addClass('is-invalid');
21355             }
21356         }
21357         
21358     },
21359     
21360     clearInvalid : function()
21361     {
21362         Roo.bootstrap.Input.prototype.clearInvalid.call(this);
21363         
21364         // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21365         
21366         var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21367         
21368         if (label && label.iconEl) {
21369             label.iconEl.removeClass([ label.validClass, label.invalidClass ]);
21370             label.iconEl.removeClass(['is-invalid', 'is-valid']);
21371         }
21372     },
21373     
21374     disable : function()
21375     {
21376         if(this.inputType != 'radio'){
21377             Roo.bootstrap.CheckBox.superclass.disable.call(this);
21378             return;
21379         }
21380         
21381         var _this = this;
21382         
21383         if(this.rendered){
21384             Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21385                 _this.getActionEl().addClass(this.disabledClass);
21386                 e.dom.disabled = true;
21387             });
21388         }
21389         
21390         this.disabled = true;
21391         this.fireEvent("disable", this);
21392         return this;
21393     },
21394
21395     enable : function()
21396     {
21397         if(this.inputType != 'radio'){
21398             Roo.bootstrap.CheckBox.superclass.enable.call(this);
21399             return;
21400         }
21401         
21402         var _this = this;
21403         
21404         if(this.rendered){
21405             Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21406                 _this.getActionEl().removeClass(this.disabledClass);
21407                 e.dom.disabled = false;
21408             });
21409         }
21410         
21411         this.disabled = false;
21412         this.fireEvent("enable", this);
21413         return this;
21414     },
21415     
21416     setBoxLabel : function(v)
21417     {
21418         this.boxLabel = v;
21419         
21420         if(this.rendered){
21421             this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21422         }
21423     }
21424
21425 });
21426
21427 Roo.apply(Roo.bootstrap.CheckBox, {
21428     
21429     groups: {},
21430     
21431      /**
21432     * register a CheckBox Group
21433     * @param {Roo.bootstrap.CheckBox} the CheckBox to add
21434     */
21435     register : function(checkbox)
21436     {
21437         if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
21438             this.groups[checkbox.groupId] = {};
21439         }
21440         
21441         if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
21442             return;
21443         }
21444         
21445         this.groups[checkbox.groupId][checkbox.name] = checkbox;
21446         
21447     },
21448     /**
21449     * fetch a CheckBox Group based on the group ID
21450     * @param {string} the group ID
21451     * @returns {Roo.bootstrap.CheckBox} the CheckBox group
21452     */
21453     get: function(groupId) {
21454         if (typeof(this.groups[groupId]) == 'undefined') {
21455             return false;
21456         }
21457         
21458         return this.groups[groupId] ;
21459     }
21460     
21461     
21462 });
21463 /*
21464  * - LGPL
21465  *
21466  * RadioItem
21467  * 
21468  */
21469
21470 /**
21471  * @class Roo.bootstrap.Radio
21472  * @extends Roo.bootstrap.Component
21473  * Bootstrap Radio class
21474  * @cfg {String} boxLabel - the label associated
21475  * @cfg {String} value - the value of radio
21476  * 
21477  * @constructor
21478  * Create a new Radio
21479  * @param {Object} config The config object
21480  */
21481 Roo.bootstrap.Radio = function(config){
21482     Roo.bootstrap.Radio.superclass.constructor.call(this, config);
21483     
21484 };
21485
21486 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
21487     
21488     boxLabel : '',
21489     
21490     value : '',
21491     
21492     getAutoCreate : function()
21493     {
21494         var cfg = {
21495             tag : 'div',
21496             cls : 'form-group radio',
21497             cn : [
21498                 {
21499                     tag : 'label',
21500                     cls : 'box-label',
21501                     html : this.boxLabel
21502                 }
21503             ]
21504         };
21505         
21506         return cfg;
21507     },
21508     
21509     initEvents : function() 
21510     {
21511         this.parent().register(this);
21512         
21513         this.el.on('click', this.onClick, this);
21514         
21515     },
21516     
21517     onClick : function(e)
21518     {
21519         if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
21520             this.setChecked(true);
21521         }
21522     },
21523     
21524     setChecked : function(state, suppressEvent)
21525     {
21526         this.parent().setValue(this.value, suppressEvent);
21527         
21528     },
21529     
21530     setBoxLabel : function(v)
21531     {
21532         this.boxLabel = v;
21533         
21534         if(this.rendered){
21535             this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21536         }
21537     }
21538     
21539 });
21540  
21541
21542  /*
21543  * - LGPL
21544  *
21545  * Input
21546  * 
21547  */
21548
21549 /**
21550  * @class Roo.bootstrap.SecurePass
21551  * @extends Roo.bootstrap.Input
21552  * Bootstrap SecurePass class
21553  *
21554  * 
21555  * @constructor
21556  * Create a new SecurePass
21557  * @param {Object} config The config object
21558  */
21559  
21560 Roo.bootstrap.SecurePass = function (config) {
21561     // these go here, so the translation tool can replace them..
21562     this.errors = {
21563         PwdEmpty: "Please type a password, and then retype it to confirm.",
21564         PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21565         PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21566         PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21567         IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21568         FNInPwd: "Your password can't contain your first name. Please type a different password.",
21569         LNInPwd: "Your password can't contain your last name. Please type a different password.",
21570         TooWeak: "Your password is Too Weak."
21571     },
21572     this.meterLabel = "Password strength:";
21573     this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
21574     this.meterClass = [
21575         "roo-password-meter-tooweak", 
21576         "roo-password-meter-weak", 
21577         "roo-password-meter-medium", 
21578         "roo-password-meter-strong", 
21579         "roo-password-meter-grey"
21580     ];
21581     
21582     this.errors = {};
21583     
21584     Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
21585 }
21586
21587 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
21588     /**
21589      * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
21590      * {
21591      *  PwdEmpty: "Please type a password, and then retype it to confirm.",
21592      *  PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21593      *  PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21594      *  PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21595      *  IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21596      *  FNInPwd: "Your password can't contain your first name. Please type a different password.",
21597      *  LNInPwd: "Your password can't contain your last name. Please type a different password."
21598      * })
21599      */
21600     // private
21601     
21602     meterWidth: 300,
21603     errorMsg :'',    
21604     errors: false,
21605     imageRoot: '/',
21606     /**
21607      * @cfg {String/Object} Label for the strength meter (defaults to
21608      * 'Password strength:')
21609      */
21610     // private
21611     meterLabel: '',
21612     /**
21613      * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
21614      * ['Weak', 'Medium', 'Strong'])
21615      */
21616     // private    
21617     pwdStrengths: false,    
21618     // private
21619     strength: 0,
21620     // private
21621     _lastPwd: null,
21622     // private
21623     kCapitalLetter: 0,
21624     kSmallLetter: 1,
21625     kDigit: 2,
21626     kPunctuation: 3,
21627     
21628     insecure: false,
21629     // private
21630     initEvents: function ()
21631     {
21632         Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
21633
21634         if (this.el.is('input[type=password]') && Roo.isSafari) {
21635             this.el.on('keydown', this.SafariOnKeyDown, this);
21636         }
21637
21638         this.el.on('keyup', this.checkStrength, this, {buffer: 50});
21639     },
21640     // private
21641     onRender: function (ct, position)
21642     {
21643         Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
21644         this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
21645         this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
21646
21647         this.trigger.createChild({
21648                    cn: [
21649                     {
21650                     //id: 'PwdMeter',
21651                     tag: 'div',
21652                     cls: 'roo-password-meter-grey col-xs-12',
21653                     style: {
21654                         //width: 0,
21655                         //width: this.meterWidth + 'px'                                                
21656                         }
21657                     },
21658                     {                            
21659                          cls: 'roo-password-meter-text'                          
21660                     }
21661                 ]            
21662         });
21663
21664          
21665         if (this.hideTrigger) {
21666             this.trigger.setDisplayed(false);
21667         }
21668         this.setSize(this.width || '', this.height || '');
21669     },
21670     // private
21671     onDestroy: function ()
21672     {
21673         if (this.trigger) {
21674             this.trigger.removeAllListeners();
21675             this.trigger.remove();
21676         }
21677         if (this.wrap) {
21678             this.wrap.remove();
21679         }
21680         Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
21681     },
21682     // private
21683     checkStrength: function ()
21684     {
21685         var pwd = this.inputEl().getValue();
21686         if (pwd == this._lastPwd) {
21687             return;
21688         }
21689
21690         var strength;
21691         if (this.ClientSideStrongPassword(pwd)) {
21692             strength = 3;
21693         } else if (this.ClientSideMediumPassword(pwd)) {
21694             strength = 2;
21695         } else if (this.ClientSideWeakPassword(pwd)) {
21696             strength = 1;
21697         } else {
21698             strength = 0;
21699         }
21700         
21701         Roo.log('strength1: ' + strength);
21702         
21703         //var pm = this.trigger.child('div/div/div').dom;
21704         var pm = this.trigger.child('div/div');
21705         pm.removeClass(this.meterClass);
21706         pm.addClass(this.meterClass[strength]);
21707                 
21708         
21709         var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;        
21710                 
21711         pt.innerHTML = this.meterLabel + '&nbsp;' + this.pwdStrengths[strength];
21712         
21713         this._lastPwd = pwd;
21714     },
21715     reset: function ()
21716     {
21717         Roo.bootstrap.SecurePass.superclass.reset.call(this);
21718         
21719         this._lastPwd = '';
21720         
21721         var pm = this.trigger.child('div/div');
21722         pm.removeClass(this.meterClass);
21723         pm.addClass('roo-password-meter-grey');        
21724         
21725         
21726         var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;        
21727         
21728         pt.innerHTML = '';
21729         this.inputEl().dom.type='password';
21730     },
21731     // private
21732     validateValue: function (value)
21733     {
21734         
21735         if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
21736             return false;
21737         }
21738         if (value.length == 0) {
21739             if (this.allowBlank) {
21740                 this.clearInvalid();
21741                 return true;
21742             }
21743
21744             this.markInvalid(this.errors.PwdEmpty);
21745             this.errorMsg = this.errors.PwdEmpty;
21746             return false;
21747         }
21748         
21749         if(this.insecure){
21750             return true;
21751         }
21752         
21753         if ('[\x21-\x7e]*'.match(value)) {
21754             this.markInvalid(this.errors.PwdBadChar);
21755             this.errorMsg = this.errors.PwdBadChar;
21756             return false;
21757         }
21758         if (value.length < 6) {
21759             this.markInvalid(this.errors.PwdShort);
21760             this.errorMsg = this.errors.PwdShort;
21761             return false;
21762         }
21763         if (value.length > 16) {
21764             this.markInvalid(this.errors.PwdLong);
21765             this.errorMsg = this.errors.PwdLong;
21766             return false;
21767         }
21768         var strength;
21769         if (this.ClientSideStrongPassword(value)) {
21770             strength = 3;
21771         } else if (this.ClientSideMediumPassword(value)) {
21772             strength = 2;
21773         } else if (this.ClientSideWeakPassword(value)) {
21774             strength = 1;
21775         } else {
21776             strength = 0;
21777         }
21778
21779         
21780         if (strength < 2) {
21781             //this.markInvalid(this.errors.TooWeak);
21782             this.errorMsg = this.errors.TooWeak;
21783             //return false;
21784         }
21785         
21786         
21787         console.log('strength2: ' + strength);
21788         
21789         //var pm = this.trigger.child('div/div/div').dom;
21790         
21791         var pm = this.trigger.child('div/div');
21792         pm.removeClass(this.meterClass);
21793         pm.addClass(this.meterClass[strength]);
21794                 
21795         var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;        
21796                 
21797         pt.innerHTML = this.meterLabel + '&nbsp;' + this.pwdStrengths[strength];
21798         
21799         this.errorMsg = ''; 
21800         return true;
21801     },
21802     // private
21803     CharacterSetChecks: function (type)
21804     {
21805         this.type = type;
21806         this.fResult = false;
21807     },
21808     // private
21809     isctype: function (character, type)
21810     {
21811         switch (type) {  
21812             case this.kCapitalLetter:
21813                 if (character >= 'A' && character <= 'Z') {
21814                     return true;
21815                 }
21816                 break;
21817             
21818             case this.kSmallLetter:
21819                 if (character >= 'a' && character <= 'z') {
21820                     return true;
21821                 }
21822                 break;
21823             
21824             case this.kDigit:
21825                 if (character >= '0' && character <= '9') {
21826                     return true;
21827                 }
21828                 break;
21829             
21830             case this.kPunctuation:
21831                 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21832                     return true;
21833                 }
21834                 break;
21835             
21836             default:
21837                 return false;
21838         }
21839
21840     },
21841     // private
21842     IsLongEnough: function (pwd, size)
21843     {
21844         return !(pwd == null || isNaN(size) || pwd.length < size);
21845     },
21846     // private
21847     SpansEnoughCharacterSets: function (word, nb)
21848     {
21849         if (!this.IsLongEnough(word, nb))
21850         {
21851             return false;
21852         }
21853
21854         var characterSetChecks = new Array(
21855             new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21856             new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21857         );
21858         
21859         for (var index = 0; index < word.length; ++index) {
21860             for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21861                 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21862                     characterSetChecks[nCharSet].fResult = true;
21863                     break;
21864                 }
21865             }
21866         }
21867
21868         var nCharSets = 0;
21869         for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21870             if (characterSetChecks[nCharSet].fResult) {
21871                 ++nCharSets;
21872             }
21873         }
21874
21875         if (nCharSets < nb) {
21876             return false;
21877         }
21878         return true;
21879     },
21880     // private
21881     ClientSideStrongPassword: function (pwd)
21882     {
21883         return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21884     },
21885     // private
21886     ClientSideMediumPassword: function (pwd)
21887     {
21888         return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21889     },
21890     // private
21891     ClientSideWeakPassword: function (pwd)
21892     {
21893         return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21894     }
21895           
21896 })//<script type="text/javascript">
21897
21898 /*
21899  * Based  Ext JS Library 1.1.1
21900  * Copyright(c) 2006-2007, Ext JS, LLC.
21901  * LGPL
21902  *
21903  */
21904  
21905 /**
21906  * @class Roo.HtmlEditorCore
21907  * @extends Roo.Component
21908  * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21909  *
21910  * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21911  */
21912
21913 Roo.HtmlEditorCore = function(config){
21914     
21915     
21916     Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21917     
21918     
21919     this.addEvents({
21920         /**
21921          * @event initialize
21922          * Fires when the editor is fully initialized (including the iframe)
21923          * @param {Roo.HtmlEditorCore} this
21924          */
21925         initialize: true,
21926         /**
21927          * @event activate
21928          * Fires when the editor is first receives the focus. Any insertion must wait
21929          * until after this event.
21930          * @param {Roo.HtmlEditorCore} this
21931          */
21932         activate: true,
21933          /**
21934          * @event beforesync
21935          * Fires before the textarea is updated with content from the editor iframe. Return false
21936          * to cancel the sync.
21937          * @param {Roo.HtmlEditorCore} this
21938          * @param {String} html
21939          */
21940         beforesync: true,
21941          /**
21942          * @event beforepush
21943          * Fires before the iframe editor is updated with content from the textarea. Return false
21944          * to cancel the push.
21945          * @param {Roo.HtmlEditorCore} this
21946          * @param {String} html
21947          */
21948         beforepush: true,
21949          /**
21950          * @event sync
21951          * Fires when the textarea is updated with content from the editor iframe.
21952          * @param {Roo.HtmlEditorCore} this
21953          * @param {String} html
21954          */
21955         sync: true,
21956          /**
21957          * @event push
21958          * Fires when the iframe editor is updated with content from the textarea.
21959          * @param {Roo.HtmlEditorCore} this
21960          * @param {String} html
21961          */
21962         push: true,
21963         
21964         /**
21965          * @event editorevent
21966          * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21967          * @param {Roo.HtmlEditorCore} this
21968          */
21969         editorevent: true
21970         
21971     });
21972     
21973     // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21974     
21975     // defaults : white / black...
21976     this.applyBlacklists();
21977     
21978     
21979     
21980 };
21981
21982
21983 Roo.extend(Roo.HtmlEditorCore, Roo.Component,  {
21984
21985
21986      /**
21987      * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field 
21988      */
21989     
21990     owner : false,
21991     
21992      /**
21993      * @cfg {String} resizable  's' or 'se' or 'e' - wrapps the element in a
21994      *                        Roo.resizable.
21995      */
21996     resizable : false,
21997      /**
21998      * @cfg {Number} height (in pixels)
21999      */   
22000     height: 300,
22001    /**
22002      * @cfg {Number} width (in pixels)
22003      */   
22004     width: 500,
22005     
22006     /**
22007      * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
22008      * 
22009      */
22010     stylesheets: false,
22011     
22012     // id of frame..
22013     frameId: false,
22014     
22015     // private properties
22016     validationEvent : false,
22017     deferHeight: true,
22018     initialized : false,
22019     activated : false,
22020     sourceEditMode : false,
22021     onFocus : Roo.emptyFn,
22022     iframePad:3,
22023     hideMode:'offsets',
22024     
22025     clearUp: true,
22026     
22027     // blacklist + whitelisted elements..
22028     black: false,
22029     white: false,
22030      
22031     bodyCls : '',
22032
22033     /**
22034      * Protected method that will not generally be called directly. It
22035      * is called when the editor initializes the iframe with HTML contents. Override this method if you
22036      * want to change the initialization markup of the iframe (e.g. to add stylesheets).
22037      */
22038     getDocMarkup : function(){
22039         // body styles..
22040         var st = '';
22041         
22042         // inherit styels from page...?? 
22043         if (this.stylesheets === false) {
22044             
22045             Roo.get(document.head).select('style').each(function(node) {
22046                 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
22047             });
22048             
22049             Roo.get(document.head).select('link').each(function(node) { 
22050                 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
22051             });
22052             
22053         } else if (!this.stylesheets.length) {
22054                 // simple..
22055                 st = '<style type="text/css">' +
22056                     'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
22057                    '</style>';
22058         } else { 
22059             st = '<style type="text/css">' +
22060                     this.stylesheets +
22061                 '</style>';
22062         }
22063         
22064         st +=  '<style type="text/css">' +
22065             'IMG { cursor: pointer } ' +
22066         '</style>';
22067
22068         var cls = 'roo-htmleditor-body';
22069         
22070         if(this.bodyCls.length){
22071             cls += ' ' + this.bodyCls;
22072         }
22073         
22074         return '<html><head>' + st  +
22075             //<style type="text/css">' +
22076             //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
22077             //'</style>' +
22078             ' </head><body class="' +  cls + '"></body></html>';
22079     },
22080
22081     // private
22082     onRender : function(ct, position)
22083     {
22084         var _t = this;
22085         //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
22086         this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
22087         
22088         
22089         this.el.dom.style.border = '0 none';
22090         this.el.dom.setAttribute('tabIndex', -1);
22091         this.el.addClass('x-hidden hide');
22092         
22093         
22094         
22095         if(Roo.isIE){ // fix IE 1px bogus margin
22096             this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
22097         }
22098        
22099         
22100         this.frameId = Roo.id();
22101         
22102          
22103         
22104         var iframe = this.owner.wrap.createChild({
22105             tag: 'iframe',
22106             cls: 'form-control', // bootstrap..
22107             id: this.frameId,
22108             name: this.frameId,
22109             frameBorder : 'no',
22110             'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL  :  "javascript:false"
22111         }, this.el
22112         );
22113         
22114         
22115         this.iframe = iframe.dom;
22116
22117          this.assignDocWin();
22118         
22119         this.doc.designMode = 'on';
22120        
22121         this.doc.open();
22122         this.doc.write(this.getDocMarkup());
22123         this.doc.close();
22124
22125         
22126         var task = { // must defer to wait for browser to be ready
22127             run : function(){
22128                 //console.log("run task?" + this.doc.readyState);
22129                 this.assignDocWin();
22130                 if(this.doc.body || this.doc.readyState == 'complete'){
22131                     try {
22132                         this.doc.designMode="on";
22133                     } catch (e) {
22134                         return;
22135                     }
22136                     Roo.TaskMgr.stop(task);
22137                     this.initEditor.defer(10, this);
22138                 }
22139             },
22140             interval : 10,
22141             duration: 10000,
22142             scope: this
22143         };
22144         Roo.TaskMgr.start(task);
22145
22146     },
22147
22148     // private
22149     onResize : function(w, h)
22150     {
22151          Roo.log('resize: ' +w + ',' + h );
22152         //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
22153         if(!this.iframe){
22154             return;
22155         }
22156         if(typeof w == 'number'){
22157             
22158             this.iframe.style.width = w + 'px';
22159         }
22160         if(typeof h == 'number'){
22161             
22162             this.iframe.style.height = h + 'px';
22163             if(this.doc){
22164                 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
22165             }
22166         }
22167         
22168     },
22169
22170     /**
22171      * Toggles the editor between standard and source edit mode.
22172      * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
22173      */
22174     toggleSourceEdit : function(sourceEditMode){
22175         
22176         this.sourceEditMode = sourceEditMode === true;
22177         
22178         if(this.sourceEditMode){
22179  
22180             Roo.get(this.iframe).addClass(['x-hidden','hide']);     //FIXME - what's the BS styles for these
22181             
22182         }else{
22183             Roo.get(this.iframe).removeClass(['x-hidden','hide']);
22184             //this.iframe.className = '';
22185             this.deferFocus();
22186         }
22187         //this.setSize(this.owner.wrap.getSize());
22188         //this.fireEvent('editmodechange', this, this.sourceEditMode);
22189     },
22190
22191     
22192   
22193
22194     /**
22195      * Protected method that will not generally be called directly. If you need/want
22196      * custom HTML cleanup, this is the method you should override.
22197      * @param {String} html The HTML to be cleaned
22198      * return {String} The cleaned HTML
22199      */
22200     cleanHtml : function(html){
22201         html = String(html);
22202         if(html.length > 5){
22203             if(Roo.isSafari){ // strip safari nonsense
22204                 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
22205             }
22206         }
22207         if(html == '&nbsp;'){
22208             html = '';
22209         }
22210         return html;
22211     },
22212
22213     /**
22214      * HTML Editor -> Textarea
22215      * Protected method that will not generally be called directly. Syncs the contents
22216      * of the editor iframe with the textarea.
22217      */
22218     syncValue : function(){
22219         if(this.initialized){
22220             var bd = (this.doc.body || this.doc.documentElement);
22221             //this.cleanUpPaste(); -- this is done else where and causes havoc..
22222             var html = bd.innerHTML;
22223             if(Roo.isSafari){
22224                 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
22225                 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
22226                 if(m && m[1]){
22227                     html = '<div style="'+m[0]+'">' + html + '</div>';
22228                 }
22229             }
22230             html = this.cleanHtml(html);
22231             // fix up the special chars.. normaly like back quotes in word...
22232             // however we do not want to do this with chinese..
22233             html = html.replace(/([\x80-\uffff])/g, function (a, b) {
22234                 var cc = b.charCodeAt();
22235                 if (
22236                     (cc >= 0x4E00 && cc < 0xA000 ) ||
22237                     (cc >= 0x3400 && cc < 0x4E00 ) ||
22238                     (cc >= 0xf900 && cc < 0xfb00 )
22239                 ) {
22240                         return b;
22241                 }
22242                 return "&#"+cc+";" 
22243             });
22244             if(this.owner.fireEvent('beforesync', this, html) !== false){
22245                 this.el.dom.value = html;
22246                 this.owner.fireEvent('sync', this, html);
22247             }
22248         }
22249     },
22250
22251     /**
22252      * Protected method that will not generally be called directly. Pushes the value of the textarea
22253      * into the iframe editor.
22254      */
22255     pushValue : function(){
22256         if(this.initialized){
22257             var v = this.el.dom.value.trim();
22258             
22259 //            if(v.length < 1){
22260 //                v = '&#160;';
22261 //            }
22262             
22263             if(this.owner.fireEvent('beforepush', this, v) !== false){
22264                 var d = (this.doc.body || this.doc.documentElement);
22265                 d.innerHTML = v;
22266                 this.cleanUpPaste();
22267                 this.el.dom.value = d.innerHTML;
22268                 this.owner.fireEvent('push', this, v);
22269             }
22270         }
22271     },
22272
22273     // private
22274     deferFocus : function(){
22275         this.focus.defer(10, this);
22276     },
22277
22278     // doc'ed in Field
22279     focus : function(){
22280         if(this.win && !this.sourceEditMode){
22281             this.win.focus();
22282         }else{
22283             this.el.focus();
22284         }
22285     },
22286     
22287     assignDocWin: function()
22288     {
22289         var iframe = this.iframe;
22290         
22291          if(Roo.isIE){
22292             this.doc = iframe.contentWindow.document;
22293             this.win = iframe.contentWindow;
22294         } else {
22295 //            if (!Roo.get(this.frameId)) {
22296 //                return;
22297 //            }
22298 //            this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
22299 //            this.win = Roo.get(this.frameId).dom.contentWindow;
22300             
22301             if (!Roo.get(this.frameId) && !iframe.contentDocument) {
22302                 return;
22303             }
22304             
22305             this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
22306             this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
22307         }
22308     },
22309     
22310     // private
22311     initEditor : function(){
22312         //console.log("INIT EDITOR");
22313         this.assignDocWin();
22314         
22315         
22316         
22317         this.doc.designMode="on";
22318         this.doc.open();
22319         this.doc.write(this.getDocMarkup());
22320         this.doc.close();
22321         
22322         var dbody = (this.doc.body || this.doc.documentElement);
22323         //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
22324         // this copies styles from the containing element into thsi one..
22325         // not sure why we need all of this..
22326         //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
22327         
22328         //var ss = this.el.getStyles( 'background-image', 'background-repeat');
22329         //ss['background-attachment'] = 'fixed'; // w3c
22330         dbody.bgProperties = 'fixed'; // ie
22331         //Roo.DomHelper.applyStyles(dbody, ss);
22332         Roo.EventManager.on(this.doc, {
22333             //'mousedown': this.onEditorEvent,
22334             'mouseup': this.onEditorEvent,
22335             'dblclick': this.onEditorEvent,
22336             'click': this.onEditorEvent,
22337             'keyup': this.onEditorEvent,
22338             buffer:100,
22339             scope: this
22340         });
22341         if(Roo.isGecko){
22342             Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
22343         }
22344         if(Roo.isIE || Roo.isSafari || Roo.isOpera){
22345             Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
22346         }
22347         this.initialized = true;
22348
22349         this.owner.fireEvent('initialize', this);
22350         this.pushValue();
22351     },
22352
22353     // private
22354     onDestroy : function(){
22355         
22356         
22357         
22358         if(this.rendered){
22359             
22360             //for (var i =0; i < this.toolbars.length;i++) {
22361             //    // fixme - ask toolbars for heights?
22362             //    this.toolbars[i].onDestroy();
22363            // }
22364             
22365             //this.wrap.dom.innerHTML = '';
22366             //this.wrap.remove();
22367         }
22368     },
22369
22370     // private
22371     onFirstFocus : function(){
22372         
22373         this.assignDocWin();
22374         
22375         
22376         this.activated = true;
22377          
22378     
22379         if(Roo.isGecko){ // prevent silly gecko errors
22380             this.win.focus();
22381             var s = this.win.getSelection();
22382             if(!s.focusNode || s.focusNode.nodeType != 3){
22383                 var r = s.getRangeAt(0);
22384                 r.selectNodeContents((this.doc.body || this.doc.documentElement));
22385                 r.collapse(true);
22386                 this.deferFocus();
22387             }
22388             try{
22389                 this.execCmd('useCSS', true);
22390                 this.execCmd('styleWithCSS', false);
22391             }catch(e){}
22392         }
22393         this.owner.fireEvent('activate', this);
22394     },
22395
22396     // private
22397     adjustFont: function(btn){
22398         var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
22399         //if(Roo.isSafari){ // safari
22400         //    adjust *= 2;
22401        // }
22402         var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
22403         if(Roo.isSafari){ // safari
22404             var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
22405             v =  (v < 10) ? 10 : v;
22406             v =  (v > 48) ? 48 : v;
22407             v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
22408             
22409         }
22410         
22411         
22412         v = Math.max(1, v+adjust);
22413         
22414         this.execCmd('FontSize', v  );
22415     },
22416
22417     onEditorEvent : function(e)
22418     {
22419         this.owner.fireEvent('editorevent', this, e);
22420       //  this.updateToolbar();
22421         this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
22422     },
22423
22424     insertTag : function(tg)
22425     {
22426         // could be a bit smarter... -> wrap the current selected tRoo..
22427         if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
22428             
22429             range = this.createRange(this.getSelection());
22430             var wrappingNode = this.doc.createElement(tg.toLowerCase());
22431             wrappingNode.appendChild(range.extractContents());
22432             range.insertNode(wrappingNode);
22433
22434             return;
22435             
22436             
22437             
22438         }
22439         this.execCmd("formatblock",   tg);
22440         
22441     },
22442     
22443     insertText : function(txt)
22444     {
22445         
22446         
22447         var range = this.createRange();
22448         range.deleteContents();
22449                //alert(Sender.getAttribute('label'));
22450                
22451         range.insertNode(this.doc.createTextNode(txt));
22452     } ,
22453     
22454      
22455
22456     /**
22457      * Executes a Midas editor command on the editor document and performs necessary focus and
22458      * toolbar updates. <b>This should only be called after the editor is initialized.</b>
22459      * @param {String} cmd The Midas command
22460      * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22461      */
22462     relayCmd : function(cmd, value){
22463         this.win.focus();
22464         this.execCmd(cmd, value);
22465         this.owner.fireEvent('editorevent', this);
22466         //this.updateToolbar();
22467         this.owner.deferFocus();
22468     },
22469
22470     /**
22471      * Executes a Midas editor command directly on the editor document.
22472      * For visual commands, you should use {@link #relayCmd} instead.
22473      * <b>This should only be called after the editor is initialized.</b>
22474      * @param {String} cmd The Midas command
22475      * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22476      */
22477     execCmd : function(cmd, value){
22478         this.doc.execCommand(cmd, false, value === undefined ? null : value);
22479         this.syncValue();
22480     },
22481  
22482  
22483    
22484     /**
22485      * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
22486      * to insert tRoo.
22487      * @param {String} text | dom node.. 
22488      */
22489     insertAtCursor : function(text)
22490     {
22491         
22492         if(!this.activated){
22493             return;
22494         }
22495         /*
22496         if(Roo.isIE){
22497             this.win.focus();
22498             var r = this.doc.selection.createRange();
22499             if(r){
22500                 r.collapse(true);
22501                 r.pasteHTML(text);
22502                 this.syncValue();
22503                 this.deferFocus();
22504             
22505             }
22506             return;
22507         }
22508         */
22509         if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
22510             this.win.focus();
22511             
22512             
22513             // from jquery ui (MIT licenced)
22514             var range, node;
22515             var win = this.win;
22516             
22517             if (win.getSelection && win.getSelection().getRangeAt) {
22518                 range = win.getSelection().getRangeAt(0);
22519                 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
22520                 range.insertNode(node);
22521             } else if (win.document.selection && win.document.selection.createRange) {
22522                 // no firefox support
22523                 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22524                 win.document.selection.createRange().pasteHTML(txt);
22525             } else {
22526                 // no firefox support
22527                 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22528                 this.execCmd('InsertHTML', txt);
22529             } 
22530             
22531             this.syncValue();
22532             
22533             this.deferFocus();
22534         }
22535     },
22536  // private
22537     mozKeyPress : function(e){
22538         if(e.ctrlKey){
22539             var c = e.getCharCode(), cmd;
22540           
22541             if(c > 0){
22542                 c = String.fromCharCode(c).toLowerCase();
22543                 switch(c){
22544                     case 'b':
22545                         cmd = 'bold';
22546                         break;
22547                     case 'i':
22548                         cmd = 'italic';
22549                         break;
22550                     
22551                     case 'u':
22552                         cmd = 'underline';
22553                         break;
22554                     
22555                     case 'v':
22556                         this.cleanUpPaste.defer(100, this);
22557                         return;
22558                         
22559                 }
22560                 if(cmd){
22561                     this.win.focus();
22562                     this.execCmd(cmd);
22563                     this.deferFocus();
22564                     e.preventDefault();
22565                 }
22566                 
22567             }
22568         }
22569     },
22570
22571     // private
22572     fixKeys : function(){ // load time branching for fastest keydown performance
22573         if(Roo.isIE){
22574             return function(e){
22575                 var k = e.getKey(), r;
22576                 if(k == e.TAB){
22577                     e.stopEvent();
22578                     r = this.doc.selection.createRange();
22579                     if(r){
22580                         r.collapse(true);
22581                         r.pasteHTML('&#160;&#160;&#160;&#160;');
22582                         this.deferFocus();
22583                     }
22584                     return;
22585                 }
22586                 
22587                 if(k == e.ENTER){
22588                     r = this.doc.selection.createRange();
22589                     if(r){
22590                         var target = r.parentElement();
22591                         if(!target || target.tagName.toLowerCase() != 'li'){
22592                             e.stopEvent();
22593                             r.pasteHTML('<br />');
22594                             r.collapse(false);
22595                             r.select();
22596                         }
22597                     }
22598                 }
22599                 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22600                     this.cleanUpPaste.defer(100, this);
22601                     return;
22602                 }
22603                 
22604                 
22605             };
22606         }else if(Roo.isOpera){
22607             return function(e){
22608                 var k = e.getKey();
22609                 if(k == e.TAB){
22610                     e.stopEvent();
22611                     this.win.focus();
22612                     this.execCmd('InsertHTML','&#160;&#160;&#160;&#160;');
22613                     this.deferFocus();
22614                 }
22615                 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22616                     this.cleanUpPaste.defer(100, this);
22617                     return;
22618                 }
22619                 
22620             };
22621         }else if(Roo.isSafari){
22622             return function(e){
22623                 var k = e.getKey();
22624                 
22625                 if(k == e.TAB){
22626                     e.stopEvent();
22627                     this.execCmd('InsertText','\t');
22628                     this.deferFocus();
22629                     return;
22630                 }
22631                if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22632                     this.cleanUpPaste.defer(100, this);
22633                     return;
22634                 }
22635                 
22636              };
22637         }
22638     }(),
22639     
22640     getAllAncestors: function()
22641     {
22642         var p = this.getSelectedNode();
22643         var a = [];
22644         if (!p) {
22645             a.push(p); // push blank onto stack..
22646             p = this.getParentElement();
22647         }
22648         
22649         
22650         while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
22651             a.push(p);
22652             p = p.parentNode;
22653         }
22654         a.push(this.doc.body);
22655         return a;
22656     },
22657     lastSel : false,
22658     lastSelNode : false,
22659     
22660     
22661     getSelection : function() 
22662     {
22663         this.assignDocWin();
22664         return Roo.isIE ? this.doc.selection : this.win.getSelection();
22665     },
22666     
22667     getSelectedNode: function() 
22668     {
22669         // this may only work on Gecko!!!
22670         
22671         // should we cache this!!!!
22672         
22673         
22674         
22675          
22676         var range = this.createRange(this.getSelection()).cloneRange();
22677         
22678         if (Roo.isIE) {
22679             var parent = range.parentElement();
22680             while (true) {
22681                 var testRange = range.duplicate();
22682                 testRange.moveToElementText(parent);
22683                 if (testRange.inRange(range)) {
22684                     break;
22685                 }
22686                 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
22687                     break;
22688                 }
22689                 parent = parent.parentElement;
22690             }
22691             return parent;
22692         }
22693         
22694         // is ancestor a text element.
22695         var ac =  range.commonAncestorContainer;
22696         if (ac.nodeType == 3) {
22697             ac = ac.parentNode;
22698         }
22699         
22700         var ar = ac.childNodes;
22701          
22702         var nodes = [];
22703         var other_nodes = [];
22704         var has_other_nodes = false;
22705         for (var i=0;i<ar.length;i++) {
22706             if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ? 
22707                 continue;
22708             }
22709             // fullly contained node.
22710             
22711             if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
22712                 nodes.push(ar[i]);
22713                 continue;
22714             }
22715             
22716             // probably selected..
22717             if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
22718                 other_nodes.push(ar[i]);
22719                 continue;
22720             }
22721             // outer..
22722             if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0))  {
22723                 continue;
22724             }
22725             
22726             
22727             has_other_nodes = true;
22728         }
22729         if (!nodes.length && other_nodes.length) {
22730             nodes= other_nodes;
22731         }
22732         if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
22733             return false;
22734         }
22735         
22736         return nodes[0];
22737     },
22738     createRange: function(sel)
22739     {
22740         // this has strange effects when using with 
22741         // top toolbar - not sure if it's a great idea.
22742         //this.editor.contentWindow.focus();
22743         if (typeof sel != "undefined") {
22744             try {
22745                 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
22746             } catch(e) {
22747                 return this.doc.createRange();
22748             }
22749         } else {
22750             return this.doc.createRange();
22751         }
22752     },
22753     getParentElement: function()
22754     {
22755         
22756         this.assignDocWin();
22757         var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
22758         
22759         var range = this.createRange(sel);
22760          
22761         try {
22762             var p = range.commonAncestorContainer;
22763             while (p.nodeType == 3) { // text node
22764                 p = p.parentNode;
22765             }
22766             return p;
22767         } catch (e) {
22768             return null;
22769         }
22770     
22771     },
22772     /***
22773      *
22774      * Range intersection.. the hard stuff...
22775      *  '-1' = before
22776      *  '0' = hits..
22777      *  '1' = after.
22778      *         [ -- selected range --- ]
22779      *   [fail]                        [fail]
22780      *
22781      *    basically..
22782      *      if end is before start or  hits it. fail.
22783      *      if start is after end or hits it fail.
22784      *
22785      *   if either hits (but other is outside. - then it's not 
22786      *   
22787      *    
22788      **/
22789     
22790     
22791     // @see http://www.thismuchiknow.co.uk/?p=64.
22792     rangeIntersectsNode : function(range, node)
22793     {
22794         var nodeRange = node.ownerDocument.createRange();
22795         try {
22796             nodeRange.selectNode(node);
22797         } catch (e) {
22798             nodeRange.selectNodeContents(node);
22799         }
22800     
22801         var rangeStartRange = range.cloneRange();
22802         rangeStartRange.collapse(true);
22803     
22804         var rangeEndRange = range.cloneRange();
22805         rangeEndRange.collapse(false);
22806     
22807         var nodeStartRange = nodeRange.cloneRange();
22808         nodeStartRange.collapse(true);
22809     
22810         var nodeEndRange = nodeRange.cloneRange();
22811         nodeEndRange.collapse(false);
22812     
22813         return rangeStartRange.compareBoundaryPoints(
22814                  Range.START_TO_START, nodeEndRange) == -1 &&
22815                rangeEndRange.compareBoundaryPoints(
22816                  Range.START_TO_START, nodeStartRange) == 1;
22817         
22818          
22819     },
22820     rangeCompareNode : function(range, node)
22821     {
22822         var nodeRange = node.ownerDocument.createRange();
22823         try {
22824             nodeRange.selectNode(node);
22825         } catch (e) {
22826             nodeRange.selectNodeContents(node);
22827         }
22828         
22829         
22830         range.collapse(true);
22831     
22832         nodeRange.collapse(true);
22833      
22834         var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22835         var ee = range.compareBoundaryPoints(  Range.END_TO_END, nodeRange);
22836          
22837         //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22838         
22839         var nodeIsBefore   =  ss == 1;
22840         var nodeIsAfter    = ee == -1;
22841         
22842         if (nodeIsBefore && nodeIsAfter) {
22843             return 0; // outer
22844         }
22845         if (!nodeIsBefore && nodeIsAfter) {
22846             return 1; //right trailed.
22847         }
22848         
22849         if (nodeIsBefore && !nodeIsAfter) {
22850             return 2;  // left trailed.
22851         }
22852         // fully contined.
22853         return 3;
22854     },
22855
22856     // private? - in a new class?
22857     cleanUpPaste :  function()
22858     {
22859         // cleans up the whole document..
22860         Roo.log('cleanuppaste');
22861         
22862         this.cleanUpChildren(this.doc.body);
22863         var clean = this.cleanWordChars(this.doc.body.innerHTML);
22864         if (clean != this.doc.body.innerHTML) {
22865             this.doc.body.innerHTML = clean;
22866         }
22867         
22868     },
22869     
22870     cleanWordChars : function(input) {// change the chars to hex code
22871         var he = Roo.HtmlEditorCore;
22872         
22873         var output = input;
22874         Roo.each(he.swapCodes, function(sw) { 
22875             var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22876             
22877             output = output.replace(swapper, sw[1]);
22878         });
22879         
22880         return output;
22881     },
22882     
22883     
22884     cleanUpChildren : function (n)
22885     {
22886         if (!n.childNodes.length) {
22887             return;
22888         }
22889         for (var i = n.childNodes.length-1; i > -1 ; i--) {
22890            this.cleanUpChild(n.childNodes[i]);
22891         }
22892     },
22893     
22894     
22895         
22896     
22897     cleanUpChild : function (node)
22898     {
22899         var ed = this;
22900         //console.log(node);
22901         if (node.nodeName == "#text") {
22902             // clean up silly Windows -- stuff?
22903             return; 
22904         }
22905         if (node.nodeName == "#comment") {
22906             node.parentNode.removeChild(node);
22907             // clean up silly Windows -- stuff?
22908             return; 
22909         }
22910         var lcname = node.tagName.toLowerCase();
22911         // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22912         // whitelist of tags..
22913         
22914         if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22915             // remove node.
22916             node.parentNode.removeChild(node);
22917             return;
22918             
22919         }
22920         
22921         var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22922         
22923         // remove <a name=....> as rendering on yahoo mailer is borked with this.
22924         // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22925         
22926         //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22927         //    remove_keep_children = true;
22928         //}
22929         
22930         if (remove_keep_children) {
22931             this.cleanUpChildren(node);
22932             // inserts everything just before this node...
22933             while (node.childNodes.length) {
22934                 var cn = node.childNodes[0];
22935                 node.removeChild(cn);
22936                 node.parentNode.insertBefore(cn, node);
22937             }
22938             node.parentNode.removeChild(node);
22939             return;
22940         }
22941         
22942         if (!node.attributes || !node.attributes.length) {
22943             this.cleanUpChildren(node);
22944             return;
22945         }
22946         
22947         function cleanAttr(n,v)
22948         {
22949             
22950             if (v.match(/^\./) || v.match(/^\//)) {
22951                 return;
22952             }
22953             if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
22954                 return;
22955             }
22956             if (v.match(/^#/)) {
22957                 return;
22958             }
22959 //            Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22960             node.removeAttribute(n);
22961             
22962         }
22963         
22964         var cwhite = this.cwhite;
22965         var cblack = this.cblack;
22966             
22967         function cleanStyle(n,v)
22968         {
22969             if (v.match(/expression/)) { //XSS?? should we even bother..
22970                 node.removeAttribute(n);
22971                 return;
22972             }
22973             
22974             var parts = v.split(/;/);
22975             var clean = [];
22976             
22977             Roo.each(parts, function(p) {
22978                 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22979                 if (!p.length) {
22980                     return true;
22981                 }
22982                 var l = p.split(':').shift().replace(/\s+/g,'');
22983                 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22984                 
22985                 if ( cwhite.length && cblack.indexOf(l) > -1) {
22986 //                    Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22987                     //node.removeAttribute(n);
22988                     return true;
22989                 }
22990                 //Roo.log()
22991                 // only allow 'c whitelisted system attributes'
22992                 if ( cwhite.length &&  cwhite.indexOf(l) < 0) {
22993 //                    Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22994                     //node.removeAttribute(n);
22995                     return true;
22996                 }
22997                 
22998                 
22999                  
23000                 
23001                 clean.push(p);
23002                 return true;
23003             });
23004             if (clean.length) { 
23005                 node.setAttribute(n, clean.join(';'));
23006             } else {
23007                 node.removeAttribute(n);
23008             }
23009             
23010         }
23011         
23012         
23013         for (var i = node.attributes.length-1; i > -1 ; i--) {
23014             var a = node.attributes[i];
23015             //console.log(a);
23016             
23017             if (a.name.toLowerCase().substr(0,2)=='on')  {
23018                 node.removeAttribute(a.name);
23019                 continue;
23020             }
23021             if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
23022                 node.removeAttribute(a.name);
23023                 continue;
23024             }
23025             if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
23026                 cleanAttr(a.name,a.value); // fixme..
23027                 continue;
23028             }
23029             if (a.name == 'style') {
23030                 cleanStyle(a.name,a.value);
23031                 continue;
23032             }
23033             /// clean up MS crap..
23034             // tecnically this should be a list of valid class'es..
23035             
23036             
23037             if (a.name == 'class') {
23038                 if (a.value.match(/^Mso/)) {
23039                     node.className = '';
23040                 }
23041                 
23042                 if (a.value.match(/^body$/)) {
23043                     node.className = '';
23044                 }
23045                 continue;
23046             }
23047             
23048             // style cleanup!?
23049             // class cleanup?
23050             
23051         }
23052         
23053         
23054         this.cleanUpChildren(node);
23055         
23056         
23057     },
23058     
23059     /**
23060      * Clean up MS wordisms...
23061      */
23062     cleanWord : function(node)
23063     {
23064         
23065         
23066         if (!node) {
23067             this.cleanWord(this.doc.body);
23068             return;
23069         }
23070         if (node.nodeName == "#text") {
23071             // clean up silly Windows -- stuff?
23072             return; 
23073         }
23074         if (node.nodeName == "#comment") {
23075             node.parentNode.removeChild(node);
23076             // clean up silly Windows -- stuff?
23077             return; 
23078         }
23079         
23080         if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
23081             node.parentNode.removeChild(node);
23082             return;
23083         }
23084         
23085         // remove - but keep children..
23086         if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
23087             while (node.childNodes.length) {
23088                 var cn = node.childNodes[0];
23089                 node.removeChild(cn);
23090                 node.parentNode.insertBefore(cn, node);
23091             }
23092             node.parentNode.removeChild(node);
23093             this.iterateChildren(node, this.cleanWord);
23094             return;
23095         }
23096         // clean styles
23097         if (node.className.length) {
23098             
23099             var cn = node.className.split(/\W+/);
23100             var cna = [];
23101             Roo.each(cn, function(cls) {
23102                 if (cls.match(/Mso[a-zA-Z]+/)) {
23103                     return;
23104                 }
23105                 cna.push(cls);
23106             });
23107             node.className = cna.length ? cna.join(' ') : '';
23108             if (!cna.length) {
23109                 node.removeAttribute("class");
23110             }
23111         }
23112         
23113         if (node.hasAttribute("lang")) {
23114             node.removeAttribute("lang");
23115         }
23116         
23117         if (node.hasAttribute("style")) {
23118             
23119             var styles = node.getAttribute("style").split(";");
23120             var nstyle = [];
23121             Roo.each(styles, function(s) {
23122                 if (!s.match(/:/)) {
23123                     return;
23124                 }
23125                 var kv = s.split(":");
23126                 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
23127                     return;
23128                 }
23129                 // what ever is left... we allow.
23130                 nstyle.push(s);
23131             });
23132             node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
23133             if (!nstyle.length) {
23134                 node.removeAttribute('style');
23135             }
23136         }
23137         this.iterateChildren(node, this.cleanWord);
23138         
23139         
23140         
23141     },
23142     /**
23143      * iterateChildren of a Node, calling fn each time, using this as the scole..
23144      * @param {DomNode} node node to iterate children of.
23145      * @param {Function} fn method of this class to call on each item.
23146      */
23147     iterateChildren : function(node, fn)
23148     {
23149         if (!node.childNodes.length) {
23150                 return;
23151         }
23152         for (var i = node.childNodes.length-1; i > -1 ; i--) {
23153            fn.call(this, node.childNodes[i])
23154         }
23155     },
23156     
23157     
23158     /**
23159      * cleanTableWidths.
23160      *
23161      * Quite often pasting from word etc.. results in tables with column and widths.
23162      * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
23163      *
23164      */
23165     cleanTableWidths : function(node)
23166     {
23167          
23168          
23169         if (!node) {
23170             this.cleanTableWidths(this.doc.body);
23171             return;
23172         }
23173         
23174         // ignore list...
23175         if (node.nodeName == "#text" || node.nodeName == "#comment") {
23176             return; 
23177         }
23178         Roo.log(node.tagName);
23179         if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
23180             this.iterateChildren(node, this.cleanTableWidths);
23181             return;
23182         }
23183         if (node.hasAttribute('width')) {
23184             node.removeAttribute('width');
23185         }
23186         
23187          
23188         if (node.hasAttribute("style")) {
23189             // pretty basic...
23190             
23191             var styles = node.getAttribute("style").split(";");
23192             var nstyle = [];
23193             Roo.each(styles, function(s) {
23194                 if (!s.match(/:/)) {
23195                     return;
23196                 }
23197                 var kv = s.split(":");
23198                 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
23199                     return;
23200                 }
23201                 // what ever is left... we allow.
23202                 nstyle.push(s);
23203             });
23204             node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
23205             if (!nstyle.length) {
23206                 node.removeAttribute('style');
23207             }
23208         }
23209         
23210         this.iterateChildren(node, this.cleanTableWidths);
23211         
23212         
23213     },
23214     
23215     
23216     
23217     
23218     domToHTML : function(currentElement, depth, nopadtext) {
23219         
23220         depth = depth || 0;
23221         nopadtext = nopadtext || false;
23222     
23223         if (!currentElement) {
23224             return this.domToHTML(this.doc.body);
23225         }
23226         
23227         //Roo.log(currentElement);
23228         var j;
23229         var allText = false;
23230         var nodeName = currentElement.nodeName;
23231         var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
23232         
23233         if  (nodeName == '#text') {
23234             
23235             return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
23236         }
23237         
23238         
23239         var ret = '';
23240         if (nodeName != 'BODY') {
23241              
23242             var i = 0;
23243             // Prints the node tagName, such as <A>, <IMG>, etc
23244             if (tagName) {
23245                 var attr = [];
23246                 for(i = 0; i < currentElement.attributes.length;i++) {
23247                     // quoting?
23248                     var aname = currentElement.attributes.item(i).name;
23249                     if (!currentElement.attributes.item(i).value.length) {
23250                         continue;
23251                     }
23252                     attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
23253                 }
23254                 
23255                 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
23256             } 
23257             else {
23258                 
23259                 // eack
23260             }
23261         } else {
23262             tagName = false;
23263         }
23264         if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
23265             return ret;
23266         }
23267         if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
23268             nopadtext = true;
23269         }
23270         
23271         
23272         // Traverse the tree
23273         i = 0;
23274         var currentElementChild = currentElement.childNodes.item(i);
23275         var allText = true;
23276         var innerHTML  = '';
23277         lastnode = '';
23278         while (currentElementChild) {
23279             // Formatting code (indent the tree so it looks nice on the screen)
23280             var nopad = nopadtext;
23281             if (lastnode == 'SPAN') {
23282                 nopad  = true;
23283             }
23284             // text
23285             if  (currentElementChild.nodeName == '#text') {
23286                 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
23287                 toadd = nopadtext ? toadd : toadd.trim();
23288                 if (!nopad && toadd.length > 80) {
23289                     innerHTML  += "\n" + (new Array( depth + 1 )).join( "  "  );
23290                 }
23291                 innerHTML  += toadd;
23292                 
23293                 i++;
23294                 currentElementChild = currentElement.childNodes.item(i);
23295                 lastNode = '';
23296                 continue;
23297             }
23298             allText = false;
23299             
23300             innerHTML  += nopad ? '' : "\n" + (new Array( depth + 1 )).join( "  "  );
23301                 
23302             // Recursively traverse the tree structure of the child node
23303             innerHTML   += this.domToHTML(currentElementChild, depth+1, nopadtext);
23304             lastnode = currentElementChild.nodeName;
23305             i++;
23306             currentElementChild=currentElement.childNodes.item(i);
23307         }
23308         
23309         ret += innerHTML;
23310         
23311         if (!allText) {
23312                 // The remaining code is mostly for formatting the tree
23313             ret+= nopadtext ? '' : "\n" + (new Array( depth  )).join( "  "  );
23314         }
23315         
23316         
23317         if (tagName) {
23318             ret+= "</"+tagName+">";
23319         }
23320         return ret;
23321         
23322     },
23323         
23324     applyBlacklists : function()
23325     {
23326         var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white  : [];
23327         var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black :  [];
23328         
23329         this.white = [];
23330         this.black = [];
23331         Roo.each(Roo.HtmlEditorCore.white, function(tag) {
23332             if (b.indexOf(tag) > -1) {
23333                 return;
23334             }
23335             this.white.push(tag);
23336             
23337         }, this);
23338         
23339         Roo.each(w, function(tag) {
23340             if (b.indexOf(tag) > -1) {
23341                 return;
23342             }
23343             if (this.white.indexOf(tag) > -1) {
23344                 return;
23345             }
23346             this.white.push(tag);
23347             
23348         }, this);
23349         
23350         
23351         Roo.each(Roo.HtmlEditorCore.black, function(tag) {
23352             if (w.indexOf(tag) > -1) {
23353                 return;
23354             }
23355             this.black.push(tag);
23356             
23357         }, this);
23358         
23359         Roo.each(b, function(tag) {
23360             if (w.indexOf(tag) > -1) {
23361                 return;
23362             }
23363             if (this.black.indexOf(tag) > -1) {
23364                 return;
23365             }
23366             this.black.push(tag);
23367             
23368         }, this);
23369         
23370         
23371         w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite  : [];
23372         b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack :  [];
23373         
23374         this.cwhite = [];
23375         this.cblack = [];
23376         Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
23377             if (b.indexOf(tag) > -1) {
23378                 return;
23379             }
23380             this.cwhite.push(tag);
23381             
23382         }, this);
23383         
23384         Roo.each(w, function(tag) {
23385             if (b.indexOf(tag) > -1) {
23386                 return;
23387             }
23388             if (this.cwhite.indexOf(tag) > -1) {
23389                 return;
23390             }
23391             this.cwhite.push(tag);
23392             
23393         }, this);
23394         
23395         
23396         Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
23397             if (w.indexOf(tag) > -1) {
23398                 return;
23399             }
23400             this.cblack.push(tag);
23401             
23402         }, this);
23403         
23404         Roo.each(b, function(tag) {
23405             if (w.indexOf(tag) > -1) {
23406                 return;
23407             }
23408             if (this.cblack.indexOf(tag) > -1) {
23409                 return;
23410             }
23411             this.cblack.push(tag);
23412             
23413         }, this);
23414     },
23415     
23416     setStylesheets : function(stylesheets)
23417     {
23418         if(typeof(stylesheets) == 'string'){
23419             Roo.get(this.iframe.contentDocument.head).createChild({
23420                 tag : 'link',
23421                 rel : 'stylesheet',
23422                 type : 'text/css',
23423                 href : stylesheets
23424             });
23425             
23426             return;
23427         }
23428         var _this = this;
23429      
23430         Roo.each(stylesheets, function(s) {
23431             if(!s.length){
23432                 return;
23433             }
23434             
23435             Roo.get(_this.iframe.contentDocument.head).createChild({
23436                 tag : 'link',
23437                 rel : 'stylesheet',
23438                 type : 'text/css',
23439                 href : s
23440             });
23441         });
23442
23443         
23444     },
23445     
23446     removeStylesheets : function()
23447     {
23448         var _this = this;
23449         
23450         Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
23451             s.remove();
23452         });
23453     },
23454     
23455     setStyle : function(style)
23456     {
23457         Roo.get(this.iframe.contentDocument.head).createChild({
23458             tag : 'style',
23459             type : 'text/css',
23460             html : style
23461         });
23462
23463         return;
23464     }
23465     
23466     // hide stuff that is not compatible
23467     /**
23468      * @event blur
23469      * @hide
23470      */
23471     /**
23472      * @event change
23473      * @hide
23474      */
23475     /**
23476      * @event focus
23477      * @hide
23478      */
23479     /**
23480      * @event specialkey
23481      * @hide
23482      */
23483     /**
23484      * @cfg {String} fieldClass @hide
23485      */
23486     /**
23487      * @cfg {String} focusClass @hide
23488      */
23489     /**
23490      * @cfg {String} autoCreate @hide
23491      */
23492     /**
23493      * @cfg {String} inputType @hide
23494      */
23495     /**
23496      * @cfg {String} invalidClass @hide
23497      */
23498     /**
23499      * @cfg {String} invalidText @hide
23500      */
23501     /**
23502      * @cfg {String} msgFx @hide
23503      */
23504     /**
23505      * @cfg {String} validateOnBlur @hide
23506      */
23507 });
23508
23509 Roo.HtmlEditorCore.white = [
23510         'area', 'br', 'img', 'input', 'hr', 'wbr',
23511         
23512        'address', 'blockquote', 'center', 'dd',      'dir',       'div', 
23513        'dl',      'dt',         'h1',     'h2',      'h3',        'h4', 
23514        'h5',      'h6',         'hr',     'isindex', 'listing',   'marquee', 
23515        'menu',    'multicol',   'ol',     'p',       'plaintext', 'pre', 
23516        'table',   'ul',         'xmp', 
23517        
23518        'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', 
23519       'thead',   'tr', 
23520      
23521       'dir', 'menu', 'ol', 'ul', 'dl',
23522        
23523       'embed',  'object'
23524 ];
23525
23526
23527 Roo.HtmlEditorCore.black = [
23528     //    'embed',  'object', // enable - backend responsiblity to clean thiese
23529         'applet', // 
23530         'base',   'basefont', 'bgsound', 'blink',  'body', 
23531         'frame',  'frameset', 'head',    'html',   'ilayer', 
23532         'iframe', 'layer',  'link',     'meta',    'object',   
23533         'script', 'style' ,'title',  'xml' // clean later..
23534 ];
23535 Roo.HtmlEditorCore.clean = [
23536     'script', 'style', 'title', 'xml'
23537 ];
23538 Roo.HtmlEditorCore.remove = [
23539     'font'
23540 ];
23541 // attributes..
23542
23543 Roo.HtmlEditorCore.ablack = [
23544     'on'
23545 ];
23546     
23547 Roo.HtmlEditorCore.aclean = [ 
23548     'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc' 
23549 ];
23550
23551 // protocols..
23552 Roo.HtmlEditorCore.pwhite= [
23553         'http',  'https',  'mailto'
23554 ];
23555
23556 // white listed style attributes.
23557 Roo.HtmlEditorCore.cwhite= [
23558       //  'text-align', /// default is to allow most things..
23559       
23560          
23561 //        'font-size'//??
23562 ];
23563
23564 // black listed style attributes.
23565 Roo.HtmlEditorCore.cblack= [
23566       //  'font-size' -- this can be set by the project 
23567 ];
23568
23569
23570 Roo.HtmlEditorCore.swapCodes   =[ 
23571     [    8211, "--" ], 
23572     [    8212, "--" ], 
23573     [    8216,  "'" ],  
23574     [    8217, "'" ],  
23575     [    8220, '"' ],  
23576     [    8221, '"' ],  
23577     [    8226, "*" ],  
23578     [    8230, "..." ]
23579 ]; 
23580
23581     /*
23582  * - LGPL
23583  *
23584  * HtmlEditor
23585  * 
23586  */
23587
23588 /**
23589  * @class Roo.bootstrap.HtmlEditor
23590  * @extends Roo.bootstrap.TextArea
23591  * Bootstrap HtmlEditor class
23592
23593  * @constructor
23594  * Create a new HtmlEditor
23595  * @param {Object} config The config object
23596  */
23597
23598 Roo.bootstrap.HtmlEditor = function(config){
23599     Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
23600     if (!this.toolbars) {
23601         this.toolbars = [];
23602     }
23603     
23604     this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
23605     this.addEvents({
23606             /**
23607              * @event initialize
23608              * Fires when the editor is fully initialized (including the iframe)
23609              * @param {HtmlEditor} this
23610              */
23611             initialize: true,
23612             /**
23613              * @event activate
23614              * Fires when the editor is first receives the focus. Any insertion must wait
23615              * until after this event.
23616              * @param {HtmlEditor} this
23617              */
23618             activate: true,
23619              /**
23620              * @event beforesync
23621              * Fires before the textarea is updated with content from the editor iframe. Return false
23622              * to cancel the sync.
23623              * @param {HtmlEditor} this
23624              * @param {String} html
23625              */
23626             beforesync: true,
23627              /**
23628              * @event beforepush
23629              * Fires before the iframe editor is updated with content from the textarea. Return false
23630              * to cancel the push.
23631              * @param {HtmlEditor} this
23632              * @param {String} html
23633              */
23634             beforepush: true,
23635              /**
23636              * @event sync
23637              * Fires when the textarea is updated with content from the editor iframe.
23638              * @param {HtmlEditor} this
23639              * @param {String} html
23640              */
23641             sync: true,
23642              /**
23643              * @event push
23644              * Fires when the iframe editor is updated with content from the textarea.
23645              * @param {HtmlEditor} this
23646              * @param {String} html
23647              */
23648             push: true,
23649              /**
23650              * @event editmodechange
23651              * Fires when the editor switches edit modes
23652              * @param {HtmlEditor} this
23653              * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23654              */
23655             editmodechange: true,
23656             /**
23657              * @event editorevent
23658              * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23659              * @param {HtmlEditor} this
23660              */
23661             editorevent: true,
23662             /**
23663              * @event firstfocus
23664              * Fires when on first focus - needed by toolbars..
23665              * @param {HtmlEditor} this
23666              */
23667             firstfocus: true,
23668             /**
23669              * @event autosave
23670              * Auto save the htmlEditor value as a file into Events
23671              * @param {HtmlEditor} this
23672              */
23673             autosave: true,
23674             /**
23675              * @event savedpreview
23676              * preview the saved version of htmlEditor
23677              * @param {HtmlEditor} this
23678              */
23679             savedpreview: true
23680         });
23681 };
23682
23683
23684 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea,  {
23685     
23686     
23687       /**
23688      * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23689      */
23690     toolbars : false,
23691     
23692      /**
23693     * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
23694     */
23695     btns : [],
23696    
23697      /**
23698      * @cfg {String} resizable  's' or 'se' or 'e' - wrapps the element in a
23699      *                        Roo.resizable.
23700      */
23701     resizable : false,
23702      /**
23703      * @cfg {Number} height (in pixels)
23704      */   
23705     height: 300,
23706    /**
23707      * @cfg {Number} width (in pixels)
23708      */   
23709     width: false,
23710     
23711     /**
23712      * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
23713      * 
23714      */
23715     stylesheets: false,
23716     
23717     // id of frame..
23718     frameId: false,
23719     
23720     // private properties
23721     validationEvent : false,
23722     deferHeight: true,
23723     initialized : false,
23724     activated : false,
23725     
23726     onFocus : Roo.emptyFn,
23727     iframePad:3,
23728     hideMode:'offsets',
23729     
23730     tbContainer : false,
23731     
23732     bodyCls : '',
23733     
23734     toolbarContainer :function() {
23735         return this.wrap.select('.x-html-editor-tb',true).first();
23736     },
23737
23738     /**
23739      * Protected method that will not generally be called directly. It
23740      * is called when the editor creates its toolbar. Override this method if you need to
23741      * add custom toolbar buttons.
23742      * @param {HtmlEditor} editor
23743      */
23744     createToolbar : function(){
23745         Roo.log('renewing');
23746         Roo.log("create toolbars");
23747         
23748         this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
23749         this.toolbars[0].render(this.toolbarContainer());
23750         
23751         return;
23752         
23753 //        if (!editor.toolbars || !editor.toolbars.length) {
23754 //            editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
23755 //        }
23756 //        
23757 //        for (var i =0 ; i < editor.toolbars.length;i++) {
23758 //            editor.toolbars[i] = Roo.factory(
23759 //                    typeof(editor.toolbars[i]) == 'string' ?
23760 //                        { xtype: editor.toolbars[i]} : editor.toolbars[i],
23761 //                Roo.bootstrap.HtmlEditor);
23762 //            editor.toolbars[i].init(editor);
23763 //        }
23764     },
23765
23766      
23767     // private
23768     onRender : function(ct, position)
23769     {
23770        // Roo.log("Call onRender: " + this.xtype);
23771         var _t = this;
23772         Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
23773       
23774         this.wrap = this.inputEl().wrap({
23775             cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23776         });
23777         
23778         this.editorcore.onRender(ct, position);
23779          
23780         if (this.resizable) {
23781             this.resizeEl = new Roo.Resizable(this.wrap, {
23782                 pinned : true,
23783                 wrap: true,
23784                 dynamic : true,
23785                 minHeight : this.height,
23786                 height: this.height,
23787                 handles : this.resizable,
23788                 width: this.width,
23789                 listeners : {
23790                     resize : function(r, w, h) {
23791                         _t.onResize(w,h); // -something
23792                     }
23793                 }
23794             });
23795             
23796         }
23797         this.createToolbar(this);
23798        
23799         
23800         if(!this.width && this.resizable){
23801             this.setSize(this.wrap.getSize());
23802         }
23803         if (this.resizeEl) {
23804             this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
23805             // should trigger onReize..
23806         }
23807         
23808     },
23809
23810     // private
23811     onResize : function(w, h)
23812     {
23813         Roo.log('resize: ' +w + ',' + h );
23814         Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
23815         var ew = false;
23816         var eh = false;
23817         
23818         if(this.inputEl() ){
23819             if(typeof w == 'number'){
23820                 var aw = w - this.wrap.getFrameWidth('lr');
23821                 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
23822                 ew = aw;
23823             }
23824             if(typeof h == 'number'){
23825                  var tbh = -11;  // fixme it needs to tool bar size!
23826                 for (var i =0; i < this.toolbars.length;i++) {
23827                     // fixme - ask toolbars for heights?
23828                     tbh += this.toolbars[i].el.getHeight();
23829                     //if (this.toolbars[i].footer) {
23830                     //    tbh += this.toolbars[i].footer.el.getHeight();
23831                     //}
23832                 }
23833               
23834                 
23835                 
23836                 
23837                 
23838                 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23839                 ah -= 5; // knock a few pixes off for look..
23840                 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23841                 var eh = ah;
23842             }
23843         }
23844         Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23845         this.editorcore.onResize(ew,eh);
23846         
23847     },
23848
23849     /**
23850      * Toggles the editor between standard and source edit mode.
23851      * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23852      */
23853     toggleSourceEdit : function(sourceEditMode)
23854     {
23855         this.editorcore.toggleSourceEdit(sourceEditMode);
23856         
23857         if(this.editorcore.sourceEditMode){
23858             Roo.log('editor - showing textarea');
23859             
23860 //            Roo.log('in');
23861 //            Roo.log(this.syncValue());
23862             this.syncValue();
23863             this.inputEl().removeClass(['hide', 'x-hidden']);
23864             this.inputEl().dom.removeAttribute('tabIndex');
23865             this.inputEl().focus();
23866         }else{
23867             Roo.log('editor - hiding textarea');
23868 //            Roo.log('out')
23869 //            Roo.log(this.pushValue()); 
23870             this.pushValue();
23871             
23872             this.inputEl().addClass(['hide', 'x-hidden']);
23873             this.inputEl().dom.setAttribute('tabIndex', -1);
23874             //this.deferFocus();
23875         }
23876          
23877         if(this.resizable){
23878             this.setSize(this.wrap.getSize());
23879         }
23880         
23881         this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23882     },
23883  
23884     // private (for BoxComponent)
23885     adjustSize : Roo.BoxComponent.prototype.adjustSize,
23886
23887     // private (for BoxComponent)
23888     getResizeEl : function(){
23889         return this.wrap;
23890     },
23891
23892     // private (for BoxComponent)
23893     getPositionEl : function(){
23894         return this.wrap;
23895     },
23896
23897     // private
23898     initEvents : function(){
23899         this.originalValue = this.getValue();
23900     },
23901
23902 //    /**
23903 //     * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23904 //     * @method
23905 //     */
23906 //    markInvalid : Roo.emptyFn,
23907 //    /**
23908 //     * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23909 //     * @method
23910 //     */
23911 //    clearInvalid : Roo.emptyFn,
23912
23913     setValue : function(v){
23914         Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23915         this.editorcore.pushValue();
23916     },
23917
23918      
23919     // private
23920     deferFocus : function(){
23921         this.focus.defer(10, this);
23922     },
23923
23924     // doc'ed in Field
23925     focus : function(){
23926         this.editorcore.focus();
23927         
23928     },
23929       
23930
23931     // private
23932     onDestroy : function(){
23933         
23934         
23935         
23936         if(this.rendered){
23937             
23938             for (var i =0; i < this.toolbars.length;i++) {
23939                 // fixme - ask toolbars for heights?
23940                 this.toolbars[i].onDestroy();
23941             }
23942             
23943             this.wrap.dom.innerHTML = '';
23944             this.wrap.remove();
23945         }
23946     },
23947
23948     // private
23949     onFirstFocus : function(){
23950         //Roo.log("onFirstFocus");
23951         this.editorcore.onFirstFocus();
23952          for (var i =0; i < this.toolbars.length;i++) {
23953             this.toolbars[i].onFirstFocus();
23954         }
23955         
23956     },
23957     
23958     // private
23959     syncValue : function()
23960     {   
23961         this.editorcore.syncValue();
23962     },
23963     
23964     pushValue : function()
23965     {   
23966         this.editorcore.pushValue();
23967     }
23968      
23969     
23970     // hide stuff that is not compatible
23971     /**
23972      * @event blur
23973      * @hide
23974      */
23975     /**
23976      * @event change
23977      * @hide
23978      */
23979     /**
23980      * @event focus
23981      * @hide
23982      */
23983     /**
23984      * @event specialkey
23985      * @hide
23986      */
23987     /**
23988      * @cfg {String} fieldClass @hide
23989      */
23990     /**
23991      * @cfg {String} focusClass @hide
23992      */
23993     /**
23994      * @cfg {String} autoCreate @hide
23995      */
23996     /**
23997      * @cfg {String} inputType @hide
23998      */
23999      
24000     /**
24001      * @cfg {String} invalidText @hide
24002      */
24003     /**
24004      * @cfg {String} msgFx @hide
24005      */
24006     /**
24007      * @cfg {String} validateOnBlur @hide
24008      */
24009 });
24010  
24011     
24012    
24013    
24014    
24015       
24016 Roo.namespace('Roo.bootstrap.htmleditor');
24017 /**
24018  * @class Roo.bootstrap.HtmlEditorToolbar1
24019  * Basic Toolbar
24020  * 
24021  * Usage:
24022  *
24023  new Roo.bootstrap.HtmlEditor({
24024     ....
24025     toolbars : [
24026         new Roo.bootstrap.HtmlEditorToolbar1({
24027             disable : { fonts: 1 , format: 1, ..., ... , ...],
24028             btns : [ .... ]
24029         })
24030     }
24031      
24032  * 
24033  * @cfg {Object} disable List of elements to disable..
24034  * @cfg {Array} btns List of additional buttons.
24035  * 
24036  * 
24037  * NEEDS Extra CSS? 
24038  * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
24039  */
24040  
24041 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
24042 {
24043     
24044     Roo.apply(this, config);
24045     
24046     // default disabled, based on 'good practice'..
24047     this.disable = this.disable || {};
24048     Roo.applyIf(this.disable, {
24049         fontSize : true,
24050         colors : true,
24051         specialElements : true
24052     });
24053     Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
24054     
24055     this.editor = config.editor;
24056     this.editorcore = config.editor.editorcore;
24057     
24058     this.buttons   = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
24059     
24060     //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
24061     // dont call parent... till later.
24062 }
24063 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar,  {
24064      
24065     bar : true,
24066     
24067     editor : false,
24068     editorcore : false,
24069     
24070     
24071     formats : [
24072         "p" ,  
24073         "h1","h2","h3","h4","h5","h6", 
24074         "pre", "code", 
24075         "abbr", "acronym", "address", "cite", "samp", "var",
24076         'div','span'
24077     ],
24078     
24079     onRender : function(ct, position)
24080     {
24081        // Roo.log("Call onRender: " + this.xtype);
24082         
24083        Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
24084        Roo.log(this.el);
24085        this.el.dom.style.marginBottom = '0';
24086        var _this = this;
24087        var editorcore = this.editorcore;
24088        var editor= this.editor;
24089        
24090        var children = [];
24091        var btn = function(id,cmd , toggle, handler, html){
24092        
24093             var  event = toggle ? 'toggle' : 'click';
24094        
24095             var a = {
24096                 size : 'sm',
24097                 xtype: 'Button',
24098                 xns: Roo.bootstrap,
24099                 //glyphicon : id,
24100                 fa: id,
24101                 cmd : id || cmd,
24102                 enableToggle:toggle !== false,
24103                 html : html || '',
24104                 pressed : toggle ? false : null,
24105                 listeners : {}
24106             };
24107             a.listeners[toggle ? 'toggle' : 'click'] = function() {
24108                 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd ||  id);
24109             };
24110             children.push(a);
24111             return a;
24112        }
24113        
24114     //    var cb_box = function...
24115         
24116         var style = {
24117                 xtype: 'Button',
24118                 size : 'sm',
24119                 xns: Roo.bootstrap,
24120                 fa : 'font',
24121                 //html : 'submit'
24122                 menu : {
24123                     xtype: 'Menu',
24124                     xns: Roo.bootstrap,
24125                     items:  []
24126                 }
24127         };
24128         Roo.each(this.formats, function(f) {
24129             style.menu.items.push({
24130                 xtype :'MenuItem',
24131                 xns: Roo.bootstrap,
24132                 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
24133                 tagname : f,
24134                 listeners : {
24135                     click : function()
24136                     {
24137                         editorcore.insertTag(this.tagname);
24138                         editor.focus();
24139                     }
24140                 }
24141                 
24142             });
24143         });
24144         children.push(style);   
24145         
24146         btn('bold',false,true);
24147         btn('italic',false,true);
24148         btn('align-left', 'justifyleft',true);
24149         btn('align-center', 'justifycenter',true);
24150         btn('align-right' , 'justifyright',true);
24151         btn('link', false, false, function(btn) {
24152             //Roo.log("create link?");
24153             var url = prompt(this.createLinkText, this.defaultLinkValue);
24154             if(url && url != 'http:/'+'/'){
24155                 this.editorcore.relayCmd('createlink', url);
24156             }
24157         }),
24158         btn('list','insertunorderedlist',true);
24159         btn('pencil', false,true, function(btn){
24160                 Roo.log(this);
24161                 this.toggleSourceEdit(btn.pressed);
24162         });
24163         
24164         if (this.editor.btns.length > 0) {
24165             for (var i = 0; i<this.editor.btns.length; i++) {
24166                 children.push(this.editor.btns[i]);
24167             }
24168         }
24169         
24170         /*
24171         var cog = {
24172                 xtype: 'Button',
24173                 size : 'sm',
24174                 xns: Roo.bootstrap,
24175                 glyphicon : 'cog',
24176                 //html : 'submit'
24177                 menu : {
24178                     xtype: 'Menu',
24179                     xns: Roo.bootstrap,
24180                     items:  []
24181                 }
24182         };
24183         
24184         cog.menu.items.push({
24185             xtype :'MenuItem',
24186             xns: Roo.bootstrap,
24187             html : Clean styles,
24188             tagname : f,
24189             listeners : {
24190                 click : function()
24191                 {
24192                     editorcore.insertTag(this.tagname);
24193                     editor.focus();
24194                 }
24195             }
24196             
24197         });
24198        */
24199         
24200          
24201        this.xtype = 'NavSimplebar';
24202         
24203         for(var i=0;i< children.length;i++) {
24204             
24205             this.buttons.add(this.addxtypeChild(children[i]));
24206             
24207         }
24208         
24209         editor.on('editorevent', this.updateToolbar, this);
24210     },
24211     onBtnClick : function(id)
24212     {
24213        this.editorcore.relayCmd(id);
24214        this.editorcore.focus();
24215     },
24216     
24217     /**
24218      * Protected method that will not generally be called directly. It triggers
24219      * a toolbar update by reading the markup state of the current selection in the editor.
24220      */
24221     updateToolbar: function(){
24222
24223         if(!this.editorcore.activated){
24224             this.editor.onFirstFocus(); // is this neeed?
24225             return;
24226         }
24227
24228         var btns = this.buttons; 
24229         var doc = this.editorcore.doc;
24230         btns.get('bold').setActive(doc.queryCommandState('bold'));
24231         btns.get('italic').setActive(doc.queryCommandState('italic'));
24232         //btns.get('underline').setActive(doc.queryCommandState('underline'));
24233         
24234         btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
24235         btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
24236         btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
24237         
24238         //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
24239         btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
24240          /*
24241         
24242         var ans = this.editorcore.getAllAncestors();
24243         if (this.formatCombo) {
24244             
24245             
24246             var store = this.formatCombo.store;
24247             this.formatCombo.setValue("");
24248             for (var i =0; i < ans.length;i++) {
24249                 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
24250                     // select it..
24251                     this.formatCombo.setValue(ans[i].tagName.toLowerCase());
24252                     break;
24253                 }
24254             }
24255         }
24256         
24257         
24258         
24259         // hides menus... - so this cant be on a menu...
24260         Roo.bootstrap.MenuMgr.hideAll();
24261         */
24262         Roo.bootstrap.MenuMgr.hideAll();
24263         //this.editorsyncValue();
24264     },
24265     onFirstFocus: function() {
24266         this.buttons.each(function(item){
24267            item.enable();
24268         });
24269     },
24270     toggleSourceEdit : function(sourceEditMode){
24271         
24272           
24273         if(sourceEditMode){
24274             Roo.log("disabling buttons");
24275            this.buttons.each( function(item){
24276                 if(item.cmd != 'pencil'){
24277                     item.disable();
24278                 }
24279             });
24280           
24281         }else{
24282             Roo.log("enabling buttons");
24283             if(this.editorcore.initialized){
24284                 this.buttons.each( function(item){
24285                     item.enable();
24286                 });
24287             }
24288             
24289         }
24290         Roo.log("calling toggole on editor");
24291         // tell the editor that it's been pressed..
24292         this.editor.toggleSourceEdit(sourceEditMode);
24293        
24294     }
24295 });
24296
24297
24298
24299
24300
24301 /**
24302  * @class Roo.bootstrap.Table.AbstractSelectionModel
24303  * @extends Roo.util.Observable
24304  * Abstract base class for grid SelectionModels.  It provides the interface that should be
24305  * implemented by descendant classes.  This class should not be directly instantiated.
24306  * @constructor
24307  */
24308 Roo.bootstrap.Table.AbstractSelectionModel = function(){
24309     this.locked = false;
24310     Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
24311 };
24312
24313
24314 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable,  {
24315     /** @ignore Called by the grid automatically. Do not call directly. */
24316     init : function(grid){
24317         this.grid = grid;
24318         this.initEvents();
24319     },
24320
24321     /**
24322      * Locks the selections.
24323      */
24324     lock : function(){
24325         this.locked = true;
24326     },
24327
24328     /**
24329      * Unlocks the selections.
24330      */
24331     unlock : function(){
24332         this.locked = false;
24333     },
24334
24335     /**
24336      * Returns true if the selections are locked.
24337      * @return {Boolean}
24338      */
24339     isLocked : function(){
24340         return this.locked;
24341     }
24342 });
24343 /**
24344  * @extends Roo.bootstrap.Table.AbstractSelectionModel
24345  * @class Roo.bootstrap.Table.RowSelectionModel
24346  * The default SelectionModel used by {@link Roo.bootstrap.Table}.
24347  * It supports multiple selections and keyboard selection/navigation. 
24348  * @constructor
24349  * @param {Object} config
24350  */
24351
24352 Roo.bootstrap.Table.RowSelectionModel = function(config){
24353     Roo.apply(this, config);
24354     this.selections = new Roo.util.MixedCollection(false, function(o){
24355         return o.id;
24356     });
24357
24358     this.last = false;
24359     this.lastActive = false;
24360
24361     this.addEvents({
24362         /**
24363              * @event selectionchange
24364              * Fires when the selection changes
24365              * @param {SelectionModel} this
24366              */
24367             "selectionchange" : true,
24368         /**
24369              * @event afterselectionchange
24370              * Fires after the selection changes (eg. by key press or clicking)
24371              * @param {SelectionModel} this
24372              */
24373             "afterselectionchange" : true,
24374         /**
24375              * @event beforerowselect
24376              * Fires when a row is selected being selected, return false to cancel.
24377              * @param {SelectionModel} this
24378              * @param {Number} rowIndex The selected index
24379              * @param {Boolean} keepExisting False if other selections will be cleared
24380              */
24381             "beforerowselect" : true,
24382         /**
24383              * @event rowselect
24384              * Fires when a row is selected.
24385              * @param {SelectionModel} this
24386              * @param {Number} rowIndex The selected index
24387              * @param {Roo.data.Record} r The record
24388              */
24389             "rowselect" : true,
24390         /**
24391              * @event rowdeselect
24392              * Fires when a row is deselected.
24393              * @param {SelectionModel} this
24394              * @param {Number} rowIndex The selected index
24395              */
24396         "rowdeselect" : true
24397     });
24398     Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
24399     this.locked = false;
24400  };
24401
24402 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel,  {
24403     /**
24404      * @cfg {Boolean} singleSelect
24405      * True to allow selection of only one row at a time (defaults to false)
24406      */
24407     singleSelect : false,
24408
24409     // private
24410     initEvents : function()
24411     {
24412
24413         //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
24414         //    this.growclickrid.on("mousedown", this.handleMouseDown, this);
24415         //}else{ // allow click to work like normal
24416          //   this.grid.on("rowclick", this.handleDragableRowClick, this);
24417         //}
24418         //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
24419         this.grid.on("rowclick", this.handleMouseDown, this);
24420         
24421         this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
24422             "up" : function(e){
24423                 if(!e.shiftKey){
24424                     this.selectPrevious(e.shiftKey);
24425                 }else if(this.last !== false && this.lastActive !== false){
24426                     var last = this.last;
24427                     this.selectRange(this.last,  this.lastActive-1);
24428                     this.grid.getView().focusRow(this.lastActive);
24429                     if(last !== false){
24430                         this.last = last;
24431                     }
24432                 }else{
24433                     this.selectFirstRow();
24434                 }
24435                 this.fireEvent("afterselectionchange", this);
24436             },
24437             "down" : function(e){
24438                 if(!e.shiftKey){
24439                     this.selectNext(e.shiftKey);
24440                 }else if(this.last !== false && this.lastActive !== false){
24441                     var last = this.last;
24442                     this.selectRange(this.last,  this.lastActive+1);
24443                     this.grid.getView().focusRow(this.lastActive);
24444                     if(last !== false){
24445                         this.last = last;
24446                     }
24447                 }else{
24448                     this.selectFirstRow();
24449                 }
24450                 this.fireEvent("afterselectionchange", this);
24451             },
24452             scope: this
24453         });
24454         this.grid.store.on('load', function(){
24455             this.selections.clear();
24456         },this);
24457         /*
24458         var view = this.grid.view;
24459         view.on("refresh", this.onRefresh, this);
24460         view.on("rowupdated", this.onRowUpdated, this);
24461         view.on("rowremoved", this.onRemove, this);
24462         */
24463     },
24464
24465     // private
24466     onRefresh : function()
24467     {
24468         var ds = this.grid.store, i, v = this.grid.view;
24469         var s = this.selections;
24470         s.each(function(r){
24471             if((i = ds.indexOfId(r.id)) != -1){
24472                 v.onRowSelect(i);
24473             }else{
24474                 s.remove(r);
24475             }
24476         });
24477     },
24478
24479     // private
24480     onRemove : function(v, index, r){
24481         this.selections.remove(r);
24482     },
24483
24484     // private
24485     onRowUpdated : function(v, index, r){
24486         if(this.isSelected(r)){
24487             v.onRowSelect(index);
24488         }
24489     },
24490
24491     /**
24492      * Select records.
24493      * @param {Array} records The records to select
24494      * @param {Boolean} keepExisting (optional) True to keep existing selections
24495      */
24496     selectRecords : function(records, keepExisting)
24497     {
24498         if(!keepExisting){
24499             this.clearSelections();
24500         }
24501             var ds = this.grid.store;
24502         for(var i = 0, len = records.length; i < len; i++){
24503             this.selectRow(ds.indexOf(records[i]), true);
24504         }
24505     },
24506
24507     /**
24508      * Gets the number of selected rows.
24509      * @return {Number}
24510      */
24511     getCount : function(){
24512         return this.selections.length;
24513     },
24514
24515     /**
24516      * Selects the first row in the grid.
24517      */
24518     selectFirstRow : function(){
24519         this.selectRow(0);
24520     },
24521
24522     /**
24523      * Select the last row.
24524      * @param {Boolean} keepExisting (optional) True to keep existing selections
24525      */
24526     selectLastRow : function(keepExisting){
24527         //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
24528         this.selectRow(this.grid.store.getCount() - 1, keepExisting);
24529     },
24530
24531     /**
24532      * Selects the row immediately following the last selected row.
24533      * @param {Boolean} keepExisting (optional) True to keep existing selections
24534      */
24535     selectNext : function(keepExisting)
24536     {
24537             if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
24538             this.selectRow(this.last+1, keepExisting);
24539             this.grid.getView().focusRow(this.last);
24540         }
24541     },
24542
24543     /**
24544      * Selects the row that precedes the last selected row.
24545      * @param {Boolean} keepExisting (optional) True to keep existing selections
24546      */
24547     selectPrevious : function(keepExisting){
24548         if(this.last){
24549             this.selectRow(this.last-1, keepExisting);
24550             this.grid.getView().focusRow(this.last);
24551         }
24552     },
24553
24554     /**
24555      * Returns the selected records
24556      * @return {Array} Array of selected records
24557      */
24558     getSelections : function(){
24559         return [].concat(this.selections.items);
24560     },
24561
24562     /**
24563      * Returns the first selected record.
24564      * @return {Record}
24565      */
24566     getSelected : function(){
24567         return this.selections.itemAt(0);
24568     },
24569
24570
24571     /**
24572      * Clears all selections.
24573      */
24574     clearSelections : function(fast)
24575     {
24576         if(this.locked) {
24577             return;
24578         }
24579         if(fast !== true){
24580                 var ds = this.grid.store;
24581             var s = this.selections;
24582             s.each(function(r){
24583                 this.deselectRow(ds.indexOfId(r.id));
24584             }, this);
24585             s.clear();
24586         }else{
24587             this.selections.clear();
24588         }
24589         this.last = false;
24590     },
24591
24592
24593     /**
24594      * Selects all rows.
24595      */
24596     selectAll : function(){
24597         if(this.locked) {
24598             return;
24599         }
24600         this.selections.clear();
24601         for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
24602             this.selectRow(i, true);
24603         }
24604     },
24605
24606     /**
24607      * Returns True if there is a selection.
24608      * @return {Boolean}
24609      */
24610     hasSelection : function(){
24611         return this.selections.length > 0;
24612     },
24613
24614     /**
24615      * Returns True if the specified row is selected.
24616      * @param {Number/Record} record The record or index of the record to check
24617      * @return {Boolean}
24618      */
24619     isSelected : function(index){
24620             var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
24621         return (r && this.selections.key(r.id) ? true : false);
24622     },
24623
24624     /**
24625      * Returns True if the specified record id is selected.
24626      * @param {String} id The id of record to check
24627      * @return {Boolean}
24628      */
24629     isIdSelected : function(id){
24630         return (this.selections.key(id) ? true : false);
24631     },
24632
24633
24634     // private
24635     handleMouseDBClick : function(e, t){
24636         
24637     },
24638     // private
24639     handleMouseDown : function(e, t)
24640     {
24641             var rowIndex = this.grid.headerShow  ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
24642         if(this.isLocked() || rowIndex < 0 ){
24643             return;
24644         };
24645         if(e.shiftKey && this.last !== false){
24646             var last = this.last;
24647             this.selectRange(last, rowIndex, e.ctrlKey);
24648             this.last = last; // reset the last
24649             t.focus();
24650     
24651         }else{
24652             var isSelected = this.isSelected(rowIndex);
24653             //Roo.log("select row:" + rowIndex);
24654             if(isSelected){
24655                 this.deselectRow(rowIndex);
24656             } else {
24657                         this.selectRow(rowIndex, true);
24658             }
24659     
24660             /*
24661                 if(e.button !== 0 && isSelected){
24662                 alert('rowIndex 2: ' + rowIndex);
24663                     view.focusRow(rowIndex);
24664                 }else if(e.ctrlKey && isSelected){
24665                     this.deselectRow(rowIndex);
24666                 }else if(!isSelected){
24667                     this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
24668                     view.focusRow(rowIndex);
24669                 }
24670             */
24671         }
24672         this.fireEvent("afterselectionchange", this);
24673     },
24674     // private
24675     handleDragableRowClick :  function(grid, rowIndex, e) 
24676     {
24677         if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
24678             this.selectRow(rowIndex, false);
24679             grid.view.focusRow(rowIndex);
24680              this.fireEvent("afterselectionchange", this);
24681         }
24682     },
24683     
24684     /**
24685      * Selects multiple rows.
24686      * @param {Array} rows Array of the indexes of the row to select
24687      * @param {Boolean} keepExisting (optional) True to keep existing selections
24688      */
24689     selectRows : function(rows, keepExisting){
24690         if(!keepExisting){
24691             this.clearSelections();
24692         }
24693         for(var i = 0, len = rows.length; i < len; i++){
24694             this.selectRow(rows[i], true);
24695         }
24696     },
24697
24698     /**
24699      * Selects a range of rows. All rows in between startRow and endRow are also selected.
24700      * @param {Number} startRow The index of the first row in the range
24701      * @param {Number} endRow The index of the last row in the range
24702      * @param {Boolean} keepExisting (optional) True to retain existing selections
24703      */
24704     selectRange : function(startRow, endRow, keepExisting){
24705         if(this.locked) {
24706             return;
24707         }
24708         if(!keepExisting){
24709             this.clearSelections();
24710         }
24711         if(startRow <= endRow){
24712             for(var i = startRow; i <= endRow; i++){
24713                 this.selectRow(i, true);
24714             }
24715         }else{
24716             for(var i = startRow; i >= endRow; i--){
24717                 this.selectRow(i, true);
24718             }
24719         }
24720     },
24721
24722     /**
24723      * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
24724      * @param {Number} startRow The index of the first row in the range
24725      * @param {Number} endRow The index of the last row in the range
24726      */
24727     deselectRange : function(startRow, endRow, preventViewNotify){
24728         if(this.locked) {
24729             return;
24730         }
24731         for(var i = startRow; i <= endRow; i++){
24732             this.deselectRow(i, preventViewNotify);
24733         }
24734     },
24735
24736     /**
24737      * Selects a row.
24738      * @param {Number} row The index of the row to select
24739      * @param {Boolean} keepExisting (optional) True to keep existing selections
24740      */
24741     selectRow : function(index, keepExisting, preventViewNotify)
24742     {
24743             if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
24744             return;
24745         }
24746         if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
24747             if(!keepExisting || this.singleSelect){
24748                 this.clearSelections();
24749             }
24750             
24751             var r = this.grid.store.getAt(index);
24752             //console.log('selectRow - record id :' + r.id);
24753             
24754             this.selections.add(r);
24755             this.last = this.lastActive = index;
24756             if(!preventViewNotify){
24757                 var proxy = new Roo.Element(
24758                                 this.grid.getRowDom(index)
24759                 );
24760                 proxy.addClass('bg-info info');
24761             }
24762             this.fireEvent("rowselect", this, index, r);
24763             this.fireEvent("selectionchange", this);
24764         }
24765     },
24766
24767     /**
24768      * Deselects a row.
24769      * @param {Number} row The index of the row to deselect
24770      */
24771     deselectRow : function(index, preventViewNotify)
24772     {
24773         if(this.locked) {
24774             return;
24775         }
24776         if(this.last == index){
24777             this.last = false;
24778         }
24779         if(this.lastActive == index){
24780             this.lastActive = false;
24781         }
24782         
24783         var r = this.grid.store.getAt(index);
24784         if (!r) {
24785             return;
24786         }
24787         
24788         this.selections.remove(r);
24789         //.console.log('deselectRow - record id :' + r.id);
24790         if(!preventViewNotify){
24791         
24792             var proxy = new Roo.Element(
24793                 this.grid.getRowDom(index)
24794             );
24795             proxy.removeClass('bg-info info');
24796         }
24797         this.fireEvent("rowdeselect", this, index);
24798         this.fireEvent("selectionchange", this);
24799     },
24800
24801     // private
24802     restoreLast : function(){
24803         if(this._last){
24804             this.last = this._last;
24805         }
24806     },
24807
24808     // private
24809     acceptsNav : function(row, col, cm){
24810         return !cm.isHidden(col) && cm.isCellEditable(col, row);
24811     },
24812
24813     // private
24814     onEditorKey : function(field, e){
24815         var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
24816         if(k == e.TAB){
24817             e.stopEvent();
24818             ed.completeEdit();
24819             if(e.shiftKey){
24820                 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
24821             }else{
24822                 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
24823             }
24824         }else if(k == e.ENTER && !e.ctrlKey){
24825             e.stopEvent();
24826             ed.completeEdit();
24827             if(e.shiftKey){
24828                 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24829             }else{
24830                 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24831             }
24832         }else if(k == e.ESC){
24833             ed.cancelEdit();
24834         }
24835         if(newCell){
24836             g.startEditing(newCell[0], newCell[1]);
24837         }
24838     }
24839 });
24840 /*
24841  * Based on:
24842  * Ext JS Library 1.1.1
24843  * Copyright(c) 2006-2007, Ext JS, LLC.
24844  *
24845  * Originally Released Under LGPL - original licence link has changed is not relivant.
24846  *
24847  * Fork - LGPL
24848  * <script type="text/javascript">
24849  */
24850  
24851 /**
24852  * @class Roo.bootstrap.PagingToolbar
24853  * @extends Roo.bootstrap.NavSimplebar
24854  * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24855  * @constructor
24856  * Create a new PagingToolbar
24857  * @param {Object} config The config object
24858  * @param {Roo.data.Store} store
24859  */
24860 Roo.bootstrap.PagingToolbar = function(config)
24861 {
24862     // old args format still supported... - xtype is prefered..
24863         // created from xtype...
24864     
24865     this.ds = config.dataSource;
24866     
24867     if (config.store && !this.ds) {
24868         this.store= Roo.factory(config.store, Roo.data);
24869         this.ds = this.store;
24870         this.ds.xmodule = this.xmodule || false;
24871     }
24872     
24873     this.toolbarItems = [];
24874     if (config.items) {
24875         this.toolbarItems = config.items;
24876     }
24877     
24878     Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24879     
24880     this.cursor = 0;
24881     
24882     if (this.ds) { 
24883         this.bind(this.ds);
24884     }
24885     
24886     if (Roo.bootstrap.version == 4) {
24887         this.navgroup = new Roo.bootstrap.ButtonGroup({ cls: 'pagination' });
24888     } else {
24889         this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24890     }
24891     
24892 };
24893
24894 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24895     /**
24896      * @cfg {Roo.data.Store} dataSource
24897      * The underlying data store providing the paged data
24898      */
24899     /**
24900      * @cfg {String/HTMLElement/Element} container
24901      * container The id or element that will contain the toolbar
24902      */
24903     /**
24904      * @cfg {Boolean} displayInfo
24905      * True to display the displayMsg (defaults to false)
24906      */
24907     /**
24908      * @cfg {Number} pageSize
24909      * The number of records to display per page (defaults to 20)
24910      */
24911     pageSize: 20,
24912     /**
24913      * @cfg {String} displayMsg
24914      * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24915      */
24916     displayMsg : 'Displaying {0} - {1} of {2}',
24917     /**
24918      * @cfg {String} emptyMsg
24919      * The message to display when no records are found (defaults to "No data to display")
24920      */
24921     emptyMsg : 'No data to display',
24922     /**
24923      * Customizable piece of the default paging text (defaults to "Page")
24924      * @type String
24925      */
24926     beforePageText : "Page",
24927     /**
24928      * Customizable piece of the default paging text (defaults to "of %0")
24929      * @type String
24930      */
24931     afterPageText : "of {0}",
24932     /**
24933      * Customizable piece of the default paging text (defaults to "First Page")
24934      * @type String
24935      */
24936     firstText : "First Page",
24937     /**
24938      * Customizable piece of the default paging text (defaults to "Previous Page")
24939      * @type String
24940      */
24941     prevText : "Previous Page",
24942     /**
24943      * Customizable piece of the default paging text (defaults to "Next Page")
24944      * @type String
24945      */
24946     nextText : "Next Page",
24947     /**
24948      * Customizable piece of the default paging text (defaults to "Last Page")
24949      * @type String
24950      */
24951     lastText : "Last Page",
24952     /**
24953      * Customizable piece of the default paging text (defaults to "Refresh")
24954      * @type String
24955      */
24956     refreshText : "Refresh",
24957
24958     buttons : false,
24959     // private
24960     onRender : function(ct, position) 
24961     {
24962         Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24963         this.navgroup.parentId = this.id;
24964         this.navgroup.onRender(this.el, null);
24965         // add the buttons to the navgroup
24966         
24967         if(this.displayInfo){
24968             this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24969             this.displayEl = this.el.select('.x-paging-info', true).first();
24970 //            var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24971 //            this.displayEl = navel.el.select('span',true).first();
24972         }
24973         
24974         var _this = this;
24975         
24976         if(this.buttons){
24977             Roo.each(_this.buttons, function(e){ // this might need to use render????
24978                Roo.factory(e).render(_this.el);
24979             });
24980         }
24981             
24982         Roo.each(_this.toolbarItems, function(e) {
24983             _this.navgroup.addItem(e);
24984         });
24985         
24986         
24987         this.first = this.navgroup.addItem({
24988             tooltip: this.firstText,
24989             cls: "prev btn-outline-secondary",
24990             html : ' <i class="fa fa-step-backward"></i>',
24991             disabled: true,
24992             preventDefault: true,
24993             listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24994         });
24995         
24996         this.prev =  this.navgroup.addItem({
24997             tooltip: this.prevText,
24998             cls: "prev btn-outline-secondary",
24999             html : ' <i class="fa fa-backward"></i>',
25000             disabled: true,
25001             preventDefault: true,
25002             listeners : { click :  this.onClick.createDelegate(this, ["prev"]) }
25003         });
25004     //this.addSeparator();
25005         
25006         
25007         var field = this.navgroup.addItem( {
25008             tagtype : 'span',
25009             cls : 'x-paging-position  btn-outline-secondary',
25010              disabled: true,
25011             html : this.beforePageText  +
25012                 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
25013                 '<span class="x-paging-after">' +  String.format(this.afterPageText, 1) + '</span>'
25014          } ); //?? escaped?
25015         
25016         this.field = field.el.select('input', true).first();
25017         this.field.on("keydown", this.onPagingKeydown, this);
25018         this.field.on("focus", function(){this.dom.select();});
25019     
25020     
25021         this.afterTextEl =  field.el.select('.x-paging-after',true).first();
25022         //this.field.setHeight(18);
25023         //this.addSeparator();
25024         this.next = this.navgroup.addItem({
25025             tooltip: this.nextText,
25026             cls: "next btn-outline-secondary",
25027             html : ' <i class="fa fa-forward"></i>',
25028             disabled: true,
25029             preventDefault: true,
25030             listeners : { click :  this.onClick.createDelegate(this, ["next"]) }
25031         });
25032         this.last = this.navgroup.addItem({
25033             tooltip: this.lastText,
25034             html : ' <i class="fa fa-step-forward"></i>',
25035             cls: "next btn-outline-secondary",
25036             disabled: true,
25037             preventDefault: true,
25038             listeners : { click :  this.onClick.createDelegate(this, ["last"]) }
25039         });
25040     //this.addSeparator();
25041         this.loading = this.navgroup.addItem({
25042             tooltip: this.refreshText,
25043             cls: "btn-outline-secondary",
25044             html : ' <i class="fa fa-refresh"></i>',
25045             preventDefault: true,
25046             listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
25047         });
25048         
25049     },
25050
25051     // private
25052     updateInfo : function(){
25053         if(this.displayEl){
25054             var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
25055             var msg = count == 0 ?
25056                 this.emptyMsg :
25057                 String.format(
25058                     this.displayMsg,
25059                     this.cursor+1, this.cursor+count, this.ds.getTotalCount()    
25060                 );
25061             this.displayEl.update(msg);
25062         }
25063     },
25064
25065     // private
25066     onLoad : function(ds, r, o)
25067     {
25068         this.cursor = o.params.start ? o.params.start : 0;
25069         
25070         var d = this.getPageData(),
25071             ap = d.activePage,
25072             ps = d.pages;
25073         
25074         
25075         this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
25076         this.field.dom.value = ap;
25077         this.first.setDisabled(ap == 1);
25078         this.prev.setDisabled(ap == 1);
25079         this.next.setDisabled(ap == ps);
25080         this.last.setDisabled(ap == ps);
25081         this.loading.enable();
25082         this.updateInfo();
25083     },
25084
25085     // private
25086     getPageData : function(){
25087         var total = this.ds.getTotalCount();
25088         return {
25089             total : total,
25090             activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
25091             pages :  total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
25092         };
25093     },
25094
25095     // private
25096     onLoadError : function(){
25097         this.loading.enable();
25098     },
25099
25100     // private
25101     onPagingKeydown : function(e){
25102         var k = e.getKey();
25103         var d = this.getPageData();
25104         if(k == e.RETURN){
25105             var v = this.field.dom.value, pageNum;
25106             if(!v || isNaN(pageNum = parseInt(v, 10))){
25107                 this.field.dom.value = d.activePage;
25108                 return;
25109             }
25110             pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
25111             this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
25112             e.stopEvent();
25113         }
25114         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))
25115         {
25116           var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
25117           this.field.dom.value = pageNum;
25118           this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
25119           e.stopEvent();
25120         }
25121         else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
25122         {
25123           var v = this.field.dom.value, pageNum; 
25124           var increment = (e.shiftKey) ? 10 : 1;
25125           if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
25126                 increment *= -1;
25127           }
25128           if(!v || isNaN(pageNum = parseInt(v, 10))) {
25129             this.field.dom.value = d.activePage;
25130             return;
25131           }
25132           else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
25133           {
25134             this.field.dom.value = parseInt(v, 10) + increment;
25135             pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
25136             this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
25137           }
25138           e.stopEvent();
25139         }
25140     },
25141
25142     // private
25143     beforeLoad : function(){
25144         if(this.loading){
25145             this.loading.disable();
25146         }
25147     },
25148
25149     // private
25150     onClick : function(which){
25151         
25152         var ds = this.ds;
25153         if (!ds) {
25154             return;
25155         }
25156         
25157         switch(which){
25158             case "first":
25159                 ds.load({params:{start: 0, limit: this.pageSize}});
25160             break;
25161             case "prev":
25162                 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
25163             break;
25164             case "next":
25165                 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
25166             break;
25167             case "last":
25168                 var total = ds.getTotalCount();
25169                 var extra = total % this.pageSize;
25170                 var lastStart = extra ? (total - extra) : total-this.pageSize;
25171                 ds.load({params:{start: lastStart, limit: this.pageSize}});
25172             break;
25173             case "refresh":
25174                 ds.load({params:{start: this.cursor, limit: this.pageSize}});
25175             break;
25176         }
25177     },
25178
25179     /**
25180      * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
25181      * @param {Roo.data.Store} store The data store to unbind
25182      */
25183     unbind : function(ds){
25184         ds.un("beforeload", this.beforeLoad, this);
25185         ds.un("load", this.onLoad, this);
25186         ds.un("loadexception", this.onLoadError, this);
25187         ds.un("remove", this.updateInfo, this);
25188         ds.un("add", this.updateInfo, this);
25189         this.ds = undefined;
25190     },
25191
25192     /**
25193      * Binds the paging toolbar to the specified {@link Roo.data.Store}
25194      * @param {Roo.data.Store} store The data store to bind
25195      */
25196     bind : function(ds){
25197         ds.on("beforeload", this.beforeLoad, this);
25198         ds.on("load", this.onLoad, this);
25199         ds.on("loadexception", this.onLoadError, this);
25200         ds.on("remove", this.updateInfo, this);
25201         ds.on("add", this.updateInfo, this);
25202         this.ds = ds;
25203     }
25204 });/*
25205  * - LGPL
25206  *
25207  * element
25208  * 
25209  */
25210
25211 /**
25212  * @class Roo.bootstrap.MessageBar
25213  * @extends Roo.bootstrap.Component
25214  * Bootstrap MessageBar class
25215  * @cfg {String} html contents of the MessageBar
25216  * @cfg {String} weight (info | success | warning | danger) default info
25217  * @cfg {String} beforeClass insert the bar before the given class
25218  * @cfg {Boolean} closable (true | false) default false
25219  * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
25220  * 
25221  * @constructor
25222  * Create a new Element
25223  * @param {Object} config The config object
25224  */
25225
25226 Roo.bootstrap.MessageBar = function(config){
25227     Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
25228 };
25229
25230 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component,  {
25231     
25232     html: '',
25233     weight: 'info',
25234     closable: false,
25235     fixed: false,
25236     beforeClass: 'bootstrap-sticky-wrap',
25237     
25238     getAutoCreate : function(){
25239         
25240         var cfg = {
25241             tag: 'div',
25242             cls: 'alert alert-dismissable alert-' + this.weight,
25243             cn: [
25244                 {
25245                     tag: 'span',
25246                     cls: 'message',
25247                     html: this.html || ''
25248                 }
25249             ]
25250         };
25251         
25252         if(this.fixed){
25253             cfg.cls += ' alert-messages-fixed';
25254         }
25255         
25256         if(this.closable){
25257             cfg.cn.push({
25258                 tag: 'button',
25259                 cls: 'close',
25260                 html: 'x'
25261             });
25262         }
25263         
25264         return cfg;
25265     },
25266     
25267     onRender : function(ct, position)
25268     {
25269         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
25270         
25271         if(!this.el){
25272             var cfg = Roo.apply({},  this.getAutoCreate());
25273             cfg.id = Roo.id();
25274             
25275             if (this.cls) {
25276                 cfg.cls += ' ' + this.cls;
25277             }
25278             if (this.style) {
25279                 cfg.style = this.style;
25280             }
25281             this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
25282             
25283             this.el.setVisibilityMode(Roo.Element.DISPLAY);
25284         }
25285         
25286         this.el.select('>button.close').on('click', this.hide, this);
25287         
25288     },
25289     
25290     show : function()
25291     {
25292         if (!this.rendered) {
25293             this.render();
25294         }
25295         
25296         this.el.show();
25297         
25298         this.fireEvent('show', this);
25299         
25300     },
25301     
25302     hide : function()
25303     {
25304         if (!this.rendered) {
25305             this.render();
25306         }
25307         
25308         this.el.hide();
25309         
25310         this.fireEvent('hide', this);
25311     },
25312     
25313     update : function()
25314     {
25315 //        var e = this.el.dom.firstChild;
25316 //        
25317 //        if(this.closable){
25318 //            e = e.nextSibling;
25319 //        }
25320 //        
25321 //        e.data = this.html || '';
25322
25323         this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
25324     }
25325    
25326 });
25327
25328  
25329
25330      /*
25331  * - LGPL
25332  *
25333  * Graph
25334  * 
25335  */
25336
25337
25338 /**
25339  * @class Roo.bootstrap.Graph
25340  * @extends Roo.bootstrap.Component
25341  * Bootstrap Graph class
25342 > Prameters
25343  -sm {number} sm 4
25344  -md {number} md 5
25345  @cfg {String} graphtype  bar | vbar | pie
25346  @cfg {number} g_x coodinator | centre x (pie)
25347  @cfg {number} g_y coodinator | centre y (pie)
25348  @cfg {number} g_r radius (pie)
25349  @cfg {number} g_height height of the chart (respected by all elements in the set)
25350  @cfg {number} g_width width of the chart (respected by all elements in the set)
25351  @cfg {Object} title The title of the chart
25352     
25353  -{Array}  values
25354  -opts (object) options for the chart 
25355      o {
25356      o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
25357      o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
25358      o vgutter (number)
25359      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.
25360      o stacked (boolean) whether or not to tread values as in a stacked bar chart
25361      o to
25362      o stretch (boolean)
25363      o }
25364  -opts (object) options for the pie
25365      o{
25366      o cut
25367      o startAngle (number)
25368      o endAngle (number)
25369      } 
25370  *
25371  * @constructor
25372  * Create a new Input
25373  * @param {Object} config The config object
25374  */
25375
25376 Roo.bootstrap.Graph = function(config){
25377     Roo.bootstrap.Graph.superclass.constructor.call(this, config);
25378     
25379     this.addEvents({
25380         // img events
25381         /**
25382          * @event click
25383          * The img click event for the img.
25384          * @param {Roo.EventObject} e
25385          */
25386         "click" : true
25387     });
25388 };
25389
25390 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component,  {
25391     
25392     sm: 4,
25393     md: 5,
25394     graphtype: 'bar',
25395     g_height: 250,
25396     g_width: 400,
25397     g_x: 50,
25398     g_y: 50,
25399     g_r: 30,
25400     opts:{
25401         //g_colors: this.colors,
25402         g_type: 'soft',
25403         g_gutter: '20%'
25404
25405     },
25406     title : false,
25407
25408     getAutoCreate : function(){
25409         
25410         var cfg = {
25411             tag: 'div',
25412             html : null
25413         };
25414         
25415         
25416         return  cfg;
25417     },
25418
25419     onRender : function(ct,position){
25420         
25421         
25422         Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
25423         
25424         if (typeof(Raphael) == 'undefined') {
25425             Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
25426             return;
25427         }
25428         
25429         this.raphael = Raphael(this.el.dom);
25430         
25431                     // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25432                     // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25433                     // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25434                     // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
25435                 /*
25436                 r.text(160, 10, "Single Series Chart").attr(txtattr);
25437                 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
25438                 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
25439                 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
25440                 
25441                 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
25442                 r.barchart(330, 10, 300, 220, data1);
25443                 r.barchart(10, 250, 300, 220, data2, {stacked: true});
25444                 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
25445                 */
25446                 
25447                 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25448                 // r.barchart(30, 30, 560, 250,  xdata, {
25449                 //    labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
25450                 //     axis : "0 0 1 1",
25451                 //     axisxlabels :  xdata
25452                 //     //yvalues : cols,
25453                    
25454                 // });
25455 //        var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25456 //        
25457 //        this.load(null,xdata,{
25458 //                axis : "0 0 1 1",
25459 //                axisxlabels :  xdata
25460 //                });
25461
25462     },
25463
25464     load : function(graphtype,xdata,opts)
25465     {
25466         this.raphael.clear();
25467         if(!graphtype) {
25468             graphtype = this.graphtype;
25469         }
25470         if(!opts){
25471             opts = this.opts;
25472         }
25473         var r = this.raphael,
25474             fin = function () {
25475                 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
25476             },
25477             fout = function () {
25478                 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
25479             },
25480             pfin = function() {
25481                 this.sector.stop();
25482                 this.sector.scale(1.1, 1.1, this.cx, this.cy);
25483
25484                 if (this.label) {
25485                     this.label[0].stop();
25486                     this.label[0].attr({ r: 7.5 });
25487                     this.label[1].attr({ "font-weight": 800 });
25488                 }
25489             },
25490             pfout = function() {
25491                 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
25492
25493                 if (this.label) {
25494                     this.label[0].animate({ r: 5 }, 500, "bounce");
25495                     this.label[1].attr({ "font-weight": 400 });
25496                 }
25497             };
25498
25499         switch(graphtype){
25500             case 'bar':
25501                 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25502                 break;
25503             case 'hbar':
25504                 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25505                 break;
25506             case 'pie':
25507 //                opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west", 
25508 //                href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
25509 //            
25510                 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
25511                 
25512                 break;
25513
25514         }
25515         
25516         if(this.title){
25517             this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
25518         }
25519         
25520     },
25521     
25522     setTitle: function(o)
25523     {
25524         this.title = o;
25525     },
25526     
25527     initEvents: function() {
25528         
25529         if(!this.href){
25530             this.el.on('click', this.onClick, this);
25531         }
25532     },
25533     
25534     onClick : function(e)
25535     {
25536         Roo.log('img onclick');
25537         this.fireEvent('click', this, e);
25538     }
25539    
25540 });
25541
25542  
25543 /*
25544  * - LGPL
25545  *
25546  * numberBox
25547  * 
25548  */
25549 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25550
25551 /**
25552  * @class Roo.bootstrap.dash.NumberBox
25553  * @extends Roo.bootstrap.Component
25554  * Bootstrap NumberBox class
25555  * @cfg {String} headline Box headline
25556  * @cfg {String} content Box content
25557  * @cfg {String} icon Box icon
25558  * @cfg {String} footer Footer text
25559  * @cfg {String} fhref Footer href
25560  * 
25561  * @constructor
25562  * Create a new NumberBox
25563  * @param {Object} config The config object
25564  */
25565
25566
25567 Roo.bootstrap.dash.NumberBox = function(config){
25568     Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
25569     
25570 };
25571
25572 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component,  {
25573     
25574     headline : '',
25575     content : '',
25576     icon : '',
25577     footer : '',
25578     fhref : '',
25579     ficon : '',
25580     
25581     getAutoCreate : function(){
25582         
25583         var cfg = {
25584             tag : 'div',
25585             cls : 'small-box ',
25586             cn : [
25587                 {
25588                     tag : 'div',
25589                     cls : 'inner',
25590                     cn :[
25591                         {
25592                             tag : 'h3',
25593                             cls : 'roo-headline',
25594                             html : this.headline
25595                         },
25596                         {
25597                             tag : 'p',
25598                             cls : 'roo-content',
25599                             html : this.content
25600                         }
25601                     ]
25602                 }
25603             ]
25604         };
25605         
25606         if(this.icon){
25607             cfg.cn.push({
25608                 tag : 'div',
25609                 cls : 'icon',
25610                 cn :[
25611                     {
25612                         tag : 'i',
25613                         cls : 'ion ' + this.icon
25614                     }
25615                 ]
25616             });
25617         }
25618         
25619         if(this.footer){
25620             var footer = {
25621                 tag : 'a',
25622                 cls : 'small-box-footer',
25623                 href : this.fhref || '#',
25624                 html : this.footer
25625             };
25626             
25627             cfg.cn.push(footer);
25628             
25629         }
25630         
25631         return  cfg;
25632     },
25633
25634     onRender : function(ct,position){
25635         Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
25636
25637
25638        
25639                 
25640     },
25641
25642     setHeadline: function (value)
25643     {
25644         this.el.select('.roo-headline',true).first().dom.innerHTML = value;
25645     },
25646     
25647     setFooter: function (value, href)
25648     {
25649         this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
25650         
25651         if(href){
25652             this.el.select('a.small-box-footer',true).first().attr('href', href);
25653         }
25654         
25655     },
25656
25657     setContent: function (value)
25658     {
25659         this.el.select('.roo-content',true).first().dom.innerHTML = value;
25660     },
25661
25662     initEvents: function() 
25663     {   
25664         
25665     }
25666     
25667 });
25668
25669  
25670 /*
25671  * - LGPL
25672  *
25673  * TabBox
25674  * 
25675  */
25676 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25677
25678 /**
25679  * @class Roo.bootstrap.dash.TabBox
25680  * @extends Roo.bootstrap.Component
25681  * Bootstrap TabBox class
25682  * @cfg {String} title Title of the TabBox
25683  * @cfg {String} icon Icon of the TabBox
25684  * @cfg {Boolean} showtabs (true|false) show the tabs default true
25685  * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25686  * 
25687  * @constructor
25688  * Create a new TabBox
25689  * @param {Object} config The config object
25690  */
25691
25692
25693 Roo.bootstrap.dash.TabBox = function(config){
25694     Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25695     this.addEvents({
25696         // raw events
25697         /**
25698          * @event addpane
25699          * When a pane is added
25700          * @param {Roo.bootstrap.dash.TabPane} pane
25701          */
25702         "addpane" : true,
25703         /**
25704          * @event activatepane
25705          * When a pane is activated
25706          * @param {Roo.bootstrap.dash.TabPane} pane
25707          */
25708         "activatepane" : true
25709         
25710          
25711     });
25712     
25713     this.panes = [];
25714 };
25715
25716 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component,  {
25717
25718     title : '',
25719     icon : false,
25720     showtabs : true,
25721     tabScrollable : false,
25722     
25723     getChildContainer : function()
25724     {
25725         return this.el.select('.tab-content', true).first();
25726     },
25727     
25728     getAutoCreate : function(){
25729         
25730         var header = {
25731             tag: 'li',
25732             cls: 'pull-left header',
25733             html: this.title,
25734             cn : []
25735         };
25736         
25737         if(this.icon){
25738             header.cn.push({
25739                 tag: 'i',
25740                 cls: 'fa ' + this.icon
25741             });
25742         }
25743         
25744         var h = {
25745             tag: 'ul',
25746             cls: 'nav nav-tabs pull-right',
25747             cn: [
25748                 header
25749             ]
25750         };
25751         
25752         if(this.tabScrollable){
25753             h = {
25754                 tag: 'div',
25755                 cls: 'tab-header',
25756                 cn: [
25757                     {
25758                         tag: 'ul',
25759                         cls: 'nav nav-tabs pull-right',
25760                         cn: [
25761                             header
25762                         ]
25763                     }
25764                 ]
25765             };
25766         }
25767         
25768         var cfg = {
25769             tag: 'div',
25770             cls: 'nav-tabs-custom',
25771             cn: [
25772                 h,
25773                 {
25774                     tag: 'div',
25775                     cls: 'tab-content no-padding',
25776                     cn: []
25777                 }
25778             ]
25779         };
25780
25781         return  cfg;
25782     },
25783     initEvents : function()
25784     {
25785         //Roo.log('add add pane handler');
25786         this.on('addpane', this.onAddPane, this);
25787     },
25788      /**
25789      * Updates the box title
25790      * @param {String} html to set the title to.
25791      */
25792     setTitle : function(value)
25793     {
25794         this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25795     },
25796     onAddPane : function(pane)
25797     {
25798         this.panes.push(pane);
25799         //Roo.log('addpane');
25800         //Roo.log(pane);
25801         // tabs are rendere left to right..
25802         if(!this.showtabs){
25803             return;
25804         }
25805         
25806         var ctr = this.el.select('.nav-tabs', true).first();
25807          
25808          
25809         var existing = ctr.select('.nav-tab',true);
25810         var qty = existing.getCount();;
25811         
25812         
25813         var tab = ctr.createChild({
25814             tag : 'li',
25815             cls : 'nav-tab' + (qty ? '' : ' active'),
25816             cn : [
25817                 {
25818                     tag : 'a',
25819                     href:'#',
25820                     html : pane.title
25821                 }
25822             ]
25823         }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25824         pane.tab = tab;
25825         
25826         tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25827         if (!qty) {
25828             pane.el.addClass('active');
25829         }
25830         
25831                 
25832     },
25833     onTabClick : function(ev,un,ob,pane)
25834     {
25835         //Roo.log('tab - prev default');
25836         ev.preventDefault();
25837         
25838         
25839         this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25840         pane.tab.addClass('active');
25841         //Roo.log(pane.title);
25842         this.getChildContainer().select('.tab-pane',true).removeClass('active');
25843         // technically we should have a deactivate event.. but maybe add later.
25844         // and it should not de-activate the selected tab...
25845         this.fireEvent('activatepane', pane);
25846         pane.el.addClass('active');
25847         pane.fireEvent('activate');
25848         
25849         
25850     },
25851     
25852     getActivePane : function()
25853     {
25854         var r = false;
25855         Roo.each(this.panes, function(p) {
25856             if(p.el.hasClass('active')){
25857                 r = p;
25858                 return false;
25859             }
25860             
25861             return;
25862         });
25863         
25864         return r;
25865     }
25866     
25867     
25868 });
25869
25870  
25871 /*
25872  * - LGPL
25873  *
25874  * Tab pane
25875  * 
25876  */
25877 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25878 /**
25879  * @class Roo.bootstrap.TabPane
25880  * @extends Roo.bootstrap.Component
25881  * Bootstrap TabPane class
25882  * @cfg {Boolean} active (false | true) Default false
25883  * @cfg {String} title title of panel
25884
25885  * 
25886  * @constructor
25887  * Create a new TabPane
25888  * @param {Object} config The config object
25889  */
25890
25891 Roo.bootstrap.dash.TabPane = function(config){
25892     Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25893     
25894     this.addEvents({
25895         // raw events
25896         /**
25897          * @event activate
25898          * When a pane is activated
25899          * @param {Roo.bootstrap.dash.TabPane} pane
25900          */
25901         "activate" : true
25902          
25903     });
25904 };
25905
25906 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component,  {
25907     
25908     active : false,
25909     title : '',
25910     
25911     // the tabBox that this is attached to.
25912     tab : false,
25913      
25914     getAutoCreate : function() 
25915     {
25916         var cfg = {
25917             tag: 'div',
25918             cls: 'tab-pane'
25919         };
25920         
25921         if(this.active){
25922             cfg.cls += ' active';
25923         }
25924         
25925         return cfg;
25926     },
25927     initEvents  : function()
25928     {
25929         //Roo.log('trigger add pane handler');
25930         this.parent().fireEvent('addpane', this)
25931     },
25932     
25933      /**
25934      * Updates the tab title 
25935      * @param {String} html to set the title to.
25936      */
25937     setTitle: function(str)
25938     {
25939         if (!this.tab) {
25940             return;
25941         }
25942         this.title = str;
25943         this.tab.select('a', true).first().dom.innerHTML = str;
25944         
25945     }
25946     
25947     
25948     
25949 });
25950
25951  
25952
25953
25954  /*
25955  * - LGPL
25956  *
25957  * menu
25958  * 
25959  */
25960 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25961
25962 /**
25963  * @class Roo.bootstrap.menu.Menu
25964  * @extends Roo.bootstrap.Component
25965  * Bootstrap Menu class - container for Menu
25966  * @cfg {String} html Text of the menu
25967  * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25968  * @cfg {String} icon Font awesome icon
25969  * @cfg {String} pos Menu align to (top | bottom) default bottom
25970  * 
25971  * 
25972  * @constructor
25973  * Create a new Menu
25974  * @param {Object} config The config object
25975  */
25976
25977
25978 Roo.bootstrap.menu.Menu = function(config){
25979     Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25980     
25981     this.addEvents({
25982         /**
25983          * @event beforeshow
25984          * Fires before this menu is displayed
25985          * @param {Roo.bootstrap.menu.Menu} this
25986          */
25987         beforeshow : true,
25988         /**
25989          * @event beforehide
25990          * Fires before this menu is hidden
25991          * @param {Roo.bootstrap.menu.Menu} this
25992          */
25993         beforehide : true,
25994         /**
25995          * @event show
25996          * Fires after this menu is displayed
25997          * @param {Roo.bootstrap.menu.Menu} this
25998          */
25999         show : true,
26000         /**
26001          * @event hide
26002          * Fires after this menu is hidden
26003          * @param {Roo.bootstrap.menu.Menu} this
26004          */
26005         hide : true,
26006         /**
26007          * @event click
26008          * Fires when this menu is clicked (or when the enter key is pressed while it is active)
26009          * @param {Roo.bootstrap.menu.Menu} this
26010          * @param {Roo.EventObject} e
26011          */
26012         click : true
26013     });
26014     
26015 };
26016
26017 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component,  {
26018     
26019     submenu : false,
26020     html : '',
26021     weight : 'default',
26022     icon : false,
26023     pos : 'bottom',
26024     
26025     
26026     getChildContainer : function() {
26027         if(this.isSubMenu){
26028             return this.el;
26029         }
26030         
26031         return this.el.select('ul.dropdown-menu', true).first();  
26032     },
26033     
26034     getAutoCreate : function()
26035     {
26036         var text = [
26037             {
26038                 tag : 'span',
26039                 cls : 'roo-menu-text',
26040                 html : this.html
26041             }
26042         ];
26043         
26044         if(this.icon){
26045             text.unshift({
26046                 tag : 'i',
26047                 cls : 'fa ' + this.icon
26048             })
26049         }
26050         
26051         
26052         var cfg = {
26053             tag : 'div',
26054             cls : 'btn-group',
26055             cn : [
26056                 {
26057                     tag : 'button',
26058                     cls : 'dropdown-button btn btn-' + this.weight,
26059                     cn : text
26060                 },
26061                 {
26062                     tag : 'button',
26063                     cls : 'dropdown-toggle btn btn-' + this.weight,
26064                     cn : [
26065                         {
26066                             tag : 'span',
26067                             cls : 'caret'
26068                         }
26069                     ]
26070                 },
26071                 {
26072                     tag : 'ul',
26073                     cls : 'dropdown-menu'
26074                 }
26075             ]
26076             
26077         };
26078         
26079         if(this.pos == 'top'){
26080             cfg.cls += ' dropup';
26081         }
26082         
26083         if(this.isSubMenu){
26084             cfg = {
26085                 tag : 'ul',
26086                 cls : 'dropdown-menu'
26087             }
26088         }
26089         
26090         return cfg;
26091     },
26092     
26093     onRender : function(ct, position)
26094     {
26095         this.isSubMenu = ct.hasClass('dropdown-submenu');
26096         
26097         Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
26098     },
26099     
26100     initEvents : function() 
26101     {
26102         if(this.isSubMenu){
26103             return;
26104         }
26105         
26106         this.hidden = true;
26107         
26108         this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
26109         this.triggerEl.on('click', this.onTriggerPress, this);
26110         
26111         this.buttonEl = this.el.select('button.dropdown-button', true).first();
26112         this.buttonEl.on('click', this.onClick, this);
26113         
26114     },
26115     
26116     list : function()
26117     {
26118         if(this.isSubMenu){
26119             return this.el;
26120         }
26121         
26122         return this.el.select('ul.dropdown-menu', true).first();
26123     },
26124     
26125     onClick : function(e)
26126     {
26127         this.fireEvent("click", this, e);
26128     },
26129     
26130     onTriggerPress  : function(e)
26131     {   
26132         if (this.isVisible()) {
26133             this.hide();
26134         } else {
26135             this.show();
26136         }
26137     },
26138     
26139     isVisible : function(){
26140         return !this.hidden;
26141     },
26142     
26143     show : function()
26144     {
26145         this.fireEvent("beforeshow", this);
26146         
26147         this.hidden = false;
26148         this.el.addClass('open');
26149         
26150         Roo.get(document).on("mouseup", this.onMouseUp, this);
26151         
26152         this.fireEvent("show", this);
26153         
26154         
26155     },
26156     
26157     hide : function()
26158     {
26159         this.fireEvent("beforehide", this);
26160         
26161         this.hidden = true;
26162         this.el.removeClass('open');
26163         
26164         Roo.get(document).un("mouseup", this.onMouseUp);
26165         
26166         this.fireEvent("hide", this);
26167     },
26168     
26169     onMouseUp : function()
26170     {
26171         this.hide();
26172     }
26173     
26174 });
26175
26176  
26177  /*
26178  * - LGPL
26179  *
26180  * menu item
26181  * 
26182  */
26183 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
26184
26185 /**
26186  * @class Roo.bootstrap.menu.Item
26187  * @extends Roo.bootstrap.Component
26188  * Bootstrap MenuItem class
26189  * @cfg {Boolean} submenu (true | false) default false
26190  * @cfg {String} html text of the item
26191  * @cfg {String} href the link
26192  * @cfg {Boolean} disable (true | false) default false
26193  * @cfg {Boolean} preventDefault (true | false) default true
26194  * @cfg {String} icon Font awesome icon
26195  * @cfg {String} pos Submenu align to (left | right) default right 
26196  * 
26197  * 
26198  * @constructor
26199  * Create a new Item
26200  * @param {Object} config The config object
26201  */
26202
26203
26204 Roo.bootstrap.menu.Item = function(config){
26205     Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
26206     this.addEvents({
26207         /**
26208          * @event mouseover
26209          * Fires when the mouse is hovering over this menu
26210          * @param {Roo.bootstrap.menu.Item} this
26211          * @param {Roo.EventObject} e
26212          */
26213         mouseover : true,
26214         /**
26215          * @event mouseout
26216          * Fires when the mouse exits this menu
26217          * @param {Roo.bootstrap.menu.Item} this
26218          * @param {Roo.EventObject} e
26219          */
26220         mouseout : true,
26221         // raw events
26222         /**
26223          * @event click
26224          * The raw click event for the entire grid.
26225          * @param {Roo.EventObject} e
26226          */
26227         click : true
26228     });
26229 };
26230
26231 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component,  {
26232     
26233     submenu : false,
26234     href : '',
26235     html : '',
26236     preventDefault: true,
26237     disable : false,
26238     icon : false,
26239     pos : 'right',
26240     
26241     getAutoCreate : function()
26242     {
26243         var text = [
26244             {
26245                 tag : 'span',
26246                 cls : 'roo-menu-item-text',
26247                 html : this.html
26248             }
26249         ];
26250         
26251         if(this.icon){
26252             text.unshift({
26253                 tag : 'i',
26254                 cls : 'fa ' + this.icon
26255             })
26256         }
26257         
26258         var cfg = {
26259             tag : 'li',
26260             cn : [
26261                 {
26262                     tag : 'a',
26263                     href : this.href || '#',
26264                     cn : text
26265                 }
26266             ]
26267         };
26268         
26269         if(this.disable){
26270             cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
26271         }
26272         
26273         if(this.submenu){
26274             cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
26275             
26276             if(this.pos == 'left'){
26277                 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
26278             }
26279         }
26280         
26281         return cfg;
26282     },
26283     
26284     initEvents : function() 
26285     {
26286         this.el.on('mouseover', this.onMouseOver, this);
26287         this.el.on('mouseout', this.onMouseOut, this);
26288         
26289         this.el.select('a', true).first().on('click', this.onClick, this);
26290         
26291     },
26292     
26293     onClick : function(e)
26294     {
26295         if(this.preventDefault){
26296             e.preventDefault();
26297         }
26298         
26299         this.fireEvent("click", this, e);
26300     },
26301     
26302     onMouseOver : function(e)
26303     {
26304         if(this.submenu && this.pos == 'left'){
26305             this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
26306         }
26307         
26308         this.fireEvent("mouseover", this, e);
26309     },
26310     
26311     onMouseOut : function(e)
26312     {
26313         this.fireEvent("mouseout", this, e);
26314     }
26315 });
26316
26317  
26318
26319  /*
26320  * - LGPL
26321  *
26322  * menu separator
26323  * 
26324  */
26325 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
26326
26327 /**
26328  * @class Roo.bootstrap.menu.Separator
26329  * @extends Roo.bootstrap.Component
26330  * Bootstrap Separator class
26331  * 
26332  * @constructor
26333  * Create a new Separator
26334  * @param {Object} config The config object
26335  */
26336
26337
26338 Roo.bootstrap.menu.Separator = function(config){
26339     Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
26340 };
26341
26342 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component,  {
26343     
26344     getAutoCreate : function(){
26345         var cfg = {
26346             tag : 'li',
26347             cls: 'divider'
26348         };
26349         
26350         return cfg;
26351     }
26352    
26353 });
26354
26355  
26356
26357  /*
26358  * - LGPL
26359  *
26360  * Tooltip
26361  * 
26362  */
26363
26364 /**
26365  * @class Roo.bootstrap.Tooltip
26366  * Bootstrap Tooltip class
26367  * This is basic at present - all componets support it by default, however they should add tooltipEl() method
26368  * to determine which dom element triggers the tooltip.
26369  * 
26370  * It needs to add support for additional attributes like tooltip-position
26371  * 
26372  * @constructor
26373  * Create a new Toolti
26374  * @param {Object} config The config object
26375  */
26376
26377 Roo.bootstrap.Tooltip = function(config){
26378     Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
26379     
26380     this.alignment = Roo.bootstrap.Tooltip.alignment;
26381     
26382     if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
26383         this.alignment = config.alignment;
26384     }
26385     
26386 };
26387
26388 Roo.apply(Roo.bootstrap.Tooltip, {
26389     /**
26390      * @function init initialize tooltip monitoring.
26391      * @static
26392      */
26393     currentEl : false,
26394     currentTip : false,
26395     currentRegion : false,
26396     
26397     //  init : delay?
26398     
26399     init : function()
26400     {
26401         Roo.get(document).on('mouseover', this.enter ,this);
26402         Roo.get(document).on('mouseout', this.leave, this);
26403          
26404         
26405         this.currentTip = new Roo.bootstrap.Tooltip();
26406     },
26407     
26408     enter : function(ev)
26409     {
26410         var dom = ev.getTarget();
26411         
26412         //Roo.log(['enter',dom]);
26413         var el = Roo.fly(dom);
26414         if (this.currentEl) {
26415             //Roo.log(dom);
26416             //Roo.log(this.currentEl);
26417             //Roo.log(this.currentEl.contains(dom));
26418             if (this.currentEl == el) {
26419                 return;
26420             }
26421             if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
26422                 return;
26423             }
26424
26425         }
26426         
26427         if (this.currentTip.el) {
26428             this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
26429         }    
26430         //Roo.log(ev);
26431         
26432         if(!el || el.dom == document){
26433             return;
26434         }
26435         
26436         var bindEl = el;
26437         
26438         // you can not look for children, as if el is the body.. then everythign is the child..
26439         if (!el.attr('tooltip')) { //
26440             if (!el.select("[tooltip]").elements.length) {
26441                 return;
26442             }
26443             // is the mouse over this child...?
26444             bindEl = el.select("[tooltip]").first();
26445             var xy = ev.getXY();
26446             if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
26447                 //Roo.log("not in region.");
26448                 return;
26449             }
26450             //Roo.log("child element over..");
26451             
26452         }
26453         this.currentEl = bindEl;
26454         this.currentTip.bind(bindEl);
26455         this.currentRegion = Roo.lib.Region.getRegion(dom);
26456         this.currentTip.enter();
26457         
26458     },
26459     leave : function(ev)
26460     {
26461         var dom = ev.getTarget();
26462         //Roo.log(['leave',dom]);
26463         if (!this.currentEl) {
26464             return;
26465         }
26466         
26467         
26468         if (dom != this.currentEl.dom) {
26469             return;
26470         }
26471         var xy = ev.getXY();
26472         if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0]  ))) {
26473             return;
26474         }
26475         // only activate leave if mouse cursor is outside... bounding box..
26476         
26477         
26478         
26479         
26480         if (this.currentTip) {
26481             this.currentTip.leave();
26482         }
26483         //Roo.log('clear currentEl');
26484         this.currentEl = false;
26485         
26486         
26487     },
26488     alignment : {
26489         'left' : ['r-l', [-2,0], 'right'],
26490         'right' : ['l-r', [2,0], 'left'],
26491         'bottom' : ['t-b', [0,2], 'top'],
26492         'top' : [ 'b-t', [0,-2], 'bottom']
26493     }
26494     
26495 });
26496
26497
26498 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component,  {
26499     
26500     
26501     bindEl : false,
26502     
26503     delay : null, // can be { show : 300 , hide: 500}
26504     
26505     timeout : null,
26506     
26507     hoverState : null, //???
26508     
26509     placement : 'bottom', 
26510     
26511     alignment : false,
26512     
26513     getAutoCreate : function(){
26514     
26515         var cfg = {
26516            cls : 'tooltip',
26517            role : 'tooltip',
26518            cn : [
26519                 {
26520                     cls : 'tooltip-arrow'
26521                 },
26522                 {
26523                     cls : 'tooltip-inner'
26524                 }
26525            ]
26526         };
26527         
26528         return cfg;
26529     },
26530     bind : function(el)
26531     {
26532         this.bindEl = el;
26533     },
26534       
26535     
26536     enter : function () {
26537        
26538         if (this.timeout != null) {
26539             clearTimeout(this.timeout);
26540         }
26541         
26542         this.hoverState = 'in';
26543          //Roo.log("enter - show");
26544         if (!this.delay || !this.delay.show) {
26545             this.show();
26546             return;
26547         }
26548         var _t = this;
26549         this.timeout = setTimeout(function () {
26550             if (_t.hoverState == 'in') {
26551                 _t.show();
26552             }
26553         }, this.delay.show);
26554     },
26555     leave : function()
26556     {
26557         clearTimeout(this.timeout);
26558     
26559         this.hoverState = 'out';
26560          if (!this.delay || !this.delay.hide) {
26561             this.hide();
26562             return;
26563         }
26564        
26565         var _t = this;
26566         this.timeout = setTimeout(function () {
26567             //Roo.log("leave - timeout");
26568             
26569             if (_t.hoverState == 'out') {
26570                 _t.hide();
26571                 Roo.bootstrap.Tooltip.currentEl = false;
26572             }
26573         }, delay);
26574     },
26575     
26576     show : function (msg)
26577     {
26578         if (!this.el) {
26579             this.render(document.body);
26580         }
26581         // set content.
26582         //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
26583         
26584         var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
26585         
26586         this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
26587         
26588         this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
26589         
26590         var placement = typeof this.placement == 'function' ?
26591             this.placement.call(this, this.el, on_el) :
26592             this.placement;
26593             
26594         var autoToken = /\s?auto?\s?/i;
26595         var autoPlace = autoToken.test(placement);
26596         if (autoPlace) {
26597             placement = placement.replace(autoToken, '') || 'top';
26598         }
26599         
26600         //this.el.detach()
26601         //this.el.setXY([0,0]);
26602         this.el.show();
26603         //this.el.dom.style.display='block';
26604         
26605         //this.el.appendTo(on_el);
26606         
26607         var p = this.getPosition();
26608         var box = this.el.getBox();
26609         
26610         if (autoPlace) {
26611             // fixme..
26612         }
26613         
26614         var align = this.alignment[placement];
26615         
26616         var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
26617         
26618         if(placement == 'top' || placement == 'bottom'){
26619             if(xy[0] < 0){
26620                 placement = 'right';
26621             }
26622             
26623             if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
26624                 placement = 'left';
26625             }
26626             
26627             var scroll = Roo.select('body', true).first().getScroll();
26628             
26629             if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
26630                 placement = 'top';
26631             }
26632             
26633             align = this.alignment[placement];
26634         }
26635         
26636         this.el.alignTo(this.bindEl, align[0],align[1]);
26637         //var arrow = this.el.select('.arrow',true).first();
26638         //arrow.set(align[2], 
26639         
26640         this.el.addClass(placement);
26641         
26642         this.el.addClass('in fade');
26643         
26644         this.hoverState = null;
26645         
26646         if (this.el.hasClass('fade')) {
26647             // fade it?
26648         }
26649         
26650     },
26651     hide : function()
26652     {
26653          
26654         if (!this.el) {
26655             return;
26656         }
26657         //this.el.setXY([0,0]);
26658         this.el.removeClass('in');
26659         //this.el.hide();
26660         
26661     }
26662     
26663 });
26664  
26665
26666  /*
26667  * - LGPL
26668  *
26669  * Location Picker
26670  * 
26671  */
26672
26673 /**
26674  * @class Roo.bootstrap.LocationPicker
26675  * @extends Roo.bootstrap.Component
26676  * Bootstrap LocationPicker class
26677  * @cfg {Number} latitude Position when init default 0
26678  * @cfg {Number} longitude Position when init default 0
26679  * @cfg {Number} zoom default 15
26680  * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
26681  * @cfg {Boolean} mapTypeControl default false
26682  * @cfg {Boolean} disableDoubleClickZoom default false
26683  * @cfg {Boolean} scrollwheel default true
26684  * @cfg {Boolean} streetViewControl default false
26685  * @cfg {Number} radius default 0
26686  * @cfg {String} locationName
26687  * @cfg {Boolean} draggable default true
26688  * @cfg {Boolean} enableAutocomplete default false
26689  * @cfg {Boolean} enableReverseGeocode default true
26690  * @cfg {String} markerTitle
26691  * 
26692  * @constructor
26693  * Create a new LocationPicker
26694  * @param {Object} config The config object
26695  */
26696
26697
26698 Roo.bootstrap.LocationPicker = function(config){
26699     
26700     Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26701     
26702     this.addEvents({
26703         /**
26704          * @event initial
26705          * Fires when the picker initialized.
26706          * @param {Roo.bootstrap.LocationPicker} this
26707          * @param {Google Location} location
26708          */
26709         initial : true,
26710         /**
26711          * @event positionchanged
26712          * Fires when the picker position changed.
26713          * @param {Roo.bootstrap.LocationPicker} this
26714          * @param {Google Location} location
26715          */
26716         positionchanged : true,
26717         /**
26718          * @event resize
26719          * Fires when the map resize.
26720          * @param {Roo.bootstrap.LocationPicker} this
26721          */
26722         resize : true,
26723         /**
26724          * @event show
26725          * Fires when the map show.
26726          * @param {Roo.bootstrap.LocationPicker} this
26727          */
26728         show : true,
26729         /**
26730          * @event hide
26731          * Fires when the map hide.
26732          * @param {Roo.bootstrap.LocationPicker} this
26733          */
26734         hide : true,
26735         /**
26736          * @event mapClick
26737          * Fires when click the map.
26738          * @param {Roo.bootstrap.LocationPicker} this
26739          * @param {Map event} e
26740          */
26741         mapClick : true,
26742         /**
26743          * @event mapRightClick
26744          * Fires when right click the map.
26745          * @param {Roo.bootstrap.LocationPicker} this
26746          * @param {Map event} e
26747          */
26748         mapRightClick : true,
26749         /**
26750          * @event markerClick
26751          * Fires when click the marker.
26752          * @param {Roo.bootstrap.LocationPicker} this
26753          * @param {Map event} e
26754          */
26755         markerClick : true,
26756         /**
26757          * @event markerRightClick
26758          * Fires when right click the marker.
26759          * @param {Roo.bootstrap.LocationPicker} this
26760          * @param {Map event} e
26761          */
26762         markerRightClick : true,
26763         /**
26764          * @event OverlayViewDraw
26765          * Fires when OverlayView Draw
26766          * @param {Roo.bootstrap.LocationPicker} this
26767          */
26768         OverlayViewDraw : true,
26769         /**
26770          * @event OverlayViewOnAdd
26771          * Fires when OverlayView Draw
26772          * @param {Roo.bootstrap.LocationPicker} this
26773          */
26774         OverlayViewOnAdd : true,
26775         /**
26776          * @event OverlayViewOnRemove
26777          * Fires when OverlayView Draw
26778          * @param {Roo.bootstrap.LocationPicker} this
26779          */
26780         OverlayViewOnRemove : true,
26781         /**
26782          * @event OverlayViewShow
26783          * Fires when OverlayView Draw
26784          * @param {Roo.bootstrap.LocationPicker} this
26785          * @param {Pixel} cpx
26786          */
26787         OverlayViewShow : true,
26788         /**
26789          * @event OverlayViewHide
26790          * Fires when OverlayView Draw
26791          * @param {Roo.bootstrap.LocationPicker} this
26792          */
26793         OverlayViewHide : true,
26794         /**
26795          * @event loadexception
26796          * Fires when load google lib failed.
26797          * @param {Roo.bootstrap.LocationPicker} this
26798          */
26799         loadexception : true
26800     });
26801         
26802 };
26803
26804 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component,  {
26805     
26806     gMapContext: false,
26807     
26808     latitude: 0,
26809     longitude: 0,
26810     zoom: 15,
26811     mapTypeId: false,
26812     mapTypeControl: false,
26813     disableDoubleClickZoom: false,
26814     scrollwheel: true,
26815     streetViewControl: false,
26816     radius: 0,
26817     locationName: '',
26818     draggable: true,
26819     enableAutocomplete: false,
26820     enableReverseGeocode: true,
26821     markerTitle: '',
26822     
26823     getAutoCreate: function()
26824     {
26825
26826         var cfg = {
26827             tag: 'div',
26828             cls: 'roo-location-picker'
26829         };
26830         
26831         return cfg
26832     },
26833     
26834     initEvents: function(ct, position)
26835     {       
26836         if(!this.el.getWidth() || this.isApplied()){
26837             return;
26838         }
26839         
26840         this.el.setVisibilityMode(Roo.Element.DISPLAY);
26841         
26842         this.initial();
26843     },
26844     
26845     initial: function()
26846     {
26847         if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26848             this.fireEvent('loadexception', this);
26849             return;
26850         }
26851         
26852         if(!this.mapTypeId){
26853             this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26854         }
26855         
26856         this.gMapContext = this.GMapContext();
26857         
26858         this.initOverlayView();
26859         
26860         this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26861         
26862         var _this = this;
26863                 
26864         google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26865             _this.setPosition(_this.gMapContext.marker.position);
26866         });
26867         
26868         google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26869             _this.fireEvent('mapClick', this, event);
26870             
26871         });
26872
26873         google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26874             _this.fireEvent('mapRightClick', this, event);
26875             
26876         });
26877         
26878         google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26879             _this.fireEvent('markerClick', this, event);
26880             
26881         });
26882
26883         google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26884             _this.fireEvent('markerRightClick', this, event);
26885             
26886         });
26887         
26888         this.setPosition(this.gMapContext.location);
26889         
26890         this.fireEvent('initial', this, this.gMapContext.location);
26891     },
26892     
26893     initOverlayView: function()
26894     {
26895         var _this = this;
26896         
26897         Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26898             
26899             draw: function()
26900             {
26901                 _this.fireEvent('OverlayViewDraw', _this);
26902             },
26903             
26904             onAdd: function()
26905             {
26906                 _this.fireEvent('OverlayViewOnAdd', _this);
26907             },
26908             
26909             onRemove: function()
26910             {
26911                 _this.fireEvent('OverlayViewOnRemove', _this);
26912             },
26913             
26914             show: function(cpx)
26915             {
26916                 _this.fireEvent('OverlayViewShow', _this, cpx);
26917             },
26918             
26919             hide: function()
26920             {
26921                 _this.fireEvent('OverlayViewHide', _this);
26922             }
26923             
26924         });
26925     },
26926     
26927     fromLatLngToContainerPixel: function(event)
26928     {
26929         return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26930     },
26931     
26932     isApplied: function() 
26933     {
26934         return this.getGmapContext() == false ? false : true;
26935     },
26936     
26937     getGmapContext: function() 
26938     {
26939         return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26940     },
26941     
26942     GMapContext: function() 
26943     {
26944         var position = new google.maps.LatLng(this.latitude, this.longitude);
26945         
26946         var _map = new google.maps.Map(this.el.dom, {
26947             center: position,
26948             zoom: this.zoom,
26949             mapTypeId: this.mapTypeId,
26950             mapTypeControl: this.mapTypeControl,
26951             disableDoubleClickZoom: this.disableDoubleClickZoom,
26952             scrollwheel: this.scrollwheel,
26953             streetViewControl: this.streetViewControl,
26954             locationName: this.locationName,
26955             draggable: this.draggable,
26956             enableAutocomplete: this.enableAutocomplete,
26957             enableReverseGeocode: this.enableReverseGeocode
26958         });
26959         
26960         var _marker = new google.maps.Marker({
26961             position: position,
26962             map: _map,
26963             title: this.markerTitle,
26964             draggable: this.draggable
26965         });
26966         
26967         return {
26968             map: _map,
26969             marker: _marker,
26970             circle: null,
26971             location: position,
26972             radius: this.radius,
26973             locationName: this.locationName,
26974             addressComponents: {
26975                 formatted_address: null,
26976                 addressLine1: null,
26977                 addressLine2: null,
26978                 streetName: null,
26979                 streetNumber: null,
26980                 city: null,
26981                 district: null,
26982                 state: null,
26983                 stateOrProvince: null
26984             },
26985             settings: this,
26986             domContainer: this.el.dom,
26987             geodecoder: new google.maps.Geocoder()
26988         };
26989     },
26990     
26991     drawCircle: function(center, radius, options) 
26992     {
26993         if (this.gMapContext.circle != null) {
26994             this.gMapContext.circle.setMap(null);
26995         }
26996         if (radius > 0) {
26997             radius *= 1;
26998             options = Roo.apply({}, options, {
26999                 strokeColor: "#0000FF",
27000                 strokeOpacity: .35,
27001                 strokeWeight: 2,
27002                 fillColor: "#0000FF",
27003                 fillOpacity: .2
27004             });
27005             
27006             options.map = this.gMapContext.map;
27007             options.radius = radius;
27008             options.center = center;
27009             this.gMapContext.circle = new google.maps.Circle(options);
27010             return this.gMapContext.circle;
27011         }
27012         
27013         return null;
27014     },
27015     
27016     setPosition: function(location) 
27017     {
27018         this.gMapContext.location = location;
27019         this.gMapContext.marker.setPosition(location);
27020         this.gMapContext.map.panTo(location);
27021         this.drawCircle(location, this.gMapContext.radius, {});
27022         
27023         var _this = this;
27024         
27025         if (this.gMapContext.settings.enableReverseGeocode) {
27026             this.gMapContext.geodecoder.geocode({
27027                 latLng: this.gMapContext.location
27028             }, function(results, status) {
27029                 
27030                 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
27031                     _this.gMapContext.locationName = results[0].formatted_address;
27032                     _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
27033                     
27034                     _this.fireEvent('positionchanged', this, location);
27035                 }
27036             });
27037             
27038             return;
27039         }
27040         
27041         this.fireEvent('positionchanged', this, location);
27042     },
27043     
27044     resize: function()
27045     {
27046         google.maps.event.trigger(this.gMapContext.map, "resize");
27047         
27048         this.gMapContext.map.setCenter(this.gMapContext.marker.position);
27049         
27050         this.fireEvent('resize', this);
27051     },
27052     
27053     setPositionByLatLng: function(latitude, longitude)
27054     {
27055         this.setPosition(new google.maps.LatLng(latitude, longitude));
27056     },
27057     
27058     getCurrentPosition: function() 
27059     {
27060         return {
27061             latitude: this.gMapContext.location.lat(),
27062             longitude: this.gMapContext.location.lng()
27063         };
27064     },
27065     
27066     getAddressName: function() 
27067     {
27068         return this.gMapContext.locationName;
27069     },
27070     
27071     getAddressComponents: function() 
27072     {
27073         return this.gMapContext.addressComponents;
27074     },
27075     
27076     address_component_from_google_geocode: function(address_components) 
27077     {
27078         var result = {};
27079         
27080         for (var i = 0; i < address_components.length; i++) {
27081             var component = address_components[i];
27082             if (component.types.indexOf("postal_code") >= 0) {
27083                 result.postalCode = component.short_name;
27084             } else if (component.types.indexOf("street_number") >= 0) {
27085                 result.streetNumber = component.short_name;
27086             } else if (component.types.indexOf("route") >= 0) {
27087                 result.streetName = component.short_name;
27088             } else if (component.types.indexOf("neighborhood") >= 0) {
27089                 result.city = component.short_name;
27090             } else if (component.types.indexOf("locality") >= 0) {
27091                 result.city = component.short_name;
27092             } else if (component.types.indexOf("sublocality") >= 0) {
27093                 result.district = component.short_name;
27094             } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
27095                 result.stateOrProvince = component.short_name;
27096             } else if (component.types.indexOf("country") >= 0) {
27097                 result.country = component.short_name;
27098             }
27099         }
27100         
27101         result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
27102         result.addressLine2 = "";
27103         return result;
27104     },
27105     
27106     setZoomLevel: function(zoom)
27107     {
27108         this.gMapContext.map.setZoom(zoom);
27109     },
27110     
27111     show: function()
27112     {
27113         if(!this.el){
27114             return;
27115         }
27116         
27117         this.el.show();
27118         
27119         this.resize();
27120         
27121         this.fireEvent('show', this);
27122     },
27123     
27124     hide: function()
27125     {
27126         if(!this.el){
27127             return;
27128         }
27129         
27130         this.el.hide();
27131         
27132         this.fireEvent('hide', this);
27133     }
27134     
27135 });
27136
27137 Roo.apply(Roo.bootstrap.LocationPicker, {
27138     
27139     OverlayView : function(map, options)
27140     {
27141         options = options || {};
27142         
27143         this.setMap(map);
27144     }
27145     
27146     
27147 });/*
27148  * - LGPL
27149  *
27150  * Alert
27151  * 
27152  */
27153
27154 /**
27155  * @class Roo.bootstrap.Alert
27156  * @extends Roo.bootstrap.Component
27157  * Bootstrap Alert class
27158  * @cfg {String} title The title of alert
27159  * @cfg {String} html The content of alert
27160  * @cfg {String} weight (  success | info | warning | danger )
27161  * @cfg {String} faicon font-awesomeicon
27162  * 
27163  * @constructor
27164  * Create a new alert
27165  * @param {Object} config The config object
27166  */
27167
27168
27169 Roo.bootstrap.Alert = function(config){
27170     Roo.bootstrap.Alert.superclass.constructor.call(this, config);
27171     
27172 };
27173
27174 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component,  {
27175     
27176     title: '',
27177     html: '',
27178     weight: false,
27179     faicon: false,
27180     
27181     getAutoCreate : function()
27182     {
27183         
27184         var cfg = {
27185             tag : 'div',
27186             cls : 'alert',
27187             cn : [
27188                 {
27189                     tag : 'i',
27190                     cls : 'roo-alert-icon'
27191                     
27192                 },
27193                 {
27194                     tag : 'b',
27195                     cls : 'roo-alert-title',
27196                     html : this.title
27197                 },
27198                 {
27199                     tag : 'span',
27200                     cls : 'roo-alert-text',
27201                     html : this.html
27202                 }
27203             ]
27204         };
27205         
27206         if(this.faicon){
27207             cfg.cn[0].cls += ' fa ' + this.faicon;
27208         }
27209         
27210         if(this.weight){
27211             cfg.cls += ' alert-' + this.weight;
27212         }
27213         
27214         return cfg;
27215     },
27216     
27217     initEvents: function() 
27218     {
27219         this.el.setVisibilityMode(Roo.Element.DISPLAY);
27220     },
27221     
27222     setTitle : function(str)
27223     {
27224         this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
27225     },
27226     
27227     setText : function(str)
27228     {
27229         this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
27230     },
27231     
27232     setWeight : function(weight)
27233     {
27234         if(this.weight){
27235             this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
27236         }
27237         
27238         this.weight = weight;
27239         
27240         this.el.select('.alert',true).first().addClass('alert-' + this.weight);
27241     },
27242     
27243     setIcon : function(icon)
27244     {
27245         if(this.faicon){
27246             this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
27247         }
27248         
27249         this.faicon = icon;
27250         
27251         this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
27252     },
27253     
27254     hide: function() 
27255     {
27256         this.el.hide();   
27257     },
27258     
27259     show: function() 
27260     {  
27261         this.el.show();   
27262     }
27263     
27264 });
27265
27266  
27267 /*
27268 * Licence: LGPL
27269 */
27270
27271 /**
27272  * @class Roo.bootstrap.UploadCropbox
27273  * @extends Roo.bootstrap.Component
27274  * Bootstrap UploadCropbox class
27275  * @cfg {String} emptyText show when image has been loaded
27276  * @cfg {String} rotateNotify show when image too small to rotate
27277  * @cfg {Number} errorTimeout default 3000
27278  * @cfg {Number} minWidth default 300
27279  * @cfg {Number} minHeight default 300
27280  * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
27281  * @cfg {Boolean} isDocument (true|false) default false
27282  * @cfg {String} url action url
27283  * @cfg {String} paramName default 'imageUpload'
27284  * @cfg {String} method default POST
27285  * @cfg {Boolean} loadMask (true|false) default true
27286  * @cfg {Boolean} loadingText default 'Loading...'
27287  * 
27288  * @constructor
27289  * Create a new UploadCropbox
27290  * @param {Object} config The config object
27291  */
27292
27293 Roo.bootstrap.UploadCropbox = function(config){
27294     Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
27295     
27296     this.addEvents({
27297         /**
27298          * @event beforeselectfile
27299          * Fire before select file
27300          * @param {Roo.bootstrap.UploadCropbox} this
27301          */
27302         "beforeselectfile" : true,
27303         /**
27304          * @event initial
27305          * Fire after initEvent
27306          * @param {Roo.bootstrap.UploadCropbox} this
27307          */
27308         "initial" : true,
27309         /**
27310          * @event crop
27311          * Fire after initEvent
27312          * @param {Roo.bootstrap.UploadCropbox} this
27313          * @param {String} data
27314          */
27315         "crop" : true,
27316         /**
27317          * @event prepare
27318          * Fire when preparing the file data
27319          * @param {Roo.bootstrap.UploadCropbox} this
27320          * @param {Object} file
27321          */
27322         "prepare" : true,
27323         /**
27324          * @event exception
27325          * Fire when get exception
27326          * @param {Roo.bootstrap.UploadCropbox} this
27327          * @param {XMLHttpRequest} xhr
27328          */
27329         "exception" : true,
27330         /**
27331          * @event beforeloadcanvas
27332          * Fire before load the canvas
27333          * @param {Roo.bootstrap.UploadCropbox} this
27334          * @param {String} src
27335          */
27336         "beforeloadcanvas" : true,
27337         /**
27338          * @event trash
27339          * Fire when trash image
27340          * @param {Roo.bootstrap.UploadCropbox} this
27341          */
27342         "trash" : true,
27343         /**
27344          * @event download
27345          * Fire when download the image
27346          * @param {Roo.bootstrap.UploadCropbox} this
27347          */
27348         "download" : true,
27349         /**
27350          * @event footerbuttonclick
27351          * Fire when footerbuttonclick
27352          * @param {Roo.bootstrap.UploadCropbox} this
27353          * @param {String} type
27354          */
27355         "footerbuttonclick" : true,
27356         /**
27357          * @event resize
27358          * Fire when resize
27359          * @param {Roo.bootstrap.UploadCropbox} this
27360          */
27361         "resize" : true,
27362         /**
27363          * @event rotate
27364          * Fire when rotate the image
27365          * @param {Roo.bootstrap.UploadCropbox} this
27366          * @param {String} pos
27367          */
27368         "rotate" : true,
27369         /**
27370          * @event inspect
27371          * Fire when inspect the file
27372          * @param {Roo.bootstrap.UploadCropbox} this
27373          * @param {Object} file
27374          */
27375         "inspect" : true,
27376         /**
27377          * @event upload
27378          * Fire when xhr upload the file
27379          * @param {Roo.bootstrap.UploadCropbox} this
27380          * @param {Object} data
27381          */
27382         "upload" : true,
27383         /**
27384          * @event arrange
27385          * Fire when arrange the file data
27386          * @param {Roo.bootstrap.UploadCropbox} this
27387          * @param {Object} formData
27388          */
27389         "arrange" : true
27390     });
27391     
27392     this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
27393 };
27394
27395 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component,  {
27396     
27397     emptyText : 'Click to upload image',
27398     rotateNotify : 'Image is too small to rotate',
27399     errorTimeout : 3000,
27400     scale : 0,
27401     baseScale : 1,
27402     rotate : 0,
27403     dragable : false,
27404     pinching : false,
27405     mouseX : 0,
27406     mouseY : 0,
27407     cropData : false,
27408     minWidth : 300,
27409     minHeight : 300,
27410     file : false,
27411     exif : {},
27412     baseRotate : 1,
27413     cropType : 'image/jpeg',
27414     buttons : false,
27415     canvasLoaded : false,
27416     isDocument : false,
27417     method : 'POST',
27418     paramName : 'imageUpload',
27419     loadMask : true,
27420     loadingText : 'Loading...',
27421     maskEl : false,
27422     
27423     getAutoCreate : function()
27424     {
27425         var cfg = {
27426             tag : 'div',
27427             cls : 'roo-upload-cropbox',
27428             cn : [
27429                 {
27430                     tag : 'input',
27431                     cls : 'roo-upload-cropbox-selector',
27432                     type : 'file'
27433                 },
27434                 {
27435                     tag : 'div',
27436                     cls : 'roo-upload-cropbox-body',
27437                     style : 'cursor:pointer',
27438                     cn : [
27439                         {
27440                             tag : 'div',
27441                             cls : 'roo-upload-cropbox-preview'
27442                         },
27443                         {
27444                             tag : 'div',
27445                             cls : 'roo-upload-cropbox-thumb'
27446                         },
27447                         {
27448                             tag : 'div',
27449                             cls : 'roo-upload-cropbox-empty-notify',
27450                             html : this.emptyText
27451                         },
27452                         {
27453                             tag : 'div',
27454                             cls : 'roo-upload-cropbox-error-notify alert alert-danger',
27455                             html : this.rotateNotify
27456                         }
27457                     ]
27458                 },
27459                 {
27460                     tag : 'div',
27461                     cls : 'roo-upload-cropbox-footer',
27462                     cn : {
27463                         tag : 'div',
27464                         cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
27465                         cn : []
27466                     }
27467                 }
27468             ]
27469         };
27470         
27471         return cfg;
27472     },
27473     
27474     onRender : function(ct, position)
27475     {
27476         Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
27477         
27478         if (this.buttons.length) {
27479             
27480             Roo.each(this.buttons, function(bb) {
27481                 
27482                 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
27483                 
27484                 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
27485                 
27486             }, this);
27487         }
27488         
27489         if(this.loadMask){
27490             this.maskEl = this.el;
27491         }
27492     },
27493     
27494     initEvents : function()
27495     {
27496         this.urlAPI = (window.createObjectURL && window) || 
27497                                 (window.URL && URL.revokeObjectURL && URL) || 
27498                                 (window.webkitURL && webkitURL);
27499                         
27500         this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
27501         this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27502         
27503         this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
27504         this.selectorEl.hide();
27505         
27506         this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
27507         this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27508         
27509         this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
27510         this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27511         this.thumbEl.hide();
27512         
27513         this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
27514         this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27515         
27516         this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
27517         this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27518         this.errorEl.hide();
27519         
27520         this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
27521         this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27522         this.footerEl.hide();
27523         
27524         this.setThumbBoxSize();
27525         
27526         this.bind();
27527         
27528         this.resize();
27529         
27530         this.fireEvent('initial', this);
27531     },
27532
27533     bind : function()
27534     {
27535         var _this = this;
27536         
27537         window.addEventListener("resize", function() { _this.resize(); } );
27538         
27539         this.bodyEl.on('click', this.beforeSelectFile, this);
27540         
27541         if(Roo.isTouch){
27542             this.bodyEl.on('touchstart', this.onTouchStart, this);
27543             this.bodyEl.on('touchmove', this.onTouchMove, this);
27544             this.bodyEl.on('touchend', this.onTouchEnd, this);
27545         }
27546         
27547         if(!Roo.isTouch){
27548             this.bodyEl.on('mousedown', this.onMouseDown, this);
27549             this.bodyEl.on('mousemove', this.onMouseMove, this);
27550             var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
27551             this.bodyEl.on(mousewheel, this.onMouseWheel, this);
27552             Roo.get(document).on('mouseup', this.onMouseUp, this);
27553         }
27554         
27555         this.selectorEl.on('change', this.onFileSelected, this);
27556     },
27557     
27558     reset : function()
27559     {    
27560         this.scale = 0;
27561         this.baseScale = 1;
27562         this.rotate = 0;
27563         this.baseRotate = 1;
27564         this.dragable = false;
27565         this.pinching = false;
27566         this.mouseX = 0;
27567         this.mouseY = 0;
27568         this.cropData = false;
27569         this.notifyEl.dom.innerHTML = this.emptyText;
27570         
27571         this.selectorEl.dom.value = '';
27572         
27573     },
27574     
27575     resize : function()
27576     {
27577         if(this.fireEvent('resize', this) != false){
27578             this.setThumbBoxPosition();
27579             this.setCanvasPosition();
27580         }
27581     },
27582     
27583     onFooterButtonClick : function(e, el, o, type)
27584     {
27585         switch (type) {
27586             case 'rotate-left' :
27587                 this.onRotateLeft(e);
27588                 break;
27589             case 'rotate-right' :
27590                 this.onRotateRight(e);
27591                 break;
27592             case 'picture' :
27593                 this.beforeSelectFile(e);
27594                 break;
27595             case 'trash' :
27596                 this.trash(e);
27597                 break;
27598             case 'crop' :
27599                 this.crop(e);
27600                 break;
27601             case 'download' :
27602                 this.download(e);
27603                 break;
27604             default :
27605                 break;
27606         }
27607         
27608         this.fireEvent('footerbuttonclick', this, type);
27609     },
27610     
27611     beforeSelectFile : function(e)
27612     {
27613         e.preventDefault();
27614         
27615         if(this.fireEvent('beforeselectfile', this) != false){
27616             this.selectorEl.dom.click();
27617         }
27618     },
27619     
27620     onFileSelected : function(e)
27621     {
27622         e.preventDefault();
27623         
27624         if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27625             return;
27626         }
27627         
27628         var file = this.selectorEl.dom.files[0];
27629         
27630         if(this.fireEvent('inspect', this, file) != false){
27631             this.prepare(file);
27632         }
27633         
27634     },
27635     
27636     trash : function(e)
27637     {
27638         this.fireEvent('trash', this);
27639     },
27640     
27641     download : function(e)
27642     {
27643         this.fireEvent('download', this);
27644     },
27645     
27646     loadCanvas : function(src)
27647     {   
27648         if(this.fireEvent('beforeloadcanvas', this, src) != false){
27649             
27650             this.reset();
27651             
27652             this.imageEl = document.createElement('img');
27653             
27654             var _this = this;
27655             
27656             this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
27657             
27658             this.imageEl.src = src;
27659         }
27660     },
27661     
27662     onLoadCanvas : function()
27663     {   
27664         this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
27665         this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
27666         
27667         this.bodyEl.un('click', this.beforeSelectFile, this);
27668         
27669         this.notifyEl.hide();
27670         this.thumbEl.show();
27671         this.footerEl.show();
27672         
27673         this.baseRotateLevel();
27674         
27675         if(this.isDocument){
27676             this.setThumbBoxSize();
27677         }
27678         
27679         this.setThumbBoxPosition();
27680         
27681         this.baseScaleLevel();
27682         
27683         this.draw();
27684         
27685         this.resize();
27686         
27687         this.canvasLoaded = true;
27688         
27689         if(this.loadMask){
27690             this.maskEl.unmask();
27691         }
27692         
27693     },
27694     
27695     setCanvasPosition : function()
27696     {   
27697         if(!this.canvasEl){
27698             return;
27699         }
27700         
27701         var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27702         var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27703         
27704         this.previewEl.setLeft(pw);
27705         this.previewEl.setTop(ph);
27706         
27707     },
27708     
27709     onMouseDown : function(e)
27710     {   
27711         e.stopEvent();
27712         
27713         this.dragable = true;
27714         this.pinching = false;
27715         
27716         if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27717             this.dragable = false;
27718             return;
27719         }
27720         
27721         this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27722         this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27723         
27724     },
27725     
27726     onMouseMove : function(e)
27727     {   
27728         e.stopEvent();
27729         
27730         if(!this.canvasLoaded){
27731             return;
27732         }
27733         
27734         if (!this.dragable){
27735             return;
27736         }
27737         
27738         var minX = Math.ceil(this.thumbEl.getLeft(true));
27739         var minY = Math.ceil(this.thumbEl.getTop(true));
27740         
27741         var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27742         var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27743         
27744         var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27745         var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27746         
27747         x = x - this.mouseX;
27748         y = y - this.mouseY;
27749         
27750         var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27751         var bgY = Math.ceil(y + this.previewEl.getTop(true));
27752         
27753         bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27754         bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27755         
27756         this.previewEl.setLeft(bgX);
27757         this.previewEl.setTop(bgY);
27758         
27759         this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27760         this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27761     },
27762     
27763     onMouseUp : function(e)
27764     {   
27765         e.stopEvent();
27766         
27767         this.dragable = false;
27768     },
27769     
27770     onMouseWheel : function(e)
27771     {   
27772         e.stopEvent();
27773         
27774         this.startScale = this.scale;
27775         
27776         this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27777         
27778         if(!this.zoomable()){
27779             this.scale = this.startScale;
27780             return;
27781         }
27782         
27783         this.draw();
27784         
27785         return;
27786     },
27787     
27788     zoomable : function()
27789     {
27790         var minScale = this.thumbEl.getWidth() / this.minWidth;
27791         
27792         if(this.minWidth < this.minHeight){
27793             minScale = this.thumbEl.getHeight() / this.minHeight;
27794         }
27795         
27796         var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27797         var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27798         
27799         if(
27800                 this.isDocument &&
27801                 (this.rotate == 0 || this.rotate == 180) && 
27802                 (
27803                     width > this.imageEl.OriginWidth || 
27804                     height > this.imageEl.OriginHeight ||
27805                     (width < this.minWidth && height < this.minHeight)
27806                 )
27807         ){
27808             return false;
27809         }
27810         
27811         if(
27812                 this.isDocument &&
27813                 (this.rotate == 90 || this.rotate == 270) && 
27814                 (
27815                     width > this.imageEl.OriginWidth || 
27816                     height > this.imageEl.OriginHeight ||
27817                     (width < this.minHeight && height < this.minWidth)
27818                 )
27819         ){
27820             return false;
27821         }
27822         
27823         if(
27824                 !this.isDocument &&
27825                 (this.rotate == 0 || this.rotate == 180) && 
27826                 (
27827                     width < this.minWidth || 
27828                     width > this.imageEl.OriginWidth || 
27829                     height < this.minHeight || 
27830                     height > this.imageEl.OriginHeight
27831                 )
27832         ){
27833             return false;
27834         }
27835         
27836         if(
27837                 !this.isDocument &&
27838                 (this.rotate == 90 || this.rotate == 270) && 
27839                 (
27840                     width < this.minHeight || 
27841                     width > this.imageEl.OriginWidth || 
27842                     height < this.minWidth || 
27843                     height > this.imageEl.OriginHeight
27844                 )
27845         ){
27846             return false;
27847         }
27848         
27849         return true;
27850         
27851     },
27852     
27853     onRotateLeft : function(e)
27854     {   
27855         if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27856             
27857             var minScale = this.thumbEl.getWidth() / this.minWidth;
27858             
27859             var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27860             var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27861             
27862             this.startScale = this.scale;
27863             
27864             while (this.getScaleLevel() < minScale){
27865             
27866                 this.scale = this.scale + 1;
27867                 
27868                 if(!this.zoomable()){
27869                     break;
27870                 }
27871                 
27872                 if(
27873                         Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27874                         Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27875                 ){
27876                     continue;
27877                 }
27878                 
27879                 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27880
27881                 this.draw();
27882                 
27883                 return;
27884             }
27885             
27886             this.scale = this.startScale;
27887             
27888             this.onRotateFail();
27889             
27890             return false;
27891         }
27892         
27893         this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27894
27895         if(this.isDocument){
27896             this.setThumbBoxSize();
27897             this.setThumbBoxPosition();
27898             this.setCanvasPosition();
27899         }
27900         
27901         this.draw();
27902         
27903         this.fireEvent('rotate', this, 'left');
27904         
27905     },
27906     
27907     onRotateRight : function(e)
27908     {
27909         if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27910             
27911             var minScale = this.thumbEl.getWidth() / this.minWidth;
27912         
27913             var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27914             var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27915             
27916             this.startScale = this.scale;
27917             
27918             while (this.getScaleLevel() < minScale){
27919             
27920                 this.scale = this.scale + 1;
27921                 
27922                 if(!this.zoomable()){
27923                     break;
27924                 }
27925                 
27926                 if(
27927                         Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27928                         Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27929                 ){
27930                     continue;
27931                 }
27932                 
27933                 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27934
27935                 this.draw();
27936                 
27937                 return;
27938             }
27939             
27940             this.scale = this.startScale;
27941             
27942             this.onRotateFail();
27943             
27944             return false;
27945         }
27946         
27947         this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27948
27949         if(this.isDocument){
27950             this.setThumbBoxSize();
27951             this.setThumbBoxPosition();
27952             this.setCanvasPosition();
27953         }
27954         
27955         this.draw();
27956         
27957         this.fireEvent('rotate', this, 'right');
27958     },
27959     
27960     onRotateFail : function()
27961     {
27962         this.errorEl.show(true);
27963         
27964         var _this = this;
27965         
27966         (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27967     },
27968     
27969     draw : function()
27970     {
27971         this.previewEl.dom.innerHTML = '';
27972         
27973         var canvasEl = document.createElement("canvas");
27974         
27975         var contextEl = canvasEl.getContext("2d");
27976         
27977         canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27978         canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27979         var center = this.imageEl.OriginWidth / 2;
27980         
27981         if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27982             canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27983             canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27984             center = this.imageEl.OriginHeight / 2;
27985         }
27986         
27987         contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27988         
27989         contextEl.translate(center, center);
27990         contextEl.rotate(this.rotate * Math.PI / 180);
27991
27992         contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27993         
27994         this.canvasEl = document.createElement("canvas");
27995         
27996         this.contextEl = this.canvasEl.getContext("2d");
27997         
27998         switch (this.rotate) {
27999             case 0 :
28000                 
28001                 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
28002                 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
28003                 
28004                 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
28005                 
28006                 break;
28007             case 90 : 
28008                 
28009                 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
28010                 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
28011                 
28012                 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28013                     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);
28014                     break;
28015                 }
28016                 
28017                 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
28018                 
28019                 break;
28020             case 180 :
28021                 
28022                 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
28023                 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
28024                 
28025                 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28026                     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);
28027                     break;
28028                 }
28029                 
28030                 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);
28031                 
28032                 break;
28033             case 270 :
28034                 
28035                 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
28036                 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
28037         
28038                 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28039                     this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
28040                     break;
28041                 }
28042                 
28043                 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);
28044                 
28045                 break;
28046             default : 
28047                 break;
28048         }
28049         
28050         this.previewEl.appendChild(this.canvasEl);
28051         
28052         this.setCanvasPosition();
28053     },
28054     
28055     crop : function()
28056     {
28057         if(!this.canvasLoaded){
28058             return;
28059         }
28060         
28061         var imageCanvas = document.createElement("canvas");
28062         
28063         var imageContext = imageCanvas.getContext("2d");
28064         
28065         imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
28066         imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
28067         
28068         var center = imageCanvas.width / 2;
28069         
28070         imageContext.translate(center, center);
28071         
28072         imageContext.rotate(this.rotate * Math.PI / 180);
28073         
28074         imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
28075         
28076         var canvas = document.createElement("canvas");
28077         
28078         var context = canvas.getContext("2d");
28079                 
28080         canvas.width = this.minWidth;
28081         canvas.height = this.minHeight;
28082
28083         switch (this.rotate) {
28084             case 0 :
28085                 
28086                 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
28087                 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
28088                 
28089                 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
28090                 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
28091                 
28092                 var targetWidth = this.minWidth - 2 * x;
28093                 var targetHeight = this.minHeight - 2 * y;
28094                 
28095                 var scale = 1;
28096                 
28097                 if((x == 0 && y == 0) || (x == 0 && y > 0)){
28098                     scale = targetWidth / width;
28099                 }
28100                 
28101                 if(x > 0 && y == 0){
28102                     scale = targetHeight / height;
28103                 }
28104                 
28105                 if(x > 0 && y > 0){
28106                     scale = targetWidth / width;
28107                     
28108                     if(width < height){
28109                         scale = targetHeight / height;
28110                     }
28111                 }
28112                 
28113                 context.scale(scale, scale);
28114                 
28115                 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
28116                 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
28117
28118                 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
28119                 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
28120
28121                 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
28122                 
28123                 break;
28124             case 90 : 
28125                 
28126                 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
28127                 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
28128                 
28129                 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
28130                 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
28131                 
28132                 var targetWidth = this.minWidth - 2 * x;
28133                 var targetHeight = this.minHeight - 2 * y;
28134                 
28135                 var scale = 1;
28136                 
28137                 if((x == 0 && y == 0) || (x == 0 && y > 0)){
28138                     scale = targetWidth / width;
28139                 }
28140                 
28141                 if(x > 0 && y == 0){
28142                     scale = targetHeight / height;
28143                 }
28144                 
28145                 if(x > 0 && y > 0){
28146                     scale = targetWidth / width;
28147                     
28148                     if(width < height){
28149                         scale = targetHeight / height;
28150                     }
28151                 }
28152                 
28153                 context.scale(scale, scale);
28154                 
28155                 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
28156                 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
28157
28158                 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
28159                 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
28160                 
28161                 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
28162                 
28163                 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
28164                 
28165                 break;
28166             case 180 :
28167                 
28168                 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
28169                 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
28170                 
28171                 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
28172                 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
28173                 
28174                 var targetWidth = this.minWidth - 2 * x;
28175                 var targetHeight = this.minHeight - 2 * y;
28176                 
28177                 var scale = 1;
28178                 
28179                 if((x == 0 && y == 0) || (x == 0 && y > 0)){
28180                     scale = targetWidth / width;
28181                 }
28182                 
28183                 if(x > 0 && y == 0){
28184                     scale = targetHeight / height;
28185                 }
28186                 
28187                 if(x > 0 && y > 0){
28188                     scale = targetWidth / width;
28189                     
28190                     if(width < height){
28191                         scale = targetHeight / height;
28192                     }
28193                 }
28194                 
28195                 context.scale(scale, scale);
28196                 
28197                 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
28198                 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
28199
28200                 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
28201                 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
28202
28203                 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
28204                 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
28205                 
28206                 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
28207                 
28208                 break;
28209             case 270 :
28210                 
28211                 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
28212                 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
28213                 
28214                 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
28215                 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
28216                 
28217                 var targetWidth = this.minWidth - 2 * x;
28218                 var targetHeight = this.minHeight - 2 * y;
28219                 
28220                 var scale = 1;
28221                 
28222                 if((x == 0 && y == 0) || (x == 0 && y > 0)){
28223                     scale = targetWidth / width;
28224                 }
28225                 
28226                 if(x > 0 && y == 0){
28227                     scale = targetHeight / height;
28228                 }
28229                 
28230                 if(x > 0 && y > 0){
28231                     scale = targetWidth / width;
28232                     
28233                     if(width < height){
28234                         scale = targetHeight / height;
28235                     }
28236                 }
28237                 
28238                 context.scale(scale, scale);
28239                 
28240                 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
28241                 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
28242
28243                 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
28244                 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
28245                 
28246                 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
28247                 
28248                 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
28249                 
28250                 break;
28251             default : 
28252                 break;
28253         }
28254         
28255         this.cropData = canvas.toDataURL(this.cropType);
28256         
28257         if(this.fireEvent('crop', this, this.cropData) !== false){
28258             this.process(this.file, this.cropData);
28259         }
28260         
28261         return;
28262         
28263     },
28264     
28265     setThumbBoxSize : function()
28266     {
28267         var width, height;
28268         
28269         if(this.isDocument && typeof(this.imageEl) != 'undefined'){
28270             width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
28271             height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
28272             
28273             this.minWidth = width;
28274             this.minHeight = height;
28275             
28276             if(this.rotate == 90 || this.rotate == 270){
28277                 this.minWidth = height;
28278                 this.minHeight = width;
28279             }
28280         }
28281         
28282         height = 300;
28283         width = Math.ceil(this.minWidth * height / this.minHeight);
28284         
28285         if(this.minWidth > this.minHeight){
28286             width = 300;
28287             height = Math.ceil(this.minHeight * width / this.minWidth);
28288         }
28289         
28290         this.thumbEl.setStyle({
28291             width : width + 'px',
28292             height : height + 'px'
28293         });
28294
28295         return;
28296             
28297     },
28298     
28299     setThumbBoxPosition : function()
28300     {
28301         var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
28302         var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
28303         
28304         this.thumbEl.setLeft(x);
28305         this.thumbEl.setTop(y);
28306         
28307     },
28308     
28309     baseRotateLevel : function()
28310     {
28311         this.baseRotate = 1;
28312         
28313         if(
28314                 typeof(this.exif) != 'undefined' &&
28315                 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
28316                 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
28317         ){
28318             this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
28319         }
28320         
28321         this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
28322         
28323     },
28324     
28325     baseScaleLevel : function()
28326     {
28327         var width, height;
28328         
28329         if(this.isDocument){
28330             
28331             if(this.baseRotate == 6 || this.baseRotate == 8){
28332             
28333                 height = this.thumbEl.getHeight();
28334                 this.baseScale = height / this.imageEl.OriginWidth;
28335
28336                 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
28337                     width = this.thumbEl.getWidth();
28338                     this.baseScale = width / this.imageEl.OriginHeight;
28339                 }
28340
28341                 return;
28342             }
28343
28344             height = this.thumbEl.getHeight();
28345             this.baseScale = height / this.imageEl.OriginHeight;
28346
28347             if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
28348                 width = this.thumbEl.getWidth();
28349                 this.baseScale = width / this.imageEl.OriginWidth;
28350             }
28351
28352             return;
28353         }
28354         
28355         if(this.baseRotate == 6 || this.baseRotate == 8){
28356             
28357             width = this.thumbEl.getHeight();
28358             this.baseScale = width / this.imageEl.OriginHeight;
28359             
28360             if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
28361                 height = this.thumbEl.getWidth();
28362                 this.baseScale = height / this.imageEl.OriginHeight;
28363             }
28364             
28365             if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28366                 height = this.thumbEl.getWidth();
28367                 this.baseScale = height / this.imageEl.OriginHeight;
28368                 
28369                 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
28370                     width = this.thumbEl.getHeight();
28371                     this.baseScale = width / this.imageEl.OriginWidth;
28372                 }
28373             }
28374             
28375             return;
28376         }
28377         
28378         width = this.thumbEl.getWidth();
28379         this.baseScale = width / this.imageEl.OriginWidth;
28380         
28381         if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
28382             height = this.thumbEl.getHeight();
28383             this.baseScale = height / this.imageEl.OriginHeight;
28384         }
28385         
28386         if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28387             
28388             height = this.thumbEl.getHeight();
28389             this.baseScale = height / this.imageEl.OriginHeight;
28390             
28391             if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
28392                 width = this.thumbEl.getWidth();
28393                 this.baseScale = width / this.imageEl.OriginWidth;
28394             }
28395             
28396         }
28397         
28398         return;
28399     },
28400     
28401     getScaleLevel : function()
28402     {
28403         return this.baseScale * Math.pow(1.1, this.scale);
28404     },
28405     
28406     onTouchStart : function(e)
28407     {
28408         if(!this.canvasLoaded){
28409             this.beforeSelectFile(e);
28410             return;
28411         }
28412         
28413         var touches = e.browserEvent.touches;
28414         
28415         if(!touches){
28416             return;
28417         }
28418         
28419         if(touches.length == 1){
28420             this.onMouseDown(e);
28421             return;
28422         }
28423         
28424         if(touches.length != 2){
28425             return;
28426         }
28427         
28428         var coords = [];
28429         
28430         for(var i = 0, finger; finger = touches[i]; i++){
28431             coords.push(finger.pageX, finger.pageY);
28432         }
28433         
28434         var x = Math.pow(coords[0] - coords[2], 2);
28435         var y = Math.pow(coords[1] - coords[3], 2);
28436         
28437         this.startDistance = Math.sqrt(x + y);
28438         
28439         this.startScale = this.scale;
28440         
28441         this.pinching = true;
28442         this.dragable = false;
28443         
28444     },
28445     
28446     onTouchMove : function(e)
28447     {
28448         if(!this.pinching && !this.dragable){
28449             return;
28450         }
28451         
28452         var touches = e.browserEvent.touches;
28453         
28454         if(!touches){
28455             return;
28456         }
28457         
28458         if(this.dragable){
28459             this.onMouseMove(e);
28460             return;
28461         }
28462         
28463         var coords = [];
28464         
28465         for(var i = 0, finger; finger = touches[i]; i++){
28466             coords.push(finger.pageX, finger.pageY);
28467         }
28468         
28469         var x = Math.pow(coords[0] - coords[2], 2);
28470         var y = Math.pow(coords[1] - coords[3], 2);
28471         
28472         this.endDistance = Math.sqrt(x + y);
28473         
28474         this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
28475         
28476         if(!this.zoomable()){
28477             this.scale = this.startScale;
28478             return;
28479         }
28480         
28481         this.draw();
28482         
28483     },
28484     
28485     onTouchEnd : function(e)
28486     {
28487         this.pinching = false;
28488         this.dragable = false;
28489         
28490     },
28491     
28492     process : function(file, crop)
28493     {
28494         if(this.loadMask){
28495             this.maskEl.mask(this.loadingText);
28496         }
28497         
28498         this.xhr = new XMLHttpRequest();
28499         
28500         file.xhr = this.xhr;
28501
28502         this.xhr.open(this.method, this.url, true);
28503         
28504         var headers = {
28505             "Accept": "application/json",
28506             "Cache-Control": "no-cache",
28507             "X-Requested-With": "XMLHttpRequest"
28508         };
28509         
28510         for (var headerName in headers) {
28511             var headerValue = headers[headerName];
28512             if (headerValue) {
28513                 this.xhr.setRequestHeader(headerName, headerValue);
28514             }
28515         }
28516         
28517         var _this = this;
28518         
28519         this.xhr.onload = function()
28520         {
28521             _this.xhrOnLoad(_this.xhr);
28522         }
28523         
28524         this.xhr.onerror = function()
28525         {
28526             _this.xhrOnError(_this.xhr);
28527         }
28528         
28529         var formData = new FormData();
28530
28531         formData.append('returnHTML', 'NO');
28532         
28533         if(crop){
28534             formData.append('crop', crop);
28535         }
28536         
28537         if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
28538             formData.append(this.paramName, file, file.name);
28539         }
28540         
28541         if(typeof(file.filename) != 'undefined'){
28542             formData.append('filename', file.filename);
28543         }
28544         
28545         if(typeof(file.mimetype) != 'undefined'){
28546             formData.append('mimetype', file.mimetype);
28547         }
28548         
28549         if(this.fireEvent('arrange', this, formData) != false){
28550             this.xhr.send(formData);
28551         };
28552     },
28553     
28554     xhrOnLoad : function(xhr)
28555     {
28556         if(this.loadMask){
28557             this.maskEl.unmask();
28558         }
28559         
28560         if (xhr.readyState !== 4) {
28561             this.fireEvent('exception', this, xhr);
28562             return;
28563         }
28564
28565         var response = Roo.decode(xhr.responseText);
28566         
28567         if(!response.success){
28568             this.fireEvent('exception', this, xhr);
28569             return;
28570         }
28571         
28572         var response = Roo.decode(xhr.responseText);
28573         
28574         this.fireEvent('upload', this, response);
28575         
28576     },
28577     
28578     xhrOnError : function()
28579     {
28580         if(this.loadMask){
28581             this.maskEl.unmask();
28582         }
28583         
28584         Roo.log('xhr on error');
28585         
28586         var response = Roo.decode(xhr.responseText);
28587           
28588         Roo.log(response);
28589         
28590     },
28591     
28592     prepare : function(file)
28593     {   
28594         if(this.loadMask){
28595             this.maskEl.mask(this.loadingText);
28596         }
28597         
28598         this.file = false;
28599         this.exif = {};
28600         
28601         if(typeof(file) === 'string'){
28602             this.loadCanvas(file);
28603             return;
28604         }
28605         
28606         if(!file || !this.urlAPI){
28607             return;
28608         }
28609         
28610         this.file = file;
28611         this.cropType = file.type;
28612         
28613         var _this = this;
28614         
28615         if(this.fireEvent('prepare', this, this.file) != false){
28616             
28617             var reader = new FileReader();
28618             
28619             reader.onload = function (e) {
28620                 if (e.target.error) {
28621                     Roo.log(e.target.error);
28622                     return;
28623                 }
28624                 
28625                 var buffer = e.target.result,
28626                     dataView = new DataView(buffer),
28627                     offset = 2,
28628                     maxOffset = dataView.byteLength - 4,
28629                     markerBytes,
28630                     markerLength;
28631                 
28632                 if (dataView.getUint16(0) === 0xffd8) {
28633                     while (offset < maxOffset) {
28634                         markerBytes = dataView.getUint16(offset);
28635                         
28636                         if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
28637                             markerLength = dataView.getUint16(offset + 2) + 2;
28638                             if (offset + markerLength > dataView.byteLength) {
28639                                 Roo.log('Invalid meta data: Invalid segment size.');
28640                                 break;
28641                             }
28642                             
28643                             if(markerBytes == 0xffe1){
28644                                 _this.parseExifData(
28645                                     dataView,
28646                                     offset,
28647                                     markerLength
28648                                 );
28649                             }
28650                             
28651                             offset += markerLength;
28652                             
28653                             continue;
28654                         }
28655                         
28656                         break;
28657                     }
28658                     
28659                 }
28660                 
28661                 var url = _this.urlAPI.createObjectURL(_this.file);
28662                 
28663                 _this.loadCanvas(url);
28664                 
28665                 return;
28666             }
28667             
28668             reader.readAsArrayBuffer(this.file);
28669             
28670         }
28671         
28672     },
28673     
28674     parseExifData : function(dataView, offset, length)
28675     {
28676         var tiffOffset = offset + 10,
28677             littleEndian,
28678             dirOffset;
28679     
28680         if (dataView.getUint32(offset + 4) !== 0x45786966) {
28681             // No Exif data, might be XMP data instead
28682             return;
28683         }
28684         
28685         // Check for the ASCII code for "Exif" (0x45786966):
28686         if (dataView.getUint32(offset + 4) !== 0x45786966) {
28687             // No Exif data, might be XMP data instead
28688             return;
28689         }
28690         if (tiffOffset + 8 > dataView.byteLength) {
28691             Roo.log('Invalid Exif data: Invalid segment size.');
28692             return;
28693         }
28694         // Check for the two null bytes:
28695         if (dataView.getUint16(offset + 8) !== 0x0000) {
28696             Roo.log('Invalid Exif data: Missing byte alignment offset.');
28697             return;
28698         }
28699         // Check the byte alignment:
28700         switch (dataView.getUint16(tiffOffset)) {
28701         case 0x4949:
28702             littleEndian = true;
28703             break;
28704         case 0x4D4D:
28705             littleEndian = false;
28706             break;
28707         default:
28708             Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28709             return;
28710         }
28711         // Check for the TIFF tag marker (0x002A):
28712         if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28713             Roo.log('Invalid Exif data: Missing TIFF marker.');
28714             return;
28715         }
28716         // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28717         dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28718         
28719         this.parseExifTags(
28720             dataView,
28721             tiffOffset,
28722             tiffOffset + dirOffset,
28723             littleEndian
28724         );
28725     },
28726     
28727     parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28728     {
28729         var tagsNumber,
28730             dirEndOffset,
28731             i;
28732         if (dirOffset + 6 > dataView.byteLength) {
28733             Roo.log('Invalid Exif data: Invalid directory offset.');
28734             return;
28735         }
28736         tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28737         dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28738         if (dirEndOffset + 4 > dataView.byteLength) {
28739             Roo.log('Invalid Exif data: Invalid directory size.');
28740             return;
28741         }
28742         for (i = 0; i < tagsNumber; i += 1) {
28743             this.parseExifTag(
28744                 dataView,
28745                 tiffOffset,
28746                 dirOffset + 2 + 12 * i, // tag offset
28747                 littleEndian
28748             );
28749         }
28750         // Return the offset to the next directory:
28751         return dataView.getUint32(dirEndOffset, littleEndian);
28752     },
28753     
28754     parseExifTag : function (dataView, tiffOffset, offset, littleEndian) 
28755     {
28756         var tag = dataView.getUint16(offset, littleEndian);
28757         
28758         this.exif[tag] = this.getExifValue(
28759             dataView,
28760             tiffOffset,
28761             offset,
28762             dataView.getUint16(offset + 2, littleEndian), // tag type
28763             dataView.getUint32(offset + 4, littleEndian), // tag length
28764             littleEndian
28765         );
28766     },
28767     
28768     getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28769     {
28770         var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28771             tagSize,
28772             dataOffset,
28773             values,
28774             i,
28775             str,
28776             c;
28777     
28778         if (!tagType) {
28779             Roo.log('Invalid Exif data: Invalid tag type.');
28780             return;
28781         }
28782         
28783         tagSize = tagType.size * length;
28784         // Determine if the value is contained in the dataOffset bytes,
28785         // or if the value at the dataOffset is a pointer to the actual data:
28786         dataOffset = tagSize > 4 ?
28787                 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28788         if (dataOffset + tagSize > dataView.byteLength) {
28789             Roo.log('Invalid Exif data: Invalid data offset.');
28790             return;
28791         }
28792         if (length === 1) {
28793             return tagType.getValue(dataView, dataOffset, littleEndian);
28794         }
28795         values = [];
28796         for (i = 0; i < length; i += 1) {
28797             values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28798         }
28799         
28800         if (tagType.ascii) {
28801             str = '';
28802             // Concatenate the chars:
28803             for (i = 0; i < values.length; i += 1) {
28804                 c = values[i];
28805                 // Ignore the terminating NULL byte(s):
28806                 if (c === '\u0000') {
28807                     break;
28808                 }
28809                 str += c;
28810             }
28811             return str;
28812         }
28813         return values;
28814     }
28815     
28816 });
28817
28818 Roo.apply(Roo.bootstrap.UploadCropbox, {
28819     tags : {
28820         'Orientation': 0x0112
28821     },
28822     
28823     Orientation: {
28824             1: 0, //'top-left',
28825 //            2: 'top-right',
28826             3: 180, //'bottom-right',
28827 //            4: 'bottom-left',
28828 //            5: 'left-top',
28829             6: 90, //'right-top',
28830 //            7: 'right-bottom',
28831             8: 270 //'left-bottom'
28832     },
28833     
28834     exifTagTypes : {
28835         // byte, 8-bit unsigned int:
28836         1: {
28837             getValue: function (dataView, dataOffset) {
28838                 return dataView.getUint8(dataOffset);
28839             },
28840             size: 1
28841         },
28842         // ascii, 8-bit byte:
28843         2: {
28844             getValue: function (dataView, dataOffset) {
28845                 return String.fromCharCode(dataView.getUint8(dataOffset));
28846             },
28847             size: 1,
28848             ascii: true
28849         },
28850         // short, 16 bit int:
28851         3: {
28852             getValue: function (dataView, dataOffset, littleEndian) {
28853                 return dataView.getUint16(dataOffset, littleEndian);
28854             },
28855             size: 2
28856         },
28857         // long, 32 bit int:
28858         4: {
28859             getValue: function (dataView, dataOffset, littleEndian) {
28860                 return dataView.getUint32(dataOffset, littleEndian);
28861             },
28862             size: 4
28863         },
28864         // rational = two long values, first is numerator, second is denominator:
28865         5: {
28866             getValue: function (dataView, dataOffset, littleEndian) {
28867                 return dataView.getUint32(dataOffset, littleEndian) /
28868                     dataView.getUint32(dataOffset + 4, littleEndian);
28869             },
28870             size: 8
28871         },
28872         // slong, 32 bit signed int:
28873         9: {
28874             getValue: function (dataView, dataOffset, littleEndian) {
28875                 return dataView.getInt32(dataOffset, littleEndian);
28876             },
28877             size: 4
28878         },
28879         // srational, two slongs, first is numerator, second is denominator:
28880         10: {
28881             getValue: function (dataView, dataOffset, littleEndian) {
28882                 return dataView.getInt32(dataOffset, littleEndian) /
28883                     dataView.getInt32(dataOffset + 4, littleEndian);
28884             },
28885             size: 8
28886         }
28887     },
28888     
28889     footer : {
28890         STANDARD : [
28891             {
28892                 tag : 'div',
28893                 cls : 'btn-group roo-upload-cropbox-rotate-left',
28894                 action : 'rotate-left',
28895                 cn : [
28896                     {
28897                         tag : 'button',
28898                         cls : 'btn btn-default',
28899                         html : '<i class="fa fa-undo"></i>'
28900                     }
28901                 ]
28902             },
28903             {
28904                 tag : 'div',
28905                 cls : 'btn-group roo-upload-cropbox-picture',
28906                 action : 'picture',
28907                 cn : [
28908                     {
28909                         tag : 'button',
28910                         cls : 'btn btn-default',
28911                         html : '<i class="fa fa-picture-o"></i>'
28912                     }
28913                 ]
28914             },
28915             {
28916                 tag : 'div',
28917                 cls : 'btn-group roo-upload-cropbox-rotate-right',
28918                 action : 'rotate-right',
28919                 cn : [
28920                     {
28921                         tag : 'button',
28922                         cls : 'btn btn-default',
28923                         html : '<i class="fa fa-repeat"></i>'
28924                     }
28925                 ]
28926             }
28927         ],
28928         DOCUMENT : [
28929             {
28930                 tag : 'div',
28931                 cls : 'btn-group roo-upload-cropbox-rotate-left',
28932                 action : 'rotate-left',
28933                 cn : [
28934                     {
28935                         tag : 'button',
28936                         cls : 'btn btn-default',
28937                         html : '<i class="fa fa-undo"></i>'
28938                     }
28939                 ]
28940             },
28941             {
28942                 tag : 'div',
28943                 cls : 'btn-group roo-upload-cropbox-download',
28944                 action : 'download',
28945                 cn : [
28946                     {
28947                         tag : 'button',
28948                         cls : 'btn btn-default',
28949                         html : '<i class="fa fa-download"></i>'
28950                     }
28951                 ]
28952             },
28953             {
28954                 tag : 'div',
28955                 cls : 'btn-group roo-upload-cropbox-crop',
28956                 action : 'crop',
28957                 cn : [
28958                     {
28959                         tag : 'button',
28960                         cls : 'btn btn-default',
28961                         html : '<i class="fa fa-crop"></i>'
28962                     }
28963                 ]
28964             },
28965             {
28966                 tag : 'div',
28967                 cls : 'btn-group roo-upload-cropbox-trash',
28968                 action : 'trash',
28969                 cn : [
28970                     {
28971                         tag : 'button',
28972                         cls : 'btn btn-default',
28973                         html : '<i class="fa fa-trash"></i>'
28974                     }
28975                 ]
28976             },
28977             {
28978                 tag : 'div',
28979                 cls : 'btn-group roo-upload-cropbox-rotate-right',
28980                 action : 'rotate-right',
28981                 cn : [
28982                     {
28983                         tag : 'button',
28984                         cls : 'btn btn-default',
28985                         html : '<i class="fa fa-repeat"></i>'
28986                     }
28987                 ]
28988             }
28989         ],
28990         ROTATOR : [
28991             {
28992                 tag : 'div',
28993                 cls : 'btn-group roo-upload-cropbox-rotate-left',
28994                 action : 'rotate-left',
28995                 cn : [
28996                     {
28997                         tag : 'button',
28998                         cls : 'btn btn-default',
28999                         html : '<i class="fa fa-undo"></i>'
29000                     }
29001                 ]
29002             },
29003             {
29004                 tag : 'div',
29005                 cls : 'btn-group roo-upload-cropbox-rotate-right',
29006                 action : 'rotate-right',
29007                 cn : [
29008                     {
29009                         tag : 'button',
29010                         cls : 'btn btn-default',
29011                         html : '<i class="fa fa-repeat"></i>'
29012                     }
29013                 ]
29014             }
29015         ]
29016     }
29017 });
29018
29019 /*
29020 * Licence: LGPL
29021 */
29022
29023 /**
29024  * @class Roo.bootstrap.DocumentManager
29025  * @extends Roo.bootstrap.Component
29026  * Bootstrap DocumentManager class
29027  * @cfg {String} paramName default 'imageUpload'
29028  * @cfg {String} toolTipName default 'filename'
29029  * @cfg {String} method default POST
29030  * @cfg {String} url action url
29031  * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
29032  * @cfg {Boolean} multiple multiple upload default true
29033  * @cfg {Number} thumbSize default 300
29034  * @cfg {String} fieldLabel
29035  * @cfg {Number} labelWidth default 4
29036  * @cfg {String} labelAlign (left|top) default left
29037  * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
29038 * @cfg {Number} labellg set the width of label (1-12)
29039  * @cfg {Number} labelmd set the width of label (1-12)
29040  * @cfg {Number} labelsm set the width of label (1-12)
29041  * @cfg {Number} labelxs set the width of label (1-12)
29042  * 
29043  * @constructor
29044  * Create a new DocumentManager
29045  * @param {Object} config The config object
29046  */
29047
29048 Roo.bootstrap.DocumentManager = function(config){
29049     Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
29050     
29051     this.files = [];
29052     this.delegates = [];
29053     
29054     this.addEvents({
29055         /**
29056          * @event initial
29057          * Fire when initial the DocumentManager
29058          * @param {Roo.bootstrap.DocumentManager} this
29059          */
29060         "initial" : true,
29061         /**
29062          * @event inspect
29063          * inspect selected file
29064          * @param {Roo.bootstrap.DocumentManager} this
29065          * @param {File} file
29066          */
29067         "inspect" : true,
29068         /**
29069          * @event exception
29070          * Fire when xhr load exception
29071          * @param {Roo.bootstrap.DocumentManager} this
29072          * @param {XMLHttpRequest} xhr
29073          */
29074         "exception" : true,
29075         /**
29076          * @event afterupload
29077          * Fire when xhr load exception
29078          * @param {Roo.bootstrap.DocumentManager} this
29079          * @param {XMLHttpRequest} xhr
29080          */
29081         "afterupload" : true,
29082         /**
29083          * @event prepare
29084          * prepare the form data
29085          * @param {Roo.bootstrap.DocumentManager} this
29086          * @param {Object} formData
29087          */
29088         "prepare" : true,
29089         /**
29090          * @event remove
29091          * Fire when remove the file
29092          * @param {Roo.bootstrap.DocumentManager} this
29093          * @param {Object} file
29094          */
29095         "remove" : true,
29096         /**
29097          * @event refresh
29098          * Fire after refresh the file
29099          * @param {Roo.bootstrap.DocumentManager} this
29100          */
29101         "refresh" : true,
29102         /**
29103          * @event click
29104          * Fire after click the image
29105          * @param {Roo.bootstrap.DocumentManager} this
29106          * @param {Object} file
29107          */
29108         "click" : true,
29109         /**
29110          * @event edit
29111          * Fire when upload a image and editable set to true
29112          * @param {Roo.bootstrap.DocumentManager} this
29113          * @param {Object} file
29114          */
29115         "edit" : true,
29116         /**
29117          * @event beforeselectfile
29118          * Fire before select file
29119          * @param {Roo.bootstrap.DocumentManager} this
29120          */
29121         "beforeselectfile" : true,
29122         /**
29123          * @event process
29124          * Fire before process file
29125          * @param {Roo.bootstrap.DocumentManager} this
29126          * @param {Object} file
29127          */
29128         "process" : true,
29129         /**
29130          * @event previewrendered
29131          * Fire when preview rendered
29132          * @param {Roo.bootstrap.DocumentManager} this
29133          * @param {Object} file
29134          */
29135         "previewrendered" : true,
29136         /**
29137          */
29138         "previewResize" : true
29139         
29140     });
29141 };
29142
29143 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component,  {
29144     
29145     boxes : 0,
29146     inputName : '',
29147     thumbSize : 300,
29148     multiple : true,
29149     files : false,
29150     method : 'POST',
29151     url : '',
29152     paramName : 'imageUpload',
29153     toolTipName : 'filename',
29154     fieldLabel : '',
29155     labelWidth : 4,
29156     labelAlign : 'left',
29157     editable : true,
29158     delegates : false,
29159     xhr : false, 
29160     
29161     labellg : 0,
29162     labelmd : 0,
29163     labelsm : 0,
29164     labelxs : 0,
29165     
29166     getAutoCreate : function()
29167     {   
29168         var managerWidget = {
29169             tag : 'div',
29170             cls : 'roo-document-manager',
29171             cn : [
29172                 {
29173                     tag : 'input',
29174                     cls : 'roo-document-manager-selector',
29175                     type : 'file'
29176                 },
29177                 {
29178                     tag : 'div',
29179                     cls : 'roo-document-manager-uploader',
29180                     cn : [
29181                         {
29182                             tag : 'div',
29183                             cls : 'roo-document-manager-upload-btn',
29184                             html : '<i class="fa fa-plus"></i>'
29185                         }
29186                     ]
29187                     
29188                 }
29189             ]
29190         };
29191         
29192         var content = [
29193             {
29194                 tag : 'div',
29195                 cls : 'column col-md-12',
29196                 cn : managerWidget
29197             }
29198         ];
29199         
29200         if(this.fieldLabel.length){
29201             
29202             content = [
29203                 {
29204                     tag : 'div',
29205                     cls : 'column col-md-12',
29206                     html : this.fieldLabel
29207                 },
29208                 {
29209                     tag : 'div',
29210                     cls : 'column col-md-12',
29211                     cn : managerWidget
29212                 }
29213             ];
29214
29215             if(this.labelAlign == 'left'){
29216                 content = [
29217                     {
29218                         tag : 'div',
29219                         cls : 'column',
29220                         html : this.fieldLabel
29221                     },
29222                     {
29223                         tag : 'div',
29224                         cls : 'column',
29225                         cn : managerWidget
29226                     }
29227                 ];
29228                 
29229                 if(this.labelWidth > 12){
29230                     content[0].style = "width: " + this.labelWidth + 'px';
29231                 }
29232
29233                 if(this.labelWidth < 13 && this.labelmd == 0){
29234                     this.labelmd = this.labelWidth;
29235                 }
29236
29237                 if(this.labellg > 0){
29238                     content[0].cls += ' col-lg-' + this.labellg;
29239                     content[1].cls += ' col-lg-' + (12 - this.labellg);
29240                 }
29241
29242                 if(this.labelmd > 0){
29243                     content[0].cls += ' col-md-' + this.labelmd;
29244                     content[1].cls += ' col-md-' + (12 - this.labelmd);
29245                 }
29246
29247                 if(this.labelsm > 0){
29248                     content[0].cls += ' col-sm-' + this.labelsm;
29249                     content[1].cls += ' col-sm-' + (12 - this.labelsm);
29250                 }
29251
29252                 if(this.labelxs > 0){
29253                     content[0].cls += ' col-xs-' + this.labelxs;
29254                     content[1].cls += ' col-xs-' + (12 - this.labelxs);
29255                 }
29256                 
29257             }
29258         }
29259         
29260         var cfg = {
29261             tag : 'div',
29262             cls : 'row clearfix',
29263             cn : content
29264         };
29265         
29266         return cfg;
29267         
29268     },
29269     
29270     initEvents : function()
29271     {
29272         this.managerEl = this.el.select('.roo-document-manager', true).first();
29273         this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29274         
29275         this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
29276         this.selectorEl.hide();
29277         
29278         if(this.multiple){
29279             this.selectorEl.attr('multiple', 'multiple');
29280         }
29281         
29282         this.selectorEl.on('change', this.onFileSelected, this);
29283         
29284         this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
29285         this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29286         
29287         this.uploader.on('click', this.onUploaderClick, this);
29288         
29289         this.renderProgressDialog();
29290         
29291         var _this = this;
29292         
29293         window.addEventListener("resize", function() { _this.refresh(); } );
29294         
29295         this.fireEvent('initial', this);
29296     },
29297     
29298     renderProgressDialog : function()
29299     {
29300         var _this = this;
29301         
29302         this.progressDialog = new Roo.bootstrap.Modal({
29303             cls : 'roo-document-manager-progress-dialog',
29304             allow_close : false,
29305             animate : false,
29306             title : '',
29307             buttons : [
29308                 {
29309                     name  :'cancel',
29310                     weight : 'danger',
29311                     html : 'Cancel'
29312                 }
29313             ], 
29314             listeners : { 
29315                 btnclick : function() {
29316                     _this.uploadCancel();
29317                     this.hide();
29318                 }
29319             }
29320         });
29321          
29322         this.progressDialog.render(Roo.get(document.body));
29323          
29324         this.progress = new Roo.bootstrap.Progress({
29325             cls : 'roo-document-manager-progress',
29326             active : true,
29327             striped : true
29328         });
29329         
29330         this.progress.render(this.progressDialog.getChildContainer());
29331         
29332         this.progressBar = new Roo.bootstrap.ProgressBar({
29333             cls : 'roo-document-manager-progress-bar',
29334             aria_valuenow : 0,
29335             aria_valuemin : 0,
29336             aria_valuemax : 12,
29337             panel : 'success'
29338         });
29339         
29340         this.progressBar.render(this.progress.getChildContainer());
29341     },
29342     
29343     onUploaderClick : function(e)
29344     {
29345         e.preventDefault();
29346      
29347         if(this.fireEvent('beforeselectfile', this) != false){
29348             this.selectorEl.dom.click();
29349         }
29350         
29351     },
29352     
29353     onFileSelected : function(e)
29354     {
29355         e.preventDefault();
29356         
29357         if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
29358             return;
29359         }
29360         
29361         Roo.each(this.selectorEl.dom.files, function(file){
29362             if(this.fireEvent('inspect', this, file) != false){
29363                 this.files.push(file);
29364             }
29365         }, this);
29366         
29367         this.queue();
29368         
29369     },
29370     
29371     queue : function()
29372     {
29373         this.selectorEl.dom.value = '';
29374         
29375         if(!this.files || !this.files.length){
29376             return;
29377         }
29378         
29379         if(this.boxes > 0 && this.files.length > this.boxes){
29380             this.files = this.files.slice(0, this.boxes);
29381         }
29382         
29383         this.uploader.show();
29384         
29385         if(this.boxes > 0 && this.files.length > this.boxes - 1){
29386             this.uploader.hide();
29387         }
29388         
29389         var _this = this;
29390         
29391         var files = [];
29392         
29393         var docs = [];
29394         
29395         Roo.each(this.files, function(file){
29396             
29397             if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29398                 var f = this.renderPreview(file);
29399                 files.push(f);
29400                 return;
29401             }
29402             
29403             if(file.type.indexOf('image') != -1){
29404                 this.delegates.push(
29405                     (function(){
29406                         _this.process(file);
29407                     }).createDelegate(this)
29408                 );
29409         
29410                 return;
29411             }
29412             
29413             docs.push(
29414                 (function(){
29415                     _this.process(file);
29416                 }).createDelegate(this)
29417             );
29418             
29419         }, this);
29420         
29421         this.files = files;
29422         
29423         this.delegates = this.delegates.concat(docs);
29424         
29425         if(!this.delegates.length){
29426             this.refresh();
29427             return;
29428         }
29429         
29430         this.progressBar.aria_valuemax = this.delegates.length;
29431         
29432         this.arrange();
29433         
29434         return;
29435     },
29436     
29437     arrange : function()
29438     {
29439         if(!this.delegates.length){
29440             this.progressDialog.hide();
29441             this.refresh();
29442             return;
29443         }
29444         
29445         var delegate = this.delegates.shift();
29446         
29447         this.progressDialog.show();
29448         
29449         this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
29450         
29451         this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
29452         
29453         delegate();
29454     },
29455     
29456     refresh : function()
29457     {
29458         this.uploader.show();
29459         
29460         if(this.boxes > 0 && this.files.length > this.boxes - 1){
29461             this.uploader.hide();
29462         }
29463         
29464         Roo.isTouch ? this.closable(false) : this.closable(true);
29465         
29466         this.fireEvent('refresh', this);
29467     },
29468     
29469     onRemove : function(e, el, o)
29470     {
29471         e.preventDefault();
29472         
29473         this.fireEvent('remove', this, o);
29474         
29475     },
29476     
29477     remove : function(o)
29478     {
29479         var files = [];
29480         
29481         Roo.each(this.files, function(file){
29482             if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
29483                 files.push(file);
29484                 return;
29485             }
29486
29487             o.target.remove();
29488
29489         }, this);
29490         
29491         this.files = files;
29492         
29493         this.refresh();
29494     },
29495     
29496     clear : function()
29497     {
29498         Roo.each(this.files, function(file){
29499             if(!file.target){
29500                 return;
29501             }
29502             
29503             file.target.remove();
29504
29505         }, this);
29506         
29507         this.files = [];
29508         
29509         this.refresh();
29510     },
29511     
29512     onClick : function(e, el, o)
29513     {
29514         e.preventDefault();
29515         
29516         this.fireEvent('click', this, o);
29517         
29518     },
29519     
29520     closable : function(closable)
29521     {
29522         Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
29523             
29524             el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29525             
29526             if(closable){
29527                 el.show();
29528                 return;
29529             }
29530             
29531             el.hide();
29532             
29533         }, this);
29534     },
29535     
29536     xhrOnLoad : function(xhr)
29537     {
29538         Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29539             el.remove();
29540         }, this);
29541         
29542         if (xhr.readyState !== 4) {
29543             this.arrange();
29544             this.fireEvent('exception', this, xhr);
29545             return;
29546         }
29547
29548         var response = Roo.decode(xhr.responseText);
29549         
29550         if(!response.success){
29551             this.arrange();
29552             this.fireEvent('exception', this, xhr);
29553             return;
29554         }
29555         
29556         var file = this.renderPreview(response.data);
29557         
29558         this.files.push(file);
29559         
29560         this.arrange();
29561         
29562         this.fireEvent('afterupload', this, xhr);
29563         
29564     },
29565     
29566     xhrOnError : function(xhr)
29567     {
29568         Roo.log('xhr on error');
29569         
29570         var response = Roo.decode(xhr.responseText);
29571           
29572         Roo.log(response);
29573         
29574         this.arrange();
29575     },
29576     
29577     process : function(file)
29578     {
29579         if(this.fireEvent('process', this, file) !== false){
29580             if(this.editable && file.type.indexOf('image') != -1){
29581                 this.fireEvent('edit', this, file);
29582                 return;
29583             }
29584
29585             this.uploadStart(file, false);
29586
29587             return;
29588         }
29589         
29590     },
29591     
29592     uploadStart : function(file, crop)
29593     {
29594         this.xhr = new XMLHttpRequest();
29595         
29596         if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29597             this.arrange();
29598             return;
29599         }
29600         
29601         file.xhr = this.xhr;
29602             
29603         this.managerEl.createChild({
29604             tag : 'div',
29605             cls : 'roo-document-manager-loading',
29606             cn : [
29607                 {
29608                     tag : 'div',
29609                     tooltip : file.name,
29610                     cls : 'roo-document-manager-thumb',
29611                     html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29612                 }
29613             ]
29614
29615         });
29616
29617         this.xhr.open(this.method, this.url, true);
29618         
29619         var headers = {
29620             "Accept": "application/json",
29621             "Cache-Control": "no-cache",
29622             "X-Requested-With": "XMLHttpRequest"
29623         };
29624         
29625         for (var headerName in headers) {
29626             var headerValue = headers[headerName];
29627             if (headerValue) {
29628                 this.xhr.setRequestHeader(headerName, headerValue);
29629             }
29630         }
29631         
29632         var _this = this;
29633         
29634         this.xhr.onload = function()
29635         {
29636             _this.xhrOnLoad(_this.xhr);
29637         }
29638         
29639         this.xhr.onerror = function()
29640         {
29641             _this.xhrOnError(_this.xhr);
29642         }
29643         
29644         var formData = new FormData();
29645
29646         formData.append('returnHTML', 'NO');
29647         
29648         if(crop){
29649             formData.append('crop', crop);
29650         }
29651         
29652         formData.append(this.paramName, file, file.name);
29653         
29654         var options = {
29655             file : file, 
29656             manually : false
29657         };
29658         
29659         if(this.fireEvent('prepare', this, formData, options) != false){
29660             
29661             if(options.manually){
29662                 return;
29663             }
29664             
29665             this.xhr.send(formData);
29666             return;
29667         };
29668         
29669         this.uploadCancel();
29670     },
29671     
29672     uploadCancel : function()
29673     {
29674         if (this.xhr) {
29675             this.xhr.abort();
29676         }
29677         
29678         this.delegates = [];
29679         
29680         Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29681             el.remove();
29682         }, this);
29683         
29684         this.arrange();
29685     },
29686     
29687     renderPreview : function(file)
29688     {
29689         if(typeof(file.target) != 'undefined' && file.target){
29690             return file;
29691         }
29692         
29693         var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29694         
29695         var previewEl = this.managerEl.createChild({
29696             tag : 'div',
29697             cls : 'roo-document-manager-preview',
29698             cn : [
29699                 {
29700                     tag : 'div',
29701                     tooltip : file[this.toolTipName],
29702                     cls : 'roo-document-manager-thumb',
29703                     html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29704                 },
29705                 {
29706                     tag : 'button',
29707                     cls : 'close',
29708                     html : '<i class="fa fa-times-circle"></i>'
29709                 }
29710             ]
29711         });
29712
29713         var close = previewEl.select('button.close', true).first();
29714
29715         close.on('click', this.onRemove, this, file);
29716
29717         file.target = previewEl;
29718
29719         var image = previewEl.select('img', true).first();
29720         
29721         var _this = this;
29722         
29723         image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29724         
29725         image.on('click', this.onClick, this, file);
29726         
29727         this.fireEvent('previewrendered', this, file);
29728         
29729         return file;
29730         
29731     },
29732     
29733     onPreviewLoad : function(file, image)
29734     {
29735         if(typeof(file.target) == 'undefined' || !file.target){
29736             return;
29737         }
29738         
29739         var width = image.dom.naturalWidth || image.dom.width;
29740         var height = image.dom.naturalHeight || image.dom.height;
29741         
29742         if(!this.previewResize) {
29743             return;
29744         }
29745         
29746         if(width > height){
29747             file.target.addClass('wide');
29748             return;
29749         }
29750         
29751         file.target.addClass('tall');
29752         return;
29753         
29754     },
29755     
29756     uploadFromSource : function(file, crop)
29757     {
29758         this.xhr = new XMLHttpRequest();
29759         
29760         this.managerEl.createChild({
29761             tag : 'div',
29762             cls : 'roo-document-manager-loading',
29763             cn : [
29764                 {
29765                     tag : 'div',
29766                     tooltip : file.name,
29767                     cls : 'roo-document-manager-thumb',
29768                     html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29769                 }
29770             ]
29771
29772         });
29773
29774         this.xhr.open(this.method, this.url, true);
29775         
29776         var headers = {
29777             "Accept": "application/json",
29778             "Cache-Control": "no-cache",
29779             "X-Requested-With": "XMLHttpRequest"
29780         };
29781         
29782         for (var headerName in headers) {
29783             var headerValue = headers[headerName];
29784             if (headerValue) {
29785                 this.xhr.setRequestHeader(headerName, headerValue);
29786             }
29787         }
29788         
29789         var _this = this;
29790         
29791         this.xhr.onload = function()
29792         {
29793             _this.xhrOnLoad(_this.xhr);
29794         }
29795         
29796         this.xhr.onerror = function()
29797         {
29798             _this.xhrOnError(_this.xhr);
29799         }
29800         
29801         var formData = new FormData();
29802
29803         formData.append('returnHTML', 'NO');
29804         
29805         formData.append('crop', crop);
29806         
29807         if(typeof(file.filename) != 'undefined'){
29808             formData.append('filename', file.filename);
29809         }
29810         
29811         if(typeof(file.mimetype) != 'undefined'){
29812             formData.append('mimetype', file.mimetype);
29813         }
29814         
29815         Roo.log(formData);
29816         
29817         if(this.fireEvent('prepare', this, formData) != false){
29818             this.xhr.send(formData);
29819         };
29820     }
29821 });
29822
29823 /*
29824 * Licence: LGPL
29825 */
29826
29827 /**
29828  * @class Roo.bootstrap.DocumentViewer
29829  * @extends Roo.bootstrap.Component
29830  * Bootstrap DocumentViewer class
29831  * @cfg {Boolean} showDownload (true|false) show download button (default true)
29832  * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29833  * 
29834  * @constructor
29835  * Create a new DocumentViewer
29836  * @param {Object} config The config object
29837  */
29838
29839 Roo.bootstrap.DocumentViewer = function(config){
29840     Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29841     
29842     this.addEvents({
29843         /**
29844          * @event initial
29845          * Fire after initEvent
29846          * @param {Roo.bootstrap.DocumentViewer} this
29847          */
29848         "initial" : true,
29849         /**
29850          * @event click
29851          * Fire after click
29852          * @param {Roo.bootstrap.DocumentViewer} this
29853          */
29854         "click" : true,
29855         /**
29856          * @event download
29857          * Fire after download button
29858          * @param {Roo.bootstrap.DocumentViewer} this
29859          */
29860         "download" : true,
29861         /**
29862          * @event trash
29863          * Fire after trash button
29864          * @param {Roo.bootstrap.DocumentViewer} this
29865          */
29866         "trash" : true
29867         
29868     });
29869 };
29870
29871 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component,  {
29872     
29873     showDownload : true,
29874     
29875     showTrash : true,
29876     
29877     getAutoCreate : function()
29878     {
29879         var cfg = {
29880             tag : 'div',
29881             cls : 'roo-document-viewer',
29882             cn : [
29883                 {
29884                     tag : 'div',
29885                     cls : 'roo-document-viewer-body',
29886                     cn : [
29887                         {
29888                             tag : 'div',
29889                             cls : 'roo-document-viewer-thumb',
29890                             cn : [
29891                                 {
29892                                     tag : 'img',
29893                                     cls : 'roo-document-viewer-image'
29894                                 }
29895                             ]
29896                         }
29897                     ]
29898                 },
29899                 {
29900                     tag : 'div',
29901                     cls : 'roo-document-viewer-footer',
29902                     cn : {
29903                         tag : 'div',
29904                         cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29905                         cn : [
29906                             {
29907                                 tag : 'div',
29908                                 cls : 'btn-group roo-document-viewer-download',
29909                                 cn : [
29910                                     {
29911                                         tag : 'button',
29912                                         cls : 'btn btn-default',
29913                                         html : '<i class="fa fa-download"></i>'
29914                                     }
29915                                 ]
29916                             },
29917                             {
29918                                 tag : 'div',
29919                                 cls : 'btn-group roo-document-viewer-trash',
29920                                 cn : [
29921                                     {
29922                                         tag : 'button',
29923                                         cls : 'btn btn-default',
29924                                         html : '<i class="fa fa-trash"></i>'
29925                                     }
29926                                 ]
29927                             }
29928                         ]
29929                     }
29930                 }
29931             ]
29932         };
29933         
29934         return cfg;
29935     },
29936     
29937     initEvents : function()
29938     {
29939         this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29940         this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29941         
29942         this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29943         this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29944         
29945         this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29946         this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29947         
29948         this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29949         this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29950         
29951         this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29952         this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29953         
29954         this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29955         this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29956         
29957         this.bodyEl.on('click', this.onClick, this);
29958         this.downloadBtn.on('click', this.onDownload, this);
29959         this.trashBtn.on('click', this.onTrash, this);
29960         
29961         this.downloadBtn.hide();
29962         this.trashBtn.hide();
29963         
29964         if(this.showDownload){
29965             this.downloadBtn.show();
29966         }
29967         
29968         if(this.showTrash){
29969             this.trashBtn.show();
29970         }
29971         
29972         if(!this.showDownload && !this.showTrash) {
29973             this.footerEl.hide();
29974         }
29975         
29976     },
29977     
29978     initial : function()
29979     {
29980         this.fireEvent('initial', this);
29981         
29982     },
29983     
29984     onClick : function(e)
29985     {
29986         e.preventDefault();
29987         
29988         this.fireEvent('click', this);
29989     },
29990     
29991     onDownload : function(e)
29992     {
29993         e.preventDefault();
29994         
29995         this.fireEvent('download', this);
29996     },
29997     
29998     onTrash : function(e)
29999     {
30000         e.preventDefault();
30001         
30002         this.fireEvent('trash', this);
30003     }
30004     
30005 });
30006 /*
30007  * - LGPL
30008  *
30009  * nav progress bar
30010  * 
30011  */
30012
30013 /**
30014  * @class Roo.bootstrap.NavProgressBar
30015  * @extends Roo.bootstrap.Component
30016  * Bootstrap NavProgressBar class
30017  * 
30018  * @constructor
30019  * Create a new nav progress bar
30020  * @param {Object} config The config object
30021  */
30022
30023 Roo.bootstrap.NavProgressBar = function(config){
30024     Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
30025
30026     this.bullets = this.bullets || [];
30027    
30028 //    Roo.bootstrap.NavProgressBar.register(this);
30029      this.addEvents({
30030         /**
30031              * @event changed
30032              * Fires when the active item changes
30033              * @param {Roo.bootstrap.NavProgressBar} this
30034              * @param {Roo.bootstrap.NavProgressItem} selected The item selected
30035              * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item 
30036          */
30037         'changed': true
30038      });
30039     
30040 };
30041
30042 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component,  {
30043     
30044     bullets : [],
30045     barItems : [],
30046     
30047     getAutoCreate : function()
30048     {
30049         var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
30050         
30051         cfg = {
30052             tag : 'div',
30053             cls : 'roo-navigation-bar-group',
30054             cn : [
30055                 {
30056                     tag : 'div',
30057                     cls : 'roo-navigation-top-bar'
30058                 },
30059                 {
30060                     tag : 'div',
30061                     cls : 'roo-navigation-bullets-bar',
30062                     cn : [
30063                         {
30064                             tag : 'ul',
30065                             cls : 'roo-navigation-bar'
30066                         }
30067                     ]
30068                 },
30069                 
30070                 {
30071                     tag : 'div',
30072                     cls : 'roo-navigation-bottom-bar'
30073                 }
30074             ]
30075             
30076         };
30077         
30078         return cfg;
30079         
30080     },
30081     
30082     initEvents: function() 
30083     {
30084         
30085     },
30086     
30087     onRender : function(ct, position) 
30088     {
30089         Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30090         
30091         if(this.bullets.length){
30092             Roo.each(this.bullets, function(b){
30093                this.addItem(b);
30094             }, this);
30095         }
30096         
30097         this.format();
30098         
30099     },
30100     
30101     addItem : function(cfg)
30102     {
30103         var item = new Roo.bootstrap.NavProgressItem(cfg);
30104         
30105         item.parentId = this.id;
30106         item.render(this.el.select('.roo-navigation-bar', true).first(), null);
30107         
30108         if(cfg.html){
30109             var top = new Roo.bootstrap.Element({
30110                 tag : 'div',
30111                 cls : 'roo-navigation-bar-text'
30112             });
30113             
30114             var bottom = new Roo.bootstrap.Element({
30115                 tag : 'div',
30116                 cls : 'roo-navigation-bar-text'
30117             });
30118             
30119             top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
30120             bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
30121             
30122             var topText = new Roo.bootstrap.Element({
30123                 tag : 'span',
30124                 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
30125             });
30126             
30127             var bottomText = new Roo.bootstrap.Element({
30128                 tag : 'span',
30129                 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
30130             });
30131             
30132             topText.onRender(top.el, null);
30133             bottomText.onRender(bottom.el, null);
30134             
30135             item.topEl = top;
30136             item.bottomEl = bottom;
30137         }
30138         
30139         this.barItems.push(item);
30140         
30141         return item;
30142     },
30143     
30144     getActive : function()
30145     {
30146         var active = false;
30147         
30148         Roo.each(this.barItems, function(v){
30149             
30150             if (!v.isActive()) {
30151                 return;
30152             }
30153             
30154             active = v;
30155             return false;
30156             
30157         });
30158         
30159         return active;
30160     },
30161     
30162     setActiveItem : function(item)
30163     {
30164         var prev = false;
30165         
30166         Roo.each(this.barItems, function(v){
30167             if (v.rid == item.rid) {
30168                 return ;
30169             }
30170             
30171             if (v.isActive()) {
30172                 v.setActive(false);
30173                 prev = v;
30174             }
30175         });
30176
30177         item.setActive(true);
30178         
30179         this.fireEvent('changed', this, item, prev);
30180     },
30181     
30182     getBarItem: function(rid)
30183     {
30184         var ret = false;
30185         
30186         Roo.each(this.barItems, function(e) {
30187             if (e.rid != rid) {
30188                 return;
30189             }
30190             
30191             ret =  e;
30192             return false;
30193         });
30194         
30195         return ret;
30196     },
30197     
30198     indexOfItem : function(item)
30199     {
30200         var index = false;
30201         
30202         Roo.each(this.barItems, function(v, i){
30203             
30204             if (v.rid != item.rid) {
30205                 return;
30206             }
30207             
30208             index = i;
30209             return false
30210         });
30211         
30212         return index;
30213     },
30214     
30215     setActiveNext : function()
30216     {
30217         var i = this.indexOfItem(this.getActive());
30218         
30219         if (i > this.barItems.length) {
30220             return;
30221         }
30222         
30223         this.setActiveItem(this.barItems[i+1]);
30224     },
30225     
30226     setActivePrev : function()
30227     {
30228         var i = this.indexOfItem(this.getActive());
30229         
30230         if (i  < 1) {
30231             return;
30232         }
30233         
30234         this.setActiveItem(this.barItems[i-1]);
30235     },
30236     
30237     format : function()
30238     {
30239         if(!this.barItems.length){
30240             return;
30241         }
30242      
30243         var width = 100 / this.barItems.length;
30244         
30245         Roo.each(this.barItems, function(i){
30246             i.el.setStyle('width', width + '%');
30247             i.topEl.el.setStyle('width', width + '%');
30248             i.bottomEl.el.setStyle('width', width + '%');
30249         }, this);
30250         
30251     }
30252     
30253 });
30254 /*
30255  * - LGPL
30256  *
30257  * Nav Progress Item
30258  * 
30259  */
30260
30261 /**
30262  * @class Roo.bootstrap.NavProgressItem
30263  * @extends Roo.bootstrap.Component
30264  * Bootstrap NavProgressItem class
30265  * @cfg {String} rid the reference id
30266  * @cfg {Boolean} active (true|false) Is item active default false
30267  * @cfg {Boolean} disabled (true|false) Is item active default false
30268  * @cfg {String} html
30269  * @cfg {String} position (top|bottom) text position default bottom
30270  * @cfg {String} icon show icon instead of number
30271  * 
30272  * @constructor
30273  * Create a new NavProgressItem
30274  * @param {Object} config The config object
30275  */
30276 Roo.bootstrap.NavProgressItem = function(config){
30277     Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
30278     this.addEvents({
30279         // raw events
30280         /**
30281          * @event click
30282          * The raw click event for the entire grid.
30283          * @param {Roo.bootstrap.NavProgressItem} this
30284          * @param {Roo.EventObject} e
30285          */
30286         "click" : true
30287     });
30288    
30289 };
30290
30291 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component,  {
30292     
30293     rid : '',
30294     active : false,
30295     disabled : false,
30296     html : '',
30297     position : 'bottom',
30298     icon : false,
30299     
30300     getAutoCreate : function()
30301     {
30302         var iconCls = 'roo-navigation-bar-item-icon';
30303         
30304         iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
30305         
30306         var cfg = {
30307             tag: 'li',
30308             cls: 'roo-navigation-bar-item',
30309             cn : [
30310                 {
30311                     tag : 'i',
30312                     cls : iconCls
30313                 }
30314             ]
30315         };
30316         
30317         if(this.active){
30318             cfg.cls += ' active';
30319         }
30320         if(this.disabled){
30321             cfg.cls += ' disabled';
30322         }
30323         
30324         return cfg;
30325     },
30326     
30327     disable : function()
30328     {
30329         this.setDisabled(true);
30330     },
30331     
30332     enable : function()
30333     {
30334         this.setDisabled(false);
30335     },
30336     
30337     initEvents: function() 
30338     {
30339         this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
30340         
30341         this.iconEl.on('click', this.onClick, this);
30342     },
30343     
30344     onClick : function(e)
30345     {
30346         e.preventDefault();
30347         
30348         if(this.disabled){
30349             return;
30350         }
30351         
30352         if(this.fireEvent('click', this, e) === false){
30353             return;
30354         };
30355         
30356         this.parent().setActiveItem(this);
30357     },
30358     
30359     isActive: function () 
30360     {
30361         return this.active;
30362     },
30363     
30364     setActive : function(state)
30365     {
30366         if(this.active == state){
30367             return;
30368         }
30369         
30370         this.active = state;
30371         
30372         if (state) {
30373             this.el.addClass('active');
30374             return;
30375         }
30376         
30377         this.el.removeClass('active');
30378         
30379         return;
30380     },
30381     
30382     setDisabled : function(state)
30383     {
30384         if(this.disabled == state){
30385             return;
30386         }
30387         
30388         this.disabled = state;
30389         
30390         if (state) {
30391             this.el.addClass('disabled');
30392             return;
30393         }
30394         
30395         this.el.removeClass('disabled');
30396     },
30397     
30398     tooltipEl : function()
30399     {
30400         return this.el.select('.roo-navigation-bar-item-icon', true).first();;
30401     }
30402 });
30403  
30404
30405  /*
30406  * - LGPL
30407  *
30408  * FieldLabel
30409  * 
30410  */
30411
30412 /**
30413  * @class Roo.bootstrap.FieldLabel
30414  * @extends Roo.bootstrap.Component
30415  * Bootstrap FieldLabel class
30416  * @cfg {String} html contents of the element
30417  * @cfg {String} tag tag of the element default label
30418  * @cfg {String} cls class of the element
30419  * @cfg {String} target label target 
30420  * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
30421  * @cfg {String} invalidClass DEPRICATED - BS4 uses is-invalid
30422  * @cfg {String} validClass DEPRICATED - BS4 uses is-valid
30423  * @cfg {String} iconTooltip default "This field is required"
30424  * @cfg {String} indicatorpos (left|right) default left
30425  * 
30426  * @constructor
30427  * Create a new FieldLabel
30428  * @param {Object} config The config object
30429  */
30430
30431 Roo.bootstrap.FieldLabel = function(config){
30432     Roo.bootstrap.Element.superclass.constructor.call(this, config);
30433     
30434     this.addEvents({
30435             /**
30436              * @event invalid
30437              * Fires after the field has been marked as invalid.
30438              * @param {Roo.form.FieldLabel} this
30439              * @param {String} msg The validation message
30440              */
30441             invalid : true,
30442             /**
30443              * @event valid
30444              * Fires after the field has been validated with no errors.
30445              * @param {Roo.form.FieldLabel} this
30446              */
30447             valid : true
30448         });
30449 };
30450
30451 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component,  {
30452     
30453     tag: 'label',
30454     cls: '',
30455     html: '',
30456     target: '',
30457     allowBlank : true,
30458     invalidClass : 'has-warning',
30459     validClass : 'has-success',
30460     iconTooltip : 'This field is required',
30461     indicatorpos : 'left',
30462     
30463     getAutoCreate : function(){
30464         
30465         var cls = "";
30466         if (!this.allowBlank) {
30467             cls  = "visible";
30468         }
30469         
30470         var cfg = {
30471             tag : this.tag,
30472             cls : 'roo-bootstrap-field-label ' + this.cls,
30473             for : this.target,
30474             cn : [
30475                 {
30476                     tag : 'i',
30477                     cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
30478                     tooltip : this.iconTooltip
30479                 },
30480                 {
30481                     tag : 'span',
30482                     html : this.html
30483                 }
30484             ] 
30485         };
30486         
30487         if(this.indicatorpos == 'right'){
30488             var cfg = {
30489                 tag : this.tag,
30490                 cls : 'roo-bootstrap-field-label ' + this.cls,
30491                 for : this.target,
30492                 cn : [
30493                     {
30494                         tag : 'span',
30495                         html : this.html
30496                     },
30497                     {
30498                         tag : 'i',
30499                         cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
30500                         tooltip : this.iconTooltip
30501                     }
30502                 ] 
30503             };
30504         }
30505         
30506         return cfg;
30507     },
30508     
30509     initEvents: function() 
30510     {
30511         Roo.bootstrap.Element.superclass.initEvents.call(this);
30512         
30513         this.indicator = this.indicatorEl();
30514         
30515         if(this.indicator){
30516             this.indicator.removeClass('visible');
30517             this.indicator.addClass('invisible');
30518         }
30519         
30520         Roo.bootstrap.FieldLabel.register(this);
30521     },
30522     
30523     indicatorEl : function()
30524     {
30525         var indicator = this.el.select('i.roo-required-indicator',true).first();
30526         
30527         if(!indicator){
30528             return false;
30529         }
30530         
30531         return indicator;
30532         
30533     },
30534     
30535     /**
30536      * Mark this field as valid
30537      */
30538     markValid : function()
30539     {
30540         if(this.indicator){
30541             this.indicator.removeClass('visible');
30542             this.indicator.addClass('invisible');
30543         }
30544         if (Roo.bootstrap.version == 3) {
30545             this.el.removeClass(this.invalidClass);
30546             this.el.addClass(this.validClass);
30547         } else {
30548             this.el.removeClass('is-invalid');
30549             this.el.addClass('is-valid');
30550         }
30551         
30552         
30553         this.fireEvent('valid', this);
30554     },
30555     
30556     /**
30557      * Mark this field as invalid
30558      * @param {String} msg The validation message
30559      */
30560     markInvalid : function(msg)
30561     {
30562         if(this.indicator){
30563             this.indicator.removeClass('invisible');
30564             this.indicator.addClass('visible');
30565         }
30566           if (Roo.bootstrap.version == 3) {
30567             this.el.removeClass(this.validClass);
30568             this.el.addClass(this.invalidClass);
30569         } else {
30570             this.el.removeClass('is-valid');
30571             this.el.addClass('is-invalid');
30572         }
30573         
30574         
30575         this.fireEvent('invalid', this, msg);
30576     }
30577     
30578    
30579 });
30580
30581 Roo.apply(Roo.bootstrap.FieldLabel, {
30582     
30583     groups: {},
30584     
30585      /**
30586     * register a FieldLabel Group
30587     * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
30588     */
30589     register : function(label)
30590     {
30591         if(this.groups.hasOwnProperty(label.target)){
30592             return;
30593         }
30594      
30595         this.groups[label.target] = label;
30596         
30597     },
30598     /**
30599     * fetch a FieldLabel Group based on the target
30600     * @param {string} target
30601     * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
30602     */
30603     get: function(target) {
30604         if (typeof(this.groups[target]) == 'undefined') {
30605             return false;
30606         }
30607         
30608         return this.groups[target] ;
30609     }
30610 });
30611
30612  
30613
30614  /*
30615  * - LGPL
30616  *
30617  * page DateSplitField.
30618  * 
30619  */
30620
30621
30622 /**
30623  * @class Roo.bootstrap.DateSplitField
30624  * @extends Roo.bootstrap.Component
30625  * Bootstrap DateSplitField class
30626  * @cfg {string} fieldLabel - the label associated
30627  * @cfg {Number} labelWidth set the width of label (0-12)
30628  * @cfg {String} labelAlign (top|left)
30629  * @cfg {Boolean} dayAllowBlank (true|false) default false
30630  * @cfg {Boolean} monthAllowBlank (true|false) default false
30631  * @cfg {Boolean} yearAllowBlank (true|false) default false
30632  * @cfg {string} dayPlaceholder 
30633  * @cfg {string} monthPlaceholder
30634  * @cfg {string} yearPlaceholder
30635  * @cfg {string} dayFormat default 'd'
30636  * @cfg {string} monthFormat default 'm'
30637  * @cfg {string} yearFormat default 'Y'
30638  * @cfg {Number} labellg set the width of label (1-12)
30639  * @cfg {Number} labelmd set the width of label (1-12)
30640  * @cfg {Number} labelsm set the width of label (1-12)
30641  * @cfg {Number} labelxs set the width of label (1-12)
30642
30643  *     
30644  * @constructor
30645  * Create a new DateSplitField
30646  * @param {Object} config The config object
30647  */
30648
30649 Roo.bootstrap.DateSplitField = function(config){
30650     Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
30651     
30652     this.addEvents({
30653         // raw events
30654          /**
30655          * @event years
30656          * getting the data of years
30657          * @param {Roo.bootstrap.DateSplitField} this
30658          * @param {Object} years
30659          */
30660         "years" : true,
30661         /**
30662          * @event days
30663          * getting the data of days
30664          * @param {Roo.bootstrap.DateSplitField} this
30665          * @param {Object} days
30666          */
30667         "days" : true,
30668         /**
30669          * @event invalid
30670          * Fires after the field has been marked as invalid.
30671          * @param {Roo.form.Field} this
30672          * @param {String} msg The validation message
30673          */
30674         invalid : true,
30675        /**
30676          * @event valid
30677          * Fires after the field has been validated with no errors.
30678          * @param {Roo.form.Field} this
30679          */
30680         valid : true
30681     });
30682 };
30683
30684 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component,  {
30685     
30686     fieldLabel : '',
30687     labelAlign : 'top',
30688     labelWidth : 3,
30689     dayAllowBlank : false,
30690     monthAllowBlank : false,
30691     yearAllowBlank : false,
30692     dayPlaceholder : '',
30693     monthPlaceholder : '',
30694     yearPlaceholder : '',
30695     dayFormat : 'd',
30696     monthFormat : 'm',
30697     yearFormat : 'Y',
30698     isFormField : true,
30699     labellg : 0,
30700     labelmd : 0,
30701     labelsm : 0,
30702     labelxs : 0,
30703     
30704     getAutoCreate : function()
30705     {
30706         var cfg = {
30707             tag : 'div',
30708             cls : 'row roo-date-split-field-group',
30709             cn : [
30710                 {
30711                     tag : 'input',
30712                     type : 'hidden',
30713                     cls : 'form-hidden-field roo-date-split-field-group-value',
30714                     name : this.name
30715                 }
30716             ]
30717         };
30718         
30719         var labelCls = 'col-md-12';
30720         var contentCls = 'col-md-4';
30721         
30722         if(this.fieldLabel){
30723             
30724             var label = {
30725                 tag : 'div',
30726                 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30727                 cn : [
30728                     {
30729                         tag : 'label',
30730                         html : this.fieldLabel
30731                     }
30732                 ]
30733             };
30734             
30735             if(this.labelAlign == 'left'){
30736             
30737                 if(this.labelWidth > 12){
30738                     label.style = "width: " + this.labelWidth + 'px';
30739                 }
30740
30741                 if(this.labelWidth < 13 && this.labelmd == 0){
30742                     this.labelmd = this.labelWidth;
30743                 }
30744
30745                 if(this.labellg > 0){
30746                     labelCls = ' col-lg-' + this.labellg;
30747                     contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30748                 }
30749
30750                 if(this.labelmd > 0){
30751                     labelCls = ' col-md-' + this.labelmd;
30752                     contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30753                 }
30754
30755                 if(this.labelsm > 0){
30756                     labelCls = ' col-sm-' + this.labelsm;
30757                     contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30758                 }
30759
30760                 if(this.labelxs > 0){
30761                     labelCls = ' col-xs-' + this.labelxs;
30762                     contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30763                 }
30764             }
30765             
30766             label.cls += ' ' + labelCls;
30767             
30768             cfg.cn.push(label);
30769         }
30770         
30771         Roo.each(['day', 'month', 'year'], function(t){
30772             cfg.cn.push({
30773                 tag : 'div',
30774                 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30775             });
30776         }, this);
30777         
30778         return cfg;
30779     },
30780     
30781     inputEl: function ()
30782     {
30783         return this.el.select('.roo-date-split-field-group-value', true).first();
30784     },
30785     
30786     onRender : function(ct, position) 
30787     {
30788         var _this = this;
30789         
30790         Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30791         
30792         this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30793         
30794         this.dayField = new Roo.bootstrap.ComboBox({
30795             allowBlank : this.dayAllowBlank,
30796             alwaysQuery : true,
30797             displayField : 'value',
30798             editable : false,
30799             fieldLabel : '',
30800             forceSelection : true,
30801             mode : 'local',
30802             placeholder : this.dayPlaceholder,
30803             selectOnFocus : true,
30804             tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30805             triggerAction : 'all',
30806             typeAhead : true,
30807             valueField : 'value',
30808             store : new Roo.data.SimpleStore({
30809                 data : (function() {    
30810                     var days = [];
30811                     _this.fireEvent('days', _this, days);
30812                     return days;
30813                 })(),
30814                 fields : [ 'value' ]
30815             }),
30816             listeners : {
30817                 select : function (_self, record, index)
30818                 {
30819                     _this.setValue(_this.getValue());
30820                 }
30821             }
30822         });
30823
30824         this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30825         
30826         this.monthField = new Roo.bootstrap.MonthField({
30827             after : '<i class=\"fa fa-calendar\"></i>',
30828             allowBlank : this.monthAllowBlank,
30829             placeholder : this.monthPlaceholder,
30830             readOnly : true,
30831             listeners : {
30832                 render : function (_self)
30833                 {
30834                     this.el.select('span.input-group-addon', true).first().on('click', function(e){
30835                         e.preventDefault();
30836                         _self.focus();
30837                     });
30838                 },
30839                 select : function (_self, oldvalue, newvalue)
30840                 {
30841                     _this.setValue(_this.getValue());
30842                 }
30843             }
30844         });
30845         
30846         this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30847         
30848         this.yearField = new Roo.bootstrap.ComboBox({
30849             allowBlank : this.yearAllowBlank,
30850             alwaysQuery : true,
30851             displayField : 'value',
30852             editable : false,
30853             fieldLabel : '',
30854             forceSelection : true,
30855             mode : 'local',
30856             placeholder : this.yearPlaceholder,
30857             selectOnFocus : true,
30858             tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30859             triggerAction : 'all',
30860             typeAhead : true,
30861             valueField : 'value',
30862             store : new Roo.data.SimpleStore({
30863                 data : (function() {
30864                     var years = [];
30865                     _this.fireEvent('years', _this, years);
30866                     return years;
30867                 })(),
30868                 fields : [ 'value' ]
30869             }),
30870             listeners : {
30871                 select : function (_self, record, index)
30872                 {
30873                     _this.setValue(_this.getValue());
30874                 }
30875             }
30876         });
30877
30878         this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30879     },
30880     
30881     setValue : function(v, format)
30882     {
30883         this.inputEl.dom.value = v;
30884         
30885         var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30886         
30887         var d = Date.parseDate(v, f);
30888         
30889         if(!d){
30890             this.validate();
30891             return;
30892         }
30893         
30894         this.setDay(d.format(this.dayFormat));
30895         this.setMonth(d.format(this.monthFormat));
30896         this.setYear(d.format(this.yearFormat));
30897         
30898         this.validate();
30899         
30900         return;
30901     },
30902     
30903     setDay : function(v)
30904     {
30905         this.dayField.setValue(v);
30906         this.inputEl.dom.value = this.getValue();
30907         this.validate();
30908         return;
30909     },
30910     
30911     setMonth : function(v)
30912     {
30913         this.monthField.setValue(v, true);
30914         this.inputEl.dom.value = this.getValue();
30915         this.validate();
30916         return;
30917     },
30918     
30919     setYear : function(v)
30920     {
30921         this.yearField.setValue(v);
30922         this.inputEl.dom.value = this.getValue();
30923         this.validate();
30924         return;
30925     },
30926     
30927     getDay : function()
30928     {
30929         return this.dayField.getValue();
30930     },
30931     
30932     getMonth : function()
30933     {
30934         return this.monthField.getValue();
30935     },
30936     
30937     getYear : function()
30938     {
30939         return this.yearField.getValue();
30940     },
30941     
30942     getValue : function()
30943     {
30944         var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30945         
30946         var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30947         
30948         return date;
30949     },
30950     
30951     reset : function()
30952     {
30953         this.setDay('');
30954         this.setMonth('');
30955         this.setYear('');
30956         this.inputEl.dom.value = '';
30957         this.validate();
30958         return;
30959     },
30960     
30961     validate : function()
30962     {
30963         var d = this.dayField.validate();
30964         var m = this.monthField.validate();
30965         var y = this.yearField.validate();
30966         
30967         var valid = true;
30968         
30969         if(
30970                 (!this.dayAllowBlank && !d) ||
30971                 (!this.monthAllowBlank && !m) ||
30972                 (!this.yearAllowBlank && !y)
30973         ){
30974             valid = false;
30975         }
30976         
30977         if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30978             return valid;
30979         }
30980         
30981         if(valid){
30982             this.markValid();
30983             return valid;
30984         }
30985         
30986         this.markInvalid();
30987         
30988         return valid;
30989     },
30990     
30991     markValid : function()
30992     {
30993         
30994         var label = this.el.select('label', true).first();
30995         var icon = this.el.select('i.fa-star', true).first();
30996
30997         if(label && icon){
30998             icon.remove();
30999         }
31000         
31001         this.fireEvent('valid', this);
31002     },
31003     
31004      /**
31005      * Mark this field as invalid
31006      * @param {String} msg The validation message
31007      */
31008     markInvalid : function(msg)
31009     {
31010         
31011         var label = this.el.select('label', true).first();
31012         var icon = this.el.select('i.fa-star', true).first();
31013
31014         if(label && !icon){
31015             this.el.select('.roo-date-split-field-label', true).createChild({
31016                 tag : 'i',
31017                 cls : 'text-danger fa fa-lg fa-star',
31018                 tooltip : 'This field is required',
31019                 style : 'margin-right:5px;'
31020             }, label, true);
31021         }
31022         
31023         this.fireEvent('invalid', this, msg);
31024     },
31025     
31026     clearInvalid : function()
31027     {
31028         var label = this.el.select('label', true).first();
31029         var icon = this.el.select('i.fa-star', true).first();
31030
31031         if(label && icon){
31032             icon.remove();
31033         }
31034         
31035         this.fireEvent('valid', this);
31036     },
31037     
31038     getName: function()
31039     {
31040         return this.name;
31041     }
31042     
31043 });
31044
31045  /**
31046  *
31047  * This is based on 
31048  * http://masonry.desandro.com
31049  *
31050  * The idea is to render all the bricks based on vertical width...
31051  *
31052  * The original code extends 'outlayer' - we might need to use that....
31053  * 
31054  */
31055
31056
31057 /**
31058  * @class Roo.bootstrap.LayoutMasonry
31059  * @extends Roo.bootstrap.Component
31060  * Bootstrap Layout Masonry class
31061  * 
31062  * @constructor
31063  * Create a new Element
31064  * @param {Object} config The config object
31065  */
31066
31067 Roo.bootstrap.LayoutMasonry = function(config){
31068     
31069     Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
31070     
31071     this.bricks = [];
31072     
31073     Roo.bootstrap.LayoutMasonry.register(this);
31074     
31075     this.addEvents({
31076         // raw events
31077         /**
31078          * @event layout
31079          * Fire after layout the items
31080          * @param {Roo.bootstrap.LayoutMasonry} this
31081          * @param {Roo.EventObject} e
31082          */
31083         "layout" : true
31084     });
31085     
31086 };
31087
31088 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component,  {
31089     
31090     /**
31091      * @cfg {Boolean} isLayoutInstant = no animation?
31092      */   
31093     isLayoutInstant : false, // needed?
31094    
31095     /**
31096      * @cfg {Number} boxWidth  width of the columns
31097      */   
31098     boxWidth : 450,
31099     
31100       /**
31101      * @cfg {Number} boxHeight  - 0 for square, or fix it at a certian height
31102      */   
31103     boxHeight : 0,
31104     
31105     /**
31106      * @cfg {Number} padWidth padding below box..
31107      */   
31108     padWidth : 10, 
31109     
31110     /**
31111      * @cfg {Number} gutter gutter width..
31112      */   
31113     gutter : 10,
31114     
31115      /**
31116      * @cfg {Number} maxCols maximum number of columns
31117      */   
31118     
31119     maxCols: 0,
31120     
31121     /**
31122      * @cfg {Boolean} isAutoInitial defalut true
31123      */   
31124     isAutoInitial : true, 
31125     
31126     containerWidth: 0,
31127     
31128     /**
31129      * @cfg {Boolean} isHorizontal defalut false
31130      */   
31131     isHorizontal : false, 
31132
31133     currentSize : null,
31134     
31135     tag: 'div',
31136     
31137     cls: '',
31138     
31139     bricks: null, //CompositeElement
31140     
31141     cols : 1,
31142     
31143     _isLayoutInited : false,
31144     
31145 //    isAlternative : false, // only use for vertical layout...
31146     
31147     /**
31148      * @cfg {Number} alternativePadWidth padding below box..
31149      */   
31150     alternativePadWidth : 50,
31151     
31152     selectedBrick : [],
31153     
31154     getAutoCreate : function(){
31155         
31156         var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
31157         
31158         var cfg = {
31159             tag: this.tag,
31160             cls: 'blog-masonary-wrapper ' + this.cls,
31161             cn : {
31162                 cls : 'mas-boxes masonary'
31163             }
31164         };
31165         
31166         return cfg;
31167     },
31168     
31169     getChildContainer: function( )
31170     {
31171         if (this.boxesEl) {
31172             return this.boxesEl;
31173         }
31174         
31175         this.boxesEl = this.el.select('.mas-boxes').first();
31176         
31177         return this.boxesEl;
31178     },
31179     
31180     
31181     initEvents : function()
31182     {
31183         var _this = this;
31184         
31185         if(this.isAutoInitial){
31186             Roo.log('hook children rendered');
31187             this.on('childrenrendered', function() {
31188                 Roo.log('children rendered');
31189                 _this.initial();
31190             } ,this);
31191         }
31192     },
31193     
31194     initial : function()
31195     {
31196         this.selectedBrick = [];
31197         
31198         this.currentSize = this.el.getBox(true);
31199         
31200         Roo.EventManager.onWindowResize(this.resize, this); 
31201
31202         if(!this.isAutoInitial){
31203             this.layout();
31204             return;
31205         }
31206         
31207         this.layout();
31208         
31209         return;
31210         //this.layout.defer(500,this);
31211         
31212     },
31213     
31214     resize : function()
31215     {
31216         var cs = this.el.getBox(true);
31217         
31218         if (
31219                 this.currentSize.width == cs.width && 
31220                 this.currentSize.x == cs.x && 
31221                 this.currentSize.height == cs.height && 
31222                 this.currentSize.y == cs.y 
31223         ) {
31224             Roo.log("no change in with or X or Y");
31225             return;
31226         }
31227         
31228         this.currentSize = cs;
31229         
31230         this.layout();
31231         
31232     },
31233     
31234     layout : function()
31235     {   
31236         this._resetLayout();
31237         
31238         var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
31239         
31240         this.layoutItems( isInstant );
31241       
31242         this._isLayoutInited = true;
31243         
31244         this.fireEvent('layout', this);
31245         
31246     },
31247     
31248     _resetLayout : function()
31249     {
31250         if(this.isHorizontal){
31251             this.horizontalMeasureColumns();
31252             return;
31253         }
31254         
31255         this.verticalMeasureColumns();
31256         
31257     },
31258     
31259     verticalMeasureColumns : function()
31260     {
31261         this.getContainerWidth();
31262         
31263 //        if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
31264 //            this.colWidth = Math.floor(this.containerWidth * 0.8);
31265 //            return;
31266 //        }
31267         
31268         var boxWidth = this.boxWidth + this.padWidth;
31269         
31270         if(this.containerWidth < this.boxWidth){
31271             boxWidth = this.containerWidth
31272         }
31273         
31274         var containerWidth = this.containerWidth;
31275         
31276         var cols = Math.floor(containerWidth / boxWidth);
31277         
31278         this.cols = Math.max( cols, 1 );
31279         
31280         this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
31281         
31282         var totalBoxWidth = this.cols * boxWidth - this.padWidth;
31283         
31284         var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
31285         
31286         this.colWidth = boxWidth + avail - this.padWidth;
31287         
31288         this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
31289         this.unitHeight = this.boxHeight > 0 ? this.boxHeight  : this.unitWidth;
31290     },
31291     
31292     horizontalMeasureColumns : function()
31293     {
31294         this.getContainerWidth();
31295         
31296         var boxWidth = this.boxWidth;
31297         
31298         if(this.containerWidth < boxWidth){
31299             boxWidth = this.containerWidth;
31300         }
31301         
31302         this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
31303         
31304         this.el.setHeight(boxWidth);
31305         
31306     },
31307     
31308     getContainerWidth : function()
31309     {
31310         this.containerWidth = this.el.getBox(true).width;  //maybe use getComputedWidth
31311     },
31312     
31313     layoutItems : function( isInstant )
31314     {
31315         Roo.log(this.bricks);
31316         
31317         var items = Roo.apply([], this.bricks);
31318         
31319         if(this.isHorizontal){
31320             this._horizontalLayoutItems( items , isInstant );
31321             return;
31322         }
31323         
31324 //        if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
31325 //            this._verticalAlternativeLayoutItems( items , isInstant );
31326 //            return;
31327 //        }
31328         
31329         this._verticalLayoutItems( items , isInstant );
31330         
31331     },
31332     
31333     _verticalLayoutItems : function ( items , isInstant)
31334     {
31335         if ( !items || !items.length ) {
31336             return;
31337         }
31338         
31339         var standard = [
31340             ['xs', 'xs', 'xs', 'tall'],
31341             ['xs', 'xs', 'tall'],
31342             ['xs', 'xs', 'sm'],
31343             ['xs', 'xs', 'xs'],
31344             ['xs', 'tall'],
31345             ['xs', 'sm'],
31346             ['xs', 'xs'],
31347             ['xs'],
31348             
31349             ['sm', 'xs', 'xs'],
31350             ['sm', 'xs'],
31351             ['sm'],
31352             
31353             ['tall', 'xs', 'xs', 'xs'],
31354             ['tall', 'xs', 'xs'],
31355             ['tall', 'xs'],
31356             ['tall']
31357             
31358         ];
31359         
31360         var queue = [];
31361         
31362         var boxes = [];
31363         
31364         var box = [];
31365         
31366         Roo.each(items, function(item, k){
31367             
31368             switch (item.size) {
31369                 // these layouts take up a full box,
31370                 case 'md' :
31371                 case 'md-left' :
31372                 case 'md-right' :
31373                 case 'wide' :
31374                     
31375                     if(box.length){
31376                         boxes.push(box);
31377                         box = [];
31378                     }
31379                     
31380                     boxes.push([item]);
31381                     
31382                     break;
31383                     
31384                 case 'xs' :
31385                 case 'sm' :
31386                 case 'tall' :
31387                     
31388                     box.push(item);
31389                     
31390                     break;
31391                 default :
31392                     break;
31393                     
31394             }
31395             
31396         }, this);
31397         
31398         if(box.length){
31399             boxes.push(box);
31400             box = [];
31401         }
31402         
31403         var filterPattern = function(box, length)
31404         {
31405             if(!box.length){
31406                 return;
31407             }
31408             
31409             var match = false;
31410             
31411             var pattern = box.slice(0, length);
31412             
31413             var format = [];
31414             
31415             Roo.each(pattern, function(i){
31416                 format.push(i.size);
31417             }, this);
31418             
31419             Roo.each(standard, function(s){
31420                 
31421                 if(String(s) != String(format)){
31422                     return;
31423                 }
31424                 
31425                 match = true;
31426                 return false;
31427                 
31428             }, this);
31429             
31430             if(!match && length == 1){
31431                 return;
31432             }
31433             
31434             if(!match){
31435                 filterPattern(box, length - 1);
31436                 return;
31437             }
31438                 
31439             queue.push(pattern);
31440
31441             box = box.slice(length, box.length);
31442
31443             filterPattern(box, 4);
31444
31445             return;
31446             
31447         }
31448         
31449         Roo.each(boxes, function(box, k){
31450             
31451             if(!box.length){
31452                 return;
31453             }
31454             
31455             if(box.length == 1){
31456                 queue.push(box);
31457                 return;
31458             }
31459             
31460             filterPattern(box, 4);
31461             
31462         }, this);
31463         
31464         this._processVerticalLayoutQueue( queue, isInstant );
31465         
31466     },
31467     
31468 //    _verticalAlternativeLayoutItems : function( items , isInstant )
31469 //    {
31470 //        if ( !items || !items.length ) {
31471 //            return;
31472 //        }
31473 //
31474 //        this._processVerticalAlternativeLayoutQueue( items, isInstant );
31475 //        
31476 //    },
31477     
31478     _horizontalLayoutItems : function ( items , isInstant)
31479     {
31480         if ( !items || !items.length || items.length < 3) {
31481             return;
31482         }
31483         
31484         items.reverse();
31485         
31486         var eItems = items.slice(0, 3);
31487         
31488         items = items.slice(3, items.length);
31489         
31490         var standard = [
31491             ['xs', 'xs', 'xs', 'wide'],
31492             ['xs', 'xs', 'wide'],
31493             ['xs', 'xs', 'sm'],
31494             ['xs', 'xs', 'xs'],
31495             ['xs', 'wide'],
31496             ['xs', 'sm'],
31497             ['xs', 'xs'],
31498             ['xs'],
31499             
31500             ['sm', 'xs', 'xs'],
31501             ['sm', 'xs'],
31502             ['sm'],
31503             
31504             ['wide', 'xs', 'xs', 'xs'],
31505             ['wide', 'xs', 'xs'],
31506             ['wide', 'xs'],
31507             ['wide'],
31508             
31509             ['wide-thin']
31510         ];
31511         
31512         var queue = [];
31513         
31514         var boxes = [];
31515         
31516         var box = [];
31517         
31518         Roo.each(items, function(item, k){
31519             
31520             switch (item.size) {
31521                 case 'md' :
31522                 case 'md-left' :
31523                 case 'md-right' :
31524                 case 'tall' :
31525                     
31526                     if(box.length){
31527                         boxes.push(box);
31528                         box = [];
31529                     }
31530                     
31531                     boxes.push([item]);
31532                     
31533                     break;
31534                     
31535                 case 'xs' :
31536                 case 'sm' :
31537                 case 'wide' :
31538                 case 'wide-thin' :
31539                     
31540                     box.push(item);
31541                     
31542                     break;
31543                 default :
31544                     break;
31545                     
31546             }
31547             
31548         }, this);
31549         
31550         if(box.length){
31551             boxes.push(box);
31552             box = [];
31553         }
31554         
31555         var filterPattern = function(box, length)
31556         {
31557             if(!box.length){
31558                 return;
31559             }
31560             
31561             var match = false;
31562             
31563             var pattern = box.slice(0, length);
31564             
31565             var format = [];
31566             
31567             Roo.each(pattern, function(i){
31568                 format.push(i.size);
31569             }, this);
31570             
31571             Roo.each(standard, function(s){
31572                 
31573                 if(String(s) != String(format)){
31574                     return;
31575                 }
31576                 
31577                 match = true;
31578                 return false;
31579                 
31580             }, this);
31581             
31582             if(!match && length == 1){
31583                 return;
31584             }
31585             
31586             if(!match){
31587                 filterPattern(box, length - 1);
31588                 return;
31589             }
31590                 
31591             queue.push(pattern);
31592
31593             box = box.slice(length, box.length);
31594
31595             filterPattern(box, 4);
31596
31597             return;
31598             
31599         }
31600         
31601         Roo.each(boxes, function(box, k){
31602             
31603             if(!box.length){
31604                 return;
31605             }
31606             
31607             if(box.length == 1){
31608                 queue.push(box);
31609                 return;
31610             }
31611             
31612             filterPattern(box, 4);
31613             
31614         }, this);
31615         
31616         
31617         var prune = [];
31618         
31619         var pos = this.el.getBox(true);
31620         
31621         var minX = pos.x;
31622         
31623         var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31624         
31625         var hit_end = false;
31626         
31627         Roo.each(queue, function(box){
31628             
31629             if(hit_end){
31630                 
31631                 Roo.each(box, function(b){
31632                 
31633                     b.el.setVisibilityMode(Roo.Element.DISPLAY);
31634                     b.el.hide();
31635
31636                 }, this);
31637
31638                 return;
31639             }
31640             
31641             var mx = 0;
31642             
31643             Roo.each(box, function(b){
31644                 
31645                 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31646                 b.el.show();
31647
31648                 mx = Math.max(mx, b.x);
31649                 
31650             }, this);
31651             
31652             maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
31653             
31654             if(maxX < minX){
31655                 
31656                 Roo.each(box, function(b){
31657                 
31658                     b.el.setVisibilityMode(Roo.Element.DISPLAY);
31659                     b.el.hide();
31660                     
31661                 }, this);
31662                 
31663                 hit_end = true;
31664                 
31665                 return;
31666             }
31667             
31668             prune.push(box);
31669             
31670         }, this);
31671         
31672         this._processHorizontalLayoutQueue( prune, eItems, isInstant );
31673     },
31674     
31675     /** Sets position of item in DOM
31676     * @param {Element} item
31677     * @param {Number} x - horizontal position
31678     * @param {Number} y - vertical position
31679     * @param {Boolean} isInstant - disables transitions
31680     */
31681     _processVerticalLayoutQueue : function( queue, isInstant )
31682     {
31683         var pos = this.el.getBox(true);
31684         var x = pos.x;
31685         var y = pos.y;
31686         var maxY = [];
31687         
31688         for (var i = 0; i < this.cols; i++){
31689             maxY[i] = pos.y;
31690         }
31691         
31692         Roo.each(queue, function(box, k){
31693             
31694             var col = k % this.cols;
31695             
31696             Roo.each(box, function(b,kk){
31697                 
31698                 b.el.position('absolute');
31699                 
31700                 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31701                 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31702                 
31703                 if(b.size == 'md-left' || b.size == 'md-right'){
31704                     width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31705                     height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31706                 }
31707                 
31708                 b.el.setWidth(width);
31709                 b.el.setHeight(height);
31710                 // iframe?
31711                 b.el.select('iframe',true).setSize(width,height);
31712                 
31713             }, this);
31714             
31715             for (var i = 0; i < this.cols; i++){
31716                 
31717                 if(maxY[i] < maxY[col]){
31718                     col = i;
31719                     continue;
31720                 }
31721                 
31722                 col = Math.min(col, i);
31723                 
31724             }
31725             
31726             x = pos.x + col * (this.colWidth + this.padWidth);
31727             
31728             y = maxY[col];
31729             
31730             var positions = [];
31731             
31732             switch (box.length){
31733                 case 1 :
31734                     positions = this.getVerticalOneBoxColPositions(x, y, box);
31735                     break;
31736                 case 2 :
31737                     positions = this.getVerticalTwoBoxColPositions(x, y, box);
31738                     break;
31739                 case 3 :
31740                     positions = this.getVerticalThreeBoxColPositions(x, y, box);
31741                     break;
31742                 case 4 :
31743                     positions = this.getVerticalFourBoxColPositions(x, y, box);
31744                     break;
31745                 default :
31746                     break;
31747             }
31748             
31749             Roo.each(box, function(b,kk){
31750                 
31751                 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31752                 
31753                 var sz = b.el.getSize();
31754                 
31755                 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31756                 
31757             }, this);
31758             
31759         }, this);
31760         
31761         var mY = 0;
31762         
31763         for (var i = 0; i < this.cols; i++){
31764             mY = Math.max(mY, maxY[i]);
31765         }
31766         
31767         this.el.setHeight(mY - pos.y);
31768         
31769     },
31770     
31771 //    _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31772 //    {
31773 //        var pos = this.el.getBox(true);
31774 //        var x = pos.x;
31775 //        var y = pos.y;
31776 //        var maxX = pos.right;
31777 //        
31778 //        var maxHeight = 0;
31779 //        
31780 //        Roo.each(items, function(item, k){
31781 //            
31782 //            var c = k % 2;
31783 //            
31784 //            item.el.position('absolute');
31785 //                
31786 //            var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31787 //
31788 //            item.el.setWidth(width);
31789 //
31790 //            var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31791 //
31792 //            item.el.setHeight(height);
31793 //            
31794 //            if(c == 0){
31795 //                item.el.setXY([x, y], isInstant ? false : true);
31796 //            } else {
31797 //                item.el.setXY([maxX - width, y], isInstant ? false : true);
31798 //            }
31799 //            
31800 //            y = y + height + this.alternativePadWidth;
31801 //            
31802 //            maxHeight = maxHeight + height + this.alternativePadWidth;
31803 //            
31804 //        }, this);
31805 //        
31806 //        this.el.setHeight(maxHeight);
31807 //        
31808 //    },
31809     
31810     _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31811     {
31812         var pos = this.el.getBox(true);
31813         
31814         var minX = pos.x;
31815         var minY = pos.y;
31816         
31817         var maxX = pos.right;
31818         
31819         this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31820         
31821         var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31822         
31823         Roo.each(queue, function(box, k){
31824             
31825             Roo.each(box, function(b, kk){
31826                 
31827                 b.el.position('absolute');
31828                 
31829                 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31830                 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31831                 
31832                 if(b.size == 'md-left' || b.size == 'md-right'){
31833                     width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31834                     height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31835                 }
31836                 
31837                 b.el.setWidth(width);
31838                 b.el.setHeight(height);
31839                 
31840             }, this);
31841             
31842             if(!box.length){
31843                 return;
31844             }
31845             
31846             var positions = [];
31847             
31848             switch (box.length){
31849                 case 1 :
31850                     positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31851                     break;
31852                 case 2 :
31853                     positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31854                     break;
31855                 case 3 :
31856                     positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31857                     break;
31858                 case 4 :
31859                     positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31860                     break;
31861                 default :
31862                     break;
31863             }
31864             
31865             Roo.each(box, function(b,kk){
31866                 
31867                 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31868                 
31869                 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31870                 
31871             }, this);
31872             
31873         }, this);
31874         
31875     },
31876     
31877     _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31878     {
31879         Roo.each(eItems, function(b,k){
31880             
31881             b.size = (k == 0) ? 'sm' : 'xs';
31882             b.x = (k == 0) ? 2 : 1;
31883             b.y = (k == 0) ? 2 : 1;
31884             
31885             b.el.position('absolute');
31886             
31887             var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31888                 
31889             b.el.setWidth(width);
31890             
31891             var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31892             
31893             b.el.setHeight(height);
31894             
31895         }, this);
31896
31897         var positions = [];
31898         
31899         positions.push({
31900             x : maxX - this.unitWidth * 2 - this.gutter,
31901             y : minY
31902         });
31903         
31904         positions.push({
31905             x : maxX - this.unitWidth,
31906             y : minY + (this.unitWidth + this.gutter) * 2
31907         });
31908         
31909         positions.push({
31910             x : maxX - this.unitWidth * 3 - this.gutter * 2,
31911             y : minY
31912         });
31913         
31914         Roo.each(eItems, function(b,k){
31915             
31916             b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31917
31918         }, this);
31919         
31920     },
31921     
31922     getVerticalOneBoxColPositions : function(x, y, box)
31923     {
31924         var pos = [];
31925         
31926         var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31927         
31928         if(box[0].size == 'md-left'){
31929             rand = 0;
31930         }
31931         
31932         if(box[0].size == 'md-right'){
31933             rand = 1;
31934         }
31935         
31936         pos.push({
31937             x : x + (this.unitWidth + this.gutter) * rand,
31938             y : y
31939         });
31940         
31941         return pos;
31942     },
31943     
31944     getVerticalTwoBoxColPositions : function(x, y, box)
31945     {
31946         var pos = [];
31947         
31948         if(box[0].size == 'xs'){
31949             
31950             pos.push({
31951                 x : x,
31952                 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31953             });
31954
31955             pos.push({
31956                 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31957                 y : y
31958             });
31959             
31960             return pos;
31961             
31962         }
31963         
31964         pos.push({
31965             x : x,
31966             y : y
31967         });
31968
31969         pos.push({
31970             x : x + (this.unitWidth + this.gutter) * 2,
31971             y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31972         });
31973         
31974         return pos;
31975         
31976     },
31977     
31978     getVerticalThreeBoxColPositions : function(x, y, box)
31979     {
31980         var pos = [];
31981         
31982         if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31983             
31984             pos.push({
31985                 x : x,
31986                 y : y
31987             });
31988
31989             pos.push({
31990                 x : x + (this.unitWidth + this.gutter) * 1,
31991                 y : y
31992             });
31993             
31994             pos.push({
31995                 x : x + (this.unitWidth + this.gutter) * 2,
31996                 y : y
31997             });
31998             
31999             return pos;
32000             
32001         }
32002         
32003         if(box[0].size == 'xs' && box[1].size == 'xs'){
32004             
32005             pos.push({
32006                 x : x,
32007                 y : y
32008             });
32009
32010             pos.push({
32011                 x : x,
32012                 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
32013             });
32014             
32015             pos.push({
32016                 x : x + (this.unitWidth + this.gutter) * 1,
32017                 y : y
32018             });
32019             
32020             return pos;
32021             
32022         }
32023         
32024         pos.push({
32025             x : x,
32026             y : y
32027         });
32028
32029         pos.push({
32030             x : x + (this.unitWidth + this.gutter) * 2,
32031             y : y
32032         });
32033
32034         pos.push({
32035             x : x + (this.unitWidth + this.gutter) * 2,
32036             y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
32037         });
32038             
32039         return pos;
32040         
32041     },
32042     
32043     getVerticalFourBoxColPositions : function(x, y, box)
32044     {
32045         var pos = [];
32046         
32047         if(box[0].size == 'xs'){
32048             
32049             pos.push({
32050                 x : x,
32051                 y : y
32052             });
32053
32054             pos.push({
32055                 x : x,
32056                 y : y + (this.unitHeight + this.gutter) * 1
32057             });
32058             
32059             pos.push({
32060                 x : x,
32061                 y : y + (this.unitHeight + this.gutter) * 2
32062             });
32063             
32064             pos.push({
32065                 x : x + (this.unitWidth + this.gutter) * 1,
32066                 y : y
32067             });
32068             
32069             return pos;
32070             
32071         }
32072         
32073         pos.push({
32074             x : x,
32075             y : y
32076         });
32077
32078         pos.push({
32079             x : x + (this.unitWidth + this.gutter) * 2,
32080             y : y
32081         });
32082
32083         pos.push({
32084             x : x + (this.unitHeightunitWidth + this.gutter) * 2,
32085             y : y + (this.unitHeight + this.gutter) * 1
32086         });
32087
32088         pos.push({
32089             x : x + (this.unitWidth + this.gutter) * 2,
32090             y : y + (this.unitWidth + this.gutter) * 2
32091         });
32092
32093         return pos;
32094         
32095     },
32096     
32097     getHorizontalOneBoxColPositions : function(maxX, minY, box)
32098     {
32099         var pos = [];
32100         
32101         if(box[0].size == 'md-left'){
32102             pos.push({
32103                 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
32104                 y : minY
32105             });
32106             
32107             return pos;
32108         }
32109         
32110         if(box[0].size == 'md-right'){
32111             pos.push({
32112                 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
32113                 y : minY + (this.unitWidth + this.gutter) * 1
32114             });
32115             
32116             return pos;
32117         }
32118         
32119         var rand = Math.floor(Math.random() * (4 - box[0].y));
32120         
32121         pos.push({
32122             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32123             y : minY + (this.unitWidth + this.gutter) * rand
32124         });
32125         
32126         return pos;
32127         
32128     },
32129     
32130     getHorizontalTwoBoxColPositions : function(maxX, minY, box)
32131     {
32132         var pos = [];
32133         
32134         if(box[0].size == 'xs'){
32135             
32136             pos.push({
32137                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32138                 y : minY
32139             });
32140
32141             pos.push({
32142                 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32143                 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
32144             });
32145             
32146             return pos;
32147             
32148         }
32149         
32150         pos.push({
32151             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32152             y : minY
32153         });
32154
32155         pos.push({
32156             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32157             y : minY + (this.unitWidth + this.gutter) * 2
32158         });
32159         
32160         return pos;
32161         
32162     },
32163     
32164     getHorizontalThreeBoxColPositions : function(maxX, minY, box)
32165     {
32166         var pos = [];
32167         
32168         if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
32169             
32170             pos.push({
32171                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32172                 y : minY
32173             });
32174
32175             pos.push({
32176                 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32177                 y : minY + (this.unitWidth + this.gutter) * 1
32178             });
32179             
32180             pos.push({
32181                 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
32182                 y : minY + (this.unitWidth + this.gutter) * 2
32183             });
32184             
32185             return pos;
32186             
32187         }
32188         
32189         if(box[0].size == 'xs' && box[1].size == 'xs'){
32190             
32191             pos.push({
32192                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32193                 y : minY
32194             });
32195
32196             pos.push({
32197                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32198                 y : minY
32199             });
32200             
32201             pos.push({
32202                 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
32203                 y : minY + (this.unitWidth + this.gutter) * 1
32204             });
32205             
32206             return pos;
32207             
32208         }
32209         
32210         pos.push({
32211             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32212             y : minY
32213         });
32214
32215         pos.push({
32216             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32217             y : minY + (this.unitWidth + this.gutter) * 2
32218         });
32219
32220         pos.push({
32221             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
32222             y : minY + (this.unitWidth + this.gutter) * 2
32223         });
32224             
32225         return pos;
32226         
32227     },
32228     
32229     getHorizontalFourBoxColPositions : function(maxX, minY, box)
32230     {
32231         var pos = [];
32232         
32233         if(box[0].size == 'xs'){
32234             
32235             pos.push({
32236                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32237                 y : minY
32238             });
32239
32240             pos.push({
32241                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32242                 y : minY
32243             });
32244             
32245             pos.push({
32246                 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),
32247                 y : minY
32248             });
32249             
32250             pos.push({
32251                 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
32252                 y : minY + (this.unitWidth + this.gutter) * 1
32253             });
32254             
32255             return pos;
32256             
32257         }
32258         
32259         pos.push({
32260             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32261             y : minY
32262         });
32263         
32264         pos.push({
32265             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32266             y : minY + (this.unitWidth + this.gutter) * 2
32267         });
32268         
32269         pos.push({
32270             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
32271             y : minY + (this.unitWidth + this.gutter) * 2
32272         });
32273         
32274         pos.push({
32275             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),
32276             y : minY + (this.unitWidth + this.gutter) * 2
32277         });
32278
32279         return pos;
32280         
32281     },
32282     
32283     /**
32284     * remove a Masonry Brick
32285     * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
32286     */
32287     removeBrick : function(brick_id)
32288     {
32289         if (!brick_id) {
32290             return;
32291         }
32292         
32293         for (var i = 0; i<this.bricks.length; i++) {
32294             if (this.bricks[i].id == brick_id) {
32295                 this.bricks.splice(i,1);
32296                 this.el.dom.removeChild(Roo.get(brick_id).dom);
32297                 this.initial();
32298             }
32299         }
32300     },
32301     
32302     /**
32303     * adds a Masonry Brick
32304     * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32305     */
32306     addBrick : function(cfg)
32307     {
32308         var cn = new Roo.bootstrap.MasonryBrick(cfg);
32309         //this.register(cn);
32310         cn.parentId = this.id;
32311         cn.render(this.el);
32312         return cn;
32313     },
32314     
32315     /**
32316     * register a Masonry Brick
32317     * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32318     */
32319     
32320     register : function(brick)
32321     {
32322         this.bricks.push(brick);
32323         brick.masonryId = this.id;
32324     },
32325     
32326     /**
32327     * clear all the Masonry Brick
32328     */
32329     clearAll : function()
32330     {
32331         this.bricks = [];
32332         //this.getChildContainer().dom.innerHTML = "";
32333         this.el.dom.innerHTML = '';
32334     },
32335     
32336     getSelected : function()
32337     {
32338         if (!this.selectedBrick) {
32339             return false;
32340         }
32341         
32342         return this.selectedBrick;
32343     }
32344 });
32345
32346 Roo.apply(Roo.bootstrap.LayoutMasonry, {
32347     
32348     groups: {},
32349      /**
32350     * register a Masonry Layout
32351     * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
32352     */
32353     
32354     register : function(layout)
32355     {
32356         this.groups[layout.id] = layout;
32357     },
32358     /**
32359     * fetch a  Masonry Layout based on the masonry layout ID
32360     * @param {string} the masonry layout to add
32361     * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
32362     */
32363     
32364     get: function(layout_id) {
32365         if (typeof(this.groups[layout_id]) == 'undefined') {
32366             return false;
32367         }
32368         return this.groups[layout_id] ;
32369     }
32370     
32371     
32372     
32373 });
32374
32375  
32376
32377  /**
32378  *
32379  * This is based on 
32380  * http://masonry.desandro.com
32381  *
32382  * The idea is to render all the bricks based on vertical width...
32383  *
32384  * The original code extends 'outlayer' - we might need to use that....
32385  * 
32386  */
32387
32388
32389 /**
32390  * @class Roo.bootstrap.LayoutMasonryAuto
32391  * @extends Roo.bootstrap.Component
32392  * Bootstrap Layout Masonry class
32393  * 
32394  * @constructor
32395  * Create a new Element
32396  * @param {Object} config The config object
32397  */
32398
32399 Roo.bootstrap.LayoutMasonryAuto = function(config){
32400     Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
32401 };
32402
32403 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component,  {
32404     
32405       /**
32406      * @cfg {Boolean} isFitWidth  - resize the width..
32407      */   
32408     isFitWidth : false,  // options..
32409     /**
32410      * @cfg {Boolean} isOriginLeft = left align?
32411      */   
32412     isOriginLeft : true,
32413     /**
32414      * @cfg {Boolean} isOriginTop = top align?
32415      */   
32416     isOriginTop : false,
32417     /**
32418      * @cfg {Boolean} isLayoutInstant = no animation?
32419      */   
32420     isLayoutInstant : false, // needed?
32421     /**
32422      * @cfg {Boolean} isResizingContainer = not sure if this is used..
32423      */   
32424     isResizingContainer : true,
32425     /**
32426      * @cfg {Number} columnWidth  width of the columns 
32427      */   
32428     
32429     columnWidth : 0,
32430     
32431     /**
32432      * @cfg {Number} maxCols maximum number of columns
32433      */   
32434     
32435     maxCols: 0,
32436     /**
32437      * @cfg {Number} padHeight padding below box..
32438      */   
32439     
32440     padHeight : 10, 
32441     
32442     /**
32443      * @cfg {Boolean} isAutoInitial defalut true
32444      */   
32445     
32446     isAutoInitial : true, 
32447     
32448     // private?
32449     gutter : 0,
32450     
32451     containerWidth: 0,
32452     initialColumnWidth : 0,
32453     currentSize : null,
32454     
32455     colYs : null, // array.
32456     maxY : 0,
32457     padWidth: 10,
32458     
32459     
32460     tag: 'div',
32461     cls: '',
32462     bricks: null, //CompositeElement
32463     cols : 0, // array?
32464     // element : null, // wrapped now this.el
32465     _isLayoutInited : null, 
32466     
32467     
32468     getAutoCreate : function(){
32469         
32470         var cfg = {
32471             tag: this.tag,
32472             cls: 'blog-masonary-wrapper ' + this.cls,
32473             cn : {
32474                 cls : 'mas-boxes masonary'
32475             }
32476         };
32477         
32478         return cfg;
32479     },
32480     
32481     getChildContainer: function( )
32482     {
32483         if (this.boxesEl) {
32484             return this.boxesEl;
32485         }
32486         
32487         this.boxesEl = this.el.select('.mas-boxes').first();
32488         
32489         return this.boxesEl;
32490     },
32491     
32492     
32493     initEvents : function()
32494     {
32495         var _this = this;
32496         
32497         if(this.isAutoInitial){
32498             Roo.log('hook children rendered');
32499             this.on('childrenrendered', function() {
32500                 Roo.log('children rendered');
32501                 _this.initial();
32502             } ,this);
32503         }
32504         
32505     },
32506     
32507     initial : function()
32508     {
32509         this.reloadItems();
32510
32511         this.currentSize = this.el.getBox(true);
32512
32513         /// was window resize... - let's see if this works..
32514         Roo.EventManager.onWindowResize(this.resize, this); 
32515
32516         if(!this.isAutoInitial){
32517             this.layout();
32518             return;
32519         }
32520         
32521         this.layout.defer(500,this);
32522     },
32523     
32524     reloadItems: function()
32525     {
32526         this.bricks = this.el.select('.masonry-brick', true);
32527         
32528         this.bricks.each(function(b) {
32529             //Roo.log(b.getSize());
32530             if (!b.attr('originalwidth')) {
32531                 b.attr('originalwidth',  b.getSize().width);
32532             }
32533             
32534         });
32535         
32536         Roo.log(this.bricks.elements.length);
32537     },
32538     
32539     resize : function()
32540     {
32541         Roo.log('resize');
32542         var cs = this.el.getBox(true);
32543         
32544         if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
32545             Roo.log("no change in with or X");
32546             return;
32547         }
32548         this.currentSize = cs;
32549         this.layout();
32550     },
32551     
32552     layout : function()
32553     {
32554          Roo.log('layout');
32555         this._resetLayout();
32556         //this._manageStamps();
32557       
32558         // don't animate first layout
32559         var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
32560         this.layoutItems( isInstant );
32561       
32562         // flag for initalized
32563         this._isLayoutInited = true;
32564     },
32565     
32566     layoutItems : function( isInstant )
32567     {
32568         //var items = this._getItemsForLayout( this.items );
32569         // original code supports filtering layout items.. we just ignore it..
32570         
32571         this._layoutItems( this.bricks , isInstant );
32572       
32573         this._postLayout();
32574     },
32575     _layoutItems : function ( items , isInstant)
32576     {
32577        //this.fireEvent( 'layout', this, items );
32578     
32579
32580         if ( !items || !items.elements.length ) {
32581           // no items, emit event with empty array
32582             return;
32583         }
32584
32585         var queue = [];
32586         items.each(function(item) {
32587             Roo.log("layout item");
32588             Roo.log(item);
32589             // get x/y object from method
32590             var position = this._getItemLayoutPosition( item );
32591             // enqueue
32592             position.item = item;
32593             position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
32594             queue.push( position );
32595         }, this);
32596       
32597         this._processLayoutQueue( queue );
32598     },
32599     /** Sets position of item in DOM
32600     * @param {Element} item
32601     * @param {Number} x - horizontal position
32602     * @param {Number} y - vertical position
32603     * @param {Boolean} isInstant - disables transitions
32604     */
32605     _processLayoutQueue : function( queue )
32606     {
32607         for ( var i=0, len = queue.length; i < len; i++ ) {
32608             var obj = queue[i];
32609             obj.item.position('absolute');
32610             obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
32611         }
32612     },
32613       
32614     
32615     /**
32616     * Any logic you want to do after each layout,
32617     * i.e. size the container
32618     */
32619     _postLayout : function()
32620     {
32621         this.resizeContainer();
32622     },
32623     
32624     resizeContainer : function()
32625     {
32626         if ( !this.isResizingContainer ) {
32627             return;
32628         }
32629         var size = this._getContainerSize();
32630         if ( size ) {
32631             this.el.setSize(size.width,size.height);
32632             this.boxesEl.setSize(size.width,size.height);
32633         }
32634     },
32635     
32636     
32637     
32638     _resetLayout : function()
32639     {
32640         //this.getSize();  // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
32641         this.colWidth = this.el.getWidth();
32642         //this.gutter = this.el.getWidth(); 
32643         
32644         this.measureColumns();
32645
32646         // reset column Y
32647         var i = this.cols;
32648         this.colYs = [];
32649         while (i--) {
32650             this.colYs.push( 0 );
32651         }
32652     
32653         this.maxY = 0;
32654     },
32655
32656     measureColumns : function()
32657     {
32658         this.getContainerWidth();
32659       // if columnWidth is 0, default to outerWidth of first item
32660         if ( !this.columnWidth ) {
32661             var firstItem = this.bricks.first();
32662             Roo.log(firstItem);
32663             this.columnWidth  = this.containerWidth;
32664             if (firstItem && firstItem.attr('originalwidth') ) {
32665                 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
32666             }
32667             // columnWidth fall back to item of first element
32668             Roo.log("set column width?");
32669                         this.initialColumnWidth = this.columnWidth  ;
32670
32671             // if first elem has no width, default to size of container
32672             
32673         }
32674         
32675         
32676         if (this.initialColumnWidth) {
32677             this.columnWidth = this.initialColumnWidth;
32678         }
32679         
32680         
32681             
32682         // column width is fixed at the top - however if container width get's smaller we should
32683         // reduce it...
32684         
32685         // this bit calcs how man columns..
32686             
32687         var columnWidth = this.columnWidth += this.gutter;
32688       
32689         // calculate columns
32690         var containerWidth = this.containerWidth + this.gutter;
32691         
32692         var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
32693         // fix rounding errors, typically with gutters
32694         var excess = columnWidth - containerWidth % columnWidth;
32695         
32696         
32697         // if overshoot is less than a pixel, round up, otherwise floor it
32698         var mathMethod = excess && excess < 1 ? 'round' : 'floor';
32699         cols = Math[ mathMethod ]( cols );
32700         this.cols = Math.max( cols, 1 );
32701         this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
32702         
32703          // padding positioning..
32704         var totalColWidth = this.cols * this.columnWidth;
32705         var padavail = this.containerWidth - totalColWidth;
32706         // so for 2 columns - we need 3 'pads'
32707         
32708         var padNeeded = (1+this.cols) * this.padWidth;
32709         
32710         var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32711         
32712         this.columnWidth += padExtra
32713         //this.padWidth = Math.floor(padavail /  ( this.cols));
32714         
32715         // adjust colum width so that padding is fixed??
32716         
32717         // we have 3 columns ... total = width * 3
32718         // we have X left over... that should be used by 
32719         
32720         //if (this.expandC) {
32721             
32722         //}
32723         
32724         
32725         
32726     },
32727     
32728     getContainerWidth : function()
32729     {
32730        /* // container is parent if fit width
32731         var container = this.isFitWidth ? this.element.parentNode : this.element;
32732         // check that this.size and size are there
32733         // IE8 triggers resize on body size change, so they might not be
32734         
32735         var size = getSize( container );  //FIXME
32736         this.containerWidth = size && size.innerWidth; //FIXME
32737         */
32738          
32739         this.containerWidth = this.el.getBox(true).width;  //maybe use getComputedWidth
32740         
32741     },
32742     
32743     _getItemLayoutPosition : function( item )  // what is item?
32744     {
32745         // we resize the item to our columnWidth..
32746       
32747         item.setWidth(this.columnWidth);
32748         item.autoBoxAdjust  = false;
32749         
32750         var sz = item.getSize();
32751  
32752         // how many columns does this brick span
32753         var remainder = this.containerWidth % this.columnWidth;
32754         
32755         var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32756         // round if off by 1 pixel, otherwise use ceil
32757         var colSpan = Math[ mathMethod ]( sz.width  / this.columnWidth );
32758         colSpan = Math.min( colSpan, this.cols );
32759         
32760         // normally this should be '1' as we dont' currently allow multi width columns..
32761         
32762         var colGroup = this._getColGroup( colSpan );
32763         // get the minimum Y value from the columns
32764         var minimumY = Math.min.apply( Math, colGroup );
32765         Roo.log([ 'setHeight',  minimumY, sz.height, setHeight ]);
32766         
32767         var shortColIndex = colGroup.indexOf(  minimumY ); // broken on ie8..?? probably...
32768          
32769         // position the brick
32770         var position = {
32771             x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32772             y: this.currentSize.y + minimumY + this.padHeight
32773         };
32774         
32775         Roo.log(position);
32776         // apply setHeight to necessary columns
32777         var setHeight = minimumY + sz.height + this.padHeight;
32778         //Roo.log([ 'setHeight',  minimumY, sz.height, setHeight ]);
32779         
32780         var setSpan = this.cols + 1 - colGroup.length;
32781         for ( var i = 0; i < setSpan; i++ ) {
32782           this.colYs[ shortColIndex + i ] = setHeight ;
32783         }
32784       
32785         return position;
32786     },
32787     
32788     /**
32789      * @param {Number} colSpan - number of columns the element spans
32790      * @returns {Array} colGroup
32791      */
32792     _getColGroup : function( colSpan )
32793     {
32794         if ( colSpan < 2 ) {
32795           // if brick spans only one column, use all the column Ys
32796           return this.colYs;
32797         }
32798       
32799         var colGroup = [];
32800         // how many different places could this brick fit horizontally
32801         var groupCount = this.cols + 1 - colSpan;
32802         // for each group potential horizontal position
32803         for ( var i = 0; i < groupCount; i++ ) {
32804           // make an array of colY values for that one group
32805           var groupColYs = this.colYs.slice( i, i + colSpan );
32806           // and get the max value of the array
32807           colGroup[i] = Math.max.apply( Math, groupColYs );
32808         }
32809         return colGroup;
32810     },
32811     /*
32812     _manageStamp : function( stamp )
32813     {
32814         var stampSize =  stamp.getSize();
32815         var offset = stamp.getBox();
32816         // get the columns that this stamp affects
32817         var firstX = this.isOriginLeft ? offset.x : offset.right;
32818         var lastX = firstX + stampSize.width;
32819         var firstCol = Math.floor( firstX / this.columnWidth );
32820         firstCol = Math.max( 0, firstCol );
32821         
32822         var lastCol = Math.floor( lastX / this.columnWidth );
32823         // lastCol should not go over if multiple of columnWidth #425
32824         lastCol -= lastX % this.columnWidth ? 0 : 1;
32825         lastCol = Math.min( this.cols - 1, lastCol );
32826         
32827         // set colYs to bottom of the stamp
32828         var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32829             stampSize.height;
32830             
32831         for ( var i = firstCol; i <= lastCol; i++ ) {
32832           this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32833         }
32834     },
32835     */
32836     
32837     _getContainerSize : function()
32838     {
32839         this.maxY = Math.max.apply( Math, this.colYs );
32840         var size = {
32841             height: this.maxY
32842         };
32843       
32844         if ( this.isFitWidth ) {
32845             size.width = this._getContainerFitWidth();
32846         }
32847       
32848         return size;
32849     },
32850     
32851     _getContainerFitWidth : function()
32852     {
32853         var unusedCols = 0;
32854         // count unused columns
32855         var i = this.cols;
32856         while ( --i ) {
32857           if ( this.colYs[i] !== 0 ) {
32858             break;
32859           }
32860           unusedCols++;
32861         }
32862         // fit container to columns that have been used
32863         return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32864     },
32865     
32866     needsResizeLayout : function()
32867     {
32868         var previousWidth = this.containerWidth;
32869         this.getContainerWidth();
32870         return previousWidth !== this.containerWidth;
32871     }
32872  
32873 });
32874
32875  
32876
32877  /*
32878  * - LGPL
32879  *
32880  * element
32881  * 
32882  */
32883
32884 /**
32885  * @class Roo.bootstrap.MasonryBrick
32886  * @extends Roo.bootstrap.Component
32887  * Bootstrap MasonryBrick class
32888  * 
32889  * @constructor
32890  * Create a new MasonryBrick
32891  * @param {Object} config The config object
32892  */
32893
32894 Roo.bootstrap.MasonryBrick = function(config){
32895     
32896     Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32897     
32898     Roo.bootstrap.MasonryBrick.register(this);
32899     
32900     this.addEvents({
32901         // raw events
32902         /**
32903          * @event click
32904          * When a MasonryBrick is clcik
32905          * @param {Roo.bootstrap.MasonryBrick} this
32906          * @param {Roo.EventObject} e
32907          */
32908         "click" : true
32909     });
32910 };
32911
32912 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component,  {
32913     
32914     /**
32915      * @cfg {String} title
32916      */   
32917     title : '',
32918     /**
32919      * @cfg {String} html
32920      */   
32921     html : '',
32922     /**
32923      * @cfg {String} bgimage
32924      */   
32925     bgimage : '',
32926     /**
32927      * @cfg {String} videourl
32928      */   
32929     videourl : '',
32930     /**
32931      * @cfg {String} cls
32932      */   
32933     cls : '',
32934     /**
32935      * @cfg {String} href
32936      */   
32937     href : '',
32938     /**
32939      * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32940      */   
32941     size : 'xs',
32942     
32943     /**
32944      * @cfg {String} placetitle (center|bottom)
32945      */   
32946     placetitle : '',
32947     
32948     /**
32949      * @cfg {Boolean} isFitContainer defalut true
32950      */   
32951     isFitContainer : true, 
32952     
32953     /**
32954      * @cfg {Boolean} preventDefault defalut false
32955      */   
32956     preventDefault : false, 
32957     
32958     /**
32959      * @cfg {Boolean} inverse defalut false
32960      */   
32961     maskInverse : false, 
32962     
32963     getAutoCreate : function()
32964     {
32965         if(!this.isFitContainer){
32966             return this.getSplitAutoCreate();
32967         }
32968         
32969         var cls = 'masonry-brick masonry-brick-full';
32970         
32971         if(this.href.length){
32972             cls += ' masonry-brick-link';
32973         }
32974         
32975         if(this.bgimage.length){
32976             cls += ' masonry-brick-image';
32977         }
32978         
32979         if(this.maskInverse){
32980             cls += ' mask-inverse';
32981         }
32982         
32983         if(!this.html.length && !this.maskInverse && !this.videourl.length){
32984             cls += ' enable-mask';
32985         }
32986         
32987         if(this.size){
32988             cls += ' masonry-' + this.size + '-brick';
32989         }
32990         
32991         if(this.placetitle.length){
32992             
32993             switch (this.placetitle) {
32994                 case 'center' :
32995                     cls += ' masonry-center-title';
32996                     break;
32997                 case 'bottom' :
32998                     cls += ' masonry-bottom-title';
32999                     break;
33000                 default:
33001                     break;
33002             }
33003             
33004         } else {
33005             if(!this.html.length && !this.bgimage.length){
33006                 cls += ' masonry-center-title';
33007             }
33008
33009             if(!this.html.length && this.bgimage.length){
33010                 cls += ' masonry-bottom-title';
33011             }
33012         }
33013         
33014         if(this.cls){
33015             cls += ' ' + this.cls;
33016         }
33017         
33018         var cfg = {
33019             tag: (this.href.length) ? 'a' : 'div',
33020             cls: cls,
33021             cn: [
33022                 {
33023                     tag: 'div',
33024                     cls: 'masonry-brick-mask'
33025                 },
33026                 {
33027                     tag: 'div',
33028                     cls: 'masonry-brick-paragraph',
33029                     cn: []
33030                 }
33031             ]
33032         };
33033         
33034         if(this.href.length){
33035             cfg.href = this.href;
33036         }
33037         
33038         var cn = cfg.cn[1].cn;
33039         
33040         if(this.title.length){
33041             cn.push({
33042                 tag: 'h4',
33043                 cls: 'masonry-brick-title',
33044                 html: this.title
33045             });
33046         }
33047         
33048         if(this.html.length){
33049             cn.push({
33050                 tag: 'p',
33051                 cls: 'masonry-brick-text',
33052                 html: this.html
33053             });
33054         }
33055         
33056         if (!this.title.length && !this.html.length) {
33057             cfg.cn[1].cls += ' hide';
33058         }
33059         
33060         if(this.bgimage.length){
33061             cfg.cn.push({
33062                 tag: 'img',
33063                 cls: 'masonry-brick-image-view',
33064                 src: this.bgimage
33065             });
33066         }
33067         
33068         if(this.videourl.length){
33069             var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
33070             // youtube support only?
33071             cfg.cn.push({
33072                 tag: 'iframe',
33073                 cls: 'masonry-brick-image-view',
33074                 src: vurl,
33075                 frameborder : 0,
33076                 allowfullscreen : true
33077             });
33078         }
33079         
33080         return cfg;
33081         
33082     },
33083     
33084     getSplitAutoCreate : function()
33085     {
33086         var cls = 'masonry-brick masonry-brick-split';
33087         
33088         if(this.href.length){
33089             cls += ' masonry-brick-link';
33090         }
33091         
33092         if(this.bgimage.length){
33093             cls += ' masonry-brick-image';
33094         }
33095         
33096         if(this.size){
33097             cls += ' masonry-' + this.size + '-brick';
33098         }
33099         
33100         switch (this.placetitle) {
33101             case 'center' :
33102                 cls += ' masonry-center-title';
33103                 break;
33104             case 'bottom' :
33105                 cls += ' masonry-bottom-title';
33106                 break;
33107             default:
33108                 if(!this.bgimage.length){
33109                     cls += ' masonry-center-title';
33110                 }
33111
33112                 if(this.bgimage.length){
33113                     cls += ' masonry-bottom-title';
33114                 }
33115                 break;
33116         }
33117         
33118         if(this.cls){
33119             cls += ' ' + this.cls;
33120         }
33121         
33122         var cfg = {
33123             tag: (this.href.length) ? 'a' : 'div',
33124             cls: cls,
33125             cn: [
33126                 {
33127                     tag: 'div',
33128                     cls: 'masonry-brick-split-head',
33129                     cn: [
33130                         {
33131                             tag: 'div',
33132                             cls: 'masonry-brick-paragraph',
33133                             cn: []
33134                         }
33135                     ]
33136                 },
33137                 {
33138                     tag: 'div',
33139                     cls: 'masonry-brick-split-body',
33140                     cn: []
33141                 }
33142             ]
33143         };
33144         
33145         if(this.href.length){
33146             cfg.href = this.href;
33147         }
33148         
33149         if(this.title.length){
33150             cfg.cn[0].cn[0].cn.push({
33151                 tag: 'h4',
33152                 cls: 'masonry-brick-title',
33153                 html: this.title
33154             });
33155         }
33156         
33157         if(this.html.length){
33158             cfg.cn[1].cn.push({
33159                 tag: 'p',
33160                 cls: 'masonry-brick-text',
33161                 html: this.html
33162             });
33163         }
33164
33165         if(this.bgimage.length){
33166             cfg.cn[0].cn.push({
33167                 tag: 'img',
33168                 cls: 'masonry-brick-image-view',
33169                 src: this.bgimage
33170             });
33171         }
33172         
33173         if(this.videourl.length){
33174             var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
33175             // youtube support only?
33176             cfg.cn[0].cn.cn.push({
33177                 tag: 'iframe',
33178                 cls: 'masonry-brick-image-view',
33179                 src: vurl,
33180                 frameborder : 0,
33181                 allowfullscreen : true
33182             });
33183         }
33184         
33185         return cfg;
33186     },
33187     
33188     initEvents: function() 
33189     {
33190         switch (this.size) {
33191             case 'xs' :
33192                 this.x = 1;
33193                 this.y = 1;
33194                 break;
33195             case 'sm' :
33196                 this.x = 2;
33197                 this.y = 2;
33198                 break;
33199             case 'md' :
33200             case 'md-left' :
33201             case 'md-right' :
33202                 this.x = 3;
33203                 this.y = 3;
33204                 break;
33205             case 'tall' :
33206                 this.x = 2;
33207                 this.y = 3;
33208                 break;
33209             case 'wide' :
33210                 this.x = 3;
33211                 this.y = 2;
33212                 break;
33213             case 'wide-thin' :
33214                 this.x = 3;
33215                 this.y = 1;
33216                 break;
33217                         
33218             default :
33219                 break;
33220         }
33221         
33222         if(Roo.isTouch){
33223             this.el.on('touchstart', this.onTouchStart, this);
33224             this.el.on('touchmove', this.onTouchMove, this);
33225             this.el.on('touchend', this.onTouchEnd, this);
33226             this.el.on('contextmenu', this.onContextMenu, this);
33227         } else {
33228             this.el.on('mouseenter'  ,this.enter, this);
33229             this.el.on('mouseleave', this.leave, this);
33230             this.el.on('click', this.onClick, this);
33231         }
33232         
33233         if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
33234             this.parent().bricks.push(this);   
33235         }
33236         
33237     },
33238     
33239     onClick: function(e, el)
33240     {
33241         var time = this.endTimer - this.startTimer;
33242         // Roo.log(e.preventDefault());
33243         if(Roo.isTouch){
33244             if(time > 1000){
33245                 e.preventDefault();
33246                 return;
33247             }
33248         }
33249         
33250         if(!this.preventDefault){
33251             return;
33252         }
33253         
33254         e.preventDefault();
33255         
33256         if (this.activeClass != '') {
33257             this.selectBrick();
33258         }
33259         
33260         this.fireEvent('click', this, e);
33261     },
33262     
33263     enter: function(e, el)
33264     {
33265         e.preventDefault();
33266         
33267         if(!this.isFitContainer || this.maskInverse || this.videourl.length){
33268             return;
33269         }
33270         
33271         if(this.bgimage.length && this.html.length){
33272             this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
33273         }
33274     },
33275     
33276     leave: function(e, el)
33277     {
33278         e.preventDefault();
33279         
33280         if(!this.isFitContainer || this.maskInverse  || this.videourl.length){
33281             return;
33282         }
33283         
33284         if(this.bgimage.length && this.html.length){
33285             this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33286         }
33287     },
33288     
33289     onTouchStart: function(e, el)
33290     {
33291 //        e.preventDefault();
33292         
33293         this.touchmoved = false;
33294         
33295         if(!this.isFitContainer){
33296             return;
33297         }
33298         
33299         if(!this.bgimage.length || !this.html.length){
33300             return;
33301         }
33302         
33303         this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
33304         
33305         this.timer = new Date().getTime();
33306         
33307     },
33308     
33309     onTouchMove: function(e, el)
33310     {
33311         this.touchmoved = true;
33312     },
33313     
33314     onContextMenu : function(e,el)
33315     {
33316         e.preventDefault();
33317         e.stopPropagation();
33318         return false;
33319     },
33320     
33321     onTouchEnd: function(e, el)
33322     {
33323 //        e.preventDefault();
33324         
33325         if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
33326         
33327             this.leave(e,el);
33328             
33329             return;
33330         }
33331         
33332         if(!this.bgimage.length || !this.html.length){
33333             
33334             if(this.href.length){
33335                 window.location.href = this.href;
33336             }
33337             
33338             return;
33339         }
33340         
33341         if(!this.isFitContainer){
33342             return;
33343         }
33344         
33345         this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33346         
33347         window.location.href = this.href;
33348     },
33349     
33350     //selection on single brick only
33351     selectBrick : function() {
33352         
33353         if (!this.parentId) {
33354             return;
33355         }
33356         
33357         var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
33358         var index = m.selectedBrick.indexOf(this.id);
33359         
33360         if ( index > -1) {
33361             m.selectedBrick.splice(index,1);
33362             this.el.removeClass(this.activeClass);
33363             return;
33364         }
33365         
33366         for(var i = 0; i < m.selectedBrick.length; i++) {
33367             var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
33368             b.el.removeClass(b.activeClass);
33369         }
33370         
33371         m.selectedBrick = [];
33372         
33373         m.selectedBrick.push(this.id);
33374         this.el.addClass(this.activeClass);
33375         return;
33376     },
33377     
33378     isSelected : function(){
33379         return this.el.hasClass(this.activeClass);
33380         
33381     }
33382 });
33383
33384 Roo.apply(Roo.bootstrap.MasonryBrick, {
33385     
33386     //groups: {},
33387     groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
33388      /**
33389     * register a Masonry Brick
33390     * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
33391     */
33392     
33393     register : function(brick)
33394     {
33395         //this.groups[brick.id] = brick;
33396         this.groups.add(brick.id, brick);
33397     },
33398     /**
33399     * fetch a  masonry brick based on the masonry brick ID
33400     * @param {string} the masonry brick to add
33401     * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
33402     */
33403     
33404     get: function(brick_id) 
33405     {
33406         // if (typeof(this.groups[brick_id]) == 'undefined') {
33407         //     return false;
33408         // }
33409         // return this.groups[brick_id] ;
33410         
33411         if(this.groups.key(brick_id)) {
33412             return this.groups.key(brick_id);
33413         }
33414         
33415         return false;
33416     }
33417     
33418     
33419     
33420 });
33421
33422  /*
33423  * - LGPL
33424  *
33425  * element
33426  * 
33427  */
33428
33429 /**
33430  * @class Roo.bootstrap.Brick
33431  * @extends Roo.bootstrap.Component
33432  * Bootstrap Brick class
33433  * 
33434  * @constructor
33435  * Create a new Brick
33436  * @param {Object} config The config object
33437  */
33438
33439 Roo.bootstrap.Brick = function(config){
33440     Roo.bootstrap.Brick.superclass.constructor.call(this, config);
33441     
33442     this.addEvents({
33443         // raw events
33444         /**
33445          * @event click
33446          * When a Brick is click
33447          * @param {Roo.bootstrap.Brick} this
33448          * @param {Roo.EventObject} e
33449          */
33450         "click" : true
33451     });
33452 };
33453
33454 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component,  {
33455     
33456     /**
33457      * @cfg {String} title
33458      */   
33459     title : '',
33460     /**
33461      * @cfg {String} html
33462      */   
33463     html : '',
33464     /**
33465      * @cfg {String} bgimage
33466      */   
33467     bgimage : '',
33468     /**
33469      * @cfg {String} cls
33470      */   
33471     cls : '',
33472     /**
33473      * @cfg {String} href
33474      */   
33475     href : '',
33476     /**
33477      * @cfg {String} video
33478      */   
33479     video : '',
33480     /**
33481      * @cfg {Boolean} square
33482      */   
33483     square : true,
33484     
33485     getAutoCreate : function()
33486     {
33487         var cls = 'roo-brick';
33488         
33489         if(this.href.length){
33490             cls += ' roo-brick-link';
33491         }
33492         
33493         if(this.bgimage.length){
33494             cls += ' roo-brick-image';
33495         }
33496         
33497         if(!this.html.length && !this.bgimage.length){
33498             cls += ' roo-brick-center-title';
33499         }
33500         
33501         if(!this.html.length && this.bgimage.length){
33502             cls += ' roo-brick-bottom-title';
33503         }
33504         
33505         if(this.cls){
33506             cls += ' ' + this.cls;
33507         }
33508         
33509         var cfg = {
33510             tag: (this.href.length) ? 'a' : 'div',
33511             cls: cls,
33512             cn: [
33513                 {
33514                     tag: 'div',
33515                     cls: 'roo-brick-paragraph',
33516                     cn: []
33517                 }
33518             ]
33519         };
33520         
33521         if(this.href.length){
33522             cfg.href = this.href;
33523         }
33524         
33525         var cn = cfg.cn[0].cn;
33526         
33527         if(this.title.length){
33528             cn.push({
33529                 tag: 'h4',
33530                 cls: 'roo-brick-title',
33531                 html: this.title
33532             });
33533         }
33534         
33535         if(this.html.length){
33536             cn.push({
33537                 tag: 'p',
33538                 cls: 'roo-brick-text',
33539                 html: this.html
33540             });
33541         } else {
33542             cn.cls += ' hide';
33543         }
33544         
33545         if(this.bgimage.length){
33546             cfg.cn.push({
33547                 tag: 'img',
33548                 cls: 'roo-brick-image-view',
33549                 src: this.bgimage
33550             });
33551         }
33552         
33553         return cfg;
33554     },
33555     
33556     initEvents: function() 
33557     {
33558         if(this.title.length || this.html.length){
33559             this.el.on('mouseenter'  ,this.enter, this);
33560             this.el.on('mouseleave', this.leave, this);
33561         }
33562         
33563         Roo.EventManager.onWindowResize(this.resize, this); 
33564         
33565         if(this.bgimage.length){
33566             this.imageEl = this.el.select('.roo-brick-image-view', true).first();
33567             this.imageEl.on('load', this.onImageLoad, this);
33568             return;
33569         }
33570         
33571         this.resize();
33572     },
33573     
33574     onImageLoad : function()
33575     {
33576         this.resize();
33577     },
33578     
33579     resize : function()
33580     {
33581         var paragraph = this.el.select('.roo-brick-paragraph', true).first();
33582         
33583         paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
33584         
33585         if(this.bgimage.length){
33586             var image = this.el.select('.roo-brick-image-view', true).first();
33587             
33588             image.setWidth(paragraph.getWidth());
33589             
33590             if(this.square){
33591                 image.setHeight(paragraph.getWidth());
33592             }
33593             
33594             this.el.setHeight(image.getHeight());
33595             paragraph.setHeight(image.getHeight());
33596             
33597         }
33598         
33599     },
33600     
33601     enter: function(e, el)
33602     {
33603         e.preventDefault();
33604         
33605         if(this.bgimage.length){
33606             this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
33607             this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
33608         }
33609     },
33610     
33611     leave: function(e, el)
33612     {
33613         e.preventDefault();
33614         
33615         if(this.bgimage.length){
33616             this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
33617             this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
33618         }
33619     }
33620     
33621 });
33622
33623  
33624
33625  /*
33626  * - LGPL
33627  *
33628  * Number field 
33629  */
33630
33631 /**
33632  * @class Roo.bootstrap.NumberField
33633  * @extends Roo.bootstrap.Input
33634  * Bootstrap NumberField class
33635  * 
33636  * 
33637  * 
33638  * 
33639  * @constructor
33640  * Create a new NumberField
33641  * @param {Object} config The config object
33642  */
33643
33644 Roo.bootstrap.NumberField = function(config){
33645     Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
33646 };
33647
33648 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
33649     
33650     /**
33651      * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
33652      */
33653     allowDecimals : true,
33654     /**
33655      * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
33656      */
33657     decimalSeparator : ".",
33658     /**
33659      * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
33660      */
33661     decimalPrecision : 2,
33662     /**
33663      * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
33664      */
33665     allowNegative : true,
33666     
33667     /**
33668      * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
33669      */
33670     allowZero: true,
33671     /**
33672      * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
33673      */
33674     minValue : Number.NEGATIVE_INFINITY,
33675     /**
33676      * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
33677      */
33678     maxValue : Number.MAX_VALUE,
33679     /**
33680      * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
33681      */
33682     minText : "The minimum value for this field is {0}",
33683     /**
33684      * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
33685      */
33686     maxText : "The maximum value for this field is {0}",
33687     /**
33688      * @cfg {String} nanText Error text to display if the value is not a valid number.  For example, this can happen
33689      * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
33690      */
33691     nanText : "{0} is not a valid number",
33692     /**
33693      * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
33694      */
33695     thousandsDelimiter : false,
33696     /**
33697      * @cfg {String} valueAlign alignment of value
33698      */
33699     valueAlign : "left",
33700
33701     getAutoCreate : function()
33702     {
33703         var hiddenInput = {
33704             tag: 'input',
33705             type: 'hidden',
33706             id: Roo.id(),
33707             cls: 'hidden-number-input'
33708         };
33709         
33710         if (this.name) {
33711             hiddenInput.name = this.name;
33712         }
33713         
33714         this.name = '';
33715         
33716         var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
33717         
33718         this.name = hiddenInput.name;
33719         
33720         if(cfg.cn.length > 0) {
33721             cfg.cn.push(hiddenInput);
33722         }
33723         
33724         return cfg;
33725     },
33726
33727     // private
33728     initEvents : function()
33729     {   
33730         Roo.bootstrap.NumberField.superclass.initEvents.call(this);
33731         
33732         var allowed = "0123456789";
33733         
33734         if(this.allowDecimals){
33735             allowed += this.decimalSeparator;
33736         }
33737         
33738         if(this.allowNegative){
33739             allowed += "-";
33740         }
33741         
33742         if(this.thousandsDelimiter) {
33743             allowed += ",";
33744         }
33745         
33746         this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33747         
33748         var keyPress = function(e){
33749             
33750             var k = e.getKey();
33751             
33752             var c = e.getCharCode();
33753             
33754             if(
33755                     (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33756                     allowed.indexOf(String.fromCharCode(c)) === -1
33757             ){
33758                 e.stopEvent();
33759                 return;
33760             }
33761             
33762             if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33763                 return;
33764             }
33765             
33766             if(allowed.indexOf(String.fromCharCode(c)) === -1){
33767                 e.stopEvent();
33768             }
33769         };
33770         
33771         this.el.on("keypress", keyPress, this);
33772     },
33773     
33774     validateValue : function(value)
33775     {
33776         
33777         if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33778             return false;
33779         }
33780         
33781         var num = this.parseValue(value);
33782         
33783         if(isNaN(num)){
33784             this.markInvalid(String.format(this.nanText, value));
33785             return false;
33786         }
33787         
33788         if(num < this.minValue){
33789             this.markInvalid(String.format(this.minText, this.minValue));
33790             return false;
33791         }
33792         
33793         if(num > this.maxValue){
33794             this.markInvalid(String.format(this.maxText, this.maxValue));
33795             return false;
33796         }
33797         
33798         return true;
33799     },
33800
33801     getValue : function()
33802     {
33803         var v = this.hiddenEl().getValue();
33804         
33805         return this.fixPrecision(this.parseValue(v));
33806     },
33807
33808     parseValue : function(value)
33809     {
33810         if(this.thousandsDelimiter) {
33811             value += "";
33812             r = new RegExp(",", "g");
33813             value = value.replace(r, "");
33814         }
33815         
33816         value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33817         return isNaN(value) ? '' : value;
33818     },
33819
33820     fixPrecision : function(value)
33821     {
33822         if(this.thousandsDelimiter) {
33823             value += "";
33824             r = new RegExp(",", "g");
33825             value = value.replace(r, "");
33826         }
33827         
33828         var nan = isNaN(value);
33829         
33830         if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33831             return nan ? '' : value;
33832         }
33833         return parseFloat(value).toFixed(this.decimalPrecision);
33834     },
33835
33836     setValue : function(v)
33837     {
33838         v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
33839         
33840         this.value = v;
33841         
33842         if(this.rendered){
33843             
33844             this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
33845             
33846             this.inputEl().dom.value = (v == '') ? '' :
33847                 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
33848             
33849             if(!this.allowZero && v === '0') {
33850                 this.hiddenEl().dom.value = '';
33851                 this.inputEl().dom.value = '';
33852             }
33853             
33854             this.validate();
33855         }
33856     },
33857
33858     decimalPrecisionFcn : function(v)
33859     {
33860         return Math.floor(v);
33861     },
33862
33863     beforeBlur : function()
33864     {
33865         var v = this.parseValue(this.getRawValue());
33866         
33867         if(v || v === 0 || v === ''){
33868             this.setValue(v);
33869         }
33870     },
33871     
33872     hiddenEl : function()
33873     {
33874         return this.el.select('input.hidden-number-input',true).first();
33875     }
33876     
33877 });
33878
33879  
33880
33881 /*
33882 * Licence: LGPL
33883 */
33884
33885 /**
33886  * @class Roo.bootstrap.DocumentSlider
33887  * @extends Roo.bootstrap.Component
33888  * Bootstrap DocumentSlider class
33889  * 
33890  * @constructor
33891  * Create a new DocumentViewer
33892  * @param {Object} config The config object
33893  */
33894
33895 Roo.bootstrap.DocumentSlider = function(config){
33896     Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33897     
33898     this.files = [];
33899     
33900     this.addEvents({
33901         /**
33902          * @event initial
33903          * Fire after initEvent
33904          * @param {Roo.bootstrap.DocumentSlider} this
33905          */
33906         "initial" : true,
33907         /**
33908          * @event update
33909          * Fire after update
33910          * @param {Roo.bootstrap.DocumentSlider} this
33911          */
33912         "update" : true,
33913         /**
33914          * @event click
33915          * Fire after click
33916          * @param {Roo.bootstrap.DocumentSlider} this
33917          */
33918         "click" : true
33919     });
33920 };
33921
33922 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component,  {
33923     
33924     files : false,
33925     
33926     indicator : 0,
33927     
33928     getAutoCreate : function()
33929     {
33930         var cfg = {
33931             tag : 'div',
33932             cls : 'roo-document-slider',
33933             cn : [
33934                 {
33935                     tag : 'div',
33936                     cls : 'roo-document-slider-header',
33937                     cn : [
33938                         {
33939                             tag : 'div',
33940                             cls : 'roo-document-slider-header-title'
33941                         }
33942                     ]
33943                 },
33944                 {
33945                     tag : 'div',
33946                     cls : 'roo-document-slider-body',
33947                     cn : [
33948                         {
33949                             tag : 'div',
33950                             cls : 'roo-document-slider-prev',
33951                             cn : [
33952                                 {
33953                                     tag : 'i',
33954                                     cls : 'fa fa-chevron-left'
33955                                 }
33956                             ]
33957                         },
33958                         {
33959                             tag : 'div',
33960                             cls : 'roo-document-slider-thumb',
33961                             cn : [
33962                                 {
33963                                     tag : 'img',
33964                                     cls : 'roo-document-slider-image'
33965                                 }
33966                             ]
33967                         },
33968                         {
33969                             tag : 'div',
33970                             cls : 'roo-document-slider-next',
33971                             cn : [
33972                                 {
33973                                     tag : 'i',
33974                                     cls : 'fa fa-chevron-right'
33975                                 }
33976                             ]
33977                         }
33978                     ]
33979                 }
33980             ]
33981         };
33982         
33983         return cfg;
33984     },
33985     
33986     initEvents : function()
33987     {
33988         this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33989         this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33990         
33991         this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33992         this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33993         
33994         this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33995         this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33996         
33997         this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33998         this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33999         
34000         this.imageEl = this.el.select('.roo-document-slider-image', true).first();
34001         this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
34002         
34003         this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
34004         this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
34005         
34006         this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
34007         this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
34008         
34009         this.thumbEl.on('click', this.onClick, this);
34010         
34011         this.prevIndicator.on('click', this.prev, this);
34012         
34013         this.nextIndicator.on('click', this.next, this);
34014         
34015     },
34016     
34017     initial : function()
34018     {
34019         if(this.files.length){
34020             this.indicator = 1;
34021             this.update()
34022         }
34023         
34024         this.fireEvent('initial', this);
34025     },
34026     
34027     update : function()
34028     {
34029         this.imageEl.attr('src', this.files[this.indicator - 1]);
34030         
34031         this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
34032         
34033         this.prevIndicator.show();
34034         
34035         if(this.indicator == 1){
34036             this.prevIndicator.hide();
34037         }
34038         
34039         this.nextIndicator.show();
34040         
34041         if(this.indicator == this.files.length){
34042             this.nextIndicator.hide();
34043         }
34044         
34045         this.thumbEl.scrollTo('top');
34046         
34047         this.fireEvent('update', this);
34048     },
34049     
34050     onClick : function(e)
34051     {
34052         e.preventDefault();
34053         
34054         this.fireEvent('click', this);
34055     },
34056     
34057     prev : function(e)
34058     {
34059         e.preventDefault();
34060         
34061         this.indicator = Math.max(1, this.indicator - 1);
34062         
34063         this.update();
34064     },
34065     
34066     next : function(e)
34067     {
34068         e.preventDefault();
34069         
34070         this.indicator = Math.min(this.files.length, this.indicator + 1);
34071         
34072         this.update();
34073     }
34074 });
34075 /*
34076  * - LGPL
34077  *
34078  * RadioSet
34079  *
34080  *
34081  */
34082
34083 /**
34084  * @class Roo.bootstrap.RadioSet
34085  * @extends Roo.bootstrap.Input
34086  * Bootstrap RadioSet class
34087  * @cfg {String} indicatorpos (left|right) default left
34088  * @cfg {Boolean} inline (true|false) inline the element (default true)
34089  * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
34090  * @constructor
34091  * Create a new RadioSet
34092  * @param {Object} config The config object
34093  */
34094
34095 Roo.bootstrap.RadioSet = function(config){
34096     
34097     Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
34098     
34099     this.radioes = [];
34100     
34101     Roo.bootstrap.RadioSet.register(this);
34102     
34103     this.addEvents({
34104         /**
34105         * @event check
34106         * Fires when the element is checked or unchecked.
34107         * @param {Roo.bootstrap.RadioSet} this This radio
34108         * @param {Roo.bootstrap.Radio} item The checked item
34109         */
34110        check : true,
34111        /**
34112         * @event click
34113         * Fires when the element is click.
34114         * @param {Roo.bootstrap.RadioSet} this This radio set
34115         * @param {Roo.bootstrap.Radio} item The checked item
34116         * @param {Roo.EventObject} e The event object
34117         */
34118        click : true
34119     });
34120     
34121 };
34122
34123 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
34124
34125     radioes : false,
34126     
34127     inline : true,
34128     
34129     weight : '',
34130     
34131     indicatorpos : 'left',
34132     
34133     getAutoCreate : function()
34134     {
34135         var label = {
34136             tag : 'label',
34137             cls : 'roo-radio-set-label',
34138             cn : [
34139                 {
34140                     tag : 'span',
34141                     html : this.fieldLabel
34142                 }
34143             ]
34144         };
34145         if (Roo.bootstrap.version == 3) {
34146             
34147             
34148             if(this.indicatorpos == 'left'){
34149                 label.cn.unshift({
34150                     tag : 'i',
34151                     cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
34152                     tooltip : 'This field is required'
34153                 });
34154             } else {
34155                 label.cn.push({
34156                     tag : 'i',
34157                     cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
34158                     tooltip : 'This field is required'
34159                 });
34160             }
34161         }
34162         var items = {
34163             tag : 'div',
34164             cls : 'roo-radio-set-items'
34165         };
34166         
34167         var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
34168         
34169         if (align === 'left' && this.fieldLabel.length) {
34170             
34171             items = {
34172                 cls : "roo-radio-set-right", 
34173                 cn: [
34174                     items
34175                 ]
34176             };
34177             
34178             if(this.labelWidth > 12){
34179                 label.style = "width: " + this.labelWidth + 'px';
34180             }
34181             
34182             if(this.labelWidth < 13 && this.labelmd == 0){
34183                 this.labelmd = this.labelWidth;
34184             }
34185             
34186             if(this.labellg > 0){
34187                 label.cls += ' col-lg-' + this.labellg;
34188                 items.cls += ' col-lg-' + (12 - this.labellg);
34189             }
34190             
34191             if(this.labelmd > 0){
34192                 label.cls += ' col-md-' + this.labelmd;
34193                 items.cls += ' col-md-' + (12 - this.labelmd);
34194             }
34195             
34196             if(this.labelsm > 0){
34197                 label.cls += ' col-sm-' + this.labelsm;
34198                 items.cls += ' col-sm-' + (12 - this.labelsm);
34199             }
34200             
34201             if(this.labelxs > 0){
34202                 label.cls += ' col-xs-' + this.labelxs;
34203                 items.cls += ' col-xs-' + (12 - this.labelxs);
34204             }
34205         }
34206         
34207         var cfg = {
34208             tag : 'div',
34209             cls : 'roo-radio-set',
34210             cn : [
34211                 {
34212                     tag : 'input',
34213                     cls : 'roo-radio-set-input',
34214                     type : 'hidden',
34215                     name : this.name,
34216                     value : this.value ? this.value :  ''
34217                 },
34218                 label,
34219                 items
34220             ]
34221         };
34222         
34223         if(this.weight.length){
34224             cfg.cls += ' roo-radio-' + this.weight;
34225         }
34226         
34227         if(this.inline) {
34228             cfg.cls += ' roo-radio-set-inline';
34229         }
34230         
34231         var settings=this;
34232         ['xs','sm','md','lg'].map(function(size){
34233             if (settings[size]) {
34234                 cfg.cls += ' col-' + size + '-' + settings[size];
34235             }
34236         });
34237         
34238         return cfg;
34239         
34240     },
34241
34242     initEvents : function()
34243     {
34244         this.labelEl = this.el.select('.roo-radio-set-label', true).first();
34245         this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
34246         
34247         if(!this.fieldLabel.length){
34248             this.labelEl.hide();
34249         }
34250         
34251         this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
34252         this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
34253         
34254         this.indicator = this.indicatorEl();
34255         
34256         if(this.indicator){
34257             this.indicator.addClass('invisible');
34258         }
34259         
34260         this.originalValue = this.getValue();
34261         
34262     },
34263     
34264     inputEl: function ()
34265     {
34266         return this.el.select('.roo-radio-set-input', true).first();
34267     },
34268     
34269     getChildContainer : function()
34270     {
34271         return this.itemsEl;
34272     },
34273     
34274     register : function(item)
34275     {
34276         this.radioes.push(item);
34277         
34278     },
34279     
34280     validate : function()
34281     {   
34282         if(this.getVisibilityEl().hasClass('hidden')){
34283             return true;
34284         }
34285         
34286         var valid = false;
34287         
34288         Roo.each(this.radioes, function(i){
34289             if(!i.checked){
34290                 return;
34291             }
34292             
34293             valid = true;
34294             return false;
34295         });
34296         
34297         if(this.allowBlank) {
34298             return true;
34299         }
34300         
34301         if(this.disabled || valid){
34302             this.markValid();
34303             return true;
34304         }
34305         
34306         this.markInvalid();
34307         return false;
34308         
34309     },
34310     
34311     markValid : function()
34312     {
34313         if(this.labelEl.isVisible(true) && this.indicatorEl()){
34314             this.indicatorEl().removeClass('visible');
34315             this.indicatorEl().addClass('invisible');
34316         }
34317         
34318         
34319         if (Roo.bootstrap.version == 3) {
34320             this.el.removeClass([this.invalidClass, this.validClass]);
34321             this.el.addClass(this.validClass);
34322         } else {
34323             this.el.removeClass(['is-invalid','is-valid']);
34324             this.el.addClass(['is-valid']);
34325         }
34326         this.fireEvent('valid', this);
34327     },
34328     
34329     markInvalid : function(msg)
34330     {
34331         if(this.allowBlank || this.disabled){
34332             return;
34333         }
34334         
34335         if(this.labelEl.isVisible(true) && this.indicatorEl()){
34336             this.indicatorEl().removeClass('invisible');
34337             this.indicatorEl().addClass('visible');
34338         }
34339         if (Roo.bootstrap.version == 3) {
34340             this.el.removeClass([this.invalidClass, this.validClass]);
34341             this.el.addClass(this.invalidClass);
34342         } else {
34343             this.el.removeClass(['is-invalid','is-valid']);
34344             this.el.addClass(['is-invalid']);
34345         }
34346         
34347         this.fireEvent('invalid', this, msg);
34348         
34349     },
34350     
34351     setValue : function(v, suppressEvent)
34352     {   
34353         if(this.value === v){
34354             return;
34355         }
34356         
34357         this.value = v;
34358         
34359         if(this.rendered){
34360             this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
34361         }
34362         
34363         Roo.each(this.radioes, function(i){
34364             i.checked = false;
34365             i.el.removeClass('checked');
34366         });
34367         
34368         Roo.each(this.radioes, function(i){
34369             
34370             if(i.value === v || i.value.toString() === v.toString()){
34371                 i.checked = true;
34372                 i.el.addClass('checked');
34373                 
34374                 if(suppressEvent !== true){
34375                     this.fireEvent('check', this, i);
34376                 }
34377                 
34378                 return false;
34379             }
34380             
34381         }, this);
34382         
34383         this.validate();
34384     },
34385     
34386     clearInvalid : function(){
34387         
34388         if(!this.el || this.preventMark){
34389             return;
34390         }
34391         
34392         this.el.removeClass([this.invalidClass]);
34393         
34394         this.fireEvent('valid', this);
34395     }
34396     
34397 });
34398
34399 Roo.apply(Roo.bootstrap.RadioSet, {
34400     
34401     groups: {},
34402     
34403     register : function(set)
34404     {
34405         this.groups[set.name] = set;
34406     },
34407     
34408     get: function(name) 
34409     {
34410         if (typeof(this.groups[name]) == 'undefined') {
34411             return false;
34412         }
34413         
34414         return this.groups[name] ;
34415     }
34416     
34417 });
34418 /*
34419  * Based on:
34420  * Ext JS Library 1.1.1
34421  * Copyright(c) 2006-2007, Ext JS, LLC.
34422  *
34423  * Originally Released Under LGPL - original licence link has changed is not relivant.
34424  *
34425  * Fork - LGPL
34426  * <script type="text/javascript">
34427  */
34428
34429
34430 /**
34431  * @class Roo.bootstrap.SplitBar
34432  * @extends Roo.util.Observable
34433  * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
34434  * <br><br>
34435  * Usage:
34436  * <pre><code>
34437 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
34438                    Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
34439 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
34440 split.minSize = 100;
34441 split.maxSize = 600;
34442 split.animate = true;
34443 split.on('moved', splitterMoved);
34444 </code></pre>
34445  * @constructor
34446  * Create a new SplitBar
34447  * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar. 
34448  * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged 
34449  * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34450  * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or  
34451                         Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
34452                         position of the SplitBar).
34453  */
34454 Roo.bootstrap.SplitBar = function(cfg){
34455     
34456     /** @private */
34457     
34458     //{
34459     //  dragElement : elm
34460     //  resizingElement: el,
34461         // optional..
34462     //    orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
34463     //    placement : Roo.bootstrap.SplitBar.LEFT  ,
34464         // existingProxy ???
34465     //}
34466     
34467     this.el = Roo.get(cfg.dragElement, true);
34468     this.el.dom.unselectable = "on";
34469     /** @private */
34470     this.resizingEl = Roo.get(cfg.resizingElement, true);
34471
34472     /**
34473      * @private
34474      * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34475      * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
34476      * @type Number
34477      */
34478     this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
34479     
34480     /**
34481      * The minimum size of the resizing element. (Defaults to 0)
34482      * @type Number
34483      */
34484     this.minSize = 0;
34485     
34486     /**
34487      * The maximum size of the resizing element. (Defaults to 2000)
34488      * @type Number
34489      */
34490     this.maxSize = 2000;
34491     
34492     /**
34493      * Whether to animate the transition to the new size
34494      * @type Boolean
34495      */
34496     this.animate = false;
34497     
34498     /**
34499      * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
34500      * @type Boolean
34501      */
34502     this.useShim = false;
34503     
34504     /** @private */
34505     this.shim = null;
34506     
34507     if(!cfg.existingProxy){
34508         /** @private */
34509         this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
34510     }else{
34511         this.proxy = Roo.get(cfg.existingProxy).dom;
34512     }
34513     /** @private */
34514     this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
34515     
34516     /** @private */
34517     this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
34518     
34519     /** @private */
34520     this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
34521     
34522     /** @private */
34523     this.dragSpecs = {};
34524     
34525     /**
34526      * @private The adapter to use to positon and resize elements
34527      */
34528     this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34529     this.adapter.init(this);
34530     
34531     if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34532         /** @private */
34533         this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
34534         this.el.addClass("roo-splitbar-h");
34535     }else{
34536         /** @private */
34537         this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
34538         this.el.addClass("roo-splitbar-v");
34539     }
34540     
34541     this.addEvents({
34542         /**
34543          * @event resize
34544          * Fires when the splitter is moved (alias for {@link #event-moved})
34545          * @param {Roo.bootstrap.SplitBar} this
34546          * @param {Number} newSize the new width or height
34547          */
34548         "resize" : true,
34549         /**
34550          * @event moved
34551          * Fires when the splitter is moved
34552          * @param {Roo.bootstrap.SplitBar} this
34553          * @param {Number} newSize the new width or height
34554          */
34555         "moved" : true,
34556         /**
34557          * @event beforeresize
34558          * Fires before the splitter is dragged
34559          * @param {Roo.bootstrap.SplitBar} this
34560          */
34561         "beforeresize" : true,
34562
34563         "beforeapply" : true
34564     });
34565
34566     Roo.util.Observable.call(this);
34567 };
34568
34569 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
34570     onStartProxyDrag : function(x, y){
34571         this.fireEvent("beforeresize", this);
34572         if(!this.overlay){
34573             var o = Roo.DomHelper.insertFirst(document.body,  {cls: "roo-drag-overlay", html: "&#160;"}, true);
34574             o.unselectable();
34575             o.enableDisplayMode("block");
34576             // all splitbars share the same overlay
34577             Roo.bootstrap.SplitBar.prototype.overlay = o;
34578         }
34579         this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
34580         this.overlay.show();
34581         Roo.get(this.proxy).setDisplayed("block");
34582         var size = this.adapter.getElementSize(this);
34583         this.activeMinSize = this.getMinimumSize();;
34584         this.activeMaxSize = this.getMaximumSize();;
34585         var c1 = size - this.activeMinSize;
34586         var c2 = Math.max(this.activeMaxSize - size, 0);
34587         if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34588             this.dd.resetConstraints();
34589             this.dd.setXConstraint(
34590                 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2, 
34591                 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
34592             );
34593             this.dd.setYConstraint(0, 0);
34594         }else{
34595             this.dd.resetConstraints();
34596             this.dd.setXConstraint(0, 0);
34597             this.dd.setYConstraint(
34598                 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2, 
34599                 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
34600             );
34601          }
34602         this.dragSpecs.startSize = size;
34603         this.dragSpecs.startPoint = [x, y];
34604         Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
34605     },
34606     
34607     /** 
34608      * @private Called after the drag operation by the DDProxy
34609      */
34610     onEndProxyDrag : function(e){
34611         Roo.get(this.proxy).setDisplayed(false);
34612         var endPoint = Roo.lib.Event.getXY(e);
34613         if(this.overlay){
34614             this.overlay.hide();
34615         }
34616         var newSize;
34617         if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34618             newSize = this.dragSpecs.startSize + 
34619                 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
34620                     endPoint[0] - this.dragSpecs.startPoint[0] :
34621                     this.dragSpecs.startPoint[0] - endPoint[0]
34622                 );
34623         }else{
34624             newSize = this.dragSpecs.startSize + 
34625                 (this.placement == Roo.bootstrap.SplitBar.TOP ?
34626                     endPoint[1] - this.dragSpecs.startPoint[1] :
34627                     this.dragSpecs.startPoint[1] - endPoint[1]
34628                 );
34629         }
34630         newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
34631         if(newSize != this.dragSpecs.startSize){
34632             if(this.fireEvent('beforeapply', this, newSize) !== false){
34633                 this.adapter.setElementSize(this, newSize);
34634                 this.fireEvent("moved", this, newSize);
34635                 this.fireEvent("resize", this, newSize);
34636             }
34637         }
34638     },
34639     
34640     /**
34641      * Get the adapter this SplitBar uses
34642      * @return The adapter object
34643      */
34644     getAdapter : function(){
34645         return this.adapter;
34646     },
34647     
34648     /**
34649      * Set the adapter this SplitBar uses
34650      * @param {Object} adapter A SplitBar adapter object
34651      */
34652     setAdapter : function(adapter){
34653         this.adapter = adapter;
34654         this.adapter.init(this);
34655     },
34656     
34657     /**
34658      * Gets the minimum size for the resizing element
34659      * @return {Number} The minimum size
34660      */
34661     getMinimumSize : function(){
34662         return this.minSize;
34663     },
34664     
34665     /**
34666      * Sets the minimum size for the resizing element
34667      * @param {Number} minSize The minimum size
34668      */
34669     setMinimumSize : function(minSize){
34670         this.minSize = minSize;
34671     },
34672     
34673     /**
34674      * Gets the maximum size for the resizing element
34675      * @return {Number} The maximum size
34676      */
34677     getMaximumSize : function(){
34678         return this.maxSize;
34679     },
34680     
34681     /**
34682      * Sets the maximum size for the resizing element
34683      * @param {Number} maxSize The maximum size
34684      */
34685     setMaximumSize : function(maxSize){
34686         this.maxSize = maxSize;
34687     },
34688     
34689     /**
34690      * Sets the initialize size for the resizing element
34691      * @param {Number} size The initial size
34692      */
34693     setCurrentSize : function(size){
34694         var oldAnimate = this.animate;
34695         this.animate = false;
34696         this.adapter.setElementSize(this, size);
34697         this.animate = oldAnimate;
34698     },
34699     
34700     /**
34701      * Destroy this splitbar. 
34702      * @param {Boolean} removeEl True to remove the element
34703      */
34704     destroy : function(removeEl){
34705         if(this.shim){
34706             this.shim.remove();
34707         }
34708         this.dd.unreg();
34709         this.proxy.parentNode.removeChild(this.proxy);
34710         if(removeEl){
34711             this.el.remove();
34712         }
34713     }
34714 });
34715
34716 /**
34717  * @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.
34718  */
34719 Roo.bootstrap.SplitBar.createProxy = function(dir){
34720     var proxy = new Roo.Element(document.createElement("div"));
34721     proxy.unselectable();
34722     var cls = 'roo-splitbar-proxy';
34723     proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
34724     document.body.appendChild(proxy.dom);
34725     return proxy.dom;
34726 };
34727
34728 /** 
34729  * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
34730  * Default Adapter. It assumes the splitter and resizing element are not positioned
34731  * elements and only gets/sets the width of the element. Generally used for table based layouts.
34732  */
34733 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
34734 };
34735
34736 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
34737     // do nothing for now
34738     init : function(s){
34739     
34740     },
34741     /**
34742      * Called before drag operations to get the current size of the resizing element. 
34743      * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34744      */
34745      getElementSize : function(s){
34746         if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34747             return s.resizingEl.getWidth();
34748         }else{
34749             return s.resizingEl.getHeight();
34750         }
34751     },
34752     
34753     /**
34754      * Called after drag operations to set the size of the resizing element.
34755      * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34756      * @param {Number} newSize The new size to set
34757      * @param {Function} onComplete A function to be invoked when resizing is complete
34758      */
34759     setElementSize : function(s, newSize, onComplete){
34760         if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34761             if(!s.animate){
34762                 s.resizingEl.setWidth(newSize);
34763                 if(onComplete){
34764                     onComplete(s, newSize);
34765                 }
34766             }else{
34767                 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
34768             }
34769         }else{
34770             
34771             if(!s.animate){
34772                 s.resizingEl.setHeight(newSize);
34773                 if(onComplete){
34774                     onComplete(s, newSize);
34775                 }
34776             }else{
34777                 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
34778             }
34779         }
34780     }
34781 };
34782
34783 /** 
34784  *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
34785  * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
34786  * Adapter that  moves the splitter element to align with the resized sizing element. 
34787  * Used with an absolute positioned SplitBar.
34788  * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
34789  * document.body, make sure you assign an id to the body element.
34790  */
34791 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
34792     this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34793     this.container = Roo.get(container);
34794 };
34795
34796 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
34797     init : function(s){
34798         this.basic.init(s);
34799     },
34800     
34801     getElementSize : function(s){
34802         return this.basic.getElementSize(s);
34803     },
34804     
34805     setElementSize : function(s, newSize, onComplete){
34806         this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34807     },
34808     
34809     moveSplitter : function(s){
34810         var yes = Roo.bootstrap.SplitBar;
34811         switch(s.placement){
34812             case yes.LEFT:
34813                 s.el.setX(s.resizingEl.getRight());
34814                 break;
34815             case yes.RIGHT:
34816                 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34817                 break;
34818             case yes.TOP:
34819                 s.el.setY(s.resizingEl.getBottom());
34820                 break;
34821             case yes.BOTTOM:
34822                 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34823                 break;
34824         }
34825     }
34826 };
34827
34828 /**
34829  * Orientation constant - Create a vertical SplitBar
34830  * @static
34831  * @type Number
34832  */
34833 Roo.bootstrap.SplitBar.VERTICAL = 1;
34834
34835 /**
34836  * Orientation constant - Create a horizontal SplitBar
34837  * @static
34838  * @type Number
34839  */
34840 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34841
34842 /**
34843  * Placement constant - The resizing element is to the left of the splitter element
34844  * @static
34845  * @type Number
34846  */
34847 Roo.bootstrap.SplitBar.LEFT = 1;
34848
34849 /**
34850  * Placement constant - The resizing element is to the right of the splitter element
34851  * @static
34852  * @type Number
34853  */
34854 Roo.bootstrap.SplitBar.RIGHT = 2;
34855
34856 /**
34857  * Placement constant - The resizing element is positioned above the splitter element
34858  * @static
34859  * @type Number
34860  */
34861 Roo.bootstrap.SplitBar.TOP = 3;
34862
34863 /**
34864  * Placement constant - The resizing element is positioned under splitter element
34865  * @static
34866  * @type Number
34867  */
34868 Roo.bootstrap.SplitBar.BOTTOM = 4;
34869 Roo.namespace("Roo.bootstrap.layout");/*
34870  * Based on:
34871  * Ext JS Library 1.1.1
34872  * Copyright(c) 2006-2007, Ext JS, LLC.
34873  *
34874  * Originally Released Under LGPL - original licence link has changed is not relivant.
34875  *
34876  * Fork - LGPL
34877  * <script type="text/javascript">
34878  */
34879
34880 /**
34881  * @class Roo.bootstrap.layout.Manager
34882  * @extends Roo.bootstrap.Component
34883  * Base class for layout managers.
34884  */
34885 Roo.bootstrap.layout.Manager = function(config)
34886 {
34887     Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34888
34889
34890
34891
34892
34893     /** false to disable window resize monitoring @type Boolean */
34894     this.monitorWindowResize = true;
34895     this.regions = {};
34896     this.addEvents({
34897         /**
34898          * @event layout
34899          * Fires when a layout is performed.
34900          * @param {Roo.LayoutManager} this
34901          */
34902         "layout" : true,
34903         /**
34904          * @event regionresized
34905          * Fires when the user resizes a region.
34906          * @param {Roo.LayoutRegion} region The resized region
34907          * @param {Number} newSize The new size (width for east/west, height for north/south)
34908          */
34909         "regionresized" : true,
34910         /**
34911          * @event regioncollapsed
34912          * Fires when a region is collapsed.
34913          * @param {Roo.LayoutRegion} region The collapsed region
34914          */
34915         "regioncollapsed" : true,
34916         /**
34917          * @event regionexpanded
34918          * Fires when a region is expanded.
34919          * @param {Roo.LayoutRegion} region The expanded region
34920          */
34921         "regionexpanded" : true
34922     });
34923     this.updating = false;
34924
34925     if (config.el) {
34926         this.el = Roo.get(config.el);
34927         this.initEvents();
34928     }
34929
34930 };
34931
34932 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34933
34934
34935     regions : null,
34936
34937     monitorWindowResize : true,
34938
34939
34940     updating : false,
34941
34942
34943     onRender : function(ct, position)
34944     {
34945         if(!this.el){
34946             this.el = Roo.get(ct);
34947             this.initEvents();
34948         }
34949         //this.fireEvent('render',this);
34950     },
34951
34952
34953     initEvents: function()
34954     {
34955
34956
34957         // ie scrollbar fix
34958         if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34959             document.body.scroll = "no";
34960         }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34961             this.el.position('relative');
34962         }
34963         this.id = this.el.id;
34964         this.el.addClass("roo-layout-container");
34965         Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34966         if(this.el.dom != document.body ) {
34967             this.el.on('resize', this.layout,this);
34968             this.el.on('show', this.layout,this);
34969         }
34970
34971     },
34972
34973     /**
34974      * Returns true if this layout is currently being updated
34975      * @return {Boolean}
34976      */
34977     isUpdating : function(){
34978         return this.updating;
34979     },
34980
34981     /**
34982      * Suspend the LayoutManager from doing auto-layouts while
34983      * making multiple add or remove calls
34984      */
34985     beginUpdate : function(){
34986         this.updating = true;
34987     },
34988
34989     /**
34990      * Restore auto-layouts and optionally disable the manager from performing a layout
34991      * @param {Boolean} noLayout true to disable a layout update
34992      */
34993     endUpdate : function(noLayout){
34994         this.updating = false;
34995         if(!noLayout){
34996             this.layout();
34997         }
34998     },
34999
35000     layout: function(){
35001         // abstract...
35002     },
35003
35004     onRegionResized : function(region, newSize){
35005         this.fireEvent("regionresized", region, newSize);
35006         this.layout();
35007     },
35008
35009     onRegionCollapsed : function(region){
35010         this.fireEvent("regioncollapsed", region);
35011     },
35012
35013     onRegionExpanded : function(region){
35014         this.fireEvent("regionexpanded", region);
35015     },
35016
35017     /**
35018      * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
35019      * performs box-model adjustments.
35020      * @return {Object} The size as an object {width: (the width), height: (the height)}
35021      */
35022     getViewSize : function()
35023     {
35024         var size;
35025         if(this.el.dom != document.body){
35026             size = this.el.getSize();
35027         }else{
35028             size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
35029         }
35030         size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
35031         size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
35032         return size;
35033     },
35034
35035     /**
35036      * Returns the Element this layout is bound to.
35037      * @return {Roo.Element}
35038      */
35039     getEl : function(){
35040         return this.el;
35041     },
35042
35043     /**
35044      * Returns the specified region.
35045      * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
35046      * @return {Roo.LayoutRegion}
35047      */
35048     getRegion : function(target){
35049         return this.regions[target.toLowerCase()];
35050     },
35051
35052     onWindowResize : function(){
35053         if(this.monitorWindowResize){
35054             this.layout();
35055         }
35056     }
35057 });
35058 /*
35059  * Based on:
35060  * Ext JS Library 1.1.1
35061  * Copyright(c) 2006-2007, Ext JS, LLC.
35062  *
35063  * Originally Released Under LGPL - original licence link has changed is not relivant.
35064  *
35065  * Fork - LGPL
35066  * <script type="text/javascript">
35067  */
35068 /**
35069  * @class Roo.bootstrap.layout.Border
35070  * @extends Roo.bootstrap.layout.Manager
35071  * This class represents a common layout manager used in desktop applications. For screenshots and more details,
35072  * please see: examples/bootstrap/nested.html<br><br>
35073  
35074 <b>The container the layout is rendered into can be either the body element or any other element.
35075 If it is not the body element, the container needs to either be an absolute positioned element,
35076 or you will need to add "position:relative" to the css of the container.  You will also need to specify
35077 the container size if it is not the body element.</b>
35078
35079 * @constructor
35080 * Create a new Border
35081 * @param {Object} config Configuration options
35082  */
35083 Roo.bootstrap.layout.Border = function(config){
35084     config = config || {};
35085     Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
35086     
35087     
35088     
35089     Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
35090         if(config[region]){
35091             config[region].region = region;
35092             this.addRegion(config[region]);
35093         }
35094     },this);
35095     
35096 };
35097
35098 Roo.bootstrap.layout.Border.regions =  ["north","south","east","west","center"];
35099
35100 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
35101     /**
35102      * Creates and adds a new region if it doesn't already exist.
35103      * @param {String} target The target region key (north, south, east, west or center).
35104      * @param {Object} config The regions config object
35105      * @return {BorderLayoutRegion} The new region
35106      */
35107     addRegion : function(config)
35108     {
35109         if(!this.regions[config.region]){
35110             var r = this.factory(config);
35111             this.bindRegion(r);
35112         }
35113         return this.regions[config.region];
35114     },
35115
35116     // private (kinda)
35117     bindRegion : function(r){
35118         this.regions[r.config.region] = r;
35119         
35120         r.on("visibilitychange",    this.layout, this);
35121         r.on("paneladded",          this.layout, this);
35122         r.on("panelremoved",        this.layout, this);
35123         r.on("invalidated",         this.layout, this);
35124         r.on("resized",             this.onRegionResized, this);
35125         r.on("collapsed",           this.onRegionCollapsed, this);
35126         r.on("expanded",            this.onRegionExpanded, this);
35127     },
35128
35129     /**
35130      * Performs a layout update.
35131      */
35132     layout : function()
35133     {
35134         if(this.updating) {
35135             return;
35136         }
35137         
35138         // render all the rebions if they have not been done alreayd?
35139         Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
35140             if(this.regions[region] && !this.regions[region].bodyEl){
35141                 this.regions[region].onRender(this.el)
35142             }
35143         },this);
35144         
35145         var size = this.getViewSize();
35146         var w = size.width;
35147         var h = size.height;
35148         var centerW = w;
35149         var centerH = h;
35150         var centerY = 0;
35151         var centerX = 0;
35152         //var x = 0, y = 0;
35153
35154         var rs = this.regions;
35155         var north = rs["north"];
35156         var south = rs["south"]; 
35157         var west = rs["west"];
35158         var east = rs["east"];
35159         var center = rs["center"];
35160         //if(this.hideOnLayout){ // not supported anymore
35161             //c.el.setStyle("display", "none");
35162         //}
35163         if(north && north.isVisible()){
35164             var b = north.getBox();
35165             var m = north.getMargins();
35166             b.width = w - (m.left+m.right);
35167             b.x = m.left;
35168             b.y = m.top;
35169             centerY = b.height + b.y + m.bottom;
35170             centerH -= centerY;
35171             north.updateBox(this.safeBox(b));
35172         }
35173         if(south && south.isVisible()){
35174             var b = south.getBox();
35175             var m = south.getMargins();
35176             b.width = w - (m.left+m.right);
35177             b.x = m.left;
35178             var totalHeight = (b.height + m.top + m.bottom);
35179             b.y = h - totalHeight + m.top;
35180             centerH -= totalHeight;
35181             south.updateBox(this.safeBox(b));
35182         }
35183         if(west && west.isVisible()){
35184             var b = west.getBox();
35185             var m = west.getMargins();
35186             b.height = centerH - (m.top+m.bottom);
35187             b.x = m.left;
35188             b.y = centerY + m.top;
35189             var totalWidth = (b.width + m.left + m.right);
35190             centerX += totalWidth;
35191             centerW -= totalWidth;
35192             west.updateBox(this.safeBox(b));
35193         }
35194         if(east && east.isVisible()){
35195             var b = east.getBox();
35196             var m = east.getMargins();
35197             b.height = centerH - (m.top+m.bottom);
35198             var totalWidth = (b.width + m.left + m.right);
35199             b.x = w - totalWidth + m.left;
35200             b.y = centerY + m.top;
35201             centerW -= totalWidth;
35202             east.updateBox(this.safeBox(b));
35203         }
35204         if(center){
35205             var m = center.getMargins();
35206             var centerBox = {
35207                 x: centerX + m.left,
35208                 y: centerY + m.top,
35209                 width: centerW - (m.left+m.right),
35210                 height: centerH - (m.top+m.bottom)
35211             };
35212             //if(this.hideOnLayout){
35213                 //center.el.setStyle("display", "block");
35214             //}
35215             center.updateBox(this.safeBox(centerBox));
35216         }
35217         this.el.repaint();
35218         this.fireEvent("layout", this);
35219     },
35220
35221     // private
35222     safeBox : function(box){
35223         box.width = Math.max(0, box.width);
35224         box.height = Math.max(0, box.height);
35225         return box;
35226     },
35227
35228     /**
35229      * Adds a ContentPanel (or subclass) to this layout.
35230      * @param {String} target The target region key (north, south, east, west or center).
35231      * @param {Roo.ContentPanel} panel The panel to add
35232      * @return {Roo.ContentPanel} The added panel
35233      */
35234     add : function(target, panel){
35235          
35236         target = target.toLowerCase();
35237         return this.regions[target].add(panel);
35238     },
35239
35240     /**
35241      * Remove a ContentPanel (or subclass) to this layout.
35242      * @param {String} target The target region key (north, south, east, west or center).
35243      * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
35244      * @return {Roo.ContentPanel} The removed panel
35245      */
35246     remove : function(target, panel){
35247         target = target.toLowerCase();
35248         return this.regions[target].remove(panel);
35249     },
35250
35251     /**
35252      * Searches all regions for a panel with the specified id
35253      * @param {String} panelId
35254      * @return {Roo.ContentPanel} The panel or null if it wasn't found
35255      */
35256     findPanel : function(panelId){
35257         var rs = this.regions;
35258         for(var target in rs){
35259             if(typeof rs[target] != "function"){
35260                 var p = rs[target].getPanel(panelId);
35261                 if(p){
35262                     return p;
35263                 }
35264             }
35265         }
35266         return null;
35267     },
35268
35269     /**
35270      * Searches all regions for a panel with the specified id and activates (shows) it.
35271      * @param {String/ContentPanel} panelId The panels id or the panel itself
35272      * @return {Roo.ContentPanel} The shown panel or null
35273      */
35274     showPanel : function(panelId) {
35275       var rs = this.regions;
35276       for(var target in rs){
35277          var r = rs[target];
35278          if(typeof r != "function"){
35279             if(r.hasPanel(panelId)){
35280                return r.showPanel(panelId);
35281             }
35282          }
35283       }
35284       return null;
35285    },
35286
35287    /**
35288      * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
35289      * @param {Roo.state.Provider} provider (optional) An alternate state provider
35290      */
35291    /*
35292     restoreState : function(provider){
35293         if(!provider){
35294             provider = Roo.state.Manager;
35295         }
35296         var sm = new Roo.LayoutStateManager();
35297         sm.init(this, provider);
35298     },
35299 */
35300  
35301  
35302     /**
35303      * Adds a xtype elements to the layout.
35304      * <pre><code>
35305
35306 layout.addxtype({
35307        xtype : 'ContentPanel',
35308        region: 'west',
35309        items: [ .... ]
35310    }
35311 );
35312
35313 layout.addxtype({
35314         xtype : 'NestedLayoutPanel',
35315         region: 'west',
35316         layout: {
35317            center: { },
35318            west: { }   
35319         },
35320         items : [ ... list of content panels or nested layout panels.. ]
35321    }
35322 );
35323 </code></pre>
35324      * @param {Object} cfg Xtype definition of item to add.
35325      */
35326     addxtype : function(cfg)
35327     {
35328         // basically accepts a pannel...
35329         // can accept a layout region..!?!?
35330         //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
35331         
35332         
35333         // theory?  children can only be panels??
35334         
35335         //if (!cfg.xtype.match(/Panel$/)) {
35336         //    return false;
35337         //}
35338         var ret = false;
35339         
35340         if (typeof(cfg.region) == 'undefined') {
35341             Roo.log("Failed to add Panel, region was not set");
35342             Roo.log(cfg);
35343             return false;
35344         }
35345         var region = cfg.region;
35346         delete cfg.region;
35347         
35348           
35349         var xitems = [];
35350         if (cfg.items) {
35351             xitems = cfg.items;
35352             delete cfg.items;
35353         }
35354         var nb = false;
35355         
35356         switch(cfg.xtype) 
35357         {
35358             case 'Content':  // ContentPanel (el, cfg)
35359             case 'Scroll':  // ContentPanel (el, cfg)
35360             case 'View': 
35361                 cfg.autoCreate = true;
35362                 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35363                 //} else {
35364                 //    var el = this.el.createChild();
35365                 //    ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
35366                 //}
35367                 
35368                 this.add(region, ret);
35369                 break;
35370             
35371             /*
35372             case 'TreePanel': // our new panel!
35373                 cfg.el = this.el.createChild();
35374                 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35375                 this.add(region, ret);
35376                 break;
35377             */
35378             
35379             case 'Nest': 
35380                 // create a new Layout (which is  a Border Layout...
35381                 
35382                 var clayout = cfg.layout;
35383                 clayout.el  = this.el.createChild();
35384                 clayout.items   = clayout.items  || [];
35385                 
35386                 delete cfg.layout;
35387                 
35388                 // replace this exitems with the clayout ones..
35389                 xitems = clayout.items;
35390                  
35391                 // force background off if it's in center...
35392                 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
35393                     cfg.background = false;
35394                 }
35395                 cfg.layout  = new Roo.bootstrap.layout.Border(clayout);
35396                 
35397                 
35398                 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35399                 //console.log('adding nested layout panel '  + cfg.toSource());
35400                 this.add(region, ret);
35401                 nb = {}; /// find first...
35402                 break;
35403             
35404             case 'Grid':
35405                 
35406                 // needs grid and region
35407                 
35408                 //var el = this.getRegion(region).el.createChild();
35409                 /*
35410                  *var el = this.el.createChild();
35411                 // create the grid first...
35412                 cfg.grid.container = el;
35413                 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
35414                 */
35415                 
35416                 if (region == 'center' && this.active ) {
35417                     cfg.background = false;
35418                 }
35419                 
35420                 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35421                 
35422                 this.add(region, ret);
35423                 /*
35424                 if (cfg.background) {
35425                     // render grid on panel activation (if panel background)
35426                     ret.on('activate', function(gp) {
35427                         if (!gp.grid.rendered) {
35428                     //        gp.grid.render(el);
35429                         }
35430                     });
35431                 } else {
35432                   //  cfg.grid.render(el);
35433                 }
35434                 */
35435                 break;
35436            
35437            
35438             case 'Border': // it can get called on it'self... - might need to check if this is fixed?
35439                 // it was the old xcomponent building that caused this before.
35440                 // espeically if border is the top element in the tree.
35441                 ret = this;
35442                 break; 
35443                 
35444                     
35445                 
35446                 
35447                 
35448             default:
35449                 /*
35450                 if (typeof(Roo[cfg.xtype]) != 'undefined') {
35451                     
35452                     ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35453                     this.add(region, ret);
35454                 } else {
35455                 */
35456                     Roo.log(cfg);
35457                     throw "Can not add '" + cfg.xtype + "' to Border";
35458                     return null;
35459              
35460                                 
35461              
35462         }
35463         this.beginUpdate();
35464         // add children..
35465         var region = '';
35466         var abn = {};
35467         Roo.each(xitems, function(i)  {
35468             region = nb && i.region ? i.region : false;
35469             
35470             var add = ret.addxtype(i);
35471            
35472             if (region) {
35473                 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
35474                 if (!i.background) {
35475                     abn[region] = nb[region] ;
35476                 }
35477             }
35478             
35479         });
35480         this.endUpdate();
35481
35482         // make the last non-background panel active..
35483         //if (nb) { Roo.log(abn); }
35484         if (nb) {
35485             
35486             for(var r in abn) {
35487                 region = this.getRegion(r);
35488                 if (region) {
35489                     // tried using nb[r], but it does not work..
35490                      
35491                     region.showPanel(abn[r]);
35492                    
35493                 }
35494             }
35495         }
35496         return ret;
35497         
35498     },
35499     
35500     
35501 // private
35502     factory : function(cfg)
35503     {
35504         
35505         var validRegions = Roo.bootstrap.layout.Border.regions;
35506
35507         var target = cfg.region;
35508         cfg.mgr = this;
35509         
35510         var r = Roo.bootstrap.layout;
35511         Roo.log(target);
35512         switch(target){
35513             case "north":
35514                 return new r.North(cfg);
35515             case "south":
35516                 return new r.South(cfg);
35517             case "east":
35518                 return new r.East(cfg);
35519             case "west":
35520                 return new r.West(cfg);
35521             case "center":
35522                 return new r.Center(cfg);
35523         }
35524         throw 'Layout region "'+target+'" not supported.';
35525     }
35526     
35527     
35528 });
35529  /*
35530  * Based on:
35531  * Ext JS Library 1.1.1
35532  * Copyright(c) 2006-2007, Ext JS, LLC.
35533  *
35534  * Originally Released Under LGPL - original licence link has changed is not relivant.
35535  *
35536  * Fork - LGPL
35537  * <script type="text/javascript">
35538  */
35539  
35540 /**
35541  * @class Roo.bootstrap.layout.Basic
35542  * @extends Roo.util.Observable
35543  * This class represents a lightweight region in a layout manager. This region does not move dom nodes
35544  * and does not have a titlebar, tabs or any other features. All it does is size and position 
35545  * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
35546  * @cfg {Roo.bootstrap.layout.Manager}   mgr The manager
35547  * @cfg {string}   region  the region that it inhabits..
35548  * @cfg {bool}   skipConfig skip config?
35549  * 
35550
35551  */
35552 Roo.bootstrap.layout.Basic = function(config){
35553     
35554     this.mgr = config.mgr;
35555     
35556     this.position = config.region;
35557     
35558     var skipConfig = config.skipConfig;
35559     
35560     this.events = {
35561         /**
35562          * @scope Roo.BasicLayoutRegion
35563          */
35564         
35565         /**
35566          * @event beforeremove
35567          * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
35568          * @param {Roo.LayoutRegion} this
35569          * @param {Roo.ContentPanel} panel The panel
35570          * @param {Object} e The cancel event object
35571          */
35572         "beforeremove" : true,
35573         /**
35574          * @event invalidated
35575          * Fires when the layout for this region is changed.
35576          * @param {Roo.LayoutRegion} this
35577          */
35578         "invalidated" : true,
35579         /**
35580          * @event visibilitychange
35581          * Fires when this region is shown or hidden 
35582          * @param {Roo.LayoutRegion} this
35583          * @param {Boolean} visibility true or false
35584          */
35585         "visibilitychange" : true,
35586         /**
35587          * @event paneladded
35588          * Fires when a panel is added. 
35589          * @param {Roo.LayoutRegion} this
35590          * @param {Roo.ContentPanel} panel The panel
35591          */
35592         "paneladded" : true,
35593         /**
35594          * @event panelremoved
35595          * Fires when a panel is removed. 
35596          * @param {Roo.LayoutRegion} this
35597          * @param {Roo.ContentPanel} panel The panel
35598          */
35599         "panelremoved" : true,
35600         /**
35601          * @event beforecollapse
35602          * Fires when this region before collapse.
35603          * @param {Roo.LayoutRegion} this
35604          */
35605         "beforecollapse" : true,
35606         /**
35607          * @event collapsed
35608          * Fires when this region is collapsed.
35609          * @param {Roo.LayoutRegion} this
35610          */
35611         "collapsed" : true,
35612         /**
35613          * @event expanded
35614          * Fires when this region is expanded.
35615          * @param {Roo.LayoutRegion} this
35616          */
35617         "expanded" : true,
35618         /**
35619          * @event slideshow
35620          * Fires when this region is slid into view.
35621          * @param {Roo.LayoutRegion} this
35622          */
35623         "slideshow" : true,
35624         /**
35625          * @event slidehide
35626          * Fires when this region slides out of view. 
35627          * @param {Roo.LayoutRegion} this
35628          */
35629         "slidehide" : true,
35630         /**
35631          * @event panelactivated
35632          * Fires when a panel is activated. 
35633          * @param {Roo.LayoutRegion} this
35634          * @param {Roo.ContentPanel} panel The activated panel
35635          */
35636         "panelactivated" : true,
35637         /**
35638          * @event resized
35639          * Fires when the user resizes this region. 
35640          * @param {Roo.LayoutRegion} this
35641          * @param {Number} newSize The new size (width for east/west, height for north/south)
35642          */
35643         "resized" : true
35644     };
35645     /** A collection of panels in this region. @type Roo.util.MixedCollection */
35646     this.panels = new Roo.util.MixedCollection();
35647     this.panels.getKey = this.getPanelId.createDelegate(this);
35648     this.box = null;
35649     this.activePanel = null;
35650     // ensure listeners are added...
35651     
35652     if (config.listeners || config.events) {
35653         Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
35654             listeners : config.listeners || {},
35655             events : config.events || {}
35656         });
35657     }
35658     
35659     if(skipConfig !== true){
35660         this.applyConfig(config);
35661     }
35662 };
35663
35664 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
35665 {
35666     getPanelId : function(p){
35667         return p.getId();
35668     },
35669     
35670     applyConfig : function(config){
35671         this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35672         this.config = config;
35673         
35674     },
35675     
35676     /**
35677      * Resizes the region to the specified size. For vertical regions (west, east) this adjusts 
35678      * the width, for horizontal (north, south) the height.
35679      * @param {Number} newSize The new width or height
35680      */
35681     resizeTo : function(newSize){
35682         var el = this.el ? this.el :
35683                  (this.activePanel ? this.activePanel.getEl() : null);
35684         if(el){
35685             switch(this.position){
35686                 case "east":
35687                 case "west":
35688                     el.setWidth(newSize);
35689                     this.fireEvent("resized", this, newSize);
35690                 break;
35691                 case "north":
35692                 case "south":
35693                     el.setHeight(newSize);
35694                     this.fireEvent("resized", this, newSize);
35695                 break;                
35696             }
35697         }
35698     },
35699     
35700     getBox : function(){
35701         return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
35702     },
35703     
35704     getMargins : function(){
35705         return this.margins;
35706     },
35707     
35708     updateBox : function(box){
35709         this.box = box;
35710         var el = this.activePanel.getEl();
35711         el.dom.style.left = box.x + "px";
35712         el.dom.style.top = box.y + "px";
35713         this.activePanel.setSize(box.width, box.height);
35714     },
35715     
35716     /**
35717      * Returns the container element for this region.
35718      * @return {Roo.Element}
35719      */
35720     getEl : function(){
35721         return this.activePanel;
35722     },
35723     
35724     /**
35725      * Returns true if this region is currently visible.
35726      * @return {Boolean}
35727      */
35728     isVisible : function(){
35729         return this.activePanel ? true : false;
35730     },
35731     
35732     setActivePanel : function(panel){
35733         panel = this.getPanel(panel);
35734         if(this.activePanel && this.activePanel != panel){
35735             this.activePanel.setActiveState(false);
35736             this.activePanel.getEl().setLeftTop(-10000,-10000);
35737         }
35738         this.activePanel = panel;
35739         panel.setActiveState(true);
35740         if(this.box){
35741             panel.setSize(this.box.width, this.box.height);
35742         }
35743         this.fireEvent("panelactivated", this, panel);
35744         this.fireEvent("invalidated");
35745     },
35746     
35747     /**
35748      * Show the specified panel.
35749      * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
35750      * @return {Roo.ContentPanel} The shown panel or null
35751      */
35752     showPanel : function(panel){
35753         panel = this.getPanel(panel);
35754         if(panel){
35755             this.setActivePanel(panel);
35756         }
35757         return panel;
35758     },
35759     
35760     /**
35761      * Get the active panel for this region.
35762      * @return {Roo.ContentPanel} The active panel or null
35763      */
35764     getActivePanel : function(){
35765         return this.activePanel;
35766     },
35767     
35768     /**
35769      * Add the passed ContentPanel(s)
35770      * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35771      * @return {Roo.ContentPanel} The panel added (if only one was added)
35772      */
35773     add : function(panel){
35774         if(arguments.length > 1){
35775             for(var i = 0, len = arguments.length; i < len; i++) {
35776                 this.add(arguments[i]);
35777             }
35778             return null;
35779         }
35780         if(this.hasPanel(panel)){
35781             this.showPanel(panel);
35782             return panel;
35783         }
35784         var el = panel.getEl();
35785         if(el.dom.parentNode != this.mgr.el.dom){
35786             this.mgr.el.dom.appendChild(el.dom);
35787         }
35788         if(panel.setRegion){
35789             panel.setRegion(this);
35790         }
35791         this.panels.add(panel);
35792         el.setStyle("position", "absolute");
35793         if(!panel.background){
35794             this.setActivePanel(panel);
35795             if(this.config.initialSize && this.panels.getCount()==1){
35796                 this.resizeTo(this.config.initialSize);
35797             }
35798         }
35799         this.fireEvent("paneladded", this, panel);
35800         return panel;
35801     },
35802     
35803     /**
35804      * Returns true if the panel is in this region.
35805      * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35806      * @return {Boolean}
35807      */
35808     hasPanel : function(panel){
35809         if(typeof panel == "object"){ // must be panel obj
35810             panel = panel.getId();
35811         }
35812         return this.getPanel(panel) ? true : false;
35813     },
35814     
35815     /**
35816      * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35817      * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35818      * @param {Boolean} preservePanel Overrides the config preservePanel option
35819      * @return {Roo.ContentPanel} The panel that was removed
35820      */
35821     remove : function(panel, preservePanel){
35822         panel = this.getPanel(panel);
35823         if(!panel){
35824             return null;
35825         }
35826         var e = {};
35827         this.fireEvent("beforeremove", this, panel, e);
35828         if(e.cancel === true){
35829             return null;
35830         }
35831         var panelId = panel.getId();
35832         this.panels.removeKey(panelId);
35833         return panel;
35834     },
35835     
35836     /**
35837      * Returns the panel specified or null if it's not in this region.
35838      * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35839      * @return {Roo.ContentPanel}
35840      */
35841     getPanel : function(id){
35842         if(typeof id == "object"){ // must be panel obj
35843             return id;
35844         }
35845         return this.panels.get(id);
35846     },
35847     
35848     /**
35849      * Returns this regions position (north/south/east/west/center).
35850      * @return {String} 
35851      */
35852     getPosition: function(){
35853         return this.position;    
35854     }
35855 });/*
35856  * Based on:
35857  * Ext JS Library 1.1.1
35858  * Copyright(c) 2006-2007, Ext JS, LLC.
35859  *
35860  * Originally Released Under LGPL - original licence link has changed is not relivant.
35861  *
35862  * Fork - LGPL
35863  * <script type="text/javascript">
35864  */
35865  
35866 /**
35867  * @class Roo.bootstrap.layout.Region
35868  * @extends Roo.bootstrap.layout.Basic
35869  * This class represents a region in a layout manager.
35870  
35871  * @cfg {Object}    margins         Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35872  * @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})
35873  * @cfg {String}    tabPosition     (top|bottom) "top" or "bottom" (defaults to "bottom")
35874  * @cfg {Boolean}   alwaysShowTabs  True to always display tabs even when there is only 1 panel (defaults to false)
35875  * @cfg {Boolean}   autoScroll      True to enable overflow scrolling (defaults to false)
35876  * @cfg {Boolean}   titlebar        True to display a title bar (defaults to true)
35877  * @cfg {String}    title           The title for the region (overrides panel titles)
35878  * @cfg {Boolean}   animate         True to animate expand/collapse (defaults to false)
35879  * @cfg {Boolean}   autoHide        False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35880  * @cfg {Boolean}   preservePanels  True to preserve removed panels so they can be readded later (defaults to false)
35881  * @cfg {Boolean}   closeOnTab      True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35882  * @cfg {Boolean}   hideTabs        True to hide the tab strip (defaults to false)
35883  * @cfg {Boolean}   resizeTabs      True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35884  *                      the space available, similar to FireFox 1.5 tabs (defaults to false)
35885  * @cfg {Number}    minTabWidth     The minimum tab width (defaults to 40)
35886  * @cfg {Number}    preferredTabWidth The preferred tab width (defaults to 150)
35887  * @cfg {String}    overflow       (hidden|visible) if you have menus in the region, then you need to set this to visible.
35888
35889  * @cfg {Boolean}   hidden          True to start the region hidden (defaults to false)
35890  * @cfg {Boolean}   hideWhenEmpty   True to hide the region when it has no panels
35891  * @cfg {Boolean}   disableTabTips  True to disable tab tooltips
35892  * @cfg {Number}    width           For East/West panels
35893  * @cfg {Number}    height          For North/South panels
35894  * @cfg {Boolean}   split           To show the splitter
35895  * @cfg {Boolean}   toolbar         xtype configuration for a toolbar - shows on right of tabbar
35896  * 
35897  * @cfg {string}   cls             Extra CSS classes to add to region
35898  * 
35899  * @cfg {Roo.bootstrap.layout.Manager}   mgr The manager
35900  * @cfg {string}   region  the region that it inhabits..
35901  *
35902
35903  * @xxxcfg {Boolean}   collapsible     DISABLED False to disable collapsing (defaults to true)
35904  * @xxxcfg {Boolean}   collapsed       DISABLED True to set the initial display to collapsed (defaults to false)
35905
35906  * @xxxcfg {String}    collapsedTitle  DISABLED Optional string message to display in the collapsed block of a north or south region
35907  * @xxxxcfg {Boolean}   floatable       DISABLED False to disable floating (defaults to true)
35908  * @xxxxcfg {Boolean}   showPin         True to show a pin button NOT SUPPORTED YET
35909  */
35910 Roo.bootstrap.layout.Region = function(config)
35911 {
35912     this.applyConfig(config);
35913
35914     var mgr = config.mgr;
35915     var pos = config.region;
35916     config.skipConfig = true;
35917     Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35918     
35919     if (mgr.el) {
35920         this.onRender(mgr.el);   
35921     }
35922      
35923     this.visible = true;
35924     this.collapsed = false;
35925     this.unrendered_panels = [];
35926 };
35927
35928 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35929
35930     position: '', // set by wrapper (eg. north/south etc..)
35931     unrendered_panels : null,  // unrendered panels.
35932     createBody : function(){
35933         /** This region's body element 
35934         * @type Roo.Element */
35935         this.bodyEl = this.el.createChild({
35936                 tag: "div",
35937                 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35938         });
35939     },
35940
35941     onRender: function(ctr, pos)
35942     {
35943         var dh = Roo.DomHelper;
35944         /** This region's container element 
35945         * @type Roo.Element */
35946         this.el = dh.append(ctr.dom, {
35947                 tag: "div",
35948                 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35949             }, true);
35950         /** This region's title element 
35951         * @type Roo.Element */
35952     
35953         this.titleEl = dh.append(this.el.dom,
35954             {
35955                     tag: "div",
35956                     unselectable: "on",
35957                     cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35958                     children:[
35959                         {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: "&#160;"},
35960                         {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35961                     ]}, true);
35962         
35963         this.titleEl.enableDisplayMode();
35964         /** This region's title text element 
35965         * @type HTMLElement */
35966         this.titleTextEl = this.titleEl.dom.firstChild;
35967         this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35968         /*
35969         this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35970         this.closeBtn.enableDisplayMode();
35971         this.closeBtn.on("click", this.closeClicked, this);
35972         this.closeBtn.hide();
35973     */
35974         this.createBody(this.config);
35975         if(this.config.hideWhenEmpty){
35976             this.hide();
35977             this.on("paneladded", this.validateVisibility, this);
35978             this.on("panelremoved", this.validateVisibility, this);
35979         }
35980         if(this.autoScroll){
35981             this.bodyEl.setStyle("overflow", "auto");
35982         }else{
35983             this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35984         }
35985         //if(c.titlebar !== false){
35986             if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35987                 this.titleEl.hide();
35988             }else{
35989                 this.titleEl.show();
35990                 if(this.config.title){
35991                     this.titleTextEl.innerHTML = this.config.title;
35992                 }
35993             }
35994         //}
35995         if(this.config.collapsed){
35996             this.collapse(true);
35997         }
35998         if(this.config.hidden){
35999             this.hide();
36000         }
36001         
36002         if (this.unrendered_panels && this.unrendered_panels.length) {
36003             for (var i =0;i< this.unrendered_panels.length; i++) {
36004                 this.add(this.unrendered_panels[i]);
36005             }
36006             this.unrendered_panels = null;
36007             
36008         }
36009         
36010     },
36011     
36012     applyConfig : function(c)
36013     {
36014         /*
36015          *if(c.collapsible && this.position != "center" && !this.collapsedEl){
36016             var dh = Roo.DomHelper;
36017             if(c.titlebar !== false){
36018                 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
36019                 this.collapseBtn.on("click", this.collapse, this);
36020                 this.collapseBtn.enableDisplayMode();
36021                 /*
36022                 if(c.showPin === true || this.showPin){
36023                     this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
36024                     this.stickBtn.enableDisplayMode();
36025                     this.stickBtn.on("click", this.expand, this);
36026                     this.stickBtn.hide();
36027                 }
36028                 
36029             }
36030             */
36031             /** This region's collapsed element
36032             * @type Roo.Element */
36033             /*
36034              *
36035             this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
36036                 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
36037             ]}, true);
36038             
36039             if(c.floatable !== false){
36040                this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
36041                this.collapsedEl.on("click", this.collapseClick, this);
36042             }
36043
36044             if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
36045                 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
36046                    id: "message", unselectable: "on", style:{"float":"left"}});
36047                this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
36048              }
36049             this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
36050             this.expandBtn.on("click", this.expand, this);
36051             
36052         }
36053         
36054         if(this.collapseBtn){
36055             this.collapseBtn.setVisible(c.collapsible == true);
36056         }
36057         
36058         this.cmargins = c.cmargins || this.cmargins ||
36059                          (this.position == "west" || this.position == "east" ?
36060                              {top: 0, left: 2, right:2, bottom: 0} :
36061                              {top: 2, left: 0, right:0, bottom: 2});
36062         */
36063         this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
36064         
36065         
36066         this.bottomTabs = c.tabPosition != "top";
36067         
36068         this.autoScroll = c.autoScroll || false;
36069         
36070         
36071        
36072         
36073         this.duration = c.duration || .30;
36074         this.slideDuration = c.slideDuration || .45;
36075         this.config = c;
36076        
36077     },
36078     /**
36079      * Returns true if this region is currently visible.
36080      * @return {Boolean}
36081      */
36082     isVisible : function(){
36083         return this.visible;
36084     },
36085
36086     /**
36087      * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
36088      * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&amp;#160;")
36089      */
36090     //setCollapsedTitle : function(title){
36091     //    title = title || "&#160;";
36092      //   if(this.collapsedTitleTextEl){
36093       //      this.collapsedTitleTextEl.innerHTML = title;
36094        // }
36095     //},
36096
36097     getBox : function(){
36098         var b;
36099       //  if(!this.collapsed){
36100             b = this.el.getBox(false, true);
36101        // }else{
36102           //  b = this.collapsedEl.getBox(false, true);
36103         //}
36104         return b;
36105     },
36106
36107     getMargins : function(){
36108         return this.margins;
36109         //return this.collapsed ? this.cmargins : this.margins;
36110     },
36111 /*
36112     highlight : function(){
36113         this.el.addClass("x-layout-panel-dragover");
36114     },
36115
36116     unhighlight : function(){
36117         this.el.removeClass("x-layout-panel-dragover");
36118     },
36119 */
36120     updateBox : function(box)
36121     {
36122         if (!this.bodyEl) {
36123             return; // not rendered yet..
36124         }
36125         
36126         this.box = box;
36127         if(!this.collapsed){
36128             this.el.dom.style.left = box.x + "px";
36129             this.el.dom.style.top = box.y + "px";
36130             this.updateBody(box.width, box.height);
36131         }else{
36132             this.collapsedEl.dom.style.left = box.x + "px";
36133             this.collapsedEl.dom.style.top = box.y + "px";
36134             this.collapsedEl.setSize(box.width, box.height);
36135         }
36136         if(this.tabs){
36137             this.tabs.autoSizeTabs();
36138         }
36139     },
36140
36141     updateBody : function(w, h)
36142     {
36143         if(w !== null){
36144             this.el.setWidth(w);
36145             w -= this.el.getBorderWidth("rl");
36146             if(this.config.adjustments){
36147                 w += this.config.adjustments[0];
36148             }
36149         }
36150         if(h !== null && h > 0){
36151             this.el.setHeight(h);
36152             h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
36153             h -= this.el.getBorderWidth("tb");
36154             if(this.config.adjustments){
36155                 h += this.config.adjustments[1];
36156             }
36157             this.bodyEl.setHeight(h);
36158             if(this.tabs){
36159                 h = this.tabs.syncHeight(h);
36160             }
36161         }
36162         if(this.panelSize){
36163             w = w !== null ? w : this.panelSize.width;
36164             h = h !== null ? h : this.panelSize.height;
36165         }
36166         if(this.activePanel){
36167             var el = this.activePanel.getEl();
36168             w = w !== null ? w : el.getWidth();
36169             h = h !== null ? h : el.getHeight();
36170             this.panelSize = {width: w, height: h};
36171             this.activePanel.setSize(w, h);
36172         }
36173         if(Roo.isIE && this.tabs){
36174             this.tabs.el.repaint();
36175         }
36176     },
36177
36178     /**
36179      * Returns the container element for this region.
36180      * @return {Roo.Element}
36181      */
36182     getEl : function(){
36183         return this.el;
36184     },
36185
36186     /**
36187      * Hides this region.
36188      */
36189     hide : function(){
36190         //if(!this.collapsed){
36191             this.el.dom.style.left = "-2000px";
36192             this.el.hide();
36193         //}else{
36194          //   this.collapsedEl.dom.style.left = "-2000px";
36195          //   this.collapsedEl.hide();
36196        // }
36197         this.visible = false;
36198         this.fireEvent("visibilitychange", this, false);
36199     },
36200
36201     /**
36202      * Shows this region if it was previously hidden.
36203      */
36204     show : function(){
36205         //if(!this.collapsed){
36206             this.el.show();
36207         //}else{
36208         //    this.collapsedEl.show();
36209        // }
36210         this.visible = true;
36211         this.fireEvent("visibilitychange", this, true);
36212     },
36213 /*
36214     closeClicked : function(){
36215         if(this.activePanel){
36216             this.remove(this.activePanel);
36217         }
36218     },
36219
36220     collapseClick : function(e){
36221         if(this.isSlid){
36222            e.stopPropagation();
36223            this.slideIn();
36224         }else{
36225            e.stopPropagation();
36226            this.slideOut();
36227         }
36228     },
36229 */
36230     /**
36231      * Collapses this region.
36232      * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
36233      */
36234     /*
36235     collapse : function(skipAnim, skipCheck = false){
36236         if(this.collapsed) {
36237             return;
36238         }
36239         
36240         if(skipCheck || this.fireEvent("beforecollapse", this) != false){
36241             
36242             this.collapsed = true;
36243             if(this.split){
36244                 this.split.el.hide();
36245             }
36246             if(this.config.animate && skipAnim !== true){
36247                 this.fireEvent("invalidated", this);
36248                 this.animateCollapse();
36249             }else{
36250                 this.el.setLocation(-20000,-20000);
36251                 this.el.hide();
36252                 this.collapsedEl.show();
36253                 this.fireEvent("collapsed", this);
36254                 this.fireEvent("invalidated", this);
36255             }
36256         }
36257         
36258     },
36259 */
36260     animateCollapse : function(){
36261         // overridden
36262     },
36263
36264     /**
36265      * Expands this region if it was previously collapsed.
36266      * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
36267      * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
36268      */
36269     /*
36270     expand : function(e, skipAnim){
36271         if(e) {
36272             e.stopPropagation();
36273         }
36274         if(!this.collapsed || this.el.hasActiveFx()) {
36275             return;
36276         }
36277         if(this.isSlid){
36278             this.afterSlideIn();
36279             skipAnim = true;
36280         }
36281         this.collapsed = false;
36282         if(this.config.animate && skipAnim !== true){
36283             this.animateExpand();
36284         }else{
36285             this.el.show();
36286             if(this.split){
36287                 this.split.el.show();
36288             }
36289             this.collapsedEl.setLocation(-2000,-2000);
36290             this.collapsedEl.hide();
36291             this.fireEvent("invalidated", this);
36292             this.fireEvent("expanded", this);
36293         }
36294     },
36295 */
36296     animateExpand : function(){
36297         // overridden
36298     },
36299
36300     initTabs : function()
36301     {
36302         //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
36303         
36304         var ts = new Roo.bootstrap.panel.Tabs({
36305                 el: this.bodyEl.dom,
36306                 tabPosition: this.bottomTabs ? 'bottom' : 'top',
36307                 disableTooltips: this.config.disableTabTips,
36308                 toolbar : this.config.toolbar
36309             });
36310         
36311         if(this.config.hideTabs){
36312             ts.stripWrap.setDisplayed(false);
36313         }
36314         this.tabs = ts;
36315         ts.resizeTabs = this.config.resizeTabs === true;
36316         ts.minTabWidth = this.config.minTabWidth || 40;
36317         ts.maxTabWidth = this.config.maxTabWidth || 250;
36318         ts.preferredTabWidth = this.config.preferredTabWidth || 150;
36319         ts.monitorResize = false;
36320         //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
36321         ts.bodyEl.addClass('roo-layout-tabs-body');
36322         this.panels.each(this.initPanelAsTab, this);
36323     },
36324
36325     initPanelAsTab : function(panel){
36326         var ti = this.tabs.addTab(
36327             panel.getEl().id,
36328             panel.getTitle(),
36329             null,
36330             this.config.closeOnTab && panel.isClosable(),
36331             panel.tpl
36332         );
36333         if(panel.tabTip !== undefined){
36334             ti.setTooltip(panel.tabTip);
36335         }
36336         ti.on("activate", function(){
36337               this.setActivePanel(panel);
36338         }, this);
36339         
36340         if(this.config.closeOnTab){
36341             ti.on("beforeclose", function(t, e){
36342                 e.cancel = true;
36343                 this.remove(panel);
36344             }, this);
36345         }
36346         
36347         panel.tabItem = ti;
36348         
36349         return ti;
36350     },
36351
36352     updatePanelTitle : function(panel, title)
36353     {
36354         if(this.activePanel == panel){
36355             this.updateTitle(title);
36356         }
36357         if(this.tabs){
36358             var ti = this.tabs.getTab(panel.getEl().id);
36359             ti.setText(title);
36360             if(panel.tabTip !== undefined){
36361                 ti.setTooltip(panel.tabTip);
36362             }
36363         }
36364     },
36365
36366     updateTitle : function(title){
36367         if(this.titleTextEl && !this.config.title){
36368             this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : "&#160;");
36369         }
36370     },
36371
36372     setActivePanel : function(panel)
36373     {
36374         panel = this.getPanel(panel);
36375         if(this.activePanel && this.activePanel != panel){
36376             if(this.activePanel.setActiveState(false) === false){
36377                 return;
36378             }
36379         }
36380         this.activePanel = panel;
36381         panel.setActiveState(true);
36382         if(this.panelSize){
36383             panel.setSize(this.panelSize.width, this.panelSize.height);
36384         }
36385         if(this.closeBtn){
36386             this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
36387         }
36388         this.updateTitle(panel.getTitle());
36389         if(this.tabs){
36390             this.fireEvent("invalidated", this);
36391         }
36392         this.fireEvent("panelactivated", this, panel);
36393     },
36394
36395     /**
36396      * Shows the specified panel.
36397      * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
36398      * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
36399      */
36400     showPanel : function(panel)
36401     {
36402         panel = this.getPanel(panel);
36403         if(panel){
36404             if(this.tabs){
36405                 var tab = this.tabs.getTab(panel.getEl().id);
36406                 if(tab.isHidden()){
36407                     this.tabs.unhideTab(tab.id);
36408                 }
36409                 tab.activate();
36410             }else{
36411                 this.setActivePanel(panel);
36412             }
36413         }
36414         return panel;
36415     },
36416
36417     /**
36418      * Get the active panel for this region.
36419      * @return {Roo.ContentPanel} The active panel or null
36420      */
36421     getActivePanel : function(){
36422         return this.activePanel;
36423     },
36424
36425     validateVisibility : function(){
36426         if(this.panels.getCount() < 1){
36427             this.updateTitle("&#160;");
36428             this.closeBtn.hide();
36429             this.hide();
36430         }else{
36431             if(!this.isVisible()){
36432                 this.show();
36433             }
36434         }
36435     },
36436
36437     /**
36438      * Adds the passed ContentPanel(s) to this region.
36439      * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
36440      * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
36441      */
36442     add : function(panel)
36443     {
36444         if(arguments.length > 1){
36445             for(var i = 0, len = arguments.length; i < len; i++) {
36446                 this.add(arguments[i]);
36447             }
36448             return null;
36449         }
36450         
36451         // if we have not been rendered yet, then we can not really do much of this..
36452         if (!this.bodyEl) {
36453             this.unrendered_panels.push(panel);
36454             return panel;
36455         }
36456         
36457         
36458         
36459         
36460         if(this.hasPanel(panel)){
36461             this.showPanel(panel);
36462             return panel;
36463         }
36464         panel.setRegion(this);
36465         this.panels.add(panel);
36466        /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
36467             // sinle panel - no tab...?? would it not be better to render it with the tabs,
36468             // and hide them... ???
36469             this.bodyEl.dom.appendChild(panel.getEl().dom);
36470             if(panel.background !== true){
36471                 this.setActivePanel(panel);
36472             }
36473             this.fireEvent("paneladded", this, panel);
36474             return panel;
36475         }
36476         */
36477         if(!this.tabs){
36478             this.initTabs();
36479         }else{
36480             this.initPanelAsTab(panel);
36481         }
36482         
36483         
36484         if(panel.background !== true){
36485             this.tabs.activate(panel.getEl().id);
36486         }
36487         this.fireEvent("paneladded", this, panel);
36488         return panel;
36489     },
36490
36491     /**
36492      * Hides the tab for the specified panel.
36493      * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36494      */
36495     hidePanel : function(panel){
36496         if(this.tabs && (panel = this.getPanel(panel))){
36497             this.tabs.hideTab(panel.getEl().id);
36498         }
36499     },
36500
36501     /**
36502      * Unhides the tab for a previously hidden panel.
36503      * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36504      */
36505     unhidePanel : function(panel){
36506         if(this.tabs && (panel = this.getPanel(panel))){
36507             this.tabs.unhideTab(panel.getEl().id);
36508         }
36509     },
36510
36511     clearPanels : function(){
36512         while(this.panels.getCount() > 0){
36513              this.remove(this.panels.first());
36514         }
36515     },
36516
36517     /**
36518      * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
36519      * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36520      * @param {Boolean} preservePanel Overrides the config preservePanel option
36521      * @return {Roo.ContentPanel} The panel that was removed
36522      */
36523     remove : function(panel, preservePanel)
36524     {
36525         panel = this.getPanel(panel);
36526         if(!panel){
36527             return null;
36528         }
36529         var e = {};
36530         this.fireEvent("beforeremove", this, panel, e);
36531         if(e.cancel === true){
36532             return null;
36533         }
36534         preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
36535         var panelId = panel.getId();
36536         this.panels.removeKey(panelId);
36537         if(preservePanel){
36538             document.body.appendChild(panel.getEl().dom);
36539         }
36540         if(this.tabs){
36541             this.tabs.removeTab(panel.getEl().id);
36542         }else if (!preservePanel){
36543             this.bodyEl.dom.removeChild(panel.getEl().dom);
36544         }
36545         if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
36546             var p = this.panels.first();
36547             var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
36548             tempEl.appendChild(p.getEl().dom);
36549             this.bodyEl.update("");
36550             this.bodyEl.dom.appendChild(p.getEl().dom);
36551             tempEl = null;
36552             this.updateTitle(p.getTitle());
36553             this.tabs = null;
36554             this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
36555             this.setActivePanel(p);
36556         }
36557         panel.setRegion(null);
36558         if(this.activePanel == panel){
36559             this.activePanel = null;
36560         }
36561         if(this.config.autoDestroy !== false && preservePanel !== true){
36562             try{panel.destroy();}catch(e){}
36563         }
36564         this.fireEvent("panelremoved", this, panel);
36565         return panel;
36566     },
36567
36568     /**
36569      * Returns the TabPanel component used by this region
36570      * @return {Roo.TabPanel}
36571      */
36572     getTabs : function(){
36573         return this.tabs;
36574     },
36575
36576     createTool : function(parentEl, className){
36577         var btn = Roo.DomHelper.append(parentEl, {
36578             tag: "div",
36579             cls: "x-layout-tools-button",
36580             children: [ {
36581                 tag: "div",
36582                 cls: "roo-layout-tools-button-inner " + className,
36583                 html: "&#160;"
36584             }]
36585         }, true);
36586         btn.addClassOnOver("roo-layout-tools-button-over");
36587         return btn;
36588     }
36589 });/*
36590  * Based on:
36591  * Ext JS Library 1.1.1
36592  * Copyright(c) 2006-2007, Ext JS, LLC.
36593  *
36594  * Originally Released Under LGPL - original licence link has changed is not relivant.
36595  *
36596  * Fork - LGPL
36597  * <script type="text/javascript">
36598  */
36599  
36600
36601
36602 /**
36603  * @class Roo.SplitLayoutRegion
36604  * @extends Roo.LayoutRegion
36605  * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
36606  */
36607 Roo.bootstrap.layout.Split = function(config){
36608     this.cursor = config.cursor;
36609     Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
36610 };
36611
36612 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
36613 {
36614     splitTip : "Drag to resize.",
36615     collapsibleSplitTip : "Drag to resize. Double click to hide.",
36616     useSplitTips : false,
36617
36618     applyConfig : function(config){
36619         Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
36620     },
36621     
36622     onRender : function(ctr,pos) {
36623         
36624         Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
36625         if(!this.config.split){
36626             return;
36627         }
36628         if(!this.split){
36629             
36630             var splitEl = Roo.DomHelper.append(ctr.dom,  {
36631                             tag: "div",
36632                             id: this.el.id + "-split",
36633                             cls: "roo-layout-split roo-layout-split-"+this.position,
36634                             html: "&#160;"
36635             });
36636             /** The SplitBar for this region 
36637             * @type Roo.SplitBar */
36638             // does not exist yet...
36639             Roo.log([this.position, this.orientation]);
36640             
36641             this.split = new Roo.bootstrap.SplitBar({
36642                 dragElement : splitEl,
36643                 resizingElement: this.el,
36644                 orientation : this.orientation
36645             });
36646             
36647             this.split.on("moved", this.onSplitMove, this);
36648             this.split.useShim = this.config.useShim === true;
36649             this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
36650             if(this.useSplitTips){
36651                 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
36652             }
36653             //if(config.collapsible){
36654             //    this.split.el.on("dblclick", this.collapse,  this);
36655             //}
36656         }
36657         if(typeof this.config.minSize != "undefined"){
36658             this.split.minSize = this.config.minSize;
36659         }
36660         if(typeof this.config.maxSize != "undefined"){
36661             this.split.maxSize = this.config.maxSize;
36662         }
36663         if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
36664             this.hideSplitter();
36665         }
36666         
36667     },
36668
36669     getHMaxSize : function(){
36670          var cmax = this.config.maxSize || 10000;
36671          var center = this.mgr.getRegion("center");
36672          return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
36673     },
36674
36675     getVMaxSize : function(){
36676          var cmax = this.config.maxSize || 10000;
36677          var center = this.mgr.getRegion("center");
36678          return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
36679     },
36680
36681     onSplitMove : function(split, newSize){
36682         this.fireEvent("resized", this, newSize);
36683     },
36684     
36685     /** 
36686      * Returns the {@link Roo.SplitBar} for this region.
36687      * @return {Roo.SplitBar}
36688      */
36689     getSplitBar : function(){
36690         return this.split;
36691     },
36692     
36693     hide : function(){
36694         this.hideSplitter();
36695         Roo.bootstrap.layout.Split.superclass.hide.call(this);
36696     },
36697
36698     hideSplitter : function(){
36699         if(this.split){
36700             this.split.el.setLocation(-2000,-2000);
36701             this.split.el.hide();
36702         }
36703     },
36704
36705     show : function(){
36706         if(this.split){
36707             this.split.el.show();
36708         }
36709         Roo.bootstrap.layout.Split.superclass.show.call(this);
36710     },
36711     
36712     beforeSlide: function(){
36713         if(Roo.isGecko){// firefox overflow auto bug workaround
36714             this.bodyEl.clip();
36715             if(this.tabs) {
36716                 this.tabs.bodyEl.clip();
36717             }
36718             if(this.activePanel){
36719                 this.activePanel.getEl().clip();
36720                 
36721                 if(this.activePanel.beforeSlide){
36722                     this.activePanel.beforeSlide();
36723                 }
36724             }
36725         }
36726     },
36727     
36728     afterSlide : function(){
36729         if(Roo.isGecko){// firefox overflow auto bug workaround
36730             this.bodyEl.unclip();
36731             if(this.tabs) {
36732                 this.tabs.bodyEl.unclip();
36733             }
36734             if(this.activePanel){
36735                 this.activePanel.getEl().unclip();
36736                 if(this.activePanel.afterSlide){
36737                     this.activePanel.afterSlide();
36738                 }
36739             }
36740         }
36741     },
36742
36743     initAutoHide : function(){
36744         if(this.autoHide !== false){
36745             if(!this.autoHideHd){
36746                 var st = new Roo.util.DelayedTask(this.slideIn, this);
36747                 this.autoHideHd = {
36748                     "mouseout": function(e){
36749                         if(!e.within(this.el, true)){
36750                             st.delay(500);
36751                         }
36752                     },
36753                     "mouseover" : function(e){
36754                         st.cancel();
36755                     },
36756                     scope : this
36757                 };
36758             }
36759             this.el.on(this.autoHideHd);
36760         }
36761     },
36762
36763     clearAutoHide : function(){
36764         if(this.autoHide !== false){
36765             this.el.un("mouseout", this.autoHideHd.mouseout);
36766             this.el.un("mouseover", this.autoHideHd.mouseover);
36767         }
36768     },
36769
36770     clearMonitor : function(){
36771         Roo.get(document).un("click", this.slideInIf, this);
36772     },
36773
36774     // these names are backwards but not changed for compat
36775     slideOut : function(){
36776         if(this.isSlid || this.el.hasActiveFx()){
36777             return;
36778         }
36779         this.isSlid = true;
36780         if(this.collapseBtn){
36781             this.collapseBtn.hide();
36782         }
36783         this.closeBtnState = this.closeBtn.getStyle('display');
36784         this.closeBtn.hide();
36785         if(this.stickBtn){
36786             this.stickBtn.show();
36787         }
36788         this.el.show();
36789         this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
36790         this.beforeSlide();
36791         this.el.setStyle("z-index", 10001);
36792         this.el.slideIn(this.getSlideAnchor(), {
36793             callback: function(){
36794                 this.afterSlide();
36795                 this.initAutoHide();
36796                 Roo.get(document).on("click", this.slideInIf, this);
36797                 this.fireEvent("slideshow", this);
36798             },
36799             scope: this,
36800             block: true
36801         });
36802     },
36803
36804     afterSlideIn : function(){
36805         this.clearAutoHide();
36806         this.isSlid = false;
36807         this.clearMonitor();
36808         this.el.setStyle("z-index", "");
36809         if(this.collapseBtn){
36810             this.collapseBtn.show();
36811         }
36812         this.closeBtn.setStyle('display', this.closeBtnState);
36813         if(this.stickBtn){
36814             this.stickBtn.hide();
36815         }
36816         this.fireEvent("slidehide", this);
36817     },
36818
36819     slideIn : function(cb){
36820         if(!this.isSlid || this.el.hasActiveFx()){
36821             Roo.callback(cb);
36822             return;
36823         }
36824         this.isSlid = false;
36825         this.beforeSlide();
36826         this.el.slideOut(this.getSlideAnchor(), {
36827             callback: function(){
36828                 this.el.setLeftTop(-10000, -10000);
36829                 this.afterSlide();
36830                 this.afterSlideIn();
36831                 Roo.callback(cb);
36832             },
36833             scope: this,
36834             block: true
36835         });
36836     },
36837     
36838     slideInIf : function(e){
36839         if(!e.within(this.el)){
36840             this.slideIn();
36841         }
36842     },
36843
36844     animateCollapse : function(){
36845         this.beforeSlide();
36846         this.el.setStyle("z-index", 20000);
36847         var anchor = this.getSlideAnchor();
36848         this.el.slideOut(anchor, {
36849             callback : function(){
36850                 this.el.setStyle("z-index", "");
36851                 this.collapsedEl.slideIn(anchor, {duration:.3});
36852                 this.afterSlide();
36853                 this.el.setLocation(-10000,-10000);
36854                 this.el.hide();
36855                 this.fireEvent("collapsed", this);
36856             },
36857             scope: this,
36858             block: true
36859         });
36860     },
36861
36862     animateExpand : function(){
36863         this.beforeSlide();
36864         this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36865         this.el.setStyle("z-index", 20000);
36866         this.collapsedEl.hide({
36867             duration:.1
36868         });
36869         this.el.slideIn(this.getSlideAnchor(), {
36870             callback : function(){
36871                 this.el.setStyle("z-index", "");
36872                 this.afterSlide();
36873                 if(this.split){
36874                     this.split.el.show();
36875                 }
36876                 this.fireEvent("invalidated", this);
36877                 this.fireEvent("expanded", this);
36878             },
36879             scope: this,
36880             block: true
36881         });
36882     },
36883
36884     anchors : {
36885         "west" : "left",
36886         "east" : "right",
36887         "north" : "top",
36888         "south" : "bottom"
36889     },
36890
36891     sanchors : {
36892         "west" : "l",
36893         "east" : "r",
36894         "north" : "t",
36895         "south" : "b"
36896     },
36897
36898     canchors : {
36899         "west" : "tl-tr",
36900         "east" : "tr-tl",
36901         "north" : "tl-bl",
36902         "south" : "bl-tl"
36903     },
36904
36905     getAnchor : function(){
36906         return this.anchors[this.position];
36907     },
36908
36909     getCollapseAnchor : function(){
36910         return this.canchors[this.position];
36911     },
36912
36913     getSlideAnchor : function(){
36914         return this.sanchors[this.position];
36915     },
36916
36917     getAlignAdj : function(){
36918         var cm = this.cmargins;
36919         switch(this.position){
36920             case "west":
36921                 return [0, 0];
36922             break;
36923             case "east":
36924                 return [0, 0];
36925             break;
36926             case "north":
36927                 return [0, 0];
36928             break;
36929             case "south":
36930                 return [0, 0];
36931             break;
36932         }
36933     },
36934
36935     getExpandAdj : function(){
36936         var c = this.collapsedEl, cm = this.cmargins;
36937         switch(this.position){
36938             case "west":
36939                 return [-(cm.right+c.getWidth()+cm.left), 0];
36940             break;
36941             case "east":
36942                 return [cm.right+c.getWidth()+cm.left, 0];
36943             break;
36944             case "north":
36945                 return [0, -(cm.top+cm.bottom+c.getHeight())];
36946             break;
36947             case "south":
36948                 return [0, cm.top+cm.bottom+c.getHeight()];
36949             break;
36950         }
36951     }
36952 });/*
36953  * Based on:
36954  * Ext JS Library 1.1.1
36955  * Copyright(c) 2006-2007, Ext JS, LLC.
36956  *
36957  * Originally Released Under LGPL - original licence link has changed is not relivant.
36958  *
36959  * Fork - LGPL
36960  * <script type="text/javascript">
36961  */
36962 /*
36963  * These classes are private internal classes
36964  */
36965 Roo.bootstrap.layout.Center = function(config){
36966     config.region = "center";
36967     Roo.bootstrap.layout.Region.call(this, config);
36968     this.visible = true;
36969     this.minWidth = config.minWidth || 20;
36970     this.minHeight = config.minHeight || 20;
36971 };
36972
36973 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36974     hide : function(){
36975         // center panel can't be hidden
36976     },
36977     
36978     show : function(){
36979         // center panel can't be hidden
36980     },
36981     
36982     getMinWidth: function(){
36983         return this.minWidth;
36984     },
36985     
36986     getMinHeight: function(){
36987         return this.minHeight;
36988     }
36989 });
36990
36991
36992
36993
36994  
36995
36996
36997
36998
36999
37000 Roo.bootstrap.layout.North = function(config)
37001 {
37002     config.region = 'north';
37003     config.cursor = 'n-resize';
37004     
37005     Roo.bootstrap.layout.Split.call(this, config);
37006     
37007     
37008     if(this.split){
37009         this.split.placement = Roo.bootstrap.SplitBar.TOP;
37010         this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
37011         this.split.el.addClass("roo-layout-split-v");
37012     }
37013     var size = config.initialSize || config.height;
37014     if(typeof size != "undefined"){
37015         this.el.setHeight(size);
37016     }
37017 };
37018 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
37019 {
37020     orientation: Roo.bootstrap.SplitBar.VERTICAL,
37021     
37022     
37023     
37024     getBox : function(){
37025         if(this.collapsed){
37026             return this.collapsedEl.getBox();
37027         }
37028         var box = this.el.getBox();
37029         if(this.split){
37030             box.height += this.split.el.getHeight();
37031         }
37032         return box;
37033     },
37034     
37035     updateBox : function(box){
37036         if(this.split && !this.collapsed){
37037             box.height -= this.split.el.getHeight();
37038             this.split.el.setLeft(box.x);
37039             this.split.el.setTop(box.y+box.height);
37040             this.split.el.setWidth(box.width);
37041         }
37042         if(this.collapsed){
37043             this.updateBody(box.width, null);
37044         }
37045         Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
37046     }
37047 });
37048
37049
37050
37051
37052
37053 Roo.bootstrap.layout.South = function(config){
37054     config.region = 'south';
37055     config.cursor = 's-resize';
37056     Roo.bootstrap.layout.Split.call(this, config);
37057     if(this.split){
37058         this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
37059         this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
37060         this.split.el.addClass("roo-layout-split-v");
37061     }
37062     var size = config.initialSize || config.height;
37063     if(typeof size != "undefined"){
37064         this.el.setHeight(size);
37065     }
37066 };
37067
37068 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
37069     orientation: Roo.bootstrap.SplitBar.VERTICAL,
37070     getBox : function(){
37071         if(this.collapsed){
37072             return this.collapsedEl.getBox();
37073         }
37074         var box = this.el.getBox();
37075         if(this.split){
37076             var sh = this.split.el.getHeight();
37077             box.height += sh;
37078             box.y -= sh;
37079         }
37080         return box;
37081     },
37082     
37083     updateBox : function(box){
37084         if(this.split && !this.collapsed){
37085             var sh = this.split.el.getHeight();
37086             box.height -= sh;
37087             box.y += sh;
37088             this.split.el.setLeft(box.x);
37089             this.split.el.setTop(box.y-sh);
37090             this.split.el.setWidth(box.width);
37091         }
37092         if(this.collapsed){
37093             this.updateBody(box.width, null);
37094         }
37095         Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
37096     }
37097 });
37098
37099 Roo.bootstrap.layout.East = function(config){
37100     config.region = "east";
37101     config.cursor = "e-resize";
37102     Roo.bootstrap.layout.Split.call(this, config);
37103     if(this.split){
37104         this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
37105         this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
37106         this.split.el.addClass("roo-layout-split-h");
37107     }
37108     var size = config.initialSize || config.width;
37109     if(typeof size != "undefined"){
37110         this.el.setWidth(size);
37111     }
37112 };
37113 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
37114     orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
37115     getBox : function(){
37116         if(this.collapsed){
37117             return this.collapsedEl.getBox();
37118         }
37119         var box = this.el.getBox();
37120         if(this.split){
37121             var sw = this.split.el.getWidth();
37122             box.width += sw;
37123             box.x -= sw;
37124         }
37125         return box;
37126     },
37127
37128     updateBox : function(box){
37129         if(this.split && !this.collapsed){
37130             var sw = this.split.el.getWidth();
37131             box.width -= sw;
37132             this.split.el.setLeft(box.x);
37133             this.split.el.setTop(box.y);
37134             this.split.el.setHeight(box.height);
37135             box.x += sw;
37136         }
37137         if(this.collapsed){
37138             this.updateBody(null, box.height);
37139         }
37140         Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
37141     }
37142 });
37143
37144 Roo.bootstrap.layout.West = function(config){
37145     config.region = "west";
37146     config.cursor = "w-resize";
37147     
37148     Roo.bootstrap.layout.Split.call(this, config);
37149     if(this.split){
37150         this.split.placement = Roo.bootstrap.SplitBar.LEFT;
37151         this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
37152         this.split.el.addClass("roo-layout-split-h");
37153     }
37154     
37155 };
37156 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
37157     orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
37158     
37159     onRender: function(ctr, pos)
37160     {
37161         Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
37162         var size = this.config.initialSize || this.config.width;
37163         if(typeof size != "undefined"){
37164             this.el.setWidth(size);
37165         }
37166     },
37167     
37168     getBox : function(){
37169         if(this.collapsed){
37170             return this.collapsedEl.getBox();
37171         }
37172         var box = this.el.getBox();
37173         if(this.split){
37174             box.width += this.split.el.getWidth();
37175         }
37176         return box;
37177     },
37178     
37179     updateBox : function(box){
37180         if(this.split && !this.collapsed){
37181             var sw = this.split.el.getWidth();
37182             box.width -= sw;
37183             this.split.el.setLeft(box.x+box.width);
37184             this.split.el.setTop(box.y);
37185             this.split.el.setHeight(box.height);
37186         }
37187         if(this.collapsed){
37188             this.updateBody(null, box.height);
37189         }
37190         Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
37191     }
37192 });
37193 Roo.namespace("Roo.bootstrap.panel");/*
37194  * Based on:
37195  * Ext JS Library 1.1.1
37196  * Copyright(c) 2006-2007, Ext JS, LLC.
37197  *
37198  * Originally Released Under LGPL - original licence link has changed is not relivant.
37199  *
37200  * Fork - LGPL
37201  * <script type="text/javascript">
37202  */
37203 /**
37204  * @class Roo.ContentPanel
37205  * @extends Roo.util.Observable
37206  * A basic ContentPanel element.
37207  * @cfg {Boolean}   fitToFrame    True for this panel to adjust its size to fit when the region resizes  (defaults to false)
37208  * @cfg {Boolean}   fitContainer   When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container  (defaults to false)
37209  * @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
37210  * @cfg {Boolean}   closable      True if the panel can be closed/removed
37211  * @cfg {Boolean}   background    True if the panel should not be activated when it is added (defaults to false)
37212  * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
37213  * @cfg {Toolbar}   toolbar       A toolbar for this panel
37214  * @cfg {Boolean} autoScroll    True to scroll overflow in this panel (use with {@link #fitToFrame})
37215  * @cfg {String} title          The title for this panel
37216  * @cfg {Array} adjustments     Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
37217  * @cfg {String} url            Calls {@link #setUrl} with this value
37218  * @cfg {String} region         (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
37219  * @cfg {String/Object} params  When used with {@link #url}, calls {@link #setUrl} with this value
37220  * @cfg {Boolean} loadOnce      When used with {@link #url}, calls {@link #setUrl} with this value
37221  * @cfg {String}    content        Raw content to fill content panel with (uses setContent on construction.)
37222  * @cfg {Boolean} badges render the badges
37223
37224  * @constructor
37225  * Create a new ContentPanel.
37226  * @param {String/HTMLElement/Roo.Element} el The container element for this panel
37227  * @param {String/Object} config A string to set only the title or a config object
37228  * @param {String} content (optional) Set the HTML content for this panel
37229  * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
37230  */
37231 Roo.bootstrap.panel.Content = function( config){
37232     
37233     this.tpl = config.tpl || false;
37234     
37235     var el = config.el;
37236     var content = config.content;
37237
37238     if(config.autoCreate){ // xtype is available if this is called from factory
37239         el = Roo.id();
37240     }
37241     this.el = Roo.get(el);
37242     if(!this.el && config && config.autoCreate){
37243         if(typeof config.autoCreate == "object"){
37244             if(!config.autoCreate.id){
37245                 config.autoCreate.id = config.id||el;
37246             }
37247             this.el = Roo.DomHelper.append(document.body,
37248                         config.autoCreate, true);
37249         }else{
37250             var elcfg =  {   tag: "div",
37251                             cls: "roo-layout-inactive-content",
37252                             id: config.id||el
37253                             };
37254             if (config.html) {
37255                 elcfg.html = config.html;
37256                 
37257             }
37258                         
37259             this.el = Roo.DomHelper.append(document.body, elcfg , true);
37260         }
37261     } 
37262     this.closable = false;
37263     this.loaded = false;
37264     this.active = false;
37265    
37266       
37267     if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
37268         
37269         this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
37270         
37271         this.wrapEl = this.el; //this.el.wrap();
37272         var ti = [];
37273         if (config.toolbar.items) {
37274             ti = config.toolbar.items ;
37275             delete config.toolbar.items ;
37276         }
37277         
37278         var nitems = [];
37279         this.toolbar.render(this.wrapEl, 'before');
37280         for(var i =0;i < ti.length;i++) {
37281           //  Roo.log(['add child', items[i]]);
37282             nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37283         }
37284         this.toolbar.items = nitems;
37285         this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
37286         delete config.toolbar;
37287         
37288     }
37289     /*
37290     // xtype created footer. - not sure if will work as we normally have to render first..
37291     if (this.footer && !this.footer.el && this.footer.xtype) {
37292         if (!this.wrapEl) {
37293             this.wrapEl = this.el.wrap();
37294         }
37295     
37296         this.footer.container = this.wrapEl.createChild();
37297          
37298         this.footer = Roo.factory(this.footer, Roo);
37299         
37300     }
37301     */
37302     
37303      if(typeof config == "string"){
37304         this.title = config;
37305     }else{
37306         Roo.apply(this, config);
37307     }
37308     
37309     if(this.resizeEl){
37310         this.resizeEl = Roo.get(this.resizeEl, true);
37311     }else{
37312         this.resizeEl = this.el;
37313     }
37314     // handle view.xtype
37315     
37316  
37317     
37318     
37319     this.addEvents({
37320         /**
37321          * @event activate
37322          * Fires when this panel is activated. 
37323          * @param {Roo.ContentPanel} this
37324          */
37325         "activate" : true,
37326         /**
37327          * @event deactivate
37328          * Fires when this panel is activated. 
37329          * @param {Roo.ContentPanel} this
37330          */
37331         "deactivate" : true,
37332
37333         /**
37334          * @event resize
37335          * Fires when this panel is resized if fitToFrame is true.
37336          * @param {Roo.ContentPanel} this
37337          * @param {Number} width The width after any component adjustments
37338          * @param {Number} height The height after any component adjustments
37339          */
37340         "resize" : true,
37341         
37342          /**
37343          * @event render
37344          * Fires when this tab is created
37345          * @param {Roo.ContentPanel} this
37346          */
37347         "render" : true
37348         
37349         
37350         
37351     });
37352     
37353
37354     
37355     
37356     if(this.autoScroll){
37357         this.resizeEl.setStyle("overflow", "auto");
37358     } else {
37359         // fix randome scrolling
37360         //this.el.on('scroll', function() {
37361         //    Roo.log('fix random scolling');
37362         //    this.scrollTo('top',0); 
37363         //});
37364     }
37365     content = content || this.content;
37366     if(content){
37367         this.setContent(content);
37368     }
37369     if(config && config.url){
37370         this.setUrl(this.url, this.params, this.loadOnce);
37371     }
37372     
37373     
37374     
37375     Roo.bootstrap.panel.Content.superclass.constructor.call(this);
37376     
37377     if (this.view && typeof(this.view.xtype) != 'undefined') {
37378         this.view.el = this.el.appendChild(document.createElement("div"));
37379         this.view = Roo.factory(this.view); 
37380         this.view.render  &&  this.view.render(false, '');  
37381     }
37382     
37383     
37384     this.fireEvent('render', this);
37385 };
37386
37387 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
37388     
37389     tabTip : '',
37390     
37391     setRegion : function(region){
37392         this.region = region;
37393         this.setActiveClass(region && !this.background);
37394     },
37395     
37396     
37397     setActiveClass: function(state)
37398     {
37399         if(state){
37400            this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
37401            this.el.setStyle('position','relative');
37402         }else{
37403            this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
37404            this.el.setStyle('position', 'absolute');
37405         } 
37406     },
37407     
37408     /**
37409      * Returns the toolbar for this Panel if one was configured. 
37410      * @return {Roo.Toolbar} 
37411      */
37412     getToolbar : function(){
37413         return this.toolbar;
37414     },
37415     
37416     setActiveState : function(active)
37417     {
37418         this.active = active;
37419         this.setActiveClass(active);
37420         if(!active){
37421             if(this.fireEvent("deactivate", this) === false){
37422                 return false;
37423             }
37424             return true;
37425         }
37426         this.fireEvent("activate", this);
37427         return true;
37428     },
37429     /**
37430      * Updates this panel's element
37431      * @param {String} content The new content
37432      * @param {Boolean} loadScripts (optional) true to look for and process scripts
37433     */
37434     setContent : function(content, loadScripts){
37435         this.el.update(content, loadScripts);
37436     },
37437
37438     ignoreResize : function(w, h){
37439         if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
37440             return true;
37441         }else{
37442             this.lastSize = {width: w, height: h};
37443             return false;
37444         }
37445     },
37446     /**
37447      * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
37448      * @return {Roo.UpdateManager} The UpdateManager
37449      */
37450     getUpdateManager : function(){
37451         return this.el.getUpdateManager();
37452     },
37453      /**
37454      * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
37455      * @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:
37456 <pre><code>
37457 panel.load({
37458     url: "your-url.php",
37459     params: {param1: "foo", param2: "bar"}, // or a URL encoded string
37460     callback: yourFunction,
37461     scope: yourObject, //(optional scope)
37462     discardUrl: false,
37463     nocache: false,
37464     text: "Loading...",
37465     timeout: 30,
37466     scripts: false
37467 });
37468 </code></pre>
37469      * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
37470      * 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.
37471      * @param {String/Object} params (optional) The parameters to pass as either a URL encoded string "param1=1&amp;param2=2" or an object {param1: 1, param2: 2}
37472      * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
37473      * @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.
37474      * @return {Roo.ContentPanel} this
37475      */
37476     load : function(){
37477         var um = this.el.getUpdateManager();
37478         um.update.apply(um, arguments);
37479         return this;
37480     },
37481
37482
37483     /**
37484      * 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.
37485      * @param {String/Function} url The URL to load the content from or a function to call to get the URL
37486      * @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)
37487      * @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)
37488      * @return {Roo.UpdateManager} The UpdateManager
37489      */
37490     setUrl : function(url, params, loadOnce){
37491         if(this.refreshDelegate){
37492             this.removeListener("activate", this.refreshDelegate);
37493         }
37494         this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37495         this.on("activate", this.refreshDelegate);
37496         return this.el.getUpdateManager();
37497     },
37498     
37499     _handleRefresh : function(url, params, loadOnce){
37500         if(!loadOnce || !this.loaded){
37501             var updater = this.el.getUpdateManager();
37502             updater.update(url, params, this._setLoaded.createDelegate(this));
37503         }
37504     },
37505     
37506     _setLoaded : function(){
37507         this.loaded = true;
37508     }, 
37509     
37510     /**
37511      * Returns this panel's id
37512      * @return {String} 
37513      */
37514     getId : function(){
37515         return this.el.id;
37516     },
37517     
37518     /** 
37519      * Returns this panel's element - used by regiosn to add.
37520      * @return {Roo.Element} 
37521      */
37522     getEl : function(){
37523         return this.wrapEl || this.el;
37524     },
37525     
37526    
37527     
37528     adjustForComponents : function(width, height)
37529     {
37530         //Roo.log('adjustForComponents ');
37531         if(this.resizeEl != this.el){
37532             width -= this.el.getFrameWidth('lr');
37533             height -= this.el.getFrameWidth('tb');
37534         }
37535         if(this.toolbar){
37536             var te = this.toolbar.getEl();
37537             te.setWidth(width);
37538             height -= te.getHeight();
37539         }
37540         if(this.footer){
37541             var te = this.footer.getEl();
37542             te.setWidth(width);
37543             height -= te.getHeight();
37544         }
37545         
37546         
37547         if(this.adjustments){
37548             width += this.adjustments[0];
37549             height += this.adjustments[1];
37550         }
37551         return {"width": width, "height": height};
37552     },
37553     
37554     setSize : function(width, height){
37555         if(this.fitToFrame && !this.ignoreResize(width, height)){
37556             if(this.fitContainer && this.resizeEl != this.el){
37557                 this.el.setSize(width, height);
37558             }
37559             var size = this.adjustForComponents(width, height);
37560             this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
37561             this.fireEvent('resize', this, size.width, size.height);
37562         }
37563     },
37564     
37565     /**
37566      * Returns this panel's title
37567      * @return {String} 
37568      */
37569     getTitle : function(){
37570         
37571         if (typeof(this.title) != 'object') {
37572             return this.title;
37573         }
37574         
37575         var t = '';
37576         for (var k in this.title) {
37577             if (!this.title.hasOwnProperty(k)) {
37578                 continue;
37579             }
37580             
37581             if (k.indexOf('-') >= 0) {
37582                 var s = k.split('-');
37583                 for (var i = 0; i<s.length; i++) {
37584                     t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
37585                 }
37586             } else {
37587                 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
37588             }
37589         }
37590         return t;
37591     },
37592     
37593     /**
37594      * Set this panel's title
37595      * @param {String} title
37596      */
37597     setTitle : function(title){
37598         this.title = title;
37599         if(this.region){
37600             this.region.updatePanelTitle(this, title);
37601         }
37602     },
37603     
37604     /**
37605      * Returns true is this panel was configured to be closable
37606      * @return {Boolean} 
37607      */
37608     isClosable : function(){
37609         return this.closable;
37610     },
37611     
37612     beforeSlide : function(){
37613         this.el.clip();
37614         this.resizeEl.clip();
37615     },
37616     
37617     afterSlide : function(){
37618         this.el.unclip();
37619         this.resizeEl.unclip();
37620     },
37621     
37622     /**
37623      *   Force a content refresh from the URL specified in the {@link #setUrl} method.
37624      *   Will fail silently if the {@link #setUrl} method has not been called.
37625      *   This does not activate the panel, just updates its content.
37626      */
37627     refresh : function(){
37628         if(this.refreshDelegate){
37629            this.loaded = false;
37630            this.refreshDelegate();
37631         }
37632     },
37633     
37634     /**
37635      * Destroys this panel
37636      */
37637     destroy : function(){
37638         this.el.removeAllListeners();
37639         var tempEl = document.createElement("span");
37640         tempEl.appendChild(this.el.dom);
37641         tempEl.innerHTML = "";
37642         this.el.remove();
37643         this.el = null;
37644     },
37645     
37646     /**
37647      * form - if the content panel contains a form - this is a reference to it.
37648      * @type {Roo.form.Form}
37649      */
37650     form : false,
37651     /**
37652      * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
37653      *    This contains a reference to it.
37654      * @type {Roo.View}
37655      */
37656     view : false,
37657     
37658       /**
37659      * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
37660      * <pre><code>
37661
37662 layout.addxtype({
37663        xtype : 'Form',
37664        items: [ .... ]
37665    }
37666 );
37667
37668 </code></pre>
37669      * @param {Object} cfg Xtype definition of item to add.
37670      */
37671     
37672     
37673     getChildContainer: function () {
37674         return this.getEl();
37675     }
37676     
37677     
37678     /*
37679         var  ret = new Roo.factory(cfg);
37680         return ret;
37681         
37682         
37683         // add form..
37684         if (cfg.xtype.match(/^Form$/)) {
37685             
37686             var el;
37687             //if (this.footer) {
37688             //    el = this.footer.container.insertSibling(false, 'before');
37689             //} else {
37690                 el = this.el.createChild();
37691             //}
37692
37693             this.form = new  Roo.form.Form(cfg);
37694             
37695             
37696             if ( this.form.allItems.length) {
37697                 this.form.render(el.dom);
37698             }
37699             return this.form;
37700         }
37701         // should only have one of theses..
37702         if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
37703             // views.. should not be just added - used named prop 'view''
37704             
37705             cfg.el = this.el.appendChild(document.createElement("div"));
37706             // factory?
37707             
37708             var ret = new Roo.factory(cfg);
37709              
37710              ret.render && ret.render(false, ''); // render blank..
37711             this.view = ret;
37712             return ret;
37713         }
37714         return false;
37715     }
37716     \*/
37717 });
37718  
37719 /**
37720  * @class Roo.bootstrap.panel.Grid
37721  * @extends Roo.bootstrap.panel.Content
37722  * @constructor
37723  * Create a new GridPanel.
37724  * @cfg {Roo.bootstrap.Table} grid The grid for this panel
37725  * @param {Object} config A the config object
37726   
37727  */
37728
37729
37730
37731 Roo.bootstrap.panel.Grid = function(config)
37732 {
37733     
37734       
37735     this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
37736         {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
37737
37738     config.el = this.wrapper;
37739     //this.el = this.wrapper;
37740     
37741       if (config.container) {
37742         // ctor'ed from a Border/panel.grid
37743         
37744         
37745         this.wrapper.setStyle("overflow", "hidden");
37746         this.wrapper.addClass('roo-grid-container');
37747
37748     }
37749     
37750     
37751     if(config.toolbar){
37752         var tool_el = this.wrapper.createChild();    
37753         this.toolbar = Roo.factory(config.toolbar);
37754         var ti = [];
37755         if (config.toolbar.items) {
37756             ti = config.toolbar.items ;
37757             delete config.toolbar.items ;
37758         }
37759         
37760         var nitems = [];
37761         this.toolbar.render(tool_el);
37762         for(var i =0;i < ti.length;i++) {
37763           //  Roo.log(['add child', items[i]]);
37764             nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37765         }
37766         this.toolbar.items = nitems;
37767         
37768         delete config.toolbar;
37769     }
37770     
37771     Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
37772     config.grid.scrollBody = true;;
37773     config.grid.monitorWindowResize = false; // turn off autosizing
37774     config.grid.autoHeight = false;
37775     config.grid.autoWidth = false;
37776     
37777     this.grid = new config.grid.xns[config.grid.xtype](config.grid);
37778     
37779     if (config.background) {
37780         // render grid on panel activation (if panel background)
37781         this.on('activate', function(gp) {
37782             if (!gp.grid.rendered) {
37783                 gp.grid.render(this.wrapper);
37784                 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");   
37785             }
37786         });
37787             
37788     } else {
37789         this.grid.render(this.wrapper);
37790         this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");               
37791
37792     }
37793     //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
37794     // ??? needed ??? config.el = this.wrapper;
37795     
37796     
37797     
37798   
37799     // xtype created footer. - not sure if will work as we normally have to render first..
37800     if (this.footer && !this.footer.el && this.footer.xtype) {
37801         
37802         var ctr = this.grid.getView().getFooterPanel(true);
37803         this.footer.dataSource = this.grid.dataSource;
37804         this.footer = Roo.factory(this.footer, Roo);
37805         this.footer.render(ctr);
37806         
37807     }
37808     
37809     
37810     
37811     
37812      
37813 };
37814
37815 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37816     getId : function(){
37817         return this.grid.id;
37818     },
37819     
37820     /**
37821      * Returns the grid for this panel
37822      * @return {Roo.bootstrap.Table} 
37823      */
37824     getGrid : function(){
37825         return this.grid;    
37826     },
37827     
37828     setSize : function(width, height){
37829         if(!this.ignoreResize(width, height)){
37830             var grid = this.grid;
37831             var size = this.adjustForComponents(width, height);
37832             var gridel = grid.getGridEl();
37833             gridel.setSize(size.width, size.height);
37834             /*
37835             var thd = grid.getGridEl().select('thead',true).first();
37836             var tbd = grid.getGridEl().select('tbody', true).first();
37837             if (tbd) {
37838                 tbd.setSize(width, height - thd.getHeight());
37839             }
37840             */
37841             grid.autoSize();
37842         }
37843     },
37844      
37845     
37846     
37847     beforeSlide : function(){
37848         this.grid.getView().scroller.clip();
37849     },
37850     
37851     afterSlide : function(){
37852         this.grid.getView().scroller.unclip();
37853     },
37854     
37855     destroy : function(){
37856         this.grid.destroy();
37857         delete this.grid;
37858         Roo.bootstrap.panel.Grid.superclass.destroy.call(this); 
37859     }
37860 });
37861
37862 /**
37863  * @class Roo.bootstrap.panel.Nest
37864  * @extends Roo.bootstrap.panel.Content
37865  * @constructor
37866  * Create a new Panel, that can contain a layout.Border.
37867  * 
37868  * 
37869  * @param {Roo.BorderLayout} layout The layout for this panel
37870  * @param {String/Object} config A string to set only the title or a config object
37871  */
37872 Roo.bootstrap.panel.Nest = function(config)
37873 {
37874     // construct with only one argument..
37875     /* FIXME - implement nicer consturctors
37876     if (layout.layout) {
37877         config = layout;
37878         layout = config.layout;
37879         delete config.layout;
37880     }
37881     if (layout.xtype && !layout.getEl) {
37882         // then layout needs constructing..
37883         layout = Roo.factory(layout, Roo);
37884     }
37885     */
37886     
37887     config.el =  config.layout.getEl();
37888     
37889     Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37890     
37891     config.layout.monitorWindowResize = false; // turn off autosizing
37892     this.layout = config.layout;
37893     this.layout.getEl().addClass("roo-layout-nested-layout");
37894     
37895     
37896     
37897     
37898 };
37899
37900 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37901
37902     setSize : function(width, height){
37903         if(!this.ignoreResize(width, height)){
37904             var size = this.adjustForComponents(width, height);
37905             var el = this.layout.getEl();
37906             if (size.height < 1) {
37907                 el.setWidth(size.width);   
37908             } else {
37909                 el.setSize(size.width, size.height);
37910             }
37911             var touch = el.dom.offsetWidth;
37912             this.layout.layout();
37913             // ie requires a double layout on the first pass
37914             if(Roo.isIE && !this.initialized){
37915                 this.initialized = true;
37916                 this.layout.layout();
37917             }
37918         }
37919     },
37920     
37921     // activate all subpanels if not currently active..
37922     
37923     setActiveState : function(active){
37924         this.active = active;
37925         this.setActiveClass(active);
37926         
37927         if(!active){
37928             this.fireEvent("deactivate", this);
37929             return;
37930         }
37931         
37932         this.fireEvent("activate", this);
37933         // not sure if this should happen before or after..
37934         if (!this.layout) {
37935             return; // should not happen..
37936         }
37937         var reg = false;
37938         for (var r in this.layout.regions) {
37939             reg = this.layout.getRegion(r);
37940             if (reg.getActivePanel()) {
37941                 //reg.showPanel(reg.getActivePanel()); // force it to activate.. 
37942                 reg.setActivePanel(reg.getActivePanel());
37943                 continue;
37944             }
37945             if (!reg.panels.length) {
37946                 continue;
37947             }
37948             reg.showPanel(reg.getPanel(0));
37949         }
37950         
37951         
37952         
37953         
37954     },
37955     
37956     /**
37957      * Returns the nested BorderLayout for this panel
37958      * @return {Roo.BorderLayout} 
37959      */
37960     getLayout : function(){
37961         return this.layout;
37962     },
37963     
37964      /**
37965      * Adds a xtype elements to the layout of the nested panel
37966      * <pre><code>
37967
37968 panel.addxtype({
37969        xtype : 'ContentPanel',
37970        region: 'west',
37971        items: [ .... ]
37972    }
37973 );
37974
37975 panel.addxtype({
37976         xtype : 'NestedLayoutPanel',
37977         region: 'west',
37978         layout: {
37979            center: { },
37980            west: { }   
37981         },
37982         items : [ ... list of content panels or nested layout panels.. ]
37983    }
37984 );
37985 </code></pre>
37986      * @param {Object} cfg Xtype definition of item to add.
37987      */
37988     addxtype : function(cfg) {
37989         return this.layout.addxtype(cfg);
37990     
37991     }
37992 });        /*
37993  * Based on:
37994  * Ext JS Library 1.1.1
37995  * Copyright(c) 2006-2007, Ext JS, LLC.
37996  *
37997  * Originally Released Under LGPL - original licence link has changed is not relivant.
37998  *
37999  * Fork - LGPL
38000  * <script type="text/javascript">
38001  */
38002 /**
38003  * @class Roo.TabPanel
38004  * @extends Roo.util.Observable
38005  * A lightweight tab container.
38006  * <br><br>
38007  * Usage:
38008  * <pre><code>
38009 // basic tabs 1, built from existing content
38010 var tabs = new Roo.TabPanel("tabs1");
38011 tabs.addTab("script", "View Script");
38012 tabs.addTab("markup", "View Markup");
38013 tabs.activate("script");
38014
38015 // more advanced tabs, built from javascript
38016 var jtabs = new Roo.TabPanel("jtabs");
38017 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
38018
38019 // set up the UpdateManager
38020 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
38021 var updater = tab2.getUpdateManager();
38022 updater.setDefaultUrl("ajax1.htm");
38023 tab2.on('activate', updater.refresh, updater, true);
38024
38025 // Use setUrl for Ajax loading
38026 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
38027 tab3.setUrl("ajax2.htm", null, true);
38028
38029 // Disabled tab
38030 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
38031 tab4.disable();
38032
38033 jtabs.activate("jtabs-1");
38034  * </code></pre>
38035  * @constructor
38036  * Create a new TabPanel.
38037  * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
38038  * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
38039  */
38040 Roo.bootstrap.panel.Tabs = function(config){
38041     /**
38042     * The container element for this TabPanel.
38043     * @type Roo.Element
38044     */
38045     this.el = Roo.get(config.el);
38046     delete config.el;
38047     if(config){
38048         if(typeof config == "boolean"){
38049             this.tabPosition = config ? "bottom" : "top";
38050         }else{
38051             Roo.apply(this, config);
38052         }
38053     }
38054     
38055     if(this.tabPosition == "bottom"){
38056         this.bodyEl = Roo.get(this.createBody(this.el.dom));
38057         this.el.addClass("roo-tabs-bottom");
38058     }
38059     this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
38060     this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
38061     this.stripEl.setVisibilityMode(Roo.Element.DISPLAY);
38062     this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
38063     if(Roo.isIE){
38064         Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
38065     }
38066     if(this.tabPosition != "bottom"){
38067         /** The body element that contains {@link Roo.TabPanelItem} bodies. +
38068          * @type Roo.Element
38069          */
38070         this.bodyEl = Roo.get(this.createBody(this.el.dom));
38071         this.el.addClass("roo-tabs-top");
38072     }
38073     this.items = [];
38074
38075     this.bodyEl.setStyle("position", "relative");
38076
38077     this.active = null;
38078     this.activateDelegate = this.activate.createDelegate(this);
38079
38080     this.addEvents({
38081         /**
38082          * @event tabchange
38083          * Fires when the active tab changes
38084          * @param {Roo.TabPanel} this
38085          * @param {Roo.TabPanelItem} activePanel The new active tab
38086          */
38087         "tabchange": true,
38088         /**
38089          * @event beforetabchange
38090          * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
38091          * @param {Roo.TabPanel} this
38092          * @param {Object} e Set cancel to true on this object to cancel the tab change
38093          * @param {Roo.TabPanelItem} tab The tab being changed to
38094          */
38095         "beforetabchange" : true
38096     });
38097
38098     Roo.EventManager.onWindowResize(this.onResize, this);
38099     this.cpad = this.el.getPadding("lr");
38100     this.hiddenCount = 0;
38101
38102
38103     // toolbar on the tabbar support...
38104     if (this.toolbar) {
38105         alert("no toolbar support yet");
38106         this.toolbar  = false;
38107         /*
38108         var tcfg = this.toolbar;
38109         tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');  
38110         this.toolbar = new Roo.Toolbar(tcfg);
38111         if (Roo.isSafari) {
38112             var tbl = tcfg.container.child('table', true);
38113             tbl.setAttribute('width', '100%');
38114         }
38115         */
38116         
38117     }
38118    
38119
38120
38121     Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
38122 };
38123
38124 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
38125     /*
38126      *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
38127      */
38128     tabPosition : "top",
38129     /*
38130      *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
38131      */
38132     currentTabWidth : 0,
38133     /*
38134      *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
38135      */
38136     minTabWidth : 40,
38137     /*
38138      *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
38139      */
38140     maxTabWidth : 250,
38141     /*
38142      *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
38143      */
38144     preferredTabWidth : 175,
38145     /*
38146      *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
38147      */
38148     resizeTabs : false,
38149     /*
38150      *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
38151      */
38152     monitorResize : true,
38153     /*
38154      *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar. 
38155      */
38156     toolbar : false,
38157
38158     /**
38159      * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
38160      * @param {String} id The id of the div to use <b>or create</b>
38161      * @param {String} text The text for the tab
38162      * @param {String} content (optional) Content to put in the TabPanelItem body
38163      * @param {Boolean} closable (optional) True to create a close icon on the tab
38164      * @return {Roo.TabPanelItem} The created TabPanelItem
38165      */
38166     addTab : function(id, text, content, closable, tpl)
38167     {
38168         var item = new Roo.bootstrap.panel.TabItem({
38169             panel: this,
38170             id : id,
38171             text : text,
38172             closable : closable,
38173             tpl : tpl
38174         });
38175         this.addTabItem(item);
38176         if(content){
38177             item.setContent(content);
38178         }
38179         return item;
38180     },
38181
38182     /**
38183      * Returns the {@link Roo.TabPanelItem} with the specified id/index
38184      * @param {String/Number} id The id or index of the TabPanelItem to fetch.
38185      * @return {Roo.TabPanelItem}
38186      */
38187     getTab : function(id){
38188         return this.items[id];
38189     },
38190
38191     /**
38192      * Hides the {@link Roo.TabPanelItem} with the specified id/index
38193      * @param {String/Number} id The id or index of the TabPanelItem to hide.
38194      */
38195     hideTab : function(id){
38196         var t = this.items[id];
38197         if(!t.isHidden()){
38198            t.setHidden(true);
38199            this.hiddenCount++;
38200            this.autoSizeTabs();
38201         }
38202     },
38203
38204     /**
38205      * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
38206      * @param {String/Number} id The id or index of the TabPanelItem to unhide.
38207      */
38208     unhideTab : function(id){
38209         var t = this.items[id];
38210         if(t.isHidden()){
38211            t.setHidden(false);
38212            this.hiddenCount--;
38213            this.autoSizeTabs();
38214         }
38215     },
38216
38217     /**
38218      * Adds an existing {@link Roo.TabPanelItem}.
38219      * @param {Roo.TabPanelItem} item The TabPanelItem to add
38220      */
38221     addTabItem : function(item)
38222     {
38223         this.items[item.id] = item;
38224         this.items.push(item);
38225         this.autoSizeTabs();
38226       //  if(this.resizeTabs){
38227     //       item.setWidth(this.currentTabWidth || this.preferredTabWidth);
38228   //         this.autoSizeTabs();
38229 //        }else{
38230 //            item.autoSize();
38231        // }
38232     },
38233
38234     /**
38235      * Removes a {@link Roo.TabPanelItem}.
38236      * @param {String/Number} id The id or index of the TabPanelItem to remove.
38237      */
38238     removeTab : function(id){
38239         var items = this.items;
38240         var tab = items[id];
38241         if(!tab) { return; }
38242         var index = items.indexOf(tab);
38243         if(this.active == tab && items.length > 1){
38244             var newTab = this.getNextAvailable(index);
38245             if(newTab) {
38246                 newTab.activate();
38247             }
38248         }
38249         this.stripEl.dom.removeChild(tab.pnode.dom);
38250         if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
38251             this.bodyEl.dom.removeChild(tab.bodyEl.dom);
38252         }
38253         items.splice(index, 1);
38254         delete this.items[tab.id];
38255         tab.fireEvent("close", tab);
38256         tab.purgeListeners();
38257         this.autoSizeTabs();
38258     },
38259
38260     getNextAvailable : function(start){
38261         var items = this.items;
38262         var index = start;
38263         // look for a next tab that will slide over to
38264         // replace the one being removed
38265         while(index < items.length){
38266             var item = items[++index];
38267             if(item && !item.isHidden()){
38268                 return item;
38269             }
38270         }
38271         // if one isn't found select the previous tab (on the left)
38272         index = start;
38273         while(index >= 0){
38274             var item = items[--index];
38275             if(item && !item.isHidden()){
38276                 return item;
38277             }
38278         }
38279         return null;
38280     },
38281
38282     /**
38283      * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
38284      * @param {String/Number} id The id or index of the TabPanelItem to disable.
38285      */
38286     disableTab : function(id){
38287         var tab = this.items[id];
38288         if(tab && this.active != tab){
38289             tab.disable();
38290         }
38291     },
38292
38293     /**
38294      * Enables a {@link Roo.TabPanelItem} that is disabled.
38295      * @param {String/Number} id The id or index of the TabPanelItem to enable.
38296      */
38297     enableTab : function(id){
38298         var tab = this.items[id];
38299         tab.enable();
38300     },
38301
38302     /**
38303      * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
38304      * @param {String/Number} id The id or index of the TabPanelItem to activate.
38305      * @return {Roo.TabPanelItem} The TabPanelItem.
38306      */
38307     activate : function(id)
38308     {
38309         var tab = this.items[id];
38310         if(!tab){
38311             return null;
38312         }
38313         if(tab == this.active || tab.disabled){
38314             return tab;
38315         }
38316         var e = {};
38317         this.fireEvent("beforetabchange", this, e, tab);
38318         if(e.cancel !== true && !tab.disabled){
38319             if(this.active){
38320                 this.active.hide();
38321             }
38322             this.active = this.items[id];
38323             this.active.show();
38324             this.fireEvent("tabchange", this, this.active);
38325         }
38326         return tab;
38327     },
38328
38329     /**
38330      * Gets the active {@link Roo.TabPanelItem}.
38331      * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
38332      */
38333     getActiveTab : function(){
38334         return this.active;
38335     },
38336
38337     /**
38338      * Updates the tab body element to fit the height of the container element
38339      * for overflow scrolling
38340      * @param {Number} targetHeight (optional) Override the starting height from the elements height
38341      */
38342     syncHeight : function(targetHeight){
38343         var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
38344         var bm = this.bodyEl.getMargins();
38345         var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
38346         this.bodyEl.setHeight(newHeight);
38347         return newHeight;
38348     },
38349
38350     onResize : function(){
38351         if(this.monitorResize){
38352             this.autoSizeTabs();
38353         }
38354     },
38355
38356     /**
38357      * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
38358      */
38359     beginUpdate : function(){
38360         this.updating = true;
38361     },
38362
38363     /**
38364      * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
38365      */
38366     endUpdate : function(){
38367         this.updating = false;
38368         this.autoSizeTabs();
38369     },
38370
38371     /**
38372      * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
38373      */
38374     autoSizeTabs : function()
38375     {
38376         var count = this.items.length;
38377         var vcount = count - this.hiddenCount;
38378         
38379         if (vcount < 2) {
38380             this.stripEl.hide();
38381         } else {
38382             this.stripEl.show();
38383         }
38384         
38385         if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
38386             return;
38387         }
38388         
38389         
38390         var w = Math.max(this.el.getWidth() - this.cpad, 10);
38391         var availWidth = Math.floor(w / vcount);
38392         var b = this.stripBody;
38393         if(b.getWidth() > w){
38394             var tabs = this.items;
38395             this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
38396             if(availWidth < this.minTabWidth){
38397                 /*if(!this.sleft){    // incomplete scrolling code
38398                     this.createScrollButtons();
38399                 }
38400                 this.showScroll();
38401                 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
38402             }
38403         }else{
38404             if(this.currentTabWidth < this.preferredTabWidth){
38405                 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
38406             }
38407         }
38408     },
38409
38410     /**
38411      * Returns the number of tabs in this TabPanel.
38412      * @return {Number}
38413      */
38414      getCount : function(){
38415          return this.items.length;
38416      },
38417
38418     /**
38419      * Resizes all the tabs to the passed width
38420      * @param {Number} The new width
38421      */
38422     setTabWidth : function(width){
38423         this.currentTabWidth = width;
38424         for(var i = 0, len = this.items.length; i < len; i++) {
38425                 if(!this.items[i].isHidden()) {
38426                 this.items[i].setWidth(width);
38427             }
38428         }
38429     },
38430
38431     /**
38432      * Destroys this TabPanel
38433      * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
38434      */
38435     destroy : function(removeEl){
38436         Roo.EventManager.removeResizeListener(this.onResize, this);
38437         for(var i = 0, len = this.items.length; i < len; i++){
38438             this.items[i].purgeListeners();
38439         }
38440         if(removeEl === true){
38441             this.el.update("");
38442             this.el.remove();
38443         }
38444     },
38445     
38446     createStrip : function(container)
38447     {
38448         var strip = document.createElement("nav");
38449         strip.className = Roo.bootstrap.version == 4 ?
38450             "navbar-light bg-light" : 
38451             "navbar navbar-default"; //"x-tabs-wrap";
38452         container.appendChild(strip);
38453         return strip;
38454     },
38455     
38456     createStripList : function(strip)
38457     {
38458         // div wrapper for retard IE
38459         // returns the "tr" element.
38460         strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
38461         //'<div class="x-tabs-strip-wrap">'+
38462           //  '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
38463           //  '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
38464         return strip.firstChild; //.firstChild.firstChild.firstChild;
38465     },
38466     createBody : function(container)
38467     {
38468         var body = document.createElement("div");
38469         Roo.id(body, "tab-body");
38470         //Roo.fly(body).addClass("x-tabs-body");
38471         Roo.fly(body).addClass("tab-content");
38472         container.appendChild(body);
38473         return body;
38474     },
38475     createItemBody :function(bodyEl, id){
38476         var body = Roo.getDom(id);
38477         if(!body){
38478             body = document.createElement("div");
38479             body.id = id;
38480         }
38481         //Roo.fly(body).addClass("x-tabs-item-body");
38482         Roo.fly(body).addClass("tab-pane");
38483          bodyEl.insertBefore(body, bodyEl.firstChild);
38484         return body;
38485     },
38486     /** @private */
38487     createStripElements :  function(stripEl, text, closable, tpl)
38488     {
38489         var td = document.createElement("li"); // was td..
38490         td.className = 'nav-item';
38491         
38492         //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
38493         
38494         
38495         stripEl.appendChild(td);
38496         /*if(closable){
38497             td.className = "x-tabs-closable";
38498             if(!this.closeTpl){
38499                 this.closeTpl = new Roo.Template(
38500                    '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38501                    '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
38502                    '<div unselectable="on" class="close-icon">&#160;</div></em></span></a>'
38503                 );
38504             }
38505             var el = this.closeTpl.overwrite(td, {"text": text});
38506             var close = el.getElementsByTagName("div")[0];
38507             var inner = el.getElementsByTagName("em")[0];
38508             return {"el": el, "close": close, "inner": inner};
38509         } else {
38510         */
38511         // not sure what this is..
38512 //            if(!this.tabTpl){
38513                 //this.tabTpl = new Roo.Template(
38514                 //   '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38515                 //   '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
38516                 //);
38517 //                this.tabTpl = new Roo.Template(
38518 //                   '<a href="#">' +
38519 //                   '<span unselectable="on"' +
38520 //                            (this.disableTooltips ? '' : ' title="{text}"') +
38521 //                            ' >{text}</span></a>'
38522 //                );
38523 //                
38524 //            }
38525
38526
38527             var template = tpl || this.tabTpl || false;
38528             
38529             if(!template){
38530                 template =  new Roo.Template(
38531                         Roo.bootstrap.version == 4 ? 
38532                             (
38533                                 '<a class="nav-link" href="#" unselectable="on"' +
38534                                      (this.disableTooltips ? '' : ' title="{text}"') +
38535                                      ' >{text}</a>'
38536                             ) : (
38537                                 '<a class="nav-link" href="#">' +
38538                                 '<span unselectable="on"' +
38539                                          (this.disableTooltips ? '' : ' title="{text}"') +
38540                                     ' >{text}</span></a>'
38541                             )
38542                 );
38543             }
38544             
38545             switch (typeof(template)) {
38546                 case 'object' :
38547                     break;
38548                 case 'string' :
38549                     template = new Roo.Template(template);
38550                     break;
38551                 default :
38552                     break;
38553             }
38554             
38555             var el = template.overwrite(td, {"text": text});
38556             
38557             var inner = el.getElementsByTagName("span")[0];
38558             
38559             return {"el": el, "inner": inner};
38560             
38561     }
38562         
38563     
38564 });
38565
38566 /**
38567  * @class Roo.TabPanelItem
38568  * @extends Roo.util.Observable
38569  * Represents an individual item (tab plus body) in a TabPanel.
38570  * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
38571  * @param {String} id The id of this TabPanelItem
38572  * @param {String} text The text for the tab of this TabPanelItem
38573  * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
38574  */
38575 Roo.bootstrap.panel.TabItem = function(config){
38576     /**
38577      * The {@link Roo.TabPanel} this TabPanelItem belongs to
38578      * @type Roo.TabPanel
38579      */
38580     this.tabPanel = config.panel;
38581     /**
38582      * The id for this TabPanelItem
38583      * @type String
38584      */
38585     this.id = config.id;
38586     /** @private */
38587     this.disabled = false;
38588     /** @private */
38589     this.text = config.text;
38590     /** @private */
38591     this.loaded = false;
38592     this.closable = config.closable;
38593
38594     /**
38595      * The body element for this TabPanelItem.
38596      * @type Roo.Element
38597      */
38598     this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
38599     this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
38600     this.bodyEl.setStyle("display", "block");
38601     this.bodyEl.setStyle("zoom", "1");
38602     //this.hideAction();
38603
38604     var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
38605     /** @private */
38606     this.el = Roo.get(els.el);
38607     this.inner = Roo.get(els.inner, true);
38608      this.textEl = Roo.bootstrap.version == 4 ?
38609         this.el : Roo.get(this.el.dom.firstChild, true);
38610
38611     this.pnode = this.linode = Roo.get(els.el.parentNode, true);
38612     this.status_node = Roo.bootstrap.version == 4 ? this.el : this.linode;
38613
38614     
38615 //    this.el.on("mousedown", this.onTabMouseDown, this);
38616     this.el.on("click", this.onTabClick, this);
38617     /** @private */
38618     if(config.closable){
38619         var c = Roo.get(els.close, true);
38620         c.dom.title = this.closeText;
38621         c.addClassOnOver("close-over");
38622         c.on("click", this.closeClick, this);
38623      }
38624
38625     this.addEvents({
38626          /**
38627          * @event activate
38628          * Fires when this tab becomes the active tab.
38629          * @param {Roo.TabPanel} tabPanel The parent TabPanel
38630          * @param {Roo.TabPanelItem} this
38631          */
38632         "activate": true,
38633         /**
38634          * @event beforeclose
38635          * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
38636          * @param {Roo.TabPanelItem} this
38637          * @param {Object} e Set cancel to true on this object to cancel the close.
38638          */
38639         "beforeclose": true,
38640         /**
38641          * @event close
38642          * Fires when this tab is closed.
38643          * @param {Roo.TabPanelItem} this
38644          */
38645          "close": true,
38646         /**
38647          * @event deactivate
38648          * Fires when this tab is no longer the active tab.
38649          * @param {Roo.TabPanel} tabPanel The parent TabPanel
38650          * @param {Roo.TabPanelItem} this
38651          */
38652          "deactivate" : true
38653     });
38654     this.hidden = false;
38655
38656     Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
38657 };
38658
38659 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
38660            {
38661     purgeListeners : function(){
38662        Roo.util.Observable.prototype.purgeListeners.call(this);
38663        this.el.removeAllListeners();
38664     },
38665     /**
38666      * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
38667      */
38668     show : function(){
38669         this.status_node.addClass("active");
38670         this.showAction();
38671         if(Roo.isOpera){
38672             this.tabPanel.stripWrap.repaint();
38673         }
38674         this.fireEvent("activate", this.tabPanel, this);
38675     },
38676
38677     /**
38678      * Returns true if this tab is the active tab.
38679      * @return {Boolean}
38680      */
38681     isActive : function(){
38682         return this.tabPanel.getActiveTab() == this;
38683     },
38684
38685     /**
38686      * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
38687      */
38688     hide : function(){
38689         this.status_node.removeClass("active");
38690         this.hideAction();
38691         this.fireEvent("deactivate", this.tabPanel, this);
38692     },
38693
38694     hideAction : function(){
38695         this.bodyEl.hide();
38696         this.bodyEl.setStyle("position", "absolute");
38697         this.bodyEl.setLeft("-20000px");
38698         this.bodyEl.setTop("-20000px");
38699     },
38700
38701     showAction : function(){
38702         this.bodyEl.setStyle("position", "relative");
38703         this.bodyEl.setTop("");
38704         this.bodyEl.setLeft("");
38705         this.bodyEl.show();
38706     },
38707
38708     /**
38709      * Set the tooltip for the tab.
38710      * @param {String} tooltip The tab's tooltip
38711      */
38712     setTooltip : function(text){
38713         if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
38714             this.textEl.dom.qtip = text;
38715             this.textEl.dom.removeAttribute('title');
38716         }else{
38717             this.textEl.dom.title = text;
38718         }
38719     },
38720
38721     onTabClick : function(e){
38722         e.preventDefault();
38723         this.tabPanel.activate(this.id);
38724     },
38725
38726     onTabMouseDown : function(e){
38727         e.preventDefault();
38728         this.tabPanel.activate(this.id);
38729     },
38730 /*
38731     getWidth : function(){
38732         return this.inner.getWidth();
38733     },
38734
38735     setWidth : function(width){
38736         var iwidth = width - this.linode.getPadding("lr");
38737         this.inner.setWidth(iwidth);
38738         this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
38739         this.linode.setWidth(width);
38740     },
38741 */
38742     /**
38743      * Show or hide the tab
38744      * @param {Boolean} hidden True to hide or false to show.
38745      */
38746     setHidden : function(hidden){
38747         this.hidden = hidden;
38748         this.linode.setStyle("display", hidden ? "none" : "");
38749     },
38750
38751     /**
38752      * Returns true if this tab is "hidden"
38753      * @return {Boolean}
38754      */
38755     isHidden : function(){
38756         return this.hidden;
38757     },
38758
38759     /**
38760      * Returns the text for this tab
38761      * @return {String}
38762      */
38763     getText : function(){
38764         return this.text;
38765     },
38766     /*
38767     autoSize : function(){
38768         //this.el.beginMeasure();
38769         this.textEl.setWidth(1);
38770         /*
38771          *  #2804 [new] Tabs in Roojs
38772          *  increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
38773          */
38774         //this.setWidth(this.textEl.dom.scrollWidth+this.linode.getPadding("lr")+this.inner.getPadding("lr") + 2);
38775         //this.el.endMeasure();
38776     //},
38777
38778     /**
38779      * Sets the text for the tab (Note: this also sets the tooltip text)
38780      * @param {String} text The tab's text and tooltip
38781      */
38782     setText : function(text){
38783         this.text = text;
38784         this.textEl.update(text);
38785         this.setTooltip(text);
38786         //if(!this.tabPanel.resizeTabs){
38787         //    this.autoSize();
38788         //}
38789     },
38790     /**
38791      * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
38792      */
38793     activate : function(){
38794         this.tabPanel.activate(this.id);
38795     },
38796
38797     /**
38798      * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
38799      */
38800     disable : function(){
38801         if(this.tabPanel.active != this){
38802             this.disabled = true;
38803             this.status_node.addClass("disabled");
38804         }
38805     },
38806
38807     /**
38808      * Enables this TabPanelItem if it was previously disabled.
38809      */
38810     enable : function(){
38811         this.disabled = false;
38812         this.status_node.removeClass("disabled");
38813     },
38814
38815     /**
38816      * Sets the content for this TabPanelItem.
38817      * @param {String} content The content
38818      * @param {Boolean} loadScripts true to look for and load scripts
38819      */
38820     setContent : function(content, loadScripts){
38821         this.bodyEl.update(content, loadScripts);
38822     },
38823
38824     /**
38825      * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
38826      * @return {Roo.UpdateManager} The UpdateManager
38827      */
38828     getUpdateManager : function(){
38829         return this.bodyEl.getUpdateManager();
38830     },
38831
38832     /**
38833      * Set a URL to be used to load the content for this TabPanelItem.
38834      * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
38835      * @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)
38836      * @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)
38837      * @return {Roo.UpdateManager} The UpdateManager
38838      */
38839     setUrl : function(url, params, loadOnce){
38840         if(this.refreshDelegate){
38841             this.un('activate', this.refreshDelegate);
38842         }
38843         this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38844         this.on("activate", this.refreshDelegate);
38845         return this.bodyEl.getUpdateManager();
38846     },
38847
38848     /** @private */
38849     _handleRefresh : function(url, params, loadOnce){
38850         if(!loadOnce || !this.loaded){
38851             var updater = this.bodyEl.getUpdateManager();
38852             updater.update(url, params, this._setLoaded.createDelegate(this));
38853         }
38854     },
38855
38856     /**
38857      *   Forces a content refresh from the URL specified in the {@link #setUrl} method.
38858      *   Will fail silently if the setUrl method has not been called.
38859      *   This does not activate the panel, just updates its content.
38860      */
38861     refresh : function(){
38862         if(this.refreshDelegate){
38863            this.loaded = false;
38864            this.refreshDelegate();
38865         }
38866     },
38867
38868     /** @private */
38869     _setLoaded : function(){
38870         this.loaded = true;
38871     },
38872
38873     /** @private */
38874     closeClick : function(e){
38875         var o = {};
38876         e.stopEvent();
38877         this.fireEvent("beforeclose", this, o);
38878         if(o.cancel !== true){
38879             this.tabPanel.removeTab(this.id);
38880         }
38881     },
38882     /**
38883      * The text displayed in the tooltip for the close icon.
38884      * @type String
38885      */
38886     closeText : "Close this tab"
38887 });
38888 /**
38889 *    This script refer to:
38890 *    Title: International Telephone Input
38891 *    Author: Jack O'Connor
38892 *    Code version:  v12.1.12
38893 *    Availability: https://github.com/jackocnr/intl-tel-input.git
38894 **/
38895
38896 Roo.bootstrap.PhoneInputData = function() {
38897     var d = [
38898       [
38899         "Afghanistan (‫افغانستان‬‎)",
38900         "af",
38901         "93"
38902       ],
38903       [
38904         "Albania (Shqipëri)",
38905         "al",
38906         "355"
38907       ],
38908       [
38909         "Algeria (‫الجزائر‬‎)",
38910         "dz",
38911         "213"
38912       ],
38913       [
38914         "American Samoa",
38915         "as",
38916         "1684"
38917       ],
38918       [
38919         "Andorra",
38920         "ad",
38921         "376"
38922       ],
38923       [
38924         "Angola",
38925         "ao",
38926         "244"
38927       ],
38928       [
38929         "Anguilla",
38930         "ai",
38931         "1264"
38932       ],
38933       [
38934         "Antigua and Barbuda",
38935         "ag",
38936         "1268"
38937       ],
38938       [
38939         "Argentina",
38940         "ar",
38941         "54"
38942       ],
38943       [
38944         "Armenia (Հայաստան)",
38945         "am",
38946         "374"
38947       ],
38948       [
38949         "Aruba",
38950         "aw",
38951         "297"
38952       ],
38953       [
38954         "Australia",
38955         "au",
38956         "61",
38957         0
38958       ],
38959       [
38960         "Austria (Österreich)",
38961         "at",
38962         "43"
38963       ],
38964       [
38965         "Azerbaijan (Azərbaycan)",
38966         "az",
38967         "994"
38968       ],
38969       [
38970         "Bahamas",
38971         "bs",
38972         "1242"
38973       ],
38974       [
38975         "Bahrain (‫البحرين‬‎)",
38976         "bh",
38977         "973"
38978       ],
38979       [
38980         "Bangladesh (বাংলাদেশ)",
38981         "bd",
38982         "880"
38983       ],
38984       [
38985         "Barbados",
38986         "bb",
38987         "1246"
38988       ],
38989       [
38990         "Belarus (Беларусь)",
38991         "by",
38992         "375"
38993       ],
38994       [
38995         "Belgium (België)",
38996         "be",
38997         "32"
38998       ],
38999       [
39000         "Belize",
39001         "bz",
39002         "501"
39003       ],
39004       [
39005         "Benin (Bénin)",
39006         "bj",
39007         "229"
39008       ],
39009       [
39010         "Bermuda",
39011         "bm",
39012         "1441"
39013       ],
39014       [
39015         "Bhutan (འབྲུག)",
39016         "bt",
39017         "975"
39018       ],
39019       [
39020         "Bolivia",
39021         "bo",
39022         "591"
39023       ],
39024       [
39025         "Bosnia and Herzegovina (Босна и Херцеговина)",
39026         "ba",
39027         "387"
39028       ],
39029       [
39030         "Botswana",
39031         "bw",
39032         "267"
39033       ],
39034       [
39035         "Brazil (Brasil)",
39036         "br",
39037         "55"
39038       ],
39039       [
39040         "British Indian Ocean Territory",
39041         "io",
39042         "246"
39043       ],
39044       [
39045         "British Virgin Islands",
39046         "vg",
39047         "1284"
39048       ],
39049       [
39050         "Brunei",
39051         "bn",
39052         "673"
39053       ],
39054       [
39055         "Bulgaria (България)",
39056         "bg",
39057         "359"
39058       ],
39059       [
39060         "Burkina Faso",
39061         "bf",
39062         "226"
39063       ],
39064       [
39065         "Burundi (Uburundi)",
39066         "bi",
39067         "257"
39068       ],
39069       [
39070         "Cambodia (កម្ពុជា)",
39071         "kh",
39072         "855"
39073       ],
39074       [
39075         "Cameroon (Cameroun)",
39076         "cm",
39077         "237"
39078       ],
39079       [
39080         "Canada",
39081         "ca",
39082         "1",
39083         1,
39084         ["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"]
39085       ],
39086       [
39087         "Cape Verde (Kabu Verdi)",
39088         "cv",
39089         "238"
39090       ],
39091       [
39092         "Caribbean Netherlands",
39093         "bq",
39094         "599",
39095         1
39096       ],
39097       [
39098         "Cayman Islands",
39099         "ky",
39100         "1345"
39101       ],
39102       [
39103         "Central African Republic (République centrafricaine)",
39104         "cf",
39105         "236"
39106       ],
39107       [
39108         "Chad (Tchad)",
39109         "td",
39110         "235"
39111       ],
39112       [
39113         "Chile",
39114         "cl",
39115         "56"
39116       ],
39117       [
39118         "China (中国)",
39119         "cn",
39120         "86"
39121       ],
39122       [
39123         "Christmas Island",
39124         "cx",
39125         "61",
39126         2
39127       ],
39128       [
39129         "Cocos (Keeling) Islands",
39130         "cc",
39131         "61",
39132         1
39133       ],
39134       [
39135         "Colombia",
39136         "co",
39137         "57"
39138       ],
39139       [
39140         "Comoros (‫جزر القمر‬‎)",
39141         "km",
39142         "269"
39143       ],
39144       [
39145         "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
39146         "cd",
39147         "243"
39148       ],
39149       [
39150         "Congo (Republic) (Congo-Brazzaville)",
39151         "cg",
39152         "242"
39153       ],
39154       [
39155         "Cook Islands",
39156         "ck",
39157         "682"
39158       ],
39159       [
39160         "Costa Rica",
39161         "cr",
39162         "506"
39163       ],
39164       [
39165         "Côte d’Ivoire",
39166         "ci",
39167         "225"
39168       ],
39169       [
39170         "Croatia (Hrvatska)",
39171         "hr",
39172         "385"
39173       ],
39174       [
39175         "Cuba",
39176         "cu",
39177         "53"
39178       ],
39179       [
39180         "Curaçao",
39181         "cw",
39182         "599",
39183         0
39184       ],
39185       [
39186         "Cyprus (Κύπρος)",
39187         "cy",
39188         "357"
39189       ],
39190       [
39191         "Czech Republic (Česká republika)",
39192         "cz",
39193         "420"
39194       ],
39195       [
39196         "Denmark (Danmark)",
39197         "dk",
39198         "45"
39199       ],
39200       [
39201         "Djibouti",
39202         "dj",
39203         "253"
39204       ],
39205       [
39206         "Dominica",
39207         "dm",
39208         "1767"
39209       ],
39210       [
39211         "Dominican Republic (República Dominicana)",
39212         "do",
39213         "1",
39214         2,
39215         ["809", "829", "849"]
39216       ],
39217       [
39218         "Ecuador",
39219         "ec",
39220         "593"
39221       ],
39222       [
39223         "Egypt (‫مصر‬‎)",
39224         "eg",
39225         "20"
39226       ],
39227       [
39228         "El Salvador",
39229         "sv",
39230         "503"
39231       ],
39232       [
39233         "Equatorial Guinea (Guinea Ecuatorial)",
39234         "gq",
39235         "240"
39236       ],
39237       [
39238         "Eritrea",
39239         "er",
39240         "291"
39241       ],
39242       [
39243         "Estonia (Eesti)",
39244         "ee",
39245         "372"
39246       ],
39247       [
39248         "Ethiopia",
39249         "et",
39250         "251"
39251       ],
39252       [
39253         "Falkland Islands (Islas Malvinas)",
39254         "fk",
39255         "500"
39256       ],
39257       [
39258         "Faroe Islands (Føroyar)",
39259         "fo",
39260         "298"
39261       ],
39262       [
39263         "Fiji",
39264         "fj",
39265         "679"
39266       ],
39267       [
39268         "Finland (Suomi)",
39269         "fi",
39270         "358",
39271         0
39272       ],
39273       [
39274         "France",
39275         "fr",
39276         "33"
39277       ],
39278       [
39279         "French Guiana (Guyane française)",
39280         "gf",
39281         "594"
39282       ],
39283       [
39284         "French Polynesia (Polynésie française)",
39285         "pf",
39286         "689"
39287       ],
39288       [
39289         "Gabon",
39290         "ga",
39291         "241"
39292       ],
39293       [
39294         "Gambia",
39295         "gm",
39296         "220"
39297       ],
39298       [
39299         "Georgia (საქართველო)",
39300         "ge",
39301         "995"
39302       ],
39303       [
39304         "Germany (Deutschland)",
39305         "de",
39306         "49"
39307       ],
39308       [
39309         "Ghana (Gaana)",
39310         "gh",
39311         "233"
39312       ],
39313       [
39314         "Gibraltar",
39315         "gi",
39316         "350"
39317       ],
39318       [
39319         "Greece (Ελλάδα)",
39320         "gr",
39321         "30"
39322       ],
39323       [
39324         "Greenland (Kalaallit Nunaat)",
39325         "gl",
39326         "299"
39327       ],
39328       [
39329         "Grenada",
39330         "gd",
39331         "1473"
39332       ],
39333       [
39334         "Guadeloupe",
39335         "gp",
39336         "590",
39337         0
39338       ],
39339       [
39340         "Guam",
39341         "gu",
39342         "1671"
39343       ],
39344       [
39345         "Guatemala",
39346         "gt",
39347         "502"
39348       ],
39349       [
39350         "Guernsey",
39351         "gg",
39352         "44",
39353         1
39354       ],
39355       [
39356         "Guinea (Guinée)",
39357         "gn",
39358         "224"
39359       ],
39360       [
39361         "Guinea-Bissau (Guiné Bissau)",
39362         "gw",
39363         "245"
39364       ],
39365       [
39366         "Guyana",
39367         "gy",
39368         "592"
39369       ],
39370       [
39371         "Haiti",
39372         "ht",
39373         "509"
39374       ],
39375       [
39376         "Honduras",
39377         "hn",
39378         "504"
39379       ],
39380       [
39381         "Hong Kong (香港)",
39382         "hk",
39383         "852"
39384       ],
39385       [
39386         "Hungary (Magyarország)",
39387         "hu",
39388         "36"
39389       ],
39390       [
39391         "Iceland (Ísland)",
39392         "is",
39393         "354"
39394       ],
39395       [
39396         "India (भारत)",
39397         "in",
39398         "91"
39399       ],
39400       [
39401         "Indonesia",
39402         "id",
39403         "62"
39404       ],
39405       [
39406         "Iran (‫ایران‬‎)",
39407         "ir",
39408         "98"
39409       ],
39410       [
39411         "Iraq (‫العراق‬‎)",
39412         "iq",
39413         "964"
39414       ],
39415       [
39416         "Ireland",
39417         "ie",
39418         "353"
39419       ],
39420       [
39421         "Isle of Man",
39422         "im",
39423         "44",
39424         2
39425       ],
39426       [
39427         "Israel (‫ישראל‬‎)",
39428         "il",
39429         "972"
39430       ],
39431       [
39432         "Italy (Italia)",
39433         "it",
39434         "39",
39435         0
39436       ],
39437       [
39438         "Jamaica",
39439         "jm",
39440         "1876"
39441       ],
39442       [
39443         "Japan (日本)",
39444         "jp",
39445         "81"
39446       ],
39447       [
39448         "Jersey",
39449         "je",
39450         "44",
39451         3
39452       ],
39453       [
39454         "Jordan (‫الأردن‬‎)",
39455         "jo",
39456         "962"
39457       ],
39458       [
39459         "Kazakhstan (Казахстан)",
39460         "kz",
39461         "7",
39462         1
39463       ],
39464       [
39465         "Kenya",
39466         "ke",
39467         "254"
39468       ],
39469       [
39470         "Kiribati",
39471         "ki",
39472         "686"
39473       ],
39474       [
39475         "Kosovo",
39476         "xk",
39477         "383"
39478       ],
39479       [
39480         "Kuwait (‫الكويت‬‎)",
39481         "kw",
39482         "965"
39483       ],
39484       [
39485         "Kyrgyzstan (Кыргызстан)",
39486         "kg",
39487         "996"
39488       ],
39489       [
39490         "Laos (ລາວ)",
39491         "la",
39492         "856"
39493       ],
39494       [
39495         "Latvia (Latvija)",
39496         "lv",
39497         "371"
39498       ],
39499       [
39500         "Lebanon (‫لبنان‬‎)",
39501         "lb",
39502         "961"
39503       ],
39504       [
39505         "Lesotho",
39506         "ls",
39507         "266"
39508       ],
39509       [
39510         "Liberia",
39511         "lr",
39512         "231"
39513       ],
39514       [
39515         "Libya (‫ليبيا‬‎)",
39516         "ly",
39517         "218"
39518       ],
39519       [
39520         "Liechtenstein",
39521         "li",
39522         "423"
39523       ],
39524       [
39525         "Lithuania (Lietuva)",
39526         "lt",
39527         "370"
39528       ],
39529       [
39530         "Luxembourg",
39531         "lu",
39532         "352"
39533       ],
39534       [
39535         "Macau (澳門)",
39536         "mo",
39537         "853"
39538       ],
39539       [
39540         "Macedonia (FYROM) (Македонија)",
39541         "mk",
39542         "389"
39543       ],
39544       [
39545         "Madagascar (Madagasikara)",
39546         "mg",
39547         "261"
39548       ],
39549       [
39550         "Malawi",
39551         "mw",
39552         "265"
39553       ],
39554       [
39555         "Malaysia",
39556         "my",
39557         "60"
39558       ],
39559       [
39560         "Maldives",
39561         "mv",
39562         "960"
39563       ],
39564       [
39565         "Mali",
39566         "ml",
39567         "223"
39568       ],
39569       [
39570         "Malta",
39571         "mt",
39572         "356"
39573       ],
39574       [
39575         "Marshall Islands",
39576         "mh",
39577         "692"
39578       ],
39579       [
39580         "Martinique",
39581         "mq",
39582         "596"
39583       ],
39584       [
39585         "Mauritania (‫موريتانيا‬‎)",
39586         "mr",
39587         "222"
39588       ],
39589       [
39590         "Mauritius (Moris)",
39591         "mu",
39592         "230"
39593       ],
39594       [
39595         "Mayotte",
39596         "yt",
39597         "262",
39598         1
39599       ],
39600       [
39601         "Mexico (México)",
39602         "mx",
39603         "52"
39604       ],
39605       [
39606         "Micronesia",
39607         "fm",
39608         "691"
39609       ],
39610       [
39611         "Moldova (Republica Moldova)",
39612         "md",
39613         "373"
39614       ],
39615       [
39616         "Monaco",
39617         "mc",
39618         "377"
39619       ],
39620       [
39621         "Mongolia (Монгол)",
39622         "mn",
39623         "976"
39624       ],
39625       [
39626         "Montenegro (Crna Gora)",
39627         "me",
39628         "382"
39629       ],
39630       [
39631         "Montserrat",
39632         "ms",
39633         "1664"
39634       ],
39635       [
39636         "Morocco (‫المغرب‬‎)",
39637         "ma",
39638         "212",
39639         0
39640       ],
39641       [
39642         "Mozambique (Moçambique)",
39643         "mz",
39644         "258"
39645       ],
39646       [
39647         "Myanmar (Burma) (မြန်မာ)",
39648         "mm",
39649         "95"
39650       ],
39651       [
39652         "Namibia (Namibië)",
39653         "na",
39654         "264"
39655       ],
39656       [
39657         "Nauru",
39658         "nr",
39659         "674"
39660       ],
39661       [
39662         "Nepal (नेपाल)",
39663         "np",
39664         "977"
39665       ],
39666       [
39667         "Netherlands (Nederland)",
39668         "nl",
39669         "31"
39670       ],
39671       [
39672         "New Caledonia (Nouvelle-Calédonie)",
39673         "nc",
39674         "687"
39675       ],
39676       [
39677         "New Zealand",
39678         "nz",
39679         "64"
39680       ],
39681       [
39682         "Nicaragua",
39683         "ni",
39684         "505"
39685       ],
39686       [
39687         "Niger (Nijar)",
39688         "ne",
39689         "227"
39690       ],
39691       [
39692         "Nigeria",
39693         "ng",
39694         "234"
39695       ],
39696       [
39697         "Niue",
39698         "nu",
39699         "683"
39700       ],
39701       [
39702         "Norfolk Island",
39703         "nf",
39704         "672"
39705       ],
39706       [
39707         "North Korea (조선 민주주의 인민 공화국)",
39708         "kp",
39709         "850"
39710       ],
39711       [
39712         "Northern Mariana Islands",
39713         "mp",
39714         "1670"
39715       ],
39716       [
39717         "Norway (Norge)",
39718         "no",
39719         "47",
39720         0
39721       ],
39722       [
39723         "Oman (‫عُمان‬‎)",
39724         "om",
39725         "968"
39726       ],
39727       [
39728         "Pakistan (‫پاکستان‬‎)",
39729         "pk",
39730         "92"
39731       ],
39732       [
39733         "Palau",
39734         "pw",
39735         "680"
39736       ],
39737       [
39738         "Palestine (‫فلسطين‬‎)",
39739         "ps",
39740         "970"
39741       ],
39742       [
39743         "Panama (Panamá)",
39744         "pa",
39745         "507"
39746       ],
39747       [
39748         "Papua New Guinea",
39749         "pg",
39750         "675"
39751       ],
39752       [
39753         "Paraguay",
39754         "py",
39755         "595"
39756       ],
39757       [
39758         "Peru (Perú)",
39759         "pe",
39760         "51"
39761       ],
39762       [
39763         "Philippines",
39764         "ph",
39765         "63"
39766       ],
39767       [
39768         "Poland (Polska)",
39769         "pl",
39770         "48"
39771       ],
39772       [
39773         "Portugal",
39774         "pt",
39775         "351"
39776       ],
39777       [
39778         "Puerto Rico",
39779         "pr",
39780         "1",
39781         3,
39782         ["787", "939"]
39783       ],
39784       [
39785         "Qatar (‫قطر‬‎)",
39786         "qa",
39787         "974"
39788       ],
39789       [
39790         "Réunion (La Réunion)",
39791         "re",
39792         "262",
39793         0
39794       ],
39795       [
39796         "Romania (România)",
39797         "ro",
39798         "40"
39799       ],
39800       [
39801         "Russia (Россия)",
39802         "ru",
39803         "7",
39804         0
39805       ],
39806       [
39807         "Rwanda",
39808         "rw",
39809         "250"
39810       ],
39811       [
39812         "Saint Barthélemy",
39813         "bl",
39814         "590",
39815         1
39816       ],
39817       [
39818         "Saint Helena",
39819         "sh",
39820         "290"
39821       ],
39822       [
39823         "Saint Kitts and Nevis",
39824         "kn",
39825         "1869"
39826       ],
39827       [
39828         "Saint Lucia",
39829         "lc",
39830         "1758"
39831       ],
39832       [
39833         "Saint Martin (Saint-Martin (partie française))",
39834         "mf",
39835         "590",
39836         2
39837       ],
39838       [
39839         "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39840         "pm",
39841         "508"
39842       ],
39843       [
39844         "Saint Vincent and the Grenadines",
39845         "vc",
39846         "1784"
39847       ],
39848       [
39849         "Samoa",
39850         "ws",
39851         "685"
39852       ],
39853       [
39854         "San Marino",
39855         "sm",
39856         "378"
39857       ],
39858       [
39859         "São Tomé and Príncipe (São Tomé e Príncipe)",
39860         "st",
39861         "239"
39862       ],
39863       [
39864         "Saudi Arabia (‫المملكة العربية السعودية‬‎)",
39865         "sa",
39866         "966"
39867       ],
39868       [
39869         "Senegal (Sénégal)",
39870         "sn",
39871         "221"
39872       ],
39873       [
39874         "Serbia (Србија)",
39875         "rs",
39876         "381"
39877       ],
39878       [
39879         "Seychelles",
39880         "sc",
39881         "248"
39882       ],
39883       [
39884         "Sierra Leone",
39885         "sl",
39886         "232"
39887       ],
39888       [
39889         "Singapore",
39890         "sg",
39891         "65"
39892       ],
39893       [
39894         "Sint Maarten",
39895         "sx",
39896         "1721"
39897       ],
39898       [
39899         "Slovakia (Slovensko)",
39900         "sk",
39901         "421"
39902       ],
39903       [
39904         "Slovenia (Slovenija)",
39905         "si",
39906         "386"
39907       ],
39908       [
39909         "Solomon Islands",
39910         "sb",
39911         "677"
39912       ],
39913       [
39914         "Somalia (Soomaaliya)",
39915         "so",
39916         "252"
39917       ],
39918       [
39919         "South Africa",
39920         "za",
39921         "27"
39922       ],
39923       [
39924         "South Korea (대한민국)",
39925         "kr",
39926         "82"
39927       ],
39928       [
39929         "South Sudan (‫جنوب السودان‬‎)",
39930         "ss",
39931         "211"
39932       ],
39933       [
39934         "Spain (España)",
39935         "es",
39936         "34"
39937       ],
39938       [
39939         "Sri Lanka (ශ්‍රී ලංකාව)",
39940         "lk",
39941         "94"
39942       ],
39943       [
39944         "Sudan (‫السودان‬‎)",
39945         "sd",
39946         "249"
39947       ],
39948       [
39949         "Suriname",
39950         "sr",
39951         "597"
39952       ],
39953       [
39954         "Svalbard and Jan Mayen",
39955         "sj",
39956         "47",
39957         1
39958       ],
39959       [
39960         "Swaziland",
39961         "sz",
39962         "268"
39963       ],
39964       [
39965         "Sweden (Sverige)",
39966         "se",
39967         "46"
39968       ],
39969       [
39970         "Switzerland (Schweiz)",
39971         "ch",
39972         "41"
39973       ],
39974       [
39975         "Syria (‫سوريا‬‎)",
39976         "sy",
39977         "963"
39978       ],
39979       [
39980         "Taiwan (台灣)",
39981         "tw",
39982         "886"
39983       ],
39984       [
39985         "Tajikistan",
39986         "tj",
39987         "992"
39988       ],
39989       [
39990         "Tanzania",
39991         "tz",
39992         "255"
39993       ],
39994       [
39995         "Thailand (ไทย)",
39996         "th",
39997         "66"
39998       ],
39999       [
40000         "Timor-Leste",
40001         "tl",
40002         "670"
40003       ],
40004       [
40005         "Togo",
40006         "tg",
40007         "228"
40008       ],
40009       [
40010         "Tokelau",
40011         "tk",
40012         "690"
40013       ],
40014       [
40015         "Tonga",
40016         "to",
40017         "676"
40018       ],
40019       [
40020         "Trinidad and Tobago",
40021         "tt",
40022         "1868"
40023       ],
40024       [
40025         "Tunisia (‫تونس‬‎)",
40026         "tn",
40027         "216"
40028       ],
40029       [
40030         "Turkey (Türkiye)",
40031         "tr",
40032         "90"
40033       ],
40034       [
40035         "Turkmenistan",
40036         "tm",
40037         "993"
40038       ],
40039       [
40040         "Turks and Caicos Islands",
40041         "tc",
40042         "1649"
40043       ],
40044       [
40045         "Tuvalu",
40046         "tv",
40047         "688"
40048       ],
40049       [
40050         "U.S. Virgin Islands",
40051         "vi",
40052         "1340"
40053       ],
40054       [
40055         "Uganda",
40056         "ug",
40057         "256"
40058       ],
40059       [
40060         "Ukraine (Україна)",
40061         "ua",
40062         "380"
40063       ],
40064       [
40065         "United Arab Emirates (‫الإمارات العربية المتحدة‬‎)",
40066         "ae",
40067         "971"
40068       ],
40069       [
40070         "United Kingdom",
40071         "gb",
40072         "44",
40073         0
40074       ],
40075       [
40076         "United States",
40077         "us",
40078         "1",
40079         0
40080       ],
40081       [
40082         "Uruguay",
40083         "uy",
40084         "598"
40085       ],
40086       [
40087         "Uzbekistan (Oʻzbekiston)",
40088         "uz",
40089         "998"
40090       ],
40091       [
40092         "Vanuatu",
40093         "vu",
40094         "678"
40095       ],
40096       [
40097         "Vatican City (Città del Vaticano)",
40098         "va",
40099         "39",
40100         1
40101       ],
40102       [
40103         "Venezuela",
40104         "ve",
40105         "58"
40106       ],
40107       [
40108         "Vietnam (Việt Nam)",
40109         "vn",
40110         "84"
40111       ],
40112       [
40113         "Wallis and Futuna (Wallis-et-Futuna)",
40114         "wf",
40115         "681"
40116       ],
40117       [
40118         "Western Sahara (‫الصحراء الغربية‬‎)",
40119         "eh",
40120         "212",
40121         1
40122       ],
40123       [
40124         "Yemen (‫اليمن‬‎)",
40125         "ye",
40126         "967"
40127       ],
40128       [
40129         "Zambia",
40130         "zm",
40131         "260"
40132       ],
40133       [
40134         "Zimbabwe",
40135         "zw",
40136         "263"
40137       ],
40138       [
40139         "Åland Islands",
40140         "ax",
40141         "358",
40142         1
40143       ]
40144   ];
40145   
40146   return d;
40147 }/**
40148 *    This script refer to:
40149 *    Title: International Telephone Input
40150 *    Author: Jack O'Connor
40151 *    Code version:  v12.1.12
40152 *    Availability: https://github.com/jackocnr/intl-tel-input.git
40153 **/
40154
40155 /**
40156  * @class Roo.bootstrap.PhoneInput
40157  * @extends Roo.bootstrap.TriggerField
40158  * An input with International dial-code selection
40159  
40160  * @cfg {String} defaultDialCode default '+852'
40161  * @cfg {Array} preferedCountries default []
40162   
40163  * @constructor
40164  * Create a new PhoneInput.
40165  * @param {Object} config Configuration options
40166  */
40167
40168 Roo.bootstrap.PhoneInput = function(config) {
40169     Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
40170 };
40171
40172 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
40173         
40174         listWidth: undefined,
40175         
40176         selectedClass: 'active',
40177         
40178         invalidClass : "has-warning",
40179         
40180         validClass: 'has-success',
40181         
40182         allowed: '0123456789',
40183         
40184         max_length: 15,
40185         
40186         /**
40187          * @cfg {String} defaultDialCode The default dial code when initializing the input
40188          */
40189         defaultDialCode: '+852',
40190         
40191         /**
40192          * @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
40193          */
40194         preferedCountries: false,
40195         
40196         getAutoCreate : function()
40197         {
40198             var data = Roo.bootstrap.PhoneInputData();
40199             var align = this.labelAlign || this.parentLabelAlign();
40200             var id = Roo.id();
40201             
40202             this.allCountries = [];
40203             this.dialCodeMapping = [];
40204             
40205             for (var i = 0; i < data.length; i++) {
40206               var c = data[i];
40207               this.allCountries[i] = {
40208                 name: c[0],
40209                 iso2: c[1],
40210                 dialCode: c[2],
40211                 priority: c[3] || 0,
40212                 areaCodes: c[4] || null
40213               };
40214               this.dialCodeMapping[c[2]] = {
40215                   name: c[0],
40216                   iso2: c[1],
40217                   priority: c[3] || 0,
40218                   areaCodes: c[4] || null
40219               };
40220             }
40221             
40222             var cfg = {
40223                 cls: 'form-group',
40224                 cn: []
40225             };
40226             
40227             var input =  {
40228                 tag: 'input',
40229                 id : id,
40230                 // type: 'number', -- do not use number - we get the flaky up/down arrows.
40231                 maxlength: this.max_length,
40232                 cls : 'form-control tel-input',
40233                 autocomplete: 'new-password'
40234             };
40235             
40236             var hiddenInput = {
40237                 tag: 'input',
40238                 type: 'hidden',
40239                 cls: 'hidden-tel-input'
40240             };
40241             
40242             if (this.name) {
40243                 hiddenInput.name = this.name;
40244             }
40245             
40246             if (this.disabled) {
40247                 input.disabled = true;
40248             }
40249             
40250             var flag_container = {
40251                 tag: 'div',
40252                 cls: 'flag-box',
40253                 cn: [
40254                     {
40255                         tag: 'div',
40256                         cls: 'flag'
40257                     },
40258                     {
40259                         tag: 'div',
40260                         cls: 'caret'
40261                     }
40262                 ]
40263             };
40264             
40265             var box = {
40266                 tag: 'div',
40267                 cls: this.hasFeedback ? 'has-feedback' : '',
40268                 cn: [
40269                     hiddenInput,
40270                     input,
40271                     {
40272                         tag: 'input',
40273                         cls: 'dial-code-holder',
40274                         disabled: true
40275                     }
40276                 ]
40277             };
40278             
40279             var container = {
40280                 cls: 'roo-select2-container input-group',
40281                 cn: [
40282                     flag_container,
40283                     box
40284                 ]
40285             };
40286             
40287             if (this.fieldLabel.length) {
40288                 var indicator = {
40289                     tag: 'i',
40290                     tooltip: 'This field is required'
40291                 };
40292                 
40293                 var label = {
40294                     tag: 'label',
40295                     'for':  id,
40296                     cls: 'control-label',
40297                     cn: []
40298                 };
40299                 
40300                 var label_text = {
40301                     tag: 'span',
40302                     html: this.fieldLabel
40303                 };
40304                 
40305                 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40306                 label.cn = [
40307                     indicator,
40308                     label_text
40309                 ];
40310                 
40311                 if(this.indicatorpos == 'right') {
40312                     indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40313                     label.cn = [
40314                         label_text,
40315                         indicator
40316                     ];
40317                 }
40318                 
40319                 if(align == 'left') {
40320                     container = {
40321                         tag: 'div',
40322                         cn: [
40323                             container
40324                         ]
40325                     };
40326                     
40327                     if(this.labelWidth > 12){
40328                         label.style = "width: " + this.labelWidth + 'px';
40329                     }
40330                     if(this.labelWidth < 13 && this.labelmd == 0){
40331                         this.labelmd = this.labelWidth;
40332                     }
40333                     if(this.labellg > 0){
40334                         label.cls += ' col-lg-' + this.labellg;
40335                         input.cls += ' col-lg-' + (12 - this.labellg);
40336                     }
40337                     if(this.labelmd > 0){
40338                         label.cls += ' col-md-' + this.labelmd;
40339                         container.cls += ' col-md-' + (12 - this.labelmd);
40340                     }
40341                     if(this.labelsm > 0){
40342                         label.cls += ' col-sm-' + this.labelsm;
40343                         container.cls += ' col-sm-' + (12 - this.labelsm);
40344                     }
40345                     if(this.labelxs > 0){
40346                         label.cls += ' col-xs-' + this.labelxs;
40347                         container.cls += ' col-xs-' + (12 - this.labelxs);
40348                     }
40349                 }
40350             }
40351             
40352             cfg.cn = [
40353                 label,
40354                 container
40355             ];
40356             
40357             var settings = this;
40358             
40359             ['xs','sm','md','lg'].map(function(size){
40360                 if (settings[size]) {
40361                     cfg.cls += ' col-' + size + '-' + settings[size];
40362                 }
40363             });
40364             
40365             this.store = new Roo.data.Store({
40366                 proxy : new Roo.data.MemoryProxy({}),
40367                 reader : new Roo.data.JsonReader({
40368                     fields : [
40369                         {
40370                             'name' : 'name',
40371                             'type' : 'string'
40372                         },
40373                         {
40374                             'name' : 'iso2',
40375                             'type' : 'string'
40376                         },
40377                         {
40378                             'name' : 'dialCode',
40379                             'type' : 'string'
40380                         },
40381                         {
40382                             'name' : 'priority',
40383                             'type' : 'string'
40384                         },
40385                         {
40386                             'name' : 'areaCodes',
40387                             'type' : 'string'
40388                         }
40389                     ]
40390                 })
40391             });
40392             
40393             if(!this.preferedCountries) {
40394                 this.preferedCountries = [
40395                     'hk',
40396                     'gb',
40397                     'us'
40398                 ];
40399             }
40400             
40401             var p = this.preferedCountries.reverse();
40402             
40403             if(p) {
40404                 for (var i = 0; i < p.length; i++) {
40405                     for (var j = 0; j < this.allCountries.length; j++) {
40406                         if(this.allCountries[j].iso2 == p[i]) {
40407                             var t = this.allCountries[j];
40408                             this.allCountries.splice(j,1);
40409                             this.allCountries.unshift(t);
40410                         }
40411                     } 
40412                 }
40413             }
40414             
40415             this.store.proxy.data = {
40416                 success: true,
40417                 data: this.allCountries
40418             };
40419             
40420             return cfg;
40421         },
40422         
40423         initEvents : function()
40424         {
40425             this.createList();
40426             Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
40427             
40428             this.indicator = this.indicatorEl();
40429             this.flag = this.flagEl();
40430             this.dialCodeHolder = this.dialCodeHolderEl();
40431             
40432             this.trigger = this.el.select('div.flag-box',true).first();
40433             this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
40434             
40435             var _this = this;
40436             
40437             (function(){
40438                 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40439                 _this.list.setWidth(lw);
40440             }).defer(100);
40441             
40442             this.list.on('mouseover', this.onViewOver, this);
40443             this.list.on('mousemove', this.onViewMove, this);
40444             this.inputEl().on("keyup", this.onKeyUp, this);
40445             this.inputEl().on("keypress", this.onKeyPress, this);
40446             
40447             this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
40448
40449             this.view = new Roo.View(this.list, this.tpl, {
40450                 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40451             });
40452             
40453             this.view.on('click', this.onViewClick, this);
40454             this.setValue(this.defaultDialCode);
40455         },
40456         
40457         onTriggerClick : function(e)
40458         {
40459             Roo.log('trigger click');
40460             if(this.disabled){
40461                 return;
40462             }
40463             
40464             if(this.isExpanded()){
40465                 this.collapse();
40466                 this.hasFocus = false;
40467             }else {
40468                 this.store.load({});
40469                 this.hasFocus = true;
40470                 this.expand();
40471             }
40472         },
40473         
40474         isExpanded : function()
40475         {
40476             return this.list.isVisible();
40477         },
40478         
40479         collapse : function()
40480         {
40481             if(!this.isExpanded()){
40482                 return;
40483             }
40484             this.list.hide();
40485             Roo.get(document).un('mousedown', this.collapseIf, this);
40486             Roo.get(document).un('mousewheel', this.collapseIf, this);
40487             this.fireEvent('collapse', this);
40488             this.validate();
40489         },
40490         
40491         expand : function()
40492         {
40493             Roo.log('expand');
40494
40495             if(this.isExpanded() || !this.hasFocus){
40496                 return;
40497             }
40498             
40499             var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
40500             this.list.setWidth(lw);
40501             
40502             this.list.show();
40503             this.restrictHeight();
40504             
40505             Roo.get(document).on('mousedown', this.collapseIf, this);
40506             Roo.get(document).on('mousewheel', this.collapseIf, this);
40507             
40508             this.fireEvent('expand', this);
40509         },
40510         
40511         restrictHeight : function()
40512         {
40513             this.list.alignTo(this.inputEl(), this.listAlign);
40514             this.list.alignTo(this.inputEl(), this.listAlign);
40515         },
40516         
40517         onViewOver : function(e, t)
40518         {
40519             if(this.inKeyMode){
40520                 return;
40521             }
40522             var item = this.view.findItemFromChild(t);
40523             
40524             if(item){
40525                 var index = this.view.indexOf(item);
40526                 this.select(index, false);
40527             }
40528         },
40529
40530         // private
40531         onViewClick : function(view, doFocus, el, e)
40532         {
40533             var index = this.view.getSelectedIndexes()[0];
40534             
40535             var r = this.store.getAt(index);
40536             
40537             if(r){
40538                 this.onSelect(r, index);
40539             }
40540             if(doFocus !== false && !this.blockFocus){
40541                 this.inputEl().focus();
40542             }
40543         },
40544         
40545         onViewMove : function(e, t)
40546         {
40547             this.inKeyMode = false;
40548         },
40549         
40550         select : function(index, scrollIntoView)
40551         {
40552             this.selectedIndex = index;
40553             this.view.select(index);
40554             if(scrollIntoView !== false){
40555                 var el = this.view.getNode(index);
40556                 if(el){
40557                     this.list.scrollChildIntoView(el, false);
40558                 }
40559             }
40560         },
40561         
40562         createList : function()
40563         {
40564             this.list = Roo.get(document.body).createChild({
40565                 tag: 'ul',
40566                 cls: 'typeahead typeahead-long dropdown-menu tel-list',
40567                 style: 'display:none'
40568             });
40569             
40570             this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
40571         },
40572         
40573         collapseIf : function(e)
40574         {
40575             var in_combo  = e.within(this.el);
40576             var in_list =  e.within(this.list);
40577             var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
40578             
40579             if (in_combo || in_list || is_list) {
40580                 return;
40581             }
40582             this.collapse();
40583         },
40584         
40585         onSelect : function(record, index)
40586         {
40587             if(this.fireEvent('beforeselect', this, record, index) !== false){
40588                 
40589                 this.setFlagClass(record.data.iso2);
40590                 this.setDialCode(record.data.dialCode);
40591                 this.hasFocus = false;
40592                 this.collapse();
40593                 this.fireEvent('select', this, record, index);
40594             }
40595         },
40596         
40597         flagEl : function()
40598         {
40599             var flag = this.el.select('div.flag',true).first();
40600             if(!flag){
40601                 return false;
40602             }
40603             return flag;
40604         },
40605         
40606         dialCodeHolderEl : function()
40607         {
40608             var d = this.el.select('input.dial-code-holder',true).first();
40609             if(!d){
40610                 return false;
40611             }
40612             return d;
40613         },
40614         
40615         setDialCode : function(v)
40616         {
40617             this.dialCodeHolder.dom.value = '+'+v;
40618         },
40619         
40620         setFlagClass : function(n)
40621         {
40622             this.flag.dom.className = 'flag '+n;
40623         },
40624         
40625         getValue : function()
40626         {
40627             var v = this.inputEl().getValue();
40628             if(this.dialCodeHolder) {
40629                 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
40630             }
40631             return v;
40632         },
40633         
40634         setValue : function(v)
40635         {
40636             var d = this.getDialCode(v);
40637             
40638             //invalid dial code
40639             if(v.length == 0 || !d || d.length == 0) {
40640                 if(this.rendered){
40641                     this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40642                     this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40643                 }
40644                 return;
40645             }
40646             
40647             //valid dial code
40648             this.setFlagClass(this.dialCodeMapping[d].iso2);
40649             this.setDialCode(d);
40650             this.inputEl().dom.value = v.replace('+'+d,'');
40651             this.hiddenEl().dom.value = this.getValue();
40652             
40653             this.validate();
40654         },
40655         
40656         getDialCode : function(v)
40657         {
40658             v = v ||  '';
40659             
40660             if (v.length == 0) {
40661                 return this.dialCodeHolder.dom.value;
40662             }
40663             
40664             var dialCode = "";
40665             if (v.charAt(0) != "+") {
40666                 return false;
40667             }
40668             var numericChars = "";
40669             for (var i = 1; i < v.length; i++) {
40670               var c = v.charAt(i);
40671               if (!isNaN(c)) {
40672                 numericChars += c;
40673                 if (this.dialCodeMapping[numericChars]) {
40674                   dialCode = v.substr(1, i);
40675                 }
40676                 if (numericChars.length == 4) {
40677                   break;
40678                 }
40679               }
40680             }
40681             return dialCode;
40682         },
40683         
40684         reset : function()
40685         {
40686             this.setValue(this.defaultDialCode);
40687             this.validate();
40688         },
40689         
40690         hiddenEl : function()
40691         {
40692             return this.el.select('input.hidden-tel-input',true).first();
40693         },
40694         
40695         // after setting val
40696         onKeyUp : function(e){
40697             this.setValue(this.getValue());
40698         },
40699         
40700         onKeyPress : function(e){
40701             if(this.allowed.indexOf(String.fromCharCode(e.getCharCode())) === -1){
40702                 e.stopEvent();
40703             }
40704         }
40705         
40706 });
40707 /**
40708  * @class Roo.bootstrap.MoneyField
40709  * @extends Roo.bootstrap.ComboBox
40710  * Bootstrap MoneyField class
40711  * 
40712  * @constructor
40713  * Create a new MoneyField.
40714  * @param {Object} config Configuration options
40715  */
40716
40717 Roo.bootstrap.MoneyField = function(config) {
40718     
40719     Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
40720     
40721 };
40722
40723 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
40724     
40725     /**
40726      * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40727      */
40728     allowDecimals : true,
40729     /**
40730      * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40731      */
40732     decimalSeparator : ".",
40733     /**
40734      * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40735      */
40736     decimalPrecision : 0,
40737     /**
40738      * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40739      */
40740     allowNegative : true,
40741     /**
40742      * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40743      */
40744     allowZero: true,
40745     /**
40746      * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40747      */
40748     minValue : Number.NEGATIVE_INFINITY,
40749     /**
40750      * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40751      */
40752     maxValue : Number.MAX_VALUE,
40753     /**
40754      * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40755      */
40756     minText : "The minimum value for this field is {0}",
40757     /**
40758      * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40759      */
40760     maxText : "The maximum value for this field is {0}",
40761     /**
40762      * @cfg {String} nanText Error text to display if the value is not a valid number.  For example, this can happen
40763      * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40764      */
40765     nanText : "{0} is not a valid number",
40766     /**
40767      * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
40768      */
40769     castInt : true,
40770     /**
40771      * @cfg {String} defaults currency of the MoneyField
40772      * value should be in lkey
40773      */
40774     defaultCurrency : false,
40775     /**
40776      * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40777      */
40778     thousandsDelimiter : false,
40779     /**
40780      * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
40781      */
40782     max_length: false,
40783     
40784     inputlg : 9,
40785     inputmd : 9,
40786     inputsm : 9,
40787     inputxs : 6,
40788     
40789     store : false,
40790     
40791     getAutoCreate : function()
40792     {
40793         var align = this.labelAlign || this.parentLabelAlign();
40794         
40795         var id = Roo.id();
40796
40797         var cfg = {
40798             cls: 'form-group',
40799             cn: []
40800         };
40801
40802         var input =  {
40803             tag: 'input',
40804             id : id,
40805             cls : 'form-control roo-money-amount-input',
40806             autocomplete: 'new-password'
40807         };
40808         
40809         var hiddenInput = {
40810             tag: 'input',
40811             type: 'hidden',
40812             id: Roo.id(),
40813             cls: 'hidden-number-input'
40814         };
40815         
40816         if(this.max_length) {
40817             input.maxlength = this.max_length; 
40818         }
40819         
40820         if (this.name) {
40821             hiddenInput.name = this.name;
40822         }
40823
40824         if (this.disabled) {
40825             input.disabled = true;
40826         }
40827
40828         var clg = 12 - this.inputlg;
40829         var cmd = 12 - this.inputmd;
40830         var csm = 12 - this.inputsm;
40831         var cxs = 12 - this.inputxs;
40832         
40833         var container = {
40834             tag : 'div',
40835             cls : 'row roo-money-field',
40836             cn : [
40837                 {
40838                     tag : 'div',
40839                     cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
40840                     cn : [
40841                         {
40842                             tag : 'div',
40843                             cls: 'roo-select2-container input-group',
40844                             cn: [
40845                                 {
40846                                     tag : 'input',
40847                                     cls : 'form-control roo-money-currency-input',
40848                                     autocomplete: 'new-password',
40849                                     readOnly : 1,
40850                                     name : this.currencyName
40851                                 },
40852                                 {
40853                                     tag :'span',
40854                                     cls : 'input-group-addon',
40855                                     cn : [
40856                                         {
40857                                             tag: 'span',
40858                                             cls: 'caret'
40859                                         }
40860                                     ]
40861                                 }
40862                             ]
40863                         }
40864                     ]
40865                 },
40866                 {
40867                     tag : 'div',
40868                     cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40869                     cn : [
40870                         {
40871                             tag: 'div',
40872                             cls: this.hasFeedback ? 'has-feedback' : '',
40873                             cn: [
40874                                 input
40875                             ]
40876                         }
40877                     ]
40878                 }
40879             ]
40880             
40881         };
40882         
40883         if (this.fieldLabel.length) {
40884             var indicator = {
40885                 tag: 'i',
40886                 tooltip: 'This field is required'
40887             };
40888
40889             var label = {
40890                 tag: 'label',
40891                 'for':  id,
40892                 cls: 'control-label',
40893                 cn: []
40894             };
40895
40896             var label_text = {
40897                 tag: 'span',
40898                 html: this.fieldLabel
40899             };
40900
40901             indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40902             label.cn = [
40903                 indicator,
40904                 label_text
40905             ];
40906
40907             if(this.indicatorpos == 'right') {
40908                 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40909                 label.cn = [
40910                     label_text,
40911                     indicator
40912                 ];
40913             }
40914
40915             if(align == 'left') {
40916                 container = {
40917                     tag: 'div',
40918                     cn: [
40919                         container
40920                     ]
40921                 };
40922
40923                 if(this.labelWidth > 12){
40924                     label.style = "width: " + this.labelWidth + 'px';
40925                 }
40926                 if(this.labelWidth < 13 && this.labelmd == 0){
40927                     this.labelmd = this.labelWidth;
40928                 }
40929                 if(this.labellg > 0){
40930                     label.cls += ' col-lg-' + this.labellg;
40931                     input.cls += ' col-lg-' + (12 - this.labellg);
40932                 }
40933                 if(this.labelmd > 0){
40934                     label.cls += ' col-md-' + this.labelmd;
40935                     container.cls += ' col-md-' + (12 - this.labelmd);
40936                 }
40937                 if(this.labelsm > 0){
40938                     label.cls += ' col-sm-' + this.labelsm;
40939                     container.cls += ' col-sm-' + (12 - this.labelsm);
40940                 }
40941                 if(this.labelxs > 0){
40942                     label.cls += ' col-xs-' + this.labelxs;
40943                     container.cls += ' col-xs-' + (12 - this.labelxs);
40944                 }
40945             }
40946         }
40947
40948         cfg.cn = [
40949             label,
40950             container,
40951             hiddenInput
40952         ];
40953         
40954         var settings = this;
40955
40956         ['xs','sm','md','lg'].map(function(size){
40957             if (settings[size]) {
40958                 cfg.cls += ' col-' + size + '-' + settings[size];
40959             }
40960         });
40961         
40962         return cfg;
40963     },
40964     
40965     initEvents : function()
40966     {
40967         this.indicator = this.indicatorEl();
40968         
40969         this.initCurrencyEvent();
40970         
40971         this.initNumberEvent();
40972     },
40973     
40974     initCurrencyEvent : function()
40975     {
40976         if (!this.store) {
40977             throw "can not find store for combo";
40978         }
40979         
40980         this.store = Roo.factory(this.store, Roo.data);
40981         this.store.parent = this;
40982         
40983         this.createList();
40984         
40985         this.triggerEl = this.el.select('.input-group-addon', true).first();
40986         
40987         this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40988         
40989         var _this = this;
40990         
40991         (function(){
40992             var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40993             _this.list.setWidth(lw);
40994         }).defer(100);
40995         
40996         this.list.on('mouseover', this.onViewOver, this);
40997         this.list.on('mousemove', this.onViewMove, this);
40998         this.list.on('scroll', this.onViewScroll, this);
40999         
41000         if(!this.tpl){
41001             this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
41002         }
41003         
41004         this.view = new Roo.View(this.list, this.tpl, {
41005             singleSelect:true, store: this.store, selectedClass: this.selectedClass
41006         });
41007         
41008         this.view.on('click', this.onViewClick, this);
41009         
41010         this.store.on('beforeload', this.onBeforeLoad, this);
41011         this.store.on('load', this.onLoad, this);
41012         this.store.on('loadexception', this.onLoadException, this);
41013         
41014         this.keyNav = new Roo.KeyNav(this.currencyEl(), {
41015             "up" : function(e){
41016                 this.inKeyMode = true;
41017                 this.selectPrev();
41018             },
41019
41020             "down" : function(e){
41021                 if(!this.isExpanded()){
41022                     this.onTriggerClick();
41023                 }else{
41024                     this.inKeyMode = true;
41025                     this.selectNext();
41026                 }
41027             },
41028
41029             "enter" : function(e){
41030                 this.collapse();
41031                 
41032                 if(this.fireEvent("specialkey", this, e)){
41033                     this.onViewClick(false);
41034                 }
41035                 
41036                 return true;
41037             },
41038
41039             "esc" : function(e){
41040                 this.collapse();
41041             },
41042
41043             "tab" : function(e){
41044                 this.collapse();
41045                 
41046                 if(this.fireEvent("specialkey", this, e)){
41047                     this.onViewClick(false);
41048                 }
41049                 
41050                 return true;
41051             },
41052
41053             scope : this,
41054
41055             doRelay : function(foo, bar, hname){
41056                 if(hname == 'down' || this.scope.isExpanded()){
41057                    return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
41058                 }
41059                 return true;
41060             },
41061
41062             forceKeyDown: true
41063         });
41064         
41065         this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
41066         
41067     },
41068     
41069     initNumberEvent : function(e)
41070     {
41071         this.inputEl().on("keydown" , this.fireKey,  this);
41072         this.inputEl().on("focus", this.onFocus,  this);
41073         this.inputEl().on("blur", this.onBlur,  this);
41074         
41075         this.inputEl().relayEvent('keyup', this);
41076         
41077         if(this.indicator){
41078             this.indicator.addClass('invisible');
41079         }
41080  
41081         this.originalValue = this.getValue();
41082         
41083         if(this.validationEvent == 'keyup'){
41084             this.validationTask = new Roo.util.DelayedTask(this.validate, this);
41085             this.inputEl().on('keyup', this.filterValidation, this);
41086         }
41087         else if(this.validationEvent !== false){
41088             this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
41089         }
41090         
41091         if(this.selectOnFocus){
41092             this.on("focus", this.preFocus, this);
41093             
41094         }
41095         if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
41096             this.inputEl().on("keypress", this.filterKeys, this);
41097         } else {
41098             this.inputEl().relayEvent('keypress', this);
41099         }
41100         
41101         var allowed = "0123456789";
41102         
41103         if(this.allowDecimals){
41104             allowed += this.decimalSeparator;
41105         }
41106         
41107         if(this.allowNegative){
41108             allowed += "-";
41109         }
41110         
41111         if(this.thousandsDelimiter) {
41112             allowed += ",";
41113         }
41114         
41115         this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
41116         
41117         var keyPress = function(e){
41118             
41119             var k = e.getKey();
41120             
41121             var c = e.getCharCode();
41122             
41123             if(
41124                     (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
41125                     allowed.indexOf(String.fromCharCode(c)) === -1
41126             ){
41127                 e.stopEvent();
41128                 return;
41129             }
41130             
41131             if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
41132                 return;
41133             }
41134             
41135             if(allowed.indexOf(String.fromCharCode(c)) === -1){
41136                 e.stopEvent();
41137             }
41138         };
41139         
41140         this.inputEl().on("keypress", keyPress, this);
41141         
41142     },
41143     
41144     onTriggerClick : function(e)
41145     {   
41146         if(this.disabled){
41147             return;
41148         }
41149         
41150         this.page = 0;
41151         this.loadNext = false;
41152         
41153         if(this.isExpanded()){
41154             this.collapse();
41155             return;
41156         }
41157         
41158         this.hasFocus = true;
41159         
41160         if(this.triggerAction == 'all') {
41161             this.doQuery(this.allQuery, true);
41162             return;
41163         }
41164         
41165         this.doQuery(this.getRawValue());
41166     },
41167     
41168     getCurrency : function()
41169     {   
41170         var v = this.currencyEl().getValue();
41171         
41172         return v;
41173     },
41174     
41175     restrictHeight : function()
41176     {
41177         this.list.alignTo(this.currencyEl(), this.listAlign);
41178         this.list.alignTo(this.currencyEl(), this.listAlign);
41179     },
41180     
41181     onViewClick : function(view, doFocus, el, e)
41182     {
41183         var index = this.view.getSelectedIndexes()[0];
41184         
41185         var r = this.store.getAt(index);
41186         
41187         if(r){
41188             this.onSelect(r, index);
41189         }
41190     },
41191     
41192     onSelect : function(record, index){
41193         
41194         if(this.fireEvent('beforeselect', this, record, index) !== false){
41195         
41196             this.setFromCurrencyData(index > -1 ? record.data : false);
41197             
41198             this.collapse();
41199             
41200             this.fireEvent('select', this, record, index);
41201         }
41202     },
41203     
41204     setFromCurrencyData : function(o)
41205     {
41206         var currency = '';
41207         
41208         this.lastCurrency = o;
41209         
41210         if (this.currencyField) {
41211             currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
41212         } else {
41213             Roo.log('no  currencyField value set for '+ (this.name ? this.name : this.id));
41214         }
41215         
41216         this.lastSelectionText = currency;
41217         
41218         //setting default currency
41219         if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
41220             this.setCurrency(this.defaultCurrency);
41221             return;
41222         }
41223         
41224         this.setCurrency(currency);
41225     },
41226     
41227     setFromData : function(o)
41228     {
41229         var c = {};
41230         
41231         c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
41232         
41233         this.setFromCurrencyData(c);
41234         
41235         var value = '';
41236         
41237         if (this.name) {
41238             value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
41239         } else {
41240             Roo.log('no value set for '+ (this.name ? this.name : this.id));
41241         }
41242         
41243         this.setValue(value);
41244         
41245     },
41246     
41247     setCurrency : function(v)
41248     {   
41249         this.currencyValue = v;
41250         
41251         if(this.rendered){
41252             this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
41253             this.validate();
41254         }
41255     },
41256     
41257     setValue : function(v)
41258     {
41259         v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
41260         
41261         this.value = v;
41262         
41263         if(this.rendered){
41264             
41265             this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
41266             
41267             this.inputEl().dom.value = (v == '') ? '' :
41268                 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
41269             
41270             if(!this.allowZero && v === '0') {
41271                 this.hiddenEl().dom.value = '';
41272                 this.inputEl().dom.value = '';
41273             }
41274             
41275             this.validate();
41276         }
41277     },
41278     
41279     getRawValue : function()
41280     {
41281         var v = this.inputEl().getValue();
41282         
41283         return v;
41284     },
41285     
41286     getValue : function()
41287     {
41288         return this.fixPrecision(this.parseValue(this.getRawValue()));
41289     },
41290     
41291     parseValue : function(value)
41292     {
41293         if(this.thousandsDelimiter) {
41294             value += "";
41295             r = new RegExp(",", "g");
41296             value = value.replace(r, "");
41297         }
41298         
41299         value = parseFloat(String(value).replace(this.decimalSeparator, "."));
41300         return isNaN(value) ? '' : value;
41301         
41302     },
41303     
41304     fixPrecision : function(value)
41305     {
41306         if(this.thousandsDelimiter) {
41307             value += "";
41308             r = new RegExp(",", "g");
41309             value = value.replace(r, "");
41310         }
41311         
41312         var nan = isNaN(value);
41313         
41314         if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
41315             return nan ? '' : value;
41316         }
41317         return parseFloat(value).toFixed(this.decimalPrecision);
41318     },
41319     
41320     decimalPrecisionFcn : function(v)
41321     {
41322         return Math.floor(v);
41323     },
41324     
41325     validateValue : function(value)
41326     {
41327         if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
41328             return false;
41329         }
41330         
41331         var num = this.parseValue(value);
41332         
41333         if(isNaN(num)){
41334             this.markInvalid(String.format(this.nanText, value));
41335             return false;
41336         }
41337         
41338         if(num < this.minValue){
41339             this.markInvalid(String.format(this.minText, this.minValue));
41340             return false;
41341         }
41342         
41343         if(num > this.maxValue){
41344             this.markInvalid(String.format(this.maxText, this.maxValue));
41345             return false;
41346         }
41347         
41348         return true;
41349     },
41350     
41351     validate : function()
41352     {
41353         if(this.disabled || this.allowBlank){
41354             this.markValid();
41355             return true;
41356         }
41357         
41358         var currency = this.getCurrency();
41359         
41360         if(this.validateValue(this.getRawValue()) && currency.length){
41361             this.markValid();
41362             return true;
41363         }
41364         
41365         this.markInvalid();
41366         return false;
41367     },
41368     
41369     getName: function()
41370     {
41371         return this.name;
41372     },
41373     
41374     beforeBlur : function()
41375     {
41376         if(!this.castInt){
41377             return;
41378         }
41379         
41380         var v = this.parseValue(this.getRawValue());
41381         
41382         if(v || v == 0){
41383             this.setValue(v);
41384         }
41385     },
41386     
41387     onBlur : function()
41388     {
41389         this.beforeBlur();
41390         
41391         if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
41392             //this.el.removeClass(this.focusClass);
41393         }
41394         
41395         this.hasFocus = false;
41396         
41397         if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
41398             this.validate();
41399         }
41400         
41401         var v = this.getValue();
41402         
41403         if(String(v) !== String(this.startValue)){
41404             this.fireEvent('change', this, v, this.startValue);
41405         }
41406         
41407         this.fireEvent("blur", this);
41408     },
41409     
41410     inputEl : function()
41411     {
41412         return this.el.select('.roo-money-amount-input', true).first();
41413     },
41414     
41415     currencyEl : function()
41416     {
41417         return this.el.select('.roo-money-currency-input', true).first();
41418     },
41419     
41420     hiddenEl : function()
41421     {
41422         return this.el.select('input.hidden-number-input',true).first();
41423     }
41424     
41425 });