Project

General

Profile

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$
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
  this.filter = Sarissa.getDomDocument();
30
  this.filter.async = false; 
31
  this.filter.load("OWSCatResourceFilter.xml");
32
  this.filter.setProperty("SelectionLanguage", "XPath");
33

    
34

    
35
  /**
36
   * Refreshes the form onblur handlers when this widget is painted.
37
   * @param objRef Pointer to this CurorTrack object.
38
   */
39
  this.postPaint = function(objRef) {
40
    objRef.searchForm = document.getElementById(objRef.formName);
41
    objRef.searchForm.parentWidget = objRef;
42

    
43
    objRef.searchForm.westCoord.onblur = objRef.setAoi;
44
    objRef.searchForm.northCoord.onblur = objRef.setAoi;
45
    objRef.searchForm.eastCoord.onblur = objRef.setAoi;
46
    objRef.searchForm.southCoord.onblur = objRef.setAoi;
47
    objRef.searchForm.westCoord.model = objRef.model;
48
    objRef.searchForm.northCoord.model = objRef.model;
49
    objRef.searchForm.eastCoord.model = objRef.model;
50
    objRef.searchForm.southCoord.model = objRef.model;
51

    
52
    objRef.searchForm.onkeypress = objRef.handleKeyPress;
53
    objRef.searchForm.onsubmit = objRef.submitForm;
54
    //objRef.searchForm.mapsheet.onblur = objRef.setMapsheet;
55
  }
56

    
57
  /**
58
   * Output the AOI coordinates to the associated form input elements.  This
59
   * method is registered as an AOI listener on the context doc.
60
   * @param objRef Pointer to this searchForm object.
61
   */
62
  this.displayAoiCoords = function(objRef) {
63
    //objRef.searchForm = document.getElementById(objRef.formName);
64
    var aoi = objRef.model.getParam("aoi");
65
    objRef.searchForm.westCoord.value = aoi[0][0];
66
    objRef.searchForm.northCoord.value = aoi[0][1];
67
    objRef.searchForm.eastCoord.value = aoi[1][0];
68
    objRef.searchForm.southCoord.value = aoi[1][1];
69
  }
70
  this.model.addListener('aoi', this.displayAoiCoords, this);
71

    
72
  /**
73
   * Handles user input from the form element.  This is an onblur handler for 
74
   * the input elements.
75
   */
76
  this.setAoi = function() {
77
    var aoi = this.model.getParam("aoi");
78
    if (aoi) {
79
      var ul = aoi[0];
80
      var lr = aoi[1];
81
      switch(this.name) {
82
        case 'westCoord':
83
          ul[0] = this.value;
84
          break;
85
        case 'northCoord':
86
          ul[1] = this.value;
87
          break;
88
        case 'eastCoord':
89
          lr[0] = this.value;
90
          break;
91
        case 'southCoord':
92
          lr[1] = this.value;
93
          break;
94
      }
95
      this.model.setParam("aoi",new Array(ul,lr) );
96
    }
97
  }
98

    
99
/**
100
 * Change the AOI coordinates from select box choice of prefined locations
101
 * @param bbox the bbox value of the location keyword chosen
102
 */
103
  this.setLocation = function(bbox) {
104
    var bboxArray = new Array();
105
    bboxArray     = bbox.split(",");
106
    var ul = new Array(parseFloat(bboxArray[0]),parseFloat(bboxArray[2]));
107
    var lr = new Array(parseFloat(bboxArray[1]),parseFloat(bboxArray[3]));
108
    this.model.setParam("aoi",new Array(ul,lr));
109

    
110
    //convert this.model XY to latlong
111
    //convert latlong to targetmodel XY
112
    //extent.setAoi takes XY as input
113
    //this.targetModel.setParam("aoi", new Array(ul,lr));
114
    //this.targetModel.setParam("mouseup",this);
115
  }
116

    
117

    
118
  /**
119
   * Handles submission of the form (via javascript in an <a> tag)
120
   */
121
  this.submitForm = function() {
122
    var thisWidget = this.parentWidget;
123
    thisWidget.createFilter(thisWidget);
124
    thisWidget.targetModel.setParam("wfs_GetFeature","service_resources");
125
    return false;
126
  }
127

    
128
  /**
129
   * creates the filter expression
130
   */
131
  this.createFilter = function(objRef) {
132
    objRef.searchForm = document.getElementById(objRef.formName);
133
    var filter = config.objects["filterExpression"];    //TBD get this ID from config
134

    
135
    var aoi = this.model.getParam("aoi");
136
    var bboxStr = "";
137
    if (aoi) {
138
      bboxStr = aoi[0][0]+","+aoi[1][1]+" "+aoi[1][0]+","+aoi[0][1];
139
    } else {
140
      var bbox = this.model.getBoundingBox();
141
      bboxStr = bbox[0]+","+bbox[1]+" "+bbox[2]+","+bbox[3];
142
    }
143
    filter.setXpathValue(filter,"/Filter/And/BBOX/Box/coordinates",bboxStr);
144
    var keywords = "*"+objRef.searchForm.keywords.value+"*";
145
    filter.setXpathValue(filter,"/Filter/And/Or/Or/PropertyIsLike[PropertyName='title']/Literal",keywords);
146
    filter.setXpathValue(filter,"/Filter/And/Or/Or/PropertyIsLike[PropertyName='abstract']/Literal",keywords);
147
    filter.setXpathValue(filter,"/Filter/And/Or/PropertyIsLike[PropertyName='keywords']/Literal",keywords);
148
  }
149

    
150

    
151
  /**
152
   * handles keypress events to filter out everything except "enter".  
153
   * Pressing the "enter" key will trigger a form submit
154
   * @param event  the event object passed in for Mozilla; IE uses window.event
155
   */
156
  this.handleKeyPress = function(event) {
157
    var keycode;
158
    var target;
159
    if (event){
160
      //Mozilla
161
      keycode=event.which;
162
      target=event.currentTarget;
163
    }else{
164
      //IE
165
      keycode=window.event.keyCode;
166
      target=window.event.srcElement.form;
167
    }
168

    
169
    if (keycode == 13) {    //enter key
170
      return true;
171
    }
172
  }
173

    
174
  var RUC_Window=null;
175
  this.openRucWindow = function( rucType ) { 
176
    if ( RUC_Window == null || RUC_Window.closed ) { 
177
      var baseUrl;
178
      var params;
179
      switch(rucType) {
180
        case "placename":
181
          baseURL = "/rucs/placeName.html?language=" + config.lang + "&formName=" + this.formName;
182
          params = "width=290,height=480,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0";
183
          break;
184
        case "postalCode":
185
          baseURL = "/rucs/postalCode.html?language=" + config.lang + "&formName=" + this.formName;
186
          params = "width=280,height=180,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0";
187
          break;
188
        default:
189
          alert("unkown RUC type");
190
          break;
191
      }
192
      RUC_Window = open( baseURL, "RUCWindow", params );
193
    }
194
    RUC_Window.focus();
195
    return false;
196
  } 
197
  function RUC_closeRUCWindow() { 
198
    if ( RUC_Window != null && !RUC_Window.closed ) { 
199
      RUC_Window.close();
200
    } 
201
  } 
202

    
203
  //set some properties for the form output
204
  this.formName = "WebServiceForm_" + mbIds.getId();
205
  this.stylesheet.setParameter("formName", this.formName);
206
}
207

    
208
  /**
209
   */
210
  SetAoiCoords = function(aoiBox) {
211
    config.objects.mainMap.setParam("aoi",aoiBox );
212
  }
213

    
(3-3/10)