Project

General

Profile

1
/*
2
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
3
$Id: Loading2.js 3879 2008-02-27 14:20:29Z gjvoosten $
4
*/
5

    
6
// Ensure this object's dependancies are loaded.
7
mapbuilder.loadScript(baseDir+"/widget/WidgetBase.js");
8

    
9
/**
10
 * This widget is used to display ModelStatus messages.  This widget is used
11
 * like any other except that it is clreaed on the loadModel event and painted
12
 * on the "newModel" and "modelStatus" events.
13
 * Optional config parameters are an image source (usually an animated GIF) in 
14
 * the imageSource property, an optional static text message to be displayed as 
15
 * the textMessage property and if the widget is to be displayed over top of a 
16
 * map you can also specify the mapContainerId property.
17
 * Dynamic message can be displayed by listening on the "modelStatus" event which
18
 * sends a message as the parameter.  Send a null message param to clear the widget.
19
 * @constructor
20
 * @base WidgetBase
21
 * @author Mike Adair
22
 * @param widgetNode The widget's XML object node from the configuration document.
23
 * @param model The model object that this widget belongs to.
24
 */
25
function Loading2(widgetNode, model) {
26
  WidgetBase.apply(this,new Array(widgetNode, model));
27

    
28
  //loading img to be displayed  while models load
29
  this.imageSrc = config.skinDir + this.getProperty("mb:imageSrc", "/images/Loading.gif");
30

    
31
  //a text message to be displayed while models load
32
  this.textMessage = this.getProperty("mb:textMessage", mbGetMessage("docLoading"));
33
  this.updateMessage = this.textMessage;
34

    
35
  //check to see if this is to be put over a map if there isa mapContainerID supplied
36
  this.mapContainerNode = widgetNode.selectSingleNode("mb:mapContainerId");
37
  if (!this.mapContainerNode) {
38
    this.mapContainerNode = widgetNode.selectSingleNode("mb:targetModel");
39
  }
40
  if (this.mapContainerNode) {
41
    this.containerNodeId = getNodeValue(this.mapContainerNode);
42
    this.htmlTagId = this.containerNodeId;
43
  }
44

    
45
  //paint it on the "newModel" event, clear it on "loadModel" event
46
  this.model.addListener("newModel",this.paint, this);
47
  this.model.addListener("loadModel",this.clear, this);
48
  this.model.addListener("refresh",this.paint, this);
49
  this.model.addListener("modelStatus",this.update, this);
50
}
51

    
52
/**
53
 * Render the widget.
54
 * @param objRef Pointer to widget object.
55
 */
56
Loading2.prototype.paint = function(objRef) {
57
  var node = objRef.getNode();
58
  if (node) {
59
    //if it is a template model, no loader should be shown in the output div
60
    if (objRef.model.template) return;
61
    //if there's no url, there will never be an update on the ModelStatus, so the image stays while nothing is happening.
62
    if (!objRef.model.url && !objRef.mapContainerNode) return;
63
    //create the output node the first time this is called
64
    var outputNode = document.getElementById( objRef.outputNodeId+"_loading" );
65
    if (!outputNode) {
66
      outputNode = document.createElement("div");
67
      outputNode.setAttribute("id",objRef.outputNodeId+"_loading");
68
      node.appendChild(outputNode);
69
    }
70
    outputNode.className = "loadingIndicator";
71
    outputNode.style.zIndex = 10001;
72
    //In a mapcontainer you want the loader in the left top, in other widgets embedded in the output area
73
    if (objRef.mapContainerNode){
74
      outputNode.style.position="absolute";
75
      outputNode.style.left='0px';
76
      outputNode.style.top='0px';
77
    }
78
    if (objRef.imageSrc) {
79
      var imageNode = document.getElementById( objRef.outputNodeId+"_imageNode" );
80
      if (!imageNode) {
81
        imageNode = document.createElement("img");
82
        imageNode.setAttribute("id",objRef.outputNodeId+"_imageNode");
83
        outputNode.appendChild(imageNode);
84
        imageNode.style.zIndex = 10001;
85
      }
86
      imageNode.src = objRef.imageSrc;
87
    }
88
    if (objRef.updateMessage) {
89
      var messageNode = document.getElementById( objRef.outputNodeId+"_messageNode" );
90
      if (!messageNode) {
91
        messageNode = document.createElement("p");
92
        messageNode.setAttribute("id",objRef.outputNodeId+"_messageNode");
93
        outputNode.appendChild(messageNode);
94
      }
95
      messageNode.innerHTML = objRef.updateMessage;
96
    }
97
  }
98
}
99

    
100
/**
101
 * Remove the contents of the HTML tag for this widget.
102
 * @param objRef Reference to this object.
103
 */
104
Loading2.prototype.clear= function(objRef, message) {
105
  var outputNode = document.getElementById( objRef.outputNodeId+"_loading" );
106
  var node = objRef.getNode();
107
  if (node && outputNode) node.removeChild(outputNode);
108
}
109

    
110
/**
111
 * Updates the loading indicator with a new message as a "updateStatus" listener.
112
 * Send an null message to clear the loading indicator.
113
 * @param objRef Reference to this object.
114
 */
115
Loading2.prototype.update= function(objRef, message) {
116
  objRef.updateMessage = message || null;
117
  if (message) {
118
    objRef.paint(objRef);
119
  } else {
120
    objRef.clear(objRef);
121
  }
122
}
123

    
(70-70/145)