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(){
157 // split the id into controller, key
158 var controller = $(this).data('helptext-controller');
159 var key = $(this).data('helptext-key');
160 bind_helptext($(this), controller, key);
162 $('body').on('click', ".helptext_target", function() {return false;});
164 $('#multi_action_select').bind('change', function() {
165 multi_action_select($(this).find('option:selected').val());
168 $('.select_all_items_service').live('click', function() {
169 if ($(this).attr('checked')) {
170 $(this).parents('table').find(".item_select_service input[type='checkbox']").not('.select_all_items_service').each(function() {
171 if (!$(this).attr('disabled') && !$(this).is(':hidden')) {
172 $(this).attr('checked', true);
174 else if ($(this).is(':hidden')) {
175 $(this).attr('checked', false);
179 $(this).parents('table').find(".item_select_service input[type='checkbox']").not('.select_all_items_service').each(function() {
180 $(this).attr('checked', false);
184 // Toggle visibility for quick menu items
185 $("#page_settings_icon, #global_notifications_icon").click(function() {
186 var menu_item = $(this);
187 var li = menu_item.parents('li');
188 var submenu = $('#'+menu_item[0].id.replace(/_icon$/, ''));
189 if (submenu.is(':hidden')) {
190 li.addClass("selected");
194 .css('left', (menu_item.offset().left - 10) + 'px');
197 li.removeClass("selected");
203 // are we using keyboard commands or not
204 if (_keycommands_active) {
205 if (typeof _keycommand_forward !== 'undefined' && _keycommand_forward !== '') {
206 jQuery(document).bind('keydown', _keycommand_forward, function (evt){
207 if (typeof $('.nextpage').attr('href') != 'undefined') {
208 // reset scroll memory to start at top for next page
209 _save_scroll = false;
210 self.location.href=$('.nextpage').attr('href');
216 if (typeof _keycommand_back !== 'undefined' && _keycommand_back !== '') {
217 jQuery(document).bind('keydown', _keycommand_back, function (evt){
218 if (typeof $('.prevpage').attr('href') != 'undefined') {
219 // reset scroll memory to start at top for previous page
220 _save_scroll = false;
221 self.location.href=$('.prevpage').attr('href');
227 if (typeof _keycommand_search !== 'undefined' && _keycommand_search !== '') {
228 jQuery(document).bind('keydown', _keycommand_search, function (evt){$('#query').focus(); return false; });
231 if (typeof _keycommand_pause !== 'undefined' && _keycommand_pause !== '') {
232 jQuery(document).bind('keydown', _keycommand_pause, function (evt){
240 * Toggle page refresh and show a jGrowl message to user about state
242 function toggle_refresh()
244 if ($("#ninja_refresh_control").attr('checked')) {
245 // restore previous refresh rate
246 ninja_refresh(old_refresh);
247 refresh_is_paused = false;
248 $('#ninja_refresh_lable').css('font-weight', '');
249 $("#ninja_refresh_control").attr('checked', false);
252 $.jGrowl(_refresh_unpaused_msg, { header: _success_header });
254 // Prevent message from showing up when no pause is available
255 if ($("#ninja_page_refresh").html() === null) {
259 $("#ninja_refresh_control").attr('checked', true);
260 // save previous refresh rate
261 // to be able to restore it later
262 old_refresh = current_interval;
263 $('#ninja_refresh_lable').css('font-weight', 'bold');
265 refresh_is_paused = true;
268 $.jGrowl(_refresh_paused_msg, { header: _success_header });
272 $('#multi_object_submit_service').click(function() {
273 // check that we have any selected items
274 if (!$('.item_select_service input[name=object_select\\[\\]]').is(':checked')) {
275 show_message("multi_object_submit_progress_service", _nothing_selected_error);
279 // Check if we actually set an action
280 if ($('#multi_action_select_service').val() === "") {
281 show_message("multi_object_submit_progress_service", _no_action_error);
285 show_progress("multi_object_submit_progress_service", _wait_str);
288 $('#multi_object_submit').click(function() {
289 // check that we have any selected items
290 if (!$('.item_select input[name=object_select\\[\\]]').is(':checked')) {
291 show_message("multi_object_submit_progress", _nothing_selected_error);
295 // Check if we actually set an action
296 if ($('#multi_action_select').val() === "") {
297 show_message("multi_object_submit_progress", _no_action_error);
301 show_progress("multi_object_submit_progress", _wait_str);
308 // console.log('To translate: '+ text);
312 var loadimg_sml = new Image(16,16);
313 loadimg_sml.src = _site_domain + 'application/media/images/loading_small.gif';
316 * cache the progress indicator image to show faster...
318 var Image1 = new Image(16,16);
319 Image1.src = _site_domain + 'application/media/images/loading.gif';
322 * Show a progress indicator to inform user that something
325 function show_progress(the_id, info_str, size_str) {
327 case "small": case "tiny":
328 size_str = loadimg_sml.src;
330 case "large": case "big":
331 size_str = Image1.src;
334 size_str = loadimg_sml.src;
337 $("#" + the_id).html('<img id="progress_image_id" src="' + size_str + '"> <em>' + info_str +'</em>').show();
340 function show_message(the_id, info_str) {
341 $("#" + the_id).html('<em>' + info_str +'</em>').show();
344 function switch_image(html_id, src)
346 $('#' + html_id).attr('src', src);
349 function object_action(action,the_id)
351 var parts = the_id.split('|');
355 switch(parts.length) {
358 case 2: // host or groups
375 case 'schedule_host_downtime':
376 case 'schedule_svc_downtime':
377 case 'del_host_downtime':
378 case 'del_svc_downtime':
379 case 'acknowledge_host_problem':
380 case 'acknowledge_svc_problem':
381 case 'disable_host_svc_notifications':
382 case 'disable_host_check':
383 case 'disable_svc_check':
384 case 'enable_host_check':
385 case 'enable_svc_check':
386 case 'schedule_host_check':
387 case 'schedule_host_svc_checks':
388 case 'schedule_svc_check':
389 case 'add_host_comment':
390 case 'add_svc_comment':
391 cmd = action.toUpperCase();
393 case 'remove_acknowledgement':
394 cmd = type == 'host' ? 'REMOVE_HOST_ACKNOWLEDGEMENT' : 'REMOVE_SVC_ACKNOWLEDGEMENT';
396 case 'disable_notifications':
397 cmd = type == 'host' ? 'DISABLE_HOST_NOTIFICATIONS' : 'DISABLE_SVC_NOTIFICATIONS';
399 case 'enable_notifications':
400 cmd = type == 'host' ? 'ENABLE_HOST_NOTIFICATIONS' : 'ENABLE_SVC_NOTIFICATIONS';
404 // return if we couldn't figure out what command to run
409 var target = _site_domain + _index_page + '/command/submit?cmd_typ=' + cmd + '&host_name=' + name;
410 if (service !== false) {
411 target += '&service=' + service;
413 self.location.href = target;
417 * Handle multi select of different actions
419 function multi_action_select(action, type)
421 // start by enabling all checkboxes in case
422 // they have been previously disabled
423 var field = 'item_select';
424 var prop_field = 'obj_prop';
425 if (type == 'service') {
426 $(".item_select_service input[type='checkbox']").attr('disabled', false);
427 field = 'item_select_service';
428 prop_field = 'obj_prop_service';
430 $(".item_select input[type='checkbox']").attr('disabled', false);
436 var ACKNOWLEDGED = 1;
437 var NOTIFICATIONS_ENABLED = 2;
438 var CHECKS_ENABLED = 4;
439 var SCHEDULED_DT = 8;
441 $('.' + prop_field).each(function() {
445 case 'ACKNOWLEDGE_HOST_PROBLEM':
446 case 'ACKNOWLEDGE_SVC_PROBLEM':
447 test = that.text() & ACKNOWLEDGED || !(that.text() & 16);
449 case 'REMOVE_HOST_ACKNOWLEDGEMENT':
450 case 'REMOVE_SVC_ACKNOWLEDGEMENT':
451 test = !(that.text() & ACKNOWLEDGED);
453 case 'DISABLE_HOST_NOTIFICATIONS':
454 case 'DISABLE_SVC_NOTIFICATIONS':
455 test = that.text() & NOTIFICATIONS_ENABLED;
457 case 'ENABLE_HOST_NOTIFICATIONS':
458 case 'ENABLE_SVC_NOTIFICATIONS':
459 test = !(that.text() & NOTIFICATIONS_ENABLED);
461 case 'ENABLE_HOST_CHECK':
462 case 'ENABLE_SVC_CHECK':
463 test = !(that.text() & CHECKS_ENABLED);
465 case 'DISABLE_HOST_CHECK':
466 case 'DISABLE_SVC_CHECK':
467 test = that.text() & CHECKS_ENABLED;
469 case 'DEL_HOST_DOWNTIME':
470 case 'DEL_SVC_DOWNTIME':
471 test = !(that.text() & SCHEDULED_DT);
475 that.closest('tr').find("." + field + " input[type='checkbox']").attr('disabled', true).attr('checked', false);
480 function create_slider(the_id)
482 var last_update_request = false;
483 var id = $('#' + the_id + '_value');
484 var key = id.data('key');
485 var interval = id.val();
486 $("#" + the_id + "_slider").slider({
491 slide: function(event, ui) {
492 $("#" + the_id + "_value").val(ui.value);
494 stop: function(event, ui) {
496 if(last_update_request !== false) {
497 last_update_request.abort();
499 last_update_request = $.ajax(
500 _site_domain + _index_page + "/ajax/save_page_setting/",
507 complete: function() {
508 last_update_request = false;
516 id.val($("#" + the_id + "_slider").slider("value"));
519 function ninja_refresh(val)
522 clearInterval(_interval);
524 var refresh_val = (val === null) ? _refresh : val;
525 current_interval = refresh_val;
527 _interval = setInterval( "refresh()", refresh_val*1000 );
531 function jgrowl_message(message_str, header_str)
533 if (message_str!=='') {
534 $.jGrowl(message_str, { header: header_str });
539 // ===========================================================
540 // code for remembering scroll position between page reloads
541 // adapted from http://www.huntingground.freeserve.co.uk/main/mainfram.htm?../scripts/cookies/scrollpos.htm
542 // ===========================================================
544 cookieName = "page_scroll";
547 function setCookie(name, value, expires, path, domain, secure) {
549 expires = new Date();
551 document.cookie = name + "=" + escape(value) +
552 ((expires === null) ? "" : "; expires=" + expires.toGMTString()) +
553 ((path === null) ? "" : "; path=" + path) +
554 ((domain === null) ? "" : "; domain=" + domain) +
555 ((secure === null) ? "" : "; secure");
558 function getCookie(name) {
559 var arg = name + "=";
560 var alen = arg.length;
561 var clen = document.cookie.length;
565 if (document.cookie.substring(i, j) == arg){
566 return getCookieVal(j);
568 i = document.cookie.indexOf(" ", i) + 1;
576 function getCookieVal(offset) {
577 var endstr = document.cookie.indexOf (";", offset);
579 endstr = document.cookie.length;
581 return unescape(document.cookie.substring(offset, endstr));
584 function deleteCookie(name,path,domain) {
585 document.cookie = name + "=" + ((path === null) ? "" : "; path=" + path) + ((domain === null) ? "" : "; domain=" + domain) + "; expires=Thu, 01-Jan-00 00:00:01 GMT";
588 function saveScroll() {
589 var expdate = new Date();
590 expdate.setTime (expdate.getTime() + (expdays*24*60*60*1000)); // expiry date
593 // reset scroll memory to top
594 setCookie(cookieName,'0_0',expdate);
598 var x = $(window).scrollLeft();
599 var y = $(window).scrollTop();
602 setCookie(cookieName,Data,expdate);
605 $(window).bind('beforeunload', saveScroll);
607 function loadScroll() { // added function
608 inf = getCookie(cookieName);
612 var ar = inf.split("_");
613 if (ar.length == 2) {
614 $(window).scrollLeft(parseInt(ar[0], 10));
615 $(window).scrollTop(parseInt(ar[1], 10));
619 $(window).bind('load', loadScroll);
621 function trigger_cb_on_nth_call(cb, n) {
628 function bind_helptext(element, controller, key) {
629 element.qtip($.extend(true, {}, qtip_default, {
631 text: function(ev, api) {
633 url: _site_domain + _index_page + "/ajax/get_translation/",
634 data: {controller: controller, key: key},
637 .done(function(html) {
638 api.set('content.text', html);
640 .fail(function(xhr, status, error) {
641 api.set('content.text', status + ': ' + error);
644 return '<img src="' + _site_domain + loading_img + '" alt="' + _loading_str + '" />';