Fixes and improvements in the use of agents and monitors multiselects

This commit is contained in:
Alejandro Gallardo Escobar 2015-08-05 10:38:32 +02:00
parent d14e250ad8
commit 8fb71f8413
3 changed files with 63 additions and 50 deletions

View File

@ -50,7 +50,7 @@ require_once($config['homedir'] . "/include/functions_agents.php");
$table->id = 'wizard_table'; $table->id = 'wizard_table';
$table->head = array (); $table->head = array ();
if (!defined('METACONSOLE')) { if (!is_metaconsole()) {
$metaconsole_hack = ''; $metaconsole_hack = '';
$table->width = '100%'; $table->width = '100%';
$table->class = 'databox filters'; $table->class = 'databox filters';
@ -188,16 +188,17 @@ $table->data["percentileitem_4"][1] = html_print_radio_button_extended(
'value', false, '', 'style="float: left;"', true); 'value', false, '', 'style="float: left;"', true);
if (defined('METACONSOLE')) { if (is_metaconsole()) {
$table->rowstyle["all_2"] = 'display: none;'; $table->rowstyle["all_2"] = 'display: none;';
$table->data["all_2"][0] = __('Servers'); $table->data["all_2"][0] = __('Servers');
if ($strict_user) if ($strict_user)
$table->data["all_2"][1] = html_print_select('','server_id', $table->data["all_2"][1] = html_print_select('','servers',
$server_id, 'metaconsole_init();', __('All'), '0', true); '', 'metaconsole_init();', __('All'), '0', true);
else else
$sql = 'SELECT id, server_name
FROM tmetaconsole_setup';
$table->data["all_2"][1] = html_print_select_from_sql( $table->data["all_2"][1] = html_print_select_from_sql(
'SELECT id, server_name FROM tmetaconsole_setup', $sql, 'servers', '', 'metaconsole_init();', __('All'),
'server_id', $server_id, 'metaconsole_init();', __('All'),
'0', true); '0', true);
} }
@ -229,7 +230,7 @@ $table->rowstyle["all_4"] = 'display: none;';
$table->data["all_4"][0] = __('Agents'); $table->data["all_4"][0] = __('Agents');
$agents_list = array(); $agents_list = array();
if (!defined('METACONSOLE')) if (!is_metaconsole())
$agents_list = agents_get_group_agents(0, false, "none", false, $agents_list = agents_get_group_agents(0, false, "none", false,
true); true);
@ -282,7 +283,7 @@ $table->data["all_8"][3] = '<span id="parent_column_3_item_in_visual_map">' .
if (defined('METACONSOLE')) { if (is_metaconsole()) {
$pure = get_parameter('pure', 0); $pure = get_parameter('pure', 0);
echo '<form method="post" echo '<form method="post"
@ -303,7 +304,7 @@ if (defined("METACONSOLE")) {
html_print_table ($table); html_print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">'; echo '<div class="action-buttons" style="width: '.$table->width.'">';
if (defined('METACONSOLE')) { if (is_metaconsole()) {
html_print_input_hidden ('action2', 'update'); html_print_input_hidden ('action2', 'update');
} }
else { else {
@ -324,7 +325,7 @@ echo '<span id="loading_text" style="display: none;">' .
?> ?>
<script type="text/javascript"> <script type="text/javascript">
var metaconsole_enabled = <?php echo json_encode(defined('METACONSOLE')); ?>; var metaconsole_enabled = <?php echo (int) is_metaconsole(); ?>;
var show_only_enabled_modules = true; var show_only_enabled_modules = true;
var url_ajax = "ajax.php"; var url_ajax = "ajax.php";
@ -333,6 +334,8 @@ if (metaconsole_enabled) {
} }
$(document).ready (function () { $(document).ready (function () {
var noneText = $("#none_text").html(); //Trick for catch the translate text.
hidden_rows(); hidden_rows();
$("#process_value").change(function () { $("#process_value").change(function () {
@ -351,8 +354,17 @@ $(document).ready (function () {
}); });
$("#groups").change (function () { $("#groups").change (function () {
$('#module')
.prop('disabled', true)
.empty()
.append($('<option></option>')
.html(noneText)
.attr("None", "")
.attr('value', -1)
.prop('selected', true));
$('#id_agents') $('#id_agents')
.attr('disabled', true) .prop('disabled', true)
.empty () .empty ()
.css ("width", "auto") .css ("width", "auto")
.css ("max-width", "") .css ("max-width", "")
@ -362,6 +374,7 @@ $(document).ready (function () {
page: "include/ajax/agent", page: "include/ajax/agent",
get_agents_group: 1, get_agents_group: 1,
id_group: $("#groups").val(), id_group: $("#groups").val(),
serialized: 1,
mode: "json" mode: "json"
}; };
@ -377,8 +390,6 @@ $(document).ready (function () {
$('#id_agents').empty(); $('#id_agents').empty();
if (isEmptyObject(data)) { if (isEmptyObject(data)) {
var noneText = $("#none_text").html(); //Trick for catch the translate text.
$('#id_agents') $('#id_agents')
.append($('<option></option>') .append($('<option></option>')
.html(noneText) .html(noneText)
@ -388,14 +399,14 @@ $(document).ready (function () {
} }
else { else {
jQuery.each (data, function (i, val) { jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val); var s = js_html_entity_decode(val);
$('#id_agents') $('#id_agents')
.append($('<option></option>') .append($('<option></option>')
.html(s).attr("value", i)); .html(s).attr("value", i));
}); });
} }
$('#id_agents').removeAttr('disabled'); $('#id_agents').prop('disabled', false);
} }
}); });
}); });

View File

@ -170,43 +170,40 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
//Hack to find only enabled modules //Hack to find only enabled modules
//Pass a flag as global var //Pass a flag as global var
find_modules = 'all'; find_modules = 'all';
if (typeof(show_only_enabled_modules) != "undefined") { if (typeof show_only_enabled_modules !== 'undefined'
if (show_only_enabled_modules == true) { && show_only_enabled_modules) {
find_modules = 'enabled'; find_modules = 'enabled';
}
} }
var selection_mode = $('#modules_selection_mode').val(); var selection_mode = $('#modules_selection_mode').val();
if (selection_mode == undefined) { if (typeof selection_mode === 'undefined') {
selection_mode = 'common'; selection_mode = 'common';
} }
var serialized = $('#hidden-serialized').val(); var serialized = $('#hidden-serialized').val();
if (serialized == undefined) { if (typeof serialized === 'undefined') {
serialized = ''; serialized = '';
} }
$('#module').attr ('disabled', 1); $('#module')
$('#module').empty (); .prop('disabled', true)
$('#module').append ($('<option></option>') .empty()
.html ("Loading...").attr ("value", 0)); .append($('<option></option>')
.html("Loading...")
.attr("value", 0));
// Check if homedir was received like a JSON // Check if homedir was received like a JSON
homedir = ''; var homedir = '.';
id_server = 0; var id_server = 0;
if (typeof(event) == 'undefined') { if (typeof event !== 'undefined' && typeof event.data !== 'undefined') {
homedir += '.';
} if (typeof event.data.homedir !== 'undefined') {
else { homedir = event.data.homedir;
if (event.data == null) }
homedir += '.';
else { if (typeof event.data.metaconsole !== 'undefined'
homedir = event.data.homedir; && event.data.metaconsole) {
id_server = $("#" + event.data.id_server).val();
if (event.data.metaconsole != null) {
id_server = $("#" + event.data.id_server).val();
}
} }
} }
@ -272,7 +269,7 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
} }
} }
jQuery.each (data, function (i, val) { jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val); var s = js_html_entity_decode(val);
$('#module') $('#module')
.append ($('<option></option>') .append ($('<option></option>')
@ -282,20 +279,18 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
$('#module').fadeIn ('normal'); $('#module').fadeIn ('normal');
}); });
if (selected != undefined) if (typeof selected !== 'undefined')
$('#module').attr ('value', selected); $('#module').attr ('value', selected);
$('#module').css ("max-width", ""); $('#module')
.css ("max-width", "")
.prop('disabled', false);
$('#module').removeAttr('disabled');
if (typeof(function_hook_loaded_module_list) == 'function') { if (typeof(function_hook_loaded_module_list) == 'function') {
function_hook_loaded_module_list(); function_hook_loaded_module_list();
} }
}, },
"json" "json");
);
} }
/** /**

View File

@ -226,7 +226,7 @@ if (is_ajax ()) {
$serialized = get_parameter('serialized', ''); $serialized = get_parameter('serialized', '');
$id_server = (int) get_parameter('id_server', 0); $id_server = (int) get_parameter('id_server', 0);
$metaconsole_server_name = null; $metaconsole_server_name = null;
if ($id_server != 0) { if (!empty($id_server)) {
$metaconsole_server_name = db_get_value('server_name', $metaconsole_server_name = db_get_value('server_name',
'tmetaconsole_setup', 'id', $id_server); 'tmetaconsole_setup', 'id', $id_server);
} }
@ -308,7 +308,14 @@ if (is_ajax ()) {
foreach ($array_reduced as $server_name => $id_agents) { foreach ($array_reduced as $server_name => $id_agents) {
//Metaconsole db connection //Metaconsole db connection
$connection = metaconsole_get_connection($server_name); // $server_name can be the server id (ugly hack, I know)
if (is_numeric($server_name)) {
$connection = metaconsole_get_connection_by_id($server_name);
}
else {
$connection = metaconsole_get_connection($server_name);
}
if (metaconsole_load_external_db($connection) != NOERR) { if (metaconsole_load_external_db($connection) != NOERR) {
continue; continue;
} }