Implement user-definable alert timeout option

This commit is contained in:
billz
2025-07-25 19:34:31 -07:00
parent a005ba30b9
commit 2967f5b692
3 changed files with 46 additions and 4 deletions

View File

@@ -582,8 +582,13 @@ $(document)
.ready(loadWifiStations());
// To auto-close Bootstrap alerts; time is in milliseconds
window.setTimeout(function() {
const alertTimeout = parseInt(getCookie('alert_timeout'), 10);
if (!isNaN(alertTimeout) && alertTimeout > 0) {
window.setTimeout(function() {
$(".alert").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
$(this).remove();
});
}, 5000);
}, alertTimeout);
}

View File

@@ -12,6 +12,10 @@ function DisplaySystem(&$extraFooterScripts)
$dashboard = new \RaspAP\UI\Dashboard;
$pluginInstaller = \RaspAP\Plugins\PluginInstaller::getInstance();
// set defaults
$optAutoclose = true;
$alertTimeout = 5000;
if (isset($_POST['SaveLanguage'])) {
if (isset($_POST['locale'])) {
$_SESSION['locale'] = $_POST['locale'];
@@ -51,6 +55,21 @@ function DisplaySystem(&$extraFooterScripts)
$status->addMessage(sprintf(_('Changing log limit size to %s KB'), $_SESSION['log_limit']), 'info');
}
}
// Validate alert timout
if (isset($_POST['autoClose'])) {
$alertTimeout = trim($_POST['alertTimeout'] ?? '');
if (strlen($alertTimeout) > 7 || !is_numeric($alertTimeout)) {
$status->addMessage('Invalid value for alert close timeout', 'danger');
$good_input = false;
} else {
setcookie('alert_timeout', (int) $alertTimeout);
$status->addMessage(sprintf(_('Changing alert close timeout to %s ms'), $alertTimeout), 'info');
}
} else {
setcookie('alert_timeout', '', time() - 3600, '/');
$optAutoclose = false;
}
// Save settings
if ($good_input) {
exec("sudo /etc/raspap/lighttpd/configport.sh $serverPort $serverBind " .RASPI_LIGHTTPD_CONFIG. " ".$_SERVER['SERVER_NAME'], $return);
@@ -155,7 +174,9 @@ function DisplaySystem(&$extraFooterScripts)
"themes",
"selectedTheme",
"logLimit",
"pluginsTable"
"pluginsTable",
"optAutoclose",
"alertTimeout"
));
}

View File

@@ -22,6 +22,22 @@
<input type="text" class="form-control" name="logLimit" value="<?php echo htmlspecialchars($logLimit, ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="col-md-6 mb-2">
<div class="form-check form-switch">
<?php $checked = $optAutoclose == 1 ? 'checked="checked"' : '' ?>
<input class="form-check-input" id="chxautoclose" name="autoClose" type="checkbox" value="1" <?php echo $checked ?> />
<label class="form-check-label" for="chxautoclose"><?php echo _("Automatically close alerts after a specified timeout"); ?></label>
</div>
</div>
</div>
<div class="row">
<div class="mb-3 col-md-6">
<label for="code"><?php echo _("Alert close timeout (milliseconds)") ;?></label>
<input type="text" class="form-control" name="alertTimeout" value="<?php echo htmlspecialchars($alertTimeout, ENT_QUOTES); ?>" />
</div>
</div>
<input type="submit" class="btn btn-outline btn-primary" name="SaveServerSettings" value="<?php echo _("Save settings"); ?>" />
<input type="submit" class="btn btn-warning" name="RestartLighttpd" value="<?php echo _("Restart lighttpd"); ?>" />
</form>