source: trunk/web/addons/job_monarch/lib/extjs/examples/grid-filtering/grid/filter/DateFilter.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: 4.4 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.grid.filter.DateFilter = Ext.extend(Ext.grid.filter.Filter, {
10    /**
11     * @cfg {Date} dateFormat
12     * The date format applied to the menu's {@link Ext.menu.DateMenu}
13     */
14        dateFormat: 'm/d/Y',
15    /**
16     * @cfg {Object} pickerOpts
17     * The config object that will be passed to the menu's {@link Ext.menu.DateMenu} during
18     * initialization (sets minDate, maxDate and format to the same configs specified on the filter)
19     */
20        pickerOpts: {},
21    /**
22     * @cfg {String} beforeText
23     * The text displayed for the "Before" menu item
24     */
25    beforeText: 'Before',
26    /**
27     * @cfg {String} afterText
28     * The text displayed for the "After" menu item
29     */
30    afterText: 'After',
31    /**
32     * @cfg {String} onText
33     * The text displayed for the "On" menu item
34     */
35    onText: 'On',
36    /**
37     * @cfg {Date} minDate
38     * The minimum date allowed in the menu's {@link Ext.menu.DateMenu}
39     */
40    /**
41     * @cfg {Date} maxDate
42     * The maximum date allowed in the menu's {@link Ext.menu.DateMenu}
43     */
44       
45        init: function() {
46                var opts = Ext.apply(this.pickerOpts, {
47                        minDate: this.minDate, 
48                        maxDate: this.maxDate, 
49                        format:  this.dateFormat
50                });
51                var dates = this.dates = {
52                        'before': new Ext.menu.CheckItem({text: this.beforeText, menu: new Ext.menu.DateMenu(opts)}),
53                        'after':  new Ext.menu.CheckItem({text: this.afterText, menu: new Ext.menu.DateMenu(opts)}),
54                        'on':     new Ext.menu.CheckItem({text: this.onText, menu: new Ext.menu.DateMenu(opts)})
55    };
56                               
57                this.menu.add(dates.before, dates.after, "-", dates.on);
58               
59                for(var key in dates) {
60                        var date = dates[key];
61                        date.menu.on('select', this.onSelect.createDelegate(this, [date]), this);
62 
63      date.on('checkchange', function(){
64        this.setActive(this.isActivatable());
65                        }, this);
66                };
67        },
68 
69        onSelect: function(date, menuItem, value, picker) {
70    date.setChecked(true);
71    var dates = this.dates;
72   
73    if(date == dates.on) {
74      dates.before.setChecked(false, true);
75      dates.after.setChecked(false, true);
76    } else {
77      dates.on.setChecked(false, true);
78     
79      if(date == dates.after && dates.before.menu.picker.value < value) {
80        dates.before.setChecked(false, true);
81      } else if (date == dates.before && dates.after.menu.picker.value > value) {
82        dates.after.setChecked(false, true);
83      }
84    }
85   
86    this.fireEvent("update", this);
87  },
88 
89        getFieldValue: function(field) {
90                return this.dates[field].menu.picker.getValue();
91        },
92       
93        getPicker: function(field) {
94                return this.dates[field].menu.picker;
95        },
96       
97        isActivatable: function() {
98                return this.dates.on.checked || this.dates.after.checked || this.dates.before.checked;
99        },
100       
101        setValue: function(value) {
102                for(var key in this.dates) {
103                        if(value[key]) {
104                                this.dates[key].menu.picker.setValue(value[key]);
105                                this.dates[key].setChecked(true);
106                        } else {
107                                this.dates[key].setChecked(false);
108                        }
109    }
110        },
111       
112        getValue: function() {
113                var result = {};
114                for(var key in this.dates) {
115                        if(this.dates[key].checked) {
116                                result[key] = this.dates[key].menu.picker.getValue();
117      }
118    }   
119                return result;
120        },
121       
122        serialize: function() {
123                var args = [];
124                if(this.dates.before.checked) {
125                        args = [{type: 'date', comparison: 'lt', value: this.getFieldValue('before').format(this.dateFormat)}];
126    }
127                if(this.dates.after.checked) {
128                        args.push({type: 'date', comparison: 'gt', value: this.getFieldValue('after').format(this.dateFormat)});
129    }
130                if(this.dates.on.checked) {
131                        args = {type: 'date', comparison: 'eq', value: this.getFieldValue('on').format(this.dateFormat)};
132    }
133
134    this.fireEvent('serialize', args, this);
135                return args;
136        },
137       
138        validateRecord: function(record) {
139                var val = record.get(this.dataIndex).clearTime(true).getTime();
140               
141                if(this.dates.on.checked && val != this.getFieldValue('on').clearTime(true).getTime()) {
142                        return false;
143    }
144                if(this.dates.before.checked && val >= this.getFieldValue('before').clearTime(true).getTime()) {
145                        return false;
146    }
147                if(this.dates.after.checked && val <= this.getFieldValue('after').clearTime(true).getTime()) {
148                        return false;
149    }
150                return true;
151        }
152});
Note: See TracBrowser for help on using the repository browser.