jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [editor.js] - Blame information for rev 52

 

Line No. Rev Author Line
11simandl// global variable for subwindow reference
2 
3var newWindow;
4 
5var helptexts = new Object;
6 
7// seed the help text. Done in a big lump here, so we could make a foreign language version someday.
8 
9helptexts.link_target
10 = 'Where should Weathermap get data for this link? This can either be an RRD file, or an HTML with special comments in it (normally from MRTG).';
11helptexts.link_width = 'How wide the link arrow will be drawn, in pixels.';
12helptexts.link_infourl
13 = 'If you are using the \'overlib\' HTML style then this is the URL that will be opened when you click on the link';
14helptexts.link_hover
15 = 'If you are using the \'overlib\' HTML style then this is the URL of the image that will be shown when you hover over the link';
16 
17helptexts.tb_newfile = 'Change to a different file, or start creating a new one.';
18helptexts.tb_addnode = 'Add a new node to the map';
19helptexts.tb_addlink = 'Add a new link to the map, by joining two nodes together.';
20 
21helptexts.hover_tb_newfile = 'Select a different map to edit, or start a new one.';
22 
23helptexts.link_default = 'This is where help appears for links';
24helptexts.map_default = 'This is where help appears for maps';
25helptexts.node_default = 'This is where help appears for nodes';
26helptexts.tb_defaults = 'or click a Node or Link to edit it\'s properties';
27 
28addEvent(window, 'load', initJS);
29addEvent(window, 'unload', cleanupJS);
30 
31function addEvent(obj, evType, fn)
32 {
33 if (obj.addEventListener)
34 {
35 obj.addEventListener(evType, fn, false);
36 return true;
37 }
38 
39 else if (obj.attachEvent)
40 {
41 var r = obj.attachEvent("on" + evType, fn);
42 return r;
43 }
44 
45 else
46 {
47 return false;
48 }
49 }
50 
51function initJS()
52 {
53 // check if DOM is available, if not, we'll stop here, leaving the warning showing
54 if (!document.getElementById || !document.createTextNode || !document.getElementsByTagName)
55 {
56 return;
57 }
58 
59 // check if there is a "No JavaScript" message
60 var nojsmsg = document.getElementById('nojs');
61 
62 if (nojsmsg)
63 {
64 nojsmsg.style.display = 'none';
65 }
66 
67 // so that's the warning hidden, now let's show the content
68 
69 // check if there is a "with JavaScript" div
70 var jsmsg = document.getElementById('withjs');
71 
72 if (jsmsg)
73 {
74 jsmsg.style.display = 'block';
75 }
76 
77 // if the xycapture element is there, then we are in the main edit screen
78 if (document.getElementById('xycapture'))
79 {
80 attach_click_events();
81 attach_help_events();
82 show_context_help('node_label', 'node_help');
83 
84 // set the mapmode, so we know where we stand.
85 mapmode('existing');
86 }
87 }
88 
89function cleanupJS()
90 {
91 
92 // This should be cleaning up all the handlers we added in initJS, to avoid killing
93 // IE/Win and Safari (at least) over a period of time with memory leaks.
94 
95 }
96 
97function attach_help_events()
98 {
99 var helps;
100 
101 // add an onblur/onfocus handler to all the visible <input> items
102 helps = document.getElementsByTagName('input');
103 
104 for (i = 0; i < helps.length; ++i)
105 {
106 if (helps[i].getAttribute('type') != 'hidden')
107 {
108 addEvent(helps[i], 'focus', help_handler);
109 addEvent(helps[i], 'blur', help_handler);
110 }
111 }
112 
113 if (6 == 8)
114 {
115 // add an onmousein/onmouseout handler to the toolbar buttons
116 helps = document.getElementsByTagName('li');
117 
118 for (i = 0; i < helps.length; ++i)
119 {
120 // alert(helps[i].id.slice(0,3));
121 //alert(helps[i].className);
122 if (helps[i].className == 'tb_active')
123 { // alert(helps[i].id);
124 addEvent(helps[i], 'mouseover', mouse_help_handler);
125 addEvent(helps[i], 'mouseout', mouse_help_handler);
126 // alert('Attaching to ' + helps[i].className);
127 }
128 }
129 }
130 }
131 
132function attach_click_events()
133 {
134 var alt, i;
135 var areas, type;
136 
137 areas = document.getElementsByTagName('area');
138 
139 for (i = 0; i < areas.length; ++i)
140 {
141 alt = areas[i].getAttribute('alt');
142 type = alt.slice(0, 5);
143 
144 if (type == 'LINK:' || type == 'NODE:')
145 {
146 // we add the href so that the browser adds a 'hand' cursor
147 areas[i].setAttribute('href', '#');
148 // and the click_handler does the actual work
149 addEvent(areas[i], 'click', click_handler);
150 }
151 
152 if (type == 'TIMES')
153 {
154 areas[i].setAttribute('href', '#');
155 addEvent(areas[i], 'click', position_timestamp);
156 }
157 
158 if (type == 'LEGEN')
159 {
160 areas[i].setAttribute('href', '#');
161 addEvent(areas[i], 'click', position_legend);
162 }
163 }
164 
165 addEvent(document.getElementById('tb_newfile'), 'click', new_file);
166 addEvent(document.getElementById('tb_addnode'), 'click', add_node);
167 addEvent(document.getElementById('tb_mapprops'), 'click', map_properties);
168 addEvent(document.getElementById('tb_mapstyle'), 'click', map_style);
169 
170 addEvent(document.getElementById('tb_addlink'), 'click', add_link);
171 addEvent(document.getElementById('tb_poslegend'), 'click', position_first_legend);
172 addEvent(document.getElementById('tb_postime'), 'click', position_timestamp);
173 addEvent(document.getElementById('tb_colours'), 'click', manage_colours);
174 addEvent(document.getElementById('tb_manageimages'), 'click', manage_images);
175 addEvent(document.getElementById('tb_prefs'), 'click', prefs);
176 
177 addEvent(document.getElementById('tb_node_cancel'), 'click', cancel_op);
178 addEvent(document.getElementById('tb_node_submit'), 'click', do_submit);
179 addEvent(document.getElementById('node_move'), 'click', move_node);
180 addEvent(document.getElementById('node_delete'), 'click', delete_node);
181 
182 addEvent(document.getElementById('tb_link_cancel'), 'click', cancel_op);
183 addEvent(document.getElementById('tb_link_submit'), 'click', do_submit);
184 addEvent(document.getElementById('link_delete'), 'click', delete_link);
185 
186 addEvent(document.getElementById('tb_map_cancel'), 'click', cancel_op);
187 addEvent(document.getElementById('tb_map_submit'), 'click', do_submit);
188 
189 addEvent(document.getElementById('tb_mapstyle_cancel'), 'click', cancel_op);
190 addEvent(document.getElementById('tb_mapstyle_submit'), 'click', do_submit);
191 
192 addEvent(document.getElementById('tb_colours_cancel'), 'click', cancel_op);
193 addEvent(document.getElementById('tb_colours_submit'), 'click', do_submit);
194 
195 addEvent(document.getElementById('tb_images_cancel'), 'click', cancel_op);
196 addEvent(document.getElementById('tb_images_submit'), 'click', do_submit);
197 
198 var cp = document.getElementById('link_cactipick');
199 addEvent(cp, 'click', cactipicker);
200 cp.setAttribute('href', '#');
20113simandl 
202 cp = document.getElementById('node_cactipick');
203 addEvent(cp, 'click', nodecactipicker);
204 cp.setAttribute('href', '#');
2051simandl }
206 
207// used by the cancel button on each of the properties dialogs
208function cancel_op()
209 {
210 hide_all_dialogs();
211 document.frmMain.action.value = '';
212 }
213 
214function help_handler(e)
215 {
216 var el;
217 
218 if (window.event && window.event.srcElement)
219 {
220 el = window.event.srcElement;
221 }
222 
223 if (e && e.target)
224 {
225 el = e.target;
226 }
227 
228 if (!el)
229 {
230 return;
231 }
232 
233 var objectid = el.id;
234 
235 if ((e.type == 'focus') || (e.type == 'mouseover'))
236 {
237 if (helptexts[objectid])
238 {
239 var help = helptexts[objectid];
240 var target = objectid.slice(0, objectid.indexOf('_')) + '_help';
241 
242 document.getElementById(target).firstChild.nodeValue = help;
243 
244 // alert(target);
245 }
246 }
247 
248 if ((e.type == 'blur') || (e.type == 'mouseout'))
249 {
250 // alert('blurred - figure out default, and apply it.');
251 
252 var section = objectid.slice(0, objectid.indexOf('_'));
253 var target = section + '_help';
254 var help = helptexts[section + '_default'];
255 
256 if (help == 'undefined')
257 {
258 alert('OID is: ' + objectid + ' and target is:' + target + ' and section is: ' + section);
259 }
260 
261 document.getElementById(target).firstChild.nodeValue = help;
262 }
263 }
264 
265function mouse_help_handler(e)
266 {
267 var el;
268 
269 // alert('ddd');
270 
271 if (window.event && window.event.srcElement)
272 {
273 el = window.event.srcElement;
274 }
275 
276 if (e && e.target)
277 {
278 el = e.target;
279 }
280 
281 if (!el)
282 {
283 return;
284 }
285 
286 var objectid = el.firstChild.id;
287 
288 if ((e.type == 'focus') || (e.type == 'mouseover'))
289 {
290 if (helptexts[objectid])
291 {
292 var help = helptexts[objectid];
293 var target = objectid.slice(0, objectid.indexOf('_')) + '_help';
294 
295 document.getElementById(target).firstChild.nodeValue = help;
296 
297 // alert(target);
298 }
299 }
300 
301 if ((e.type == 'blur') || (e.type == 'mouseout'))
302 {
303 // alert('blurred - figure out default, and apply it.');
304 
305 var section = objectid.slice(0, objectid.indexOf('_'));
306 var target = section + '_help';
307 var help = helptexts[section + '_default'];
308 
309 if (help == 'undefined')
310 {
311 alert('OID is: ' + objectid + ' and target is:' + target + ' and section is: ' + section);
312 }
313 
314 document.getElementById(target).firstChild.nodeValue = help;
315 }
316 }
317 
318// Any clicks in the imagemap end up here.
319function click_handler(e)
320 {
321 var el;
322 var alt, objectname, objecttype;
323 
324 if (window.event && window.event.srcElement)
325 {
326 el = window.event.srcElement;
327 }
328 
329 if (e && e.target)
330 {
331 el = e.target;
332 }
333 
334 if (!el)
335 {
336 return;
337 }
338 
339 alt = el.getAttribute('alt');
340 
341 objecttype = alt.slice(0, 4);
342 objectname = alt.slice(5, alt.length);
343 
344 // if we're not in a mode yet...
345 if (document.frmMain.action.value === '')
346 {
347 
348 // if we're waiting for a node specifically (e.g. "make link") then ignore links here
349 if (objecttype == 'NODE')
350 {
351 show_node(objectname);
352 }
353 
354 if (objecttype == 'LINK')
355 {
356 show_link(objectname);
357 }
358 }
359 
360 // we've got a command queued, so do the appropriate thing
361 else
362 {
363 if (objecttype == 'NODE' && document.getElementById('action').value == 'add_link')
364 {
365 document.getElementById('param').value = objectname;
366 document.frmMain.submit();
367 }
368 
369 else if (objecttype == 'NODE' && document.getElementById('action').value == 'add_link2')
370 {
371 document.getElementById('param').value = objectname;
372 document.frmMain.submit();
373 }
374 
375 else
376 {
377 // Halfway through one operation, the user has done something unexpected.
378 // reset back to standard state, and see if we can oblige them
379 // alert('A bit confused');
380 document.frmMain.action.value = '';
381 hide_all_dialogs()
382 click_handler(e);
383 }
384 }
385 }
386 
387// used by the Submit button on each of the properties dialogs
388function do_submit()
389 {
390 document.frmMain.submit();
391 }
392 
393function cactipicker()
394 {
395 // make sure it isn't already opened
396 if (!newWindow || newWindow.closed)
397 {
398 newWindow = window.open("", "cactipicker", "status,scrollbars=yes,height=400,width=400");
399 }
400 
401 else if (newWindow.focus)
402 {
403 // window is already open and focusable, so bring it to the front
404 newWindow.focus();
405 }
406 
40713simandl newWindow.location = "cacti-pick.php?command=link_step1";
4081simandl }
409 
41013simandl 
411function nodecactipicker()
412 {
413 // make sure it isn't already opened
414 if (!newWindow || newWindow.closed)
415 {
416 newWindow = window.open("", "cactipicker", "status,scrollbars=yes,height=400,width=400");
417 }
418 
419 else if (newWindow.focus)
420 {
421 // window is already open and focusable, so bring it to the front
422 newWindow.focus();
423 }
424 
425 newWindow.location = "cacti-pick.php?command=node_step1";
426 }
427 
4281simandlfunction show_context_help(itemid, targetid)
429 {
430 // var itemid = item.id;
431 var helpbox, helpboxtext, message;
432 // var ct = document.getElementById(targetid);
433 // if(ct)
434 // {
435 message = "We'd show helptext for " + itemid + " in the'" + targetid + "' div";
436 // }
437 helpbox = document.getElementById(targetid);
438 helpboxtext = helpbox.firstChild;
439 helpboxtext.nodeValue = message;
440 }
441 
442function manage_colours()
443 {
444 mapmode('existing');
445 
446 hide_all_dialogs();
447 document.getElementById('action').value = "set_map_colours";
448 show_dialog('dlgColours');
449 }
450 
451function manage_images()
452 {
453 mapmode('existing');
454 
455 hide_all_dialogs();
456 document.getElementById('action').value = "set_image";
457 show_dialog('dlgImages');
458 }
459 
460function prefs()
461 {
462 alert("Not Yet");
463 }
464 
465function default_toolbar()
466 {
467 }
468 
469function working_toolbar()
470 {
471 }
472 
473function new_file()
474 {
475 self.location = "?action=newfile";
476 }
477 
478function mapmode(m)
479 {
480 if (m == 'xy')
481 {
482 document.getElementById('debug').value = "xy";
483 document.getElementById('xycapture').style.display = 'inline';
484 document.getElementById('existingdata').style.display = 'none';
485 }
486 
487 else if (m == 'existing')
488 {
489 document.getElementById('debug').value = "existing";
490 document.getElementById('xycapture').style.display = 'none';
491 document.getElementById('existingdata').style.display = 'inline';
492 }
493 
494 else
495 {
496 alert('invalid mode');
497 }
498 }
499 
500function add_node()
501 {
502 document.getElementById('tb_help').innerText = 'Click on the map where you would like to add a new node.';
503 document.getElementById('action').value = "add_node";
504 mapmode('xy');
505 }
506 
507function delete_node()
508 {
509 if (confirm("This node (and any links it is part of) will be deleted permanently."))
510 {
511 document.getElementById('action').value = "delete_node";
512 document.frmMain.submit();
513 }
514 }
515 
516function move_node()
517 {
518 hide_dialog('dlgNodeProperties');
519 document.getElementById('tb_help').innerText = 'Click on the map where you would like to move the node to.';
520 document.getElementById('action').value = "move_node";
521 mapmode('xy');
522 }
523 
524function add_link()
525 {
526 document.getElementById('tb_help').innerText = 'Click on the first node for one end of the link.';
527 document.getElementById('action').value = "add_link";
528 mapmode('existing');
529 }
530 
531function delete_link()
532 {
533 if (confirm("This link will be deleted permanently."))
534 {
535 document.getElementById('action').value = "delete_link";
536 document.frmMain.submit();
537 }
538 }
539 
540function map_properties()
541 {
542 mapmode('existing');
543 
544 hide_all_dialogs();
545 document.getElementById('action').value = "set_map_properties";
546 show_dialog('dlgMapProperties');
547 }
548 
549function map_style()
550 {
551 mapmode('existing');
552 
553 hide_all_dialogs();
554 document.getElementById('action').value = "set_map_style";
555 show_dialog('dlgMapStyle');
556 }
557 
558function position_timestamp()
559 {
560 document.getElementById('tb_help').innerText = 'Click on the map where you would like to put the timestamp.';
561 document.getElementById('action').value = "place_stamp";
562 mapmode('xy');
563 }
564 
565// called from clicking the toolbar
566function position_first_legend()
567{
568 real_position_legend('DEFAULT');
569}
570 
571// called from clicking on the existing legends
572function position_legend(e)
573 {
574 var el;
575 var alt, objectname, objecttype;
576 
577 if (window.event && window.event.srcElement)
578 {
579 el = window.event.srcElement;
580 }
581 
582 if (e && e.target)
583 {
584 el = e.target;
585 }
586 
587 if (!el)
588 {
589 return;
590 }
591 
592 // we need to figure out WHICH legend, nowadays
593 alt = el.getAttribute('alt');
594 
595 // objecttype = alt.slice(0, 5);
596 objectname = alt.slice(7, alt.length);
597 
598 real_position_legend(objectname);
599 
600 //document.getElementById('tb_help').innerText = 'Click on the map where you would like to put the legend.';
601 //document.getElementById('action').value = "place_legend";
602 //document.getElementById('param').value = objectname;
603 //mapmode('xy');
604 }
605 
606function real_position_legend(scalename)
607{
608 document.getElementById('tb_help').innerText = 'Click on the map where you would like to put the legend.';
609 document.getElementById('action').value = "place_legend";
610 document.getElementById('param').value = scalename;
611 mapmode('xy');
612}
613 
614function show_node(name)
615 {
616 var found = -1;
617 mapmode('existing');
618 
619 hide_all_dialogs();
620 
621 var mynode = Nodes[name];
622 
623 if (mynode)
624 {
625 document.frmMain.action.value = "set_node_properties";
626 document.frmMain.node_name.value = name;
627 document.frmMain.node_new_name.value = name;
628 
629 document.frmMain.node_name.value = mynode.name;
630 document.frmMain.node_new_name.value = mynode.name;
631 document.frmMain.node_label.value = mynode.label;
632 document.frmMain.node_infourl.value = mynode.infourl;
633 document.frmMain.node_hover.value = mynode.overliburl;
634 
635 if(mynode.iconfile != '')
636 {
637 document.frmMain.node_iconfilename.value = mynode.iconfile;
638 }
639 else
640 {
641 document.frmMain.node_iconfilename.value = '--NONE--';
642 }
643 
644 
645 // save this here, just in case they choose delete_node or move_node
646 document.getElementById('param').value = mynode.name;
647 
648 show_dialog('dlgNodeProperties');
649 }
650 }
651 
652function show_link(name)
653 {
654 var found = -1;
655 mapmode('existing');
656 
657 hide_all_dialogs();
658 
659 var mylink = Links[name];
660 
661 if (mylink)
662 {
663 document.frmMain.link_name.value = mylink.name;
664 document.frmMain.link_target.value = mylink.target;
665 document.frmMain.link_width.value = mylink.width;
666 
667 document.frmMain.link_bandwidth_in.value = mylink.bw_in;
668 
669 if (mylink.bw_in == mylink.bw_out)
670 {
671 document.frmMain.link_bandwidth_out.value = '';
672 document.frmMain.link_bandwidth_out_cb.checked = 1;
673 }
674 
675 else
676 {
677 document.frmMain.link_bandwidth_out_cb.checked = 0;
678 document.frmMain.link_bandwidth_out.value = mylink.bw_out;
679 }
680 
681 document.frmMain.link_infourl.value = mylink.infourl;
682 document.frmMain.link_hover.value = mylink.overliburl;
683 
684 document.getElementById('link_nodename1').firstChild.nodeValue = mylink.a;
685 document.getElementById('link_nodename1a').firstChild.nodeValue = mylink.a;
686 document.getElementById('link_nodename1b').firstChild.nodeValue = mylink.a;
687 
688 document.getElementById('link_nodename2').firstChild.nodeValue = mylink.b;
689 
690 document.getElementById('param').value = mylink.name;
691 
692 document.frmMain.action.value = "set_link_properties";
693 
694 show_dialog('dlgLinkProperties');
695 }
696 }
697 
698function show_dialog(dlg)
699 {
700 document.getElementById(dlg).style.display = 'block';
701 }
702 
703function hide_dialog(dlg)
704 {
705 document.getElementById(dlg).style.display = 'none';
706 // reset the action. The use pressed Cancel, if this function was called
707 // (that, or they're about to open a new Properties dialog, so the value is irrelevant)
708 document.frmMain.action.value = '';
709 // alert('ACTION=' + document.frmMain.action.value);
710 }
711 
712function hide_all_dialogs()
713 {
714 hide_dialog('dlgMapProperties');
715 hide_dialog('dlgMapStyle');
716 hide_dialog('dlgLinkProperties');
717 hide_dialog('dlgNodeProperties');
718 hide_dialog('dlgColours');
719 hide_dialog('dlgImages');
720 }

Powered by WebSVN 2.2.1