1 var sURL = window.location.pathname + location.search;
3 var _save_page_interval = 0;
4 var current_interval = 0;
6 var _save_scroll = true;
8 $(document).ready(function() {
10 var content_div = $( "body > .container > #content" ),
11 header_div = $( "body > .container >#header" ),
14 function fit_content () {
15 var height = body.height() - header_div.outerHeight();
16 content_div.css( "height", height + "px" );
19 $(window).bind( "resize", fit_content );
22 // make scroll memory cookie to be reset
23 // when actively clicking on a link.
24 $('body').on('click', 'a', function() {
33 // stop widgets from trying to reload once user clicked
35 $('#menu a').click(function() {_is_refreshing = true;});
37 if ($.fn.contextMenu) {
38 $("body").contextMenu({
39 menu: 'property_menu', use_prop:true
41 function(action, elem){
42 object_action(action, elem.attr('id'));
43 }, ".obj_properties:not(.white)");
45 $("body").contextMenu({
46 menu: 'svc_property_menu', use_prop:true
48 function(action, elem){
49 object_action(action, elem.attr('id'));
50 },".svc_obj_properties");
53 // refresh helper code
55 var refresh_is_paused = false;
56 $("#ninja_refresh_control").bind('change', function() {
57 if ($("#ninja_refresh_control").attr('checked')) {
58 // save previous refresh rate
59 // to be able to restore it later
60 old_refresh = current_interval;
61 $('#ninja_refresh_lable').css('font-weight', 'bold');
63 refresh_is_paused = true;
65 // restore previous refresh rate
66 ninja_refresh(old_refresh);
67 refresh_is_paused = false;
68 $('#ninja_refresh_lable').css('font-weight', '');
71 if ($('#ninja_refresh_edit').text()!=='') {
72 create_slider('ninja_page_refresh');
73 $('#ninja_page_refresh_slider').on('slidechange', function() {
74 var delay = parseInt($('#ninja_page_refresh_value').val(), 10);
75 $.jGrowl(sprintf(_page_refresh_msg, delay), { header: _success_header });
79 $('#ninja_refresh_edit').bind('click', function() {
81 $('#ninja_page_refresh_slider').show();
84 $('#ninja_page_refresh_slider').hide();
88 // -- end refresh helper code
90 // listview refresh helper code
91 $("#listview_refresh_control").bind('change', function() {
92 if ($("#listview_refresh_control").attr('checked')) {
93 // save previous refresh rate
94 // to be able to restore it later
95 $('#listview_refresh_lable').css('font-weight', 'bold');
96 clearTimeout(lsfilter_storage.list.autorefresh_timer);
97 $.jGrowl(_listview_refresh_paused_msg, { header: _success_header });
99 // restore previous refresh rate
100 $('#listview_refresh_lable').css('font-weight', '');
101 lsfilter_storage.list.start_autorefresh_timer();
102 $.jGrowl(_listview_refresh_unpaused_msg, { header: _success_header });
105 $("#listview_refresh_value").bind('change', function() {
106 $("#listview_refresh_slider").slider("value", this.value);
108 if ($('#listview_refresh_edit').text()!=='') {
109 create_slider('listview_refresh');
110 $('#listview_refresh_slider').on('slidechange', function() {
111 var delay = parseInt($('#listview_refresh_value').val(), 10);
112 $.jGrowl(sprintf(_listview_refresh_msg, delay), { header: _success_header });
113 clearTimeout(lsfilter_storage.list.autorefresh_timer);
115 lsfilter_storage.list.config.autorefresh_enabled = true;
117 lsfilter_storage.list.config.autorefresh_enabled = false;
119 lsfilter_storage.list.config.autorefresh_delay = delay * 1000;
120 lsfilter_storage.list.start_autorefresh_timer();
123 // -- end listview refresh helper code
125 $('.host_comment').each(function() {
126 var anchor = $(this);
127 var obj_name = anchor.data('obj_name');
133 // Remove the tooltip of the inner element since it overlays qtip
134 anchor.find('span').attr('title', '');
136 anchor.qtip($.extend(true, {}, qtip_default, {
138 text: function(ev, api) {
140 url: _site_domain + _index_page + "/ajax/fetch_comments/",
141 data: {host: obj_name}
143 .done(function(html) {
144 api.set('content.text', html);
146 .fail(function(xhr, status, error) {
147 api.set('content.text', status + ': ' + error);
150 return '<img src="' + _site_domain + loading_img + '" alt="' + _loading_str + '" />';
156 $(".helptext_target").each(function(){
158 // split the id into controller, key
159 var the_id = $(this).attr('id');
160 var part = the_id.split('|');
164 var controller = part[1];
166 var elem_id = the_id;
168 $(this).qtip($.extend(true, {}, qtip_default, {
170 text: function(ev, api) {
172 url: _site_domain + _index_page + "/ajax/get_translation/",
173 data: {controller: controller, key: key},
176 .done(function(html) {
177 api.set('content.text', html);
179 .fail(function(xhr, status, error) {
180 api.set('content.text', status + ': ' + error);
183 return '<img src="' + _site_domain + loading_img + '" alt="' + _loading_str + '" />';
188 $(".helptext_target").click(function() {return false;});
190 $('#multi_action_select').bind('change', function() {
191 multi_action_select($(this).find('option:selected').val());
194 $('.select_all_items_service').live('click', function() {
195 if ($(this).attr('checked')) {
196 $(this).parents('table').find(".item_select_service input[type='checkbox']").not('.select_all_items_service').each(function() {
197 if (!$(this).attr('disabled') && !$(this).is(':hidden')) {
198 $(this).attr('checked', true);
200 else if ($(this).is(':hidden')) {
201 $(this).attr('checked', false);
205 $(this).parents('table').find(".item_select_service input[type='checkbox']").not('.select_all_items_service').each(function() {
206 $(this).attr('checked', false);
210 // Toggle visibility for quick menu items
211 $("#page_settings_icon, #global_notifications_icon").click(function() {
212 var menu_item = $(this);
213 var li = menu_item.parents('li');
214 var submenu = $('#'+menu_item[0].id.replace(/_icon$/, ''));
215 if (submenu.is(':hidden')) {
216 li.addClass("selected");
220 .css('left', (menu_item.offset().left - 10) + 'px');
223 li.removeClass("selected");
229 // are we using keyboard commands or not
230 if (_keycommands_active) {
231 if (typeof _keycommand_forward !== 'undefined' && _keycommand_forward !== '') {
232 jQuery(document).bind('keydown', _keycommand_forward, function (evt){
233 if (typeof $('.nextpage').attr('href') != 'undefined') {
234 // reset scroll memory to start at top for next page
235 _save_scroll = false;
236 self.location.href=$('.nextpage').attr('href');
242 if (typeof _keycommand_back !== 'undefined' && _keycommand_back !== '') {
243 jQuery(document).bind('keydown', _keycommand_back, function (evt){
244 if (typeof $('.prevpage').attr('href') != 'undefined') {
245 // reset scroll memory to start at top for previous page
246 _save_scroll = false;
247 self.location.href=$('.prevpage').attr('href');
253 if (typeof _keycommand_search !== 'undefined' && _keycommand_search !== '') {
254 jQuery(document).bind('keydown', _keycommand_search, function (evt){$('#query').focus(); return false; });
257 if (typeof _keycommand_pause !== 'undefined' && _keycommand_pause !== '') {
258 jQuery(document).bind('keydown', _keycommand_pause, function (evt){
266 * Toggle page refresh and show a jGrowl message to user about state
268 function toggle_refresh()
270 if ($("#ninja_refresh_control").attr('checked')) {
271 // restore previous refresh rate
272 ninja_refresh(old_refresh);
273 refresh_is_paused = false;
274 $('#ninja_refresh_lable').css('font-weight', '');
275 $("#ninja_refresh_control").attr('checked', false);
278 $.jGrowl(_refresh_unpaused_msg, { header: _success_header });
280 // Prevent message from showing up when no pause is available
281 if ($("#ninja_page_refresh").html() === null) {
285 $("#ninja_refresh_control").attr('checked', true);
286 // save previous refresh rate
287 // to be able to restore it later
288 old_refresh = current_interval;
289 $('#ninja_refresh_lable').css('font-weight', 'bold');
291 refresh_is_paused = true;
294 $.jGrowl(_refresh_paused_msg, { header: _success_header });
298 $('#multi_object_submit_service').click(function() {
299 // check that we have any selected items
300 if (!$('.item_select_service input[name=object_select\\[\\]]').is(':checked')) {
301 show_message("multi_object_submit_progress_service", _nothing_selected_error);
305 // Check if we actually set an action
306 if ($('#multi_action_select_service').val() === "") {
307 show_message("multi_object_submit_progress_service", _no_action_error);
311 show_progress("multi_object_submit_progress_service", _wait_str);
314 $('#multi_object_submit').click(function() {
315 // check that we have any selected items
316 if (!$('.item_select input[name=object_select\\[\\]]').is(':checked')) {
317 show_message("multi_object_submit_progress", _nothing_selected_error);
321 // Check if we actually set an action
322 if ($('#multi_action_select').val() === "") {
323 show_message("multi_object_submit_progress", _no_action_error);
327 show_progress("multi_object_submit_progress", _wait_str);
334 // console.log('To translate: '+ text);
338 var loadimg_sml = new Image(16,16);
339 loadimg_sml.src = _site_domain + 'application/media/images/loading_small.gif';
342 * cache the progress indicator image to show faster...
344 var Image1 = new Image(16,16);
345 Image1.src = _site_domain + 'application/media/images/loading.gif';
348 * Show a progress indicator to inform user that something
351 function show_progress(the_id, info_str, size_str) {
353 case "small": case "tiny":
354 size_str = loadimg_sml.src;
356 case "large": case "big":
357 size_str = Image1.src;
360 size_str = loadimg_sml.src;
363 $("#" + the_id).html('<img id="progress_image_id" src="' + size_str + '"> <em>' + info_str +'</em>').show();
366 function show_message(the_id, info_str) {
367 $("#" + the_id).html('<em>' + info_str +'</em>').show();
370 function switch_image(html_id, src)
372 $('#' + html_id).attr('src', src);
375 function object_action(action,the_id)
377 var parts = the_id.split('|');
381 switch(parts.length) {
384 case 2: // host or groups
401 case 'schedule_host_downtime':
402 case 'schedule_svc_downtime':
403 case 'del_host_downtime':
404 case 'del_svc_downtime':
405 case 'acknowledge_host_problem':
406 case 'acknowledge_svc_problem':
407 case 'disable_host_svc_notifications':
408 case 'disable_host_check':
409 case 'disable_svc_check':
410 case 'enable_host_check':
411 case 'enable_svc_check':
412 case 'schedule_host_check':
413 case 'schedule_host_svc_checks':
414 case 'schedule_svc_check':
415 case 'add_host_comment':
416 case 'add_svc_comment':
417 cmd = action.toUpperCase();
419 case 'remove_acknowledgement':
420 cmd = type == 'host' ? 'REMOVE_HOST_ACKNOWLEDGEMENT' : 'REMOVE_SVC_ACKNOWLEDGEMENT';
422 case 'disable_notifications':
423 cmd = type == 'host' ? 'DISABLE_HOST_NOTIFICATIONS' : 'DISABLE_SVC_NOTIFICATIONS';
425 case 'enable_notifications':
426 cmd = type == 'host' ? 'ENABLE_HOST_NOTIFICATIONS' : 'ENABLE_SVC_NOTIFICATIONS';
430 // return if we couldn't figure out what command to run
435 var target = _site_domain + _index_page + '/command/submit?cmd_typ=' + cmd + '&host_name=' + name;
436 if (service !== false) {
437 target += '&service=' + service;
439 self.location.href = target;
443 * Handle multi select of different actions
445 function multi_action_select(action, type)
447 // start by enabling all checkboxes in case
448 // they have been previously disabled
449 var field = 'item_select';
450 var prop_field = 'obj_prop';
451 if (type == 'service') {
452 $(".item_select_service input[type='checkbox']").attr('disabled', false);
453 field = 'item_select_service';
454 prop_field = 'obj_prop_service';
456 $(".item_select input[type='checkbox']").attr('disabled', false);
462 var ACKNOWLEDGED = 1;
463 var NOTIFICATIONS_ENABLED = 2;
464 var CHECKS_ENABLED = 4;
465 var SCHEDULED_DT = 8;
467 $('.' + prop_field).each(function() {
471 case 'ACKNOWLEDGE_HOST_PROBLEM':
472 case 'ACKNOWLEDGE_SVC_PROBLEM':
473 test = that.text() & ACKNOWLEDGED || !(that.text() & 16);
475 case 'REMOVE_HOST_ACKNOWLEDGEMENT':
476 case 'REMOVE_SVC_ACKNOWLEDGEMENT':
477 test = !(that.text() & ACKNOWLEDGED);
479 case 'DISABLE_HOST_NOTIFICATIONS':
480 case 'DISABLE_SVC_NOTIFICATIONS':
481 test = that.text() & NOTIFICATIONS_ENABLED;
483 case 'ENABLE_HOST_NOTIFICATIONS':
484 case 'ENABLE_SVC_NOTIFICATIONS':
485 test = !(that.text() & NOTIFICATIONS_ENABLED);
487 case 'ENABLE_HOST_CHECK':
488 case 'ENABLE_SVC_CHECK':
489 test = !(that.text() & CHECKS_ENABLED);
491 case 'DISABLE_HOST_CHECK':
492 case 'DISABLE_SVC_CHECK':
493 test = that.text() & CHECKS_ENABLED;
495 case 'DEL_HOST_DOWNTIME':
496 case 'DEL_SVC_DOWNTIME':
497 test = !(that.text() & SCHEDULED_DT);
501 that.closest('tr').find("." + field + " input[type='checkbox']").attr('disabled', true).attr('checked', false);
506 function create_slider(the_id)
508 var last_update_request = false;
509 var id = $('#' + the_id + '_value');
510 var key = id.data('key');
511 var interval = id.val();
512 $("#" + the_id + "_slider").slider({
517 slide: function(event, ui) {
518 $("#" + the_id + "_value").val(ui.value);
520 stop: function(event, ui) {
522 if(last_update_request !== false) {
523 last_update_request.abort();
525 last_update_request = $.ajax(
526 _site_domain + _index_page + "/ajax/save_page_setting/",
533 complete: function() {
534 last_update_request = false;
542 id.val($("#" + the_id + "_slider").slider("value"));
545 function ninja_refresh(val)
548 clearInterval(_interval);
550 var refresh_val = (val === null) ? _refresh : val;
551 current_interval = refresh_val;
553 _interval = setInterval( "refresh()", refresh_val*1000 );
557 function jgrowl_message(message_str, header_str)
559 if (message_str!=='') {
560 $.jGrowl(message_str, { header: header_str });
565 // ===========================================================
566 // code for remembering scroll position between page reloads
567 // adapted from http://www.huntingground.freeserve.co.uk/main/mainfram.htm?../scripts/cookies/scrollpos.htm
568 // ===========================================================
570 cookieName = "page_scroll";
573 function setCookie(name, value, expires, path, domain, secure) {
575 expires = new Date();
577 document.cookie = name + "=" + escape(value) +
578 ((expires === null) ? "" : "; expires=" + expires.toGMTString()) +
579 ((path === null) ? "" : "; path=" + path) +
580 ((domain === null) ? "" : "; domain=" + domain) +
581 ((secure === null) ? "" : "; secure");
584 function getCookie(name) {
585 var arg = name + "=";
586 var alen = arg.length;
587 var clen = document.cookie.length;
591 if (document.cookie.substring(i, j) == arg){
592 return getCookieVal(j);
594 i = document.cookie.indexOf(" ", i) + 1;
602 function getCookieVal(offset) {
603 var endstr = document.cookie.indexOf (";", offset);
605 endstr = document.cookie.length;
607 return unescape(document.cookie.substring(offset, endstr));
610 function deleteCookie(name,path,domain) {
611 document.cookie = name + "=" + ((path === null) ? "" : "; path=" + path) + ((domain === null) ? "" : "; domain=" + domain) + "; expires=Thu, 01-Jan-00 00:00:01 GMT";
614 function saveScroll() {
615 var expdate = new Date();
616 expdate.setTime (expdate.getTime() + (expdays*24*60*60*1000)); // expiry date
619 // reset scroll memory to top
620 setCookie(cookieName,'0_0',expdate);
624 var x = $(window).scrollLeft();
625 var y = $(window).scrollTop();
628 setCookie(cookieName,Data,expdate);
631 $(window).bind('beforeunload', saveScroll);
633 function loadScroll() { // added function
634 inf = getCookie(cookieName);
638 var ar = inf.split("_");
639 if (ar.length == 2) {
640 $(window).scrollLeft(parseInt(ar[0], 10));
641 $(window).scrollTop(parseInt(ar[1], 10));
645 $(window).bind('load', loadScroll);
647 function trigger_cb_on_nth_call(cb, n) {