Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / ux / grid / filter / ListFilter.js
similarity index 77%
rename from examples/ux/gridfilters/filter/ListFilter.js
rename to examples/ux/grid/filter/ListFilter.js
index f42b15e..9a6bc6f 100644 (file)
@@ -1,21 +1,15 @@
-/*!
- * Ext JS Library 3.3.1
- * Copyright(c) 2006-2010 Sencha Inc.
- * licensing@sencha.com
- * http://www.sencha.com/license
- */
-/** 
+/**
  * @class Ext.ux.grid.filter.ListFilter
  * @extends Ext.ux.grid.filter.Filter
  * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
  * their options the first time they are shown. ListFilter utilizes the
- * {@link Ext.ux.menu.ListMenu} component.</p>
+ * {@link Ext.ux.grid.menu.ListMenu} component.</p>
  * <p>Although not shown here, this class accepts all configuration options
- * for {@link Ext.ux.menu.ListMenu}.</p>
- * 
+ * for {@link Ext.ux.grid.menu.ListMenu}.</p>
+ *
  * <p><b><u>Example Usage:</u></b></p>
- * <pre><code>    
-var filters = new Ext.ux.grid.GridFilters({
+ * <pre><code>
+var filters = Ext.create('Ext.ux.grid.GridFilters', {
     ...
     filters: [{
         type: 'list',
@@ -26,9 +20,11 @@ var filters = new Ext.ux.grid.GridFilters({
     }]
 });
  * </code></pre>
- * 
+ *
  */
-Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
+Ext.define('Ext.ux.grid.filter.ListFilter', {
+    extend: 'Ext.ux.grid.filter.Filter',
+    alias: 'gridfilter.list',
 
     /**
      * @cfg {Array} options
@@ -42,7 +38,7 @@ Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
      * <li><b>Array</b> :
      * <pre><code>
 options: [
-    [11, 'extra small'], 
+    [11, 'extra small'],
     [18, 'small'],
     [22, 'medium'],
     [35, 'large'],
@@ -54,11 +50,11 @@ options: [
      * <pre><code>
 labelField: 'name', // override default of 'text'
 options: [
-    {id: 11, name:'extra small'}, 
-    {id: 18, name:'small'}, 
-    {id: 22, name:'medium'}, 
-    {id: 35, name:'large'}, 
-    {id: 44, name:'extra large'} 
+    {id: 11, name:'extra small'},
+    {id: 18, name:'small'},
+    {id: 22, name:'medium'},
+    {id: 35, name:'large'},
+    {id: 44, name:'extra large'}
 ]
      * </code></pre>
      * </li>
@@ -77,12 +73,12 @@ options: [
 filter[0][data][type] list
 filter[0][data][value] value1
 filter[0][data][value] value2
-filter[0][field] prod 
+filter[0][field] prod
 
 // phpMode == true:
 filter[0][data][type] list
 filter[0][data][value] value1, value2
-filter[0][field] prod 
+filter[0][field] prod
      * </code></pre>
      * When GridFilters <code>@cfg encode = true</code>:
      * <pre><code>
@@ -101,22 +97,27 @@ filter : [{"type":"list","value":"small,medium","field":"size"}]
      * is local, use the <code>{@link #options}</code> config instead.
      */
 
-    /**  
+    /**
      * @private
-     * Template method that is to initialize the filter and install required menu items.
+     * Template method that is to initialize the filter.
      * @param {Object} config
      */
     init : function (config) {
-        this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);
+        this.dt = Ext.create('Ext.util.DelayedTask', this.fireUpdate, this);
+    },
 
-        // if a menu already existed, do clean up first
-        if (this.menu){
-            this.menu.destroy();
-        }
-        this.menu = new Ext.ux.menu.ListMenu(config);
-        this.menu.on('checkchange', this.onCheckChange, this);
+    /**
+     * @private @override
+     * Creates the Menu for this filter.
+     * @param {Object} config Filter configuration
+     * @return {Ext.menu.Menu}
+     */
+    createMenu: function(config) {
+        var menu = Ext.create('Ext.ux.grid.menu.ListMenu', config);
+        menu.on('checkchange', this.onCheckChange, this);
+        return menu;
     },
-    
+
     /**
      * @private
      * Template method that is to get and return the value of the filter.
@@ -129,7 +130,7 @@ filter : [{"type":"list","value":"small,medium","field":"size"}]
      * @private
      * Template method that is to set the value of the filter.
      * @param {Object} value The value to set the filter
-     */        
+     */
     setValue : function (value) {
         this.menu.setSelected(value);
         this.fireEvent('update', this);
@@ -144,7 +145,7 @@ filter : [{"type":"list","value":"small,medium","field":"size"}]
     isActivatable : function () {
         return this.getValue().length > 0;
     },
-    
+
     /**
      * @private
      * Template method that is to get and return serialized filter data for
@@ -153,16 +154,15 @@ filter : [{"type":"list","value":"small,medium","field":"size"}]
      * key value pairs representing the current configuration of the filter.
      */
     getSerialArgs : function () {
-        var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
-        return args;
+        return {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
     },
 
     /** @private */
     onCheckChange : function(){
         this.dt.delay(this.updateBuffer);
     },
-    
-    
+
+
     /**
      * Template method that is to validate the provided Ext.data.Record
      * against the filters configuration.
@@ -171,6 +171,7 @@ filter : [{"type":"list","value":"small,medium","field":"size"}]
      * of the filter, false otherwise.
      */
     validateRecord : function (record) {
-        return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
+        var valuesArray = this.getValue();
+        return Ext.Array.indexOf(valuesArray, record.get(this.dataIndex)) > -1;
     }
-});
\ No newline at end of file
+});