Merge branch 'ent-12327-bug-de-estilos-al-anadir-acciones-de-alertas-snmp' into 'develop'

Add action ITSM in SNMP alert pandora_enterprise#12327

See merge request artica/pandorafms!6630
This commit is contained in:
Rafael Ameijeiras 2023-11-07 12:24:23 +00:00
commit 925e89e59b
3 changed files with 353 additions and 193 deletions

View File

@ -484,6 +484,7 @@ echo '</form>';
ui_require_javascript_file('pandora_alerts');
ui_require_javascript_file('tinymce', 'vendor/tinymce/tinymce/');
ui_require_javascript_file('alert');
?>
<script type="text/javascript">
@ -500,194 +501,6 @@ $(document).ready (function () {
render_command_description(command_description);
}
function ajax_get_integria_custom_fields(ticket_type_id, values, recovery_values) {
var values = values || [];
var recovery_values = recovery_values || [];
var max_macro_fields = <?php echo $config['max_macro_fields']; ?>;
if (ticket_type_id === null || ticket_type_id === '' || (Array.isArray(values) && values.length === 0 && Array.isArray(recovery_values) && recovery_values.length === 0)) {
for (var i=8; i <= max_macro_fields; i++) {
$('[name=field'+i+'_value\\[\\]').val('');
$('[name=field'+i+'_recovery_value\\[\\]').val('');
}
}
// On ticket type change, hide all table rows and inputs corresponding to custom fields, regardless of what its type is.
for (var i=8; i <= max_macro_fields; i++) {
$('[name=field'+i+'_value\\[\\]').hide();
$('[name=field'+i+'_recovery_value\\[\\]').hide();
$('#table_macros-field'+i).hide();
$('[name=field'+i+'_value_container').hide();
$('[name=field'+i+'_recovery_value_container').hide();
}
jQuery.post(
"ajax.php",
{
page: "godmode/alerts/configure_alert_action",
get_integria_ticket_custom_types: 1,
ticket_type_id: ticket_type_id
},
function(data) {
var max_macro_fields = <?php echo $config['max_macro_fields']; ?>;
data.forEach(function(custom_field, key) {
var custom_field_key = key+8; // Custom fields start from field 8.
if (custom_field_key > max_macro_fields) {
return;
}
// Display field row for current input.
var custom_field_row = $('#table_macros-field'+custom_field_key);
custom_field_row.show();
// Replace label text of field row for current input.
var label_html = $('#table_macros-field'+custom_field_key+' td').first().html();
var label_name = label_html.split('<br>')[0];
var new_html_content = custom_field_row.html().replace(label_name, custom_field.label);
custom_field_row.html(new_html_content);
switch (custom_field.type) {
case 'CHECKBOX':
var checkbox_selector = $('input[type="checkbox"][name=field'+custom_field_key+'_value\\[\\]]');
var checkbox_recovery_selector = $('input[type="checkbox"][name=field'+custom_field_key+'_recovery_value\\[\\]]');
checkbox_selector.on('change', function() {
if (checkbox_selector.prop('checked')) {
checkbox_selector.attr('value', "1");
} else {
checkbox_selector.attr('value', "0");
}
});
checkbox_recovery_selector.on('change', function() {
if (checkbox_recovery_selector.prop('checked')) {
checkbox_recovery_selector.attr('value', "1");
} else {
checkbox_recovery_selector.attr('value', "0");
}
});
if (typeof values[key] !== "undefined") {
if (values[key] == 1) {
checkbox_selector.prop('checked', true);
checkbox_selector.attr('value', "1");
} else {
checkbox_selector.prop('checked', false);
checkbox_selector.attr('value', "0");
}
}
if (typeof recovery_values[key] !== "undefined") {
if (recovery_values[key] == 1) {
checkbox_recovery_selector.prop('checked', true);
checkbox_recovery_selector.attr('value', "1");
} else {
checkbox_recovery_selector.prop('checked', false);
checkbox_recovery_selector.attr('value', "0");
}
}
$('[name=field'+custom_field_key+'_value_container]').show();
$('[name=field'+custom_field_key+'_recovery_value_container]').show();
$('input[type="checkbox"][name=field'+custom_field_key+'_value\\[\\]]').show();
$('input[type="checkbox"][name=field'+custom_field_key+'_recovery_value\\[\\]]').show();
break;
case 'COMBO':
var combo_input = $('select[name=field'+custom_field_key+'_value\\[\\]]');
var combo_input_recovery = $('select[name=field'+custom_field_key+'_recovery_value\\[\\]]');
combo_input.find('option').remove();
combo_input_recovery.find('option').remove();
var combo_values_array = custom_field.comboValue.split(',');
combo_values_array.forEach(function(value) {
combo_input.append($('<option>', {
value: value,
text: value
}));
combo_input_recovery.append($('<option>', {
value: value,
text: value
}));
});
if (typeof values[key] !== "undefined") {
combo_input.val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
combo_input_recovery.val(recovery_values[key]);
}
combo_input.show();
combo_input_recovery.show();
break;
case 'DATE':
$('input.datepicker[type="text"][name=field'+custom_field_key+'_value\\[\\]]').removeClass("hasDatepicker");
$('input.datepicker[type="text"][name=field'+custom_field_key+'_recovery_value\\[\\]]').removeClass("hasDatepicker");
$('input.datepicker[type="text"][name=field'+custom_field_key+'_value\\[\\]]').datepicker("destroy");
$('input.datepicker[type="text"][name=field'+custom_field_key+'_recovery_value\\[\\]]').datepicker("destroy");
$('input.datepicker[type="text"][name=field'+custom_field_key+'_value\\[\\]]').show();
$('input.datepicker[type="text"][name=field'+custom_field_key+'_recovery_value\\[\\]]').show();
$('input.datepicker[type="text"][name=field'+custom_field_key+'_value\\[\\]]').datepicker({dateFormat: "<?php echo 'yy-mm-dd 00:00:00'; ?>"});
$('input.datepicker[type="text"][name=field'+custom_field_key+'_recovery_value\\[\\]]').datepicker({dateFormat: "<?php echo 'yy-mm-dd 00:00:00'; ?>"});
$.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]);
if (typeof values[key] !== "undefined") {
$('input.datepicker[type="text"][name=field'+custom_field_key+'_value\\[\\]]').val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
$('input.datepicker[type="text"][name=field'+custom_field_key+'_recovery_value\\[\\]]').val(recovery_values[key]);
}
break;
case 'NUMERIC':
if (typeof values[key] !== "undefined") {
$('input[type="number"][name=field'+custom_field_key+'_value\\[\\]]').val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
$('input[type="number"][name=field'+custom_field_key+'_recovery_value\\[\\]]').val(recovery_values[key]);
}
$('input[type="number"][name=field'+custom_field_key+'_value\\[\\]]').show();
$('input[type="number"][name=field'+custom_field_key+'_recovery_value\\[\\]]').show();
break;
case 'TEXT':
if (typeof values[key] !== "undefined") {
$('input.normal[type="text"][name=field'+custom_field_key+'_value\\[\\]]').val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
$('input.normal[type="text"][name=field'+custom_field_key+'_recovery_value\\[\\]]').val(recovery_values[key]);
}
$('input.normal[type="text"][name=field'+custom_field_key+'_value\\[\\]]').show();
$('input.normal[type="text"][name=field'+custom_field_key+'_recovery_value\\[\\]]').show();
break;
case 'TEXTAREA':
default:
if (typeof values[key] !== "undefined") {
$('textarea[name=field'+custom_field_key+'_value\\[\\]]').val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
$('textarea[name=field'+custom_field_key+'_recovery_value\\[\\]]').val(recovery_values[key]);
}
$('textarea[name=field'+custom_field_key+'_value\\[\\]]').show();
$('textarea[name=field'+custom_field_key+'_recovery_value\\[\\]]').show();
break;
}
});
},
"json"
);
}
$("#id_command").change (function () {
values = Array ();
// No se envia el valor del commando.
@ -914,12 +727,22 @@ $(document).ready (function () {
}
if ($('#field5_value').val() !== '') {
ajax_get_integria_custom_fields($('#field5_value').val(), integria_custom_fields_values, integria_custom_fields_rvalues);
ajax_get_integria_custom_fields(
$('#field5_value').val(),
integria_custom_fields_values,
integria_custom_fields_rvalues,
max_macro_fields
);
$('#field5_value').trigger('change');
}
$('#field5_value').on('change', function() {
ajax_get_integria_custom_fields($(this).val());
ajax_get_integria_custom_fields(
$(this).val(),
[],
[],
max_macro_fields
);
});
}

View File

@ -2063,7 +2063,7 @@ if ($create_alert || $update_alert) {
}
// DIALOG ADD MORE ACTIONS.
echo '<div id="add_action_snmp-div" class="invisible left">';
echo '<div id="add_action_snmp-div" class="invisible">';
echo '<form id="add_action_form" method="post">';
echo '<table class="w100p">';
@ -2212,6 +2212,7 @@ if ($create_alert || $update_alert) {
ui_require_javascript_file('pandora', 'include/javascript/', true);
ui_require_javascript_file('tinymce', 'vendor/tinymce/tinymce/');
ui_require_javascript_file('alert');
?>
<script language="javascript" type="text/javascript">
@ -2287,6 +2288,7 @@ $(document).ready (function () {
name: "content_type",
value: "<?php echo $al_field4; ?>"
})
jQuery.post (<?php echo "'".ui_get_full_url('ajax.php', false, false, false)."'"; ?>,
values,
function (data, status) {
@ -2317,6 +2319,26 @@ $(document).ready (function () {
}
$('#table_macros-field').show();
}
if($("#alert_type option:selected").text() === "Create Pandora ITSM ticket") {
// At start hide all rows and inputs corresponding to custom fields, regardless of what its type is.
if (i>=8) {
$('[name=field'+i+'_value\\[\\]').hide();
$('[name=field'+i+'_recovery_value\\[\\]').hide();
$('#table_macros-field'+i).hide();
$('[name=field'+i+'_value_container').hide();
$('[name=field'+i+'_recovery_value_container').hide();
}
if ($('#field5_value').val() !== '') {
ajax_get_integria_custom_fields($('#field5_value').val(), [], [], max_fields);
$('#field5_value').trigger('change');
}
$('#field5_value').on('change', function() {
ajax_get_integria_custom_fields($(this).val(), [], [], max_fields);
});
}
}
},
"json"
@ -2341,7 +2363,8 @@ $(document).ready (function () {
});
function show_add_action_snmp(id_alert_snmp) {
$("#add_action_snmp-div").hide()
$("#add_action_snmp-div")
.hide()
.dialog ({
resizable: true,
draggable: true,

View File

@ -1,5 +1,5 @@
/* eslint-disable no-unused-vars */
/* global $, load_modal, generalShowMsg, confirmDialog */
/* global $, load_modal, generalShowMsg, confirmDialog, jQuery */
function allowDrop(ev) {
ev.preventDefault();
@ -172,3 +172,317 @@ function disabled_alert(settings) {
}
});
}
function ajax_get_integria_custom_fields(
ticket_type_id,
values,
recovery_values,
max_macro_fields
) {
values = values || [];
recovery_values = recovery_values || [];
if (
ticket_type_id === null ||
ticket_type_id === "" ||
(Array.isArray(values) &&
values.length === 0 &&
Array.isArray(recovery_values) &&
recovery_values.length === 0)
) {
for (let i = 8; i <= max_macro_fields; i++) {
$("[name=field" + i + "_value\\[\\]").val("");
$("[name=field" + i + "_recovery_value\\[\\]").val("");
}
}
// On ticket type change, hide all table rows and inputs corresponding to custom fields, regardless of what its type is.
for (let i = 8; i <= max_macro_fields; i++) {
$("[name=field" + i + "_value\\[\\]").hide();
$("[name=field" + i + "_recovery_value\\[\\]").hide();
$("#table_macros-field" + i).hide();
$("[name=field" + i + "_value_container").hide();
$("[name=field" + i + "_recovery_value_container").hide();
}
jQuery.post(
"ajax.php",
{
page: "godmode/alerts/configure_alert_action",
get_integria_ticket_custom_types: 1,
ticket_type_id: ticket_type_id
},
function(data) {
data.forEach(function(custom_field, key) {
var custom_field_key = key + 8; // Custom fields start from field 8.
if (custom_field_key > max_macro_fields) {
return;
}
// Display field row for current input.
var custom_field_row = $("#table_macros-field" + custom_field_key);
custom_field_row.show();
// Replace label text of field row for current input.
var label_html = $("#table_macros-field" + custom_field_key + " td")
.first()
.html();
var label_name = label_html.split("<br>")[0];
var new_html_content = custom_field_row
.html()
.replace(label_name, custom_field.label);
custom_field_row.html(new_html_content);
switch (custom_field.type) {
case "CHECKBOX":
var checkbox_selector = $(
'input[type="checkbox"][name=field' +
custom_field_key +
"_value\\[\\]]"
);
var checkbox_recovery_selector = $(
'input[type="checkbox"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
);
checkbox_selector.on("change", function() {
if (checkbox_selector.prop("checked")) {
checkbox_selector.attr("value", "1");
} else {
checkbox_selector.attr("value", "0");
}
});
checkbox_recovery_selector.on("change", function() {
if (checkbox_recovery_selector.prop("checked")) {
checkbox_recovery_selector.attr("value", "1");
} else {
checkbox_recovery_selector.attr("value", "0");
}
});
if (typeof values[key] !== "undefined") {
if (values[key] == 1) {
checkbox_selector.prop("checked", true);
checkbox_selector.attr("value", "1");
} else {
checkbox_selector.prop("checked", false);
checkbox_selector.attr("value", "0");
}
}
if (typeof recovery_values[key] !== "undefined") {
if (recovery_values[key] == 1) {
checkbox_recovery_selector.prop("checked", true);
checkbox_recovery_selector.attr("value", "1");
} else {
checkbox_recovery_selector.prop("checked", false);
checkbox_recovery_selector.attr("value", "0");
}
}
$("[name=field" + custom_field_key + "_value_container]").show();
$(
"[name=field" + custom_field_key + "_recovery_value_container]"
).show();
$(
'input[type="checkbox"][name=field' +
custom_field_key +
"_value\\[\\]]"
).show();
$(
'input[type="checkbox"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).show();
break;
case "COMBO":
var combo_input = $(
"select[name=field" + custom_field_key + "_value\\[\\]]"
);
var combo_input_recovery = $(
"select[name=field" + custom_field_key + "_recovery_value\\[\\]]"
);
combo_input.find("option").remove();
combo_input_recovery.find("option").remove();
var combo_values_array = custom_field.comboValue.split(",");
combo_values_array.forEach(function(value) {
combo_input.append(
$("<option>", {
value: value,
text: value
})
);
combo_input_recovery.append(
$("<option>", {
value: value,
text: value
})
);
});
if (typeof values[key] !== "undefined") {
combo_input.val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
combo_input_recovery.val(recovery_values[key]);
}
combo_input.show();
combo_input_recovery.show();
break;
case "DATE":
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_value\\[\\]]"
).removeClass("hasDatepicker");
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).removeClass("hasDatepicker");
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_value\\[\\]]"
).datepicker("destroy");
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).datepicker("destroy");
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_value\\[\\]]"
).show();
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).show();
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_value\\[\\]]"
).datepicker({ dateFormat: "<?php echo 'yy-mm-dd 00:00:00'; ?>" });
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).datepicker({ dateFormat: "<?php echo 'yy-mm-dd 00:00:00'; ?>" });
$.datepicker.setDefaults(
$.datepicker.regional["<?php echo get_user_language(); ?>"]
);
if (typeof values[key] !== "undefined") {
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_value\\[\\]]"
).val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
$(
'input.datepicker[type="text"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).val(recovery_values[key]);
}
break;
case "NUMERIC":
if (typeof values[key] !== "undefined") {
$(
'input[type="number"][name=field' +
custom_field_key +
"_value\\[\\]]"
).val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
$(
'input[type="number"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).val(recovery_values[key]);
}
$(
'input[type="number"][name=field' +
custom_field_key +
"_value\\[\\]]"
).show();
$(
'input[type="number"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).show();
break;
case "TEXT":
if (typeof values[key] !== "undefined") {
$(
'input.normal[type="text"][name=field' +
custom_field_key +
"_value\\[\\]]"
).val(values[key]);
}
if (typeof recovery_values[key] !== "undefined") {
$(
'input.normal[type="text"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).val(recovery_values[key]);
}
$(
'input.normal[type="text"][name=field' +
custom_field_key +
"_value\\[\\]]"
).show();
$(
'input.normal[type="text"][name=field' +
custom_field_key +
"_recovery_value\\[\\]]"
).show();
break;
case "TEXTAREA":
default:
if (typeof values[key] !== "undefined") {
$("textarea[name=field" + custom_field_key + "_value\\[\\]]").val(
values[key]
);
}
if (typeof recovery_values[key] !== "undefined") {
$(
"textarea[name=field" +
custom_field_key +
"_recovery_value\\[\\]]"
).val(recovery_values[key]);
}
$(
"textarea[name=field" + custom_field_key + "_value\\[\\]]"
).show();
$(
"textarea[name=field" +
custom_field_key +
"_recovery_value\\[\\]]"
).show();
break;
}
});
},
"json"
);
}