provide installation instructions
[extjs.git] / examples / grid-filtering / grid / filter / Filter.js
1 /*\r
2  * Ext JS Library 2.2.1\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 Ext.ns("Ext.grid.filter");\r
10 Ext.grid.filter.Filter = function(config){\r
11         Ext.apply(this, config);\r
12                 \r
13         this.events = {\r
14                 /**\r
15                  * @event activate\r
16                  * Fires when a inactive filter becomes active\r
17                  * @param {Ext.ux.grid.filter.Filter} this\r
18                  */\r
19                 'activate': true,\r
20                 /**\r
21                  * @event deactivate\r
22                  * Fires when a active filter becomes inactive\r
23                  * @param {Ext.ux.grid.filter.Filter} this\r
24                  */\r
25                 'deactivate': true,\r
26                 /**\r
27                  * @event update\r
28                  * Fires when a filter configuration has changed\r
29                  * @param {Ext.ux.grid.filter.Filter} this\r
30                  */\r
31                 'update': true,\r
32                 /**\r
33                  * @event serialize\r
34                  * Fires after the serialization process. Use this to apply additional parameters to the serialized data.\r
35                  * @param {Array/Object} data A map or collection of maps representing the current filter configuration.\r
36                  * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.\r
37                  **/\r
38                 'serialize': true\r
39         };\r
40         Ext.grid.filter.Filter.superclass.constructor.call(this);\r
41         \r
42         this.menu = new Ext.menu.Menu();\r
43         this.init();\r
44         \r
45         if(config && config.value) {\r
46                 this.setValue(config.value);\r
47                 this.setActive(config.active !== false, true);\r
48                 delete config.value;\r
49         }\r
50 };\r
51 Ext.extend(Ext.grid.filter.Filter, Ext.util.Observable, {\r
52         /**\r
53          * @cfg {Boolean} active\r
54          * Indicates the default status of the filter (defaults to false).\r
55          */\r
56     /**\r
57      * True if this filter is active. Read-only.\r
58      * @type Boolean\r
59      * @property\r
60      */\r
61         active: false,\r
62         /**\r
63          * @cfg {String} dataIndex \r
64          * The {@link Ext.data.Store} data index of the field this filter represents. The dataIndex does not actually\r
65          * have to exist in the store.\r
66          */\r
67         dataIndex: null,\r
68         /**\r
69          * The filter configuration menu that will be installed into the filter submenu of a column menu.\r
70          * @type Ext.menu.Menu\r
71          * @property\r
72          */\r
73         menu: null,\r
74         \r
75         /**\r
76          * Initialize the filter and install required menu items.\r
77          */\r
78         init: Ext.emptyFn,\r
79         \r
80         fireUpdate: function() {\r
81                 this.value = this.item.getValue();\r
82                 \r
83                 if(this.active) {\r
84                         this.fireEvent("update", this);\r
85     }\r
86                 this.setActive(this.value.length > 0);\r
87         },\r
88         \r
89         /**\r
90          * Returns true if the filter has enough configuration information to be activated.\r
91          * @return {Boolean}\r
92          */\r
93         isActivatable: function() {\r
94                 return true;\r
95         },\r
96         \r
97         /**\r
98          * Sets the status of the filter and fires that appropriate events.\r
99          * @param {Boolean} active        The new filter state.\r
100          * @param {Boolean} suppressEvent True to prevent events from being fired.\r
101          */\r
102         setActive: function(active, suppressEvent) {\r
103                 if(this.active != active) {\r
104                         this.active = active;\r
105                         if(suppressEvent !== true) {\r
106                                 this.fireEvent(active ? 'activate' : 'deactivate', this);\r
107       }\r
108                 }\r
109         },\r
110         \r
111         /**\r
112          * Get the value of the filter\r
113          * @return {Object} The 'serialized' form of this filter\r
114          */\r
115         getValue: Ext.emptyFn,\r
116         \r
117         /**\r
118          * Set the value of the filter.\r
119          * @param {Object} data The value of the filter\r
120          */     \r
121         setValue: Ext.emptyFn,\r
122         \r
123         /**\r
124          * Serialize the filter data for transmission to the server.\r
125          * @return {Object/Array} An object or collection of objects containing key value pairs representing\r
126          *      the current configuration of the filter.\r
127          */\r
128         serialize: Ext.emptyFn,\r
129         \r
130         /**\r
131          * Validates the provided Ext.data.Record against the filters configuration.\r
132          * @param {Ext.data.Record} record The record to validate\r
133          * @return {Boolean} True if the record is valid with in the bounds of the filter, false otherwise.\r
134          */\r
135          validateRecord: function(){return true;}\r
136 });