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,8 +670,35 @@ if ($config['menu_type'] == 'classic') {
<?php <?php
if ($_GET['refr'] || $do_refresh === true) { 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'); $("#header_autorefresh").css('padding-right', '5px');
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 refr_time = <?php echo (int) get_parameter('refr', $config['refr']); ?>;
var t = new Date(); var t = new Date();
t.setTime (t.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>)); t.setTime (t.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
@ -685,6 +712,7 @@ if ($config['menu_type'] == 'classic') {
$(document).attr ("location", href); $(document).attr ("location", href);
} }
}); });
}
<?php <?php
} }
?> ?>
@ -694,7 +722,22 @@ if ($config['menu_type'] == 'classic') {
$("#combo_refr").toggle (); $("#combo_refr").toggle ();
$("select#ref").change (function () { $("select#ref").change (function () {
href = $("a.autorefresh").attr ("href"); href = $("a.autorefresh").attr ("href");
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); $(document).attr ("location", href + this.value);
}
}); });
return false; return false;

View File

@ -1469,6 +1469,11 @@ echo "<div id='event_response_command_window' title='".__('Parameters')."'></div
// Load filter div for dialog. // Load filter div for dialog.
echo '<div id="load-modal-filter" style="display: none"></div>'; echo '<div id="load-modal-filter" style="display: none"></div>';
echo '<div id="save-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"> <script type="text/javascript">
var loading = 0; 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) { function process_datatables_item(item) {