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: AoiForm.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 AOI box coordinates in a 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 AoiForm(widgetNode, model) {
21
  WidgetBaseXSL.apply(this,new Array(widgetNode, model));
22

    
23
  /**
24
   * Output the AOI coordinates to the associated form input elements.  This
25
   * method is registered as an AOI listener on the context doc.
26
   * @param objRef Pointer to this AoiForm object.
27
   * @param targetNode The node for the enclosing HTML tag for this widget.
28
   */
29
  this.displayAoiCoords = function(objRef, targetNode) {
30
    var aoiForm = document.getElementById(objRef.formName);
31
    var aoi = objRef.model.getParam("aoi");
32
    if (aoi && aoiForm) {
33
      aoiForm.westCoord.value = aoi[0][0];
34
      aoiForm.northCoord.value = aoi[0][1];
35
      aoiForm.eastCoord.value = aoi[1][0];
36
      aoiForm.southCoord.value = aoi[1][1];
37
    }
38
  }
39
  this.model.addListener('aoi', this.displayAoiCoords, this);
40

    
41
  /**
42
   * Handles user input from the form element.  This is an onblur handler for 
43
   * the input elements.
44
   */
45
  this.setAoi = function() {
46
    var aoi = this.model.getParam("aoi");
47
    if (aoi) {
48
      var ul = aoi[0];
49
      var lr = aoi[1];
50
      switch(this.name) {
51
        case 'westCoord':
52
          ul[0] = this.value;
53
          break;
54
        case 'northCoord':
55
          ul[1] = this.value;
56
          break;
57
        case 'eastCoord':
58
          lr[0] = this.value;
59
          break;
60
        case 'southCoord':
61
          lr[1] = this.value;
62
          break;
63
      }
64
      this.model.setParam("aoi",new Array(ul,lr) );
65
    }
66
  }
67

    
68
  /**
69
   * Refreshes the form onblur handlers when this widget is painted.
70
   * @param objRef Pointer to this AoiForm object.
71
   */
72
  this.postPaint = function(objRef) {
73
    var aoiForm = document.getElementById(objRef.formName);
74
    aoiForm.westCoord.onblur = objRef.setAoi;
75
    aoiForm.northCoord.onblur = objRef.setAoi;
76
    aoiForm.eastCoord.onblur = objRef.setAoi;
77
    aoiForm.southCoord.onblur = objRef.setAoi;
78
    aoiForm.westCoord.model = objRef.model;
79
    aoiForm.northCoord.model = objRef.model;
80
    aoiForm.eastCoord.model = objRef.model;
81
    aoiForm.southCoord.model = objRef.model;
82
  }
83

    
84
  //set some properties for the form output
85
  //allow it to have a different form name
86
  this.formName = this.getProperty("mb:formName", "AoiForm_" + mbIds.getId());
87
  this.stylesheet.setParameter("formName", this.formName);
88
}
89

    
(7-7/145)