Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / ux / gridfilters / filter / ListFilter.js
index b6f8e53..dbc4180 100644 (file)
 /*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
+ * Ext JS Library 3.2.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
-/** \r
- * @class Ext.ux.grid.filter.ListFilter\r
- * @extends Ext.ux.grid.filter.Filter\r
- * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load\r
- * their options the first time they are shown. ListFilter utilizes the\r
- * {@link Ext.ux.menu.ListMenu} component.</p>\r
- * <p>Although not shown here, this class accepts all configuration options\r
- * for {@link Ext.ux.menu.ListMenu}.</p>\r
- * \r
- * <p><b><u>Example Usage:</u></b></p>\r
- * <pre><code>    \r
-var filters = new Ext.ux.grid.GridFilters({\r
-    ...\r
-    filters: [{\r
-        type: 'list',\r
-        dataIndex: 'size',\r
-        phpMode: true,\r
-        // options will be used as data to implicitly creates an ArrayStore\r
-        options: ['extra small', 'small', 'medium', 'large', 'extra large']\r
-    }]\r
-});\r
- * </code></pre>\r
- * \r
- */\r
-Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {\r
-\r
-    /**\r
-     * @cfg {Array} options\r
-     * <p><code>data</code> to be used to implicitly create a data store\r
-     * to back this list when the data source is <b>local</b>. If the\r
-     * data for the list is remote, use the <code>{@link #store}</code>\r
-     * config instead.</p>\r
-     * <br><p>Each item within the provided array may be in one of the\r
-     * following formats:</p>\r
-     * <div class="mdetail-params"><ul>\r
-     * <li><b>Array</b> :\r
-     * <pre><code>\r
-options: [\r
-    [11, 'extra small'], \r
-    [18, 'small'],\r
-    [22, 'medium'],\r
-    [35, 'large'],\r
-    [44, 'extra large']\r
-]\r
-     * </code></pre>\r
-     * </li>\r
-     * <li><b>Object</b> :\r
-     * <pre><code>\r
-labelField: 'name', // override default of 'text'\r
-options: [\r
-    {id: 11, name:'extra small'}, \r
-    {id: 18, name:'small'}, \r
-    {id: 22, name:'medium'}, \r
-    {id: 35, name:'large'}, \r
-    {id: 44, name:'extra large'} \r
-]\r
-     * </code></pre>\r
-     * </li>\r
-     * <li><b>String</b> :\r
-     * <pre><code>\r
-     * options: ['extra small', 'small', 'medium', 'large', 'extra large']\r
-     * </code></pre>\r
-     * </li>\r
-     */\r
-    /**\r
-     * @cfg {Boolean} phpMode\r
-     * <p>Adjust the format of this filter. Defaults to false.</p>\r
-     * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>\r
-     * <pre><code>\r
-// phpMode == false (default):\r
-filter[0][data][type] list\r
-filter[0][data][value] value1\r
-filter[0][data][value] value2\r
-filter[0][field] prod \r
-\r
-// phpMode == true:\r
-filter[0][data][type] list\r
-filter[0][data][value] value1, value2\r
-filter[0][field] prod \r
-     * </code></pre>\r
-     * When GridFilters <code>@cfg encode = true</code>:\r
-     * <pre><code>\r
-// phpMode == false (default):\r
-filter : [{"type":"list","value":["small","medium"],"field":"size"}]\r
-\r
-// phpMode == true:\r
-filter : [{"type":"list","value":"small,medium","field":"size"}]\r
-     * </code></pre>\r
-     */\r
-    phpMode : false,\r
-    /**\r
-     * @cfg {Ext.data.Store} store\r
-     * The {@link Ext.data.Store} this list should use as its data source\r
-     * when the data source is <b>remote</b>. If the data for the list\r
-     * is local, use the <code>{@link #options}</code> config instead.\r
-     */\r
-\r
-    /**  \r
-     * @private\r
-     * Template method that is to initialize the filter and install required menu items.\r
-     * @param {Object} config\r
-     */\r
-    init : function (config) {\r
-        this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);\r
-\r
-        // if a menu already existed, do clean up first\r
-        if (this.menu){\r
-            this.menu.destroy();\r
-        }\r
-        this.menu = new Ext.ux.menu.ListMenu(config);\r
-        this.menu.on('checkchange', this.onCheckChange, this);\r
-    },\r
-    \r
-    /**\r
-     * @private\r
-     * Template method that is to get and return the value of the filter.\r
-     * @return {String} The value of this filter\r
-     */\r
-    getValue : function () {\r
-        return this.menu.getSelected();\r
-    },\r
-    /**\r
-     * @private\r
-     * Template method that is to set the value of the filter.\r
-     * @param {Object} value The value to set the filter\r
-     */        \r
-    setValue : function (value) {\r
-        this.menu.setSelected(value);\r
-        this.fireEvent('update', this);\r
-    },\r
-\r
-    /**\r
-     * @private\r
-     * Template method that is to return <tt>true</tt> if the filter\r
-     * has enough configuration information to be activated.\r
-     * @return {Boolean}\r
-     */\r
-    isActivatable : function () {\r
-        return this.getValue().length > 0;\r
-    },\r
-    \r
-    /**\r
-     * @private\r
-     * Template method that is to get and return serialized filter data for\r
-     * transmission to the server.\r
-     * @return {Object/Array} An object or collection of objects containing\r
-     * key value pairs representing the current configuration of the filter.\r
-     */\r
-    getSerialArgs : function () {\r
-        var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};\r
-        return args;\r
-    },\r
-\r
-    /** @private */\r
-    onCheckChange : function(){\r
-        this.dt.delay(this.updateBuffer);\r
-    },\r
-    \r
-    \r
-    /**\r
-     * Template method that is to validate the provided Ext.data.Record\r
-     * against the filters configuration.\r
-     * @param {Ext.data.Record} record The record to validate\r
-     * @return {Boolean} true if the record is valid within the bounds\r
-     * of the filter, false otherwise.\r
-     */\r
-    validateRecord : function (record) {\r
-        return this.getValue().indexOf(record.get(this.dataIndex)) > -1;\r
-    }\r
+/** 
+ * @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>
+ * <p>Although not shown here, this class accepts all configuration options
+ * for {@link Ext.ux.menu.ListMenu}.</p>
+ * 
+ * <p><b><u>Example Usage:</u></b></p>
+ * <pre><code>    
+var filters = new Ext.ux.grid.GridFilters({
+    ...
+    filters: [{
+        type: 'list',
+        dataIndex: 'size',
+        phpMode: true,
+        // options will be used as data to implicitly creates an ArrayStore
+        options: ['extra small', 'small', 'medium', 'large', 'extra large']
+    }]
+});
+ * </code></pre>
+ * 
+ */
+Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
+
+    /**
+     * @cfg {Array} options
+     * <p><code>data</code> to be used to implicitly create a data store
+     * to back this list when the data source is <b>local</b>. If the
+     * data for the list is remote, use the <code>{@link #store}</code>
+     * config instead.</p>
+     * <br><p>Each item within the provided array may be in one of the
+     * following formats:</p>
+     * <div class="mdetail-params"><ul>
+     * <li><b>Array</b> :
+     * <pre><code>
+options: [
+    [11, 'extra small'], 
+    [18, 'small'],
+    [22, 'medium'],
+    [35, 'large'],
+    [44, 'extra large']
+]
+     * </code></pre>
+     * </li>
+     * <li><b>Object</b> :
+     * <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'} 
+]
+     * </code></pre>
+     * </li>
+     * <li><b>String</b> :
+     * <pre><code>
+     * options: ['extra small', 'small', 'medium', 'large', 'extra large']
+     * </code></pre>
+     * </li>
+     */
+    /**
+     * @cfg {Boolean} phpMode
+     * <p>Adjust the format of this filter. Defaults to false.</p>
+     * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
+     * <pre><code>
+// phpMode == false (default):
+filter[0][data][type] list
+filter[0][data][value] value1
+filter[0][data][value] value2
+filter[0][field] prod 
+
+// phpMode == true:
+filter[0][data][type] list
+filter[0][data][value] value1, value2
+filter[0][field] prod 
+     * </code></pre>
+     * When GridFilters <code>@cfg encode = true</code>:
+     * <pre><code>
+// phpMode == false (default):
+filter : [{"type":"list","value":["small","medium"],"field":"size"}]
+
+// phpMode == true:
+filter : [{"type":"list","value":"small,medium","field":"size"}]
+     * </code></pre>
+     */
+    phpMode : false,
+    /**
+     * @cfg {Ext.data.Store} store
+     * The {@link Ext.data.Store} this list should use as its data source
+     * when the data source is <b>remote</b>. If the data for the list
+     * is local, use the <code>{@link #options}</code> config instead.
+     */
+
+    /**  
+     * @private
+     * Template method that is to initialize the filter and install required menu items.
+     * @param {Object} config
+     */
+    init : function (config) {
+        this.dt = new 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
+     * Template method that is to get and return the value of the filter.
+     * @return {String} The value of this filter
+     */
+    getValue : function () {
+        return this.menu.getSelected();
+    },
+    /**
+     * @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);
+    },
+
+    /**
+     * @private
+     * Template method that is to return <tt>true</tt> if the filter
+     * has enough configuration information to be activated.
+     * @return {Boolean}
+     */
+    isActivatable : function () {
+        return this.getValue().length > 0;
+    },
+    
+    /**
+     * @private
+     * Template method that is to get and return serialized filter data for
+     * transmission to the server.
+     * @return {Object/Array} An object or collection of objects containing
+     * 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;
+    },
+
+    /** @private */
+    onCheckChange : function(){
+        this.dt.delay(this.updateBuffer);
+    },
+    
+    
+    /**
+     * Template method that is to validate the provided Ext.data.Record
+     * against the filters configuration.
+     * @param {Ext.data.Record} record The record to validate
+     * @return {Boolean} true if the record is valid within the bounds
+     * of the filter, false otherwise.
+     */
+    validateRecord : function (record) {
+        return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
+    }
 });
\ No newline at end of file