1 |
4307
|
leinfelder
|
/*
|
2 |
|
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3 |
|
|
$Id: $
|
4 |
|
|
*/
|
5 |
|
|
|
6 |
|
|
// Ensure this object's dependencies are loaded.
|
7 |
|
|
mapbuilder.loadScript(baseDir+"/widget/WidgetBaseXSL.js");
|
8 |
|
|
|
9 |
|
|
// For customised searching/loading indication
|
10 |
|
|
httpStatusMsg = ['uninitialized','searching','loaded','building results list','completed'];
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* Display a Catalog Search form.
|
14 |
|
|
* @constructor
|
15 |
|
|
* @base WidgetBaseXSL
|
16 |
|
|
* @param widgetNode The widget's XML object node from the configuration document.
|
17 |
|
|
* @param model The model object that this widget belongs to.
|
18 |
|
|
*/
|
19 |
|
|
function CatalogSearchForm(widgetNode, model) {
|
20 |
|
|
WidgetBaseXSL.apply(this,new Array(widgetNode, model));
|
21 |
|
|
|
22 |
|
|
this.targetContext = this.getProperty("mb:targetContext");
|
23 |
|
|
this.wrsUrl = this.getProperty("mb:wrsUrl");
|
24 |
|
|
this.wrsServiceAssociation = this.getProperty("mb:wrsServiceAssociation");
|
25 |
|
|
this.convert2ContextXsl = this.getProperty("mb:convert2ContextXsl");
|
26 |
|
|
this.queryXsl = this.getProperty("mb:queryXsl");
|
27 |
|
|
|
28 |
|
|
this.httpPayload = new Object();
|
29 |
|
|
this.httpPayload.url = this.wrsUrl;
|
30 |
|
|
this.httpPayload.method = "post";
|
31 |
|
|
|
32 |
|
|
this.mapModel = this.getProperty("mb:mapModel") || model.id;
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* Refreshes the form onblur handlers when this widget is painted.
|
36 |
|
|
* @param objRef Pointer to this CurorTrack object.
|
37 |
|
|
*/
|
38 |
|
|
this.postPaint = function() {
|
39 |
|
|
//config.objects[this.mapModel].addListener('aoi', this.displayAoiCoords, this);
|
40 |
|
|
|
41 |
|
|
this.searchForm = document.getElementById(this.formName);
|
42 |
|
|
this.searchForm.parentWidget = this;
|
43 |
|
|
//this.searchForm.westCoord.model = this.model;
|
44 |
|
|
//this.searchForm.northCoord.model = this.model;
|
45 |
|
|
//this.searchForm.eastCoord.model = this.model;
|
46 |
|
|
//this.searchForm.southCoord.model = this.model;
|
47 |
|
|
this.searchForm.onkeypress = this.handleKeyPress;
|
48 |
|
|
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
/**
|
52 |
|
|
* Output the AOI coordinates to the associated form input elements. This
|
53 |
|
|
* method is registered as an AOI listener on the context doc.
|
54 |
|
|
* @param objRef Pointer to this searchForm object.
|
55 |
|
|
*/
|
56 |
|
|
//CatalogSearchForm.prototype.displayAoiCoords = function(objRef) {
|
57 |
|
|
//var aoi = config.objects[objRef.mapModel].getParam("aoi");
|
58 |
|
|
//objRef.searchForm.westCoord.value = aoi[0][0];
|
59 |
|
|
//objRef.searchForm.northCoord.value = aoi[0][1];
|
60 |
|
|
//objRef.searchForm.eastCoord.value = aoi[1][0];
|
61 |
|
|
//objRef.searchForm.southCoord.value = aoi[1][1];
|
62 |
|
|
|
63 |
|
|
//}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Handles user input from the form element. This is an onblur handler for
|
67 |
|
|
* the input elements.
|
68 |
|
|
*/
|
69 |
|
|
CatalogSearchForm.prototype.setAoi = function() {
|
70 |
|
|
// var aoi = config.objects[this.mapModel].getParam("aoi");
|
71 |
|
|
// if (aoi) {
|
72 |
|
|
// var ul = aoi[0];
|
73 |
|
|
// var lr = aoi[1];
|
74 |
|
|
// switch(this.name) {
|
75 |
|
|
// case 'westCoord':
|
76 |
|
|
// ul[0] = this.value;
|
77 |
|
|
// break;
|
78 |
|
|
// case 'northCoord':
|
79 |
|
|
// ul[1] = this.value;
|
80 |
|
|
// break;
|
81 |
|
|
// case 'eastCoord':
|
82 |
|
|
// lr[0] = this.value;
|
83 |
|
|
// break;
|
84 |
|
|
// case 'southCoord':
|
85 |
|
|
// lr[1] = this.value;
|
86 |
|
|
// break;
|
87 |
|
|
// }
|
88 |
|
|
// config.objects[this.mapModel].setParam("aoi",new Array(ul,lr) );
|
89 |
|
|
// }
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
/**
|
93 |
|
|
* Change the AOI coordinates from select box choice of prefined locations
|
94 |
|
|
* @param bbox the bbox value of the location keyword chosen
|
95 |
|
|
*/
|
96 |
|
|
CatalogSearchForm.prototype.setLocation = function(bbox) {
|
97 |
|
|
var bboxArray = new Array();
|
98 |
|
|
bboxArray = bbox.split(",");
|
99 |
|
|
var ul = new Array(parseFloat(bboxArray[0]),parseFloat(bboxArray[2]));
|
100 |
|
|
var lr = new Array(parseFloat(bboxArray[1]),parseFloat(bboxArray[3]));
|
101 |
|
|
config.objects[this.mapModel].setParam("aoi",new Array(ul,lr));
|
102 |
|
|
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
/**
|
107 |
|
|
* Build and send a catalog query. The results will be inserted into the
|
108 |
|
|
* targetModel which will trigger an event to handleResponse().
|
109 |
|
|
*
|
110 |
|
|
* @return none
|
111 |
|
|
*/
|
112 |
|
|
CatalogSearchForm.prototype.doSelect = function() {
|
113 |
|
|
// Register for an event sent after the catalog query has finished
|
114 |
|
|
|
115 |
|
|
if(!this.initialized){
|
116 |
|
|
this.targetModel.addListener("loadModel",this.handleResponse,this);
|
117 |
|
|
this.xslProcessor = new XslProcessor(this.convert2ContextXsl);
|
118 |
|
|
this.initialized=1;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
// call buildQuery method to read form values, put them into the model
|
122 |
|
|
// and perform an XSL translation to get the WRS Query
|
123 |
|
|
var wrsQueryXML = this.buildQuery();
|
124 |
|
|
|
125 |
|
|
// POST the query to the WRS Service configured in config.xml (wrsUrl)
|
126 |
|
|
this.httpPayload.postData= wrsQueryXML;
|
127 |
|
|
this.targetModel.transactionType="insert";
|
128 |
|
|
this.targetModel.newRequest(this.targetModel,this.httpPayload);
|
129 |
|
|
|
130 |
|
|
// Load the new model
|
131 |
|
|
// Disabled, otherwise the loading indicator doesn't work
|
132 |
|
|
//this.targetModel.callListeners("loadModel");
|
133 |
|
|
|
134 |
|
|
// Activate the loading indicator
|
135 |
|
|
this.targetModel.callListeners("refresh");
|
136 |
|
|
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
/**
|
140 |
|
|
* Builds WRS Catalog query
|
141 |
|
|
* returns: WRS Query XML (string)
|
142 |
|
|
*
|
143 |
|
|
* @return wrsQueryXML A textual representation of the WRS Query XML
|
144 |
|
|
*/
|
145 |
|
|
CatalogSearchForm.prototype.buildQuery = function() {
|
146 |
|
|
// Get the reference to the form
|
147 |
|
|
this.searchForm = document.getElementById(this.formName);
|
148 |
|
|
|
149 |
|
|
// Fill the model with the values needed for building the query
|
150 |
|
|
// TBD: This is not a correct way to address the model, since the form values will disappear when
|
151 |
|
|
// the model changes. View needs to correspond to the model.
|
152 |
|
|
|
153 |
|
|
// added empty string '' to prevent IE from crashing on empty/null values
|
154 |
|
|
this.model.setXpathValue(this.model, "/filter/keywords", this.searchForm.keywords.value + '', false);
|
155 |
|
|
this.model.setXpathValue(this.model, "/filter/servicetype", this.searchForm.serviceType.value + '', false);
|
156 |
|
|
this.model.setXpathValue(this.model, "/filter/serviceassociation", this.wrsServiceAssociation + '', false);
|
157 |
|
|
|
158 |
|
|
// determine the BBox
|
159 |
|
|
var aoi = config.objects[this.mapModel].getParam("aoi");
|
160 |
|
|
var bboxStr = "";
|
161 |
|
|
if (aoi) {
|
162 |
|
|
// a bbox was set in the map pane
|
163 |
|
|
bboxStr = aoi[0][0]+","+aoi[1][1]+" "+aoi[1][0]+","+aoi[0][1];
|
164 |
|
|
} else {
|
165 |
|
|
// no bbox was set, use the bbox of the map model
|
166 |
|
|
var bbox = config.objects[this.mapModel].getBoundingBox();
|
167 |
|
|
bboxStr = bbox[0]+","+bbox[1]+" "+bbox[2]+","+bbox[3];
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
// Add location based filter (BBOX)
|
171 |
|
|
// TBD: uncomment this line below when WRS filtering works OK
|
172 |
|
|
//this.model.setXpathValue(this.model, "/filter/location", bboxStr, false);
|
173 |
|
|
|
174 |
|
|
// Load the XSL to generate the WRS Query
|
175 |
|
|
//this.wrsQuery=new XslProcessor(baseDir+"/tool/xsl/wrs_Query.xsl");
|
176 |
|
|
var queryProcessor = new XslProcessor(this.queryXsl);
|
177 |
|
|
|
178 |
|
|
// Add filter to XSL as a parameter
|
179 |
|
|
queryProcessor.setParameter("filter", this.model.doc);
|
180 |
|
|
|
181 |
|
|
// Do the actual XSL translation to generate the WRS Query
|
182 |
|
|
var wrsQueryXML = queryProcessor.transformNodeToString(this.model.doc);
|
183 |
|
|
return wrsQueryXML;
|
184 |
|
|
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
/**
|
188 |
|
|
* Convert the response of a Catalog Query into an OWSContext document
|
189 |
|
|
* so that it can be processed.
|
190 |
|
|
* Called after the response from a Catalog query has been received and
|
191 |
|
|
* populated in the targetModel.
|
192 |
|
|
* @param objRef Pointer to widget object.
|
193 |
|
|
*/
|
194 |
|
|
CatalogSearchForm.prototype.handleResponse = function(objRef) {
|
195 |
|
|
|
196 |
|
|
var newContext=objRef.xslProcessor.transformNodeToObject(objRef.targetModel.doc);
|
197 |
|
|
|
198 |
|
|
window.config.objects[objRef.targetContext].setModel(
|
199 |
|
|
window.config.objects[objRef.targetContext],
|
200 |
|
|
newContext);
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
//set some properties for the form output
|
204 |
|
|
this.formName = "WebServiceForm_" + mbIds.getId();
|
205 |
|
|
this.stylesheet.setParameter("formName", this.formName);
|
206 |
|
|
}
|