Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / ux / gridfilters / filter / Filter.js
index 76c0665..532ba10 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
  */
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
-Ext.namespace('Ext.ux.grid.filter');\r
-\r
-/** \r
- * @class Ext.ux.grid.filter.Filter\r
- * @extends Ext.util.Observable\r
- * Abstract base class for filter implementations.\r
- */\r
-Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {\r
-    /**\r
-     * @cfg {Boolean} active\r
-     * Indicates the initial status of the filter (defaults to false).\r
-     */\r
-    active : false,\r
-    /**\r
-     * True if this filter is active.  Use setActive() to alter after configuration.\r
-     * @type Boolean\r
-     * @property active\r
-     */\r
-    /**\r
-     * @cfg {String} dataIndex \r
-     * The {@link Ext.data.Store} dataIndex of the field this filter represents.\r
-     * The dataIndex does not actually have to exist in the store.\r
-     */\r
-    dataIndex : null,\r
-    /**\r
-     * The filter configuration menu that will be installed into the filter submenu of a column menu.\r
-     * @type Ext.menu.Menu\r
-     * @property\r
-     */\r
-    menu : null,\r
-    /**\r
-     * @cfg {Number} updateBuffer\r
-     * Number of milliseconds to wait after user interaction to fire an update. Only supported \r
-     * by filters: 'list', 'numeric', and 'string'. Defaults to 500.\r
-     */\r
-    updateBuffer : 500,\r
-\r
-    constructor : function (config) {\r
-        Ext.apply(this, config);\r
-            \r
-        this.addEvents(\r
-            /**\r
-             * @event activate\r
-             * Fires when an inactive filter becomes active\r
-             * @param {Ext.ux.grid.filter.Filter} this\r
-             */\r
-            'activate',\r
-            /**\r
-             * @event deactivate\r
-             * Fires when an active filter becomes inactive\r
-             * @param {Ext.ux.grid.filter.Filter} this\r
-             */\r
-            'deactivate',\r
-            /**\r
-             * @event serialize\r
-             * Fires after the serialization process. Use this to attach additional parameters to serialization\r
-             * data before it is encoded and sent to the server.\r
-             * @param {Array/Object} data A map or collection of maps representing the current filter configuration.\r
-             * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.\r
-             */\r
-            'serialize',\r
-            /**\r
-             * @event update\r
-             * Fires when a filter configuration has changed\r
-             * @param {Ext.ux.grid.filter.Filter} this The filter object.\r
-             */\r
-            'update'\r
-        );\r
-        Ext.ux.grid.filter.Filter.superclass.constructor.call(this);\r
-\r
-        this.menu = new Ext.menu.Menu();\r
-        this.init(config);\r
-        if(config && config.value){\r
-            this.setValue(config.value);\r
-            this.setActive(config.active !== false, true);\r
-            delete config.value;\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Destroys this filter by purging any event listeners, and removing any menus.\r
-     */\r
-    destroy : function(){\r
-        if (this.menu){\r
-            this.menu.destroy();\r
-        }\r
-        this.purgeListeners();\r
-    },\r
-\r
-    /**\r
-     * Template method to be implemented by all subclasses that is to\r
-     * initialize the filter and install required menu items.\r
-     * Defaults to Ext.emptyFn.\r
-     */\r
-    init : Ext.emptyFn,\r
-    \r
-    /**\r
-     * Template method to be implemented by all subclasses that is to\r
-     * get and return the value of the filter.\r
-     * Defaults to Ext.emptyFn.\r
-     * @return {Object} The 'serialized' form of this filter\r
-     * @methodOf Ext.ux.grid.filter.Filter\r
-     */\r
-    getValue : Ext.emptyFn,\r
-    \r
-    /**\r
-     * Template method to be implemented by all subclasses that is to\r
-     * set the value of the filter and fire the 'update' event.\r
-     * Defaults to Ext.emptyFn.\r
-     * @param {Object} data The value to set the filter\r
-     * @methodOf Ext.ux.grid.filter.Filter\r
-     */        \r
-    setValue : Ext.emptyFn,\r
-    \r
-    /**\r
-     * Template method to be implemented by all subclasses that is to\r
-     * return <tt>true</tt> if the filter has enough configuration information to be activated.\r
-     * Defaults to <tt>return true</tt>.\r
-     * @return {Boolean}\r
-     */\r
-    isActivatable : function(){\r
-        return true;\r
-    },\r
-    \r
-    /**\r
-     * Template method to be implemented by all subclasses that is to\r
-     * get and return serialized filter data for transmission to the server.\r
-     * Defaults to Ext.emptyFn.\r
-     */\r
-    getSerialArgs : Ext.emptyFn,\r
-\r
-    /**\r
-     * Template method to be implemented by all subclasses that is to\r
-     * validates the provided Ext.data.Record against the filters configuration.\r
-     * Defaults to <tt>return true</tt>.\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(){\r
-        return true;\r
-    },\r
-\r
-    /**\r
-     * Returns the serialized filter data for transmission to the server\r
-     * and fires the 'serialize' event.\r
-     * @return {Object/Array} An object or collection of objects containing\r
-     * key value pairs representing the current configuration of the filter.\r
-     * @methodOf Ext.ux.grid.filter.Filter\r
-     */\r
-    serialize : function(){\r
-        var args = this.getSerialArgs();\r
-        this.fireEvent('serialize', args, this);\r
-        return args;\r
-    },\r
-\r
-    /** @private */\r
-    fireUpdate : function(){\r
-        if (this.active) {\r
-            this.fireEvent('update', this);\r
-        }\r
-        this.setActive(this.isActivatable());\r
-    },\r
-    \r
-    /**\r
-     * Sets the status of the filter and fires the appropriate events.\r
-     * @param {Boolean} active        The new filter state.\r
-     * @param {Boolean} suppressEvent True to prevent events from being fired.\r
-     * @methodOf Ext.ux.grid.filter.Filter\r
-     */\r
-    setActive : function(active, suppressEvent){\r
-        if(this.active != active){\r
-            this.active = active;\r
-            if (suppressEvent !== true) {\r
-                this.fireEvent(active ? 'activate' : 'deactivate', this);\r
-            }\r
-        }\r
-    }    \r
+Ext.namespace('Ext.ux.grid.filter');
+
+/** 
+ * @class Ext.ux.grid.filter.Filter
+ * @extends Ext.util.Observable
+ * Abstract base class for filter implementations.
+ */
+Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
+    /**
+     * @cfg {Boolean} active
+     * Indicates the initial status of the filter (defaults to false).
+     */
+    active : false,
+    /**
+     * True if this filter is active.  Use setActive() to alter after configuration.
+     * @type Boolean
+     * @property active
+     */
+    /**
+     * @cfg {String} dataIndex 
+     * The {@link Ext.data.Store} dataIndex of the field this filter represents.
+     * The dataIndex does not actually have to exist in the store.
+     */
+    dataIndex : null,
+    /**
+     * The filter configuration menu that will be installed into the filter submenu of a column menu.
+     * @type Ext.menu.Menu
+     * @property
+     */
+    menu : null,
+    /**
+     * @cfg {Number} updateBuffer
+     * Number of milliseconds to wait after user interaction to fire an update. Only supported 
+     * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
+     */
+    updateBuffer : 500,
+
+    constructor : function (config) {
+        Ext.apply(this, config);
+            
+        this.addEvents(
+            /**
+             * @event activate
+             * Fires when an inactive filter becomes active
+             * @param {Ext.ux.grid.filter.Filter} this
+             */
+            'activate',
+            /**
+             * @event deactivate
+             * Fires when an active filter becomes inactive
+             * @param {Ext.ux.grid.filter.Filter} this
+             */
+            'deactivate',
+            /**
+             * @event serialize
+             * Fires after the serialization process. Use this to attach additional parameters to serialization
+             * data before it is encoded and sent to the server.
+             * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
+             * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
+             */
+            'serialize',
+            /**
+             * @event update
+             * Fires when a filter configuration has changed
+             * @param {Ext.ux.grid.filter.Filter} this The filter object.
+             */
+            'update'
+        );
+        Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
+
+        this.menu = new Ext.menu.Menu();
+        this.init(config);
+        if(config && config.value){
+            this.setValue(config.value);
+            this.setActive(config.active !== false, true);
+            delete config.value;
+        }
+    },
+
+    /**
+     * Destroys this filter by purging any event listeners, and removing any menus.
+     */
+    destroy : function(){
+        if (this.menu){
+            this.menu.destroy();
+        }
+        this.purgeListeners();
+    },
+
+    /**
+     * Template method to be implemented by all subclasses that is to
+     * initialize the filter and install required menu items.
+     * Defaults to Ext.emptyFn.
+     */
+    init : Ext.emptyFn,
+    
+    /**
+     * Template method to be implemented by all subclasses that is to
+     * get and return the value of the filter.
+     * Defaults to Ext.emptyFn.
+     * @return {Object} The 'serialized' form of this filter
+     * @methodOf Ext.ux.grid.filter.Filter
+     */
+    getValue : Ext.emptyFn,
+    
+    /**
+     * Template method to be implemented by all subclasses that is to
+     * set the value of the filter and fire the 'update' event.
+     * Defaults to Ext.emptyFn.
+     * @param {Object} data The value to set the filter
+     * @methodOf Ext.ux.grid.filter.Filter
+     */        
+    setValue : Ext.emptyFn,
+    
+    /**
+     * Template method to be implemented by all subclasses that is to
+     * return <tt>true</tt> if the filter has enough configuration information to be activated.
+     * Defaults to <tt>return true</tt>.
+     * @return {Boolean}
+     */
+    isActivatable : function(){
+        return true;
+    },
+    
+    /**
+     * Template method to be implemented by all subclasses that is to
+     * get and return serialized filter data for transmission to the server.
+     * Defaults to Ext.emptyFn.
+     */
+    getSerialArgs : Ext.emptyFn,
+
+    /**
+     * Template method to be implemented by all subclasses that is to
+     * validates the provided Ext.data.Record against the filters configuration.
+     * Defaults to <tt>return true</tt>.
+     * @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(){
+        return true;
+    },
+
+    /**
+     * Returns the serialized filter data for transmission to the server
+     * and fires the 'serialize' event.
+     * @return {Object/Array} An object or collection of objects containing
+     * key value pairs representing the current configuration of the filter.
+     * @methodOf Ext.ux.grid.filter.Filter
+     */
+    serialize : function(){
+        var args = this.getSerialArgs();
+        this.fireEvent('serialize', args, this);
+        return args;
+    },
+
+    /** @private */
+    fireUpdate : function(){
+        if (this.active) {
+            this.fireEvent('update', this);
+        }
+        this.setActive(this.isActivatable());
+    },
+    
+    /**
+     * Sets the status of the filter and fires the appropriate events.
+     * @param {Boolean} active        The new filter state.
+     * @param {Boolean} suppressEvent True to prevent events from being fired.
+     * @methodOf Ext.ux.grid.filter.Filter
+     */
+    setActive : function(active, suppressEvent){
+        if(this.active != active){
+            this.active = active;
+            if (suppressEvent !== true) {
+                this.fireEvent(active ? 'activate' : 'deactivate', this);
+            }
+        }
+    }    
 });
\ No newline at end of file
 });
\ No newline at end of file