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: ModelUrlInput.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 a form to input any model's URL and load the new URL 
13
 * as the model's document
14
 *
15
 * @constructor
16
 * @base WidgetBaseXSL
17
 * @param widgetNode  This widget's object node from the configuration document.
18
 * @param model       The model that this widget is a view of.
19
 */
20

    
21
function ModelUrlInput(widgetNode, model) {
22
  WidgetBaseXSL.apply(this,new Array(widgetNode, model));
23

    
24
  //a default value to be used in the form
25
  this.defaultUrl = this.getProperty("mb:defaultUrl");
26

    
27
  /**
28
   * Handles submission of the form (via javascript in an <a> tag)
29
   */
30
  this.submitForm = function() {
31
    var httpPayload = new Object();
32
    httpPayload.url = this.urlInputForm.defaultUrl.value;
33
    httpPayload.method = this.targetModel.method;
34
/*
35
    for (var i=0; i<httpMethod.length; ++i) {   //loop through radio buttons
36
      if (httpMethod[i].checked) {
37
        httpPayload.method = httpMethod[i].value;
38
        if (httpPayload.method.toLowerCase() == "post") {
39
          httpPayload.postData = null; //TBD get this from somewhere? or not allow post?
40
          mbDebugMessage(this, "postData:"+httpPayload.postData.xml);
41
        } else {
42
          httpPayload.postData = null;
43
        }
44
        break;
45
      }
46
    }
47
*/    
48
    this.targetModel.newRequest(this.targetModel,httpPayload);
49
  }
50

    
51
  /**
52
   * handles keypress events to filter out everything except "enter".  
53
   * Pressing the "enter" key will trigger a form submit
54
   * @param event  the event object passed in for Mozilla; IE uses window.event
55
   */
56
  this.handleKeyPress = function(event) {
57
    var keycode;
58
    var target;
59
    if (event){
60
      //Mozilla
61
      keycode=event.which;
62
      target=event.currentTarget;
63
    }else{
64
      //IE
65
      keycode=window.event.keyCode;
66
      target=window.event.srcElement.form;
67
    }
68

    
69
    if (keycode == 13) {    //enter key
70
      target.parentWidget.submitForm();
71
    return false;   //prevent the form from actually being submitted
72
    }
73
  }
74

    
75
  /**
76
   * initializes stylesheet parameters for the form
77
   * @param objRef Pointer to this widget object.
78
   */
79
  this.prePaint = function(objRef) {
80
    objRef.stylesheet.setParameter("modelTitle", objRef.targetModel.title);
81
    if (!objRef.defaultUrl) objRef.defaultUrl = objRef.targetModel.url;
82
    objRef.stylesheet.setParameter("defaultUrl", objRef.defaultUrl);
83
  }
84

    
85
  /**
86
   * Refreshes the form and event handlers when this widget is painted.
87
   * @param objRef Pointer to this CurorTrack object.
88
   */
89
  this.postPaint = function(objRef) {
90
    objRef.urlInputForm = document.getElementById(objRef.formName);
91
    objRef.urlInputForm.parentWidget = objRef;
92
    objRef.urlInputForm.onkeypress = objRef.handleKeyPress;
93
    //objRef.WebServiceForm.onsubmit = objRef.submitForm;
94
    //objRef.WebServiceForm.mapsheet.onblur = objRef.setMapsheet;
95
  }
96

    
97
  //set some properties for the form output
98
  this.formName = "urlInputForm_" + mbIds.getId();
99
  this.stylesheet.setParameter("formName", this.formName);
100
}
101

    
(88-88/145)