Fixed the preview alert action in the form editor. TICKET: #1944
This commit is contained in:
parent
ce108bb54c
commit
b7264f61c3
|
@ -61,16 +61,19 @@ if (is_ajax ()) {
|
||||||
// Get the html rows of the fields form
|
// Get the html rows of the fields form
|
||||||
|
|
||||||
// Descriptions are stored in json
|
// Descriptions are stored in json
|
||||||
$fields_descriptions = empty($command['fields_descriptions']) ? '' : json_decode(io_safe_output($command['fields_descriptions']), true);
|
$fields_descriptions = empty($command['fields_descriptions']) ?
|
||||||
|
'' : json_decode(io_safe_output($command['fields_descriptions']), true);
|
||||||
|
|
||||||
// Fields values are stored in json
|
// Fields values are stored in json
|
||||||
$fields_values = empty($command['fields_values']) ? '' : io_safe_output(json_decode($command['fields_values'], true));
|
$fields_values = empty($command['fields_values']) ?
|
||||||
|
'' : io_safe_output(json_decode($command['fields_values'], true));
|
||||||
|
|
||||||
$fields_rows = array();
|
$fields_rows = array();
|
||||||
for ($i = 1; $i <= 10; $i++) {
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
if (!empty($fields_descriptions[$i - 1])) {
|
if (!empty($fields_descriptions[$i - 1])) {
|
||||||
$fdesc = $fields_descriptions[$i - 1] .
|
$fdesc = $fields_descriptions[$i - 1] .
|
||||||
' <br><span style="font-size:xx-small; font-weight:normal;">' . sprintf(__('Field %s'), $i) . '</span>';
|
' <br><span style="font-size:xx-small; font-weight:normal;">' .
|
||||||
|
sprintf(__('Field %s'), $i) . '</span>';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If the macro hasn't description and doesnt appear in command, set with empty description to dont show it
|
// If the macro hasn't description and doesnt appear in command, set with empty description to dont show it
|
||||||
|
@ -82,9 +85,9 @@ if (is_ajax ()) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($fields_values[$i-1])) {
|
if (!empty($fields_values[$i - 1])) {
|
||||||
$fields_value_select = array();
|
$fields_value_select = array();
|
||||||
$fv = $fields_values[$i-1];
|
$fv = $fields_values[$i - 1];
|
||||||
$fv = explode(';', $fv);
|
$fv = explode(';', $fv);
|
||||||
|
|
||||||
if (empty($fv)) {
|
if (empty($fv)) {
|
||||||
|
@ -96,12 +99,18 @@ if (is_ajax ()) {
|
||||||
$fields_value_select[$fv_option[0]] = $fv_option[1];
|
$fields_value_select[$fv_option[0]] = $fv_option[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
$ffield = html_print_select($fields_value_select, 'field'.$i.'_value', '', '', '', 0, true, false, false);
|
|
||||||
$rfield = html_print_select($fields_value_select, 'field'.$i.'_recovery_value', '', '', '', 0, true, false, false);
|
$ffield = html_print_select($fields_value_select,
|
||||||
|
'field' . $i . '_value', '', '', '', 0, true, false, false, 'fields');
|
||||||
|
$rfield = html_print_select($fields_value_select,
|
||||||
|
'field' . $i . '_recovery_value', '', '', '', 0, true, false, false, 'fields_recovery');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$ffield = html_print_textarea ('field'.$i.'_value', 1, 1, '', 'style="min-height:40px" class="fields"', true);
|
$ffield = html_print_textarea ('field' . $i . '_value',
|
||||||
$rfield = html_print_textarea ('field'.$i.'_recovery_value', 1, 1, '', 'style="min-height:40px" class="fields_recovery"', true);
|
1, 1, '', 'style="min-height:40px" class="fields"', true);
|
||||||
|
$rfield = html_print_textarea (
|
||||||
|
'field' . $i . '_recovery_value', 1, 1, '',
|
||||||
|
'style="min-height:40px" class="fields_recovery"', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,14 +51,18 @@ if ($al_action !== false) {
|
||||||
if (defined('METACONSOLE'))
|
if (defined('METACONSOLE'))
|
||||||
alerts_meta_print_header();
|
alerts_meta_print_header();
|
||||||
else
|
else
|
||||||
ui_print_page_header (__('Alerts').' » '.__('Configure alert action'), "images/gm_alerts.png", false, "alert_config", true);
|
ui_print_page_header (__('Alerts') . ' » ' .
|
||||||
|
__('Configure alert action'), "images/gm_alerts.png", false,
|
||||||
|
"alert_config", true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Header
|
// Header
|
||||||
if (defined('METACONSOLE'))
|
if (defined('METACONSOLE'))
|
||||||
alerts_meta_print_header();
|
alerts_meta_print_header();
|
||||||
else
|
else
|
||||||
ui_print_page_header (__('Alerts').' » '.__('Configure alert action'), "images/gm_alerts.png", false, "alert_config", true);
|
ui_print_page_header (__('Alerts') . ' » ' .
|
||||||
|
__('Configure alert action'), "images/gm_alerts.png", false,
|
||||||
|
"alert_config", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
enterprise_hook('open_meta_frame');
|
enterprise_hook('open_meta_frame');
|
||||||
|
@ -78,7 +82,10 @@ if ($id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hidden div with help hint to fill with javascript
|
// Hidden div with help hint to fill with javascript
|
||||||
html_print_div(array('id' => 'help_alert_macros_hint', 'content' => ui_print_help_icon ('alert_macros', true), 'hidden' => true));
|
html_print_div(
|
||||||
|
array('id' => 'help_alert_macros_hint',
|
||||||
|
'content' => ui_print_help_icon ('alert_macros', true),
|
||||||
|
'hidden' => true));
|
||||||
|
|
||||||
$table->id = 'table_macros';
|
$table->id = 'table_macros';
|
||||||
$table->width = '98%';
|
$table->width = '98%';
|
||||||
|
@ -136,19 +143,30 @@ $table->data[5][2] = html_print_textarea ('command_recovery_preview', 5, 30, '',
|
||||||
|
|
||||||
$row = 6;
|
$row = 6;
|
||||||
for ($i = 1; $i <= 10; $i++) {
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
$table->data['field' . $i][0] = html_print_image('images/spinner.gif', true);
|
$table->data['field' . $i][0] = html_print_image(
|
||||||
$table->data['field' . $i][1] = html_print_image('images/spinner.gif', true);
|
'images/spinner.gif', true);
|
||||||
$table->data['field' . $i][2] = html_print_image('images/spinner.gif', true);
|
$table->data['field' . $i][1] = html_print_image(
|
||||||
|
'images/spinner.gif', true);
|
||||||
|
$table->data['field' . $i][2] = html_print_image(
|
||||||
|
'images/spinner.gif', true);
|
||||||
|
|
||||||
// Store the value in a hidden to keep it on first execution
|
// Store the value in a hidden to keep it on first execution
|
||||||
$table->data['field' . $i][1] .= html_print_input_hidden('field' . $i . '_value',
|
$table->data['field' . $i][1] .= html_print_input_hidden(
|
||||||
|
'field' . $i . '_value',
|
||||||
!empty($action['field' . $i]) ?
|
!empty($action['field' . $i]) ?
|
||||||
$action['field' . $i] : '', true);
|
$action['field' . $i] : '',
|
||||||
$table->data['field' . $i][2] .= html_print_input_hidden('field' . $i . '_recovery_value',
|
true);
|
||||||
|
$table->data['field' . $i][2] .= html_print_input_hidden(
|
||||||
|
'field' . $i . '_recovery_value',
|
||||||
!empty($action['field' . $i . '_recovery']) ?
|
!empty($action['field' . $i . '_recovery']) ?
|
||||||
$action['field' . $i . '_recovery'] : '', true);
|
$action['field' . $i . '_recovery'] : '',
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<form method="post" action="index.php?sec=' . $sec . '&sec2=godmode/alerts/alert_actions&pure='.$pure.'">';
|
echo '<form method="post" action="' .
|
||||||
|
'index.php?sec=' . $sec . '&' .
|
||||||
|
'sec2=godmode/alerts/alert_actions&' .
|
||||||
|
'pure=' . $pure . '">';
|
||||||
$table_html = html_print_table ($table, true);
|
$table_html = html_print_table ($table, true);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -248,12 +266,15 @@ $(document).ready (function () {
|
||||||
// Only keep the value if is provided from hidden (first time)
|
// Only keep the value if is provided from hidden (first time)
|
||||||
if (($("[name=field" + i + "_value]").attr('id'))
|
if (($("[name=field" + i + "_value]").attr('id'))
|
||||||
== ("hidden-field" + i + "_value")) {
|
== ("hidden-field" + i + "_value")) {
|
||||||
|
|
||||||
old_value = $("[name=field" + i + "_value]").val();
|
old_value = $("[name=field" + i + "_value]").val();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($("[name=field" + i + "_recovery_value]").attr('id'))
|
if (($("[name=field" + i + "_recovery_value]").attr('id'))
|
||||||
== ("hidden-field" + i + "_recovery_value")) {
|
== ("hidden-field" + i + "_recovery_value")) {
|
||||||
old_recovery_value = $("[name=field" + i + "_recovery_value]").val();
|
|
||||||
|
old_recovery_value =
|
||||||
|
$("[name=field" + i + "_recovery_value]").val();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the row is empty, hide de row
|
// If the row is empty, hide de row
|
||||||
|
@ -263,7 +284,8 @@ $(document).ready (function () {
|
||||||
else {
|
else {
|
||||||
$('#table_macros-field' + i).replaceWith(field_row);
|
$('#table_macros-field' + i).replaceWith(field_row);
|
||||||
$("[name=field" + i + "_value]").val(old_value);
|
$("[name=field" + i + "_value]").val(old_value);
|
||||||
$("[name=field" + i + "_recovery_value]").val(old_recovery_value);
|
$("[name=field" + i + "_recovery_value]")
|
||||||
|
.val(old_recovery_value);
|
||||||
|
|
||||||
|
|
||||||
// Add help hint only in first field
|
// Add help hint only in first field
|
||||||
|
@ -273,7 +295,9 @@ $(document).ready (function () {
|
||||||
|
|
||||||
$(td_content)
|
$(td_content)
|
||||||
.html(
|
.html(
|
||||||
$(td_content).html() + $('#help_alert_macros_hint').html());
|
$(td_content).html() +
|
||||||
|
$('#help_alert_macros_hint').html()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#table_macros-field' + i).show();
|
$('#table_macros-field' + i).show();
|
||||||
|
@ -283,10 +307,16 @@ $(document).ready (function () {
|
||||||
render_command_preview(original_command);
|
render_command_preview(original_command);
|
||||||
render_command_recovery_preview(original_command);
|
render_command_recovery_preview(original_command);
|
||||||
|
|
||||||
$(".fields").keyup (function() {
|
$(".fields").keyup(function() {
|
||||||
render_command_preview(original_command);
|
render_command_preview(original_command);
|
||||||
});
|
});
|
||||||
$(".fields_recovery").keyup (function() {
|
$(".fields_recovery").keyup(function() {
|
||||||
|
render_command_recovery_preview(original_command);
|
||||||
|
});
|
||||||
|
$("select.fields").change(function() {
|
||||||
|
render_command_preview(original_command);
|
||||||
|
});
|
||||||
|
$("select.fields_recovery").change(function() {
|
||||||
render_command_recovery_preview(original_command);
|
render_command_recovery_preview(original_command);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,33 +8,44 @@ function parse_alert_command (command, classs) {
|
||||||
classs = 'fields';
|
classs = 'fields';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var nfield = 1;
|
var nfield = 1;
|
||||||
$('.' + classs).each(function() {
|
$('.' + classs).each(function() {
|
||||||
|
|
||||||
// Only render values different from ''
|
// Only render values different from ''
|
||||||
if ($(this).val() == '') {
|
if ($(this).val() == '') {
|
||||||
|
|
||||||
nfield++;
|
nfield++;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var field = '_field' + nfield + '_';
|
var field = '_field' + nfield + '_';
|
||||||
nfield++;
|
|
||||||
var regex = new RegExp(field,"gi");
|
var regex = new RegExp(field, "gi");
|
||||||
|
|
||||||
|
|
||||||
command = command.replace (regex, $(this).val());
|
command = command.replace (regex, $(this).val());
|
||||||
|
|
||||||
|
nfield++;
|
||||||
});
|
});
|
||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_command_preview (original_command) {
|
function render_command_preview (original_command) {
|
||||||
$("#textarea_command_preview").text (parse_alert_command (original_command, ''));
|
$("#textarea_command_preview")
|
||||||
|
.text(parse_alert_command (original_command, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_command_recovery_preview (original_command) {
|
function render_command_recovery_preview (original_command) {
|
||||||
$("#textarea_command_recovery_preview").text (parse_alert_command (original_command, 'recovery'));
|
$("#textarea_command_recovery_preview")
|
||||||
|
.text(parse_alert_command (original_command, 'recovery'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_command_description (command_description) {
|
function render_command_description (command_description) {
|
||||||
if (command_description != '') {
|
if (command_description != '') {
|
||||||
command_description = '<br>'+command_description;
|
command_description = '<br>' + command_description;
|
||||||
}
|
}
|
||||||
$("#command_description").html(command_description);
|
$("#command_description").html(command_description);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue