1
|
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
|
2
|
<html>
|
3
|
<head>
|
4
|
<title>
|
5
|
<a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008 Overview
|
6
|
</title>
|
7
|
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
|
8
|
<script>
|
9
|
function asd() {
|
10
|
|
11
|
parent.document.title="ModelBase.js Overview";
|
12
|
|
13
|
}
|
14
|
</script>
|
15
|
</head>
|
16
|
<body bgcolor="white" onload="asd();">
|
17
|
|
18
|
<!-- ========== START OF NAVBAR ========== -->
|
19
|
<a name="navbar_top"><!-- --></a>
|
20
|
<table border="0" width="100%" cellpadding="1" cellspacing="0">
|
21
|
<tr>
|
22
|
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
|
23
|
<a name="navbar_top_firstrow"><!-- --></a>
|
24
|
<table border="0" cellpadding="0" cellspacing="3">
|
25
|
<tr align="center" valign="top">
|
26
|
|
27
|
|
28
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td>
|
29
|
<td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td>
|
30
|
|
31
|
|
32
|
<td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td>
|
33
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td>
|
34
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td>
|
35
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td>
|
36
|
</tr>
|
37
|
</table>
|
38
|
</td>
|
39
|
<td bgcolor="#EEEEFF" align="right" valign="top">
|
40
|
<em>
|
41
|
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
|
42
|
</td>
|
43
|
</tr>
|
44
|
|
45
|
<tr>
|
46
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
47
|
PREV
|
48
|
NEXT</font></td>
|
49
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
50
|
<a href="index.html" target="_top"><b>FRAMES</b></a>
|
51
|
<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
|
52
|
|
53
|
<script>
|
54
|
<!--
|
55
|
if(window==top) {
|
56
|
document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
|
57
|
}
|
58
|
//-->
|
59
|
</script>
|
60
|
<noscript>
|
61
|
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
|
62
|
</noscript>
|
63
|
</font></td>
|
64
|
</tr>
|
65
|
</table>
|
66
|
<!-- =========== END OF NAVBAR =========== -->
|
67
|
|
68
|
<hr>
|
69
|
<center>
|
70
|
|
71
|
<h2>ModelBase.js</h2>
|
72
|
|
73
|
</center>
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
<h4>Summary</h4>
|
79
|
<p>
|
80
|
|
81
|
No overview generated for 'ModelBase.js'<BR/><BR/>
|
82
|
|
83
|
</p>
|
84
|
|
85
|
<hr>
|
86
|
|
87
|
|
88
|
<table border="1" cellpadding="3" cellspacing="0" width="100%">
|
89
|
<tr bgcolor="#CCCCFF" class="TableHeadingColor">
|
90
|
<td colspan=2><font size="+2">
|
91
|
|
92
|
<b>Class Summary</b>
|
93
|
|
94
|
</font></td>
|
95
|
</tr>
|
96
|
|
97
|
<tr bgcolor="white" class="TableRowColor">
|
98
|
<td width="15%"><b><a href="ModelBase.html">ModelBase</a></b></td>
|
99
|
<td> </td>
|
100
|
</tr>
|
101
|
|
102
|
</table>
|
103
|
<hr/>
|
104
|
|
105
|
|
106
|
<!-- ========== METHOD SUMMARY =========== -->
|
107
|
|
108
|
<!-- ========== END METHOD SUMMARY =========== -->
|
109
|
|
110
|
|
111
|
<pre class="sourceview"><span class="comment">/*
|
112
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
113
|
$Id: ModelBase.js 3953 2008-03-31 10:25:24Z oterral $
|
114
|
*/</span>
|
115
|
<span class="comment">
|
116
|
// Ensure this object's dependancies are loaded.</span>
|
117
|
mapbuilder.loadScript(baseDir+<span class="literal">"/util/Listener.js"</span>);
|
118
|
|
119
|
<span class="comment">/**
|
120
|
* Base Model class to be inherited by all Model objects and provdes methods
|
121
|
* and properties common to all models.
|
122
|
* Stores the XML document as the .doc property of the model.
|
123
|
* Inherits from the Listener class so all models are also listener objects that
|
124
|
* can call registered listeners.
|
125
|
* <span class="attrib">@constructor</span>
|
126
|
* <span class="attrib">@base</span> Listener
|
127
|
* <span class="attrib">@author</span> Cameron Shorter
|
128
|
* <span class="attrib">@param</span> modelNode The model's XML object node from the configuration document.
|
129
|
* <span class="attrib">@param</span> parentModel The model object that this model belongs to.
|
130
|
*/</span>
|
131
|
<span class="reserved">function</span> ModelBase(modelNode, parentModel) {
|
132
|
<span class="comment"> // Inherit the Listener functions and parameters</span>
|
133
|
Listener.apply(<span class="reserved">this</span>);
|
134
|
<span class="comment">
|
135
|
//models are loaded asynchronously by default; </span>
|
136
|
<span class="reserved">this</span>.async = true; //change to false <span class="reserved">for</span> sync loading
|
137
|
<span class="reserved">this</span>.contentType = <span class="literal">"text/xml"</span>;
|
138
|
|
139
|
<span class="reserved">this</span>.modelNode = modelNode;
|
140
|
var idAttr = modelNode.attributes.getNamedItem(<span class="literal">"id"</span>);
|
141
|
<span class="reserved">if</span> (idAttr) {
|
142
|
<span class="reserved">this</span>.id = idAttr.nodeValue;
|
143
|
} <span class="reserved">else</span> {
|
144
|
<span class="comment"> //auto generated unique ID assigned to this model</span>
|
145
|
<span class="reserved">this</span>.id = <span class="literal">"MbModel_"</span> + mbIds.getId();
|
146
|
}
|
147
|
|
148
|
<span class="comment">/**
|
149
|
* Convenient access to Mapbuilder.getProperty
|
150
|
* <span class="attrib">@param</span> property property to get
|
151
|
* <span class="attrib">@param</span> default value to use if property is not set
|
152
|
* <span class="attrib">@return</span> the value for the property
|
153
|
*/</span>
|
154
|
<span class="reserved">this</span>.getProperty = <span class="reserved">function</span>(property, defaultValue) {
|
155
|
<span class="reserved">return</span> Mapbuilder.getProperty(modelNode, property, defaultValue);
|
156
|
}
|
157
|
<span class="comment">
|
158
|
//get the human readable title for the model</span>
|
159
|
<span class="reserved">this</span>.title = <span class="reserved">this</span>.getProperty(<span class="literal">"mb:title"</span>, <span class="reserved">this</span>.id);
|
160
|
<span class="comment">
|
161
|
//set a debug property in config to see alerts for a particular model</span>
|
162
|
<span class="reserved">this</span>.debug = Mapbuilder.parseBoolean(<span class="reserved">this</span>.getProperty(<span class="literal">"mb:debug"</span>, false));
|
163
|
|
164
|
<span class="comment">/**
|
165
|
* set the initial model URL in config.
|
166
|
* the URL can also be passed in as a URL parameter by using the model ID
|
167
|
* as the parameter name (which takes precendence over the config file)
|
168
|
**/</span>
|
169
|
<span class="reserved">if</span> (window.cgiArgs[<span class="reserved">this</span>.id]) {
|
170
|
<span class="reserved">this</span>.url = window.cgiArgs[<span class="reserved">this</span>.id];
|
171
|
} <span class="reserved">else</span> <span class="reserved">if</span> (window[<span class="reserved">this</span>.id] && typeof window[<span class="reserved">this</span>.id] == <span class="literal">"string"</span>) {
|
172
|
<span class="reserved">this</span>.url = window[<span class="reserved">this</span>.id];
|
173
|
} <span class="reserved">else</span> <span class="reserved">if</span> (modelNode.url) {
|
174
|
<span class="reserved">this</span>.url = modelNode.url;
|
175
|
} <span class="reserved">else</span> {
|
176
|
var defaultModel = modelNode.selectSingleNode(<span class="literal">"mb:defaultModelUrl"</span>);
|
177
|
<span class="reserved">if</span> (defaultModel) <span class="reserved">this</span>.url = getNodeValue(defaultModel);
|
178
|
}
|
179
|
<span class="comment">
|
180
|
//set the method property</span>
|
181
|
<span class="reserved">this</span>.method = <span class="reserved">this</span>.getProperty(<span class="literal">"mb:method"</span>, <span class="literal">"get"</span>);
|
182
|
<span class="comment">
|
183
|
//set the namespace property</span>
|
184
|
<span class="reserved">this</span>.namespace = <span class="reserved">this</span>.getProperty(<span class="literal">"mb:namespace"</span>);
|
185
|
|
186
|
var templateAttr = modelNode.attributes.getNamedItem(<span class="literal">"template"</span>);
|
187
|
<span class="reserved">if</span> (templateAttr) {
|
188
|
<span class="reserved">this</span>.template = Mapbuilder.parseBoolean(templateAttr.nodeValue);
|
189
|
<span class="reserved">this</span>.modelNode.removeAttribute(<span class="literal">"template"</span>);
|
190
|
}
|
191
|
<span class="comment">
|
192
|
//get the xpath to select nodes from the parent doc</span>
|
193
|
<span class="reserved">this</span>.nodeSelectXpath = <span class="reserved">this</span>.getProperty(<span class="literal">"mb:nodeSelectXpath"</span>);
|
194
|
|
195
|
<span class="comment">/**
|
196
|
* Widgets can place configurations in a model. This is an associative
|
197
|
* array with the widgetId of the widget that places its configuration
|
198
|
* here as key.
|
199
|
*/</span>
|
200
|
<span class="reserved">this</span>.config = new Array();
|
201
|
|
202
|
<span class="comment">/**
|
203
|
* Get the value of a node as selected by an XPath expression.1
|
204
|
* <span class="attrib">@param</span> objRef Reference to this node.
|
205
|
* <span class="attrib">@param</span> xpath XPath of the node to update.
|
206
|
* <span class="attrib">@return</span> value of the node or null if XPath does not find a node.
|
207
|
*/</span>
|
208
|
<span class="reserved">this</span>.getXpathValue=<span class="reserved">function</span>(objRef,xpath){
|
209
|
<span class="reserved">if</span> (!objRef.doc) <span class="reserved">return</span> null;
|
210
|
node=objRef.doc.selectSingleNode(xpath);
|
211
|
<span class="reserved">if</span>(node && node.firstChild){
|
212
|
<span class="reserved">return</span> getNodeValue(node);
|
213
|
}<span class="reserved">else</span>{
|
214
|
<span class="reserved">return</span> null;
|
215
|
}
|
216
|
}
|
217
|
|
218
|
<span class="comment">/**
|
219
|
* Update the value of a node within this model's XML document.
|
220
|
* Triggers a refresh event from the model.
|
221
|
* <span class="attrib">@param</span> objRef Reference to this node.
|
222
|
* <span class="attrib">@param</span> xpath Xpath of the node to update.
|
223
|
* <span class="attrib">@param</span> value Node's new value.
|
224
|
* <span class="attrib">@param</span> refresh determines if the model should be refreshed (optional).
|
225
|
* <span class="attrib">@return</span> Returns false if Xpath does not find a node.
|
226
|
*/</span>
|
227
|
<span class="reserved">this</span>.setXpathValue=<span class="reserved">function</span>(objRef,xpath,value,refresh){
|
228
|
<span class="reserved">if</span> (refresh==null) refresh=true;
|
229
|
var node=objRef.doc.selectSingleNode(xpath);
|
230
|
<span class="reserved">if</span>(node){
|
231
|
<span class="reserved">if</span>(node.firstChild){
|
232
|
node.firstChild.nodeValue=value;
|
233
|
}<span class="reserved">else</span>{
|
234
|
dom=Sarissa.getDomDocument();
|
235
|
v=dom.createTextNode(value);
|
236
|
node.appendChild(v);
|
237
|
}
|
238
|
<span class="reserved">if</span> (refresh) objRef.setParam(<span class="literal">"refresh"</span>);
|
239
|
<span class="reserved">return</span> true;
|
240
|
}<span class="reserved">else</span>{
|
241
|
<span class="reserved">return</span> false;
|
242
|
}
|
243
|
}
|
244
|
|
245
|
<span class="comment">/**
|
246
|
* Load a Model's document.
|
247
|
* This will only occur if the model.url property is set.
|
248
|
* Calling this method triggers several events:
|
249
|
* modelStatus - to indicate that the model state is changing
|
250
|
* newModel - to give widgets a chance to clear themselves before the doc is loaded
|
251
|
* loadModel - to indicate that the document is loaded successfully
|
252
|
*
|
253
|
* <span class="attrib">@param</span> objRef Pointer to the model object being loaded.
|
254
|
*/</span>
|
255
|
<span class="reserved">this</span>.loadModelDoc = <span class="reserved">function</span>(objRef){
|
256
|
<span class="comment"> //alert("loading:"+objRef.url);</span>
|
257
|
|
258
|
<span class="reserved">if</span> (objRef.url) {
|
259
|
objRef.callListeners( <span class="literal">"newModel"</span> );
|
260
|
objRef.setParam(<span class="literal">"modelStatus"</span>,<span class="literal">"loading"</span>);
|
261
|
|
262
|
<span class="reserved">if</span> (objRef.contentType == <span class="literal">"image"</span>) {
|
263
|
<span class="comment"> //image models are set as a DOM image object</span>
|
264
|
objRef.doc = new Image();
|
265
|
objRef.doc.src = objRef.url;
|
266
|
<span class="comment"> //objRef.doc.onload = callback //TBD: for when image is loaded</span>
|
267
|
|
268
|
} <span class="reserved">else</span> {
|
269
|
<span class="comment"> //XML content type</span>
|
270
|
var xmlHttp = new XMLHttpRequest();
|
271
|
|
272
|
var sUri = objRef.url;
|
273
|
<span class="reserved">if</span> ( sUri.indexOf(<span class="literal">"http://"</span>)==0 || sUri.indexOf(<span class="literal">"https://"</span>)==0) {
|
274
|
<span class="reserved">if</span> (objRef.method.toLowerCase() == <span class="literal">"get"</span>) {
|
275
|
sUri = getProxyPlusUrl(sUri);
|
276
|
} <span class="reserved">else</span> {
|
277
|
sUri = config.proxyUrl;
|
278
|
}
|
279
|
}
|
280
|
<span class="comment"> //alert( "ModelBase:"+objRef.method + " to:"+ sUri+ " " + objRef.url)</span>
|
281
|
|
282
|
xmlHttp.open(objRef.method, sUri, objRef.async);
|
283
|
<span class="reserved">if</span> (objRef.method.toLowerCase() == <span class="literal">"post"</span>) {
|
284
|
xmlHttp.setRequestHeader(<span class="literal">"content-type"</span>,objRef.contentType);
|
285
|
xmlHttp.setRequestHeader(<span class="literal">"serverUrl"</span>,objRef.url);
|
286
|
}
|
287
|
|
288
|
xmlHttp.onreadystatechange = <span class="reserved">function</span>() {
|
289
|
objRef.setParam(<span class="literal">"modelStatus"</span>,httpStatusMsg[xmlHttp.readyState]);
|
290
|
<span class="reserved">if</span> (xmlHttp.readyState==4) {
|
291
|
<span class="reserved">if</span> (xmlHttp.status >= 400) { //http errors status start at 400
|
292
|
var errorMsg = mbGetMessage(<span class="literal">"errorLoadingDocument"</span>, sUri, xmlHttp.statusText, xmlHttp.responseText);
|
293
|
alert(errorMsg);
|
294
|
objRef.setParam(<span class="literal">"modelStatus"</span>,errorMsg);
|
295
|
<span class="reserved">return</span>;
|
296
|
} <span class="reserved">else</span> {
|
297
|
<span class="comment"> //alert(xmlHttp.getResponseHeader("Content-Type"));</span>
|
298
|
<span class="comment"> //if ( null==xmlHttp.responseXML ) {</span>
|
299
|
<span class="comment"> // alert( "null XML response:" + xmlHttp.responseText );</span>
|
300
|
<span class="comment"> //} else {</span>
|
301
|
<span class="comment"> // Problem with IE is that sometimes the XML files do not get loaded as XML for some reason (especially from disk)</span>
|
302
|
<span class="comment"> // So we need to deal with it here</span>
|
303
|
|
304
|
<span class="reserved">if</span>( (xmlHttp.responseXML != null) && (xmlHttp.responseXML.root != null) && (xmlHttp.responseXML.root.children.length>0) ) {
|
305
|
objRef.doc = xmlHttp.responseXML;
|
306
|
<span class="reserved">if</span>( Sarissa.getParseErrorText(objRef.doc) == Sarissa.PARSED_OK ) {
|
307
|
objRef.finishLoading();
|
308
|
} <span class="reserved">else</span> {
|
309
|
alert(mbGetMessage(<span class="literal">"parseError"</span>, Sarissa.getParseErrorText(objRef.doc)));
|
310
|
}
|
311
|
<span class="reserved">return</span>;
|
312
|
}
|
313
|
|
314
|
<span class="reserved">if</span>( xmlHttp.responseText != null ) {
|
315
|
<span class="comment"> // if that's the case, the xml file is in the responseText</span>
|
316
|
<span class="comment"> // we have to load it manually </span>
|
317
|
objRef.doc = Sarissa.getDomDocument();
|
318
|
objRef.doc.async = false;
|
319
|
objRef.doc = (new DOMParser()).parseFromString( xmlHttp.responseText.replace(/>\s+</g, <span class="literal">"><"</span>), <span class="literal">"text/xml"</span>)
|
320
|
<span class="reserved">if</span>( objRef.doc == null ) {
|
321
|
alert(mbGetMessage(<span class="literal">"documentParseError"</span>, Sarissa.getParseErrorText(objRef.doc)));
|
322
|
<span class="comment"> // debugger;</span>
|
323
|
} <span class="reserved">else</span> {
|
324
|
<span class="reserved">if</span>( Sarissa.getParseErrorText(objRef.doc) == Sarissa.PARSED_OK ) {
|
325
|
objRef.finishLoading();
|
326
|
} <span class="reserved">else</span> {
|
327
|
alert(mbGetMessage(<span class="literal">"parseError"</span>, Sarissa.getParseErrorText(objRef.doc)));
|
328
|
}
|
329
|
}
|
330
|
<span class="reserved">return</span>;
|
331
|
}
|
332
|
<span class="comment"> //if (objRef.doc.documentElement.nodeName.search(/exception/i)>=0) {</span>
|
333
|
<span class="comment"> // objRef.setParam("modelStatus",-1);</span>
|
334
|
<span class="comment"> // alert("Exception:"+(new XMLSerializer()).serializeToString(xmlHttp.responseText));</span>
|
335
|
<span class="comment"> //}</span>
|
336
|
<span class="comment"> //}</span>
|
337
|
<span class="comment"> //objRef.finishLoading();</span>
|
338
|
}
|
339
|
}
|
340
|
}
|
341
|
|
342
|
var postData = objRef.postData || <span class="literal">""</span>;
|
343
|
<span class="reserved">if</span> (typeof postData == <span class="literal">"object"</span>) {
|
344
|
postData = new XMLSerializer().serializeToString(postData);
|
345
|
}
|
346
|
xmlHttp.send(postData);
|
347
|
|
348
|
<span class="reserved">if</span> (!objRef.async) {
|
349
|
<span class="reserved">if</span> (xmlHttp.status >= 400) { //http errors status start at 400
|
350
|
var errorMsg = mbGetMessage(<span class="literal">"errorLoadingDocument"</span>, sUri, xmlHttp.statusText, xmlHttp.responseText);
|
351
|
alert(errorMsg);
|
352
|
<span class="reserved">this</span>.objRef.setParam(<span class="literal">"modelStatus"</span>,errorMsg);
|
353
|
<span class="reserved">return</span>;
|
354
|
} <span class="reserved">else</span> {
|
355
|
<span class="comment"> //alert(xmlHttp.getResponseHeader("Content-Type"));</span>
|
356
|
<span class="reserved">if</span> ( null==xmlHttp.responseXML ) alert(mbGetMessage(<span class="literal">"nullXmlResponse"</span>, xmlHttp.responseText));
|
357
|
objRef.doc = xmlHttp.responseXML;
|
358
|
objRef.finishLoading();
|
359
|
}
|
360
|
}
|
361
|
<span class="comment">
|
362
|
//objRef.doc.validateOnParse=false; //IE6 SP2 parsing bug</span>
|
363
|
}
|
364
|
}
|
365
|
}
|
366
|
<span class="reserved">this</span>.addListener(<span class="literal">"reloadModel"</span>,<span class="reserved">this</span>.loadModelDoc, <span class="reserved">this</span>);
|
367
|
|
368
|
<span class="comment">/**
|
369
|
* Set the model's XML document using an XML object as a parameter.
|
370
|
* <span class="attrib">@param</span> objRef Pointer to this object.
|
371
|
* <span class="attrib">@param</span> newModel XML object to be inserted into the new model.
|
372
|
*/</span>
|
373
|
<span class="reserved">this</span>.setModel=<span class="reserved">function</span>(objRef,newModel){
|
374
|
objRef.callListeners(<span class="literal">"newModel"</span>);
|
375
|
objRef.doc=newModel;
|
376
|
<span class="reserved">if</span> ((newModel == null) && objRef.url) {
|
377
|
objRef.url = null;
|
378
|
}
|
379
|
objRef.finishLoading();
|
380
|
}
|
381
|
|
382
|
<span class="comment">/**
|
383
|
* Common steps to be carried out after all manner of model loading
|
384
|
* Called to set the namespace for XPath selections and call the loadModel
|
385
|
* listeners.
|
386
|
*/</span>
|
387
|
<span class="reserved">this</span>.finishLoading = <span class="reserved">function</span>() {
|
388
|
<span class="comment"> // the following two lines are needed for IE; set the namespace for selection</span>
|
389
|
<span class="reserved">if</span>(<span class="reserved">this</span>.doc){
|
390
|
<span class="reserved">if</span>(! _SARISSA_IS_SAFARI){
|
391
|
<span class="reserved">this</span>.doc.setProperty(<span class="literal">"SelectionLanguage"</span>, <span class="literal">"XPath"</span>);
|
392
|
<span class="reserved">if</span>(<span class="reserved">this</span>.namespace) Sarissa.setXpathNamespaces(<span class="reserved">this</span>.doc, <span class="reserved">this</span>.namespace);
|
393
|
}
|
394
|
<span class="comment">
|
395
|
// Show the newly loaded XML document</span>
|
396
|
<span class="reserved">if</span>(<span class="reserved">this</span>.debug) mbDebugMessage(<span class="reserved">this</span>, <span class="literal">"Loading Model:"</span>+<span class="reserved">this</span>.id+<span class="literal">" "</span>+(new XMLSerializer()).serializeToString(<span class="reserved">this</span>.doc));
|
397
|
|
398
|
<span class="reserved">this</span>.callListeners(<span class="literal">"loadModel"</span>);
|
399
|
}
|
400
|
}
|
401
|
|
402
|
<span class="comment">/**
|
403
|
* Load XML for a model from an httpPayload object. This will also handle
|
404
|
* instantiating template models if they have the "template" attribute set.
|
405
|
* To update model data, use:<br/>
|
406
|
* httpPayload=new Object();<br/>
|
407
|
* httpPayload.url="url" or null. If set to null, all dependant widgets
|
408
|
* will be removed from the display.<br/>
|
409
|
* httpPayload.httpMethod="post" or "get"<br/>
|
410
|
* httpPayload.postData=XML or null<br/>
|
411
|
* <span class="attrib">@param</span> objRef Pointer to the model object being loaded.
|
412
|
* <span class="attrib">@param</span> httpPayload an object to fully specify the request to be made
|
413
|
*/</span>
|
414
|
<span class="reserved">this</span>.newRequest = <span class="reserved">function</span>(objRef, httpPayload){
|
415
|
var model = objRef;
|
416
|
<span class="comment"> // if the targetModel is a template model, then create new model object and</span>
|
417
|
<span class="comment"> // assign it an id</span>
|
418
|
<span class="reserved">if</span> (objRef.template) {
|
419
|
var parentNode = objRef.modelNode.parentNode;
|
420
|
<span class="reserved">if</span>(_SARISSA_IS_IE) {
|
421
|
var newConfigNode = parentNode.appendChild(modelNode.cloneNode(true));
|
422
|
}
|
423
|
<span class="reserved">else</span> {
|
424
|
var newConfigNode = parentNode.appendChild(objRef.modelNode.ownerDocument.importNode(objRef.modelNode,true));
|
425
|
}
|
426
|
newConfigNode.removeAttribute(<span class="literal">"id"</span>); //<span class="reserved">this</span> will get created automatically
|
427
|
newConfigNode.setAttribute(<span class="literal">"createByTemplate"</span>,<span class="literal">"true"</span>);
|
428
|
<span class="comment"> //set defaultModelUrl config properties</span>
|
429
|
model = objRef.createObject(newConfigNode);
|
430
|
model.callListeners(<span class="literal">"init"</span>);
|
431
|
<span class="reserved">if</span> (!objRef.templates) objRef.templates = new Array();
|
432
|
objRef.templates.push(model);
|
433
|
}
|
434
|
<span class="comment">
|
435
|
//set the payload in the model and issue the request</span>
|
436
|
model.url = httpPayload.url;
|
437
|
<span class="reserved">if</span> (!model.url) model.doc=null;
|
438
|
model.method = httpPayload.method;
|
439
|
model.postData = httpPayload.postData;
|
440
|
model.loadModelDoc(model);
|
441
|
}
|
442
|
|
443
|
<span class="comment">/**
|
444
|
* deletes all template models and clears their widgets
|
445
|
*/</span>
|
446
|
<span class="reserved">this</span>.deleteTemplates = <span class="reserved">function</span>() {
|
447
|
<span class="reserved">if</span> (<span class="reserved">this</span>.templates) {
|
448
|
var model;
|
449
|
<span class="reserved">while</span>( model=<span class="reserved">this</span>.templates.pop() ) {
|
450
|
model.setParam(<span class="literal">"newModel"</span>);
|
451
|
var parentNode = <span class="reserved">this</span>.modelNode.parentNode;
|
452
|
parentNode.removeChild(model.modelNode);
|
453
|
}
|
454
|
}
|
455
|
}
|
456
|
<span class="comment">/**
|
457
|
* save the model by posting it to the serializeUrl, which is defined as a
|
458
|
* property of config.
|
459
|
* <span class="attrib">@param</span> objRef Pointer to this object.
|
460
|
*/</span>
|
461
|
<span class="reserved">this</span>.saveModel = <span class="reserved">function</span>(objRef) {
|
462
|
<span class="reserved">if</span> (config.serializeUrl) {
|
463
|
var response = postGetLoad(config.serializeUrl, objRef.doc ,<span class="literal">"text/xml"</span>,<span class="literal">""</span>,<span class="literal">""</span>);
|
464
|
<span class="reserved">if</span>(! _SARISSA_IS_SAFARI){
|
465
|
response.setProperty(<span class="literal">"SelectionLanguage"</span>, <span class="literal">"XPath"</span>);
|
466
|
Sarissa.setXpathNamespaces(response, <span class="literal">"xmlns:xlink='http://www.w3.org/1999/xlink'"</span>);
|
467
|
}
|
468
|
var onlineResource = response.selectSingleNode(<span class="literal">"//OnlineResource"</span>);
|
469
|
var fileUrl = onlineResource.attributes.getNamedItem(<span class="literal">"xlink:href"</span>).nodeValue;
|
470
|
objRef.setParam(<span class="literal">"modelSaved"</span>, fileUrl);
|
471
|
} <span class="reserved">else</span> {
|
472
|
alert(mbGetMessage(<span class="literal">"noSerializeUrl"</span>));
|
473
|
}
|
474
|
}
|
475
|
|
476
|
<span class="comment">/**
|
477
|
* Creates all mapbuilder JavaScript objects based on the Object nodes defined
|
478
|
* in the configuration file.
|
479
|
* A reference to the created model is stored as a property of the config.objects
|
480
|
* property using the model's ID; you can always get a reference to a mapbuilder
|
481
|
* object as: "config.objects.objectId"
|
482
|
* <span class="attrib">@param</span> configNode The node from config for the model to be created
|
483
|
*/</span>
|
484
|
<span class="reserved">this</span>.createObject = <span class="reserved">function</span>(configNode) {
|
485
|
var objectType = configNode.nodeName;
|
486
|
<span class="comment"> //var evalStr = "new " + objectType + "(configNode,this);";</span>
|
487
|
<span class="comment"> //var newObject = eval( evalStr );</span>
|
488
|
<span class="comment"> //hint from Alex Russel alex<span class="attrib">@dojotoolkit</span>.org so we can compress it</span>
|
489
|
<span class="comment">
|
490
|
// If model/tool/widget doesn't exist, exit</span>
|
491
|
<span class="reserved">if</span> (!window[objectType]) {
|
492
|
alert(mbGetMessage(<span class="literal">"errorCreatingObject"</span>, objectType));
|
493
|
<span class="reserved">return</span> false;
|
494
|
}
|
495
|
|
496
|
var newObject = new window[objectType](configNode, <span class="reserved">this</span>);
|
497
|
<span class="reserved">if</span> (newObject) {
|
498
|
config.objects[newObject.id] = newObject;
|
499
|
<span class="reserved">return</span> newObject;
|
500
|
} <span class="reserved">else</span> {
|
501
|
alert(mbGetMessage(<span class="literal">"errorCreatingObject"</span>, objectType));
|
502
|
}
|
503
|
}
|
504
|
|
505
|
<span class="comment">/**
|
506
|
* Creates all the mapbuilder objects from the config file as selected by the
|
507
|
* XPath value passed in.
|
508
|
* <span class="attrib">@param</span> objectXpath The XPath for the set of nodes being created
|
509
|
*/</span>
|
510
|
<span class="reserved">this</span>.loadObjects = <span class="reserved">function</span>(objectXpath) {
|
511
|
<span class="comment"> //loop through all nodes selected from config</span>
|
512
|
var configObjects = <span class="reserved">this</span>.modelNode.selectNodes( objectXpath );
|
513
|
<span class="reserved">for</span> (var i=0; i<configObjects.length; i++ ) {
|
514
|
<span class="reserved">if</span>(configObjects[i].nodeName != <span class="literal">"#text"</span> && configObjects[i].nodeName != <span class="literal">"#comment"</span> )
|
515
|
{
|
516
|
<span class="reserved">this</span>.createObject( configObjects[i]);
|
517
|
}
|
518
|
}
|
519
|
}
|
520
|
|
521
|
<span class="comment">/**
|
522
|
* Initialization of all javascript model, widget and tool objects for this model.
|
523
|
* Calling this method triggers an init event for this model.
|
524
|
* <span class="attrib">@param</span> objRef Pointer to this object.
|
525
|
*/</span>
|
526
|
<span class="reserved">this</span>.parseConfig = <span class="reserved">function</span>(objRef) {
|
527
|
objRef.loadObjects(<span class="literal">"mb:widgets/*"</span>);
|
528
|
objRef.loadObjects(<span class="literal">"mb:tools/*"</span>);
|
529
|
objRef.loadObjects(<span class="literal">"mb:models/*"</span>);
|
530
|
}
|
531
|
|
532
|
<span class="comment">/**
|
533
|
* Listener registered with the parent model to call refresh listeners when
|
534
|
* the model document is loaded
|
535
|
* <span class="attrib">@param</span> objRef Pointer to this object.
|
536
|
*/</span>
|
537
|
<span class="reserved">this</span>.refresh = <span class="reserved">function</span>(objRef) {
|
538
|
objRef.setParam(<span class="literal">"refresh"</span>);
|
539
|
}
|
540
|
<span class="reserved">this</span>.addListener(<span class="literal">"loadModel"</span>,<span class="reserved">this</span>.refresh, <span class="reserved">this</span>);
|
541
|
|
542
|
<span class="comment">/**
|
543
|
* Listener registered with the parent model to call init listeners when
|
544
|
* the parent model is init'ed
|
545
|
* <span class="attrib">@param</span> objRef Pointer to this object.
|
546
|
*/</span>
|
547
|
<span class="reserved">this</span>.init = <span class="reserved">function</span>(objRef) {
|
548
|
objRef.callListeners(<span class="literal">"init"</span>);
|
549
|
}
|
550
|
|
551
|
<span class="comment">/**
|
552
|
* Listener registered with the parent model to remove the doc and url
|
553
|
* of child models whenever the parent is reloaded.
|
554
|
* <span class="attrib">@param</span> objRef Pointer to this object.
|
555
|
*/</span>
|
556
|
<span class="reserved">this</span>.clearModel = <span class="reserved">function</span>(objRef) {
|
557
|
objRef.doc=null;
|
558
|
<span class="comment"> //objRef.url=null;</span>
|
559
|
}
|
560
|
<span class="comment">
|
561
|
//don't load in models and widgets if this is the config doc, </span>
|
562
|
<span class="comment"> //defer that to an explcit config.init() call in mapbuilder.js</span>
|
563
|
<span class="reserved">if</span> (parentModel) {
|
564
|
<span class="reserved">this</span>.parentModel = parentModel;
|
565
|
<span class="reserved">this</span>.parentModel.addListener(<span class="literal">"init"</span>,<span class="reserved">this</span>.init, <span class="reserved">this</span>);
|
566
|
<span class="reserved">this</span>.parentModel.addListener(<span class="literal">"loadModel"</span>,<span class="reserved">this</span>.loadModelDoc, <span class="reserved">this</span>);
|
567
|
<span class="reserved">this</span>.parentModel.addListener(<span class="literal">"newModel"</span>, <span class="reserved">this</span>.clearModel, <span class="reserved">this</span>);
|
568
|
<span class="reserved">this</span>.parseConfig(<span class="reserved">this</span>);
|
569
|
}
|
570
|
}
|
571
|
<span class="comment">
|
572
|
//ModelBase.prototype.httpStatusMsg = ['uninitialized','loading','loaded','interactive','completed'];</span>
|
573
|
var httpStatusMsg = [<span class="literal">'uninitialized'</span>,<span class="literal">'loading'</span>,<span class="literal">'loaded'</span>,<span class="literal">'interactive'</span>,<span class="literal">'completed'</span>];
|
574
|
</pre>
|
575
|
<hr>
|
576
|
|
577
|
|
578
|
|
579
|
<!-- ========== START OF NAVBAR ========== -->
|
580
|
<a name="navbar_top"><!-- --></a>
|
581
|
<table border="0" width="100%" cellpadding="1" cellspacing="0">
|
582
|
<tr>
|
583
|
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
|
584
|
<a name="navbar_top_firstrow"><!-- --></a>
|
585
|
<table border="0" cellpadding="0" cellspacing="3">
|
586
|
<tr align="center" valign="top">
|
587
|
|
588
|
|
589
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td>
|
590
|
<td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td>
|
591
|
|
592
|
|
593
|
<td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td>
|
594
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td>
|
595
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td>
|
596
|
<td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td>
|
597
|
</tr>
|
598
|
</table>
|
599
|
</td>
|
600
|
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
|
601
|
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
|
602
|
</td>
|
603
|
</tr>
|
604
|
|
605
|
<tr>
|
606
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
607
|
PREV
|
608
|
NEXT</font></td>
|
609
|
<td bgcolor="white" class="NavBarCell2"><font size="-2">
|
610
|
<a href="index.html" target="_top"><b>FRAMES</b></a>
|
611
|
<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
|
612
|
|
613
|
<script>
|
614
|
<!--
|
615
|
if(window==top) {
|
616
|
document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
|
617
|
}
|
618
|
//-->
|
619
|
</script>
|
620
|
<noscript>
|
621
|
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
|
622
|
</noscript>
|
623
|
</font></td>
|
624
|
</tr>
|
625
|
</table>
|
626
|
<!-- =========== END OF NAVBAR =========== -->
|
627
|
|
628
|
<hr>
|
629
|
<font size="-1">
|
630
|
|
631
|
</font>
|
632
|
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Sun Apr 27 20:30:54 2008</div>
|
633
|
</body>
|
634
|
</html>
|