mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-12-26 23:26:47 +01:00
Implement user-definable alert timeout option
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user