1 |
/** |
---|
2 |
* |
---|
3 |
* @project CWC2 |
---|
4 |
* @revision $Id: cwc_cs.js,v 1.8 2004/02/25 20:37:14 wbronsema Exp $ |
---|
5 |
* @purpose Java Script API for CWC |
---|
6 |
* @author DM Solutions Group (assefa@dmsolutions.ca) |
---|
7 |
* @copyright |
---|
8 |
* <b>Copyright (c) 2002, DM Solutions Group Inc.</b> |
---|
9 |
* Permission is hereby granted, free of charge, to any person obtaining a |
---|
10 |
* copy of this software and associated documentation files (the "Software"), |
---|
11 |
* to deal in the Software without restriction, including without limitation |
---|
12 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
13 |
* and/or sell copies of the Software, and to permit persons to whom the |
---|
14 |
* Software is furnished to do so, subject to the following conditions: |
---|
15 |
* |
---|
16 |
* The above copyright notice and this permission notice shall be included |
---|
17 |
* in all copies or substantial portions of the Software. |
---|
18 |
* |
---|
19 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
22 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
24 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
25 |
* DEALINGS IN THE SOFTWARE. |
---|
26 |
*/ |
---|
27 |
|
---|
28 |
function CWC2_CS_Manager() |
---|
29 |
{ |
---|
30 |
this.nThemes = 0; |
---|
31 |
this.aThemes = new Array(); |
---|
32 |
this.form = null; |
---|
33 |
} |
---|
34 |
|
---|
35 |
function CWC2_CS_Manager_AddTheme( oTheme ) |
---|
36 |
{ |
---|
37 |
oTheme.SetForm( this.form ); |
---|
38 |
this.aThemes[this.nThemes++] = oTheme; |
---|
39 |
//js1.2/1.3 feature not supported by IE 5.0 |
---|
40 |
//this.nThemes = this.aThemes.push( oTheme ); |
---|
41 |
} |
---|
42 |
|
---|
43 |
function CWC2_CS_Manager_UpdateStatus( ) |
---|
44 |
{ |
---|
45 |
var i; |
---|
46 |
for( i=0; i<this.nThemes; i++ ) |
---|
47 |
{ |
---|
48 |
this.aThemes[i].UpdateStatus(); |
---|
49 |
} |
---|
50 |
|
---|
51 |
return true; |
---|
52 |
} |
---|
53 |
|
---|
54 |
function CWC2_CS_Manager_SetThemeStatus( nTheme, bStatus ) |
---|
55 |
{ |
---|
56 |
this.aThemes[nTheme].SetStatus( bStatus ); |
---|
57 |
} |
---|
58 |
|
---|
59 |
function CWC2_CS_Manager_SetGroupStatus( nTheme, nGroup, bStatus ) |
---|
60 |
{ |
---|
61 |
this.aThemes[nTheme].SetGroupStatus( nGroup, bStatus ); |
---|
62 |
} |
---|
63 |
|
---|
64 |
function CWC2_CS_Manager_GetVisibleLayerNames( ) |
---|
65 |
{ |
---|
66 |
var szResult = ""; |
---|
67 |
var szThemeLayers = ""; |
---|
68 |
var szSep = ""; |
---|
69 |
var i; |
---|
70 |
|
---|
71 |
this.UpdateStatus(); |
---|
72 |
|
---|
73 |
for( i=0; i<this.nThemes; i++ ) |
---|
74 |
{ |
---|
75 |
szThemeLayers = this.aThemes[i].GetVisibleLayerNames(); |
---|
76 |
if (szThemeLayers != "") |
---|
77 |
{ |
---|
78 |
szResult += szSep + szThemeLayers; |
---|
79 |
szSep = "|"; |
---|
80 |
} |
---|
81 |
} |
---|
82 |
return szResult; |
---|
83 |
} |
---|
84 |
|
---|
85 |
function CWC2_CS_Manager_GetState() |
---|
86 |
{ |
---|
87 |
var anState = new Array(); |
---|
88 |
|
---|
89 |
// loop through themes & groups and record state |
---|
90 |
for (var i=0; i<this.aThemes.length; i++) |
---|
91 |
{ |
---|
92 |
// record theme status in the 0 index |
---|
93 |
anState[i] = new Array(); |
---|
94 |
anState[i][0] = this.aThemes[i].GetStatus(); |
---|
95 |
|
---|
96 |
// record group(s) status |
---|
97 |
for (var j=0; j<this.aThemes[i].aGroups.length; j++) |
---|
98 |
{ |
---|
99 |
anState[i][j+1] = this.aThemes[i].aGroups[j].GetStatus(); |
---|
100 |
} |
---|
101 |
} |
---|
102 |
|
---|
103 |
// return the array |
---|
104 |
return anState; |
---|
105 |
} |
---|
106 |
|
---|
107 |
function CWC2_CS_Manager_SetState( anState ) |
---|
108 |
{ |
---|
109 |
// loop through state array and set the status |
---|
110 |
for (var i=0; i<anState.length; i++) |
---|
111 |
{ |
---|
112 |
// set theme status from the 0 index |
---|
113 |
this.SetThemeStatus( i, anState[i][0] ); |
---|
114 |
|
---|
115 |
// record group(s) status |
---|
116 |
for (var j=0; j<anState[i].length - 1; j++) |
---|
117 |
{ |
---|
118 |
this.SetGroupStatus( i, j, anState[i][j+1] ); |
---|
119 |
} |
---|
120 |
} |
---|
121 |
|
---|
122 |
// update the status |
---|
123 |
this.UpdateStatus(); |
---|
124 |
|
---|
125 |
return; |
---|
126 |
} |
---|
127 |
|
---|
128 |
CWC2_CS_Manager.prototype.AddTheme = CWC2_CS_Manager_AddTheme; |
---|
129 |
CWC2_CS_Manager.prototype.SetThemeStatus = CWC2_CS_Manager_SetThemeStatus; |
---|
130 |
CWC2_CS_Manager.prototype.SetGroupStatus = CWC2_CS_Manager_SetGroupStatus; |
---|
131 |
CWC2_CS_Manager.prototype.UpdateStatus = CWC2_CS_Manager_UpdateStatus; |
---|
132 |
CWC2_CS_Manager.prototype.GetVisibleLayerNames = CWC2_CS_Manager_GetVisibleLayerNames; |
---|
133 |
CWC2_CS_Manager.prototype.GetState = CWC2_CS_Manager_GetState; |
---|
134 |
CWC2_CS_Manager.prototype.SetState = CWC2_CS_Manager_SetState; |
---|
135 |
|
---|
136 |
/* |
---|
137 |
* the main theme object |
---|
138 |
*/ |
---|
139 |
function CWC2_CS_Theme( szName ) |
---|
140 |
{ |
---|
141 |
this.name = szName; |
---|
142 |
this.nGroups = 0; |
---|
143 |
this.aGroups = new Array(); |
---|
144 |
this.status = false; |
---|
145 |
this.type = "checkbox"; |
---|
146 |
this.form = null; |
---|
147 |
} |
---|
148 |
|
---|
149 |
function CWC2_CS_Theme_SetForm( oForm ) |
---|
150 |
{ |
---|
151 |
this.form = oForm; |
---|
152 |
} |
---|
153 |
|
---|
154 |
function CWC2_CS_Theme_AddGroup( oGroup ) |
---|
155 |
{ |
---|
156 |
oGroup.SetTheme( this ); |
---|
157 |
oGroup.SetForm( this.form ); |
---|
158 |
this.aGroups[this.nGroups++] = oGroup; |
---|
159 |
//js1.2/1.3 feature, not compatible with IE 5 |
---|
160 |
//this.nGroups = this.aGroups.push( oGroup ) |
---|
161 |
} |
---|
162 |
|
---|
163 |
function CWC2_CS_Theme_SetStatus( bStatus ) |
---|
164 |
{ |
---|
165 |
var i; |
---|
166 |
var found; |
---|
167 |
|
---|
168 |
this.status = bStatus; |
---|
169 |
|
---|
170 |
if (this.type == 'radio' && this.nGroups > 0 && bStatus ) |
---|
171 |
{ |
---|
172 |
found = false; |
---|
173 |
|
---|
174 |
for( i=0; i<this.nGroups; i++ ) |
---|
175 |
{ |
---|
176 |
if (this.aGroups[i].GetStatus()) |
---|
177 |
if (!found) |
---|
178 |
found = true; |
---|
179 |
else |
---|
180 |
this.aGroups[i].SetStatus( false ); |
---|
181 |
} |
---|
182 |
if (!found) |
---|
183 |
this.aGroups[0].SetStatus( true ); |
---|
184 |
} |
---|
185 |
else |
---|
186 |
{ |
---|
187 |
for( i=0; i<this.nGroups; i++ ) |
---|
188 |
{ |
---|
189 |
this.aGroups[i].SetStatus( bStatus ); |
---|
190 |
} |
---|
191 |
} |
---|
192 |
} |
---|
193 |
|
---|
194 |
function CWC2_CS_Theme_SetGroupStatus( nGroup, bStatus ) |
---|
195 |
{ |
---|
196 |
var i; |
---|
197 |
this.aGroups[nGroup].SetStatus( bStatus ); |
---|
198 |
|
---|
199 |
if (this.type == 'radio') |
---|
200 |
{ |
---|
201 |
for (i=0; i<this.nGroups; i++) |
---|
202 |
if (i != nGroup ) |
---|
203 |
this.aGroups[i].SetStatus( false ); |
---|
204 |
} |
---|
205 |
} |
---|
206 |
|
---|
207 |
function CWC2_CS_Theme_UpdateStatus( ) |
---|
208 |
{ |
---|
209 |
var i; |
---|
210 |
var n = 0; |
---|
211 |
var status = (this.type == 'checkbox') |
---|
212 |
|
---|
213 |
//get the status of each group, ignoring invisible ones |
---|
214 |
for( i=0; i<this.nGroups; i++ ) |
---|
215 |
{ |
---|
216 |
if (this.aGroups[i].GetVisible()) |
---|
217 |
{ |
---|
218 |
if (this.type == 'checkbox') |
---|
219 |
status &= this.aGroups[i].UpdateStatus( ); |
---|
220 |
else |
---|
221 |
status |= this.aGroups[i].UpdateStatus( ); |
---|
222 |
n++; |
---|
223 |
} |
---|
224 |
} |
---|
225 |
|
---|
226 |
if (n>0) //at least one non-visible group |
---|
227 |
{ |
---|
228 |
this.status = status; |
---|
229 |
} |
---|
230 |
|
---|
231 |
//process hidden groups separately, they follow the status of the theme |
---|
232 |
for (i=0; i<this.nGroups; i++) |
---|
233 |
{ |
---|
234 |
if (!this.aGroups[i].GetVisible()) |
---|
235 |
this.aGroups[i].SetStatus( this.status ); |
---|
236 |
} |
---|
237 |
|
---|
238 |
if (this.form != null && this.form.elements[this.name] != null) |
---|
239 |
{ |
---|
240 |
this.form.elements[this.name].checked = this.status; |
---|
241 |
} |
---|
242 |
|
---|
243 |
return this.status; |
---|
244 |
} |
---|
245 |
|
---|
246 |
function CWC2_CS_Theme_GetStatus( bStatus ) |
---|
247 |
{ |
---|
248 |
return this.status; |
---|
249 |
} |
---|
250 |
|
---|
251 |
function CWC2_CS_Theme_GetVisibleLayerNames( ) |
---|
252 |
{ |
---|
253 |
var szResult = ""; |
---|
254 |
var szGroupLayers = ""; |
---|
255 |
var szSep = ""; |
---|
256 |
var i; |
---|
257 |
|
---|
258 |
for( i=0; i<this.nGroups; i++ ) |
---|
259 |
{ |
---|
260 |
szGroupLayers = this.aGroups[i].GetVisibleLayerNames(); |
---|
261 |
if (szGroupLayers != "") |
---|
262 |
{ |
---|
263 |
szResult += szSep + szGroupLayers; |
---|
264 |
szSep = "|"; |
---|
265 |
} |
---|
266 |
} |
---|
267 |
return szResult; |
---|
268 |
} |
---|
269 |
|
---|
270 |
function CWC2_CS_Theme_SetType( szType ) |
---|
271 |
{ |
---|
272 |
this.type = szType; |
---|
273 |
} |
---|
274 |
|
---|
275 |
function CWC2_CS_Theme_GetType( ) |
---|
276 |
{ |
---|
277 |
return this.type; |
---|
278 |
} |
---|
279 |
|
---|
280 |
CWC2_CS_Theme.prototype.SetForm = CWC2_CS_Theme_SetForm; |
---|
281 |
CWC2_CS_Theme.prototype.AddGroup = CWC2_CS_Theme_AddGroup; |
---|
282 |
CWC2_CS_Theme.prototype.SetStatus = CWC2_CS_Theme_SetStatus; |
---|
283 |
CWC2_CS_Theme.prototype.SetGroupStatus = CWC2_CS_Theme_SetGroupStatus; |
---|
284 |
CWC2_CS_Theme.prototype.UpdateStatus = CWC2_CS_Theme_UpdateStatus; |
---|
285 |
CWC2_CS_Theme.prototype.GetStatus = CWC2_CS_Theme_GetStatus; |
---|
286 |
CWC2_CS_Theme.prototype.GetVisibleLayerNames = CWC2_CS_Theme_GetVisibleLayerNames; |
---|
287 |
CWC2_CS_Theme.prototype.SetType = CWC2_CS_Theme_SetType; |
---|
288 |
CWC2_CS_Theme.prototype.GetType = CWC2_CS_Theme_GetType; |
---|
289 |
|
---|
290 |
/* |
---|
291 |
* A Group Object |
---|
292 |
*/ |
---|
293 |
function CWC2_CS_Group( szName ) |
---|
294 |
{ |
---|
295 |
this.name = szName; |
---|
296 |
this.nLayers = 0; |
---|
297 |
this.aLayers = new Array(); |
---|
298 |
this.theme = null; this.form = null; |
---|
299 |
this.status = false; |
---|
300 |
this.form = null; |
---|
301 |
this.visible = true; |
---|
302 |
} |
---|
303 |
|
---|
304 |
function CWC2_CS_Group_GetVisible( ) |
---|
305 |
{ |
---|
306 |
return this.visible; |
---|
307 |
} |
---|
308 |
|
---|
309 |
function CWC2_CS_Group_SetVisible( bVisible ) |
---|
310 |
{ |
---|
311 |
this.visible = bVisible; |
---|
312 |
} |
---|
313 |
|
---|
314 |
function CWC2_CS_Group_AddLayer( oLayer) |
---|
315 |
{ |
---|
316 |
oLayer.SetGroup( this ); |
---|
317 |
this.aLayers[this.nLayers++] = oLayer; |
---|
318 |
//js1.2/1.3 feature not supported by IE 5.0 |
---|
319 |
//this.nLayers = this.aLayers.push( oLayer ); |
---|
320 |
} |
---|
321 |
|
---|
322 |
function CWC2_CS_Group_SetForm( oForm ) |
---|
323 |
{ |
---|
324 |
this.form = oForm; |
---|
325 |
} |
---|
326 |
|
---|
327 |
function CWC2_CS_Group_SetTheme( oTheme ) |
---|
328 |
{ |
---|
329 |
this.theme = oTheme; |
---|
330 |
} |
---|
331 |
|
---|
332 |
function CWC2_CS_Group_SetStatus( bStatus ) |
---|
333 |
{ |
---|
334 |
var i; |
---|
335 |
var szStatement; |
---|
336 |
|
---|
337 |
this.status = bStatus; |
---|
338 |
|
---|
339 |
for( i=0; i<this.nLayers; i++ ) |
---|
340 |
{ |
---|
341 |
this.aLayers[i].SetStatus( bStatus ); |
---|
342 |
} |
---|
343 |
|
---|
344 |
if( this.theme.GetStatus() != this.status ) |
---|
345 |
{ |
---|
346 |
this.theme.UpdateStatus(); |
---|
347 |
} |
---|
348 |
|
---|
349 |
} |
---|
350 |
|
---|
351 |
function CWC2_CS_Group_UpdateStatus( ) |
---|
352 |
{ |
---|
353 |
var i; |
---|
354 |
|
---|
355 |
this.status = true;//(this.nLayers > 0); |
---|
356 |
|
---|
357 |
for( i=0; i<this.nLayers; i++ ) |
---|
358 |
{ |
---|
359 |
this.status &= this.aLayers[i].UpdateStatus( ); |
---|
360 |
} |
---|
361 |
|
---|
362 |
if (this.form != null && this.form.elements[this.name] != null && this.visible) |
---|
363 |
{ |
---|
364 |
this.form.elements[this.name].checked = this.status; |
---|
365 |
} |
---|
366 |
|
---|
367 |
return this.status; |
---|
368 |
} |
---|
369 |
|
---|
370 |
function CWC2_CS_Group_GetStatus( ) |
---|
371 |
{ |
---|
372 |
return this.status; |
---|
373 |
} |
---|
374 |
|
---|
375 |
function CWC2_CS_Group_GetVisibleLayerNames( ) |
---|
376 |
{ |
---|
377 |
var i; |
---|
378 |
var szResult = ""; |
---|
379 |
var szSep = ""; |
---|
380 |
|
---|
381 |
if (this.status) |
---|
382 |
{ |
---|
383 |
for( i=0; i<this.nLayers; i++ ) |
---|
384 |
{ |
---|
385 |
szResult += szSep + this.aLayers[i].name; |
---|
386 |
szSep = "|"; |
---|
387 |
} |
---|
388 |
} |
---|
389 |
//alert('visible layer names:' + szResult); |
---|
390 |
return szResult; |
---|
391 |
} |
---|
392 |
|
---|
393 |
|
---|
394 |
CWC2_CS_Group.prototype.GetVisible = CWC2_CS_Group_GetVisible; |
---|
395 |
CWC2_CS_Group.prototype.SetVisible = CWC2_CS_Group_SetVisible; |
---|
396 |
CWC2_CS_Group.prototype.SetForm = CWC2_CS_Group_SetForm; |
---|
397 |
CWC2_CS_Group.prototype.AddLayer = CWC2_CS_Group_AddLayer; |
---|
398 |
CWC2_CS_Group.prototype.SetTheme = CWC2_CS_Group_SetTheme; |
---|
399 |
CWC2_CS_Group.prototype.SetStatus = CWC2_CS_Group_SetStatus; |
---|
400 |
CWC2_CS_Group.prototype.UpdateStatus = CWC2_CS_Group_UpdateStatus; |
---|
401 |
CWC2_CS_Group.prototype.GetStatus = CWC2_CS_Group_GetStatus; |
---|
402 |
CWC2_CS_Group.prototype.GetVisibleLayerNames = CWC2_CS_Group_GetVisibleLayerNames; |
---|
403 |
|
---|
404 |
|
---|
405 |
/* |
---|
406 |
* A Layer object - not needed likely |
---|
407 |
*/ |
---|
408 |
function CWC2_CS_Layer( szName ) |
---|
409 |
{ |
---|
410 |
this.name = szName; |
---|
411 |
this.oGroup = null; |
---|
412 |
this.status = false; |
---|
413 |
} |
---|
414 |
|
---|
415 |
function CWC2_CS_Layer_SetGroup( oGroup ) |
---|
416 |
{ |
---|
417 |
this.oGroup = oGroup; |
---|
418 |
} |
---|
419 |
|
---|
420 |
function CWC2_CS_Layer_SetStatus( bStatus ) |
---|
421 |
{ |
---|
422 |
this.status = bStatus; |
---|
423 |
} |
---|
424 |
|
---|
425 |
function CWC2_CS_Layer_UpdateStatus( ) |
---|
426 |
{ |
---|
427 |
return this.GetStatus(); |
---|
428 |
} |
---|
429 |
|
---|
430 |
function CWC2_CS_Layer_GetStatus( ) |
---|
431 |
{ |
---|
432 |
return this.status; |
---|
433 |
} |
---|
434 |
|
---|
435 |
CWC2_CS_Layer.prototype.SetGroup = CWC2_CS_Layer_SetGroup; |
---|
436 |
CWC2_CS_Layer.prototype.SetStatus = CWC2_CS_Layer_SetStatus; |
---|
437 |
CWC2_CS_Layer.prototype.UpdateStatus = CWC2_CS_Layer_UpdateStatus; |
---|
438 |
CWC2_CS_Layer.prototype.GetStatus = CWC2_CS_Layer_GetStatus; |
---|