From d48d55cb04d50d83bfd048d90a64892878a6b969 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Thu, 5 Jul 2012 09:16:57 +0000 Subject: [PATCH] 2012-07-05 Sergio Martin * include/functions_html.php include/javascript/pandora_modules.js include/javascript/pandora.js godmode/agentes/module_manager_editor_common.php godmode/modules/manage_network_components_form_common.php: Fixed several bugs of the network/local components javascript code and added new fields to local components Add new code on advanced select for time to update it from javascript and a workaround to do it from code loaded through ajax git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6736 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 13 ++++ .../agentes/module_manager_editor_common.php | 2 +- .../manage_network_components_form_common.php | 4 +- pandora_console/include/functions_html.php | 25 ++++-- pandora_console/include/javascript/pandora.js | 13 ++++ .../include/javascript/pandora_modules.js | 78 +++++++++++++------ 6 files changed, 102 insertions(+), 33 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index cec6050506..cc4bd5c094 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2012-07-05 Sergio Martin + + * include/functions_html.php + include/javascript/pandora_modules.js + include/javascript/pandora.js + godmode/agentes/module_manager_editor_common.php + godmode/modules/manage_network_components_form_common.php: + Fixed several bugs of the network/local components javascript + code and added new fields to local components + Add new code on advanced select for time to update it from + javascript and a workaround to do it from code loaded through + ajax + 2012-07-04 Sergio Martin * include/functions_menu.php diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 8824bc213e..bf37784de9 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -245,7 +245,7 @@ $table_advanced->data[1][4] = html_print_input_text ('module_ff_interval', $ff_i $table_advanced->data[2][0] = __('Interval').ui_print_help_tip (__('Module execution time interval.'), true); $table_advanced->colspan[2][1] = 2; -$table_advanced->data[2][1] = html_print_extended_select_for_time ('module_interval' , $interval, '', '', '0', false, true); +$table_advanced->data[2][1] = html_print_extended_select_for_time ('module_interval' , $interval, '', '', '0', false, true, false, false); $table_advanced->data[2][3] = __('Post process').' ' . ui_print_help_icon ('postprocess', true); $table_advanced->data[2][4] = html_print_input_text ('post_process', diff --git a/pandora_console/godmode/modules/manage_network_components_form_common.php b/pandora_console/godmode/modules/manage_network_components_form_common.php index b7c350d548..d6fa992649 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_common.php +++ b/pandora_console/godmode/modules/manage_network_components_form_common.php @@ -65,8 +65,8 @@ $table->data[2][0] = __('Group'); $table->data[2][1] = html_print_select (network_components_get_groups (), 'id_group', $id_group, '', '', '', true, false, false); $table->data[2][2] = __('Interval'); -$table->data[2][3] = html_print_input_text ('module_interval', $module_interval, '', - 5, 15, true); +$table->data[2][3] = html_print_extended_select_for_time ('module_interval' , $module_interval, '', '', '0', false, true); + $table->data[3][0] = __('Warning status'); $table->data[3][1] = ''.__('Min.').''; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index c72d33773a..144969e50a 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -428,12 +428,13 @@ function html_print_select_from_sql ($sql, $name, $selected = '', * @param variant Value when nothing is selected * @param integer $size Size of the input. * @param bool Whether to return an output string or echo now (optional, echo by default). + * @param bool Wherter to assign to combo a unique name (to have more than one on same page, like dashboard) * * @return string HTML code if return parameter is true. */ function html_print_extended_select_for_time ($name, $selected = '', $script = '', $nothing = '', - $nothing_value = '0', $size = false, $return = false, $select_style = false) { + $nothing_value = '0', $size = false, $return = false, $select_style = false, $unique_name = true) { $fields = get_periods(); @@ -449,7 +450,12 @@ function html_print_extended_select_for_time ($name, $selected = '', $script = ' SECONDS_1MONTH => __('months'), SECONDS_1YEAR => __('years')); - $uniq_name = uniqid($name); + if($unique_name === true) { + $uniq_name = uniqid($name); + } + else { + $uniq_name = $name; + } ob_start(); @@ -467,16 +473,19 @@ function html_print_extended_select_for_time ($name, $selected = '', $script = ' html_print_select ($units, $uniq_name . '_units', 1, "" . $script, $nothing, $nothing_value, false, false, false, '', false, 'font-size: xx-small;'.$select_style); echo ''; - - echo " - - "; - + function period_select_".$name."_update(seconds) { + $('#text-".$uniq_name."_text').val(seconds); + adjustTextUnits('".$uniq_name."'); + calculateSeconds('".$uniq_name."'); + $('#".$uniq_name."_manual').show(); + $('#".$uniq_name."_default').hide(); + } + "; $returnString = ob_get_clean(); if ($return) diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 1466f01010..f4dfce68b2 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -770,6 +770,19 @@ function calculateSeconds(name) { $('.'+name).val(calculated); } +/** + * + * Update via Javascript an advance selec for time + * + */ +function period_select_update(name, seconds) { + $('#text-'+name+'_text').val(seconds); + adjustTextUnits(name); + calculateSeconds(name); + $('#'+name+'_manual').show(); + $('#'+name+'_default').hide(); +} + /** * * Adjust units in the advanced select for time diff --git a/pandora_console/include/javascript/pandora_modules.js b/pandora_console/include/javascript/pandora_modules.js index 78d4bb4594..acfa15c9e8 100644 --- a/pandora_console/include/javascript/pandora_modules.js +++ b/pandora_console/include/javascript/pandora_modules.js @@ -69,13 +69,35 @@ function configure_modules_form () { }, function (data, status) { configuration_data = js_html_entity_decode (data['data']); - $("#text-name").attr ("value", js_html_entity_decode (data["name"])); $("#textarea_description").attr ("value", js_html_entity_decode (data["description"])); $("#textarea_configuration_data").attr ("value", configuration_data); $("#component_loading").hide (); - $("#id_module_type option[value="+data["type"]+"]").select (1); + $("#text-max").attr ("value", data["max"]); + $("#text-min").attr ("value", data["min"]); + // Workaround to update the advanced select control from html and ajax + if(typeof 'period_select_module_interval_update' == 'function') { + period_select_module_interval_update(data["module_interval"]); + } + else { + period_select_update('module_interval', data["module_interval"]); + } $("#id_module_group option[value="+data["id_module_group"]+"]").select (1); + if (data["history_data"]) + $("#checkbox-history_data").check (); + else + $("#checkbox-history_data").uncheck (); + $("#text-min_warning").attr ("value", (data["min_warning"] == 0) ? 0 : data["min_warning"]); + $("#text-max_warning").attr ("value", (data["max_warning"] == 0) ? 0 : data["max_warning"]); + $("#text-str_warning").attr ("value", (data["str_warning"] == 0) ? 0 : data["str_warning"]); + $("#text-min_critical").attr ("value", (data["min_critical"] == 0) ? 0 : data["min_critical"]); + $("#text-max_critical").attr ("value", (data["max_critical"] == 0) ? 0 : data["max_critical"]); + $("#text-str_critical").attr ("value", (data["str_critical"] == 0) ? 0 : data["str_critical"]); + $("#text-ff_event").attr ("value", (data["min_ff_event"] == 0) ? 0 : data["min_ff_event"]); + $("#text-post_process").attr("value", (data["post_process"] == 0) ? 0 : data["post_process"]) + $("#text-unit").attr("value", (data["unit"] == '') ? '' : data["unit"]) + $("#component_loading").hide (); + $("#id_module_type").change (); }, "json" ); @@ -131,14 +153,20 @@ function configure_modules_form () { $("#id_module_type option[value="+data["type"]+"]").select (1); $("#text-max").attr ("value", data["max"]); $("#text-min").attr ("value", data["min"]); - $("#text-module_interval").attr ("value", data["module_interval"]); + // Workaround to update the advanced select control from html and ajax + if(typeof 'period_select_module_interval_update' == 'function') { + period_select_module_interval_update(data["module_interval"]); + } + else { + period_select_update('module_interval', data["module_interval"]); + } $("#text-tcp_port").attr ("value", data["tcp_port"]); $("#textarea_tcp_send").attr ("value", js_html_entity_decode (data["tcp_send"])); $("#textarea_tcp_rcv").attr ("value", js_html_entity_decode (data["tcp_rcv"])); $("#text-snmp_community").attr ("value", js_html_entity_decode (data["snmp_community"])); $("#text-snmp_oid").attr ("value", js_html_entity_decode (data["snmp_oid"])).show (); $("#oid, img#edit_oid").hide (); - $("#id_module_group option["+data["id_group"]+"]").select (1); + $("#id_module_group option[value="+data["id_module_group"]+"]").select (1); $("#max_timeout").attr ("value", data["max_timeout"]); $("#id_plugin option[value="+data["id_plugin"]+"]").select (1); $("#text-plugin_user").attr ("value", js_html_entity_decode (data["plugin_user"])); @@ -150,9 +178,11 @@ function configure_modules_form () { $("#checkbox-history_data").uncheck (); $("#text-min_warning").attr ("value", (data["min_warning"] == 0) ? 0 : data["min_warning"]); $("#text-max_warning").attr ("value", (data["max_warning"] == 0) ? 0 : data["max_warning"]); + $("#text-str_warning").attr ("value", (data["str_warning"] == 0) ? 0 : data["str_warning"]); $("#text-min_critical").attr ("value", (data["min_critical"] == 0) ? 0 : data["min_critical"]); $("#text-max_critical").attr ("value", (data["max_critical"] == 0) ? 0 : data["max_critical"]); - $("#text-ff_threshold").attr ("value", (data["min_ff_event"] == 0) ? 0 : data["min_ff_event"]); + $("#text-str_critical").attr ("value", (data["str_critical"] == 0) ? 0 : data["str_critical"]); + $("#text-ff_event").attr ("value", (data["min_ff_event"] == 0) ? 0 : data["min_ff_event"]); $("#text-post_process").attr("value", (data["post_process"] == 0) ? 0 : data["post_process"]) $("#text-unit").attr("value", (data["unit"] == '') ? '' : data["unit"]) $("#component_loading").hide (); @@ -344,23 +374,27 @@ function configure_modules_form () { return true; }); - $("#prediction_id_group").pandoraSelectGroupAgent ({ - agentSelect: "select#prediction_id_agent", - callbackBefore: function () { - $("#module_loading").show (); - $("#prediction_module option").remove (); - return true; - }, - callbackAfter: function (e) { - if ($("#prediction_id_agent").children ().length == 0) { - $("#module_loading").hide (); - return; + if(typeof $("#prediction_id_group").pandoraSelectGroupAgent == 'function') { + $("#prediction_id_group").pandoraSelectGroupAgent ({ + agentSelect: "select#prediction_id_agent", + callbackBefore: function () { + $("#module_loading").show (); + $("#prediction_module option").remove (); + return true; + }, + callbackAfter: function (e) { + if ($("#prediction_id_agent").children ().length == 0) { + $("#module_loading").hide (); + return; + } + $("#prediction_id_agent").change (); } - $("#prediction_id_agent").change (); - } - }); + }); + } - $("#prediction_id_agent").pandoraSelectAgentModule ({ - moduleSelect: "select#prediction_module" - }); + if(typeof $("#prediction_id_agent").pandoraSelectAgentModule == 'function') { + $("#prediction_id_agent").pandoraSelectAgentModule ({ + moduleSelect: "select#prediction_module" + }); + } }