Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / examples / ux / SelectBox.js
index d693c06..d0d63cd 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Ext JS Library 3.0.3
+ * Ext JS Library 3.1.0
  * Copyright(c) 2006-2009 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
@@ -19,182 +19,182 @@ Ext.ns('Ext.ux.form');
  * @xtype selectbox\r
  */\r
 Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {\r
-    constructor: function(config){\r
-        this.searchResetDelay = 1000;\r
-        config = config || {};\r
-        config = Ext.apply(config || {}, {\r
-            editable: false,\r
-            forceSelection: true,\r
-            rowHeight: false,\r
-            lastSearchTerm: false,\r
-            triggerAction: 'all',\r
-            mode: 'local'\r
-        });\r
-\r
-        Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);\r
-\r
-        this.lastSelectedIndex = this.selectedIndex || 0;\r
-    },\r
-\r
-    initEvents : function(){\r
-        Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);\r
-        // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE\r
-        this.el.on('keydown', this.keySearch, this, true);\r
-        this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);\r
-    },\r
-\r
-    keySearch : function(e, target, options) {\r
-        var raw = e.getKey();\r
-        var key = String.fromCharCode(raw);\r
-        var startIndex = 0;\r
-\r
-        if( !this.store.getCount() ) {\r
-            return;\r
-        }\r
-\r
-        switch(raw) {\r
-            case Ext.EventObject.HOME:\r
-                e.stopEvent();\r
-                this.selectFirst();\r
-                return;\r
-\r
-            case Ext.EventObject.END:\r
-                e.stopEvent();\r
-                this.selectLast();\r
-                return;\r
-\r
-            case Ext.EventObject.PAGEDOWN:\r
-                this.selectNextPage();\r
-                e.stopEvent();\r
-                return;\r
-\r
-            case Ext.EventObject.PAGEUP:\r
-                this.selectPrevPage();\r
-                e.stopEvent();\r
-                return;\r
-        }\r
-\r
-        // skip special keys other than the shift key\r
-        if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {\r
-            return;\r
-        }\r
-        if( this.lastSearchTerm == key ) {\r
-            startIndex = this.lastSelectedIndex;\r
-        }\r
-        this.search(this.displayField, key, startIndex);\r
-        this.cshTask.delay(this.searchResetDelay);\r
-    },\r
-\r
-    onRender : function(ct, position) {\r
-        this.store.on('load', this.calcRowsPerPage, this);\r
-        Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);\r
-        if( this.mode == 'local' ) {\r
+       constructor: function(config){\r
+               this.searchResetDelay = 1000;\r
+               config = config || {};\r
+               config = Ext.apply(config || {}, {\r
+                       editable: false,\r
+                       forceSelection: true,\r
+                       rowHeight: false,\r
+                       lastSearchTerm: false,\r
+                       triggerAction: 'all',\r
+                       mode: 'local'\r
+               });\r
+\r
+               Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);\r
+\r
+               this.lastSelectedIndex = this.selectedIndex || 0;\r
+       },\r
+\r
+       initEvents : function(){\r
+               Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);\r
+               // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE\r
+               this.el.on('keydown', this.keySearch, this, true);\r
+               this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);\r
+       },\r
+\r
+       keySearch : function(e, target, options) {\r
+               var raw = e.getKey();\r
+               var key = String.fromCharCode(raw);\r
+               var startIndex = 0;\r
+\r
+               if( !this.store.getCount() ) {\r
+                       return;\r
+               }\r
+\r
+               switch(raw) {\r
+                       case Ext.EventObject.HOME:\r
+                               e.stopEvent();\r
+                               this.selectFirst();\r
+                               return;\r
+\r
+                       case Ext.EventObject.END:\r
+                               e.stopEvent();\r
+                               this.selectLast();\r
+                               return;\r
+\r
+                       case Ext.EventObject.PAGEDOWN:\r
+                               this.selectNextPage();\r
+                               e.stopEvent();\r
+                               return;\r
+\r
+                       case Ext.EventObject.PAGEUP:\r
+                               this.selectPrevPage();\r
+                               e.stopEvent();\r
+                               return;\r
+               }\r
+\r
+               // skip special keys other than the shift key\r
+               if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {\r
+                       return;\r
+               }\r
+               if( this.lastSearchTerm == key ) {\r
+                       startIndex = this.lastSelectedIndex;\r
+               }\r
+               this.search(this.displayField, key, startIndex);\r
+               this.cshTask.delay(this.searchResetDelay);\r
+       },\r
+\r
+       onRender : function(ct, position) {\r
+               this.store.on('load', this.calcRowsPerPage, this);\r
+               Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);\r
+               if( this.mode == 'local' ) {\r
             this.initList();\r
-            this.calcRowsPerPage();\r
-        }\r
-    },\r
-\r
-    onSelect : function(record, index, skipCollapse){\r
-        if(this.fireEvent('beforeselect', this, record, index) !== false){\r
-            this.setValue(record.data[this.valueField || this.displayField]);\r
-            if( !skipCollapse ) {\r
-                this.collapse();\r
-            }\r
-            this.lastSelectedIndex = index + 1;\r
-            this.fireEvent('select', this, record, index);\r
-        }\r
-    },\r
-\r
-    afterRender : function() {\r
-        Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);\r
-        if(Ext.isWebKit) {\r
-            this.el.swallowEvent('mousedown', true);\r
-        }\r
-        this.el.unselectable();\r
-        this.innerList.unselectable();\r
-        this.trigger.unselectable();\r
-        this.innerList.on('mouseup', function(e, target, options) {\r
-            if( target.id && target.id == this.innerList.id ) {\r
-                return;\r
-            }\r
-            this.onViewClick();\r
-        }, this);\r
-\r
-        this.innerList.on('mouseover', function(e, target, options) {\r
-            if( target.id && target.id == this.innerList.id ) {\r
-                return;\r
-            }\r
-            this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;\r
-            this.cshTask.delay(this.searchResetDelay);\r
-        }, this);\r
-\r
-        this.trigger.un('click', this.onTriggerClick, this);\r
-        this.trigger.on('mousedown', function(e, target, options) {\r
-            e.preventDefault();\r
-            this.onTriggerClick();\r
-        }, this);\r
-\r
-        this.on('collapse', function(e, target, options) {\r
-            Ext.getDoc().un('mouseup', this.collapseIf, this);\r
-        }, this, true);\r
-\r
-        this.on('expand', function(e, target, options) {\r
-            Ext.getDoc().on('mouseup', this.collapseIf, this);\r
-        }, this, true);\r
-    },\r
-\r
-    clearSearchHistory : function() {\r
-        this.lastSelectedIndex = 0;\r
-        this.lastSearchTerm = false;\r
-    },\r
-\r
-    selectFirst : function() {\r
-        this.focusAndSelect(this.store.data.first());\r
-    },\r
-\r
-    selectLast : function() {\r
-        this.focusAndSelect(this.store.data.last());\r
-    },\r
-\r
-    selectPrevPage : function() {\r
-        if( !this.rowHeight ) {\r
-            return;\r
-        }\r
-        var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);\r
-        this.focusAndSelect(this.store.getAt(index));\r
-    },\r
-\r
-    selectNextPage : function() {\r
-        if( !this.rowHeight ) {\r
-            return;\r
-        }\r
-        var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);\r
-        this.focusAndSelect(this.store.getAt(index));\r
-    },\r
-\r
-    search : function(field, value, startIndex) {\r
-        field = field || this.displayField;\r
-        this.lastSearchTerm = value;\r
-        var index = this.store.find.apply(this.store, arguments);\r
-        if( index !== -1 ) {\r
-            this.focusAndSelect(index);\r
-        }\r
-    },\r
-\r
-    focusAndSelect : function(record) {\r
+                       this.calcRowsPerPage();\r
+               }\r
+       },\r
+\r
+       onSelect : function(record, index, skipCollapse){\r
+               if(this.fireEvent('beforeselect', this, record, index) !== false){\r
+                       this.setValue(record.data[this.valueField || this.displayField]);\r
+                       if( !skipCollapse ) {\r
+                               this.collapse();\r
+                       }\r
+                       this.lastSelectedIndex = index + 1;\r
+                       this.fireEvent('select', this, record, index);\r
+               }\r
+       },\r
+\r
+       afterRender : function() {\r
+               Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);\r
+               if(Ext.isWebKit) {\r
+                       this.el.swallowEvent('mousedown', true);\r
+               }\r
+               this.el.unselectable();\r
+               this.innerList.unselectable();\r
+               this.trigger.unselectable();\r
+               this.innerList.on('mouseup', function(e, target, options) {\r
+                       if( target.id && target.id == this.innerList.id ) {\r
+                               return;\r
+                       }\r
+                       this.onViewClick();\r
+               }, this);\r
+\r
+               this.innerList.on('mouseover', function(e, target, options) {\r
+                       if( target.id && target.id == this.innerList.id ) {\r
+                               return;\r
+                       }\r
+                       this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;\r
+                       this.cshTask.delay(this.searchResetDelay);\r
+               }, this);\r
+\r
+               this.trigger.un('click', this.onTriggerClick, this);\r
+               this.trigger.on('mousedown', function(e, target, options) {\r
+                       e.preventDefault();\r
+                       this.onTriggerClick();\r
+               }, this);\r
+\r
+               this.on('collapse', function(e, target, options) {\r
+                       Ext.getDoc().un('mouseup', this.collapseIf, this);\r
+               }, this, true);\r
+\r
+               this.on('expand', function(e, target, options) {\r
+                       Ext.getDoc().on('mouseup', this.collapseIf, this);\r
+               }, this, true);\r
+       },\r
+\r
+       clearSearchHistory : function() {\r
+               this.lastSelectedIndex = 0;\r
+               this.lastSearchTerm = false;\r
+       },\r
+\r
+       selectFirst : function() {\r
+               this.focusAndSelect(this.store.data.first());\r
+       },\r
+\r
+       selectLast : function() {\r
+               this.focusAndSelect(this.store.data.last());\r
+       },\r
+\r
+       selectPrevPage : function() {\r
+               if( !this.rowHeight ) {\r
+                       return;\r
+               }\r
+               var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);\r
+               this.focusAndSelect(this.store.getAt(index));\r
+       },\r
+\r
+       selectNextPage : function() {\r
+               if( !this.rowHeight ) {\r
+                       return;\r
+               }\r
+               var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);\r
+               this.focusAndSelect(this.store.getAt(index));\r
+       },\r
+\r
+       search : function(field, value, startIndex) {\r
+               field = field || this.displayField;\r
+               this.lastSearchTerm = value;\r
+               var index = this.store.find.apply(this.store, arguments);\r
+               if( index !== -1 ) {\r
+                       this.focusAndSelect(index);\r
+               }\r
+       },\r
+\r
+       focusAndSelect : function(record) {\r
         var index = Ext.isNumber(record) ? record : this.store.indexOf(record);\r
         this.select(index, this.isExpanded());\r
         this.onSelect(this.store.getAt(index), index, this.isExpanded());\r
-    },\r
-\r
-    calcRowsPerPage : function() {\r
-        if( this.store.getCount() ) {\r
-            this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();\r
-            this.rowsPerPage = this.maxHeight / this.rowHeight;\r
-        } else {\r
-            this.rowHeight = false;\r
-        }\r
-    }\r
+       },\r
+\r
+       calcRowsPerPage : function() {\r
+               if( this.store.getCount() ) {\r
+                       this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();\r
+                       this.rowsPerPage = this.maxHeight / this.rowHeight;\r
+               } else {\r
+                       this.rowHeight = false;\r
+               }\r
+       }\r
 \r
 });\r
 \r