if(typeof(locale) == "undefined") var locale = {};
locale['S_MAX_COOKIE_SIZE_REACHED'] = 'We are sorry, the maximum possible number of elements to remember has been reached.';locale['S_CLOSE'] = 'Close';locale['S_NO_ELEMENTS_SELECTED'] = 'No elements selected!';locale['DO_YOU_REPLACE_CONDITIONAL_EXPRESSION_Q'] = 'Do you wish to replace the conditional expression?';locale['S_INSERT_MACRO'] = 'Insert macro';locale['S_CREATE_LOG_TRIGGER'] = 'Create trigger';locale['S_DELETE'] = 'Delete';locale['S_DELETE_KEYWORD_Q'] = 'Delete keyword?';locale['S_DELETE_EXPRESSION_Q'] = 'Delete expression?';locale['S_SIMPLE_GRAPHS'] = 'Simple graphs';locale['S_HISTORY'] = 'History';locale['S_HISTORY_AND_SIMPLE_GRAPHS'] = 'History and simple graphs';locale['Host screens'] = 'Host screens';locale['Go to'] = 'Go to';locale['Latest data'] = 'Latest data';locale['Scripts'] = 'Scripts';locale['Host inventories'] = 'Host inventories';locale['Add service'] = 'Add service';locale['Edit service'] = 'Edit service';locale['Delete service'] = 'Delete service';locale['Delete the selected service?'] = 'Delete the selected service?';locale['S_MUTE'] = 'Mute';locale['S_UNMUTE'] = 'Unmute';locale['S_MESSAGES'] = 'Messages';locale['S_CLEAR'] = 'Clear';locale['S_SNOOZE'] = 'Snooze';locale['S_MOVE'] = 'Move';/* Prototype JavaScript framework, version 1.6.1
* (c) 2005-2009 Sam Stephenson
*
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://www.prototypejs.org/
*
*--------------------------------------------------------------------------*/
var Prototype = {
Version: '1.6.1',
Browser: (function(){
var ua = navigator.userAgent;
var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
return {
IE: !!window.attachEvent && !isOpera,
Opera: isOpera,
WebKit: ua.indexOf('AppleWebKit/') > -1,
Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
MobileSafari: /Apple.*Mobile.*Safari/.test(ua)
}
})(),
BrowserFeatures: {
XPath: !!document.evaluate,
SelectorsAPI: !!document.querySelector,
ElementExtensions: (function() {
var constructor = window.Element || window.HTMLElement;
return !!(constructor && constructor.prototype);
})(),
SpecificElementExtensions: (function() {
if (typeof window.HTMLDivElement !== 'undefined')
return true;
var div = document.createElement('div');
var form = document.createElement('form');
var isSupported = false;
if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
isSupported = true;
}
div = form = null;
return isSupported;
})()
},
ScriptFragment: '
* Elements with class 'blink' will blink for 'data-seconds-to-blink' seconds
* If 'data-seconds-to-blink' is omitted, element will blink forever.
* @author Konstantin Buravcov
*/
var jqBlink = {
shown: false, // are objects currently shown or hidden?
blinkInterval: 1000, // how fast will they blink (ms)
secondsSinceInit: 0,
/**
* Shows/hides the elements and repeats it self after 'this.blinkInterval' ms
*/
blink: function() {
var objects = jQuery('.blink');
// maybe some of the objects should not blink any more?
objects = this.filterOutNonBlinking(objects);
// changing visibility state
objects.css('visibility', this.shown ? 'hidden' : 'visible');
// reversing the value of indicator attribute
this.shown = !this.shown;
// I close my eyes only for a moment, and a moment's gone
this.secondsSinceInit += this.blinkInterval / 1000;
// repeating this function with delay
setTimeout(jQuery.proxy(this.blink, this), this.blinkInterval);
},
/**
* Check all currently found objects and exclude ones that should stop blinking by now
*/
filterOutNonBlinking: function(objects) {
var that = this;
return objects.filter(function() {
var obj = jQuery(this);
if (typeof obj.data('timeToBlink') !== 'undefined') {
var shouldBlink = parseInt(obj.data('timeToBlink'), 10) > that.secondsSinceInit;
// if object stops blinking, it should be left visible
if (!shouldBlink && !that.shown) {
obj.css('visibility', 'visible');
}
return shouldBlink;
}
else {
// no time-to-blink attribute, should blink forever
return true;
}
});
}
};
/*
* ZABBIX HintBoxes
*/
var hintBox = {
createBox: function(e, target, hintText, width, className, isStatic) {
var box = jQuery('
').addClass('hintbox');
if (!empty(className)) {
box.append(jQuery('').addClass(className).html(hintText));
}
else {
box.html(hintText);
}
if (!empty(width)) {
box.css('width', width + 'px');
}
if (isStatic) {
var close_link = jQuery('
' + locale['S_CLOSE'] + '
')
.addClass('link')
.css({
'text-align': 'right',
'border-bottom': '1px #333 solid'
}).click(function() {
hintBox.hideHint(e, target, true);
});
box.prepend(close_link);
}
jQuery('body').append(box);
return box;
},
HintWraper: function(e, target, hintText, width, className) {
target.isStatic = false;
jQuery(target).bind('mouseenter', function(e, d){
if (d) e = d;
hintBox.showHint(e, target, hintText, width, className, false);
}).bind('mouseleave', function(e){
hintBox.hideHint(e, target);
});
jQuery(target).removeAttr('onmouseover');
jQuery(target).trigger('mouseenter', e);
},
showStaticHint: function(e, target, hint, width, className, resizeAfterLoad) {
var isStatic = target.isStatic;
hintBox.hideHint(e, target, true);
if (!isStatic) {
target.isStatic = true;
hintBox.showHint(e, target, hint, width, className, true);
if (resizeAfterLoad) {
hint.one('load', function(e){
hintBox.positionHint(e, target);
});
}
}
},
showHint: function(e, target, hintText, width, className, isStatic) {
if (target.hintBoxItem) return;
target.hintBoxItem = hintBox.createBox(e, target, hintText, width, className, isStatic);
hintBox.positionHint(e, target);
target.hintBoxItem.show();
},
positionHint: function(e, target) {
var wWidth = jQuery(window).width(),
wHeight = jQuery(window).height(),
scrollTop = jQuery(window).scrollTop(),
scrollLeft = jQuery(window).scrollLeft(),
top, left;
// uses stored clientX on afterload positioning when there is no event
if (e.clientX) {
target.clientX = e.clientX;
target.clientY = e.clientY;
}
// doesn't fit in the screen horizontaly
if (target.hintBoxItem.width() + 10 > wWidth) {
left = scrollLeft + 2;
}
// 10px to right if fit
else if (wWidth - target.clientX - 10 > target.hintBoxItem.width()) {
left = scrollLeft + target.clientX + 10;
}
// 10px from screen right side
else {
left = scrollLeft + wWidth - 10 - target.hintBoxItem.width();
}
// 10px below if fit
if (wHeight - target.clientY - target.hintBoxItem.height() - 10 > 0) {
top = scrollTop + target.clientY + 10;
}
// 10px above if fit
else if (target.clientY - target.hintBoxItem.height() - 10 > 0) {
top = scrollTop + target.clientY - target.hintBoxItem.height() - 10;
}
// 10px below as fallback
else {
top = scrollTop + target.clientY + 10;
}
// fallback if doesnt't fit verticaly but could fit if aligned to right or left
if ((top - scrollTop + target.hintBoxItem.height() > wHeight)
&& (target.clientX - 10 > target.hintBoxItem.width() || wWidth - target.clientX - 10 > target.hintBoxItem.width())) {
// align to left if fit
if (wWidth - target.clientX - 10 > target.hintBoxItem.width()) {
left = scrollLeft + target.clientX + 10;
}
// align to right
else {
left = scrollLeft + target.clientX - target.hintBoxItem.width() - 10;
}
// 10px from bottom if fit
if (wHeight - 10 > target.hintBoxItem.height()) {
top = scrollTop + wHeight - target.hintBoxItem.height() - 10;
}
// 10px from top
else {
top = scrollTop + 10;
}
}
target.hintBoxItem.css({
'top': top + 'px',
'left': left + 'px',
'zIndex': '999'
});
},
hideHint: function(e, target, hideStatic) {
if (target.isStatic && !hideStatic) return;
if (target.hintBoxItem) {
target.hintBoxItem.remove();
delete target.hintBoxItem;
if (target.isStatic) {
delete target.isStatic;
}
}
}
};
/*
* Color picker
*/
function hide_color_picker() {
if (!color_picker) {
return;
}
color_picker.style.zIndex = 1000;
color_picker.style.visibility = 'hidden';
color_picker.style.left = '-' + ((color_picker.style.width) ? color_picker.style.width : 100) + 'px';
curr_lbl = null;
curr_txt = null;
}
function show_color_picker(id) {
if (!color_picker) {
return;
}
curr_lbl = document.getElementById('lbl_' + id);
curr_txt = document.getElementById(id);
var pos = getPosition(curr_lbl);
color_picker.x = pos.left;
color_picker.y = pos.top;
color_picker.style.left = (color_picker.x + 20) + 'px';
color_picker.style.top = color_picker.y + 'px';
color_picker.style.visibility = 'visible';
}
function create_color_picker() {
if (color_picker) {
return;
}
color_picker = document.createElement('div');
color_picker.setAttribute('id', 'color_picker');
color_picker.innerHTML = color_table;
document.body.appendChild(color_picker);
hide_color_picker();
}
function set_color(color) {
if (curr_lbl) {
curr_lbl.style.background = curr_lbl.style.color = '#' + color;
curr_lbl.title = '#' + color;
}
if (curr_txt) {
curr_txt.value = color.toString().toUpperCase();
}
hide_color_picker();
}
function set_color_by_name(id, color) {
curr_lbl = document.getElementById('lbl_' + id);
curr_txt = document.getElementById(id);
set_color(color);
}
/*
* Zabbix ajax requests
*/
function add2favorites(favobj, favid) {
if ('undefined' == typeof(Ajax)) {
throw('Prototype.js lib is required!');
}
if (typeof(favid) == 'undefined' || empty(favid)) {
return;
}
var params = {
'favobj': favobj,
'favid': favid,
'favaction': 'add'
};
send_params(params);
}
function rm4favorites(favobj, favid, menu_rowid) {
if ('undefined' == typeof(Ajax)) {
throw('Prototype.js lib is required!');
}
if (typeof(favobj) == 'undefined' || typeof(favid) == 'undefined') {
throw 'No agruments sent to function [rm4favorites()].';
}
var params = {
'favobj': favobj,
'favid': favid,
'favcnt': menu_rowid,
'favaction': 'remove'
};
send_params(params);
}
function change_flicker_state(divid) {
deselectAll();
var switchArrows = function() {
switchElementsClass($('flicker_icon_l'), 'dbl_arrow_up', 'dbl_arrow_down');
switchElementsClass($('flicker_icon_r'), 'dbl_arrow_up', 'dbl_arrow_down');
};
var filter_state = showHide(divid);
switchArrows();
if (false === filter_state) {
return false;
}
var params = {
'favaction': 'flop',
'favobj': 'filter',
'favref': divid,
'favstate': filter_state
};
send_params(params);
// selection box position
if (typeof(moveSBoxes) != 'undefined') {
moveSBoxes();
}
}
function changeHatStateUI(icon, divid) {
deselectAll();
var switchIcon = function() {
switchElementsClass(icon, 'arrowup', 'arrowdown');
};
jQuery($(divid).parentNode).
find('.body').toggle().end().
find('.footer').toggle().end();
switchIcon();
var hat_state = jQuery(icon).hasClass('arrowup') ? 1 : 0;
if (false === hat_state) {
return false;
}
var params = {
'favaction': 'flop',
'favobj': 'hat',
'favref': divid,
'favstate': hat_state
};
send_params(params);
}
function change_hat_state(icon, divid) {
deselectAll();
var switchIcon = function() {
switchElementsClass(icon, 'arrowup', 'arrowdown');
};
var hat_state = showHide(divid);
switchIcon();
if (false === hat_state) {
return false;
}
var params = {
'favaction': 'flop',
'favobj': 'hat',
'favref': divid,
'favstate': hat_state
};
send_params(params);
}
function send_params(params) {
if (typeof(params) === 'undefined') {
params = [];
}
var url = new Curl(location.href);
url.setQuery('?output=ajax');
new Ajax.Request(url.getUrl(), {
'method': 'post',
'parameters': params,
'onSuccess': function() { },
'onFailure': function() {
document.location = url.getPath() + '?' + Object.toQueryString(params);
}
}
);
}
function setRefreshRate(pmasterid, dollid, interval, params) {
if (typeof(Ajax) == 'undefined') {
throw('Prototype.js lib is required!');
}
if (typeof(params) == 'undefined' || is_null(params)) {
params = {};
}
params['pmasterid'] = pmasterid;
params['favobj'] = 'set_rf_rate';
params['favref'] = dollid;
params['favcnt'] = interval;
send_params(params);
}
function switch_mute(icon) {
deselectAll();
var sound_state = switchElementsClass(icon, 'iconmute', 'iconsound');
if (false === sound_state) {
return false;
}
sound_state = (sound_state == 'iconmute') ? 1 : 0;
var params = {
'favobj': 'sound',
'favref': 'sound',
'favstate': sound_state
};
send_params(params);
}
function createPlaceholders() {
if (IE) {
jQuery(document).ready(function() {
'use strict';
jQuery('[placeholder]').focus(function() {
if (jQuery(this).val() == jQuery(this).attr('placeholder')) {
jQuery(this).val('');
jQuery(this).removeClass('placeholder');
}
}).blur(function() {
if (jQuery(this).val() == '' || jQuery(this).val() == jQuery(this).attr('placeholder')) {
jQuery(this).addClass('placeholder');
jQuery(this).val(jQuery(this).attr('placeholder'));
}
}).blur();
});
}
}
/*
** Zabbix
** Copyright (C) 2000-2011 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
// trigger log expression
var logexpr_count = 0;
var key_count = 0;
function nextObject(n) {
var t = n.parentNode.tagName;
do {
n = n.nextSibling;
} while (n && n.nodeType != 1 && n.parentNode.tagName == t);
return n;
}
function previousObject(p) {
var t = p.parentNode.tagName;
do {
p = p.previousSibling;
} while (p && p.nodeType != 1 && p.parentNode.tagName == t);
return p;
}
function call_ins_macro_menu(ev) {
show_popup_menu(ev,
[
[locale['S_INSERT_MACRO'], null, null, {'outer' : ['pum_oheader'], 'inner' : ['pum_iheader']}],
['TRIGGER.VALUE=0', function() { set_macro(0); },
null, {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}],
['TRIGGER.VALUE=1', function() { set_macro(1); },
null, {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}],
['TRIGGER.VALUE=2', function() { set_macro(2); },
null, {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}],
['TRIGGER.VALUE#0', function() { set_macro(10); },
null, {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}],
['TRIGGER.VALUE#1', function() { set_macro(11); },
null, {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}],
['TRIGGER.VALUE#2', function() { set_macro(12); },
null, {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}]
], 150);
return false;
}
function call_triggerlog_menu(evnt, id, name, menu_options) {
var tname = locale['S_CREATE_LOG_TRIGGER'];
if (typeof(menu_options) != 'undefined') {
show_popup_menu(evnt,
[
[name, null, null, {'outer' : ['pum_oheader'], 'inner' : ['pum_iheader']}],
[tname, "javascript: openWinCentered('tr_logform.php?sform=1&itemid=" + id + "', 'TriggerLog', 760, 540, 'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');", {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}],
menu_options
], 240);
}
else {
show_popup_menu(evnt,
[
[name, null, null, {'outer' : ['pum_oheader'], 'inner' : ['pum_iheader']}],
[tname, "javascript: openWinCentered('tr_logform.php?sform=1&itemid=" + id + "', 'ServiceForm', 760, 540, 'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');", {'outer' : ['pum_o_item'], 'inner' : ['pum_i_item']}]
], 140);
}
return false;
}
function add_logexpr() {
var REGEXP_EXCLUDE = 1;
try {
var expr = document.getElementById('logexpr');
var expr_t = document.getElementById('expr_type');
var bt_and = document.getElementById('add_key_and');
var bt_or = document.getElementById('add_key_or');
var iregexp = document.getElementById('iregexp');
}
catch(e) {
throw('Error: ' + (IE ? e.description : e));
}
var ex = bt_and.disabled ? '|' : '&';
var ex_v = bt_and.disabled ? ' OR ' : ' AND ';
if (expr_t.value == REGEXP_EXCLUDE) {
ex = bt_and.disabled ? '&' : '|';
}
var expression = '';
var expr_v = '';
var lp;
for (lp = 0; lp < key_count; lp++) {
var key = document.getElementsByName('keys[' + lp + '][value]')[0];
var typ = document.getElementsByName('keys[' + lp + '][type]')[0];
if (typeof(key) != 'undefined' && typeof(typ) != 'undefined') {
if (expression != '') {
expression += ex;
expr_v += ex_v;
}
expression += typ.value + '(' + key.value + ')';
expr_v += typ.value + '(' + key.value + ')';
remove_keyword('keytr' + lp);
}
}
if (typeof(expr.value) != 'undefined' && expr.value != '') {
if (expression != '') {
expression += ex;
expr_v += ex_v;
}
expression += iregexp.checked ? 'iregexp' : 'regexp';
expression += '(' + expr.value + ')';
expr_v += iregexp.checked ? 'iregexp' : 'regexp';
expr_v += '(' + expr.value + ')';
}
if (expression == '') {
return false;
}
var classattr = IE ? 'className' : 'class';
var tr = document.createElement('tr');
document.getElementById('exp_list').firstChild.appendChild(tr);
tr.setAttribute(classattr, 'even_row');
tr.setAttribute('id', 'logtr' + logexpr_count);
var td = document.createElement('td');
tr.appendChild(td);
td.appendChild(document.createTextNode(expr_v));
var input = IE ? document.createElement('') : document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('value', expression);
!IE ? input.setAttribute('name', 'expressions[' + logexpr_count + '][value]') : '';
td.appendChild(input);
var input = IE ? document.createElement('') : document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('value', expr_v);
!IE ? input.setAttribute('name', 'expressions[' + logexpr_count + '][view]') : '';
td.appendChild(input);
var td = document.createElement('td');
tr.appendChild(td);
td.appendChild(document.createTextNode(expr_t.options[expr_t.selectedIndex].text));
var input = IE ? document.createElement('') : document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('value', expr_t.value);
!IE ? input.setAttribute('name', 'expressions[' + logexpr_count + '][type]') : '';
td.appendChild(input);
// optional
var td = document.createElement('td');
tr.appendChild(td);
td.setAttribute(IE ? 'cssText' : 'style', 'white-space: nowrap;');
var img = document.createElement('img');
img.setAttribute('src', 'images/general/arrowup.gif');
img.setAttribute('border', '0');
img.setAttribute('alt', 'up');
var url = document.createElement('a');
url.setAttribute('href', 'javascript: element_up("logtr' + logexpr_count + '");');
url.setAttribute(classattr, 'action');
url.appendChild(img);
td.appendChild(url);
td.appendChild(document.createTextNode(' '));
var img = document.createElement('img');
img.setAttribute('src', 'images/general/arrowdown.gif');
img.setAttribute('border', '0');
img.setAttribute('alt', 'down');
var url = document.createElement('a');
url.setAttribute('href', 'javascript: element_down("logtr' + logexpr_count + '");');
url.setAttribute(classattr, 'action');
url.appendChild(img);
td.appendChild(url);
var td = document.createElement('td');
tr.appendChild(td);
var url = document.createElement('a');
url.setAttribute('href', 'javascript: if (confirm("' + locale['S_DELETE_EXPRESSION_Q'] + '")) { remove_expression("logtr' + logexpr_count + '"); }');
url.setAttribute(classattr, 'action');
url.appendChild(document.createTextNode(locale['S_DELETE']));
td.appendChild(url);
logexpr_count++;
expr.value = '';
expr_t.selectedIndex=0;
bt_and.disabled = false;
bt_or.disabled = false;
}
function remove_expression(expr_id) {
var expr_tr = document.getElementById(expr_id);
var id = getIdFromNodeId(expr_id);
if (is_number(id)) {
var elm_v = document.getElementsByName('expressions[' + id + '][value]')[0];
var elm_t = document.getElementsByName('expressions[' + id + '][type]')[0];
var elm_s = document.getElementsByName('expressions[' + id + '][view]')[0];
if (typeof(elm_v) != 'undefined') {
elm_v.parentNode.removeChild(elm_v);
}
if (typeof(elm_t) != 'undefined') {
elm_t.parentNode.removeChild(elm_t);
}
if (typeof(elm_s) != 'undefined') {
elm_s.parentNode.removeChild(elm_s);
}
}
if (typeof(expr_tr) != 'undefined') {
expr_tr.parentNode.removeChild(expr_tr);
}
}
function getIdFromNodeId(id) {
if (typeof(id) == 'string') {
var reg = /logtr([0-9])/i;
id = parseInt(id.replace(reg, '$1'));
}
if (typeof(id) == 'number') {
return id;
}
return null;
}
function element_up(elementid) {
var c_obj = document.getElementById(elementid);
var p_obj = c_obj.parentNode;
if (typeof(p_obj) == 'undefined') {
return null;
}
var c2_obj = previousObject(c_obj);
if (c2_obj && c2_obj.id.length > 0) {
swapNodes(c2_obj, c_obj);
swapNodesNames(c2_obj, c_obj);
}
}
function element_down(elementid) {
var c_obj = document.getElementById(elementid);
var p_obj = c_obj.parentNode;
if (typeof(p_obj) == 'undefined') {
return null;
}
var c2_obj = nextObject(c_obj);
if (c2_obj && c2_obj.id.length > 0) {
swapNodes(c_obj, c2_obj);
swapNodesNames(c_obj, c2_obj);
}
}
function swapNodes(n1, n2) {
var p1, p2, b;
if ((p1 = n1.parentNode) && (p2 = n2.parentNode)) {
b = nextObject(n2);
if (n1 == b) {
return;
}
p1.replaceChild(n2, n1); // new, old
if (b) {
// n1 - the node which we insert
// b - the node before which we insert
p2.insertBefore(n1, b);
}
else {
p2.appendChild(n1);
}
}
}
function swapNodesNames(n1, n2) {
var id1 = n1.id;
var id2 = n2.id;
if (is_string(id1) && is_string(id2)) {
var reg = /logtr([0-9])/i;
id1 = parseInt(id1.replace(reg, '$1'));
id2 = parseInt(id2.replace(reg, '$1'));
}
if (is_number(id1) && is_number(id2)) {
var elm = [];
elm[0] = document.getElementsByName('expressions[' + id1 + '][value]')[0];
elm[1] = document.getElementsByName('expressions[' + id1 + '][type]')[0];
elm[2] = document.getElementsByName('expressions[' + id1 + '][view]')[0];
elm[3] = document.getElementsByName('expressions[' + id2 + '][value]')[0];
elm[4] = document.getElementsByName('expressions[' + id2 + '][type]')[0];
elm[5] = document.getElementsByName('expressions[' + id2 + '][view]')[0];
swapNodes(elm[0], elm[3]);
swapNodes(elm[1], elm[4]);
swapNodes(elm[2], elm[5]);
return true;
}
return false;
}
function closeForm(page) {
try {
// set header confirmation message to opener
var msg = IE ? document.getElementById('page_msg').innerText : document.getElementById('page_msg').textContent;
window.opener.location.replace(page + '?msg=' + encodeURI(msg));
}
catch(e) {
zbx_throw(e);
}
if (IE) {
// close current popup after 1s, wait when opener window is refreshed (IE7 issue)
window.setTimeout(function() { window.self.close() }, 1000);
}
else {
window.self.close();
}
}
function add_keyword(bt_type) {
try {
var expr = document.getElementById('logexpr');
var iregexp = document.getElementById('iregexp');
var cb = document.getElementById(bt_type == 'and' ? 'add_key_or' : 'add_key_and');
}
catch(e) {
throw('Error: ' + (IE ? e.description : e));
}
if (typeof(expr.value) == 'undefined' || expr.value == '') {
return false;
}
cb.disabled = true;
var classattr = IE ? 'className' : 'class';
var tr = document.createElement('tr');
document.getElementById('key_list').firstChild.appendChild(tr);
tr.setAttribute(classattr, 'even_row');
tr.setAttribute('id', 'keytr' + key_count);
// keyword
var td = document.createElement('td');
tr.appendChild(td);
td.appendChild(document.createTextNode(expr.value));
var input = IE ? document.createElement('') : document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('value', expr.value);
!IE ? input.setAttribute('name', 'keys[' + key_count + '][value]') : '';
td.appendChild(input);
// type
var td = document.createElement('td');
tr.appendChild(td);
td.appendChild(document.createTextNode(iregexp.checked ? 'iregexp' : 'regexp'));
var input = IE ? document.createElement('') : document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('value', iregexp.checked ? 'iregexp' : 'regexp');
!IE ? input.setAttribute('name', 'keys[' + key_count + '][type]') : '';
td.appendChild(input);
// delete
var td = document.createElement('td');
tr.appendChild(td);
var url = document.createElement('a');
url.setAttribute('href', 'javascript: if(confirm("' + locale['S_DELETE_KEYWORD_Q'] + '")) remove_keyword("keytr' + key_count + '");');
url.setAttribute(classattr, 'action');
url.appendChild(document.createTextNode(locale['S_DELETE']));
td.appendChild(url);
key_count++;
expr.value = '';
}
function add_keyword_and() {
add_keyword('and');
}
function add_keyword_or() {
add_keyword('or');
}
function getIdFromNodeKeyId(id) {
if (typeof(id) == 'string') {
var reg = /keytr([0-9])/i;
id = parseInt(id.replace(reg, '$1'));
}
if (typeof(id) == 'number') {
return id;
}
return null;
}
function remove_keyword(key_id) {
var key_tr = document.getElementById(key_id);
var id = getIdFromNodeKeyId(key_id);
if (is_number(id)) {
var elm_v = document.getElementsByName('keys[' + id + '][value]')[0];
var elm_t = document.getElementsByName('keys[' + id + '][type]')[0];
if (typeof(elm_v) == 'undefined') {
elm_v.parentNode.removeChild(elm_v);
}
if (typeof(elm_t) == 'undefined') {
elm_t.parentNode.removeChild(elm_t);
}
}
if (typeof(key_tr) != 'undefined') {
key_tr.parentNode.removeChild(key_tr);
}
var lp;
var bData = false;
for (lp = 0; lp < key_count; lp++) {
var elm_v = document.getElementsByName('keys[' + lp + '][value]')[0];
if (typeof(elm_v) != 'undefined') {
bData = true;
}
}
if (!bData) {
var bt_and = document.getElementById('add_key_and');
var bt_or = document.getElementById('add_key_or');
if (typeof(bt_and) != 'undefined') {
bt_and.disabled = false;
}
if (typeof(bt_or) != 'undefined') {
bt_or.disabled = false;
}
}
}
function check_target(e) {
var targets = document.getElementsByName('expr_target_single');
for (var i = 0; i < targets.length; ++i) {
targets[i].checked = targets[i] == e;
}
}
function delete_expression(expr_id) {
document.getElementsByName('remove_expression')[0].value = expr_id;
}
function copy_expression(id) {
var expr_temp = document.getElementsByName('expr_temp')[0];
if (expr_temp.value.length > 0 && !confirm(locale['DO_YOU_REPLACE_CONDITIONAL_EXPRESSION_Q'])) {
return null;
}
var src = document.getElementById(id);
if (typeof src.textContent != 'undefined') {
expr_temp.value = src.textContent;
}
else {
expr_temp.value = src.innerText;
}
}
function set_macro(v) {
var expr_temp = jQuery('#expr_temp');
if (expr_temp.val().length > 0 && !confirm(locale['DO_YOU_REPLACE_CONDITIONAL_EXPRESSION_Q'])) {
return false;
}
var sign = '=';
if (v >= 10) {
v %= 10;
sign = '#';
}
expr_temp.val('{TRIGGER.VALUE}' + sign + v);
return true;
}
/*
* Graph related stuff
*/
var graphs = {
graphtype : 0,
submit : function(obj) {
if (obj.name == 'graphtype') {
if ((obj.selectedIndex > 1 && this.graphtype < 2) || (obj.selectedIndex < 2 && this.graphtype > 1)) {
var refr = document.getElementsByName('form_refresh');
refr[0].value = 0;
}
}
document.getElementsByName('frm_graph')[0].submit();
}
};
function cloneRow(elementid, count) {
if (typeof(cloneRow.count) == 'undefined') {
cloneRow.count = count;
}
cloneRow.count++;
var tpl = new Template($(elementid).cloneNode(true).wrap('div').innerHTML);
var emptyEntry = tpl.evaluate({'id' : cloneRow.count});
var newEntry = $(elementid).insert({'before' : emptyEntry}).previousSibling;
$(newEntry).descendants().each(function(e) {
e.removeAttribute('disabled');
});
newEntry.setAttribute('id', 'entry_' + cloneRow.count);
newEntry.style.display = '';
}
// dashboard js menu
function create_page_menu(e, id) {
if (!e) {
e = window.event;
}
id = 'menu_' + id;
var dbrd_menu = [];
// to create a copy of array, but not references!!!!
for (var i=0; i < page_menu[id].length; i++) {
if (typeof(page_menu[id][i]) != 'undefined' && !empty(page_menu[id][i])) {
dbrd_menu[i] = page_menu[id][i].clone();
}
}
for (var i = 0; i < page_submenu[id].length; i++) {
if (typeof(page_submenu[id][i]) != 'undefined' && !empty(page_submenu[id][i])) {
var row = page_submenu[id][i];
var menu_row = [row.name, "javascript: rm4favorites('" + row.favobj + "', '" + row.favid + "', '" + i + "');"];
dbrd_menu[dbrd_menu.length-1].push(menu_row);
}
}
show_popup_menu(e, dbrd_menu);
}
// triggers js menu
function create_mon_trigger_menu(e, args, items) {
var tr_menu = [['Triggers', null, null, {'outer' : ['pum_oheader'], 'inner' : ['pum_iheader']}], ['Events', 'events.php?triggerid=' + args[0].triggerid + '&nav_time=' + args[0].lastchange, null]];
if (args.length > 1 && !is_null(args[1])) {
tr_menu.push(args[1]);
}
if (args.length > 1 && !is_null(args[2])) {
tr_menu.push(args[2]);
}
// getting info about types of items that we have
var has_char_items = false;
var has_int_items = false;
// checking every item
for (var itemid in items) {
// if no info about type is given
if (!isset(itemid, items)) {
continue;
}
if (!isset('value_type', items[itemid])) {
continue;
}
// 1, 2, 4 - character types
if (items[itemid].value_type == '1' || items[itemid].value_type == '2' || items[itemid].value_type == '4') {
has_char_items = true;
}
// 0, 3 - numeric types
if (items[itemid].value_type == '0' || items[itemid].value_type == '3') {
has_int_items = true;
}
}
var history_section_caption = '';
// we have chars and numbers, or we have none (probably 'value_type' key was not set)
if (has_char_items == has_int_items) {
history_section_caption = locale['S_HISTORY_AND_SIMPLE_GRAPHS'];
}
// we have only character items, so 'history' should be shown
else if (has_char_items) {
history_section_caption = locale['S_HISTORY'];
}
// we have only numeric items, so 'simple graphs' should be shown
else {
history_section_caption = locale['S_SIMPLE_GRAPHS'];
}
tr_menu.push([history_section_caption, null, null, {'outer' : ['pum_oheader'], 'inner' : ['pum_iheader']}]);
for (var itemid in items) {
if (!isset(itemid, items)) {
continue;
}
tr_menu.push([items[itemid].name, 'history.php?action=' + items[itemid].action + '&itemid=' + items[itemid].itemid, null]);
}
show_popup_menu(e, tr_menu, 280);
}
function testUserSound(idx) {
var sound = $(idx).options[$(idx).selectedIndex].value;
var repeat = $('messages_sounds.repeat').options[$('messages_sounds.repeat').selectedIndex].value;
if (repeat == 1) {
AudioList.play(sound);
}
else if (repeat > 1) {
AudioList.loop(sound, {'seconds': repeat});
}
else {
AudioList.loop(sound, {'seconds': $('messages_timeout').value});
}
}
function removeObjectById(id) {
var obj = document.getElementById(id);
if (obj != null && typeof(obj) == 'object') {
obj.parentNode.removeChild(obj);
}
}
/**
* Converts all HTML entities into the corresponding symbols.
*/
jQuery.unescapeHtml = function(html) {
return jQuery('').html(html).text();
}
/**
* Converts all HTML symbols into HTML entities.
*/
jQuery.escapeHtml = function(html) {
return jQuery('').text(html).html();
}
function validateNumericBox(obj, allowempty, allownegative) {
if (obj != null) {
if (allowempty) {
if (obj.value.length == 0 || obj.value == null) {
obj.value = '';
}
else {
if (isNaN(parseInt(obj.value, 10))) {
obj.value = 0;
}
else {
obj.value = parseInt(obj.value, 10);
}
}
}
else {
if (isNaN(parseInt(obj.value, 10))) {
obj.value = 0;
}
else {
obj.value = parseInt(obj.value, 10);
}
}
}
if (!allownegative) {
if (obj.value < 0) {
obj.value = obj.value * -1;
}
}
}
/**
* Translates the given string.
*
* @param {String} str
*/
function t(str) {
return (!!locale[str]) ? locale[str] : str;
}
/**
* Generates unique id with prefix 'new'.
* id starts from 0 in each JS session.
*
* @return string
*/
function getUniqueId() {
if (typeof getUniqueId.id === 'undefined') {
getUniqueId.id = 0;
}
return 'new' + (getUniqueId.id++).toString();
}
/**
* Color palette, (implementation from PHP)
*/
var prevColor = {'color': 0, 'gradient': 0};
function incrementNextColor() {
prevColor['color']++;
if (prevColor['color'] == 7) {
prevColor['color'] = 0;
prevColor['gradient']++;
if (prevColor['gradient'] == 3) {
prevColor['gradient'] = 0;
}
}
}
function getNextColor(paletteType) {
var palette, gradient, hexColor, r, g, b;
switch (paletteType) {
case 1:
palette = [200, 150, 255, 100, 50, 0];
break;
case 2:
palette = [100, 50, 200, 150, 250, 0];
break;
case 0:
default:
palette = [255, 200, 150, 100, 50, 0];
break;
}
gradient = palette[prevColor['gradient']];
r = (100 < gradient) ? 0 : 255;
g = r;
b = r;
switch (prevColor['color']) {
case 0:
r = gradient;
break;
case 1:
g = gradient;
break;
case 2:
b = gradient;
break;
case 3:
b = gradient;
r = b;
break;
case 4:
b = gradient;
g = b;
break;
case 5:
g = gradient;
r = g;
break;
case 6:
b = gradient;
g = b;
r = b;
break;
}
incrementNextColor();
hexColor = ('0' + parseInt(r, 10).toString(16)).slice(-2)
+ ('0' + parseInt(g, 10).toString(16)).slice(-2)
+ ('0' + parseInt(b, 10).toString(16)).slice(-2);
return hexColor.toUpperCase();
}
/**
* Used for php ctweenbox object.
* Moves item from 'from' select to 'to' select and adds or removes hidden fields to 'formname' for posting data.
* Moving perserves alphabetical order.
*
* @formname string form name where hidden fields will be added
* @objname string unique name for hidden field naming
* @from string from select id
* @to string to select id
* @action string action to perform with hidden field
*
* @return true
*/
function moveListBoxSelectedItem(formname, objname, from, to, action) {
to = jQuery("#"+to);
jQuery("#"+from).find("option:selected").each(function(i, fromel){
var notApp = true;
to.find("option").each(function(j, toel){
if (toel.innerHTML.toLowerCase() > fromel.innerHTML.toLowerCase()) {
jQuery(toel).before(fromel);
notApp = false;
return false;
}
});
if (notApp) {
to.append(fromel);
}
fromel = jQuery(fromel);
if (action.toLowerCase() == "add") {
jQuery(document.forms[formname]).append("");
}
else if (action.toLowerCase() == "rmv") {
jQuery("#"+objname + "_" + fromel.val()).remove();
}
});
return true;
}
/*
** Zabbix
** Copyright (C) 2000-2011 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
// Title: tigra menu
// Description: See the demo at url
// URL: http://www.softcomplex.com/products/tigra_menu/
// Version: 2.0 (commented source)
// Date: 04-05-2003 (mm-dd-yyyy)
// Tech. Support: http://www.softcomplex.com/forum/forumdisplay.php?fid=40
// Notes: This script is free. Visit official site for further details.
// This script adapted by Eugene Grigorjev for using as popup menu
// of Zabbix software. See http://www.zabbix.com.
//debugger;
// Getting CSS style property
function get_style(el, styleProp) {
if (el.currentStyle) {
var y = el.currentStyle[styleProp];
}
else if (window.getComputedStyle) {
var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
}
return y;
}
// Getting text width in user's browser
function get_real_text_width(text, id) {
var item_type = 'pum_o_submenu';
if (id==0) {
item_type = 'pum_iheader';
}
var test_element = document.createElement('div');
test_element.setAttribute('class', item_type);
test_element.setAttribute('style', 'visibility: hidden');
document.body.appendChild(test_element);
var font_size_text = get_style(test_element, 'font-size');
if (!font_size_text) {
font_size_text = get_style(test_element, 'fontSize');
}
var font_size = parseInt(font_size_text);
font_size += 2;
var margin_left_text = get_style(test_element, 'margin-left');
if (!margin_left_text) {
margin_left_text = get_style(test_element, 'marginLeft');
}
var margin_left = parseInt(margin_left_text);
document.body.removeChild(test_element);
test_element = document.createElement('a');
test_element.setAttribute('class', item_type);
test_element.setAttribute('style', 'font-size: '+font_size+'px; visibility: hidden');
test_element.innerHTML = text;
document.body.appendChild(test_element);
var tmp_len = test_element.offsetWidth+margin_left+5;
document.body.removeChild(test_element);
test_element = null;
return tmp_len;
}
function truncateText(text, len) {
return (text.length > len) ? text.substring(0, len) + '...' : text;
}
function show_popup_menu(e, content, width){
if (A_MENUS[0] !== undefined) {
A_MENUS[0].collapse();
}
var cursor = get_cursor_position(e);
var tmp_width = 0;
var max_width = 0;
var menuTextLength = 35;
for (var i = 0; i < content.length; i++) {
if (content[i].length) {
content[i][0] = truncateText(content[i][0], menuTextLength);
tmp_width = get_real_text_width(content[i][0], i);
if (max_width < tmp_width) {
max_width = tmp_width;
}
}
// truncate sub menu text
if (content[i].length > 4) {
for (var j = 4; j < content[i].length; j++) {
content[i][j][0] = truncateText(content[i][j][0], menuTextLength);
tmp_width = get_real_text_width(content[i][j][0], i);
if (max_width < tmp_width) {
max_width = tmp_width;
}
}
}
}
if (width == null || width < max_width) {
width = max_width;
}
if (width == 0)
width = 220;
var pos = [
{'block_top': -12, 'block_left': -5, 'width': width},
{'block_top': 5, 'block_left': width-5, 'width': width}
];
new popup_menu (content, pos, cursor.x, cursor.y);
return false;
}
// global collection containing all menus on current page
var A_MENUS = [];
// menu class
function popup_menu (a_items, a_tpl, x, y) {
// browser check
if (!document.body || !document.body.style) {
return null;
}
this.n_scroll_left = get_scroll_pos()[0];
if (document.body.clientWidth) {
this.n_scr_width = document.body.clientWidth;
}
else {
this.n_scr_width = document.width;
}
// store items structure
this.a_config = a_items;
// store template structure
this.a_tpl = a_tpl;
// get menu id
this.n_id = A_MENUS.length;
// declare collections
this.a_index = [];
this.a_children = [];
// assign methods and event handlers
this.expand = menu_expand;
this.collapse = menu_collapse;
this.onclick = menu_onclick;
this.onmouseout = menu_onmouseout;
this.onmouseover = menu_onmouseover;
this.onmousedown = menu_onmousedown;
this.getstyle = mitem_getstyle;
this.set_x_direction = mitem_set_x_direction;
this.get_x_direction = mitem_get_x_direction;
this.set_y_direction = mitem_set_y_direction;
this.get_y_direction = mitem_get_y_direction;
// default level scope description structure
this.a_tpl_def = {
'block_top' : 0,
'block_left' : 0,
'top' : 23,
'left' : 0,
'width' : 170,
'height' : 24,
'hide_delay' : 200,
'expd_delay' : 200
};
// default css
this.a_css_def = {
'outer' : ['pum_o_item'],
'inner' : ['pum_i_item']
};
// assign methods and properties required to emulate parent item
this.getprop = function (s_key) {
return this.a_tpl_def[s_key];
};
this.o_root = this;
this.n_depth = -1;
this.n_x = x;
this.n_y = y;
// init items recursively
for (n_order = 0; n_order < a_items.length; n_order++) {
new menu_item(this, n_order);
}
// register self in global collection
A_MENUS[this.n_id] = this;
// make root level visible
for (var n_order = 0; n_order < this.a_children.length; n_order++) {
this.a_children[n_order].e_oelement.style.visibility = 'visible';
}
}
function mitem_set_x_direction(n_val) {
this.n_x_direction = n_val;
}
function mitem_get_x_direction() {
return this.n_x_direction ? this.n_x_direction : null;
}
function mitem_set_y_direction(n_val) {
this.n_y_direction = n_val;
}
function mitem_get_y_direction() {
return this.n_y_direction ? this.n_y_direction : null;
}
function menu_collapse (n_id) {
// cancel item open delay
clearTimeout(this.o_showtimer);
// by default collapse all levels
var n_tolevel = (n_id ? this.a_index[n_id].n_depth : -1);
if (-1 == n_tolevel) {
for (n_id = 0; n_id < this.a_index.length; n_id++) {
var o_curritem = this.a_index[n_id];
if (o_curritem) {
var e_oelement = document.getElementById(o_curritem.e_oelement.id);
if (e_oelement != null) {
document.body.removeChild(e_oelement);
}
}
}
A_MENUS.splice(this.o_root.n_id);
}
else {
// hide all items over the level specified
for (n_id = 0; n_id < this.a_index.length; n_id++) {
var o_curritem = this.a_index[n_id];
if (o_curritem && o_curritem.n_depth > n_tolevel && o_curritem.b_visible) {
o_curritem.e_oelement.style.visibility = 'hidden';
o_curritem.b_visible = false;
}
}
}
// reset current item if mouse has gone out of items
if (!n_id) {
this.o_current = null;
}
}
function menu_expand (n_id) {
// expand only when mouse is over some menu item
if (this.o_hidetimer) {
return null;
}
// lookup current item
var o_item = this.a_index[n_id];
// close previously opened items
if (this.o_current && this.o_current.n_depth >= o_item.n_depth) {
this.collapse(o_item.n_id);
}
this.o_current = o_item;
// exit if there are no children to open
if (!o_item.a_children) {
return null;
}
// show direct child items
for (var n_order = 0; n_order < o_item.a_children.length; n_order++) {
var o_curritem = o_item.a_children[n_order];
o_curritem.e_oelement.style.visibility = 'visible';
o_curritem.b_visible = true;
}
}
function menu_onclick (n_id) {
// don't go anywhere if item has no link defined
// lookup new item's object
if (Boolean(this.a_index[n_id].a_config[1])) {
// lookup new item's object
var o_item = this.a_index[n_id];
// apply rollout
o_item.e_oelement.className = o_item.getstyle(0, 0);
o_item.e_ielement.className = o_item.getstyle(1, 0);
this.o_hidetimer = setTimeout('if (typeof(A_MENUS[' + this.n_id + ']) != "undefined") { A_MENUS['+ this.n_id +'].collapse(); }', 100);
return true;
}
return false;
}
function menu_onmouseout (n_id) {
// lookup new item's object
var o_item = this.a_index[n_id];
// apply rollout
o_item.e_oelement.className = o_item.getstyle(0, 0);
o_item.e_ielement.className = o_item.getstyle(1, 0);
// run mouseover timer
this.o_hidetimer = setTimeout('if (typeof(A_MENUS[' + this.n_id + ']) != "undefined") { A_MENUS['+ this.n_id +'].collapse(); }', o_item.getprop('hide_delay'));
}
function menu_onmouseover (n_id) {
// cancel mouseoute menu close and item open delay
clearTimeout(this.o_hidetimer);
this.o_hidetimer = null;
clearTimeout(this.o_showtimer);
// lookup new item's object
var o_item = this.a_index[n_id];
// apply rollover
o_item.e_oelement.className = o_item.getstyle(0, 1);
o_item.e_ielement.className = o_item.getstyle(1, 1);
// if onclick open is set then no more actions required
if (o_item.getprop('expd_delay') < 0) {
return null;
}
// run expand timer
this.o_showtimer = setTimeout('A_MENUS[' + this.n_id + '].expand(' + n_id + ');', o_item.getprop('expd_delay'));
}
// called when mouse button is pressed on menu item
function menu_onmousedown (n_id) {
// lookup new item's object
var o_item = this.a_index[n_id];
// apply mouse down style
o_item.e_oelement.className = o_item.getstyle(0, 2);
o_item.e_ielement.className = o_item.getstyle(1, 2);
this.expand(n_id);
}
// menu item Class
function menu_item (o_parent, n_order) {
// store parameters passed to the constructor
this.n_depth = o_parent.n_depth + 1;
var item_offset = this.n_depth ? 4 : 0;
this.a_config = o_parent.a_config[n_order + item_offset];
// return if required parameters are missing
if (!this.a_config || !this.a_config[0]) {
return;
}
// store info from parent item
this.o_root = o_parent.o_root;
this.o_parent = o_parent;
this.n_order = n_order;
// register in global and parent's collections
this.n_id = this.o_root.a_index.length + 1;
this.o_root.a_index[this.n_id] = this;
o_parent.a_children[n_order] = this;
// calculate item's coordinates
var o_root = this.o_root,
a_tpl = this.o_root.a_tpl;
this.a_css = this.a_config[3] ? this.a_config[3] : null;
// assign methods
this.getprop = mitem_getprop;
this.getstyle = mitem_getstyle;
this.set_x_direction = mitem_set_x_direction;
this.get_x_direction = mitem_get_x_direction;
this.set_y_direction = mitem_set_y_direction;
this.get_y_direction = mitem_get_y_direction;
if (!o_parent.n_x_direction && !n_order) {
// calculate menu direction in first element
o_parent.set_x_direction(
this.getprop('width') + o_parent.n_x + this.getprop('block_left') > o_root.n_scr_width + o_root.n_scroll_left ? -1 : 1
);
}
this.n_x = n_order
? o_parent.a_children[n_order - 1].n_x + this.getprop('left') * o_parent.get_x_direction()
: o_parent.n_x + this.getprop('block_left') * o_parent.get_x_direction();
if (-1 == o_parent.get_x_direction() && o_parent == o_root && !n_order) {
this.n_x -= this.getprop('width');
}
if (!o_parent.n_y_direction && !n_order) {
o_parent.set_y_direction(jQuery(window).height() + jQuery(window).scrollTop() - o_parent.n_y - this.getprop('height') * o_parent.a_config.length < 0 ? -1 : 1);
}
// top
this.n_y = n_order
? o_parent.a_children[n_order - 1].n_y + this.getprop('top')
: o_parent.n_y + this.getprop('block_top') * (o_parent == o_root ? o_parent.get_y_direction() : 1);
if (-1 == o_parent.get_y_direction() && !n_order) {
this.n_y = jQuery(window).height() + jQuery(window).scrollTop() - this.getprop('height') * (o_parent.a_config.length - item_offset);
}
// generate item's HMTL
var el = document.createElement('a');
var menuItemId = 'e' + o_root.n_id + '_' + this.n_id + 'o';
el.setAttribute('id', menuItemId);
// js callback action
if (jQuery.isFunction(this.a_config[1])) {
jQuery(el).click(this.a_config[1]);
}
// url action
else {
if (!is_null(this.a_config[1]) && (this.a_config[1].indexOf('javascript') == -1)
&& !(!is_null(this.a_config[2]) || this.a_config[2] == 'nosid')) {
var url = new Curl(this.a_config[1]);
this.a_config[1] = url.getUrl();
}
el.setAttribute('href', this.a_config[1]);
if (this.a_config[2] && this.a_config[2]['tw']) {
el.setAttribute('target', this.a_config[2]['tw']);
}
}
el.className = this.getstyle(0, 0);
el.style.position = 'absolute';
el.style.top = this.n_y + 'px';
el.style.left = this.n_x + 'px';
el.style.width = this.getprop('width') + 'px';
el.style.height = this.getprop('height') + 'px';
el.style.visibility = 'hidden';
el.style.zIndex = parseInt(this.n_depth, 10) + 100;
el.o_root_n_id = o_root.n_id;
el.this_n_id = this.n_id;
el.onclick = A_MENUS_onclick;
el.onmouseout = A_MENUS_onmouseout;
el.onmouseover = A_MENUS_onmouseover;
el.onmousedown = A_MENUS_onmousedown;
var eldiv = document.createElement('div');
eldiv.setAttribute('id', 'e' + o_root.n_id + '_' + this.n_id +'i');
eldiv.className = this.getstyle(1, 0);
// truncating long strings - they don't fit in the popup menu'
if (typeof(this.a_config[0]) == 'string' && this.a_config[0].length > 35) {
eldiv.setAttribute('title', this.a_config[0]);
}
eldiv.appendChild(document.createTextNode(this.a_config[0]));
el.appendChild(eldiv);
document.body.appendChild(el);
this.e_ielement = document.getElementById('e' + o_root.n_id + '_' + this.n_id + 'i');
this.e_oelement = document.getElementById('e' + o_root.n_id + '_' + this.n_id + 'o');
this.b_visible = !this.n_depth;
var newResult = 0;
var nText = '';
newResult = this.e_ielement.scrollWidth - this.getprop('width');
if (newResult > 0) {
// anti down
var x = 500;
while (x) {
newResult = this.e_ielement.scrollWidth - this.getprop('width');
nText = jQuery.unescapeHtml(this.e_ielement.innerHTML);
this.e_ielement.innerHTML = jQuery.escapeHtml(nText.substring(0, nText.length-10));
x--;
if (newResult < 1) {
this.e_ielement.innerHTML += '...';
x = 0;
break;
}
}
}
// no more initialization if leaf
if (this.a_config.length < item_offset) {
return null;
}
// node specific methods and properties
this.a_children = [];
// init downline recursively
for (var n_order = 0; n_order < this.a_config.length - item_offset; n_order++) {
new menu_item(this, n_order);
}
}
function A_MENUS_onclick() {
return A_MENUS[this.o_root_n_id].onclick(this.this_n_id);
}
function A_MENUS_onmouseout() {
return A_MENUS[this.o_root_n_id].onmouseout(this.this_n_id);
}
function A_MENUS_onmouseover() {
return A_MENUS[this.o_root_n_id].onmouseover(this.this_n_id);
}
function A_MENUS_onmousedown() {
return A_MENUS[this.o_root_n_id].onmousedown(this.this_n_id);
}
// reads property from template file, inherits from parent level if not found
function mitem_getprop (s_key) {
// check if value is defined for current level
var s_value = null,
a_level = this.o_root.a_tpl[this.n_depth];
// return value if explicitly defined
if (a_level) {
s_value = a_level[s_key];
}
// request recursively from parent levels if not defined
return s_value == null ? this.o_parent.getprop(s_key) : s_value;
}
// reads property from template file, inherits from parent level if not found
function mitem_getstyle (n_pos, n_state) {
var a_css = this.a_css;
// request recursively from parent levels if not defined
if (!a_css) {
a_css = this.o_root.a_css_def;
}
var a_oclass = a_css[n_pos ? 'inner' : 'outer'];
// same class for all states
if (typeof(a_oclass) == 'string') {
return a_oclass;
}
// inherit class from previous state if not explicitly defined
for (var n_currst = n_state; n_currst >= 0; n_currst--) {
if (a_oclass[n_currst]) {
return a_oclass[n_currst];
}
}
}
/**
* Creates a header object for the menu.
*
* @param label
*
* @return {Array}
*/
function createMenuHeader(label) {
return [label, null, null, { outer: 'pum_oheader', inner: 'pum_iheader' }];
}
/**
* Creates a menu link object for the menu
*
* @param label
* @param action the target URL
*
* @return {Array}
*/
function createMenuItem(label, action) {
return [label, action, null, { outer: 'pum_o_item', inner: 'pum_i_item' }];
}
/*
** Zabbix
** Copyright (C) 2000-2011 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
jQuery(function() {
cookie.init();
// search
if (jQuery('#search').length) {
createSuggest('search');
}
/**
* Handles host pop up menus.
*/
jQuery(document).on('click', '.menu-host', function(event) {
var menuData = jQuery(this).data('menu');
var menu = [];
// add scripts
if (menuData.scripts.length) {
menu.push(createMenuHeader(t('Scripts')));
jQuery.each(menuData.scripts, function(i, script) {
menu.push(createMenuItem(script.name, function () {
executeScript(menuData.hostid, script.scriptid, script.confirmation);
return false;
}));
});
}
// add go to links
menu.push(createMenuHeader(t('Go to')));
menu.push(createMenuItem(t('Latest data'), 'latest.php?hostid=' + menuData.hostid));
if (menuData.hasInventory) {
menu.push(createMenuItem(t('Host inventories'), 'hostinventories.php?hostid=' + menuData.hostid));
}
if (menuData.hasScreens) {
menu.push(createMenuItem(t('Host screens'), 'host_screen.php?hostid=' + menuData.hostid));
}
// render the menu
show_popup_menu(event, menu, 180);
return false;
});
});
/*
** Zabbix
** Copyright (C) 2000-2011 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
var ZBX_MESSAGES = [];
// use this function to initialize Messaging system
function initMessages(args) {
var messagesListId = ZBX_MESSAGES.length;
ZBX_MESSAGES[messagesListId] = new CMessageList(messagesListId, args);
return messagesListId;
}
var CMessageList = Class.create(CDebug, {
messageListId: 0, // reference id
updateFrequency: 60, // seconds
timeoutFrequency: 10, // seconds
ready: false,
PEupdater: null, // PeriodicalExecuter object update
PEtimeout: null, // PeriodicalExecuter object update
lastupdate: 0, // lastupdate timestamp
msgcounter: 0, // how many messages have been added
pipeLength: 15, // how many messages to show
messageList: {}, // list of received messages
messagePipe: [], // messageid pipe line
messageLast: {}, // last message's sourceid by caption
effectTimeout: 1000, // effect time out
dom: {}, // dom object links
sounds: { // sound playback settings
'priority': 0, // max new message priority
'sound': null, // sound to play
'repeat': 1, // loop sound for 1,3,5,10 .. times
'mute': 0, // mute alarms
'timeout': 0
},
initialize: function($super, messagesListId, args) {
this.messageListId = messagesListId;
$super('CMessageList[' + messagesListId + ']');
this.dom = {};
this.messageList = {};
this.messageLast = {};
this.updateSettings();
this.createContainer();
addListener(this.dom.closeAll, 'click', this.closeAllMessages.bindAsEventListener(this));
addListener(this.dom.snooze, 'click', this.stopSound.bindAsEventListener(this));
addListener(this.dom.mute, 'click', this.mute.bindAsEventListener(this));
jQuery(this.dom.container).draggable({
handle: [this.dom.caption, this.dom.move],
axis: 'y',
containment: [0, 0, 0, 1600]
});
},
start: function() {
this.stop();
if (is_null(this.PEupdater)) {
this.ready = true;
this.lastupdate = 0;
this.PEupdater = new PeriodicalExecuter(this.getServerMessages.bind(this), this.updateFrequency);
this.getServerMessages();
}
if (is_null(this.PEtimeout)) {
this.PEtimeout = new PeriodicalExecuter(this.timeoutMessages.bind(this), this.timeoutFrequency);
this.timeoutMessages();
}
},
stop: function() {
if (!is_null(this.PEupdater)) {
this.PEupdater.stop();
}
if (!is_null(this.PEtimeout)) {
this.PEtimeout.stop();
}
this.PEupdater = null;
this.PEtimeout = null;
},
setSettings: function(settings) {
this.debug('setSettings');
this.sounds.repeat = settings['sounds.repeat'];
this.sounds.mute = settings['sounds.mute'];
if (this.sounds.mute == 1) {
this.dom.mute.className = 'iconmute menu_icon shadow';
}
if (settings.enabled != 1) {
this.stop();
}
else {
this.start();
}
},
updateSettings: function() {
this.debug('updateSettings');
var rpcRequest = {
'method': 'message.settings',
'params': {},
'onSuccess': this.setSettings.bind(this),
'onFailure': function() {
zbx_throw('Messages Widget: settings request failed.');
}
};
new RPC.Call(rpcRequest);
},
addMessage: function(newMessage) {
this.debug('addMessage');
newMessage = newMessage || {};
while (isset(this.msgcounter, this.messageList)) {
this.msgcounter++;
}
if (this.messagePipe.length > this.pipeLength) {
var lastMessageId = this.messagePipe.shift();
this.closeMessage(lastMessageId);
}
this.messagePipe.push(this.msgcounter);
newMessage.messageid = this.msgcounter;
this.messageList[this.msgcounter] = new CMessage(this, newMessage);
this.messageLast[this.messageList[this.msgcounter].caption] = {
'caption': this.messageList[this.msgcounter].caption,
'sourceid': this.messageList[this.msgcounter].sourceid,
'time': this.messageList[this.msgcounter].time,
'messageid': this.messageList[this.msgcounter].messageid
};
jQuery(this.dom.container).fadeTo('fast', 0.9);
return this.messageList[this.msgcounter];
},
mute: function(e) {
this.debug('mute');
e = e || window.event;
var icon = Event.element(e);
var newClass = switchElementsClass(icon, 'iconmute', 'iconsound');
if (newClass == 'iconmute') {
var action = 'message.mute';
this.sounds.mute = 1;
}
else {
var action = 'message.unmute';
this.sounds.mute = 0;
}
var rpcRequest = {
'method': action,
'params': {},
'onFailure': function() {
zbx_throw('Messages Widget: mute request failed.');
}
};
new RPC.Call(rpcRequest);
this.stopSound(e);
},
playSound: function(messages) {
this.debug('playSound');
if (this.sounds.mute != 0) {
return true;
}
this.stopSound();
this.sounds.priority = 0;
this.sounds.sound = null;
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
if (message.type != 1 && message.type != 3) {
continue;
}
if (message.priority >= this.sounds.priority) {
this.sounds.priority = message.priority;
this.sounds.sound = message.sound;
this.sounds.timeout = message.timeout;
}
}
this.ready = true;
if (!is_null(this.sounds.sound)) {
if (this.sounds.repeat == 1) {
AudioList.play(this.sounds.sound);
}
else if (this.sounds.repeat > 1) {
AudioList.loop(this.sounds.sound, {'seconds': this.sounds.repeat});
}
else {
AudioList.loop(this.sounds.sound, {'seconds': this.sounds.timeout});
}
}
},
stopSound: function() {
this.debug('stopSound');
if (!is_null(this.sounds.sound)) {
AudioList.stop(this.sounds.sound);
}
},
closeMessage: function(messageid, withEffect) {
this.debug('closeMessage', messageid);
if (!isset(messageid, this.messageList)) {
return true;
}
AudioList.stop(this.messageList[messageid].sound);
if (withEffect) {
this.messageList[messageid].remove();
}
else {
this.messageList[messageid].close();
}
try {
delete(this.messageList[messageid]);
}
catch(e) {
this.messageList[messageid] = null;
}
this.messagePipe = [];
for (var messageid in this.messageList) {
this.messagePipe.push(messageid);
}
if (this.messagePipe.length < 1) {
this.messagePipe = [];
this.messageList = {};
setTimeout(Element.hide.bind(Element, this.dom.container), this.effectTimeout);
}
},
closeAllMessages: function() {
this.debug('closeAllMessages');
var lastMessageId = this.messagePipe.pop();
var rpcRequest = {
'method': 'message.closeAll',
'params': {
'caption': this.messageList[lastMessageId].caption,
'sourceid': this.messageList[lastMessageId].sourceid,
'time': this.messageList[lastMessageId].time,
'messageid': this.messageList[lastMessageId].messageid
},
'onFailure': function(resp) {
zbx_throw('Messages Widget: message request failed.');
}
};
new RPC.Call(rpcRequest);
jQuery(this.dom.container).slideUp(this.effectTimeout);
var count = 0;
var effect = false;
for (var messageid in this.messageList) {
if (empty(this.messageList[messageid])) {
continue;
}
if (!effect) {
this.closeMessage(this, messageid, effect);
}
else {
setTimeout(this.closeMessage.bind(this, messageid, effect), count * this.effectTimeout * 0.5);
}
count++;
}
},
timeoutMessages: function() {
this.debug('timeoutMessages');
var now = parseInt(new Date().getTime() / 1000);
var timeout = 0;
for (var messageid in this.messageList) {
if (empty(this.messageList[messageid])) {
continue;
}
var msg = this.messageList[messageid];
if ((msg.time + parseInt(msg.timeout, 10)) < now) {
setTimeout(this.closeMessage.bind(this, messageid, true), 500 * timeout);
timeout++;
}
}
},
getServerMessages: function() {
this.debug('getServerMessages');
var now = parseInt(new Date().getTime() / 1000);
if (!this.ready || ((this.lastupdate + this.updateFrequency) > now)) {
return true;
}
this.ready = false;
var rpcRequest = {
'method': 'message.get',
'params': {
'messageListId': this.messageListId,
'messageLast': this.messageLast
},
'onSuccess': this.serverRespond.bind(this),
'onFailure': function() {
zbx_throw('Messages Widget: message request failed.');
}
};
new RPC.Call(rpcRequest);
this.lastupdate = now;
},
serverRespond: function(messages) {
this.debug('serverRespond');
for (var i = 0; i < messages.length; i++) {
this.addMessage(messages[i]);
}
this.playSound(messages);
this.ready = true;
},
createContainer: function() {
this.debug('createContainer');
this.dom.container = $('zbx_messages');
if (!empty(this.dom.container)) {
return false;
}
var doc_body = document.getElementsByTagName('body')[0];
if (empty(doc_body)) {
return false;
}
this.dom.container = document.createElement('div');
doc_body.appendChild(this.dom.container);
// container
this.dom.container.setAttribute('id', 'zbx_messages');
this.dom.container.className = 'messagecontainer';
$(this.dom.container).hide();
// header
this.dom.header = document.createElement('div');
this.dom.container.appendChild(this.dom.header);
this.dom.header.className = 'header';
// text
this.dom.caption = document.createElement('h3');
this.dom.caption.className = 'headertext move';
this.dom.caption.appendChild(document.createTextNode(locale['S_MESSAGES']));
this.dom.header.appendChild(this.dom.caption);
// controls
this.dom.controls = document.createElement('div');
this.dom.header.appendChild(this.dom.controls);
this.dom.controls.className = 'controls';
// buttons list
this.dom.controlList = new CList().node;
this.dom.controls.appendChild(this.dom.controlList);
this.dom.controlList.style.cssFloat = 'right';
// snooze
this.dom.snooze = document.createElement('div');
this.dom.snooze.setAttribute('title', locale['S_SNOOZE']);
this.dom.snooze.className = 'iconsnooze menu_icon shadow';
this.dom.controlList.addItem(this.dom.snooze, 'linear');
// mute
this.dom.mute = document.createElement('div');
this.dom.mute.setAttribute('title', locale['S_MUTE'] + '/' + locale['S_UNMUTE']);
this.dom.mute.className = 'iconsound menu_icon shadow';
this.dom.controlList.addItem(this.dom.mute, 'linear');
// close all
this.dom.closeAll = document.createElement('div');
this.dom.closeAll.setAttribute('title', locale['S_CLEAR']);
this.dom.closeAll.className = 'iconclose menu_icon shadow';
this.dom.controlList.addItem(this.dom.closeAll, 'linear');
// message list
this.dom.list = new CList().node;
this.dom.container.appendChild(this.dom.list);
}
});
var CMessage = Class.create(CDebug, {
list: null, // link to message list containing this message
messageid: null, // msg id
caption: 'unknown', // msg caption (events, actions, infos.. e.t.c.)
sourceid: null, // caption + sourceid = identifier for server
type: 0, // 1 - sound, 2 - text, 3 - sound & text, 4 - notdefined
priority: 0, // msg priority ASC
sound: null, // msg sound
color: 'ffffff', // msg color
time: 0, // msg time arrival
title: 'No title', // msg header
body: ['No text'],// msg details
timeout: 60, // msg timeout
dom: {}, // msg dom links
initialize: function($super, messageList, message) {
this.messageid = message.messageid;
$super('CMessage[' + this.messageid + ']');
this.dom = {};
this.list = messageList;
for (var key in message) {
if (empty(message[key]) || !isset(key, this)) {
continue;
}
if (key == 'time') {
this[key] = parseInt(message[key]);
}
else {
this[key] = message[key];
}
}
this.createMessage();
},
close: function() {
this.debug('close');
$(this.dom.listItem).remove();
this.dom = {};
},
remove: function() {
this.debug('remove');
jQuery(this.dom.listItem).slideUp(this.list.effectTimeout);
jQuery(this.dom.listItem).fadeOut(this.list.effectTimeout);
setTimeout(this.close.bind(this), this.list.effectTimeout);
},
createMessage: function() {
this.debug('createMessage');
// message
this.dom.message = document.createElement('div');
this.dom.message.className = 'message';
this.dom.message.style.backgroundColor = '#' + this.color;
// li
this.dom.listItem = new CListItem(this.dom.message, 'listItem').node;
$(this.list.dom.list).insert({'top': this.dom.listItem});
// message box
this.dom.messageBox = document.createElement('div');
this.dom.message.appendChild(this.dom.messageBox);
this.dom.messageBox.className = 'messagebox';
// title
this.dom.title = document.createElement('span');
this.dom.messageBox.appendChild(this.dom.title);
$(this.dom.title).update(BBCode.Parse(this.title));
this.dom.title.className = 'title';
// body
if (!is_array(this.body)) {
this.body = [this.body];
}
for (var i = 0; i < this.body.length; i++) {
if (!isset(i, this.body) || empty(this.body[i])) {
continue;
}
this.dom.messageBox.appendChild(document.createElement('br'));
this.dom.body = document.createElement('span');
this.dom.messageBox.appendChild(this.dom.body);
$(this.dom.body).update(BBCode.Parse(this.body[i]));
this.dom.body.className = 'body';
}
},
show: function() {},
notify: function() {}
});
var CNode = Class.create({
node: null, // main node (ul)
initialize: function(nodeName) {
this.node = document.createElement(nodeName);
return this.node;
},
addItem: function(item) {
if (is_object(item)) {
this.node.appendChild(item);
}
else if (is_string(item)) {
this.node.appendChild(documect.createTextNode(item));
}
else {
return true;
}
},
setClass: function(className) {
className = className || '';
this.node.className = className;
}
});
var CList = Class.create(CNode, {
items: [],
initialize: function($super, className) {
className = className || '';
$super('ul');
this.setClass(this.classNames);
Object.extend(this.node, this);
},
addItem: function($super, item, className) {
className = className || '';
if (!is_object(item, CListItem)) {
item = new CListItem(item, className).node;
}
$super(item);
this.items.push(item);
}
});
var CListItem = Class.create(CNode, {
items: [],
initialize: function($super, item, className) {
className = className || '';
item = item || null;
$super('li');
this.setClass(className);
this.addItem(item);
},
addItem: function($super, item) {
$super(item);
this.items.push(item);
}
});