git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / NumberBetween.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*/
|
20 |
/*
|
21 |
* @include "../AbstractComponentsWithUnit.js"
|
22 |
* @include "../ComponentFactory.js"
|
23 |
*/
|
24 |
Ext.ns('sitools.common.forms.components');
|
25 |
/**
|
26 |
* A number between form component.
|
27 |
* @cfg {string} parameterId Id of the future component.
|
28 |
* @cfg {Array} code Array of string representing columns alias attached to this component
|
29 |
* @cfg {string} type Defines wich unique type of component it is.
|
30 |
* @cfg {string} label The label of the form component.
|
31 |
* @cfg {numeric} height height of the future component.
|
32 |
* @cfg {numeric} widthBox width of the future component.
|
33 |
* @cfg {string} valueSelection "S" for specific Selection, "D" for data selection.
|
34 |
* @cfg {string} dataUrl the url to request the data in case of valueSelection == "D".
|
35 |
* @cfg {boolean} autoComplete for TEXTFIELD, autoComplete configuration of future Ext.form.Textfield.
|
36 |
* @cfg {string} formId The form id that contains this component.
|
37 |
* @cfg {string} dimensionId The sitools units dimension id.
|
38 |
* @cfg {string} css An optional css to add to this component.
|
39 |
* @cfg {Array} defaultValues Array of default values.
|
40 |
* @cfg {} datasetCm the dataset ColumnModel object
|
41 |
* @requires sitools.common.forms.ComponentFactory
|
42 |
* @class sitools.common.forms.components.NumericBetween
|
43 |
* @extends sitools.common.forms.AbstractWithUnit
|
44 |
*/
|
45 |
sitools.common.forms.components.NumericBetween = Ext.extend(sitools.common.forms.AbstractWithUnit, { |
46 |
//sitools.component.users.SubSelectionParameters.SingleSelection.NumericBetween = Ext.extend(sitools.common.forms.AbstractWithUnit, {
|
47 |
/**
|
48 |
* The left bound of the period.
|
49 |
*/
|
50 |
fieldFrom : null, |
51 |
|
52 |
/**
|
53 |
* The right bound of the period.
|
54 |
*/
|
55 |
fieldTo : null, |
56 |
|
57 |
initComponent : function () { |
58 |
this.context = new sitools.common.forms.ComponentFactory(this.context); |
59 |
//formattage de extraParams :
|
60 |
var extraParams = {};
|
61 |
Ext.each(this.extraParams, function (param) { |
62 |
extraParams[param.name]= param.value; |
63 |
}, this);
|
64 |
|
65 |
this.extraParams = extraParams;
|
66 |
|
67 |
var unit = this.getUnitComponent(); |
68 |
|
69 |
this.fieldFrom = new Ext.form.NumberField({ |
70 |
allowBlank : true, |
71 |
flex : 1, |
72 |
//height : this.height,
|
73 |
|
74 |
validator : function (value) { |
75 |
if (Ext.isEmpty(this.ownerCt.fieldTo.getValue())) { |
76 |
return true; |
77 |
} |
78 |
if (value > this.ownerCt.fieldTo.getValue()) { |
79 |
return "invalid Value"; |
80 |
} else {
|
81 |
return true; |
82 |
} |
83 |
}, |
84 |
decimalPrecision : 20 |
85 |
}); |
86 |
|
87 |
// *** Default min value is provided as hint, with 'emptyText' style ***
|
88 |
if(this.defaultValues[0]){ |
89 |
this.fieldFrom.emptyText="min: "+String(this.defaultValues[0]); |
90 |
} |
91 |
// ****** //
|
92 |
|
93 |
this.fieldTo = new Ext.form.NumberField({ |
94 |
allowBlank : true, |
95 |
flex : 1, |
96 |
//height : this.height,
|
97 |
|
98 |
validator : function (value) { |
99 |
if (value < this.ownerCt.fieldFrom.getValue()) { |
100 |
return "invalid Value"; |
101 |
} else {
|
102 |
return true; |
103 |
} |
104 |
}, |
105 |
decimalPrecision : 20 |
106 |
}); |
107 |
|
108 |
// *** Default max value is provided as hint, with 'emptyText' style ***
|
109 |
if(this.defaultValues[1]){ |
110 |
this.fieldTo.emptyText="max: "+String(this.defaultValues[1]); |
111 |
} |
112 |
// ****** //
|
113 |
|
114 |
var items = [this.fieldFrom, { |
115 |
html : " ", |
116 |
width : "10" |
117 |
}, this.fieldTo];
|
118 |
|
119 |
if (!Ext.isEmpty(unit)) {
|
120 |
items.push(unit); |
121 |
} |
122 |
|
123 |
Ext.apply(this, {
|
124 |
layout : 'hbox', |
125 |
stype : "sitoolsFormContainer", |
126 |
overCls : 'fieldset-child', |
127 |
defaults : {
|
128 |
xtype : 'container', |
129 |
autoEl : 'div' |
130 |
}, |
131 |
items : items
|
132 |
}); |
133 |
sitools.common.forms.components.NumericBetween.superclass.initComponent.apply( |
134 |
this, arguments); |
135 |
if (!Ext.isEmpty(this.label)) { |
136 |
var labels = this.label.split("|") || []; |
137 |
switch (labels.length) {
|
138 |
case 0 : |
139 |
break;
|
140 |
case 1 : |
141 |
this.items.insert(0, new Ext.Container({ |
142 |
border : false, |
143 |
html : labels[0], |
144 |
width : 100 |
145 |
})); |
146 |
break;
|
147 |
case 2 : |
148 |
this.items.insert(0, new Ext.Container({ |
149 |
border : false, |
150 |
html : labels[0], |
151 |
width : 50 |
152 |
})); |
153 |
this.items.insert(2, new Ext.Container({ |
154 |
border : false, |
155 |
html : labels[1], |
156 |
width : 50, |
157 |
style : {
|
158 |
"padding-left" : "10px" |
159 |
} |
160 |
})); |
161 |
break;
|
162 |
case 3 : |
163 |
this.items.insert(0, new Ext.Container({ |
164 |
border : false, |
165 |
html : labels[0], |
166 |
width : 50 |
167 |
})); |
168 |
this.items.insert(1, new Ext.Container({ |
169 |
border : false, |
170 |
html : labels[1], |
171 |
width : 50, |
172 |
style : {
|
173 |
"padding-left" : "10px" |
174 |
} |
175 |
})); |
176 |
this.items.insert(3, new Ext.Container({ |
177 |
border : false, |
178 |
html : labels[2], |
179 |
width : 50, |
180 |
style : {
|
181 |
"padding-left" : "10px" |
182 |
} |
183 |
})); |
184 |
break;
|
185 |
} |
186 |
} |
187 |
}, |
188 |
|
189 |
/**
|
190 |
* Notify the parent of any change
|
191 |
* @method
|
192 |
*/
|
193 |
notifyValueSelected : function () { |
194 |
this.parent.notifyValueChanged(this.code); |
195 |
}, |
196 |
|
197 |
/**
|
198 |
* Return if both values are defined.
|
199 |
* @method
|
200 |
* @return {Boolean}
|
201 |
*/
|
202 |
isValueDefined : function () { |
203 |
if (this.fieldFrom.getValue() && this.fieldTo.getValue()) { |
204 |
return true; |
205 |
} else {
|
206 |
return false; |
207 |
} |
208 |
}, |
209 |
/**
|
210 |
* Get the selected Value
|
211 |
* @return {} the selected Value {
|
212 |
* from : from value,
|
213 |
* to : to value
|
214 |
* }
|
215 |
*/
|
216 |
getSelectedValue : function () { |
217 |
return {
|
218 |
from : this.fieldFrom.getValue(), |
219 |
to : this.fieldTo.getValue() |
220 |
}; |
221 |
}, |
222 |
|
223 |
/**
|
224 |
* Returns the value to request corresponding to the Filter API.
|
225 |
* @return {String} parameter filter value
|
226 |
*/
|
227 |
getParameterValue : function () { |
228 |
var value = this.getSelectedValue(); |
229 |
if (Ext.isEmpty(value) || Ext.isEmpty(value.from) || Ext.isEmpty(value.to)) {
|
230 |
return null; |
231 |
} |
232 |
// var result = this.type + "|" + this.code + "|" + value.from + "|" + value.to;
|
233 |
// if (!Ext.isEmpty(this.userDimension) && !Ext.isEmpty(this.userUnit)){
|
234 |
// result += "|" + this.userDimension + "|" + this.userUnit;
|
235 |
// }
|
236 |
return {
|
237 |
type : this.type, |
238 |
code : this.code, |
239 |
value : value.from + "|" + value.to, |
240 |
userDimension : this.userDimension, |
241 |
userUnit : this.userUnit |
242 |
}; |
243 |
|
244 |
}, |
245 |
|
246 |
// *** Reset function for RESET button ***//
|
247 |
resetToDefault : function () { |
248 |
this.fieldFrom.reset();
|
249 |
this.fieldTo.reset();
|
250 |
} |
251 |
// ***************************************//
|
252 |
|
253 |
}); |