source: trunk/web/addons/job_monarch/lib/extjs/examples/grid-filtering/menu/RangeMenu.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 2.2 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9Ext.menu.RangeMenu = function(config){
10        Ext.menu.RangeMenu.superclass.constructor.call(this, config);
11 
12        this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
13
14        var cfg = this.fieldCfg;
15        var cls = this.fieldCls;
16        var fields = this.fields = Ext.applyIf(this.fields || {}, {
17                'gt': new Ext.menu.EditableItem({
18                        icon:  this.icons.gt,
19                        editor: new cls(typeof cfg == "object" ? cfg.gt || '' : cfg)
20    }),
21                'lt': new Ext.menu.EditableItem({
22                        icon:  this.icons.lt,
23                        editor: new cls(typeof cfg == "object" ? cfg.lt || '' : cfg)
24    }),
25                'eq': new Ext.menu.EditableItem({
26                        icon:   this.icons.eq, 
27                        editor: new cls(typeof cfg == "object" ? cfg.gt || '' : cfg)
28    })
29        });
30        this.add(fields.gt, fields.lt, '-', fields.eq);
31       
32        for(var key in fields) {
33                fields[key].on('keyup', this.onKeyUp.createDelegate(this, [fields[key]], true), this);
34  }
35 
36        this.addEvents('update');
37};
38
39Ext.extend(Ext.menu.RangeMenu, Ext.menu.Menu, {
40        fieldCls:     Ext.form.NumberField,
41        fieldCfg:     '',
42        updateBuffer: 500,
43        icons: {
44                gt: '/img/small_icons/greater_then.png', 
45                lt: '/img/small_icons/less_then.png',
46                eq: '/img/small_icons/equals.png'
47  },
48               
49        fireUpdate: function() {
50                this.fireEvent("update", this);
51        },
52       
53        setValue: function(data) {
54                for(var key in this.fields) {
55                        this.fields[key].setValue(data[key] !== undefined ? data[key] : '');
56    }
57                this.fireEvent("update", this);
58        },
59       
60        getValue: function() {
61                var result = {};
62                for(var key in this.fields) {
63                        var field = this.fields[key];
64                        if(field.isValid() && String(field.getValue()).length > 0) { 
65                                result[key] = field.getValue();
66      }
67                }
68               
69                return result;
70        },
71 
72  onKeyUp: function(event, input, notSure, field) {
73    if(event.getKey() == event.ENTER && field.isValid()) {
74            this.hide(true);
75            return;
76          }
77       
78          if(field == this.fields.eq) {
79            this.fields.gt.setValue(null);
80            this.fields.lt.setValue(null);
81          } else {
82            this.fields.eq.setValue(null);
83          }
84         
85          this.updateTask.delay(this.updateBuffer);
86  }
87});
Note: See TracBrowser for help on using the repository browser.