8541475e9becbd3fd8850ab7fb9dbdf6190da99e
[roojs1] / Roo / bootstrap / ComboBox.js
1 /*
2  * - LGPL
3  * * 
4  */
5
6 /**
7  * @class Roo.bootstrap.ComboBox
8  * @extends Roo.bootstrap.TriggerField
9  * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10  * @cfg {Boolean} append (true|false) default false
11  * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12  * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13  * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14  * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15  * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16  * @cfg {Boolean} animate default true
17  * @cfg {Boolean} emptyResultText only for touch device
18  * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
19  * @constructor
20  * Create a new ComboBox.
21  * @param {Object} config Configuration options
22  */
23 Roo.bootstrap.ComboBox = function(config){
24     Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
25     this.addEvents({
26         /**
27          * @event expand
28          * Fires when the dropdown list is expanded
29              * @param {Roo.bootstrap.ComboBox} combo This combo box
30              */
31         'expand' : true,
32         /**
33          * @event collapse
34          * Fires when the dropdown list is collapsed
35              * @param {Roo.bootstrap.ComboBox} combo This combo box
36              */
37         'collapse' : true,
38         /**
39          * @event beforeselect
40          * Fires before a list item is selected. Return false to cancel the selection.
41              * @param {Roo.bootstrap.ComboBox} combo This combo box
42              * @param {Roo.data.Record} record The data record returned from the underlying store
43              * @param {Number} index The index of the selected item in the dropdown list
44              */
45         'beforeselect' : true,
46         /**
47          * @event select
48          * Fires when a list item is selected
49              * @param {Roo.bootstrap.ComboBox} combo This combo box
50              * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
51              * @param {Number} index The index of the selected item in the dropdown list
52              */
53         'select' : true,
54         /**
55          * @event beforequery
56          * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
57          * The event object passed has these properties:
58              * @param {Roo.bootstrap.ComboBox} combo This combo box
59              * @param {String} query The query
60              * @param {Boolean} forceAll true to force "all" query
61              * @param {Boolean} cancel true to cancel the query
62              * @param {Object} e The query event object
63              */
64         'beforequery': true,
65          /**
66          * @event add
67          * Fires when the 'add' icon is pressed (add a listener to enable add button)
68              * @param {Roo.bootstrap.ComboBox} combo This combo box
69              */
70         'add' : true,
71         /**
72          * @event edit
73          * Fires when the 'edit' icon is pressed (add a listener to enable add button)
74              * @param {Roo.bootstrap.ComboBox} combo This combo box
75              * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
76              */
77         'edit' : true,
78         /**
79          * @event remove
80          * Fires when the remove value from the combobox array
81              * @param {Roo.bootstrap.ComboBox} combo This combo box
82              */
83         'remove' : true,
84         /**
85          * @event specialfilter
86          * Fires when specialfilter
87             * @param {Roo.bootstrap.ComboBox} combo This combo box
88             */
89         'specialfilter' : true,
90         /**
91          * @event tick
92          * Fires when tick the element
93             * @param {Roo.bootstrap.ComboBox} combo This combo box
94             */
95         'tick' : true
96         
97     });
98     
99     this.item = [];
100     this.tickItems = [];
101     
102     this.selectedIndex = -1;
103     if(this.mode == 'local'){
104         if(config.queryDelay === undefined){
105             this.queryDelay = 10;
106         }
107         if(config.minChars === undefined){
108             this.minChars = 0;
109         }
110     }
111 };
112
113 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
114      
115     /**
116      * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
117      * rendering into an Roo.Editor, defaults to false)
118      */
119     /**
120      * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
121      * {tag: "input", type: "text", size: "24", autocomplete: "off"})
122      */
123     /**
124      * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
125      */
126     /**
127      * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
128      * the dropdown list (defaults to undefined, with no header element)
129      */
130
131      /**
132      * @cfg {String/Roo.Template} tpl The template to use to render the output
133      */
134      
135      /**
136      * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
137      */
138     listWidth: undefined,
139     /**
140      * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
141      * mode = 'remote' or 'text' if mode = 'local')
142      */
143     displayField: undefined,
144     
145     /**
146      * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
147      * mode = 'remote' or 'value' if mode = 'local'). 
148      * Note: use of a valueField requires the user make a selection
149      * in order for a value to be mapped.
150      */
151     valueField: undefined,
152     
153     
154     /**
155      * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
156      * field's data value (defaults to the underlying DOM element's name)
157      */
158     hiddenName: undefined,
159     /**
160      * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
161      */
162     listClass: '',
163     /**
164      * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
165      */
166     selectedClass: 'active',
167     
168     /**
169      * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
170      */
171     shadow:'sides',
172     /**
173      * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
174      * anchor positions (defaults to 'tl-bl')
175      */
176     listAlign: 'tl-bl?',
177     /**
178      * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
179      */
180     maxHeight: 300,
181     /**
182      * @cfg {String} triggerAction The action to execute when the trigger field is activated.  Use 'all' to run the
183      * query specified by the allQuery config option (defaults to 'query')
184      */
185     triggerAction: 'query',
186     /**
187      * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
188      * (defaults to 4, does not apply if editable = false)
189      */
190     minChars : 4,
191     /**
192      * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
193      * delay (typeAheadDelay) if it matches a known value (defaults to false)
194      */
195     typeAhead: false,
196     /**
197      * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
198      * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
199      */
200     queryDelay: 500,
201     /**
202      * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
203      * filter queries will execute with page start and limit parameters.  Only applies when mode = 'remote' (defaults to 0)
204      */
205     pageSize: 0,
206     /**
207      * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus.  Only applies
208      * when editable = true (defaults to false)
209      */
210     selectOnFocus:false,
211     /**
212      * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
213      */
214     queryParam: 'query',
215     /**
216      * @cfg {String} loadingText The text to display in the dropdown list while data is loading.  Only applies
217      * when mode = 'remote' (defaults to 'Loading...')
218      */
219     loadingText: 'Loading...',
220     /**
221      * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
222      */
223     resizable: false,
224     /**
225      * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
226      */
227     handleHeight : 8,
228     /**
229      * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
230      * traditional select (defaults to true)
231      */
232     editable: true,
233     /**
234      * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
235      */
236     allQuery: '',
237     /**
238      * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
239      */
240     mode: 'remote',
241     /**
242      * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
243      * listWidth has a higher value)
244      */
245     minListWidth : 70,
246     /**
247      * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
248      * allow the user to set arbitrary text into the field (defaults to false)
249      */
250     forceSelection:false,
251     /**
252      * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
253      * if typeAhead = true (defaults to 250)
254      */
255     typeAheadDelay : 250,
256     /**
257      * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
258      * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
259      */
260     valueNotFoundText : undefined,
261     /**
262      * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
263      */
264     blockFocus : false,
265     
266     /**
267      * @cfg {Boolean} disableClear Disable showing of clear button.
268      */
269     disableClear : false,
270     /**
271      * @cfg {Boolean} alwaysQuery  Disable caching of results, and always send query
272      */
273     alwaysQuery : false,
274     
275     /**
276      * @cfg {Boolean} multiple  (true|false) ComboBobArray, default false
277      */
278     multiple : false,
279     
280     /**
281      * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
282      */
283     invalidClass : "has-warning",
284     
285     /**
286      * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
287      */
288     validClass : "has-success",
289     
290     /**
291      * @cfg {Boolean} specialFilter (true|false) special filter default false
292      */
293     specialFilter : false,
294     
295     /**
296      * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
297      */
298     mobileTouchView : true,
299     
300     //private
301     addicon : false,
302     editicon: false,
303     
304     page: 0,
305     hasQuery: false,
306     append: false,
307     loadNext: false,
308     autoFocus : true,
309     tickable : false,
310     btnPosition : 'right',
311     triggerList : true,
312     showToggleBtn : true,
313     animate : true,
314     emptyResultText: 'Empty',
315     triggerText : 'Select',
316     
317     // element that contains real text value.. (when hidden is used..)
318     
319     getAutoCreate : function()
320     {
321         var cfg = false;
322         
323         /*
324          * Touch Devices
325          */
326         
327         if(Roo.isTouch && this.mobileTouchView){
328             cfg = this.getAutoCreateTouchView();
329             return cfg;;
330         }
331         
332         /*
333          *  Normal ComboBox
334          */
335         if(!this.tickable){
336             cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
337             return cfg;
338         }
339         
340         /*
341          *  ComboBox with tickable selections
342          */
343              
344         var align = this.labelAlign || this.parentLabelAlign();
345         
346         cfg = {
347             cls : 'form-group roo-combobox-tickable' //input-group
348         };
349         
350         var buttons = {
351             tag : 'div',
352             cls : 'tickable-buttons',
353             cn : [
354                 {
355                     tag : 'button',
356                     type : 'button',
357                     cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
358                     html : this.triggerText
359                 },
360                 {
361                     tag : 'button',
362                     type : 'button',
363                     name : 'ok',
364                     cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
365                     html : 'Done'
366                 },
367                 {
368                     tag : 'button',
369                     type : 'button',
370                     name : 'cancel',
371                     cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
372                     html : 'Cancel'
373                 }
374             ]
375         };
376         
377         if(this.editable){
378             buttons.cn.unshift({
379                 tag: 'input',
380                 cls: 'select2-search-field-input'
381             });
382         }
383         
384         var _this = this;
385         
386         Roo.each(buttons.cn, function(c){
387             if (_this.size) {
388                 c.cls += ' btn-' + _this.size;
389             }
390
391             if (_this.disabled) {
392                 c.disabled = true;
393             }
394         });
395         
396         var box = {
397             tag: 'div',
398             cn: [
399                 {
400                     tag: 'input',
401                     type : 'hidden',
402                     cls: 'form-hidden-field'
403                 },
404                 {
405                     tag: 'ul',
406                     cls: 'select2-choices',
407                     cn:[
408                         {
409                             tag: 'li',
410                             cls: 'select2-search-field',
411                             cn: [
412
413                                 buttons
414                             ]
415                         }
416                     ]
417                 }
418             ]
419         };
420         
421         var combobox = {
422             cls: 'select2-container input-group select2-container-multi',
423             cn: [
424                 box
425 //                {
426 //                    tag: 'ul',
427 //                    cls: 'typeahead typeahead-long dropdown-menu',
428 //                    style: 'display:none; max-height:' + this.maxHeight + 'px;'
429 //                }
430             ]
431         };
432         
433         if(this.hasFeedback && !this.allowBlank){
434             
435             var feedback = {
436                 tag: 'span',
437                 cls: 'glyphicon form-control-feedback'
438             };
439
440             combobox.cn.push(feedback);
441         }
442         
443         if (align ==='left' && this.fieldLabel.length) {
444             
445                 Roo.log("left and has label");
446                 cfg.cn = [
447                     
448                     {
449                         tag: 'label',
450                         'for' :  id,
451                         cls : 'control-label col-sm-' + this.labelWidth,
452                         html : this.fieldLabel
453                         
454                     },
455                     {
456                         cls : "col-sm-" + (12 - this.labelWidth), 
457                         cn: [
458                             combobox
459                         ]
460                     }
461                     
462                 ];
463         } else if ( this.fieldLabel.length) {
464                 Roo.log(" label");
465                  cfg.cn = [
466                    
467                     {
468                         tag: 'label',
469                         //cls : 'input-group-addon',
470                         html : this.fieldLabel
471                         
472                     },
473                     
474                     combobox
475                     
476                 ];
477
478         } else {
479             
480                 Roo.log(" no label && no align");
481                 cfg = combobox
482                      
483                 
484         }
485          
486         var settings=this;
487         ['xs','sm','md','lg'].map(function(size){
488             if (settings[size]) {
489                 cfg.cls += ' col-' + size + '-' + settings[size];
490             }
491         });
492         
493         return cfg;
494         
495     },
496     
497     _initEventsCalled : false,
498     
499     // private
500     initEvents: function()
501     {
502         
503         if (this._initEventsCalled) { // as we call render... prevent looping...
504             return;
505         }
506         this._initEventsCalled = true;
507         
508         if (!this.store) {
509             throw "can not find store for combo";
510         }
511         
512         this.store = Roo.factory(this.store, Roo.data);
513         
514         // if we are building from html. then this element is so complex, that we can not really
515         // use the rendered HTML.
516         // so we have to trash and replace the previous code.
517         if (Roo.XComponent.build_from_html) {
518             
519             // remove this element....
520             var e = this.el.dom, k=0;
521             while (e ) { e = e.previousSibling;  ++k;}
522
523             this.el.remove();
524             
525             this.el=false;
526             this.rendered = false;
527             
528             this.render(this.parent().getChildContainer(true), k);
529             
530             
531             
532         }
533         
534         
535         /*
536          * Touch Devices
537          */
538         
539         if(Roo.isTouch && this.mobileTouchView){
540             this.initTouchView();
541             return;
542         }
543         
544         if(this.tickable){
545             this.initTickableEvents();
546             return;
547         }
548         
549         Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
550         
551         if(this.hiddenName){
552             
553             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
554             
555             this.hiddenField.dom.value =
556                 this.hiddenValue !== undefined ? this.hiddenValue :
557                 this.value !== undefined ? this.value : '';
558
559             // prevent input submission
560             this.el.dom.removeAttribute('name');
561             this.hiddenField.dom.setAttribute('name', this.hiddenName);
562              
563              
564         }
565         //if(Roo.isGecko){
566         //    this.el.dom.setAttribute('autocomplete', 'off');
567         //}
568         
569         var cls = 'x-combo-list';
570         
571         //this.list = new Roo.Layer({
572         //    shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
573         //});
574         
575         var _this = this;
576         
577         (function(){
578             var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
579             _this.list.setWidth(lw);
580         }).defer(100);
581         
582         this.list.on('mouseover', this.onViewOver, this);
583         this.list.on('mousemove', this.onViewMove, this);
584         
585         this.list.on('scroll', this.onViewScroll, this);
586         
587         /*
588         this.list.swallowEvent('mousewheel');
589         this.assetHeight = 0;
590
591         if(this.title){
592             this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
593             this.assetHeight += this.header.getHeight();
594         }
595
596         this.innerList = this.list.createChild({cls:cls+'-inner'});
597         this.innerList.on('mouseover', this.onViewOver, this);
598         this.innerList.on('mousemove', this.onViewMove, this);
599         this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
600         
601         if(this.allowBlank && !this.pageSize && !this.disableClear){
602             this.footer = this.list.createChild({cls:cls+'-ft'});
603             this.pageTb = new Roo.Toolbar(this.footer);
604            
605         }
606         if(this.pageSize){
607             this.footer = this.list.createChild({cls:cls+'-ft'});
608             this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
609                     {pageSize: this.pageSize});
610             
611         }
612         
613         if (this.pageTb && this.allowBlank && !this.disableClear) {
614             var _this = this;
615             this.pageTb.add(new Roo.Toolbar.Fill(), {
616                 cls: 'x-btn-icon x-btn-clear',
617                 text: ' ',
618                 handler: function()
619                 {
620                     _this.collapse();
621                     _this.clearValue();
622                     _this.onSelect(false, -1);
623                 }
624             });
625         }
626         if (this.footer) {
627             this.assetHeight += this.footer.getHeight();
628         }
629         */
630             
631         if(!this.tpl){
632             this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
633         }
634
635         this.view = new Roo.View(this.list, this.tpl, {
636             singleSelect:true, store: this.store, selectedClass: this.selectedClass
637         });
638         //this.view.wrapEl.setDisplayed(false);
639         this.view.on('click', this.onViewClick, this);
640         
641         
642         
643         this.store.on('beforeload', this.onBeforeLoad, this);
644         this.store.on('load', this.onLoad, this);
645         this.store.on('loadexception', this.onLoadException, this);
646         /*
647         if(this.resizable){
648             this.resizer = new Roo.Resizable(this.list,  {
649                pinned:true, handles:'se'
650             });
651             this.resizer.on('resize', function(r, w, h){
652                 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
653                 this.listWidth = w;
654                 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
655                 this.restrictHeight();
656             }, this);
657             this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
658         }
659         */
660         if(!this.editable){
661             this.editable = true;
662             this.setEditable(false);
663         }
664         
665         /*
666         
667         if (typeof(this.events.add.listeners) != 'undefined') {
668             
669             this.addicon = this.wrap.createChild(
670                 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });  
671        
672             this.addicon.on('click', function(e) {
673                 this.fireEvent('add', this);
674             }, this);
675         }
676         if (typeof(this.events.edit.listeners) != 'undefined') {
677             
678             this.editicon = this.wrap.createChild(
679                 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });  
680             if (this.addicon) {
681                 this.editicon.setStyle('margin-left', '40px');
682             }
683             this.editicon.on('click', function(e) {
684                 
685                 // we fire even  if inothing is selected..
686                 this.fireEvent('edit', this, this.lastData );
687                 
688             }, this);
689         }
690         */
691         
692         this.keyNav = new Roo.KeyNav(this.inputEl(), {
693             "up" : function(e){
694                 this.inKeyMode = true;
695                 this.selectPrev();
696             },
697
698             "down" : function(e){
699                 if(!this.isExpanded()){
700                     this.onTriggerClick();
701                 }else{
702                     this.inKeyMode = true;
703                     this.selectNext();
704                 }
705             },
706
707             "enter" : function(e){
708 //                this.onViewClick();
709                 //return true;
710                 this.collapse();
711                 
712                 if(this.fireEvent("specialkey", this, e)){
713                     this.onViewClick(false);
714                 }
715                 
716                 return true;
717             },
718
719             "esc" : function(e){
720                 this.collapse();
721             },
722
723             "tab" : function(e){
724                 this.collapse();
725                 
726                 if(this.fireEvent("specialkey", this, e)){
727                     this.onViewClick(false);
728                 }
729                 
730                 return true;
731             },
732
733             scope : this,
734
735             doRelay : function(foo, bar, hname){
736                 if(hname == 'down' || this.scope.isExpanded()){
737                    return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
738                 }
739                 return true;
740             },
741
742             forceKeyDown: true
743         });
744         
745         
746         this.queryDelay = Math.max(this.queryDelay || 10,
747                 this.mode == 'local' ? 10 : 250);
748         
749         
750         this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
751         
752         if(this.typeAhead){
753             this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
754         }
755         if(this.editable !== false){
756             this.inputEl().on("keyup", this.onKeyUp, this);
757         }
758         if(this.forceSelection){
759             this.inputEl().on('blur', this.doForce, this);
760         }
761         
762         if(this.multiple){
763             this.choices = this.el.select('ul.select2-choices', true).first();
764             this.searchField = this.el.select('ul li.select2-search-field', true).first();
765         }
766     },
767     
768     initTickableEvents: function()
769     {   
770         this.createList();
771         
772         if(this.hiddenName){
773             
774             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
775             
776             this.hiddenField.dom.value =
777                 this.hiddenValue !== undefined ? this.hiddenValue :
778                 this.value !== undefined ? this.value : '';
779
780             // prevent input submission
781             this.el.dom.removeAttribute('name');
782             this.hiddenField.dom.setAttribute('name', this.hiddenName);
783              
784              
785         }
786         
787 //        this.list = this.el.select('ul.dropdown-menu',true).first();
788         
789         this.choices = this.el.select('ul.select2-choices', true).first();
790         this.searchField = this.el.select('ul li.select2-search-field', true).first();
791         if(this.triggerList){
792             this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
793         }
794          
795         this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
796         this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
797         
798         this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
799         this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
800         
801         this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
802         this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
803         
804         this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
805         this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
806         this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
807         
808         this.okBtn.hide();
809         this.cancelBtn.hide();
810         
811         var _this = this;
812         
813         (function(){
814             var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
815             _this.list.setWidth(lw);
816         }).defer(100);
817         
818         this.list.on('mouseover', this.onViewOver, this);
819         this.list.on('mousemove', this.onViewMove, this);
820         
821         this.list.on('scroll', this.onViewScroll, this);
822         
823         if(!this.tpl){
824             this.tpl = '<li class="select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></li>';
825         }
826
827         this.view = new Roo.View(this.list, this.tpl, {
828             singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
829         });
830         
831         //this.view.wrapEl.setDisplayed(false);
832         this.view.on('click', this.onViewClick, this);
833         
834         
835         
836         this.store.on('beforeload', this.onBeforeLoad, this);
837         this.store.on('load', this.onLoad, this);
838         this.store.on('loadexception', this.onLoadException, this);
839         
840         if(this.editable){
841             this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
842                 "up" : function(e){
843                     this.inKeyMode = true;
844                     this.selectPrev();
845                 },
846
847                 "down" : function(e){
848                     this.inKeyMode = true;
849                     this.selectNext();
850                 },
851
852                 "enter" : function(e){
853                     if(this.fireEvent("specialkey", this, e)){
854                         this.onViewClick(false);
855                     }
856                     
857                     return true;
858                 },
859
860                 "esc" : function(e){
861                     this.onTickableFooterButtonClick(e, false, false);
862                 },
863
864                 "tab" : function(e){
865                     this.fireEvent("specialkey", this, e);
866                     
867                     this.onTickableFooterButtonClick(e, false, false);
868                     
869                     return true;
870                 },
871
872                 scope : this,
873
874                 doRelay : function(e, fn, key){
875                     if(this.scope.isExpanded()){
876                        return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
877                     }
878                     return true;
879                 },
880
881                 forceKeyDown: true
882             });
883         }
884         
885         this.queryDelay = Math.max(this.queryDelay || 10,
886                 this.mode == 'local' ? 10 : 250);
887         
888         
889         this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
890         
891         if(this.typeAhead){
892             this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
893         }
894         
895         if(this.editable !== false){
896             this.tickableInputEl().on("keyup", this.onKeyUp, this);
897         }
898         
899     },
900
901     onDestroy : function(){
902         if(this.view){
903             this.view.setStore(null);
904             this.view.el.removeAllListeners();
905             this.view.el.remove();
906             this.view.purgeListeners();
907         }
908         if(this.list){
909             this.list.dom.innerHTML  = '';
910         }
911         
912         if(this.store){
913             this.store.un('beforeload', this.onBeforeLoad, this);
914             this.store.un('load', this.onLoad, this);
915             this.store.un('loadexception', this.onLoadException, this);
916         }
917         Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
918     },
919
920     // private
921     fireKey : function(e){
922         if(e.isNavKeyPress() && !this.list.isVisible()){
923             this.fireEvent("specialkey", this, e);
924         }
925     },
926
927     // private
928     onResize: function(w, h){
929 //        Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
930 //        
931 //        if(typeof w != 'number'){
932 //            // we do not handle it!?!?
933 //            return;
934 //        }
935 //        var tw = this.trigger.getWidth();
936 //       // tw += this.addicon ? this.addicon.getWidth() : 0;
937 //       // tw += this.editicon ? this.editicon.getWidth() : 0;
938 //        var x = w - tw;
939 //        this.inputEl().setWidth( this.adjustWidth('input', x));
940 //            
941 //        //this.trigger.setStyle('left', x+'px');
942 //        
943 //        if(this.list && this.listWidth === undefined){
944 //            var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
945 //            this.list.setWidth(lw);
946 //            this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
947 //        }
948         
949     
950         
951     },
952
953     /**
954      * Allow or prevent the user from directly editing the field text.  If false is passed,
955      * the user will only be able to select from the items defined in the dropdown list.  This method
956      * is the runtime equivalent of setting the 'editable' config option at config time.
957      * @param {Boolean} value True to allow the user to directly edit the field text
958      */
959     setEditable : function(value){
960         if(value == this.editable){
961             return;
962         }
963         this.editable = value;
964         if(!value){
965             this.inputEl().dom.setAttribute('readOnly', true);
966             this.inputEl().on('mousedown', this.onTriggerClick,  this);
967             this.inputEl().addClass('x-combo-noedit');
968         }else{
969             this.inputEl().dom.setAttribute('readOnly', false);
970             this.inputEl().un('mousedown', this.onTriggerClick,  this);
971             this.inputEl().removeClass('x-combo-noedit');
972         }
973     },
974
975     // private
976     
977     onBeforeLoad : function(combo,opts){
978         if(!this.hasFocus){
979             return;
980         }
981          if (!opts.add) {
982             this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
983          }
984         this.restrictHeight();
985         this.selectedIndex = -1;
986     },
987
988     // private
989     onLoad : function(){
990         
991         this.hasQuery = false;
992         
993         if(!this.hasFocus){
994             return;
995         }
996         
997         if(typeof(this.loading) !== 'undefined' && this.loading !== null){
998             this.loading.hide();
999         }
1000              
1001         if(this.store.getCount() > 0){
1002             this.expand();
1003             this.restrictHeight();
1004             if(this.lastQuery == this.allQuery){
1005                 if(this.editable && !this.tickable){
1006                     this.inputEl().dom.select();
1007                 }
1008                 
1009                 if(
1010                     !this.selectByValue(this.value, true) &&
1011                     this.autoFocus && 
1012                     (
1013                         !this.store.lastOptions ||
1014                         typeof(this.store.lastOptions.add) == 'undefined' || 
1015                         this.store.lastOptions.add != true
1016                     )
1017                 ){
1018                     this.select(0, true);
1019                 }
1020             }else{
1021                 if(this.autoFocus){
1022                     this.selectNext();
1023                 }
1024                 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1025                     this.taTask.delay(this.typeAheadDelay);
1026                 }
1027             }
1028         }else{
1029             this.onEmptyResults();
1030         }
1031         
1032         //this.el.focus();
1033     },
1034     // private
1035     onLoadException : function()
1036     {
1037         this.hasQuery = false;
1038         
1039         if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1040             this.loading.hide();
1041         }
1042         
1043         if(this.tickable && this.editable){
1044             return;
1045         }
1046         
1047         this.collapse();
1048         // only causes errors at present
1049         //Roo.log(this.store.reader.jsonData);
1050         //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1051             // fixme
1052             //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1053         //}
1054         
1055         
1056     },
1057     // private
1058     onTypeAhead : function(){
1059         if(this.store.getCount() > 0){
1060             var r = this.store.getAt(0);
1061             var newValue = r.data[this.displayField];
1062             var len = newValue.length;
1063             var selStart = this.getRawValue().length;
1064             
1065             if(selStart != len){
1066                 this.setRawValue(newValue);
1067                 this.selectText(selStart, newValue.length);
1068             }
1069         }
1070     },
1071
1072     // private
1073     onSelect : function(record, index){
1074         
1075         if(this.fireEvent('beforeselect', this, record, index) !== false){
1076         
1077             this.setFromData(index > -1 ? record.data : false);
1078             
1079             this.collapse();
1080             this.fireEvent('select', this, record, index);
1081         }
1082     },
1083
1084     /**
1085      * Returns the currently selected field value or empty string if no value is set.
1086      * @return {String} value The selected value
1087      */
1088     getValue : function(){
1089         
1090         if(this.multiple){
1091             return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1092         }
1093         
1094         if(this.valueField){
1095             return typeof this.value != 'undefined' ? this.value : '';
1096         }else{
1097             return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1098         }
1099     },
1100
1101     /**
1102      * Clears any text/value currently set in the field
1103      */
1104     clearValue : function(){
1105         if(this.hiddenField){
1106             this.hiddenField.dom.value = '';
1107         }
1108         this.value = '';
1109         this.setRawValue('');
1110         this.lastSelectionText = '';
1111         this.lastData = false;
1112         
1113         var close = this.closeTriggerEl();
1114         
1115         if(close){
1116             close.hide();
1117         }
1118         
1119     },
1120
1121     /**
1122      * Sets the specified value into the field.  If the value finds a match, the corresponding record text
1123      * will be displayed in the field.  If the value does not match the data value of an existing item,
1124      * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1125      * Otherwise the field will be blank (although the value will still be set).
1126      * @param {String} value The value to match
1127      */
1128     setValue : function(v){
1129         if(this.multiple){
1130             this.syncValue();
1131             return;
1132         }
1133         
1134         var text = v;
1135         if(this.valueField){
1136             var r = this.findRecord(this.valueField, v);
1137             if(r){
1138                 text = r.data[this.displayField];
1139             }else if(this.valueNotFoundText !== undefined){
1140                 text = this.valueNotFoundText;
1141             }
1142         }
1143         this.lastSelectionText = text;
1144         if(this.hiddenField){
1145             this.hiddenField.dom.value = v;
1146         }
1147         Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1148         this.value = v;
1149         
1150         var close = this.closeTriggerEl();
1151         
1152         if(close){
1153             (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1154         }
1155     },
1156     /**
1157      * @property {Object} the last set data for the element
1158      */
1159     
1160     lastData : false,
1161     /**
1162      * Sets the value of the field based on a object which is related to the record format for the store.
1163      * @param {Object} value the value to set as. or false on reset?
1164      */
1165     setFromData : function(o){
1166         
1167         if(this.multiple){
1168             this.addItem(o);
1169             return;
1170         }
1171             
1172         var dv = ''; // display value
1173         var vv = ''; // value value..
1174         this.lastData = o;
1175         if (this.displayField) {
1176             dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1177         } else {
1178             // this is an error condition!!!
1179             Roo.log('no  displayField value set for '+ (this.name ? this.name : this.id));
1180         }
1181         
1182         if(this.valueField){
1183             vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1184         }
1185         
1186         var close = this.closeTriggerEl();
1187         
1188         if(close){
1189             (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1190         }
1191         
1192         if(this.hiddenField){
1193             this.hiddenField.dom.value = vv;
1194             
1195             this.lastSelectionText = dv;
1196             Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1197             this.value = vv;
1198             return;
1199         }
1200         // no hidden field.. - we store the value in 'value', but still display
1201         // display field!!!!
1202         this.lastSelectionText = dv;
1203         Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1204         this.value = vv;
1205         
1206         
1207         
1208     },
1209     // private
1210     reset : function(){
1211         // overridden so that last data is reset..
1212         
1213         if(this.multiple){
1214             this.clearItem();
1215             return;
1216         }
1217         
1218         this.setValue(this.originalValue);
1219         this.clearInvalid();
1220         this.lastData = false;
1221         if (this.view) {
1222             this.view.clearSelections();
1223         }
1224     },
1225     // private
1226     findRecord : function(prop, value){
1227         var record;
1228         if(this.store.getCount() > 0){
1229             this.store.each(function(r){
1230                 if(r.data[prop] == value){
1231                     record = r;
1232                     return false;
1233                 }
1234                 return true;
1235             });
1236         }
1237         return record;
1238     },
1239     
1240     getName: function()
1241     {
1242         // returns hidden if it's set..
1243         if (!this.rendered) {return ''};
1244         return !this.hiddenName && this.inputEl().dom.name  ? this.inputEl().dom.name : (this.hiddenName || '');
1245         
1246     },
1247     // private
1248     onViewMove : function(e, t){
1249         this.inKeyMode = false;
1250     },
1251
1252     // private
1253     onViewOver : function(e, t){
1254         if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1255             return;
1256         }
1257         var item = this.view.findItemFromChild(t);
1258         
1259         if(item){
1260             var index = this.view.indexOf(item);
1261             this.select(index, false);
1262         }
1263     },
1264
1265     // private
1266     onViewClick : function(view, doFocus, el, e)
1267     {
1268         var index = this.view.getSelectedIndexes()[0];
1269         
1270         var r = this.store.getAt(index);
1271         
1272         if(this.tickable){
1273             
1274             if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1275                 return;
1276             }
1277             
1278             var rm = false;
1279             var _this = this;
1280             
1281             
1282             
1283             Roo.each(this.tickItems, function(v,k){
1284                 
1285                 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1286                     Roo.log(v);
1287                     _this.tickItems.splice(k, 1);
1288                     
1289                     if(typeof(e) == 'undefined' && view == false){
1290                         Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1291                     }
1292                     
1293                     rm = true;
1294                     return;
1295                 }
1296             });
1297             Roo.log(this.tickItems);
1298             Roo.log(rm);
1299             if(rm){
1300                 return;
1301             }
1302             Roo.log(this.tickItems);
1303             if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1304                 //this.tickItems.push(r.data);
1305             }
1306             Roo.log(this.tickItems);
1307             if(typeof(e) == 'undefined' && view == false){
1308                 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1309             }
1310                     
1311             return;
1312         }
1313         
1314         if(r){
1315             this.onSelect(r, index);
1316         }
1317         if(doFocus !== false && !this.blockFocus){
1318             this.inputEl().focus();
1319         }
1320     },
1321
1322     // private
1323     restrictHeight : function(){
1324         //this.innerList.dom.style.height = '';
1325         //var inner = this.innerList.dom;
1326         //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1327         //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1328         //this.list.beginUpdate();
1329         //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1330         this.list.alignTo(this.inputEl(), this.listAlign);
1331         this.list.alignTo(this.inputEl(), this.listAlign);
1332         //this.list.endUpdate();
1333     },
1334
1335     // private
1336     onEmptyResults : function(){
1337         
1338         if(this.tickable && this.editable){
1339             this.restrictHeight();
1340             return;
1341         }
1342         
1343         this.collapse();
1344     },
1345
1346     /**
1347      * Returns true if the dropdown list is expanded, else false.
1348      */
1349     isExpanded : function(){
1350         return this.list.isVisible();
1351     },
1352
1353     /**
1354      * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1355      * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1356      * @param {String} value The data value of the item to select
1357      * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1358      * selected item if it is not currently in view (defaults to true)
1359      * @return {Boolean} True if the value matched an item in the list, else false
1360      */
1361     selectByValue : function(v, scrollIntoView){
1362         if(v !== undefined && v !== null){
1363             var r = this.findRecord(this.valueField || this.displayField, v);
1364             if(r){
1365                 this.select(this.store.indexOf(r), scrollIntoView);
1366                 return true;
1367             }
1368         }
1369         return false;
1370     },
1371
1372     /**
1373      * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1374      * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1375      * @param {Number} index The zero-based index of the list item to select
1376      * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1377      * selected item if it is not currently in view (defaults to true)
1378      */
1379     select : function(index, scrollIntoView){
1380         this.selectedIndex = index;
1381         this.view.select(index);
1382         if(scrollIntoView !== false){
1383             var el = this.view.getNode(index);
1384             /*
1385              * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1386              */
1387             if(el){
1388                 this.list.scrollChildIntoView(el, false);
1389             }
1390         }
1391     },
1392
1393     // private
1394     selectNext : function(){
1395         var ct = this.store.getCount();
1396         if(ct > 0){
1397             if(this.selectedIndex == -1){
1398                 this.select(0);
1399             }else if(this.selectedIndex < ct-1){
1400                 this.select(this.selectedIndex+1);
1401             }
1402         }
1403     },
1404
1405     // private
1406     selectPrev : function(){
1407         var ct = this.store.getCount();
1408         if(ct > 0){
1409             if(this.selectedIndex == -1){
1410                 this.select(0);
1411             }else if(this.selectedIndex != 0){
1412                 this.select(this.selectedIndex-1);
1413             }
1414         }
1415     },
1416
1417     // private
1418     onKeyUp : function(e){
1419         if(this.editable !== false && !e.isSpecialKey()){
1420             this.lastKey = e.getKey();
1421             this.dqTask.delay(this.queryDelay);
1422         }
1423     },
1424
1425     // private
1426     validateBlur : function(){
1427         return !this.list || !this.list.isVisible();   
1428     },
1429
1430     // private
1431     initQuery : function(){
1432         
1433         var v = this.getRawValue();
1434         
1435         if(this.tickable && this.editable){
1436             v = this.tickableInputEl().getValue();
1437         }
1438         
1439         this.doQuery(v);
1440     },
1441
1442     // private
1443     doForce : function(){
1444         if(this.inputEl().dom.value.length > 0){
1445             this.inputEl().dom.value =
1446                 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1447              
1448         }
1449     },
1450
1451     /**
1452      * Execute a query to filter the dropdown list.  Fires the beforequery event prior to performing the
1453      * query allowing the query action to be canceled if needed.
1454      * @param {String} query The SQL query to execute
1455      * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1456      * in the field than the minimum specified by the minChars config option.  It also clears any filter previously
1457      * saved in the current store (defaults to false)
1458      */
1459     doQuery : function(q, forceAll){
1460         
1461         if(q === undefined || q === null){
1462             q = '';
1463         }
1464         var qe = {
1465             query: q,
1466             forceAll: forceAll,
1467             combo: this,
1468             cancel:false
1469         };
1470         if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1471             return false;
1472         }
1473         q = qe.query;
1474         
1475         forceAll = qe.forceAll;
1476         if(forceAll === true || (q.length >= this.minChars)){
1477             
1478             this.hasQuery = true;
1479             
1480             if(this.lastQuery != q || this.alwaysQuery){
1481                 this.lastQuery = q;
1482                 if(this.mode == 'local'){
1483                     this.selectedIndex = -1;
1484                     if(forceAll){
1485                         this.store.clearFilter();
1486                     }else{
1487                         
1488                         if(this.specialFilter){
1489                             this.fireEvent('specialfilter', this);
1490                             this.onLoad();
1491                             return;
1492                         }
1493                         
1494                         this.store.filter(this.displayField, q);
1495                     }
1496                     
1497                     this.store.fireEvent("datachanged", this.store);
1498                     
1499                     this.onLoad();
1500                     
1501                     
1502                 }else{
1503                     
1504                     this.store.baseParams[this.queryParam] = q;
1505                     
1506                     var options = {params : this.getParams(q)};
1507                     
1508                     if(this.loadNext){
1509                         options.add = true;
1510                         options.params.start = this.page * this.pageSize;
1511                     }
1512                     
1513                     this.store.load(options);
1514                     
1515                     /*
1516                      *  this code will make the page width larger, at the beginning, the list not align correctly, 
1517                      *  we should expand the list on onLoad
1518                      *  so command out it
1519                      */
1520 //                    this.expand();
1521                 }
1522             }else{
1523                 this.selectedIndex = -1;
1524                 this.onLoad();   
1525             }
1526         }
1527         
1528         this.loadNext = false;
1529     },
1530     
1531     // private
1532     getParams : function(q){
1533         var p = {};
1534         //p[this.queryParam] = q;
1535         
1536         if(this.pageSize){
1537             p.start = 0;
1538             p.limit = this.pageSize;
1539         }
1540         return p;
1541     },
1542
1543     /**
1544      * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1545      */
1546     collapse : function(){
1547         if(!this.isExpanded()){
1548             return;
1549         }
1550         
1551         this.list.hide();
1552         
1553         if(this.tickable){
1554             this.hasFocus = false;
1555             this.okBtn.hide();
1556             this.cancelBtn.hide();
1557             this.trigger.show();
1558             
1559             if(this.editable){
1560                 this.tickableInputEl().dom.value = '';
1561                 this.tickableInputEl().blur();
1562             }
1563             
1564         }
1565         
1566         Roo.get(document).un('mousedown', this.collapseIf, this);
1567         Roo.get(document).un('mousewheel', this.collapseIf, this);
1568         if (!this.editable) {
1569             Roo.get(document).un('keydown', this.listKeyPress, this);
1570         }
1571         this.fireEvent('collapse', this);
1572     },
1573
1574     // private
1575     collapseIf : function(e){
1576         var in_combo  = e.within(this.el);
1577         var in_list =  e.within(this.list);
1578         var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1579         
1580         if (in_combo || in_list || is_list) {
1581             //e.stopPropagation();
1582             return;
1583         }
1584         
1585         if(this.tickable){
1586             this.onTickableFooterButtonClick(e, false, false);
1587         }
1588
1589         this.collapse();
1590         
1591     },
1592
1593     /**
1594      * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1595      */
1596     expand : function(){
1597        
1598         if(this.isExpanded() || !this.hasFocus){
1599             return;
1600         }
1601         
1602         var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1603         this.list.setWidth(lw);
1604         
1605         
1606          Roo.log('expand');
1607         
1608         this.list.show();
1609         
1610         this.restrictHeight();
1611         
1612         if(this.tickable){
1613             
1614             this.tickItems = Roo.apply([], this.item);
1615             
1616             this.okBtn.show();
1617             this.cancelBtn.show();
1618             this.trigger.hide();
1619             
1620             if(this.editable){
1621                 this.tickableInputEl().focus();
1622             }
1623             
1624         }
1625         
1626         Roo.get(document).on('mousedown', this.collapseIf, this);
1627         Roo.get(document).on('mousewheel', this.collapseIf, this);
1628         if (!this.editable) {
1629             Roo.get(document).on('keydown', this.listKeyPress, this);
1630         }
1631         
1632         this.fireEvent('expand', this);
1633     },
1634
1635     // private
1636     // Implements the default empty TriggerField.onTriggerClick function
1637     onTriggerClick : function(e)
1638     {
1639         Roo.log('trigger click');
1640         
1641         if(this.disabled || !this.triggerList){
1642             return;
1643         }
1644         
1645         this.page = 0;
1646         this.loadNext = false;
1647         
1648         if(this.isExpanded()){
1649             this.collapse();
1650             if (!this.blockFocus) {
1651                 this.inputEl().focus();
1652             }
1653             
1654         }else {
1655             this.hasFocus = true;
1656             if(this.triggerAction == 'all') {
1657                 this.doQuery(this.allQuery, true);
1658             } else {
1659                 this.doQuery(this.getRawValue());
1660             }
1661             if (!this.blockFocus) {
1662                 this.inputEl().focus();
1663             }
1664         }
1665     },
1666     
1667     onTickableTriggerClick : function(e)
1668     {
1669         if(this.disabled){
1670             return;
1671         }
1672         
1673         this.page = 0;
1674         this.loadNext = false;
1675         this.hasFocus = true;
1676         
1677         if(this.triggerAction == 'all') {
1678             this.doQuery(this.allQuery, true);
1679         } else {
1680             this.doQuery(this.getRawValue());
1681         }
1682     },
1683     
1684     onSearchFieldClick : function(e)
1685     {
1686         if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1687             this.onTickableFooterButtonClick(e, false, false);
1688             return;
1689         }
1690         
1691         if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1692             return;
1693         }
1694         
1695         this.page = 0;
1696         this.loadNext = false;
1697         this.hasFocus = true;
1698         
1699         if(this.triggerAction == 'all') {
1700             this.doQuery(this.allQuery, true);
1701         } else {
1702             this.doQuery(this.getRawValue());
1703         }
1704     },
1705     
1706     listKeyPress : function(e)
1707     {
1708         //Roo.log('listkeypress');
1709         // scroll to first matching element based on key pres..
1710         if (e.isSpecialKey()) {
1711             return false;
1712         }
1713         var k = String.fromCharCode(e.getKey()).toUpperCase();
1714         //Roo.log(k);
1715         var match  = false;
1716         var csel = this.view.getSelectedNodes();
1717         var cselitem = false;
1718         if (csel.length) {
1719             var ix = this.view.indexOf(csel[0]);
1720             cselitem  = this.store.getAt(ix);
1721             if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1722                 cselitem = false;
1723             }
1724             
1725         }
1726         
1727         this.store.each(function(v) { 
1728             if (cselitem) {
1729                 // start at existing selection.
1730                 if (cselitem.id == v.id) {
1731                     cselitem = false;
1732                 }
1733                 return true;
1734             }
1735                 
1736             if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1737                 match = this.store.indexOf(v);
1738                 return false;
1739             }
1740             return true;
1741         }, this);
1742         
1743         if (match === false) {
1744             return true; // no more action?
1745         }
1746         // scroll to?
1747         this.view.select(match);
1748         var sn = Roo.get(this.view.getSelectedNodes()[0])
1749         sn.scrollIntoView(sn.dom.parentNode, false);
1750     },
1751     
1752     onViewScroll : function(e, t){
1753         
1754         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){
1755             return;
1756         }
1757         
1758         this.hasQuery = true;
1759         
1760         this.loading = this.list.select('.loading', true).first();
1761         
1762         if(this.loading === null){
1763             this.list.createChild({
1764                 tag: 'div',
1765                 cls: 'loading select2-more-results select2-active',
1766                 html: 'Loading more results...'
1767             })
1768             
1769             this.loading = this.list.select('.loading', true).first();
1770             
1771             this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1772             
1773             this.loading.hide();
1774         }
1775         
1776         this.loading.show();
1777         
1778         var _combo = this;
1779         
1780         this.page++;
1781         this.loadNext = true;
1782         
1783         (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1784         
1785         return;
1786     },
1787     
1788     addItem : function(o)
1789     {   
1790         var dv = ''; // display value
1791         
1792         if (this.displayField) {
1793             dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1794         } else {
1795             // this is an error condition!!!
1796             Roo.log('no  displayField value set for '+ (this.name ? this.name : this.id));
1797         }
1798         
1799         if(!dv.length){
1800             return;
1801         }
1802         
1803         var choice = this.choices.createChild({
1804             tag: 'li',
1805             cls: 'select2-search-choice',
1806             cn: [
1807                 {
1808                     tag: 'div',
1809                     html: dv
1810                 },
1811                 {
1812                     tag: 'a',
1813                     href: '#',
1814                     cls: 'select2-search-choice-close',
1815                     tabindex: '-1'
1816                 }
1817             ]
1818             
1819         }, this.searchField);
1820         
1821         var close = choice.select('a.select2-search-choice-close', true).first()
1822         
1823         close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
1824         
1825         this.item.push(o);
1826         
1827         this.lastData = o;
1828         
1829         this.syncValue();
1830         
1831         this.inputEl().dom.value = '';
1832         
1833         this.validate();
1834     },
1835     
1836     onRemoveItem : function(e, _self, o)
1837     {
1838         e.preventDefault();
1839         
1840         this.lastItem = Roo.apply([], this.item);
1841         
1842         var index = this.item.indexOf(o.data) * 1;
1843         
1844         if( index < 0){
1845             Roo.log('not this item?!');
1846             return;
1847         }
1848         
1849         this.item.splice(index, 1);
1850         o.item.remove();
1851         
1852         this.syncValue();
1853         
1854         this.fireEvent('remove', this, e);
1855         
1856         this.validate();
1857         
1858     },
1859     
1860     syncValue : function()
1861     {
1862         if(!this.item.length){
1863             this.clearValue();
1864             return;
1865         }
1866             
1867         var value = [];
1868         var _this = this;
1869         Roo.each(this.item, function(i){
1870             if(_this.valueField){
1871                 value.push(i[_this.valueField]);
1872                 return;
1873             }
1874
1875             value.push(i);
1876         });
1877
1878         this.value = value.join(',');
1879
1880         if(this.hiddenField){
1881             this.hiddenField.dom.value = this.value;
1882         }
1883         
1884         this.store.fireEvent("datachanged", this.store);
1885     },
1886     
1887     clearItem : function()
1888     {
1889         if(!this.multiple){
1890             return;
1891         }
1892         
1893         this.item = [];
1894         
1895         Roo.each(this.choices.select('>li.select2-search-choice', true).elements, function(c){
1896            c.remove();
1897         });
1898         
1899         this.syncValue();
1900         
1901         this.validate();
1902         
1903         if(this.tickable && !Roo.isTouch){
1904             this.view.refresh();
1905         }
1906     },
1907     
1908     inputEl: function ()
1909     {
1910         if(Roo.isTouch && this.mobileTouchView){
1911             return this.el.select('input.form-control',true).first();
1912         }
1913         
1914         if(this.tickable){
1915             return this.searchField;
1916         }
1917         
1918         return this.el.select('input.form-control',true).first();
1919     },
1920     
1921     
1922     onTickableFooterButtonClick : function(e, btn, el)
1923     {
1924         e.preventDefault();
1925         
1926         this.lastItem = Roo.apply([], this.item);
1927         
1928         if(btn && btn.name == 'cancel'){
1929             this.tickItems = Roo.apply([], this.item);
1930             this.collapse();
1931             return;
1932         }
1933         
1934         this.clearItem();
1935         
1936         var _this = this;
1937         
1938         Roo.each(this.tickItems, function(o){
1939             _this.addItem(o);
1940         });
1941         
1942         this.collapse();
1943         
1944     },
1945     
1946     validate : function()
1947     {
1948         var v = this.getRawValue();
1949         
1950         if(this.multiple){
1951             v = this.getValue();
1952         }
1953         
1954         if(this.disabled || this.allowBlank || v.length){
1955             this.markValid();
1956             return true;
1957         }
1958         
1959         this.markInvalid();
1960         return false;
1961     },
1962     
1963     tickableInputEl : function()
1964     {
1965         if(!this.tickable || !this.editable){
1966             return this.inputEl();
1967         }
1968         
1969         return this.inputEl().select('.select2-search-field-input', true).first();
1970     },
1971     
1972     
1973     getAutoCreateTouchView : function()
1974     {
1975         var id = Roo.id();
1976         
1977         var cfg = {
1978             cls: 'form-group' //input-group
1979         };
1980         
1981         var input =  {
1982             tag: 'input',
1983             id : id,
1984             type : this.inputType,
1985             cls : 'form-control x-combo-noedit',
1986             autocomplete: 'new-password',
1987             placeholder : this.placeholder || '',
1988             readonly : true
1989         };
1990         
1991         if (this.name) {
1992             input.name = this.name;
1993         }
1994         
1995         if (this.size) {
1996             input.cls += ' input-' + this.size;
1997         }
1998         
1999         if (this.disabled) {
2000             input.disabled = true;
2001         }
2002         
2003         var inputblock = {
2004             cls : '',
2005             cn : [
2006                 input
2007             ]
2008         };
2009         
2010         if(this.before){
2011             inputblock.cls += ' input-group';
2012             
2013             inputblock.cn.unshift({
2014                 tag :'span',
2015                 cls : 'input-group-addon',
2016                 html : this.before
2017             });
2018         }
2019         
2020         if(this.removable && !this.multiple){
2021             inputblock.cls += ' roo-removable';
2022             
2023             inputblock.cn.push({
2024                 tag: 'button',
2025                 html : 'x',
2026                 cls : 'roo-combo-removable-btn close'
2027             });
2028         }
2029
2030         if(this.hasFeedback && !this.allowBlank){
2031             
2032             inputblock.cls += ' has-feedback';
2033             
2034             inputblock.cn.push({
2035                 tag: 'span',
2036                 cls: 'glyphicon form-control-feedback'
2037             });
2038             
2039         }
2040         
2041         if (this.after) {
2042             
2043             inputblock.cls += (this.before) ? '' : ' input-group';
2044             
2045             inputblock.cn.push({
2046                 tag :'span',
2047                 cls : 'input-group-addon',
2048                 html : this.after
2049             });
2050         }
2051
2052         var box = {
2053             tag: 'div',
2054             cn: [
2055                 {
2056                     tag: 'input',
2057                     type : 'hidden',
2058                     cls: 'form-hidden-field'
2059                 },
2060                 inputblock
2061             ]
2062             
2063         };
2064         
2065         if(this.multiple){
2066             box = {
2067                 tag: 'div',
2068                 cn: [
2069                     {
2070                         tag: 'input',
2071                         type : 'hidden',
2072                         cls: 'form-hidden-field'
2073                     },
2074                     {
2075                         tag: 'ul',
2076                         cls: 'select2-choices',
2077                         cn:[
2078                             {
2079                                 tag: 'li',
2080                                 cls: 'select2-search-field',
2081                                 cn: [
2082
2083                                     inputblock
2084                                 ]
2085                             }
2086                         ]
2087                     }
2088                 ]
2089             }
2090         };
2091         
2092         var combobox = {
2093             cls: 'select2-container input-group',
2094             cn: [
2095                 box
2096             ]
2097         };
2098         
2099         if(this.multiple){
2100             combobox.cls += ' select2-container-multi';
2101         }
2102         
2103         var align = this.labelAlign || this.parentLabelAlign();
2104         
2105         cfg.cn = combobox;
2106         
2107         if(this.fieldLabel.length){
2108             
2109             var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
2110             var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
2111             
2112             cfg.cn = [
2113                 {
2114                     tag: 'label',
2115                     cls : 'control-label ' + lw,
2116                     html : this.fieldLabel
2117
2118                 },
2119                 {
2120                     cls : cw, 
2121                     cn: [
2122                         combobox
2123                     ]
2124                 }
2125             ];
2126         }
2127         
2128         var settings = this;
2129         
2130         ['xs','sm','md','lg'].map(function(size){
2131             if (settings[size]) {
2132                 cfg.cls += ' col-' + size + '-' + settings[size];
2133             }
2134         });
2135         
2136         return cfg;
2137     },
2138     
2139     initTouchView : function()
2140     {
2141         this.renderTouchView();
2142         
2143         this.touchViewEl.on('scroll', function(){
2144             this.el.dom.scrollTop = 0;
2145         }, this);
2146         
2147         this.inputEl().on("click", this.showTouchView, this);
2148         this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2149         this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2150         
2151         this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2152         
2153         this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2154         this.store.on('load', this.onTouchViewLoad, this);
2155         this.store.on('loadexception', this.onTouchViewLoadException, this);
2156         
2157         if(this.hiddenName){
2158             
2159             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2160             
2161             this.hiddenField.dom.value =
2162                 this.hiddenValue !== undefined ? this.hiddenValue :
2163                 this.value !== undefined ? this.value : '';
2164         
2165             this.el.dom.removeAttribute('name');
2166             this.hiddenField.dom.setAttribute('name', this.hiddenName);
2167         }
2168         
2169         if(this.multiple){
2170             this.choices = this.el.select('ul.select2-choices', true).first();
2171             this.searchField = this.el.select('ul li.select2-search-field', true).first();
2172         }
2173         
2174         if(this.removable && !this.multiple){
2175             var close = this.closeTriggerEl();
2176             if(close){
2177                 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2178                 close.on('click', this.removeBtnClick, this, close);
2179             }
2180         }
2181         
2182         return;
2183         
2184         
2185     },
2186     
2187     renderTouchView : function()
2188     {
2189         this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2190         this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2191         
2192         this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2193         this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2194         
2195         this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2196         this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2197         this.touchViewBodyEl.setStyle('overflow', 'auto');
2198         
2199         this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2200         this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2201         
2202         this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2203         this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2204         
2205     },
2206     
2207     showTouchView : function()
2208     {
2209         this.touchViewHeaderEl.hide();
2210
2211         if(this.fieldLabel.length){
2212             this.touchViewHeaderEl.dom.innerHTML = this.fieldLabel;
2213             this.touchViewHeaderEl.show();
2214         }
2215
2216         this.touchViewEl.show();
2217
2218         this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2219         this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2220
2221         var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2222
2223         if(this.fieldLabel.length){
2224             bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2225         }
2226         
2227         this.touchViewBodyEl.setHeight(bodyHeight);
2228
2229         if(this.animate){
2230             var _this = this;
2231             (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2232         }else{
2233             this.touchViewEl.addClass('in');
2234         }
2235
2236         this.doTouchViewQuery();
2237         
2238     },
2239     
2240     hideTouchView : function()
2241     {
2242         this.touchViewEl.removeClass('in');
2243
2244         if(this.animate){
2245             var _this = this;
2246             (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2247         }else{
2248             this.touchViewEl.setStyle('display', 'none');
2249         }
2250         
2251     },
2252     
2253     setTouchViewValue : function()
2254     {
2255         if(this.multiple){
2256             this.clearItem();
2257         
2258             var _this = this;
2259
2260             Roo.each(this.tickItems, function(o){
2261                 this.addItem(o);
2262             }, this);
2263         }
2264         
2265         this.hideTouchView();
2266     },
2267     
2268     doTouchViewQuery : function()
2269     {
2270         var qe = {
2271             query: '',
2272             forceAll: true,
2273             combo: this,
2274             cancel:false
2275         };
2276         
2277         if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2278             return false;
2279         }
2280         
2281         if(!this.alwaysQuery || this.mode == 'local'){
2282             this.onTouchViewLoad();
2283             return;
2284         }
2285         
2286         this.store.load();
2287     },
2288     
2289     onTouchViewBeforeLoad : function(combo,opts)
2290     {
2291         return;
2292     },
2293
2294     // private
2295     onTouchViewLoad : function()
2296     {
2297         if(this.store.getCount() < 1){
2298             this.onTouchViewEmptyResults();
2299             return;
2300         }
2301         
2302         this.clearTouchView();
2303         
2304         var rawValue = this.getRawValue();
2305         
2306         var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2307         
2308         this.tickItems = [];
2309         
2310         this.store.data.each(function(d, rowIndex){
2311             var row = this.touchViewListGroup.createChild(template);
2312             
2313             if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2314                 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = d.data[this.displayField];
2315             }
2316             
2317             if(!this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue()){
2318                 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2319             }
2320             
2321             if(this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1){
2322                 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2323                 this.tickItems.push(d.data);
2324             }
2325             
2326             row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2327             
2328         }, this);
2329         
2330         var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2331         
2332         var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2333
2334         if(this.fieldLabel.length){
2335             bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2336         }
2337
2338         var listHeight = this.touchViewListGroup.getHeight();
2339         
2340         var _this = this;
2341         
2342         if(firstChecked && listHeight > bodyHeight){
2343             (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2344         }
2345         
2346     },
2347     
2348     onTouchViewLoadException : function()
2349     {
2350         this.hideTouchView();
2351     },
2352     
2353     onTouchViewEmptyResults : function()
2354     {
2355         this.clearTouchView();
2356         
2357         this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2358         
2359         this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2360         
2361     },
2362     
2363     clearTouchView : function()
2364     {
2365         this.touchViewListGroup.dom.innerHTML = '';
2366     },
2367     
2368     onTouchViewClick : function(e, el, o)
2369     {
2370         e.preventDefault();
2371         
2372         var row = o.row;
2373         var rowIndex = o.rowIndex;
2374         
2375         var r = this.store.getAt(rowIndex);
2376         
2377         if(!this.multiple){
2378             Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2379                 c.dom.removeAttribute('checked');
2380             }, this);
2381             
2382             row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2383         
2384             this.setFromData(r.data);
2385             
2386             var close = this.closeTriggerEl();
2387         
2388             if(close){
2389                 close.show();
2390             }
2391
2392             this.hideTouchView();
2393             
2394             this.fireEvent('select', this, r, rowIndex);
2395             
2396             return;
2397         }
2398         
2399         if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2400             row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2401             this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2402             return;
2403         }
2404         
2405         row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2406         this.addItem(r.data);
2407         this.tickItems.push(r.data);
2408         
2409     }
2410     
2411
2412     /** 
2413     * @cfg {Boolean} grow 
2414     * @hide 
2415     */
2416     /** 
2417     * @cfg {Number} growMin 
2418     * @hide 
2419     */
2420     /** 
2421     * @cfg {Number} growMax 
2422     * @hide 
2423     */
2424     /**
2425      * @hide
2426      * @method autoSize
2427      */
2428 });
2429
2430 Roo.apply(Roo.bootstrap.ComboBox,  {
2431     
2432     header : {
2433         tag: 'div',
2434         cls: 'modal-header',
2435         cn: [
2436             {
2437                 tag: 'h4',
2438                 cls: 'modal-title'
2439             }
2440         ]
2441     },
2442     
2443     body : {
2444         tag: 'div',
2445         cls: 'modal-body',
2446         cn: [
2447             {
2448                 tag: 'ul',
2449                 cls: 'list-group'
2450             }
2451         ]
2452     },
2453     
2454     listItemRadio : {
2455         tag: 'li',
2456         cls: 'list-group-item',
2457         cn: [
2458             {
2459                 tag: 'span',
2460                 cls: 'roo-combobox-list-group-item-value'
2461             },
2462             {
2463                 tag: 'div',
2464                 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2465                 cn: [
2466                     {
2467                         tag: 'input',
2468                         type: 'radio'
2469                     },
2470                     {
2471                         tag: 'label'
2472                     }
2473                 ]
2474             }
2475         ]
2476     },
2477     
2478     listItemCheckbox : {
2479         tag: 'li',
2480         cls: 'list-group-item',
2481         cn: [
2482             {
2483                 tag: 'span',
2484                 cls: 'roo-combobox-list-group-item-value'
2485             },
2486             {
2487                 tag: 'div',
2488                 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
2489                 cn: [
2490                     {
2491                         tag: 'input',
2492                         type: 'checkbox'
2493                     },
2494                     {
2495                         tag: 'label'
2496                     }
2497                 ]
2498             }
2499         ]
2500     },
2501     
2502     emptyResult : {
2503         tag: 'div',
2504         cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
2505     },
2506     
2507     footer : {
2508         tag: 'div',
2509         cls: 'modal-footer',
2510         cn: [
2511             {
2512                 tag: 'div',
2513                 cls: 'row',
2514                 cn: [
2515                     {
2516                         tag: 'div',
2517                         cls: 'col-xs-6 text-left',
2518                         cn: {
2519                             tag: 'button',
2520                             cls: 'btn btn-danger roo-touch-view-cancel',
2521                             html: 'Cancel'
2522                         }
2523                     },
2524                     {
2525                         tag: 'div',
2526                         cls: 'col-xs-6 text-right',
2527                         cn: {
2528                             tag: 'button',
2529                             cls: 'btn btn-success roo-touch-view-ok',
2530                             html: 'OK'
2531                         }
2532                     }
2533                 ]
2534             }
2535         ]
2536         
2537     }
2538 });
2539
2540 Roo.apply(Roo.bootstrap.ComboBox,  {
2541     
2542     touchViewTemplate : {
2543         tag: 'div',
2544         cls: 'modal fade roo-combobox-touch-view',
2545         cn: [
2546             {
2547                 tag: 'div',
2548                 cls: 'modal-dialog',
2549                 cn: [
2550                     {
2551                         tag: 'div',
2552                         cls: 'modal-content',
2553                         cn: [
2554                             Roo.bootstrap.ComboBox.header,
2555                             Roo.bootstrap.ComboBox.body,
2556                             Roo.bootstrap.ComboBox.footer
2557                         ]
2558                     }
2559                 ]
2560             }
2561         ]
2562     }
2563 });