1
|
/*
|
2
|
Description: Display a form for OpenLS geocoding request
|
3
|
Author: Steven Ottens AT geodan.nl
|
4
|
Licence: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
5
|
$Id: OpenLSForm.js 3879 2008-02-27 14:20:29Z gjvoosten $
|
6
|
*/
|
7
|
|
8
|
// Ensure this object's dependancies are loaded.
|
9
|
mapbuilder.loadScript(baseDir+"/widget/WidgetBaseXSL.js");
|
10
|
|
11
|
/**
|
12
|
* Widget to display the OpenLS request form
|
13
|
*
|
14
|
* @constructor
|
15
|
* @base WidgetBaseXSL
|
16
|
* @param widgetNode This widget's object node from the configuration document.
|
17
|
* @param model The model that this widget is a view of.
|
18
|
*/
|
19
|
|
20
|
function OpenLSForm(widgetNode, model) {
|
21
|
WidgetBaseXSL.apply(this,new Array(widgetNode, model));
|
22
|
|
23
|
this.defaultModelUrl=this.getProperty("mb:defaultModelUrl");
|
24
|
this.geocodeServerUrl=this.getProperty("mb:geocodeServerUrl");
|
25
|
|
26
|
this.xsl=new XslProcessor(baseDir+"/tool/xsl/ols_GeocodeRequest.xsl");
|
27
|
/**
|
28
|
* handles the submission of the form
|
29
|
*/
|
30
|
this.submitForm = function(objRef) {
|
31
|
//Parse the form
|
32
|
var geoForm = document.getElementById(this.formName);
|
33
|
pc = geoForm.pcValue.value;
|
34
|
street = geoForm.streetValue.value;
|
35
|
number = geoForm.numberValue.value;
|
36
|
city = geoForm.cityValue.value;
|
37
|
municipality = geoForm.municipalityValue.value;
|
38
|
country =geoForm.countryValue.value;
|
39
|
|
40
|
//fill the form output into the xsl
|
41
|
if(pc) objRef.xsl.setParameter("postalCode", pc);
|
42
|
if(street) objRef.xsl.setParameter("street", street);
|
43
|
if(number) objRef.xsl.setParameter("number", number);
|
44
|
if(city) objRef.xsl.setParameter("municipalitySubdivision", city);
|
45
|
if(municipality) objRef.xsl.setParameter("municipality", municipality);
|
46
|
if(country) objRef.xsl.setParameter("countryCode", country);
|
47
|
if(!country) {
|
48
|
alert(mbGetMessage("noCountryCode"));
|
49
|
return;
|
50
|
}
|
51
|
//no values entered, bail out
|
52
|
if(!municipality && !city && !number && !street && !pc) {
|
53
|
alert(mbGetMessage("atLeastOneValue"));
|
54
|
return;
|
55
|
}
|
56
|
|
57
|
//do the actual request
|
58
|
objRef.requestModel = objRef.xsl.transformNodeToObject(this.model.doc);
|
59
|
objRef.httpPayload = new Object();
|
60
|
objRef.httpPayload.url = objRef.geocodeServerUrl;
|
61
|
objRef.httpPayload.method="post";
|
62
|
objRef.httpPayload.postData=objRef.requestModel;
|
63
|
objRef.targetModel.newRequest(objRef.targetModel,objRef.httpPayload);
|
64
|
}
|
65
|
|
66
|
//set some properties for the form output
|
67
|
//allow it to have a different form name
|
68
|
this.formName = this.getProperty("mb:formName", "OpenLSForm_" + mbIds.getId());
|
69
|
this.stylesheet.setParameter("formName", this.formName);
|
70
|
}
|
71
|
|