dyn redraw

This commit is contained in:
fbsanchez 2019-06-13 13:07:11 +02:00
parent d12773cfd0
commit 9740275388
3 changed files with 29 additions and 17 deletions

View File

@ -196,9 +196,6 @@ function events_get_column_names($fields)
*/ */
function events_update_status($id_evento, $status, $filter=null, $history=false) function events_update_status($id_evento, $status, $filter=null, $history=false)
{ {
error_log($id_evento);
error_log($status);
if (!$status) { if (!$status) {
return false; return false;
} }
@ -263,7 +260,6 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
break; break;
} }
error_log($update_sql);
return db_process_sql($update_sql); return db_process_sql($update_sql);
} }

View File

@ -669,12 +669,14 @@ function show_event_response_command_dialog(id, response, total_checked) {
}); });
} }
function update_event(table, id_evento, type, redraw) { function update_event(table, id_evento, type, row) {
var inputs = $("#events_form :input"); var inputs = $("#events_form :input");
var values = {}; var values = {};
var redraw = false;
inputs.each(function() { inputs.each(function() {
values[this.name] = $(this).val(); values[this.name] = $(this).val();
}); });
var t1 = new Date();
// Update events matching current filters and id_evento selected. // Update events matching current filters and id_evento selected.
$.ajax({ $.ajax({
@ -688,22 +690,36 @@ function update_event(table, id_evento, type, redraw) {
filter: values filter: values
}, },
success: function() { success: function() {
var t2 = new Date();
var diff_g = t1.getTime() - t2.getTime();
var diff_s = diff_g / 1000;
// If operation takes less than 2 seconds, redraw.
if (diff_s < 2) {
redraw = true;
}
if (redraw) { if (redraw) {
table.draw().page(0); table.draw().page(0);
} else {
$(row)
.closest("tr")
.remove();
} }
} }
}); });
} }
function validate_event(table, id_evento) { function validate_event(table, id_evento, row) {
return update_event(table, id_evento, { validate_event: 1 }, false); row.firstChild.src = "http://localhost/pandora_console/images/spinner.gif";
return update_event(table, id_evento, { validate_event: 1 }, row, false);
} }
function in_process_event(table, id_evento) { function in_process_event(table, id_evento, row) {
return update_event(table, id_evento, { in_process_event: 1 }, false); row.firstChild.src = "http://localhost/pandora_console/images/spinner.gif";
return update_event(table, id_evento, { in_process_event: 1 }, row, false);
} }
function delete_event(table, id_evento) { function delete_event(table, id_evento, row) {
$(row) $(row)
.closest("tr") .closest("tr")
.remove(); .remove();

View File

@ -1428,26 +1428,26 @@ function process_datatables_item(item) {
item.options += ')" ><?php echo html_print_image('images/eye.png', true, ['title' => __('Show more')]); ?></a>'; item.options += ')" ><?php echo html_print_image('images/eye.png', true, ['title' => __('Show more')]); ?></a>';
// Validate. // Validate.
item.options += '<a href="javascript:" onclick="$(this).hide(); validate_event(dt_<?php echo $table_id; ?>,'; item.options += '<a href="javascript:" onclick="validate_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) { if (item.max_id_evento) {
item.options += item.max_id_evento+')" >'; item.options += item.max_id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate events')]); ?></a>'; item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate events')]); ?></a>';
} else { } else {
item.options += item.id_evento+')" >'; item.options += item.id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate event')]); ?></a>'; item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate event')]); ?></a>';
} }
// In process. // In process.
item.options += '<a href="javascript:" onclick="$(this).hide(); in_process_event(dt_<?php echo $table_id; ?>,'; item.options += '<a href="javascript:" onclick="in_process_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) { if (item.max_id_evento) {
item.options += item.max_id_evento+')" >'; item.options += item.max_id_evento+', this)" >';
} else { } else {
item.options += item.id_evento+')" >'; item.options += item.id_evento+', this)" >';
} }
item.options += '<?php echo html_print_image('images/hourglass.png', true, ['title' => __('Change to in progress status')]); ?></a>'; item.options += '<?php echo html_print_image('images/hourglass.png', true, ['title' => __('Change to in progress status')]); ?></a>';
// Delete. // Delete.
item.options += '<a href="javascript:" onclick="$(this).hide(); delete_event(dt_<?php echo $table_id; ?>,'; item.options += '<a href="javascript:" onclick="delete_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) { if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >'; item.options += item.max_id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete events')]); ?></a>'; item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete events')]); ?></a>';