Project

General

Profile

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

git_sitools_idoc / flarecast / workspace / client-public-3.0 / js / widget / sitoolsFilter / StringFilter.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.StringFilter', {
23
    extend : 'sitools.public.widget.sitoolsFilter.Filter',
24
        
25
    /**
26
     * @cfg {String} iconCls
27
     * The iconCls to be applied to the menu item.
28
     * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
29
     */
30
    iconCls : 'ux-gridfilter-text-icon',
31

    
32
    emptyText: 'Enter Filter Text...',
33
    selectOnFocus: true,
34
    
35
    /**  
36
     * @private
37
     * Template method that is to initialize the filter and install required menu items.
38
     */
39
    init : function (config) {
40
        config = config || {};
41
        
42
        this.inputItem = Ext.create("Ext.form.TextField", {
43
                anchor : "100%"
44
        }); 
45
        
46
        var image = Ext.create('Ext.Img', {
47
            src : '/sitools/client-public/res/images/sitoolsFilter/find.png',
48
            width : 16,
49
            height : 16,
50
            margin : '4 5 4 5'
51
        });
52
        
53
        var formPanel = Ext.create("Ext.Container", {
54
            layout : {
55
                type :'hbox',
56
                align :'stretch'                
57
            },
58
                items : [image, this.inputItem], 
59
                bodyBorder : false, 
60
                border : false
61
        });
62
        
63
        
64
        
65
        this.add(formPanel);
66
    },
67
    
68
    /**
69
     * @private
70
     * Template method that is to get and return the value of the filter.
71
     * @return {String} The value of this filter
72
     */
73
    getValue : function () {
74
        if (!Ext.isEmpty(this.inputItem.getValue())) {
75
                return [{
76
                        "columnAlias" : this.columnAlias, 
77
                        "data" : {
78
                                "comparison" : "LIKE", 
79
                                "value" : this.inputItem.getValue(), 
80
                                "type" : "string"
81
                        }
82
                }];
83
        }
84
        else {
85
                return [];
86
        }
87
    },
88
    
89
    /**
90
     * @private
91
     * Template method that is to get and return the value of the filter.
92
     * @return {String} The value of this filter
93
     */
94
    getConfig : function () {
95
             if (!Ext.isEmpty(this.inputItem.getValue())) {
96
                         return {
97
                            "columnAlias" : this.columnAlias, 
98
                            "value" : this.inputItem.getValue(), 
99
                            "type" : "string"
100
                    };
101
            }
102
            else {
103
                    return null;
104
            }       
105
    },
106
    /**
107
     * @private
108
     * Template method that is to set the value of the filter.
109
     * @param {Object} value The value to set the filter
110
     */        
111
    setValue : function (value) {
112
        this.inputItem.setValue(value);
113
    },
114

    
115
    /**
116
     * Template method that is to validate the provided Ext.data.Record
117
     * against the filters configuration.
118
     * @param {Ext.data.Record} record The record to validate
119
     * @return {Boolean} true if the record is valid within the bounds
120
     * of the filter, false otherwise.
121
     */
122
    validateRecord : function (record) {
123
        var val = record.get(this.dataIndex);
124

    
125
        if(typeof val != 'string') {
126
            return (this.getValue().length === 0);
127
        }
128

    
129
        return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
130
    }, 
131
    _getHeight : function () {
132
            return this.height;
133
    }
134
    
135
});