2 * @class Ext.ux.grid.menu.RangeMenu
3 * @extends Ext.menu.Menu
4 * Custom implementation of {@link Ext.menu.Menu} that has preconfigured items for entering numeric
5 * range comparison values: less-than, greater-than, and equal-to. This is used internally
6 * by {@link Ext.ux.grid.filter.NumericFilter} to create its menu.
8 Ext.define('Ext.ux.grid.menu.RangeMenu', {
9 extend: 'Ext.menu.Menu',
12 * @cfg {String} fieldCls
13 * The Class to use to construct each field item within this menu
15 * fieldCls : Ext.form.field.Number
18 fieldCls : 'Ext.form.field.Number',
21 * @cfg {Object} fieldCfg
22 * The default configuration options for any field item unless superseded
23 * by the <code>{@link #fields}</code> configuration.
36 * @cfg {Object} fields
37 * The field items may be configured individually
38 * Defaults to <tt>undefined</tt>.
42 gt: { // override fieldCfg options
44 fieldCls: Ext.ux.form.CustomNumberField // to override default {@link #fieldCls}
51 * @cfg {Object} iconCls
52 * The iconCls to be applied to each comparator field item.
55 gt : 'ux-rangemenu-gt',
56 lt : 'ux-rangemenu-lt',
57 eq : 'ux-rangemenu-eq'
62 gt : 'ux-rangemenu-gt',
63 lt : 'ux-rangemenu-lt',
64 eq : 'ux-rangemenu-eq'
68 * @cfg {Object} fieldLabels
69 * Accessible label text for each comparator field item. Can be overridden by localization
70 * files. Defaults to:<pre>
84 * @cfg {Object} menuItemCfgs
85 * Default configuration options for each menu item
88 emptyText: 'Enter Filter Text...',
95 emptyText: 'Enter Number...',
101 * @cfg {Array} menuItems
102 * The items to be shown in this menu. Items are added to the menu
103 * according to their position within this array. Defaults to:<pre>
104 * menuItems : ['lt','gt','-','eq']
107 menuItems : ['lt', 'gt', '-', 'eq'],
110 constructor : function (config) {
112 fields, fieldCfg, i, len, item, cfg, Cls;
114 me.callParent(arguments);
116 fields = me.fields = me.fields || {};
117 fieldCfg = me.fieldCfg = me.fieldCfg || {};
122 * Fires when a filter configuration has changed
123 * @param {Ext.ux.grid.filter.Filter} this The filter object.
128 me.updateTask = Ext.create('Ext.util.DelayedTask', me.fireUpdate, me);
130 for (i = 0, len = me.menuItems.length; i < len; i++) {
131 item = me.menuItems[i];
135 itemId: 'range-' + item,
136 enableKeyEvents: true,
138 fieldLabel: me.iconTpl.apply({
139 cls: me.iconCls[item] || 'no-icon',
140 text: me.fieldLabels[item] || '',
141 src: Ext.BLANK_IMAGE_URL
147 change: me.onInputChange,
148 keyup: me.onInputKeyUp,
155 activate: Ext.emptyFn,
156 deactivate: Ext.emptyFn
161 Ext.applyIf(fields[item] || {}, fieldCfg[item]),
162 // configurable defaults
165 Cls = cfg.fieldCls || me.fieldCls;
166 item = fields[item] = Ext.create(Cls, cfg);
174 * called by this.updateTask
176 fireUpdate : function () {
177 this.fireEvent('update', this);
181 * Get and return the value of the filter.
182 * @return {String} The value of this filter
184 getValue : function () {
185 var result = {}, key, field;
186 for (key in this.fields) {
187 field = this.fields[key];
188 if (field.isValid() && field.getValue() !== null) {
189 result[key] = field.getValue();
196 * Set the value of this menu and fires the 'update' event.
197 * @param {Object} data The data to assign to this menu
199 setValue : function (data) {
201 for (key in this.fields) {
202 this.fields[key].setValue(key in data ? data[key] : '');
204 this.fireEvent('update', this);
209 * Handler method called when there is a keyup event on an input
212 onInputKeyUp: function(field, e) {
213 if (e.getKey() === e.RETURN && field.isValid()) {
221 * Handler method called when the user changes the value of one of the input
222 * items in this menu.
224 onInputChange: function(field) {
244 this.updateTask.delay(this.updateBuffer);
249 * @cfg {Ext.XTemplate} iconTpl
250 * A template for generating the label for each field in the menu
252 this.prototype.iconTpl = Ext.create('Ext.XTemplate',
253 '<img src="{src}" alt="{text}" class="' + Ext.baseCSSPrefix + 'menu-item-icon ux-rangemenu-icon {cls}" />'