git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / ConeSearch.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 |
/**
|
27 |
* Abstract Class to build Container to display a Cone Search.
|
28 |
* subclasses :
|
29 |
* - sitools.common.forms.components.ConeSearchCartesien
|
30 |
* - sitools.common.forms.components.ConeSearchPGSphere
|
31 |
* @requires sitools.common.forms.ComponentFactory
|
32 |
* @class sitools.common.forms.components.AbstractConeSearch
|
33 |
* @extends sitools.common.forms.AbstractWithUnit
|
34 |
*/
|
35 |
sitools.common.forms.components.AbstractConeSearch = Ext.extend(sitools.common.forms.AbstractWithUnit, { |
36 |
initComponent : function () { |
37 |
this.context = new sitools.common.forms.ComponentFactory(this.context); |
38 |
//formattage de extraParams :
|
39 |
var extraParams = {};
|
40 |
Ext.each(this.extraParams, function (param) { |
41 |
extraParams[param.name]= param.value; |
42 |
}, this);
|
43 |
|
44 |
this.extraParams = extraParams;
|
45 |
var unit;
|
46 |
//the administrator defines a dimension for this component
|
47 |
if (!Ext.isEmpty(this.dimensionId)) { |
48 |
var unit = new Ext.Button({ |
49 |
scope : this, |
50 |
text : i18n.get('label.degree'), |
51 |
width : 100, |
52 |
sitoolsType : 'unitbutton', |
53 |
handler : function (b, e) { |
54 |
//inherited method
|
55 |
this.loadUnits(b, e);
|
56 |
} |
57 |
}); |
58 |
} |
59 |
else {
|
60 |
unit = new Ext.Container({
|
61 |
html : i18n.get('label.degree'), |
62 |
width : 100 |
63 |
}); |
64 |
|
65 |
} |
66 |
|
67 |
//Build the defaults Values
|
68 |
var defaultRa = null; |
69 |
var defaultDec = null; |
70 |
var defaultThirdValue = null; |
71 |
if (Ext.isArray(this.defaultValues) && this.defaultValues.length == 3) { |
72 |
defaultRa = this.defaultValues[0]; |
73 |
defaultDec = this.defaultValues[1]; |
74 |
defaultThirdValue = this.defaultValues[2]; |
75 |
} |
76 |
|
77 |
this.raParam = new Ext.form.NumberField({ |
78 |
fieldLabel : "RA", |
79 |
allowBlank : true, |
80 |
decimalPrecision : 20, |
81 |
anchor : "98%", |
82 |
value : defaultRa,
|
83 |
flex : 1, |
84 |
labelSeparator : "" |
85 |
|
86 |
}); |
87 |
this.decParam = new Ext.form.NumberField({ |
88 |
fieldLabel : "DEC", |
89 |
allowBlank : true, |
90 |
decimalPrecision : 20, |
91 |
anchor : "98%", |
92 |
value : defaultDec,
|
93 |
flex : 1, |
94 |
labelSeparator : "" |
95 |
}); |
96 |
|
97 |
this.thirdParam = new Ext.form.NumberField({ |
98 |
fieldLabel : this.getLabelThirdParam(), |
99 |
allowBlank : true, |
100 |
decimalPrecision : 20, |
101 |
value : defaultThirdValue,
|
102 |
flex : 1, |
103 |
labelSeparator : "" |
104 |
}); |
105 |
|
106 |
var thirdCont = new Ext.form.CompositeField({ |
107 |
labelWidth : 100, |
108 |
fieldLabel : this.getLabelThirdParam(), |
109 |
items : [this.thirdParam, unit], |
110 |
labelSeparator : "" |
111 |
}); |
112 |
|
113 |
//build the resolver Name
|
114 |
this.targetName = new Ext.form.TextField({ |
115 |
flex : 1, |
116 |
fieldLabel : i18n.get("label.targetName"), |
117 |
enableKeyEvents : true, |
118 |
listeners : {
|
119 |
scope : this, |
120 |
change : function (field, newValue, oldValue) { |
121 |
this.nameResolverButton.setDisabled(Ext.isEmpty(newValue));
|
122 |
}, |
123 |
keyup : function () { |
124 |
this.nameResolverButton.setDisabled(Ext.isEmpty(this.targetName.getValue())); |
125 |
} |
126 |
} |
127 |
}); |
128 |
|
129 |
|
130 |
this.nameResolverButton = new Ext.Button({ |
131 |
scope : this, |
132 |
id : 'resolveNameBtn', |
133 |
handler : this.resolveTargetName, |
134 |
text : i18n.get('label.resolveName'), |
135 |
width : 100, |
136 |
disabled : true |
137 |
}); |
138 |
|
139 |
var targetCmp = new Ext.form.FieldSet({ |
140 |
title : i18n.get('label.resolverName'), |
141 |
items : [
|
142 |
new Ext.form.CompositeField ({
|
143 |
items : [this.targetName, this.nameResolverButton] |
144 |
}) |
145 |
] |
146 |
}); |
147 |
|
148 |
//Load the 3 fields into a form layout in the main container items
|
149 |
var items = [{
|
150 |
layout : "form", |
151 |
items : [ this.raParam, this.decParam, thirdCont], |
152 |
flex : 3 |
153 |
}]; |
154 |
|
155 |
//insert first the name Resolver if needed
|
156 |
if (this.extraParams.showTargetName && this.extraParams.showTargetName != "false") { |
157 |
items[0].items.unshift(targetCmp);
|
158 |
} |
159 |
|
160 |
Ext.apply(this, {
|
161 |
autoEl: 'div', |
162 |
layout : 'hbox', |
163 |
defaults : {
|
164 |
xtype : 'container', |
165 |
autoEl : 'div' |
166 |
}, |
167 |
items : items,
|
168 |
overCls : 'fieldset-child', |
169 |
stype : "sitoolsFormContainer" |
170 |
}); |
171 |
sitools.common.forms.components.AbstractConeSearch.superclass.initComponent.apply( |
172 |
this, arguments); |
173 |
if (!Ext.isEmpty(this.label)) { |
174 |
this.items.insert(0, new Ext.Container({ |
175 |
border : false, |
176 |
html : this.label, |
177 |
width : 100 |
178 |
})); |
179 |
} |
180 |
|
181 |
}, |
182 |
/**
|
183 |
* Return true if values are specified
|
184 |
* @return {Boolean}
|
185 |
*/
|
186 |
isValueDefined : function () { |
187 |
if (this.raParam.getValue() && this.decParam.getValue() && this.thirdParam.getValue()) { |
188 |
return true; |
189 |
} else {
|
190 |
return false; |
191 |
} |
192 |
}, |
193 |
/**
|
194 |
* Return the ConeSearch value
|
195 |
* @return {}
|
196 |
*/
|
197 |
getSelectedValue : function () { |
198 |
return {
|
199 |
raParam : this.raParam.getValue(), |
200 |
decParam : this.decParam.getValue(), |
201 |
thirdParam : this.thirdParam.getValue() |
202 |
}; |
203 |
}, |
204 |
|
205 |
/**
|
206 |
* Method to be called by the form
|
207 |
* returns an object with type, code& value attributes
|
208 |
* @return {}
|
209 |
*/
|
210 |
getParameterValue : function () { |
211 |
var value = this.getSelectedValue(); |
212 |
if (Ext.isEmpty(value) || Ext.isEmpty(value.raParam) || Ext.isEmpty(value.decParam) || Ext.isEmpty(value.thirdParam)) {
|
213 |
return null; |
214 |
} |
215 |
return {
|
216 |
type : this.type, |
217 |
code : this.code, |
218 |
value : value.raParam + "|" + value.decParam + "|" + value.thirdParam, |
219 |
userDimension : this.userDimension, |
220 |
userUnit : this.userUnit |
221 |
}; |
222 |
|
223 |
}, |
224 |
/**
|
225 |
* Name Resolver action.
|
226 |
* Send a query as defined by the admin.
|
227 |
* @param type
|
228 |
* the type
|
229 |
*/
|
230 |
resolveTargetName : function () { |
231 |
|
232 |
var baseUrl = this.extraParams.resolveNameUrl; |
233 |
var url = baseUrl + "/" + this.targetName.getValue() + "/" + this.extraParams.coordSystem; |
234 |
|
235 |
if (!Ext.isEmpty(this.extraParams.resolverName)){ |
236 |
url += "?nameResolver=" + this.extraParams.resolverName; |
237 |
} |
238 |
|
239 |
this.getEl().mask();
|
240 |
Ext.Ajax.request({ |
241 |
url : url,
|
242 |
scope : this, |
243 |
method : "GET", |
244 |
success : function (ret) { |
245 |
try {
|
246 |
var json = Ext.decode(ret.responseText);
|
247 |
|
248 |
if (json.totalResults > 1){ |
249 |
this.choosePropertyType(json);
|
250 |
} |
251 |
else {
|
252 |
this.fillUpRADEC(json.features[0].geometry.coordinates); |
253 |
} |
254 |
} |
255 |
catch(err) {
|
256 |
Ext.Msg.alert(i18n.get('label.error'), i18n.get("label.unableToParseRequest")); |
257 |
return;
|
258 |
} |
259 |
}, |
260 |
failure : alertFailure,
|
261 |
callback : function () { |
262 |
this.getEl().unmask();
|
263 |
} |
264 |
}) |
265 |
}, |
266 |
|
267 |
/**
|
268 |
* Choose a property type.
|
269 |
* Define a type to fill up RA/DEC
|
270 |
*/
|
271 |
choosePropertyType : function (json) { |
272 |
|
273 |
var position = Ext.getCmp('resolveNameBtn').getPosition(); |
274 |
|
275 |
var tabTypes = [];
|
276 |
|
277 |
tabTypes.push({ |
278 |
xtype : 'label', |
279 |
text : 'Select a Type : ', |
280 |
style : 'padding:3px; margin:auto; font-style:italic;' |
281 |
}); |
282 |
|
283 |
|
284 |
Ext.each(json.features, function(feat, ind, all){
|
285 |
if(feat.properties.type){
|
286 |
tabTypes.push({ |
287 |
xtype : 'button', |
288 |
text : feat.properties.type,
|
289 |
style : 'padding:3px; margin:auto;', |
290 |
scope : this, |
291 |
handler : function(b, e){ |
292 |
this.fillUpRADEC(feat.geometry.coordinates);
|
293 |
Ext.getCmp('nameResolverTypeWin').close();
|
294 |
} |
295 |
}); |
296 |
} |
297 |
}, this);
|
298 |
|
299 |
var popup = new Ext.Window({ |
300 |
id : 'nameResolverTypeWin', |
301 |
x : position[0] + 4, |
302 |
y : position[1] + 18, |
303 |
title : '', |
304 |
bodyStyle : 'background-color : #E4E8EC;', |
305 |
frame:false, |
306 |
closable : false, |
307 |
resizable : false, |
308 |
draggable : true, |
309 |
items : tabTypes,
|
310 |
listeners : {
|
311 |
deactivate : function (t){ |
312 |
t.close(); |
313 |
} |
314 |
} |
315 |
}).show(); |
316 |
}, |
317 |
|
318 |
fillUpRADEC : function (coord){ |
319 |
this.raParam.setValue(coord[0]); |
320 |
this.decParam.setValue(coord[1]); |
321 |
}, |
322 |
|
323 |
isValid : function () { |
324 |
if(!this.isEmpty(this.raParam) || !this.isEmpty(this.decParam) || !this.isEmpty(this.decParam)) { |
325 |
var valid = true; |
326 |
valid &= this.checkTextFieldIsNotEmpty(this.raParam); |
327 |
valid &= this.checkTextFieldIsNotEmpty(this.decParam); |
328 |
valid &= this.checkTextFieldIsNotEmpty(this.thirdParam); |
329 |
return valid;
|
330 |
} else {
|
331 |
return true; |
332 |
} |
333 |
}, |
334 |
|
335 |
//private
|
336 |
checkTextFieldIsNotEmpty : function (field){ |
337 |
var valid = true; |
338 |
if(this.isEmpty(field)){ |
339 |
field.markInvalid(); |
340 |
valid = false;
|
341 |
} |
342 |
return valid;
|
343 |
}, |
344 |
|
345 |
isEmpty : function (field) { |
346 |
return Ext.isEmpty(field.getValue())
|
347 |
}, |
348 |
|
349 |
// *** Reset function for RESET button ***//
|
350 |
resetToDefault : function () { |
351 |
this.raParam.reset();
|
352 |
this.decParam.reset();
|
353 |
this.thirdParam.reset();
|
354 |
this.targetName.reset();
|
355 |
} |
356 |
// **************************************//
|
357 |
|
358 |
}); |
359 |
|
360 |
/**
|
361 |
* Specification of sitools.common.forms.components.AbstractConeSearch
|
362 |
* @class sitools.common.forms.components.ConeSearchCartesien
|
363 |
* @extends sitools.common.forms.components.AbstractConeSearch
|
364 |
*/
|
365 |
sitools.common.forms.components.ConeSearchCartesien = Ext.extend(sitools.common.forms.components.AbstractConeSearch, { |
366 |
getLabelThirdParam : function () { |
367 |
return "Search Radius"; |
368 |
} |
369 |
}); |
370 |
|
371 |
/**
|
372 |
* Specification of sitools.common.forms.components.AbstractConeSearch
|
373 |
* @class sitools.common.forms.components.ConeSearchPGSphere
|
374 |
* @extends sitools.common.forms.components.AbstractConeSearch
|
375 |
*/
|
376 |
sitools.common.forms.components.ConeSearchPGSphere = Ext.extend(sitools.common.forms.components.AbstractConeSearch, { |
377 |
getLabelThirdParam : function () { |
378 |
return "Radius"; |
379 |
} |
380 |
}); |