1
|
/*
|
2
|
Author: Mike Adair mike.adairATccrs.nrcan.gc.ca
|
3
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
4
|
|
5
|
$Id: OWSCatSearchForm.js 2097 2006-04-26 17:33:19Z madair $
|
6
|
*/
|
7
|
|
8
|
// Ensure this object's dependancies are loaded.
|
9
|
mapbuilder.loadScript(baseDir+"/widget/WidgetBaseXSL.js");
|
10
|
|
11
|
/**
|
12
|
* Widget to display a form for input of parameters to generate a web service
|
13
|
* request. This JS object handles the form submit via HTTP Get by appending
|
14
|
* a query string to the form's action URL. The query string is created from
|
15
|
* all input elements and their values.
|
16
|
* The target model is then loaded from the URL created.
|
17
|
* A stylehseet must be specified as a property in config for this widget.
|
18
|
* See widget/NtsForm.xsl for an example.
|
19
|
*
|
20
|
* @constructor
|
21
|
* @base WidgetBase
|
22
|
* @param widgetNode This widget's object node from the configuration document.
|
23
|
* @param model The model that this widget is a view of.
|
24
|
*/
|
25
|
|
26
|
function OWSCatSearchForm(widgetNode, model) {
|
27
|
WidgetBaseXSL.apply(this, new Array(widgetNode, model));
|
28
|
|
29
|
//get bbox inforamtion from a map model
|
30
|
var mapModel = widgetNode.selectSingleNode("mb:mapModel");
|
31
|
if ( mapModel ) {
|
32
|
this.mapModel = mapModel.firstChild.nodeValue;
|
33
|
} else {
|
34
|
this.mapModel = model.id;
|
35
|
}
|
36
|
|
37
|
|
38
|
/**
|
39
|
* Refreshes the form onblur handlers when this widget is painted.
|
40
|
* @param objRef Pointer to this CurorTrack object.
|
41
|
*/
|
42
|
this.postPaint = function(objRef) {
|
43
|
config.objects[objRef.mapModel].addListener('aoi', this.displayAoiCoords, this);
|
44
|
|
45
|
objRef.searchForm = document.getElementById(objRef.formName);
|
46
|
objRef.searchForm.parentWidget = objRef;
|
47
|
|
48
|
objRef.searchForm.westCoord.onblur = objRef.setAoi;
|
49
|
objRef.searchForm.northCoord.onblur = objRef.setAoi;
|
50
|
objRef.searchForm.eastCoord.onblur = objRef.setAoi;
|
51
|
objRef.searchForm.southCoord.onblur = objRef.setAoi;
|
52
|
objRef.searchForm.westCoord.model = objRef.model;
|
53
|
objRef.searchForm.northCoord.model = objRef.model;
|
54
|
objRef.searchForm.eastCoord.model = objRef.model;
|
55
|
objRef.searchForm.southCoord.model = objRef.model;
|
56
|
|
57
|
objRef.searchForm.onkeypress = objRef.handleKeyPress;
|
58
|
objRef.searchForm.onsubmit = objRef.submitForm;
|
59
|
//objRef.searchForm.mapsheet.onblur = objRef.setMapsheet;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Output the AOI coordinates to the associated form input elements. This
|
64
|
* method is registered as an AOI listener on the context doc.
|
65
|
* @param objRef Pointer to this searchForm object.
|
66
|
*/
|
67
|
this.displayAoiCoords = function(objRef) {
|
68
|
//objRef.searchForm = document.getElementById(objRef.formName);
|
69
|
var aoi = config.objects[objRef.mapModel].getParam("aoi");
|
70
|
objRef.searchForm.westCoord.value = aoi[0][0];
|
71
|
objRef.searchForm.northCoord.value = aoi[0][1];
|
72
|
objRef.searchForm.eastCoord.value = aoi[1][0];
|
73
|
objRef.searchForm.southCoord.value = aoi[1][1];
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Handles user input from the form element. This is an onblur handler for
|
78
|
* the input elements.
|
79
|
*/
|
80
|
this.setAoi = function() {
|
81
|
var aoi = config.objects[objRef.mapModel].getParam("aoi");
|
82
|
if (aoi) {
|
83
|
var ul = aoi[0];
|
84
|
var lr = aoi[1];
|
85
|
switch(this.name) {
|
86
|
case 'westCoord':
|
87
|
ul[0] = this.value;
|
88
|
break;
|
89
|
case 'northCoord':
|
90
|
ul[1] = this.value;
|
91
|
break;
|
92
|
case 'eastCoord':
|
93
|
lr[0] = this.value;
|
94
|
break;
|
95
|
case 'southCoord':
|
96
|
lr[1] = this.value;
|
97
|
break;
|
98
|
}
|
99
|
config.objects[objRef.mapModel].setParam("aoi",new Array(ul,lr) );
|
100
|
}
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Change the AOI coordinates from select box choice of prefined locations
|
105
|
* @param bbox the bbox value of the location keyword chosen
|
106
|
*/
|
107
|
this.setLocation = function(bbox) {
|
108
|
var bboxArray = new Array();
|
109
|
bboxArray = bbox.split(",");
|
110
|
var ul = new Array(parseFloat(bboxArray[0]),parseFloat(bboxArray[2]));
|
111
|
var lr = new Array(parseFloat(bboxArray[1]),parseFloat(bboxArray[3]));
|
112
|
config.objects[this.mapModel].setParam("aoi",new Array(ul,lr));
|
113
|
|
114
|
//convert this.model XY to latlong
|
115
|
//convert latlong to targetmodel XY
|
116
|
//extent.setAoi takes XY as input
|
117
|
//this.targetModel.setParam("aoi", new Array(ul,lr));
|
118
|
//this.targetModel.setParam("mouseup",this);
|
119
|
}
|
120
|
|
121
|
|
122
|
/**
|
123
|
* Handles submission of the form (via javascript in an <a> tag)
|
124
|
*/
|
125
|
this.submitForm = function() {
|
126
|
var thisWidget = this.parentWidget;
|
127
|
thisWidget.createFilter(thisWidget);
|
128
|
thisWidget.targetModel.setParam("wfs_GetFeature","service_resources");
|
129
|
return false;
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* creates the filter expression
|
134
|
*/
|
135
|
this.createFilter = function(objRef) {
|
136
|
objRef.searchForm = document.getElementById(objRef.formName);
|
137
|
|
138
|
var aoi = config.objects[objRef.mapModel].getParam("aoi");
|
139
|
var bboxStr = "";
|
140
|
if (aoi) {
|
141
|
bboxStr = aoi[0][0]+","+aoi[1][1]+" "+aoi[1][0]+","+aoi[0][1];
|
142
|
} else {
|
143
|
var bbox = config.objects[objRef.mapModel].getBoundingBox();
|
144
|
bboxStr = bbox[0]+","+bbox[1]+" "+bbox[2]+","+bbox[3];
|
145
|
}
|
146
|
objRef.model.setXpathValue(objRef.model,"/Filter/And/BBOX/Box/coordinates",bboxStr,false);
|
147
|
var keywords = "*"+objRef.searchForm.keywords.value+"*";
|
148
|
objRef.model.setXpathValue(objRef.model,"/Filter/And/Or/Or/PropertyIsLike[PropertyName='title']/Literal",keywords,false);
|
149
|
objRef.model.setXpathValue(objRef.model,"/Filter/And/Or/Or/PropertyIsLike[PropertyName='abstract']/Literal",keywords,false);
|
150
|
objRef.model.setXpathValue(objRef.model,"/Filter/And/Or/PropertyIsLike[PropertyName='keywords']/Literal",keywords,false);
|
151
|
|
152
|
objRef.model.setXpathValue(objRef.model,"/Filter/And/PropertyIsEqualTo[PropertyName='service_type']/Literal",objRef.searchForm.serviceType.value,false);
|
153
|
}
|
154
|
|
155
|
|
156
|
/**
|
157
|
* handles keypress events to filter out everything except "enter".
|
158
|
* Pressing the "enter" key will trigger a form submit
|
159
|
* @param event the event object passed in for Mozilla; IE uses window.event
|
160
|
*/
|
161
|
this.handleKeyPress = function(event) {
|
162
|
var keycode;
|
163
|
var target;
|
164
|
if (event){
|
165
|
//Mozilla
|
166
|
keycode=event.which;
|
167
|
target=event.currentTarget;
|
168
|
}else{
|
169
|
//IE
|
170
|
keycode=window.event.keyCode;
|
171
|
target=window.event.srcElement.form;
|
172
|
}
|
173
|
|
174
|
if (keycode == 13) { //enter key
|
175
|
return true;
|
176
|
}
|
177
|
}
|
178
|
|
179
|
//set some properties for the form output
|
180
|
this.formName = "WebServiceForm_" + mbIds.getId();
|
181
|
this.stylesheet.setParameter("formName", this.formName);
|
182
|
}
|