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: CatSearchForm.js 3091 2007-08-09 12:21:54Z gjvoosten $
|
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 WidgetBaseXSL
|
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
|
/**
|
30
|
* Refreshes the form onblur handlers when this widget is painted.
|
31
|
* @param objRef Pointer to this CurorTrack object.
|
32
|
*/
|
33
|
this.postPaint = function(objRef) {
|
34
|
objRef.searchForm = document.getElementById(objRef.formName);
|
35
|
objRef.searchForm.parentWidget = objRef;
|
36
|
|
37
|
objRef.searchForm.westCoord.onblur = objRef.setAoi;
|
38
|
objRef.searchForm.northCoord.onblur = objRef.setAoi;
|
39
|
objRef.searchForm.eastCoord.onblur = objRef.setAoi;
|
40
|
objRef.searchForm.southCoord.onblur = objRef.setAoi;
|
41
|
objRef.searchForm.westCoord.model = objRef.model;
|
42
|
objRef.searchForm.northCoord.model = objRef.model;
|
43
|
objRef.searchForm.eastCoord.model = objRef.model;
|
44
|
objRef.searchForm.southCoord.model = objRef.model;
|
45
|
|
46
|
|
47
|
|
48
|
objRef.searchForm.onkeypress = objRef.handleKeyPress;
|
49
|
objRef.searchForm.onsubmit = objRef.submitForm;
|
50
|
//objRef.searchForm.mapsheet.onblur = objRef.setMapsheet;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Output the AOI coordinates to the associated form input elements. This
|
55
|
* method is registered as an AOI listener on the context doc.
|
56
|
* @param objRef Pointer to this searchForm object.
|
57
|
*/
|
58
|
this.displayAoiCoords = function(objRef) {
|
59
|
objRef.searchForm = document.getElementById(objRef.formName);
|
60
|
var aoi = objRef.model.getParam("aoi");
|
61
|
objRef.searchForm.westCoord.value = aoi[0][0];
|
62
|
objRef.searchForm.northCoord.value = aoi[0][1];
|
63
|
objRef.searchForm.eastCoord.value = aoi[1][0];
|
64
|
objRef.searchForm.southCoord.value = aoi[1][1];
|
65
|
}
|
66
|
this.model.addListener('aoi', this.displayAoiCoords, this);
|
67
|
|
68
|
/**
|
69
|
* Handles user input from the form element. This is an onblur handler for
|
70
|
* the input elements.
|
71
|
*/
|
72
|
this.setAoi = function() {
|
73
|
var aoi = this.model.getParam("aoi");
|
74
|
if (aoi) {
|
75
|
var ul = aoi[0];
|
76
|
var lr = aoi[1];
|
77
|
switch(this.name) {
|
78
|
case 'westCoord':
|
79
|
ul[0] = this.value;
|
80
|
break;
|
81
|
case 'northCoord':
|
82
|
ul[1] = this.value;
|
83
|
break;
|
84
|
case 'eastCoord':
|
85
|
lr[0] = this.value;
|
86
|
break;
|
87
|
case 'southCoord':
|
88
|
lr[1] = this.value;
|
89
|
break;
|
90
|
}
|
91
|
this.model.setParam("aoi",new Array(ul,lr) );
|
92
|
}
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Change the AOI coordinates from select box choice of prefined locations
|
97
|
* @param bbox the bbox value of the location keyword chosen
|
98
|
*/
|
99
|
this.setLocation = function(bbox) {
|
100
|
var bboxArray = new Array();
|
101
|
bboxArray = bbox.split(",");
|
102
|
var ul = new Array(parseFloat(bboxArray[0]),parseFloat(bboxArray[2]));
|
103
|
var lr = new Array(parseFloat(bboxArray[1]),parseFloat(bboxArray[3]));
|
104
|
this.model.setParam("aoi",new Array(ul,lr));
|
105
|
|
106
|
//convert this.model XY to latlong
|
107
|
//convert latlong to targetmodel XY
|
108
|
//extent.setAoi takes XY as input
|
109
|
//this.targetModel.setParam("aoi", new Array(ul,lr));
|
110
|
//this.targetModel.setParam("mouseup",this);
|
111
|
}
|
112
|
|
113
|
|
114
|
/**
|
115
|
* Handles submission of the form (via javascript in an <a> tag)
|
116
|
*/
|
117
|
this.submitForm = function() {
|
118
|
thisWidget = this.parentWidget;
|
119
|
thisWidget.webServiceForm = document.getElementById(thisWidget.formName);
|
120
|
//thisWidget.targetModel.setParam("filter",filter);
|
121
|
thisWidget.targetModel.setParam("wfs_GetFeature","service_resources");
|
122
|
return false;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* handles keypress events to filter out everything except "enter".
|
127
|
* Pressing the "enter" key will trigger a form submit
|
128
|
* @param event the event object passed in for Mozilla; IE uses window.event
|
129
|
*/
|
130
|
this.handleKeyPress = function(event) {
|
131
|
var keycode;
|
132
|
var target;
|
133
|
if (event){
|
134
|
//Mozilla
|
135
|
keycode=event.which;
|
136
|
target=event.currentTarget;
|
137
|
}else{
|
138
|
//IE
|
139
|
keycode=window.event.keyCode;
|
140
|
target=window.event.srcElement.form;
|
141
|
}
|
142
|
|
143
|
if (keycode == 13) { //enter key
|
144
|
target.parentWidget.submitForm();
|
145
|
return false;
|
146
|
}
|
147
|
}
|
148
|
|
149
|
var RUC_Window=null;
|
150
|
this.openRucWindow = function( rucType ) {
|
151
|
if ( RUC_Window == null || RUC_Window.closed ) {
|
152
|
var baseUrl;
|
153
|
var params;
|
154
|
switch(rucType) {
|
155
|
case "placename":
|
156
|
baseURL = "/rucs/placeName.html?language=" + config.lang + "&formName=" + this.formName;
|
157
|
params = "width=290,height=480,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0";
|
158
|
break;
|
159
|
case "postalCode":
|
160
|
baseURL = "/rucs/postalCode.html?language=" + config.lang + "&formName=" + this.formName;
|
161
|
params = "width=280,height=180,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0";
|
162
|
break;
|
163
|
default:
|
164
|
alert(mbGetMessage("unknownRucType"));
|
165
|
break;
|
166
|
}
|
167
|
RUC_Window = open( baseURL, "RUCWindow", params );
|
168
|
}
|
169
|
RUC_Window.focus();
|
170
|
return false;
|
171
|
}
|
172
|
function RUC_closeRUCWindow() {
|
173
|
if ( RUC_Window != null && !RUC_Window.closed ) {
|
174
|
RUC_Window.close();
|
175
|
}
|
176
|
}
|
177
|
|
178
|
//set some properties for the form output
|
179
|
this.formName = "WebServiceForm_" + mbIds.getId();
|
180
|
this.stylesheet.setParameter("formName", this.formName);
|
181
|
}
|
182
|
|
183
|
/**
|
184
|
*/
|
185
|
SetAoiCoords = function(aoiBox) {
|
186
|
config.objects.mainMap.setParam("aoi",aoiBox );
|
187
|
}
|
188
|
|