Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / grid / feature / Feature.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.grid.feature.Feature
17  * @extends Ext.util.Observable
18  * 
19  * A feature is a type of plugin that is specific to the {@link Ext.grid.Panel}. It provides several
20  * hooks that allows the developer to inject additional functionality at certain points throughout the 
21  * grid creation cycle. This class provides the base template methods that are available to the developer,
22  * it should be extended.
23  * 
24  * There are several built in features that extend this class, for example:
25  *
26  *  - {@link Ext.grid.feature.Grouping} - Shows grid rows in groups as specified by the {@link Ext.data.Store}
27  *  - {@link Ext.grid.feature.RowBody} - Adds a body section for each grid row that can contain markup.
28  *  - {@link Ext.grid.feature.Summary} - Adds a summary row at the bottom of the grid with aggregate totals for a column.
29  * 
30  * ## Using Features
31  * A feature is added to the grid by specifying it an array of features in the configuration:
32  * 
33  *     var groupingFeature = Ext.create('Ext.grid.feature.Grouping');
34  *     Ext.create('Ext.grid.Panel', {
35  *         // other options
36  *         features: [groupingFeature]
37  *     });
38  * 
39  * @abstract
40  */
41 Ext.define('Ext.grid.feature.Feature', {
42     extend: 'Ext.util.Observable',
43     alias: 'feature.feature',
44     
45     isFeature: true,
46     disabled: false,
47     
48     /**
49      * @property {Boolean}
50      * Most features will expose additional events, some may not and will
51      * need to change this to false.
52      */
53     hasFeatureEvent: true,
54     
55     /**
56      * @property {String}
57      * Prefix to use when firing events on the view.
58      * For example a prefix of group would expose "groupclick", "groupcontextmenu", "groupdblclick".
59      */
60     eventPrefix: null,
61     
62     /**
63      * @property {String}
64      * Selector used to determine when to fire the event with the eventPrefix.
65      */
66     eventSelector: null,
67     
68     /**
69      * @property {Ext.view.Table}
70      * Reference to the TableView.
71      */
72     view: null,
73     
74     /**
75      * @property {Ext.grid.Panel}
76      * Reference to the grid panel
77      */
78     grid: null,
79     
80     /**
81      * Most features will not modify the data returned to the view.
82      * This is limited to one feature that manipulates the data per grid view.
83      */
84     collectData: false,
85         
86     getFeatureTpl: function() {
87         return '';
88     },
89     
90     /**
91      * Abstract method to be overriden when a feature should add additional
92      * arguments to its event signature. By default the event will fire:
93      * - view - The underlying Ext.view.Table
94      * - featureTarget - The matched element by the defined {@link #eventSelector}
95      *
96      * The method must also return the eventName as the first index of the array
97      * to be passed to fireEvent.
98      * @template
99      */
100     getFireEventArgs: function(eventName, view, featureTarget, e) {
101         return [eventName, view, featureTarget, e];
102     },
103     
104     /**
105      * Approriate place to attach events to the view, selectionmodel, headerCt, etc
106      * @template
107      */
108     attachEvents: function() {
109         
110     },
111     
112     getFragmentTpl: function() {
113         return;
114     },
115     
116     /**
117      * Allows a feature to mutate the metaRowTpl.
118      * The array received as a single argument can be manipulated to add things
119      * on the end/begining of a particular row.
120      * @template
121      */
122     mutateMetaRowTpl: function(metaRowTplArray) {
123         
124     },
125     
126     /**
127      * Allows a feature to inject member methods into the metaRowTpl. This is
128      * important for embedding functionality which will become part of the proper
129      * row tpl.
130      * @template
131      */
132     getMetaRowTplFragments: function() {
133         return {};
134     },
135
136     getTableFragments: function() {
137         return {};
138     },
139     
140     /**
141      * Provide additional data to the prepareData call within the grid view.
142      * @param {Object} data The data for this particular record.
143      * @param {Number} idx The row index for this record.
144      * @param {Ext.data.Model} record The record instance
145      * @param {Object} orig The original result from the prepareData call to massage.
146      * @template
147      */
148     getAdditionalData: function(data, idx, record, orig) {
149         return {};
150     },
151     
152     /**
153      * Enable a feature
154      */
155     enable: function() {
156         this.disabled = false;
157     },
158     
159     /**
160      * Disable a feature
161      */
162     disable: function() {
163         this.disabled = true;
164     }
165     
166 });