Added feature to autorefresh in events view with datatables - #4330

This commit is contained in:
Tatiana Llorente 2019-07-15 17:41:20 +02:00
parent 8c55c1b287
commit 7d119bfe5a
2 changed files with 73 additions and 10 deletions

View File

@ -670,21 +670,49 @@ if ($config['menu_type'] == 'classic') {
<?php
if ($_GET['refr'] || $do_refresh === true) {
if ($_GET['sec2'] == 'operation/events/events') {
$autorefresh_draw = true;
}
?>
var autorefresh_draw = '<?php echo $autorefresh_draw; ?>';
$("#header_autorefresh").css('padding-right', '5px');
var refr_time = <?php echo (int) get_parameter('refr', $config['refr']); ?>;
var t = new Date();
t.setTime (t.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
$("#refrcounter").countdown ({
until: t,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
if(autorefresh_draw == true) {
var refresh_interval = parseInt('<?php echo ($config['refr'] * 1000); ?>');
var until_time='';
function events_refresh() {
until_time = new Date();
until_time.setTime (until_time.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
$("#refrcounter").countdown ({
until: until_time,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
dt_events.draw(true);
}
});
}
// Start the countdown when page is loaded (first time).
events_refresh();
// Repeat countdown according to refresh_interval.
setInterval(events_refresh, refresh_interval);
} else {
var refr_time = <?php echo (int) get_parameter('refr', $config['refr']); ?>;
var t = new Date();
t.setTime (t.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
$("#refrcounter").countdown ({
until: t,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
href = $("a.autorefresh").attr ("href");
href = href + refr_time;
$(document).attr ("location", href);
}
});
}
<?php
}
?>
@ -694,8 +722,23 @@ if ($config['menu_type'] == 'classic') {
$("#combo_refr").toggle ();
$("select#ref").change (function () {
href = $("a.autorefresh").attr ("href");
$(document).attr ("location", href + this.value);
});
if(autorefresh_draw == true){
inputs = $("#events_form :input");
values = {};
inputs.each(function() {
values[this.name] = $(this).val();
})
var newValue = btoa(JSON.stringify(values));
console.log(newValue);
$(document).attr("location", href+'&fb64=' + newValue + '&refr=' + this.value);
} else {
console.log('recargo');
$(document).attr ("location", href + this.value);
}
});
return false;
});

View File

@ -1469,6 +1469,11 @@ echo "<div id='event_response_command_window' title='".__('Parameters')."'></div
// Load filter div for dialog.
echo '<div id="load-modal-filter" style="display: none"></div>';
echo '<div id="save-modal-filter" style="display: none"></div>';
if ($_GET['refr'] || $do_refresh === true) {
$autorefresh_draw = true;
}
?>
<script type="text/javascript">
var loading = 0;
@ -1548,6 +1553,21 @@ function process_datatables_callback(table, settings) {
})
}
var autorefresh_draw = '<?php echo $autorefresh_draw; ?>';
if (autorefresh_draw == true){
$("#refrcounter").countdown('change', {
until: countdown_repeat()
});
function countdown_repeat() {
var until_time = new Date();
until_time.setTime (until_time.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
return until_time;
}
}
}
function process_datatables_item(item) {