Revision 220d02c7
Added by Alessandro_N over 9 years ago
szcluster-db/workspace/client-public/js/forms/components/NumberBetween.js | ||
---|---|---|
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 |
/** |
|
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.NumericBetween |
|
44 |
* @extends sitools.common.forms.AbstractWithUnit |
|
45 |
*/ |
|
46 |
sitools.common.forms.components.NumericBetween = Ext.extend(sitools.common.forms.AbstractWithUnit, { |
|
47 |
//sitools.component.users.SubSelectionParameters.SingleSelection.NumericBetween = Ext.extend(sitools.common.forms.AbstractWithUnit, { |
|
48 |
/** |
|
49 |
* The left bound of the period. |
|
50 |
*/ |
|
51 |
fieldFrom : null, |
|
52 |
|
|
53 |
/** |
|
54 |
* The right bound of the period. |
|
55 |
*/ |
|
56 |
fieldTo : null, |
|
57 |
|
|
58 |
initComponent : function () { |
|
59 |
this.context = new sitools.common.forms.ComponentFactory(this.context); |
|
60 |
//formattage de extraParams : |
|
61 |
var extraParams = {}; |
|
62 |
Ext.each(this.extraParams, function (param) { |
|
63 |
extraParams[param.name]= param.value; |
|
64 |
}, this); |
|
65 |
|
|
66 |
this.extraParams = extraParams; |
|
67 |
|
|
68 |
var unit = this.getUnitComponent(); |
|
69 |
|
|
70 |
this.fieldFrom = new Ext.form.NumberField({ |
|
71 |
allowBlank : true, |
|
72 |
flex : 1, |
|
73 |
//height : this.height, |
|
74 |
|
|
75 |
validator : function (value) { |
|
76 |
if (Ext.isEmpty(this.ownerCt.fieldTo.getValue())) { |
|
77 |
return true; |
|
78 |
} |
|
79 |
if (value > this.ownerCt.fieldTo.getValue()) { |
|
80 |
return "invalid Value"; |
|
81 |
} else { |
|
82 |
return true; |
|
83 |
} |
|
84 |
}, |
|
85 |
decimalPrecision : 20 |
|
86 |
}); |
|
87 |
|
|
88 |
// *** Default min value is provided as hint, with 'emptyText' style *** |
|
89 |
if(this.defaultValues[0]){ |
|
90 |
this.fieldFrom.emptyText="min: "+String(this.defaultValues[0]); |
|
91 |
} |
|
92 |
// ****** // |
|
93 |
|
|
94 |
this.fieldTo = new Ext.form.NumberField({ |
|
95 |
allowBlank : true, |
|
96 |
flex : 1, |
|
97 |
//height : this.height, |
|
98 |
|
|
99 |
validator : function (value) { |
|
100 |
if (value < this.ownerCt.fieldFrom.getValue()) { |
|
101 |
return "invalid Value"; |
|
102 |
} else { |
|
103 |
return true; |
|
104 |
} |
|
105 |
}, |
|
106 |
decimalPrecision : 20 |
|
107 |
}); |
|
108 |
|
|
109 |
// *** Default max value is provided as hint, with 'emptyText' style *** |
|
110 |
if(this.defaultValues[1]){ |
|
111 |
this.fieldTo.emptyText="max: "+String(this.defaultValues[1]); |
|
112 |
} |
|
113 |
// ****** // |
|
114 |
|
|
115 |
var items = [this.fieldFrom, { |
|
116 |
html : " ", |
|
117 |
width : "10" |
|
118 |
}, this.fieldTo]; |
|
119 |
|
|
120 |
if (!Ext.isEmpty(unit)) { |
|
121 |
items.push(unit); |
|
122 |
} |
|
123 |
|
|
124 |
Ext.apply(this, { |
|
125 |
layout : 'hbox', |
|
126 |
stype : "sitoolsFormContainer", |
|
127 |
overCls : 'fieldset-child', |
|
128 |
defaults : { |
|
129 |
xtype : 'container', |
|
130 |
autoEl : 'div' |
|
131 |
}, |
|
132 |
items : items |
|
133 |
}); |
|
134 |
sitools.common.forms.components.NumericBetween.superclass.initComponent.apply( |
|
135 |
this, arguments); |
|
136 |
if (!Ext.isEmpty(this.label)) { |
|
137 |
var labels = this.label.split("|") || []; |
|
138 |
switch (labels.length) { |
|
139 |
case 0 : |
|
140 |
break; |
|
141 |
case 1 : |
|
142 |
this.items.insert(0, new Ext.Container({ |
|
143 |
border : false, |
|
144 |
html : labels[0], |
|
145 |
width : 100 |
|
146 |
})); |
|
147 |
break; |
|
148 |
case 2 : |
|
149 |
this.items.insert(0, new Ext.Container({ |
|
150 |
border : false, |
|
151 |
html : labels[0], |
|
152 |
width : 50 |
|
153 |
})); |
|
154 |
this.items.insert(2, new Ext.Container({ |
|
155 |
border : false, |
|
156 |
html : labels[1], |
|
157 |
width : 50, |
|
158 |
style : { |
|
159 |
"padding-left" : "10px" |
|
160 |
} |
|
161 |
})); |
|
162 |
break; |
|
163 |
case 3 : |
|
164 |
this.items.insert(0, new Ext.Container({ |
|
165 |
border : false, |
|
166 |
html : labels[0], |
|
167 |
width : 50 |
|
168 |
})); |
|
169 |
this.items.insert(1, new Ext.Container({ |
|
170 |
border : false, |
|
171 |
html : labels[1], |
|
172 |
width : 50, |
|
173 |
style : { |
|
174 |
"padding-left" : "10px" |
|
175 |
} |
|
176 |
})); |
|
177 |
this.items.insert(3, new Ext.Container({ |
|
178 |
border : false, |
|
179 |
html : labels[2], |
|
180 |
width : 50, |
|
181 |
style : { |
|
182 |
"padding-left" : "10px" |
|
183 |
} |
|
184 |
})); |
|
185 |
break; |
|
186 |
} |
|
187 |
} |
|
188 |
}, |
|
189 |
|
|
190 |
/** |
|
191 |
* Notify the parent of any change |
|
192 |
* @method |
|
193 |
*/ |
|
194 |
notifyValueSelected : function () { |
|
195 |
this.parent.notifyValueChanged(this.code); |
|
196 |
}, |
|
197 |
|
|
198 |
/** |
|
199 |
* Return if both values are defined. |
|
200 |
* @method |
|
201 |
* @return {Boolean} |
|
202 |
*/ |
|
203 |
isValueDefined : function () { |
|
204 |
if (this.fieldFrom.getValue() && this.fieldTo.getValue()) { |
|
205 |
return true; |
|
206 |
} else { |
|
207 |
return false; |
|
208 |
} |
|
209 |
}, |
|
210 |
/** |
|
211 |
* Get the selected Value |
|
212 |
* @return {} the selected Value { |
|
213 |
* from : from value, |
|
214 |
* to : to value |
|
215 |
* } |
|
216 |
*/ |
|
217 |
getSelectedValue : function () { |
|
218 |
return { |
|
219 |
from : this.fieldFrom.getValue(), |
|
220 |
to : this.fieldTo.getValue() |
|
221 |
}; |
|
222 |
}, |
|
223 |
|
|
224 |
/** |
|
225 |
* Returns the value to request corresponding to the Filter API. |
|
226 |
* @return {String} parameter filter value |
|
227 |
*/ |
|
228 |
getParameterValue : function () { |
|
229 |
var value = this.getSelectedValue(); |
|
230 |
if (Ext.isEmpty(value) || Ext.isEmpty(value.from) || Ext.isEmpty(value.to)) { |
|
231 |
return null; |
|
232 |
} |
|
233 |
// var result = this.type + "|" + this.code + "|" + value.from + "|" + value.to; |
|
234 |
// if (!Ext.isEmpty(this.userDimension) && !Ext.isEmpty(this.userUnit)){ |
|
235 |
// result += "|" + this.userDimension + "|" + this.userUnit; |
|
236 |
// } |
|
237 |
return { |
|
238 |
type : this.type, |
|
239 |
code : this.code, |
|
240 |
value : value.from + "|" + value.to, |
|
241 |
userDimension : this.userDimension, |
|
242 |
userUnit : this.userUnit |
|
243 |
}; |
|
244 |
|
|
245 |
}, |
|
246 |
|
|
247 |
// *** Reset function for RESET button ***// |
|
248 |
resetToDefault : function () { |
|
249 |
this.fieldFrom.reset(); |
|
250 |
this.fieldTo.reset(); |
|
251 |
} |
|
252 |
// ***************************************// |
|
253 |
|
|
254 |
}); |
Also available in: Unified diff
Change necessary to show default values in 'NUMERIC_BETWEEN' query form component as textbox watermarks.