Project

General

Profile

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

git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / OneOrBetween.js @ 2830ca05

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, sitools, i18n*/
20
/*
21
 * @include "../AbstractComponentsWithUnit.js"
22
 * @include "../ComponentFactory.js"
23
 */
24
Ext.ns('sitools.common.forms.components');
25

    
26
/**
27
 * A number between form component. 
28
 * @cfg {string} parameterId Id of the future component.
29
 * @cfg {Array} code Array of string representing columns alias attached to this component
30
 * @cfg {string} type Defines wich unique type of component it is.
31
 * @cfg {string} label The label of the form component.
32
 * @cfg {numeric} height height of the future component.
33
 * @cfg {numeric} widthBox width of the future component.
34
 * @cfg {string} valueSelection "S" for specific Selection, "D" for data selection.
35
 * @cfg {string} dataUrl the url to request the data in case of valueSelection == "D".
36
 * @cfg {boolean} autoComplete for TEXTFIELD, autoComplete configuration of future Ext.form.Textfield.
37
 * @cfg {string} formId The form id that contains this component.
38
 * @cfg {string} dimensionId The sitools units dimension id.
39
 * @cfg {string} css An optional css to add to this component.
40
 * @cfg {Array} defaultValues Array of default values.
41
 * @cfg {} datasetCm the dataset ColumnModel object
42
 * @requires sitools.common.forms.ComponentFactory
43
 * @class sitools.common.forms.components.OneOrBetween
44
 * @extends sitools.common.forms.AbstractWithUnit
45
 */
46
sitools.common.forms.components.OneOrBetween = Ext.extend(sitools.common.forms.AbstractWithUnit, {
47
//sitools.component.users.SubSelectionParameters.SingleSelection.OneOrBetween = Ext.extend(sitools.common.forms.AbstractWithUnit, {
48
    /**
49
         * the first value.
50
         */
51
    fieldOne : null,
52

    
53
    /**
54
         * The left bound of the period.
55
         */
56
    fieldFrom : null,
57

    
58
    /**
59
         * The right bound of the period.
60
         */
61
    fieldTo : null,
62

    
63

    
64
    initComponent : function () {
65
        this.context = new sitools.common.forms.ComponentFactory(this.context);
66
        
67
        //formattage de extraParams : 
68
            var unit = this.getUnitComponent();
69
        
70
            this.fieldOne = new Ext.form.NumberField({
71
                allowBlank : true,
72
                //height : this.height,
73
                value : this.defaultValues[0],
74
                flex : 2,
75
                listeners :
76
            {
77
                scope : this,
78
                        change : function () {
79
                                this.fieldTo.setValue("");
80
                                this.fieldFrom.setValue("");
81
                        }
82
                }, 
83
                decimalPrecision : 20
84
            });
85
        
86
            this.fieldFrom = new Ext.form.NumberField({
87
                allowBlank : true,
88
                //height : this.height,
89
                flex : 2,
90
                validator : function (value) {
91
                        if (Ext.isEmpty(this.ownerCt.fieldTo.getValue())) {
92
                                return true;
93
                        }
94
                        if (value > this.ownerCt.fieldTo.getValue()) {
95
                                return "invalid Value";
96
                        } else {
97
                                return true;
98
                        }
99
                },
100
                listeners : {
101
                        change : function () {
102
                                this.ownerCt.fieldOne.setValue("");
103
                        }
104
                }, 
105
                decimalPrecision : 20
106
            });
107
            this.fieldTo = new Ext.form.NumberField({
108
                allowBlank : true,
109
                //height : this.height,
110
                flex : 2,
111
                validator : function (value) {
112
                        if (value < this.ownerCt.fieldFrom.getValue()) {
113
                                return "invalid Value";
114
                        } else {
115
                                return true;
116
                        }
117
                },
118
                listeners : {
119
                        change : function () {
120
                                this.ownerCt.fieldOne.setValue("");
121
                        }
122
                }, 
123
                decimalPrecision : 20
124
            });
125
            var items = [this.fieldOne, new Ext.Container({
126
            border : false,
127
            html : i18n.get('label.or'),
128
            width : 35
129
        }), new Ext.Container({
130
            border : false,
131
            html : i18n.get('label.min'),
132
            width : 35
133
        }), this.fieldFrom, new Ext.Container({
134
            border : false,
135
            html : i18n.get('label.max'),
136
            width : 35
137
        }), this.fieldTo];
138
        if (!Ext.isEmpty(unit)) {
139
                items.push(unit);
140
        }
141
            Ext.apply(this, {
142
                layout : 'hbox',
143
                columns : Ext.isEmpty(unit) ? 6 : 7,
144
                fieldLabel : this.label,
145
                overCls : 'fieldset-child',
146
                stype : "sitoolsFormContainer",
147

    
148
                items : items
149
            });
150
             sitools.common.forms.components.OneOrBetween.superclass.initComponent
151
                                .apply( this, arguments);
152
               if (!Ext.isEmpty(this.label)) {
153
                    this.items.insert(0, new Ext.Container({
154
                    border : false,
155
                    html : this.label,
156
                    width : 100
157
                }));
158
            }
159

    
160
    },
161

    
162
    /**
163
     * Notify the parent of any change
164
     * @method
165
     */
166
    notifyValueSelected : function () {
167
            this.parent.notifyValueChanged(this.code);
168
    },
169

    
170
    /**
171
     * Return if at least one value is defined.
172
     * @method
173
     * @return {Boolean} 
174
     */
175
    isValueDefined : function () {
176
            var value = this.getSelectedValue();
177
            return !(Ext.isEmpty(value) || (Ext.isEmpty(value.from) && Ext.isEmpty(value.to) && Ext.isEmpty(value.one)));
178
    },
179

    
180
    /**
181
     * Get the selected Value
182
     * @return {} the selected Value {
183
     *         one : one value, 
184
     *  from : from value, 
185
     *         to : to value
186
     * }
187
     */
188
    getSelectedValue : function () {
189
            return {
190
                one : this.fieldOne.getValue(),
191
                from : this.fieldFrom.getValue(),
192
                to : this.fieldTo.getValue()
193
            };
194
    },
195

    
196
    /**
197
     * Returns the value to request corresponding to the Filter API.
198
     * @return {String} parameter filter value
199
     */
200
    getParameterValue : function () {
201
            var value = this.getSelectedValue();
202
            if (!this.isValueDefined()) {
203
                    return null;
204
            }
205

    
206
            var result = this.type + "|" + this.code + "|" + value.one + "|" + value.from+ "|" + value.to;
207
            if (!Ext.isEmpty(this.userDimension) && !Ext.isEmpty(this.userUnit)){
208
                    result += "|" + this.userDimension + "|" + this.userUnit;
209
            }
210
                   return {
211
                    type : this.type, 
212
                    code : this.code, 
213
                    value : value.one + "|" + value.from + "|" + value.to, 
214
                    userDimension : this.userDimension, 
215
                    userUnit : this.userUnit
216
            };
217
    },
218

    
219
//  *** Reset function for RESET button ***//
220
    resetToDefault : function () {
221
        this.fieldOne.reset();
222
        this.fieldFrom.reset();
223
        this.fieldTo.reset();
224
    }
225
//  ***************************************//
226

    
227

    
228
});