Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
27 jpm 1
/*
2
 * Ext JS Library 2.0.2
3
 * Copyright(c) 2006-2008, Ext JS, LLC.
4
 * licensing@extjs.com
5
 *
6
 * http://extjs.com/license
7
 */
8
 
9
/**
10
 * @class Ext.form.ComboBox
11
 * @extends Ext.form.TriggerField
12
 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
13
 * @constructor
14
 * Create a new ComboBox.
15
 * @param {Object} config Configuration options
16
 */
17
Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {
18
    /**
19
     * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.
20
     * Note that if you specify this and the combo is going to be in a {@link Ext.form.BasicForm} or
21
     * {@link Ext.form.FormPanel}, you must also set {@link #lazyRender} = true.
22
     */
23
    /**
24
     * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
25
     * rendering into an Ext.Editor, defaults to false).
26
     */
27
    /**
28
     * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
29
     * {tag: "input", type: "text", size: "24", autocomplete: "off"})
30
     */
31
    /**
32
     * @cfg {Ext.data.Store} store The data store to which this combo is bound (defaults to undefined)
33
     */
34
    /**
35
     * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
36
     * the dropdown list (defaults to undefined, with no header element)
37
     */
38
 
39
    // private
40
    defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
41
    /**
42
     * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
43
     */
44
    /**
45
     * @cfg {String} displayField The underlying data field name to bind to this ComboBox (defaults to undefined if
46
     * mode = 'remote' or 'text' if transforming a select)
47
     */
48
    /**
49
     * @cfg {String} valueField The underlying data value name to bind to this ComboBox (defaults to undefined if
50
     * mode = 'remote' or 'value' if transforming a select) Note: use of a valueField requires the user to make a selection
51
     * in order for a value to be mapped.
52
     */
53
    /**
54
     * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
55
     * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically
56
     * post during a form submission.
57
     */
58
    /**
59
     * @cfg {String} hiddenId If {@link #hiddenName} is specified, hiddenId can also be provided to give the hidden field
60
     * a unique id (defaults to the hiddenName).  The hiddenId and combo {@link #id} should be different, since no two DOM
61
     * nodes should share the same id.
62
     */
63
    /**
64
     * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
65
     */
66
    listClass: '',
67
    /**
68
     * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
69
     */
70
    selectedClass: 'x-combo-selected',
71
    /**
72
     * @cfg {String} triggerClass An additional CSS class used to style the trigger button.  The trigger will always get the
73
     * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
74
     * which displays a downward arrow icon).
75
     */
76
    triggerClass : 'x-form-arrow-trigger',
77
    /**
78
     * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
79
     */
80
    shadow:'sides',
81
    /**
82
     * @cfg {String} listAlign A valid anchor position value. See {@link Ext.Element#alignTo} for details on supported
83
     * anchor positions (defaults to 'tl-bl')
84
     */
85
    listAlign: 'tl-bl?',
86
    /**
87
     * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
88
     */
89
    maxHeight: 300,
90
    /**
91
     * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
92
     * distance to the viewport edges (defaults to 90)
93
     */
94
    minHeight: 90,
95
    /**
96
     * @cfg {String} triggerAction The action to execute when the trigger field is activated.  Use 'all' to run the
97
     * query specified by the allQuery config option (defaults to 'query')
98
     */
99
    triggerAction: 'query',
100
    /**
101
     * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
102
     * (defaults to 4 if remote or 0 if local, does not apply if editable = false)
103
     */
104
    minChars : 4,
105
    /**
106
     * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
107
     * delay (typeAheadDelay) if it matches a known value (defaults to false)
108
     */
109
    typeAhead: false,
110
    /**
111
     * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
112
     * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
113
     */
114
    queryDelay: 500,
115
    /**
116
     * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
117
     * filter queries will execute with page start and limit parameters.  Only applies when mode = 'remote' (defaults to 0)
118
     */
119
    pageSize: 0,
120
    /**
121
     * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus.  Only applies
122
     * when editable = true (defaults to false)
123
     */
124
    selectOnFocus:false,
125
    /**
126
     * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
127
     */
128
    queryParam: 'query',
129
    /**
130
     * @cfg {String} loadingText The text to display in the dropdown list while data is loading.  Only applies
131
     * when mode = 'remote' (defaults to 'Loading...')
132
     */
133
    loadingText: 'Loading...',
134
    /**
135
     * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
136
     */
137
    resizable: false,
138
    /**
139
     * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
140
     */
141
    handleHeight : 8,
142
    /**
143
     * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
144
     * traditional select (defaults to true)
145
     */
146
    editable: true,
147
    /**
148
     * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
149
     */
150
    allQuery: '',
151
    /**
152
     * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
153
     */
154
    mode: 'remote',
155
    /**
156
     * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
157
     * listWidth has a higher value)
158
     */
159
    minListWidth : 70,
160
    /**
161
     * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
162
     * allow the user to set arbitrary text into the field (defaults to false)
163
     */
164
    forceSelection:false,
165
    /**
166
     * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
167
     * if typeAhead = true (defaults to 250)
168
     */
169
    typeAheadDelay : 250,
170
    /**
171
     * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
172
     * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
173
     */
174
 
175
    /**
176
     * @cfg {Boolean} lazyInit True to not initialize the list for this combo until the field is focused. (defaults to true)
177
     */
178
    lazyInit : true,
179
 
180
    initComponent : function(){
181
        Ext.form.ComboBox.superclass.initComponent.call(this);
182
        this.addEvents(
183
            /**
184
             * @event expand
185
             * Fires when the dropdown list is expanded
186
             * @param {Ext.form.ComboBox} combo This combo box
187
             */
188
            'expand',
189
            /**
190
             * @event collapse
191
             * Fires when the dropdown list is collapsed
192
             * @param {Ext.form.ComboBox} combo This combo box
193
             */
194
            'collapse',
195
            /**
196
             * @event beforeselect
197
             * Fires before a list item is selected. Return false to cancel the selection.
198
             * @param {Ext.form.ComboBox} combo This combo box
199
             * @param {Ext.data.Record} record The data record returned from the underlying store
200
             * @param {Number} index The index of the selected item in the dropdown list
201
             */
202
            'beforeselect',
203
            /**
204
             * @event select
205
             * Fires when a list item is selected
206
             * @param {Ext.form.ComboBox} combo This combo box
207
             * @param {Ext.data.Record} record The data record returned from the underlying store
208
             * @param {Number} index The index of the selected item in the dropdown list
209
             */
210
            'select',
211
            /**
212
             * @event beforequery
213
             * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
214
             * cancel property to true.
215
             * @param {Object} queryEvent An object that has these properties:<ul>
216
             * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
217
             * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
218
             * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
219
             * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
220
             * </ul>
221
             */
222
            'beforequery'
223
        );
224
        if(this.transform){
225
            this.allowDomMove = false;
226
            var s = Ext.getDom(this.transform);
227
            if(!this.hiddenName){
228
                this.hiddenName = s.name;
229
            }
230
            if(!this.store){
231
                this.mode = 'local';
232
                var d = [], opts = s.options;
233
                for(var i = 0, len = opts.length;i < len; i++){
234
                    var o = opts[i];
235
                    var value = (Ext.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
236
                    if(o.selected) {
237
                        this.value = value;
238
                    }
239
                    d.push([value, o.text]);
240
                }
241
                this.store = new Ext.data.SimpleStore({
242
                    'id': 0,
243
                    fields: ['value', 'text'],
244
                    data : d
245
                });
246
                this.valueField = 'value';
247
                this.displayField = 'text';
248
            }
249
            s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
250
            if(!this.lazyRender){
251
                this.target = true;
252
                this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
253
                Ext.removeNode(s); // remove it
254
                this.render(this.el.parentNode);
255
            }else{
256
                Ext.removeNode(s); // remove it
257
            }
258
 
259
        }
260
        this.selectedIndex = -1;
261
        if(this.mode == 'local'){
262
            if(this.initialConfig.queryDelay === undefined){
263
                this.queryDelay = 10;
264
            }
265
            if(this.initialConfig.minChars === undefined){
266
                this.minChars = 0;
267
            }
268
        }
269
    },
270
 
271
    // private
272
    onRender : function(ct, position){
273
        Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
274
        if(this.hiddenName){
275
            this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
276
                    'before', true);
277
            this.hiddenField.value =
278
                this.hiddenValue !== undefined ? this.hiddenValue :
279
                this.value !== undefined ? this.value : '';
280
 
281
            // prevent input submission
282
            this.el.dom.removeAttribute('name');
283
        }
284
        if(Ext.isGecko){
285
            this.el.dom.setAttribute('autocomplete', 'off');
286
        }
287
 
288
        if(!this.lazyInit){
289
            this.initList();
290
        }else{
291
            this.on('focus', this.initList, this, {single: true});
292
        }
293
 
294
        if(!this.editable){
295
            this.editable = true;
296
            this.setEditable(false);
297
        }
298
    },
299
 
300
    initList : function(){
301
        if(!this.list){
302
            var cls = 'x-combo-list';
303
 
304
            this.list = new Ext.Layer({
305
                shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
306
            });
307
 
308
            var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
309
            this.list.setWidth(lw);
310
            this.list.swallowEvent('mousewheel');
311
            this.assetHeight = 0;
312
 
313
            if(this.title){
314
                this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
315
                this.assetHeight += this.header.getHeight();
316
            }
317
 
318
            this.innerList = this.list.createChild({cls:cls+'-inner'});
319
            this.innerList.on('mouseover', this.onViewOver, this);
320
            this.innerList.on('mousemove', this.onViewMove, this);
321
            this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
322
 
323
            if(this.pageSize){
324
                this.footer = this.list.createChild({cls:cls+'-ft'});
325
                this.pageTb = new Ext.PagingToolbar({
326
                    store:this.store,
327
                    pageSize: this.pageSize,
328
                    renderTo:this.footer
329
                });
330
                this.assetHeight += this.footer.getHeight();
331
            }
332
 
333
            if(!this.tpl){
334
			    /**
335
			    * @cfg {String/Ext.XTemplate} tpl The template string, or {@link Ext.XTemplate}
336
			    * instance to use to display each item in the dropdown list. Use
337
			    * this to create custom UI layouts for items in the list.
338
			    * <p>
339
			    * If you wish to preserve the default visual look of list items, add the CSS
340
			    * class name <pre>x-combo-list-item</pre> to the template's container element.
341
			    * <p>
342
			    * <b>The template must contain one or more substitution parameters using field
343
			    * names from the Combo's</b> {@link #store Store}. An example of a custom template
344
			    * would be adding an <pre>ext:qtip</pre> attribute which might display other fields
345
			    * from the Store.
346
			    * <p>
347
			    * The dropdown list is displayed in a DataView. See {@link Ext.DataView} for details.
348
			    */
349
                this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
350
            }
351
 
352
		    /**
353
		    * The {@link Ext.DataView DataView} used to display the ComboBox's options.
354
		    * @type Ext.DataView
355
		    */
356
            this.view = new Ext.DataView({
357
                applyTo: this.innerList,
358
                tpl: this.tpl,
359
                singleSelect: true,
360
                selectedClass: this.selectedClass,
361
                itemSelector: this.itemSelector || '.' + cls + '-item'
362
            });
363
 
364
            this.view.on('click', this.onViewClick, this);
365
 
366
            this.bindStore(this.store, true);
367
 
368
            if(this.resizable){
369
                this.resizer = new Ext.Resizable(this.list,  {
370
                   pinned:true, handles:'se'
371
                });
372
                this.resizer.on('resize', function(r, w, h){
373
                    this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
374
                    this.listWidth = w;
375
                    this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
376
                    this.restrictHeight();
377
                }, this);
378
                this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
379
            }
380
        }
381
    },
382
 
383
 
384
    // private
385
    bindStore : function(store, initial){
386
        if(this.store && !initial){
387
            this.store.un('beforeload', this.onBeforeLoad, this);
388
            this.store.un('load', this.onLoad, this);
389
            this.store.un('loadexception', this.collapse, this);
390
            if(!store){
391
                this.store = null;
392
                if(this.view){
393
                    this.view.setStore(null);
394
                }
395
            }
396
        }
397
        if(store){
398
            this.store = Ext.StoreMgr.lookup(store);
399
 
400
            this.store.on('beforeload', this.onBeforeLoad, this);
401
            this.store.on('load', this.onLoad, this);
402
            this.store.on('loadexception', this.collapse, this);
403
 
404
            if(this.view){
405
                this.view.setStore(store);
406
            }
407
        }
408
    },
409
 
410
    // private
411
    initEvents : function(){
412
        Ext.form.ComboBox.superclass.initEvents.call(this);
413
 
414
        this.keyNav = new Ext.KeyNav(this.el, {
415
            "up" : function(e){
416
                this.inKeyMode = true;
417
                this.selectPrev();
418
            },
419
 
420
            "down" : function(e){
421
                if(!this.isExpanded()){
422
                    this.onTriggerClick();
423
                }else{
424
                    this.inKeyMode = true;
425
                    this.selectNext();
426
                }
427
            },
428
 
429
            "enter" : function(e){
430
                this.onViewClick();
431
                this.delayedCheck = true;
432
				this.unsetDelayCheck.defer(10, this);
433
            },
434
 
435
            "esc" : function(e){
436
                this.collapse();
437
            },
438
 
439
            "tab" : function(e){
440
                this.onViewClick(false);
441
                return true;
442
            },
443
 
444
            scope : this,
445
 
446
            doRelay : function(foo, bar, hname){
447
                if(hname == 'down' || this.scope.isExpanded()){
448
                   return Ext.KeyNav.prototype.doRelay.apply(this, arguments);
449
                }
450
                return true;
451
            },
452
 
453
            forceKeyDown : true
454
        });
455
        this.queryDelay = Math.max(this.queryDelay || 10,
456
                this.mode == 'local' ? 10 : 250);
457
        this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
458
        if(this.typeAhead){
459
            this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
460
        }
461
        if(this.editable !== false){
462
            this.el.on("keyup", this.onKeyUp, this);
463
        }
464
        if(this.forceSelection){
465
            this.on('blur', this.doForce, this);
466
        }
467
    },
468
 
469
    onDestroy : function(){
470
        if(this.view){
471
            this.view.el.removeAllListeners();
472
            this.view.el.remove();
473
            this.view.purgeListeners();
474
        }
475
        if(this.list){
476
            this.list.destroy();
477
        }
478
        this.bindStore(null);
479
        Ext.form.ComboBox.superclass.onDestroy.call(this);
480
    },
481
 
482
	unsetDelayCheck : function(){
483
		delete this.delayedCheck;
484
	},
485
    // private
486
    fireKey : function(e){
487
        if(e.isNavKeyPress() && !this.isExpanded() && !this.delayedCheck){
488
            this.fireEvent("specialkey", this, e);
489
        }
490
    },
491
 
492
    // private
493
    onResize: function(w, h){
494
        Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
495
        if(this.list && this.listWidth === undefined){
496
            var lw = Math.max(w, this.minListWidth);
497
            this.list.setWidth(lw);
498
            this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
499
        }
500
    },
501
 
502
    // private
503
    onEnable: function(){
504
        Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
505
        if(this.hiddenField){
506
            this.hiddenField.disabled = false;
507
        }
508
    },
509
 
510
    // private
511
    onDisable: function(){
512
        Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
513
        if(this.hiddenField){
514
            this.hiddenField.disabled = true;
515
        }
516
    },
517
 
518
    /**
519
     * Allow or prevent the user from directly editing the field text.  If false is passed,
520
     * the user will only be able to select from the items defined in the dropdown list.  This method
521
     * is the runtime equivalent of setting the 'editable' config option at config time.
522
     * @param {Boolean} value True to allow the user to directly edit the field text
523
     */
524
    setEditable : function(value){
525
        if(value == this.editable){
526
            return;
527
        }
528
        this.editable = value;
529
        if(!value){
530
            this.el.dom.setAttribute('readOnly', true);
531
            this.el.on('mousedown', this.onTriggerClick,  this);
532
            this.el.addClass('x-combo-noedit');
533
        }else{
534
            this.el.dom.setAttribute('readOnly', false);
535
            this.el.un('mousedown', this.onTriggerClick,  this);
536
            this.el.removeClass('x-combo-noedit');
537
        }
538
    },
539
 
540
    // private
541
    onBeforeLoad : function(){
542
        if(!this.hasFocus){
543
            return;
544
        }
545
        this.innerList.update(this.loadingText ?
546
               '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
547
        this.restrictHeight();
548
        this.selectedIndex = -1;
549
    },
550
 
551
    // private
552
    onLoad : function(){
553
        if(!this.hasFocus){
554
            return;
555
        }
556
        if(this.store.getCount() > 0){
557
            this.expand();
558
            this.restrictHeight();
559
            if(this.lastQuery == this.allQuery){
560
                if(this.editable){
561
                    this.el.dom.select();
562
                }
563
                if(!this.selectByValue(this.value, true)){
564
                    this.select(0, true);
565
                }
566
            }else{
567
                this.selectNext();
568
                if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
569
                    this.taTask.delay(this.typeAheadDelay);
570
                }
571
            }
572
        }else{
573
            this.onEmptyResults();
574
        }
575
        //this.el.focus();
576
    },
577
 
578
    // private
579
    onTypeAhead : function(){
580
        if(this.store.getCount() > 0){
581
            var r = this.store.getAt(0);
582
            var newValue = r.data[this.displayField];
583
            var len = newValue.length;
584
            var selStart = this.getRawValue().length;
585
            if(selStart != len){
586
                this.setRawValue(newValue);
587
                this.selectText(selStart, newValue.length);
588
            }
589
        }
590
    },
591
 
592
    // private
593
    onSelect : function(record, index){
594
        if(this.fireEvent('beforeselect', this, record, index) !== false){
595
            this.setValue(record.data[this.valueField || this.displayField]);
596
            this.collapse();
597
            this.fireEvent('select', this, record, index);
598
        }
599
    },
600
 
601
    /**
602
     * Returns the currently selected field value or empty string if no value is set.
603
     * @return {String} value The selected value
604
     */
605
    getValue : function(){
606
        if(this.valueField){
607
            return typeof this.value != 'undefined' ? this.value : '';
608
        }else{
609
            return Ext.form.ComboBox.superclass.getValue.call(this);
610
        }
611
    },
612
 
613
    /**
614
     * Clears any text/value currently set in the field
615
     */
616
    clearValue : function(){
617
        if(this.hiddenField){
618
            this.hiddenField.value = '';
619
        }
620
        this.setRawValue('');
621
        this.lastSelectionText = '';
622
        this.applyEmptyText();
623
        this.value = '';
624
    },
625
 
626
    /**
627
     * Sets the specified value into the field.  If the value finds a match, the corresponding record text
628
     * will be displayed in the field.  If the value does not match the data value of an existing item,
629
     * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
630
     * Otherwise the field will be blank (although the value will still be set).
631
     * @param {String} value The value to match
632
     */
633
    setValue : function(v){
634
        var text = v;
635
        if(this.valueField){
636
            var r = this.findRecord(this.valueField, v);
637
            if(r){
638
                text = r.data[this.displayField];
639
            }else if(this.valueNotFoundText !== undefined){
640
                text = this.valueNotFoundText;
641
            }
642
        }
643
        this.lastSelectionText = text;
644
        if(this.hiddenField){
645
            this.hiddenField.value = v;
646
        }
647
        Ext.form.ComboBox.superclass.setValue.call(this, text);
648
        this.value = v;
649
    },
650
 
651
    // private
652
    findRecord : function(prop, value){
653
        var record;
654
        if(this.store.getCount() > 0){
655
            this.store.each(function(r){
656
                if(r.data[prop] == value){
657
                    record = r;
658
                    return false;
659
                }
660
            });
661
        }
662
        return record;
663
    },
664
 
665
    // private
666
    onViewMove : function(e, t){
667
        this.inKeyMode = false;
668
    },
669
 
670
    // private
671
    onViewOver : function(e, t){
672
        if(this.inKeyMode){ // prevent key nav and mouse over conflicts
673
            return;
674
        }
675
        var item = this.view.findItemFromChild(t);
676
        if(item){
677
            var index = this.view.indexOf(item);
678
            this.select(index, false);
679
        }
680
    },
681
 
682
    // private
683
    onViewClick : function(doFocus){
684
        var index = this.view.getSelectedIndexes()[0];
685
        var r = this.store.getAt(index);
686
        if(r){
687
            this.onSelect(r, index);
688
        }
689
        if(doFocus !== false){
690
            this.el.focus();
691
        }
692
    },
693
 
694
    // private
695
	restrictHeight : function(){
696
        this.innerList.dom.style.height = '';
697
        var inner = this.innerList.dom;
698
        var pad = this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight;
699
        var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
700
        var ha = this.getPosition()[1]-Ext.getBody().getScroll().top;
701
        var hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height;
702
        var space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadow.offset-pad-2;
703
        h = Math.min(h, space, this.maxHeight);
704
 
705
        this.innerList.setHeight(h);
706
        this.list.beginUpdate();
707
        this.list.setHeight(h+pad);
708
        this.list.alignTo(this.el, this.listAlign);
709
        this.list.endUpdate();
710
    },
711
 
712
    // private
713
    onEmptyResults : function(){
714
        this.collapse();
715
    },
716
 
717
    /**
718
     * Returns true if the dropdown list is expanded, else false.
719
     */
720
    isExpanded : function(){
721
        return this.list && this.list.isVisible();
722
    },
723
 
724
    /**
725
     * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
726
     * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
727
     * @param {String} value The data value of the item to select
728
     * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
729
     * selected item if it is not currently in view (defaults to true)
730
     * @return {Boolean} True if the value matched an item in the list, else false
731
     */
732
    selectByValue : function(v, scrollIntoView){
733
        if(v !== undefined && v !== null){
734
            var r = this.findRecord(this.valueField || this.displayField, v);
735
            if(r){
736
                this.select(this.store.indexOf(r), scrollIntoView);
737
                return true;
738
            }
739
        }
740
        return false;
741
    },
742
 
743
    /**
744
     * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
745
     * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
746
     * @param {Number} index The zero-based index of the list item to select
747
     * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
748
     * selected item if it is not currently in view (defaults to true)
749
     */
750
    select : function(index, scrollIntoView){
751
        this.selectedIndex = index;
752
        this.view.select(index);
753
        if(scrollIntoView !== false){
754
            var el = this.view.getNode(index);
755
            if(el){
756
                this.innerList.scrollChildIntoView(el, false);
757
            }
758
        }
759
    },
760
 
761
    // private
762
    selectNext : function(){
763
        var ct = this.store.getCount();
764
        if(ct > 0){
765
            if(this.selectedIndex == -1){
766
                this.select(0);
767
            }else if(this.selectedIndex < ct-1){
768
                this.select(this.selectedIndex+1);
769
            }
770
        }
771
    },
772
 
773
    // private
774
    selectPrev : function(){
775
        var ct = this.store.getCount();
776
        if(ct > 0){
777
            if(this.selectedIndex == -1){
778
                this.select(0);
779
            }else if(this.selectedIndex != 0){
780
                this.select(this.selectedIndex-1);
781
            }
782
        }
783
    },
784
 
785
    // private
786
    onKeyUp : function(e){
787
        if(this.editable !== false && !e.isSpecialKey()){
788
            this.lastKey = e.getKey();
789
            this.dqTask.delay(this.queryDelay);
790
        }
791
    },
792
 
793
    // private
794
    validateBlur : function(){
795
        return !this.list || !this.list.isVisible();
796
    },
797
 
798
    // private
799
    initQuery : function(){
800
        this.doQuery(this.getRawValue());
801
    },
802
 
803
    // private
804
    doForce : function(){
805
        if(this.el.dom.value.length > 0){
806
            this.el.dom.value =
807
                this.lastSelectionText === undefined ? '' : this.lastSelectionText;
808
            this.applyEmptyText();
809
        }
810
    },
811
 
812
    /**
813
     * Execute a query to filter the dropdown list.  Fires the beforequery event prior to performing the
814
     * query allowing the query action to be canceled if needed.
815
     * @param {String} query The SQL query to execute
816
     * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
817
     * in the field than the minimum specified by the minChars config option.  It also clears any filter previously
818
     * saved in the current store (defaults to false)
819
     */
820
    doQuery : function(q, forceAll){
821
        if(q === undefined || q === null){
822
            q = '';
823
        }
824
        var qe = {
825
            query: q,
826
            forceAll: forceAll,
827
            combo: this,
828
            cancel:false
829
        };
830
        if(this.fireEvent('beforequery', qe)===false || qe.cancel){
831
            return false;
832
        }
833
        q = qe.query;
834
        forceAll = qe.forceAll;
835
        if(forceAll === true || (q.length >= this.minChars)){
836
            if(this.lastQuery !== q){
837
                this.lastQuery = q;
838
                if(this.mode == 'local'){
839
                    this.selectedIndex = -1;
840
                    if(forceAll){
841
                        this.store.clearFilter();
842
                    }else{
843
                        this.store.filter(this.displayField, q);
844
                    }
845
                    this.onLoad();
846
                }else{
847
                    this.store.baseParams[this.queryParam] = q;
848
                    this.store.load({
849
                        params: this.getParams(q)
850
                    });
851
                    this.expand();
852
                }
853
            }else{
854
                this.selectedIndex = -1;
855
                this.onLoad();
856
            }
857
        }
858
    },
859
 
860
    // private
861
    getParams : function(q){
862
        var p = {};
863
        //p[this.queryParam] = q;
864
        if(this.pageSize){
865
            p.start = 0;
866
            p.limit = this.pageSize;
867
        }
868
        return p;
869
    },
870
 
871
    /**
872
     * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
873
     */
874
    collapse : function(){
875
        if(!this.isExpanded()){
876
            return;
877
        }
878
        this.list.hide();
879
        Ext.getDoc().un('mousewheel', this.collapseIf, this);
880
        Ext.getDoc().un('mousedown', this.collapseIf, this);
881
        this.fireEvent('collapse', this);
882
    },
883
 
884
    // private
885
    collapseIf : function(e){
886
        if(!e.within(this.wrap) && !e.within(this.list)){
887
            this.collapse();
888
        }
889
    },
890
 
891
    /**
892
     * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
893
     */
894
    expand : function(){
895
        if(this.isExpanded() || !this.hasFocus){
896
            return;
897
        }
898
        this.list.alignTo(this.wrap, this.listAlign);
899
        this.list.show();
900
        this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
901
        Ext.getDoc().on('mousewheel', this.collapseIf, this);
902
        Ext.getDoc().on('mousedown', this.collapseIf, this);
903
        this.fireEvent('expand', this);
904
    },
905
 
906
    // private
907
    // Implements the default empty TriggerField.onTriggerClick function
908
    onTriggerClick : function(){
909
        if(this.disabled){
910
            return;
911
        }
912
        if(this.isExpanded()){
913
            this.collapse();
914
            this.el.focus();
915
        }else {
916
            this.onFocus({});
917
            if(this.triggerAction == 'all') {
918
                this.doQuery(this.allQuery, true);
919
            } else {
920
                this.doQuery(this.getRawValue());
921
            }
922
            this.el.focus();
923
        }
924
    }
925
 
926
    /**
927
     * @hide
928
     * @method autoSize
929
     */
930
    /**
931
     * @cfg {Boolean} grow @hide
932
     */
933
    /**
934
     * @cfg {Number} growMin @hide
935
     */
936
    /**
937
     * @cfg {Number} growMax @hide
938
     */
939
 
940
});
941
Ext.reg('combo', Ext.form.ComboBox);