jablonka.czprosek.czf

weathermap

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

 

Line No. Rev Author Line
11simandl// global variable for subwindow reference
2 
3var newWindow;
4 
5// seed the help text. Done in a big lump here, so we could make a foreign language version someday.
6 
785simandlvar helptexts = {
8 "link_target": '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).',
9 "link_width": 'How wide the link arrow will be drawn, in pixels.',
10 "link_infourl":
11 'If you are using the \'overlib\' HTML style then this is the URL that will be opened when you click on the link',
12 "link_hover":
13 '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',
14 "link_bandwidth_in": "The bandwidth from the first node to the second node",
15 "link_bandwidth_out": "The bandwidth from the second node to the first node (if that is different)",
16 "link_commentin": "The text that will appear alongside the link",
17 "link_commentout": "The text that will appear alongside the link",
181simandl 
1985simandl "node_infourl":
20 'If you are using the \'overlib\' HTML style then this is the URL that will be opened when you click on the node',
21 "node_hover":
22 '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 node',
23 "node_x": "How far from the left to position the node, in pixels",
24 "node_y": "How far from the top to position the node, in pixels",
25 "node_label": "The text that appears on the node",
26 "node_new_name": "The name used for this node when defining links",
271simandl 
2885simandl "tb_newfile": 'Change to a different file, or start creating a new one.',
29 "tb_addnode": 'Add a new node to the map',
30 "tb_addlink": 'Add a new link to the map, by joining two nodes together.',
311simandl 
32 
3385simandl "hover_tb_newfile": 'Select a different map to edit, or start a new one.',
341simandl 
3585simandl// These are the default text - what appears when nothing more interesting
36// is happening. One for each dialog/location.
37 "link_default": 'This is where help appears for links',
38 "map_default": 'This is where help appears for maps',
39 "node_default": 'This is where help appears for nodes',
40 "tb_default": 'or click a Node or Link to edit it\'s properties'
41};
421simandl 
4385simandljQuery(document).ready(initJS);
44jQuery(document).unload(cleanupJS);
451simandl 
46function initJS()
47 {
48 // check if DOM is available, if not, we'll stop here, leaving the warning showing
49 if (!document.getElementById || !document.createTextNode || !document.getElementsByTagName)
50 {
5185simandl // I'm pretty sure this is actually impossible now.
521simandl return;
53 }
54 
5585simandl // check if there is a "No JavaScript" message
56 jQuery("#nojs").hide();
571simandl 
58 // so that's the warning hidden, now let's show the content
59 
60 // check if there is a "with JavaScript" div
6185simandl jQuery("#withjs").show();
621simandl 
63 // if the xycapture element is there, then we are in the main edit screen
64 if (document.getElementById('xycapture'))
65 {
66 attach_click_events();
67 attach_help_events();
68 show_context_help('node_label', 'node_help');
69 
70 // set the mapmode, so we know where we stand.
71 mapmode('existing');
72 }
73 }
74 
75function cleanupJS()
76 {
77 
78 // This should be cleaning up all the handlers we added in initJS, to avoid killing
79 // IE/Win and Safari (at least) over a period of time with memory leaks.
80 
81 }
82 
83 
84 
8585simandlfunction attach_click_events()
86 {
871simandl 
8885simandl jQuery("area[id^=LINK:]").attr("href","#").click(click_handler);
89 jQuery("area[id^=NODE:]").attr("href","#").click(click_handler);
90 jQuery("area[id^=TIMES]").attr("href","#").click(position_timestamp);
91 jQuery("area[id^=LEGEN]").attr("href","#").click(position_legend);
92 
93 if(fromplug===1)
94 {
95 jQuery("#tb_newfile").click( function() {window.location = "weathermap-cacti-plugin-mgmt.php";} )
961simandl }
9785simandl else
981simandl {
9985simandl jQuery("#tb_newfile").click(new_file);
100 }
1011simandl 
10285simandl jQuery("#tb_addnode").click(add_node);
103 jQuery("#tb_mapprops").click(map_properties);
104 jQuery("#tb_mapstyle").click(map_style);
1051simandl 
10685simandl jQuery("#tb_addlink").click(add_link);
107 jQuery("#tb_poslegend").click(position_first_legend);
108 jQuery("#tb_postime").click(position_timestamp);
109 jQuery("#tb_colours").click(manage_colours);
1101simandl 
11185simandl jQuery("#tb_manageimages").click(manage_images);
112 jQuery("#tb_prefs").click(prefs);
1131simandl 
11485simandl jQuery("#node_move").click(move_node);
115 jQuery("#node_delete").click(delete_node);
116 jQuery("#node_clone").click(clone_node);
117 jQuery("#node_edit").click(edit_node);
1181simandl 
11985simandl jQuery("#link_delete").click(delete_link);
120 jQuery("#link_edit").click(edit_link);
1211simandl 
12285simandl jQuery("#link_vert").click(align_link_v);
123 jQuery("#link_horiz").click(align_link_h);
124 jQuery("#link_via").click(via_link);
125 
126 jQuery('.wm_submit').click(do_submit);
127 jQuery('.wm_cancel').click(cancel_op);
12813simandl 
12985simandl jQuery('#link_cactipick').click(cactipicker).attr("href","#");
130 jQuery('#node_cactipick').click(nodecactipicker).attr("href","#");
131 
132 jQuery('#xycapture').mouseover(function(event) {coord_capture(event);});
133 jQuery('#xycapture').mousemove(function(event) {coord_update(event);});
134 jQuery('#xycapture').mouseout(function(event) {coord_release(event);});
135 
1361simandl }
137 
138// used by the cancel button on each of the properties dialogs
139function cancel_op()
140 {
141 hide_all_dialogs();
14285simandl jQuery("#action").val("");
1431simandl }
144 
145function help_handler(e)
146 {
147 
14885simandl var objectid = jQuery(this).attr('id');
149 var section = objectid.slice(0, objectid.indexOf('_'));
150 var target = section + '_help';
151 var helptext = "undefined";
1521simandl 
15385simandl if (helptexts[objectid]) {
154 helptext = helptexts[objectid];
155 }
1561simandl 
15785simandl if ((e.type == 'blur') || (e.type == 'mouseout')) {
158 
159 helptext = helptexts[section + '_default'];
1601simandl 
16185simandl if (helptext == 'undefined') {
1621simandl alert('OID is: ' + objectid + ' and target is:' + target + ' and section is: ' + section);
163 }
16485simandl 
1651simandl }
166 
16785simandl if(helptext != "undefined") {
168 jQuery("#" + target).text(helptext);
1691simandl }
170 
171 }
172 
173// Any clicks in the imagemap end up here.
174function click_handler(e)
175 {
17685simandl 
177 var alt, objectname, objecttype, objectid;
178 
179 // alt = el.getAttribute('alt');
180 alt = jQuery(this).attr("id");
1811simandl 
182 objecttype = alt.slice(0, 4);
183 objectname = alt.slice(5, alt.length);
18485simandl objectid = objectname.slice(0,objectname.length-2);
1851simandl 
186 // if we're not in a mode yet...
187 if (document.frmMain.action.value === '')
188 {
189 
190 // if we're waiting for a node specifically (e.g. "make link") then ignore links here
191 if (objecttype == 'NODE')
192 {
19385simandl // chop off the suffix
194 // objectid = objectname.slice(0,objectname.length-2);
195 objectname = NodeIDs[objectid];
196 show_node(objectname);
1971simandl }
198 
199 if (objecttype == 'LINK')
200 {
20185simandl // chop off the suffix
202 // objectid = objectname.slice(0,objectname.length-2);
203 objectname = LinkIDs[objectid];
204 show_link(objectname);
2051simandl }
206 }
207 
208 // we've got a command queued, so do the appropriate thing
209 else
210 {
211 if (objecttype == 'NODE' && document.getElementById('action').value == 'add_link')
212 {
21385simandl document.getElementById('param').value = NodeIDs[objectid];
2141simandl document.frmMain.submit();
215 }
216 
217 else if (objecttype == 'NODE' && document.getElementById('action').value == 'add_link2')
218 {
21985simandl document.getElementById('param').value = NodeIDs[objectid];
2201simandl document.frmMain.submit();
221 }
222 
223 else
224 {
225 // Halfway through one operation, the user has done something unexpected.
226 // reset back to standard state, and see if we can oblige them
227 // alert('A bit confused');
228 document.frmMain.action.value = '';
229 hide_all_dialogs()
230 click_handler(e);
231 }
232 }
233 }
234 
235// used by the Submit button on each of the properties dialogs
236function do_submit()
237 {
238 document.frmMain.submit();
239 }
240 
241function cactipicker()
242 {
243 // make sure it isn't already opened
244 if (!newWindow || newWindow.closed)
245 {
24685simandl newWindow = window.open("", "cactipicker", "scrollbars=1,status=1,height=400,width=400,resizable=1");
2471simandl }
248 
249 else if (newWindow.focus)
250 {
251 // window is already open and focusable, so bring it to the front
252 newWindow.focus();
253 }
254 
25585simandl // newWindow.location = "cacti-pick.php?command=link_step1";
25613simandl newWindow.location = "cacti-pick.php?command=link_step1";
2571simandl }
258 
25913simandl 
260function nodecactipicker()
261 {
262 // make sure it isn't already opened
263 if (!newWindow || newWindow.closed)
264 {
26585simandl newWindow = window.open("", "cactipicker", "scrollbars=1,status=1,height=400,width=400,resizable=1");
26613simandl }
267 
268 else if (newWindow.focus)
269 {
270 // window is already open and focusable, so bring it to the front
271 newWindow.focus();
272 }
273 
274 newWindow.location = "cacti-pick.php?command=node_step1";
275 }
276 
2771simandlfunction show_context_help(itemid, targetid)
278 {
279 // var itemid = item.id;
280 var helpbox, helpboxtext, message;
281 // var ct = document.getElementById(targetid);
282 // if(ct)
283 // {
284 message = "We'd show helptext for " + itemid + " in the'" + targetid + "' div";
285 // }
286 helpbox = document.getElementById(targetid);
287 helpboxtext = helpbox.firstChild;
288 helpboxtext.nodeValue = message;
289 }
290 
291function manage_colours()
292 {
293 mapmode('existing');
294 
295 hide_all_dialogs();
296 document.getElementById('action').value = "set_map_colours";
297 show_dialog('dlgColours');
298 }
299 
300function manage_images()
301 {
302 mapmode('existing');
303 
304 hide_all_dialogs();
305 document.getElementById('action').value = "set_image";
306 show_dialog('dlgImages');
307 }
308 
309function prefs()
310 {
31185simandl hide_all_dialogs();
312 document.getElementById('action').value = "editor_settings";
313 show_dialog('dlgEditorSettings');
3141simandl }
315 
316function default_toolbar()
317 {
318 }
319 
320function working_toolbar()
321 {
322 }
323 
324function new_file()
325 {
326 self.location = "?action=newfile";
327 }
328 
329function mapmode(m)
330 {
331 if (m == 'xy')
332 {
333 document.getElementById('debug').value = "xy";
334 document.getElementById('xycapture').style.display = 'inline';
335 document.getElementById('existingdata').style.display = 'none';
336 }
337 
338 else if (m == 'existing')
339 {
340 document.getElementById('debug').value = "existing";
341 document.getElementById('xycapture').style.display = 'none';
342 document.getElementById('existingdata').style.display = 'inline';
343 }
344 
345 else
346 {
347 alert('invalid mode');
348 }
349 }
350 
351function add_node()
352 {
353 document.getElementById('tb_help').innerText = 'Click on the map where you would like to add a new node.';
354 document.getElementById('action').value = "add_node";
355 mapmode('xy');
356 }
357 
358function delete_node()
359 {
360 if (confirm("This node (and any links it is part of) will be deleted permanently."))
361 {
362 document.getElementById('action').value = "delete_node";
363 document.frmMain.submit();
364 }
365 }
366 
36785simandlfunction clone_node()
368 {
369 document.getElementById('action').value = "clone_node";
370 document.frmMain.submit();
371 }
372 
373function edit_node()
374{
375 document.getElementById('action').value = "edit_node";
376 show_itemtext('node',document.frmMain.node_name.value);
377 // document.frmMain.submit();
378 }
379 
380function edit_link()
381{
382 document.getElementById('action').value = "edit_link";
383 show_itemtext('link',document.frmMain.link_name.value);
384 // document.frmMain.submit();
385}
386 
3871simandlfunction move_node()
388 {
389 hide_dialog('dlgNodeProperties');
390 document.getElementById('tb_help').innerText = 'Click on the map where you would like to move the node to.';
391 document.getElementById('action').value = "move_node";
392 mapmode('xy');
393 }
394 
39585simandlfunction via_link()
396 {
397 hide_dialog('dlgLinkProperties');
398 document.getElementById('tb_help').innerText = 'Click on the map via which point you whant to redirect link.';
399 document.getElementById('action').value = "via_link";
400 mapmode('xy');
401}
402 
4031simandlfunction add_link()
404 {
405 document.getElementById('tb_help').innerText = 'Click on the first node for one end of the link.';
406 document.getElementById('action').value = "add_link";
407 mapmode('existing');
408 }
409 
410function delete_link()
411 {
412 if (confirm("This link will be deleted permanently."))
413 {
414 document.getElementById('action').value = "delete_link";
415 document.frmMain.submit();
416 }
417 }
418 
419function map_properties()
420 {
421 mapmode('existing');
422 
423 hide_all_dialogs();
424 document.getElementById('action').value = "set_map_properties";
425 show_dialog('dlgMapProperties');
42685simandl document.getElementById('map_title').focus();
4271simandl }
428 
429function map_style()
430 {
431 mapmode('existing');
432 
433 hide_all_dialogs();
434 document.getElementById('action').value = "set_map_style";
435 show_dialog('dlgMapStyle');
43685simandl document.getElementById('mapstyle_linklabels').focus();
4371simandl }
438 
439function position_timestamp()
440 {
441 document.getElementById('tb_help').innerText = 'Click on the map where you would like to put the timestamp.';
442 document.getElementById('action').value = "place_stamp";
443 mapmode('xy');
444 }
445 
446// called from clicking the toolbar
447function position_first_legend()
448{
449 real_position_legend('DEFAULT');
450}
451 
452// called from clicking on the existing legends
453function position_legend(e)
454 {
455 var el;
456 var alt, objectname, objecttype;
457 
458 if (window.event && window.event.srcElement)
459 {
460 el = window.event.srcElement;
461 }
462 
463 if (e && e.target)
464 {
465 el = e.target;
466 }
467 
468 if (!el)
469 {
470 return;
471 }
472 
473 // we need to figure out WHICH legend, nowadays
47485simandl //alt = el.getAttribute('alt');
475 alt = el.id;
4761simandl 
477 // objecttype = alt.slice(0, 5);
478 objectname = alt.slice(7, alt.length);
479 
480 real_position_legend(objectname);
481 
482 //document.getElementById('tb_help').innerText = 'Click on the map where you would like to put the legend.';
483 //document.getElementById('action').value = "place_legend";
484 //document.getElementById('param').value = objectname;
485 //mapmode('xy');
486 }
487 
488function real_position_legend(scalename)
489{
490 document.getElementById('tb_help').innerText = 'Click on the map where you would like to put the legend.';
491 document.getElementById('action').value = "place_legend";
492 document.getElementById('param').value = scalename;
493 mapmode('xy');
494}
495 
49685simandlfunction show_itemtext(itemtype,name)
497 {
498 var found = -1;
499 mapmode('existing');
500 
501 hide_all_dialogs();
502 
503 // $('#dlgNodeProperties').block();
504 
505 // $.blockUI.defaults.elementMessage = 'Please Wait';
506 
507 jQuery('textarea#item_configtext').val('');
508 
509 if(itemtype==='node')
510 {
511 jQuery('#action').val('set_node_config');
512 }
513 
514 if(itemtype==='link')
515 {
516 jQuery('#action').val('set_link_config');
517 }
518 show_dialog('dlgTextEdit');
519 
520// $('#item_configtext').block();
521 
522 jQuery.ajax( { type: "GET",
523 url: 'editor.php',
524 data: {action: 'fetch_config',
525 item_type: itemtype,
526 item_name: name,
527 mapname: document.frmMain.mapname.value},
528 success: function(text) {
529 jQuery('#item_configtext').val(text);
530 document.getElementById('item_configtext').focus();
531 // jQuery('#dlgTextEdit').unblock();
532 }
533 } );
534}
535 
5361simandlfunction show_node(name)
537 {
538 var found = -1;
539 mapmode('existing');
540 
541 hide_all_dialogs();
542 
543 var mynode = Nodes[name];
544 
545 if (mynode)
546 {
547 document.frmMain.action.value = "set_node_properties";
548 document.frmMain.node_name.value = name;
549 document.frmMain.node_new_name.value = name;
550 
55185simandl document.frmMain.node_x.value = mynode.x;
552 document.frmMain.node_y.value = mynode.y;
553 
5541simandl document.frmMain.node_name.value = mynode.name;
555 document.frmMain.node_new_name.value = mynode.name;
556 document.frmMain.node_label.value = mynode.label;
557 document.frmMain.node_infourl.value = mynode.infourl;
558 document.frmMain.node_hover.value = mynode.overliburl;
559 
560 if(mynode.iconfile != '')
561 {
56285simandl // console.log(mynode.iconfile.substring(0,2));
563 if(mynode.iconfile.substring(0,2)=='::')
564 {
565 document.frmMain.node_iconfilename.value = '--AICON--';
566 }
567 else
568 {
569 document.frmMain.node_iconfilename.value = mynode.iconfile;
570 }
5711simandl }
572 else
573 {
574 document.frmMain.node_iconfilename.value = '--NONE--';
57585simandl }
5761simandl 
577 // save this here, just in case they choose delete_node or move_node
578 document.getElementById('param').value = mynode.name;
579 
580 show_dialog('dlgNodeProperties');
58185simandl document.getElementById('node_new_name').focus();
5821simandl }
583 }
584 
585function show_link(name)
586 {
587 var found = -1;
588 mapmode('existing');
589 
590 hide_all_dialogs();
591 
592 var mylink = Links[name];
593 
594 if (mylink)
595 {
596 document.frmMain.link_name.value = mylink.name;
597 document.frmMain.link_target.value = mylink.target;
598 document.frmMain.link_width.value = mylink.width;
599 
600 document.frmMain.link_bandwidth_in.value = mylink.bw_in;
601 
602 if (mylink.bw_in == mylink.bw_out)
603 {
604 document.frmMain.link_bandwidth_out.value = '';
605 document.frmMain.link_bandwidth_out_cb.checked = 1;
606 }
607 
608 else
609 {
610 document.frmMain.link_bandwidth_out_cb.checked = 0;
611 document.frmMain.link_bandwidth_out.value = mylink.bw_out;
612 }
613 
614 document.frmMain.link_infourl.value = mylink.infourl;
615 document.frmMain.link_hover.value = mylink.overliburl;
616 
61785simandl document.frmMain.link_commentin.value = mylink.commentin;
618 document.frmMain.link_commentout.value = mylink.commentout;
619 document.frmMain.link_commentposin.value = mylink.commentposin;
620 document.frmMain.link_commentposout.value = mylink.commentposout;
621 
622 // if that didn't "stick", then we need to add the special value
623 if( jQuery('#link_commentposout').val() != mylink.commentposout)
624 {
625 jQuery('#link_commentposout').prepend("<option selected value='" + mylink.commentposout + "'>" + mylink.commentposout + "%</option>");
626 }
627 
628 if( jQuery('#link_commentposin').val() != mylink.commentposin)
629 {
630 jQuery('#link_commentposin').prepend("<option selected value='" + mylink.commentposin + "'>" + mylink.commentposin + "%</option>");
631 }
632 
6331simandl document.getElementById('link_nodename1').firstChild.nodeValue = mylink.a;
634 document.getElementById('link_nodename1a').firstChild.nodeValue = mylink.a;
635 document.getElementById('link_nodename1b').firstChild.nodeValue = mylink.a;
636 
637 document.getElementById('link_nodename2').firstChild.nodeValue = mylink.b;
638 
639 document.getElementById('param').value = mylink.name;
640 
641 document.frmMain.action.value = "set_link_properties";
642 
643 show_dialog('dlgLinkProperties');
64485simandl document.getElementById('link_bandwidth_in').focus();
6451simandl }
646 }
647 
648function show_dialog(dlg)
649 {
650 document.getElementById(dlg).style.display = 'block';
651 }
652 
653function hide_dialog(dlg)
654 {
655 document.getElementById(dlg).style.display = 'none';
656 // reset the action. The use pressed Cancel, if this function was called
657 // (that, or they're about to open a new Properties dialog, so the value is irrelevant)
658 document.frmMain.action.value = '';
659 // alert('ACTION=' + document.frmMain.action.value);
660 }
661 
662function hide_all_dialogs()
663 {
664 hide_dialog('dlgMapProperties');
665 hide_dialog('dlgMapStyle');
666 hide_dialog('dlgLinkProperties');
66785simandl hide_dialog('dlgTextEdit');
6681simandl hide_dialog('dlgNodeProperties');
669 hide_dialog('dlgColours');
670 hide_dialog('dlgImages');
67185simandl hide_dialog('dlgEditorSettings');
6721simandl }
67385simandl 
674function ElementPosition(param){
675 var x=0, y=0;
676 var obj = (typeof param == "string") ? document.getElementById(param) : param;
677 if (obj) {
678 x = obj.offsetLeft;
679 y = obj.offsetTop;
680 var body = document.getElementsByTagName('body')[0];
681 while (obj.offsetParent && obj!=body){
682 x += obj.offsetParent.offsetLeft;
683 y += obj.offsetParent.offsetTop;
684 obj = obj.offsetParent;
685 }
686 }
687 this.x = x;
688 this.y = y;
689}
690 
691function coord_capture(event)
692{
693 // $('#tb_coords').html('+++');
694}
695 
696function coord_update(event)
697{
698 var cursorx = event.pageX;
699 var cursory = event.pageY;
700 
701 // Adjust for coords relative to the image, not the document
702 var p = new ElementPosition('xycapture');
703 cursorx -= p.x;
704 cursory -= p.y;
705 cursory++; // fudge to make coords match results from imagemap (not sure why this is needed)
706 
707 jQuery('#tb_coords').html('Position<br />'+ cursorx + ', ' + cursory);
708}
709 
710function coord_release(event)
711{
712 jQuery('#tb_coords').html('Position<br />---, ---');
713}
714 
715function align_link_h()
716{
717 document.getElementById('action').value = "link_align_horizontal";
718 document.frmMain.submit();
719}
720 
721function align_link_v()
722{
723 document.getElementById('action').value = "link_align_vertical";
724 document.frmMain.submit();
725}
726 
727function attach_help_events()
728{
729 // add an onblur/onfocus handler to all the visible <input> items
730 
731 jQuery("input").focus(help_handler).blur(help_handler);
732}

Powered by WebSVN 2.2.1