Fix issue with info box messages

This commit is contained in:
Jose Gonzalez 2023-01-26 16:00:08 +01:00
parent 251fc46d17
commit deb69a0659
3 changed files with 41 additions and 21 deletions

View File

@ -378,33 +378,25 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t
// JavaScript help vars.
$messageCreated = html_print_table($messageTable, true);
$autocloseTime = ((int) $config['notification_autoclose_time'] * 1000);
$definedMessageTop = '20';
ob_start();
?>
<script type="text/javascript">
$(document).ready(function(){
var $definedTop = <?php echo $definedMessageTop; ?>;
var $listOfMessages = document.querySelectorAll('.info_box_container');
$("#<?php echo $id; ?>").css('top', (parseInt($definedTop) + (100*($listOfMessages.length)))+'px');
<?php if (($autoclose === true) && ($autocloseTime > 0)) : ?>
setTimeout(() => { close_info_box('<?php echo $id; ?>'); }, <?php echo $autocloseTime; ?>);
<?php endif; ?>
});
$classes = 'info_box_container';
$classes .= (($autoclose === true) && ($autocloseTime > 0)) ? ' info_box_autoclose' : '';
<?php if (($first_execution === true) && ($no_close_bool === false)) : ?>
function close_info_box(id) { $("#" + id).fadeOut('slow', function(){ $("#" + id).remove(); }); }
<?php endif; ?>
</script>
<?php
$jsCode = ob_get_clean();
// This session var is defined in index.
if (isset($_SESSION['info_box_count']) === false) {
$_SESSION['info_box_count'] = 1;
} else {
$_SESSION['info_box_count']++;
}
$position = (20 + ((int) $_SESSION['info_box_count'] * 100));
$output = html_print_div(
[
'id' => $id,
'style' => 'top: 120px;',
'class' => 'info_box_container',
'content' => $jsCode.$messageCreated,
'style' => 'top: '.$position.'px;',
'class' => $classes,
'content' => $messageCreated,
],
true
);

View File

@ -2296,3 +2296,15 @@ $(document).ready(function() {
});
}
});
function close_info_box(id) {
$("#" + id).fadeOut("slow", function() {
$("#" + id).remove();
});
}
function autoclose_info_box(id, autoCloseTime) {
setTimeout(() => {
close_info_box(id);
}, autoCloseTime);
}

View File

@ -42,6 +42,11 @@ if (__PAN_XHPROF__ === 1) {
}
}
// Needed for InfoBox count.
if (isset($_SESSION['info_box_count']) === true) {
$_SESSION['info_box_count'] = 0;
}
// Set character encoding to UTF-8
// fixes a lot of multibyte character issues.
if (function_exists('mb_internal_encoding') === true) {
@ -1674,6 +1679,17 @@ require 'include/php_to_js_values.php';
"html"
);
}
// Info messages action.
$(document).ready(function() {
var $autocloseTime = <?php echo ((int) $config['notification_autoclose_time'] * 1000); ?>;
var $listOfMessages = document.querySelectorAll('.info_box_autoclose');
$listOfMessages.forEach(
function(item) {
autoclose_info_box(item.id, $autocloseTime)
}
);
});
</script>
<?php
if (__PAN_XHPROF__ === 1) {