Project

General

Profile

Download (5.04 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / flarecast / workspace / client-public-3.0 / js / widget / sitoolsFilter / DateFilter.js @ master

1
/*******************************************************************************
2
 * Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
/*global Ext, i18n, loadUrl, getDesktop, sitools, SitoolsDesk */
20
Ext.namespace("sitools.public.widget.sitoolsFilter");
21

    
22
Ext.define('sitools.public.widget.sitoolsFilter.DateFilter', {
23
    extend : 'sitools.public.widget.sitoolsFilter.Filter',
24
    alias : 'sitools.widget.DateFilter',
25
        
26
    /**
27
     * @cfg {String} iconCls
28
     * The iconCls to be applied to the menu item.
29
     * @cfg {String} format
30
     * The date format to use
31
     * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
32
     */
33
    iconCls : 'ux-gridfilter-text-icon',
34

    
35
    emptyText: 'Enter Filter Text...',
36
    selectOnFocus: true,
37
    
38
    /**  
39
     * @private
40
     * Template method that is to initialize the filter and install required menu items.
41
     */
42
    init : function (config) {
43
        config = config || {};
44
        this.dateFormat = Ext.isEmpty(config.format)?SITOOLS_DEFAULT_IHM_DATE_FORMAT:config.format; 
45
        this.inputFrom = Ext.create("Ext.form.DateField", {
46
                anchor : "100%", 
47
                format : this.dateFormat
48
        }); 
49
        this.inputTo = Ext.create("Ext.form.DateField", {
50
                anchor : "100%", 
51
                format : this.dateFormat
52
        });
53
        
54
        var imageFrom = Ext.create('Ext.Img', {
55
            src : '/sitools/client-public/res/images/sitoolsFilter/greater_than_or_equals.png',
56
            width : 16,
57
            height : 16,
58
            margin : '4 5 4 5'
59
        });
60
        
61
        var imageTo = Ext.create('Ext.Img', {
62
            src : '/sitools/client-public/res/images/sitoolsFilter/less_than_or_equals.png',
63
            width : 16,
64
            height : 16,
65
            margin : '4 5 4 5'
66
        });
67
        
68
        var formPanelFrom = Ext.create("Ext.form.FieldContainer", {
69
            layout : {
70
                type :'hbox',
71
                align :'stretch'                
72
            },
73
            items : [imageFrom, this.inputFrom], 
74
            bodyBorder : false, 
75
            border : false
76
        });
77
        
78
        var formPanelTo = Ext.create("Ext.form.FieldContainer", {
79
            layout : {
80
                type :'hbox',
81
                align :'stretch'                
82
            },
83
            items : [imageTo, this.inputTo], 
84
            bodyBorder : false, 
85
            border : false
86
        });
87
        
88
        
89
        var formPanel = Ext.create("Ext.Container", {
90
            layout : {
91
                type :'vbox',
92
                align :'stretch'                
93
            },
94
                items : [formPanelFrom, formPanelTo], 
95
                bodyBorder : false, 
96
                border : false
97
        });
98
        
99
        
100
        this.add(formPanel);
101
    },
102
    
103
    /**
104
     * @private
105
     * Template method that is to get and return the value of the filter.
106
     * @return {String} The value of this filter
107
     */
108
    getValue : function () {
109
        var result = [];
110
        if (!Ext.isEmpty(this.inputFrom.getValue())) {
111
                result.push({
112
                        "columnAlias" : this.columnAlias, 
113
                        "data" : {
114
                                "comparison" : "gte", 
115
                                "value" : Ext.Date.format(this.inputFrom.getValue(),SITOOLS_DATE_FORMAT), 
116
                                "type" : "date"
117
                        }
118
                });
119
        }
120
        if (!Ext.isEmpty(this.inputTo.getValue())) {
121
                result.push({
122
                        "columnAlias" : this.columnAlias, 
123
                        "data" : {
124
                                "comparison" : "lte", 
125
                                "value" : Ext.Date.format(this.inputTo.getValue(),SITOOLS_DATE_FORMAT), 
126
                                "type" : "date"
127
                        }
128
                });
129
        }
130
        return result;
131
    },
132
    
133
    getConfig : function () {
134
            if (!Ext.isEmpty(this.inputFrom.getValue()) || !Ext.isEmpty(this.inputTo.getValue())) {
135
                         return {
136
                            "columnAlias" : this.columnAlias, 
137
                            "value" : {
138
                                    "from" : this.inputFrom.getValue(), 
139
                                    "to" : this.inputTo.getValue() 
140
                            }, 
141
                            "type" : "date"
142
                    };
143
            }
144
            else {
145
                    return null;
146
            }
147
            
148
    }, 
149
    /**
150
     * @private
151
     * Template method that is to set the value of the filter.
152
     * @param {Object} value The value to set the filter
153
     */        
154
    setValue : function (value) {
155
        this.inputFrom.setValue(value.from);
156
        this.inputTo.setValue(value.to);
157
        
158
    } , 
159
    _getHeight : function () {
160
            return this.height;
161
    }
162
});