2014-12-16 18:32:01 +01:00
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
|
|
|
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2015-09-07 11:53:08 +02:00
|
|
|
var TreeController = {
|
2014-12-16 18:32:01 +01:00
|
|
|
controllers: [],
|
|
|
|
getController: function () {
|
|
|
|
var controller = {
|
|
|
|
index: -1,
|
|
|
|
recipient: '',
|
|
|
|
tree: [],
|
2015-03-25 10:31:32 +01:00
|
|
|
emptyMessage: "No data found.",
|
2018-02-27 11:46:28 +01:00
|
|
|
foundMessage: "Found items",
|
2014-12-16 18:32:01 +01:00
|
|
|
errorMessage: "Error",
|
2014-12-17 13:48:17 +01:00
|
|
|
baseURL: "",
|
2014-12-16 18:32:01 +01:00
|
|
|
ajaxURL: "ajax.php",
|
2014-12-17 19:45:09 +01:00
|
|
|
ajaxPage: "include/ajax/tree.ajax",
|
2014-12-17 19:11:07 +01:00
|
|
|
detailRecipient: '',
|
2014-12-17 19:46:33 +01:00
|
|
|
filter: {},
|
2014-12-30 12:43:18 +01:00
|
|
|
counterTitles: {},
|
2015-01-19 17:33:23 +01:00
|
|
|
shouldHaveCounters: true,
|
2014-12-16 18:32:01 +01:00
|
|
|
reload: function () {
|
2014-12-17 19:11:07 +01:00
|
|
|
// Bad recipient
|
2014-12-16 18:32:01 +01:00
|
|
|
if (typeof this.recipient == 'undefined' || this.recipient.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-17 19:11:07 +01:00
|
|
|
// Load branch
|
2014-12-17 20:12:21 +01:00
|
|
|
function _processGroup (container, elements, rootGroup) {
|
2014-12-16 18:32:01 +01:00
|
|
|
var $group = $("<ul></ul>");
|
2014-12-16 19:57:48 +01:00
|
|
|
|
2014-12-17 19:11:07 +01:00
|
|
|
// First group
|
2014-12-16 19:57:48 +01:00
|
|
|
if (typeof rootGroup != 'undefinded' && rootGroup == true) {
|
|
|
|
$group
|
|
|
|
.addClass("tree-root")
|
2014-12-17 13:48:17 +01:00
|
|
|
.hide()
|
2015-04-06 13:49:28 +02:00
|
|
|
.prepend('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')+'images/pandora.png" />');
|
2014-12-16 19:57:48 +01:00
|
|
|
}
|
2014-12-17 19:11:07 +01:00
|
|
|
// Normal group
|
2014-12-16 19:57:48 +01:00
|
|
|
else {
|
|
|
|
$group
|
|
|
|
.addClass("tree-group")
|
|
|
|
.hide();
|
|
|
|
}
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
container.append($group);
|
2015-01-22 16:56:44 +01:00
|
|
|
|
2015-07-06 18:26:13 +02:00
|
|
|
_.each(elements, function(element) {
|
2015-01-14 17:56:42 +01:00
|
|
|
element.jqObject = _processNode($group, element);
|
2015-07-06 18:26:13 +02:00
|
|
|
});
|
2015-01-02 09:09:56 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
return $group;
|
|
|
|
}
|
2014-12-30 12:43:18 +01:00
|
|
|
|
|
|
|
// Load leaf counters
|
|
|
|
function _processNodeCounters (container, counters, type) {
|
2015-01-19 17:47:22 +01:00
|
|
|
var hasCounters = false;
|
2015-01-19 17:35:46 +01:00
|
|
|
|
2014-12-30 12:43:18 +01:00
|
|
|
if (typeof counters != 'undefined') {
|
|
|
|
|
|
|
|
function _processNodeCounterTitle (container, elementType, counterType) {
|
|
|
|
var defaultCounterTitles = {
|
|
|
|
total: {
|
|
|
|
agents: "Total agents",
|
|
|
|
modules: "Total modules",
|
|
|
|
none: "Total"
|
|
|
|
},
|
2015-01-29 21:00:30 +01:00
|
|
|
alerts: {
|
|
|
|
agents: "Alerts fired",
|
|
|
|
modules: "Alerts fired",
|
|
|
|
none: "Alerts fired"
|
2014-12-30 12:43:18 +01:00
|
|
|
},
|
|
|
|
critical: {
|
|
|
|
agents: "Critical agents",
|
|
|
|
modules: "Critical modules",
|
|
|
|
none: "Critical"
|
|
|
|
},
|
|
|
|
warning: {
|
|
|
|
agents: "Warning agents",
|
|
|
|
modules: "Warning modules",
|
|
|
|
none: "Warning"
|
|
|
|
},
|
|
|
|
unknown: {
|
|
|
|
agents: "Unknown agents",
|
|
|
|
modules: "Unknown modules",
|
|
|
|
none: "Unknown"
|
|
|
|
},
|
|
|
|
not_init: {
|
|
|
|
agents: "Not init agents",
|
|
|
|
modules: "Not init modules",
|
|
|
|
none: "Not init"
|
|
|
|
},
|
|
|
|
ok: {
|
|
|
|
agents: "Normal agents",
|
|
|
|
modules: "Normal modules",
|
|
|
|
none: "Normal"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var title = '';
|
|
|
|
switch (elementType) {
|
|
|
|
case "group":
|
|
|
|
if (typeof controller.counterTitles != 'undefined'
|
|
|
|
&& typeof controller.counterTitles[counterType] != 'undefined'
|
|
|
|
&& typeof controller.counterTitles[counterType].agents != 'undefined') {
|
|
|
|
title = controller.counterTitles[counterType].agents;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
title = defaultCounterTitles[counterType].agents;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "agent":
|
|
|
|
if (typeof controller.counterTitles != 'undefined'
|
|
|
|
&& typeof controller.counterTitles[counterType] != 'undefined'
|
|
|
|
&& typeof controller.counterTitles[counterType].modules != 'undefined') {
|
|
|
|
title = controller.counterTitles[counterType].modules;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
title = defaultCounterTitles[counterType].modules;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (typeof controller.counterTitles != 'undefined'
|
|
|
|
&& typeof controller.counterTitles[counterType] != 'undefined'
|
|
|
|
&& typeof controller.counterTitles[counterType].none != 'undefined') {
|
|
|
|
title = controller.counterTitles[counterType].none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
title = defaultCounterTitles[counterType].none;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (title.length > 0) {
|
|
|
|
container
|
2015-07-02 13:10:39 +02:00
|
|
|
.data("title", title)
|
2014-12-30 12:43:18 +01:00
|
|
|
.addClass("forced_title")
|
|
|
|
.data("use_title_for_force_title", 1); // Trick to make easier the 'force title' output
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
// console.log(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var $counters = $("<div></div>");
|
|
|
|
$counters.addClass('tree-node-counters');
|
|
|
|
|
|
|
|
if (typeof counters.total != 'undefined'
|
|
|
|
&& counters.total > 0) {
|
|
|
|
var $totalCounter = $("<div></div>");
|
|
|
|
$totalCounter
|
|
|
|
.addClass('tree-node-counter')
|
|
|
|
.addClass('total')
|
|
|
|
.html(counters.total);
|
|
|
|
|
|
|
|
_processNodeCounterTitle($totalCounter, type, "total");
|
|
|
|
|
|
|
|
// Open the parentheses
|
|
|
|
$counters.append(" (");
|
|
|
|
|
|
|
|
$counters.append($totalCounter);
|
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
if (typeof counters.alerts != 'undefined'
|
|
|
|
&& counters.alerts > 0) {
|
2014-12-30 12:43:18 +01:00
|
|
|
var $firedCounter = $("<div></div>");
|
|
|
|
$firedCounter
|
|
|
|
.addClass('tree-node-counter')
|
2015-01-29 21:00:30 +01:00
|
|
|
.addClass('alerts')
|
2014-12-30 12:43:18 +01:00
|
|
|
.addClass('orange')
|
2015-01-29 21:00:30 +01:00
|
|
|
.html(counters.alerts);
|
2014-12-30 12:43:18 +01:00
|
|
|
|
2015-01-29 21:00:30 +01:00
|
|
|
_processNodeCounterTitle($firedCounter, type, "alerts");
|
2014-12-30 12:43:18 +01:00
|
|
|
|
|
|
|
$counters
|
|
|
|
.append(" : ")
|
|
|
|
.append($firedCounter);
|
|
|
|
}
|
|
|
|
if (typeof counters.critical != 'undefined'
|
|
|
|
&& counters.critical > 0) {
|
|
|
|
var $criticalCounter = $("<div></div>");
|
|
|
|
$criticalCounter
|
|
|
|
.addClass('tree-node-counter')
|
|
|
|
.addClass('critical')
|
|
|
|
.addClass('red')
|
|
|
|
.html(counters.critical);
|
|
|
|
|
|
|
|
_processNodeCounterTitle($criticalCounter, type, "critical");
|
|
|
|
|
|
|
|
$counters
|
|
|
|
.append(" : ")
|
|
|
|
.append($criticalCounter);
|
|
|
|
}
|
|
|
|
if (typeof counters.warning != 'undefined'
|
|
|
|
&& counters.warning > 0) {
|
|
|
|
var $warningCounter = $("<div></div>");
|
|
|
|
$warningCounter
|
|
|
|
.addClass('tree-node-counter')
|
|
|
|
.addClass('warning')
|
|
|
|
.addClass('yellow')
|
|
|
|
.html(counters.warning);
|
|
|
|
|
|
|
|
_processNodeCounterTitle($warningCounter, type, "warning");
|
|
|
|
|
|
|
|
$counters
|
|
|
|
.append(" : ")
|
|
|
|
.append($warningCounter);
|
|
|
|
}
|
|
|
|
if (typeof counters.unknown != 'undefined'
|
|
|
|
&& counters.unknown > 0) {
|
|
|
|
var $unknownCounter = $("<div></div>");
|
|
|
|
$unknownCounter
|
|
|
|
.addClass('tree-node-counter')
|
|
|
|
.addClass('unknown')
|
|
|
|
.addClass('grey')
|
|
|
|
.html(counters.unknown);
|
|
|
|
|
|
|
|
_processNodeCounterTitle($unknownCounter, type, "unknown");
|
|
|
|
|
|
|
|
$counters
|
|
|
|
.append(" : ")
|
|
|
|
.append($unknownCounter);
|
|
|
|
}
|
|
|
|
if (typeof counters.not_init != 'undefined'
|
|
|
|
&& counters.not_init > 0) {
|
|
|
|
var $notInitCounter = $("<div></div>");
|
|
|
|
$notInitCounter
|
|
|
|
.addClass('tree-node-counter')
|
|
|
|
.addClass('not_init')
|
|
|
|
.addClass('blue')
|
|
|
|
.html(counters.not_init);
|
|
|
|
|
|
|
|
_processNodeCounterTitle($notInitCounter, type, "not_init");
|
|
|
|
|
|
|
|
$counters
|
|
|
|
.append(" : ")
|
|
|
|
.append($notInitCounter);
|
|
|
|
}
|
|
|
|
if (typeof counters.ok != 'undefined'
|
|
|
|
&& counters.ok > 0) {
|
|
|
|
var $okCounter = $("<div></div>");
|
|
|
|
$okCounter
|
|
|
|
.addClass('tree-node-counter')
|
|
|
|
.addClass('ok')
|
|
|
|
.addClass('green')
|
|
|
|
.html(counters.ok);
|
|
|
|
|
|
|
|
_processNodeCounterTitle($okCounter, type, "ok");
|
|
|
|
|
|
|
|
$counters
|
|
|
|
.append(" : ")
|
|
|
|
.append($okCounter);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close the parentheses
|
|
|
|
$counters.append(")");
|
2015-01-19 17:35:46 +01:00
|
|
|
|
|
|
|
hasCounters = true;
|
2014-12-30 12:43:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the counters html to the container
|
|
|
|
container.append($counters);
|
|
|
|
}
|
2015-01-19 17:35:46 +01:00
|
|
|
|
|
|
|
return hasCounters;
|
2014-12-30 12:43:18 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 19:11:07 +01:00
|
|
|
// Load leaf
|
2015-01-14 17:56:42 +01:00
|
|
|
function _processNode (container, element) {
|
2015-09-07 11:53:08 +02:00
|
|
|
|
|
|
|
// type, [id], [serverID], callback
|
|
|
|
function _getTreeDetailData (type, id, serverID, callback) {
|
|
|
|
var lastParam = arguments[arguments.length - 1];
|
|
|
|
var callback;
|
|
|
|
if (typeof lastParam === 'function')
|
|
|
|
callback = lastParam;
|
|
|
|
|
|
|
|
var serverID;
|
|
|
|
if (arguments.length >= 4)
|
|
|
|
serverID = arguments[2];
|
|
|
|
var id;
|
|
|
|
if (arguments.length >= 3)
|
|
|
|
id = arguments[1];
|
|
|
|
var type;
|
|
|
|
if (arguments.length >= 2)
|
|
|
|
type = arguments[0];
|
|
|
|
|
|
|
|
if (typeof type === 'undefined')
|
|
|
|
throw new TypeError('Type required');
|
|
|
|
if (typeof callback === 'undefined')
|
|
|
|
throw new TypeError('Callback required');
|
|
|
|
|
|
|
|
var postData = {
|
|
|
|
page: controller.ajaxPage,
|
|
|
|
getDetail: 1,
|
|
|
|
type: type
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof id !== 'undefined')
|
|
|
|
postData.id = id;
|
|
|
|
if (typeof serverID !== 'undefined')
|
|
|
|
postData.serverID = serverID;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: controller.ajaxURL,
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'html',
|
|
|
|
data: postData,
|
|
|
|
success: function(data, textStatus, xhr) {
|
|
|
|
callback(null, data);
|
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
callback(errorThrown);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
var $node = $("<li></li>");
|
|
|
|
var $leafIcon = $("<div></div>");
|
|
|
|
var $content = $("<div></div>");
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
// Leaf icon
|
|
|
|
$leafIcon.addClass("leaf-icon");
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
// Content
|
|
|
|
$content.addClass("node-content");
|
|
|
|
switch (element.type) {
|
|
|
|
case 'group':
|
2014-12-18 18:13:22 +01:00
|
|
|
if (typeof element.icon != 'undefined' && element.icon.length > 0) {
|
|
|
|
$content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
|
2015-01-05 16:48:11 +01:00
|
|
|
+'images/groups_small/'+element.icon+'" /> ');
|
2014-12-18 18:13:22 +01:00
|
|
|
}
|
2015-01-14 17:56:42 +01:00
|
|
|
else if (typeof element.iconHTML != 'undefined' && element.iconHTML.length > 0) {
|
2015-03-09 19:29:45 +01:00
|
|
|
$content.append(element.iconHTML + " ");
|
2015-01-14 17:56:42 +01:00
|
|
|
}
|
2014-12-16 18:32:01 +01:00
|
|
|
$content.append(element.name);
|
|
|
|
break;
|
|
|
|
case 'agent':
|
2015-01-29 21:00:30 +01:00
|
|
|
// Is quiet
|
|
|
|
if (typeof element.quietImageHTML != 'undefined'
|
|
|
|
&& element.quietImageHTML.length > 0) {
|
|
|
|
var $quietImage = $(element.quietImageHTML);
|
|
|
|
$quietImage.addClass("agent-quiet");
|
|
|
|
|
|
|
|
$content.append($quietImage);
|
|
|
|
}
|
2015-01-12 11:08:05 +01:00
|
|
|
// Status image
|
|
|
|
if (typeof element.statusImageHTML != 'undefined'
|
|
|
|
&& element.statusImageHTML.length > 0) {
|
|
|
|
var $statusImage = $(element.statusImageHTML);
|
|
|
|
$statusImage.addClass("agent-status");
|
|
|
|
|
|
|
|
$content.append($statusImage);
|
|
|
|
}
|
|
|
|
// Alerts fired image
|
|
|
|
if (typeof element.alertImageHTML != 'undefined'
|
|
|
|
&& element.alertImageHTML.length > 0) {
|
|
|
|
var $alertImage = $(element.alertImageHTML);
|
|
|
|
$alertImage.addClass("agent-alerts-fired");
|
|
|
|
|
|
|
|
$content.append($alertImage);
|
|
|
|
}
|
2016-09-26 10:58:42 +02:00
|
|
|
$content.append(element.alias);
|
2014-12-19 13:02:30 +01:00
|
|
|
break;
|
2014-12-18 18:13:22 +01:00
|
|
|
case 'module':
|
2015-01-12 11:08:05 +01:00
|
|
|
// Status image
|
|
|
|
if (typeof element.statusImageHTML != 'undefined'
|
|
|
|
&& element.statusImageHTML.length > 0) {
|
|
|
|
var $statusImage = $(element.statusImageHTML);
|
|
|
|
$statusImage.addClass("module-status");
|
|
|
|
|
|
|
|
$content.append($statusImage);
|
|
|
|
}
|
2015-01-08 13:18:27 +01:00
|
|
|
// Server type
|
|
|
|
if (typeof element.serverTypeHTML != 'undefined'
|
|
|
|
&& element.serverTypeHTML.length > 0
|
|
|
|
&& element.serverTypeHTML != '--') {
|
|
|
|
var $serverTypeImage = $(element.serverTypeHTML);
|
|
|
|
$serverTypeImage.addClass("module-server-type");
|
|
|
|
|
2015-01-12 11:08:05 +01:00
|
|
|
$content.append($serverTypeImage);
|
2015-01-08 13:18:27 +01:00
|
|
|
}
|
2015-01-08 11:45:31 +01:00
|
|
|
|
2015-03-23 20:51:44 +01:00
|
|
|
if (typeof element.showGraphs != 'undefined' && element.showGraphs != 0) {
|
|
|
|
// Graph pop-up
|
|
|
|
if (typeof element.moduleGraph != 'undefined') {
|
2016-10-26 18:39:41 +02:00
|
|
|
|
|
|
|
if(element.statusImageHTML.indexOf('data:image')!=-1){
|
2015-03-23 20:51:44 +01:00
|
|
|
var $graphImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
|
2016-10-26 18:39:41 +02:00
|
|
|
+'images/photo.png" /> ');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
|
|
|
|
var $graphImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
|
2018-03-12 15:17:59 +01:00
|
|
|
+'images/chart_curve.png" /> ');
|
2016-10-26 18:39:41 +02:00
|
|
|
}
|
2018-03-12 15:17:59 +01:00
|
|
|
|
2015-03-23 20:51:44 +01:00
|
|
|
$graphImage
|
|
|
|
.addClass('module-graph')
|
|
|
|
.click(function (e) {
|
|
|
|
e.preventDefault();
|
2018-03-02 10:58:37 +01:00
|
|
|
if(element.statusImageHTML.indexOf('data:image')!=-1){
|
|
|
|
try {
|
2018-03-12 15:17:59 +01:00
|
|
|
winopeng_var(
|
|
|
|
decodeURI(element.snapshot[0]),
|
|
|
|
element.snapshot[1],
|
|
|
|
element.snapshot[2],
|
|
|
|
element.snapshot[3]
|
|
|
|
);
|
2018-03-02 10:58:37 +01:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
// console.log(error);
|
|
|
|
}
|
2015-03-23 20:51:44 +01:00
|
|
|
}
|
2018-03-02 10:58:37 +01:00
|
|
|
else{
|
|
|
|
try {
|
2016-10-26 18:39:41 +02:00
|
|
|
winopeng(element.moduleGraph.url, element.moduleGraph.handle);
|
2018-03-02 10:58:37 +01:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
// console.log(error);
|
|
|
|
}
|
2016-10-26 18:39:41 +02:00
|
|
|
}
|
2015-03-23 20:51:44 +01:00
|
|
|
});
|
2015-01-21 17:37:51 +01:00
|
|
|
|
2015-03-23 20:51:44 +01:00
|
|
|
$content.append($graphImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data pop-up
|
|
|
|
if (typeof element.id != 'undefined' && !isNaN(element.id)) {
|
|
|
|
|
|
|
|
var $dataImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
|
|
|
|
+'images/binary.png" /> ');
|
|
|
|
$dataImage
|
|
|
|
.addClass('module-data')
|
|
|
|
.click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
try {
|
|
|
|
var serverName = element.serverName.length > 0 ? element.serverName : '';
|
|
|
|
if ($("#module_details_window").length > 0)
|
2015-04-20 17:44:21 +02:00
|
|
|
show_module_detail_dialog(element.id, '', serverName, 0, 86400, element.name.replace(/ /g , " ") );
|
2015-03-23 20:51:44 +01:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
// console.log(error);
|
|
|
|
}
|
|
|
|
});
|
2015-01-30 20:06:49 +01:00
|
|
|
|
2015-03-23 20:51:44 +01:00
|
|
|
$content.append($dataImage);
|
|
|
|
}
|
2015-01-30 20:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Alerts
|
|
|
|
if (typeof element.alertsImageHTML != 'undefined'
|
|
|
|
&& element.alertsImageHTML.length > 0) {
|
|
|
|
|
|
|
|
var $alertsImage = $(element.alertsImageHTML);
|
|
|
|
|
|
|
|
$alertsImage
|
|
|
|
.addClass("module-alerts")
|
|
|
|
.click(function (e) {
|
2015-09-07 11:53:08 +02:00
|
|
|
_getTreeDetailData('alert', element.id, element.serverID, function (error, data) {
|
|
|
|
if (error) {
|
|
|
|
// console.error(error);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
controller.detailRecipient.render(element.name, data).open();
|
|
|
|
}
|
2015-01-30 20:06:49 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Avoid the execution of the module detail event
|
|
|
|
e.stopPropagation();
|
|
|
|
})
|
|
|
|
.css('cursor', 'pointer');
|
|
|
|
|
|
|
|
$content.append($alertsImage);
|
2015-01-21 17:37:51 +01:00
|
|
|
}
|
2015-01-08 11:45:31 +01:00
|
|
|
|
2015-01-30 20:06:49 +01:00
|
|
|
$content.append(element.name);
|
2014-12-16 18:32:01 +01:00
|
|
|
break;
|
2015-01-02 12:37:19 +01:00
|
|
|
case 'os':
|
|
|
|
if (typeof element.icon != 'undefined' && element.icon.length > 0) {
|
|
|
|
$content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
|
2015-01-05 16:48:11 +01:00
|
|
|
+'images/os_icons/'+element.icon+'" /> ');
|
|
|
|
}
|
|
|
|
$content.append(element.name);
|
|
|
|
break;
|
|
|
|
case 'tag':
|
|
|
|
if (typeof element.icon != 'undefined' && element.icon.length > 0) {
|
|
|
|
$content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
|
|
|
|
+'images/os_icons/'+element.icon+'" /> ');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
|
|
|
|
+'images/tag_red.png" /> ');
|
2015-01-02 12:37:19 +01:00
|
|
|
}
|
|
|
|
$content.append(element.name);
|
|
|
|
break;
|
2014-12-17 19:11:07 +01:00
|
|
|
default:
|
|
|
|
$content.append(element.name);
|
|
|
|
break;
|
|
|
|
}
|
2014-12-18 18:13:22 +01:00
|
|
|
|
|
|
|
// Load the status counters
|
2015-01-19 17:33:23 +01:00
|
|
|
var hasCounters = _processNodeCounters($content, element.counters, element.type);
|
2016-01-28 11:09:09 +01:00
|
|
|
//Don't show empty groups
|
2016-01-29 14:48:41 +01:00
|
|
|
if (element.type == 'agent') {
|
|
|
|
if (!hasCounters) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-28 11:09:09 +01:00
|
|
|
}
|
2014-12-17 19:11:07 +01:00
|
|
|
// If exist the detail container, show the data
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof controller.detailRecipient !== 'undefined') {
|
2015-01-29 21:00:30 +01:00
|
|
|
if (element.type == 'agent' || element.type == 'module') {
|
|
|
|
$content.click(function (e) {
|
2015-09-07 11:53:08 +02:00
|
|
|
_getTreeDetailData(element.type, element.id, element.serverID, function (error, data) {
|
|
|
|
if (error) {
|
|
|
|
// console.error(error);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
controller.detailRecipient.render(element.name, data).open();
|
|
|
|
}
|
2015-01-29 21:00:30 +01:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.css('cursor', 'pointer');
|
|
|
|
}
|
2014-12-16 18:32:01 +01:00
|
|
|
}
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
$node
|
|
|
|
.addClass("tree-node")
|
|
|
|
.append($leafIcon)
|
|
|
|
.append($content);
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
container.append($node);
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
$node.addClass("leaf-empty");
|
|
|
|
|
2014-12-30 16:23:31 +01:00
|
|
|
if (typeof element.children != 'undefined' && element.children.length > 0) {
|
2015-01-14 17:56:42 +01:00
|
|
|
$node
|
|
|
|
.removeClass("leaf-empty")
|
|
|
|
.addClass("leaf-closed");
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
// Add children
|
2014-12-30 16:23:31 +01:00
|
|
|
var $children = _processGroup($node, element.children);
|
2014-12-16 18:32:01 +01:00
|
|
|
$node.data('children', $children);
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (typeof element.searchChildren == 'undefined' || !element.searchChildren) {
|
|
|
|
$leafIcon.click(function (e) {
|
|
|
|
e.preventDefault();
|
2014-12-18 18:13:22 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if ($node.hasClass("leaf-open")) {
|
|
|
|
$node
|
|
|
|
.removeClass("leaf-open")
|
|
|
|
.addClass("leaf-closed")
|
|
|
|
.data('children')
|
|
|
|
.slideUp();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$node
|
|
|
|
.removeClass("leaf-closed")
|
|
|
|
.addClass("leaf-open")
|
|
|
|
.data('children')
|
|
|
|
.slideDown();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-12-16 18:32:01 +01:00
|
|
|
}
|
2017-11-21 16:59:49 +01:00
|
|
|
// Get hash and user.
|
|
|
|
var public_hash = $("#hidden-publi_dash_tree_view_hash" ).val();
|
|
|
|
if (typeof(public_hash) === 'undefined') public_hash = 0;
|
|
|
|
var public_user = $("#hidden-publi_dash_tree_view_id_user" ).val();
|
|
|
|
if (typeof(public_user) === 'undefined') public_user = 0;
|
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
if (typeof element.searchChildren != 'undefined' && element.searchChildren) {
|
|
|
|
$node
|
|
|
|
.removeClass("leaf-empty")
|
|
|
|
.addClass("leaf-closed");
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-17 19:45:09 +01:00
|
|
|
$leafIcon.click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2015-01-28 18:57:33 +01:00
|
|
|
if (!$node.hasClass("leaf-loading") && !$node.hasClass("children-loaded") && !$node.hasClass("leaf-empty")) {
|
2014-12-16 18:32:01 +01:00
|
|
|
$node
|
|
|
|
.removeClass("leaf-closed")
|
|
|
|
.removeClass("leaf-error")
|
|
|
|
.addClass("leaf-loading");
|
2014-12-18 11:20:21 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
$.ajax({
|
2014-12-17 19:45:09 +01:00
|
|
|
url: controller.ajaxURL,
|
2014-12-16 18:32:01 +01:00
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
2014-12-17 19:45:09 +01:00
|
|
|
page: controller.ajaxPage,
|
2014-12-16 18:32:01 +01:00
|
|
|
getChildren: 1,
|
|
|
|
id: element.id,
|
2014-12-17 19:46:33 +01:00
|
|
|
type: element.type,
|
2015-01-21 17:37:51 +01:00
|
|
|
rootID: element.rootID,
|
2015-01-30 15:32:39 +01:00
|
|
|
serverID: element.serverID,
|
2015-01-21 17:37:51 +01:00
|
|
|
rootType: element.rootType,
|
2017-11-21 16:59:49 +01:00
|
|
|
filter: controller.filter,
|
|
|
|
hash: public_hash,
|
|
|
|
id_user: public_user
|
2014-12-16 18:32:01 +01:00
|
|
|
},
|
|
|
|
complete: function(xhr, textStatus) {
|
|
|
|
$node.removeClass("leaf-loading");
|
2014-12-18 18:13:22 +01:00
|
|
|
$node.addClass("children-loaded");
|
2014-12-16 18:32:01 +01:00
|
|
|
},
|
|
|
|
success: function(data, textStatus, xhr) {
|
|
|
|
if (data.success) {
|
2015-01-19 17:09:31 +01:00
|
|
|
var $group = $node.children("ul.tree-group");
|
2015-01-14 17:56:42 +01:00
|
|
|
|
2015-01-19 17:07:07 +01:00
|
|
|
if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) {
|
|
|
|
$node.addClass("leaf-open");
|
2015-01-14 17:56:42 +01:00
|
|
|
|
|
|
|
if ($group.length <= 0) {
|
|
|
|
$group = $("<ul></ul>");
|
|
|
|
$group
|
|
|
|
.addClass("tree-group")
|
|
|
|
.hide();
|
|
|
|
$node.append($group);
|
|
|
|
}
|
2014-12-18 11:20:21 +01:00
|
|
|
|
2015-07-06 18:26:13 +02:00
|
|
|
_.each(data.tree, function(element) {
|
2015-01-14 17:56:42 +01:00
|
|
|
element.jqObject = _processNode($group, element);
|
2015-07-06 18:26:13 +02:00
|
|
|
});
|
2014-12-18 09:55:54 +01:00
|
|
|
|
2015-01-14 17:56:42 +01:00
|
|
|
$group.slideDown();
|
|
|
|
|
|
|
|
$node.data('children', $group);
|
|
|
|
|
|
|
|
// Add again the hover event to the 'force_callback' elements
|
|
|
|
forced_title_callback();
|
2014-12-18 09:55:54 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$node.addClass("leaf-empty");
|
|
|
|
}
|
2014-12-16 18:32:01 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$node.addClass("leaf-error");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
$node.addClass("leaf-error");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-12-18 09:55:54 +01:00
|
|
|
else if (! $node.hasClass("leaf-empty")) {
|
2014-12-16 18:32:01 +01:00
|
|
|
if ($node.hasClass("leaf-open")) {
|
|
|
|
$node
|
|
|
|
.removeClass("leaf-open")
|
|
|
|
.addClass("leaf-closed")
|
|
|
|
.data('children')
|
|
|
|
.slideUp();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$node
|
|
|
|
.removeClass("leaf-closed")
|
|
|
|
.addClass("leaf-open")
|
|
|
|
.data('children')
|
|
|
|
.slideDown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
return $node;
|
|
|
|
}
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-17 20:12:21 +01:00
|
|
|
if (controller.recipient.length == 0) {
|
2014-12-16 18:32:01 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-12-17 20:12:21 +01:00
|
|
|
else if (controller.tree.length == 0) {
|
2015-01-22 16:56:44 +01:00
|
|
|
controller.recipient.empty();
|
2014-12-17 20:12:21 +01:00
|
|
|
controller.recipient.html("<div>" + controller.emptyMessage + "</div>");
|
2014-12-16 18:32:01 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-17 20:12:21 +01:00
|
|
|
controller.recipient.empty();
|
2018-02-27 11:46:28 +01:00
|
|
|
controller.recipient.html(
|
|
|
|
"<div> " +
|
|
|
|
controller.foundMessage + ": " + controller.tree.length +
|
|
|
|
"</div>" +
|
|
|
|
"<br/>"
|
|
|
|
);
|
2014-12-16 18:32:01 +01:00
|
|
|
|
2014-12-17 20:12:21 +01:00
|
|
|
var $children = _processGroup(this.recipient, this.tree, true);
|
2014-12-16 18:32:01 +01:00
|
|
|
$children.show();
|
2014-12-17 19:46:33 +01:00
|
|
|
|
2014-12-17 20:12:21 +01:00
|
|
|
controller.recipient.data('children', $children);
|
2015-01-02 09:09:56 +01:00
|
|
|
|
|
|
|
// Add again the hover event to the 'force_callback' elements
|
|
|
|
forced_title_callback();
|
2014-12-16 18:32:01 +01:00
|
|
|
},
|
|
|
|
load: function () {
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
changeTree: function (tree) {
|
|
|
|
this.tree = tree;
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
init: function (data) {
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.recipient !== 'undefined' && data.recipient.length > 0) {
|
2014-12-16 18:32:01 +01:00
|
|
|
this.recipient = data.recipient;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.detailRecipient !== 'undefined') {
|
2014-12-17 19:11:07 +01:00
|
|
|
this.detailRecipient = data.detailRecipient;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.tree !== 'undefined') {
|
2014-12-16 18:32:01 +01:00
|
|
|
this.tree = data.tree;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.emptyMessage !== 'undefined' && data.emptyMessage.length > 0) {
|
2014-12-16 18:32:01 +01:00
|
|
|
this.emptyMessage = data.emptyMessage;
|
|
|
|
}
|
2018-02-27 11:46:28 +01:00
|
|
|
if (typeof data.foundMessage !== 'undefined' && data.foundMessage.length > 0) {
|
|
|
|
this.foundMessage = data.foundMessage;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.errorMessage !== 'undefined' && data.errorMessage.length > 0) {
|
2014-12-16 18:32:01 +01:00
|
|
|
this.errorMessage = data.errorMessage;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.baseURL !== 'undefined' && data.baseURL.length > 0) {
|
2014-12-17 13:48:17 +01:00
|
|
|
this.baseURL = data.baseURL;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.ajaxURL !== 'undefined' && data.ajaxURL.length > 0) {
|
2014-12-16 18:32:01 +01:00
|
|
|
this.ajaxURL = data.ajaxURL;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.ajaxPage !== 'undefined' && data.ajaxPage.length > 0) {
|
2014-12-16 18:32:01 +01:00
|
|
|
this.ajaxPage = data.ajaxPage;
|
|
|
|
}
|
2015-09-07 11:53:08 +02:00
|
|
|
if (typeof data.filter !== 'undefined') {
|
2014-12-17 19:46:33 +01:00
|
|
|
this.filter = data.filter;
|
|
|
|
}
|
2014-12-16 18:32:01 +01:00
|
|
|
|
|
|
|
this.load();
|
|
|
|
},
|
|
|
|
remove: function () {
|
2014-12-17 19:11:07 +01:00
|
|
|
if (typeof this.recipient != 'undefined' && this.recipient.length > 0) {
|
|
|
|
this.recipient.empty();
|
2014-12-16 18:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.index > -1) {
|
|
|
|
TreeController.controllers.splice(this.index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-18 11:20:21 +01:00
|
|
|
controller.index = TreeController.controllers.push(controller) - 1;
|
|
|
|
|
2014-12-16 18:32:01 +01:00
|
|
|
return controller;
|
|
|
|
}
|
2014-12-17 19:11:07 +01:00
|
|
|
}
|