Fix: Don't reload page if modal is open

This commit is contained in:
Zack Spear
2025-05-05 12:53:01 -07:00
parent 6edb1c6ea1
commit 3b982b8399
2 changed files with 198 additions and 126 deletions

View File

@@ -1,4 +1,4 @@
<?PHP
<?php
/* Copyright 2005-2024, Lime Technology
* Copyright 2012-2024, Bergware International.
*
@@ -10,7 +10,7 @@
* all copies or substantial portions of the Software.
*/
?>
<?
<?php
require_once "$docroot/plugins/dynamix/include/ThemeHelper.php";
$themeHelper = new ThemeHelper($display['theme'], $display['width']);
$theme = $themeHelper->getThemeName(); // keep $theme, $themes1, $themes2 vars for plugin backwards compatibility for the time being
@@ -18,7 +18,7 @@ $themes1 = $themeHelper->isTopNavTheme();
$themes2 = $themeHelper->isSidebarTheme();
$themeHelper->updateDockerLogColor($docroot);
$display['font'] = filter_var($_COOKIE['fontSize'] ?? $display['font'] ?? '',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
$display['font'] = filter_var($_COOKIE['fontSize'] ?? $display['font'] ?? '', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
$header = $display['header']; // keep $header, $backgnd vars for plugin backwards compatibility for the time being
$backgnd = $display['background'];
@@ -29,28 +29,38 @@ $alerts = '/tmp/plugins/my_alerts.txt';
$wlan0 = file_exists('/sys/class/net/wlan0');
$nchan = ['webGui/nchan/notify_poller','webGui/nchan/session_check'];
if ($wlan0) $nchan[] = 'webGui/nchan/wlan0';
$safemode = _var($var,'safeMode')=='yes';
if ($wlan0) {
$nchan[] = 'webGui/nchan/wlan0';
}
$safemode = _var($var, 'safeMode') == 'yes';
$banner = "$config/plugins/dynamix/banner.png";
$notes = '/var/tmp/unRAIDServer.txt';
if (!file_exists($notes)) file_put_contents($notes,shell_exec("$docroot/plugins/dynamix.plugin.manager/scripts/plugin changes $docroot/plugins/unRAIDServer/unRAIDServer.plg"));
if (!file_exists($notes)) {
file_put_contents($notes, shell_exec("$docroot/plugins/dynamix.plugin.manager/scripts/plugin changes $docroot/plugins/unRAIDServer/unRAIDServer.plg"));
}
$taskPages = find_pages('Tasks');
$buttonPages = find_pages('Buttons');
function annotate($text) {echo "\n<!--\n",str_repeat("#",strlen($text)),"\n$text\n",str_repeat("#",strlen($text)),"\n-->\n";}
function annotate($text)
{
echo "\n<!--\n",str_repeat("#", strlen($text)),"\n$text\n",str_repeat("#", strlen($text)),"\n-->\n";
}
function generateReloadScript($loadMinutes) {
if ($loadMinutes <= 0) return '';
function generateReloadScript($loadMinutes)
{
if ($loadMinutes <= 0) {
return '';
}
$interval = $loadMinutes * 60000;
return "\n<script>timers.reload = setInterval(function(){if (nchanPaused === false)location.reload();},{$interval});</script>\n";
}
?>
<!DOCTYPE html>
<html <?=$display['rtl']?>lang="<?=strtok($locale,'_')?:'en'?>" class="<?= $themeHelper->getThemeHtmlClass() ?>">
<html <?=$display['rtl']?>lang="<?=strtok($locale, '_') ?: 'en'?>" class="<?= $themeHelper->getThemeHtmlClass() ?>">
<head>
<title><?=_var($var,'NAME')?>/<?=_var($myPage,'name')?></title>
<title><?=_var($var, 'NAME')?>/<?=_var($myPage, 'name')?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Security-Policy" content="block-all-mixed-content">
@@ -58,7 +68,7 @@ function generateReloadScript($loadMinutes) {
<meta name="viewport" content="width=1300">
<meta name="robots" content="noindex, nofollow">
<meta name="referrer" content="same-origin">
<link type="image/png" rel="shortcut icon" href="/webGui/images/<?=_var($var,'mdColor','red-on')?>.png">
<link type="image/png" rel="shortcut icon" href="/webGui/images/<?=_var($var, 'mdColor', 'red-on')?>.png">
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-fonts.css")?>">
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-cases.css")?>">
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/font-awesome.css")?>">
@@ -86,10 +96,10 @@ function generateReloadScript($loadMinutes) {
<?endif;?>
}
<?
<?php
// Generate sidebar icon CSS if using sidebar theme
if ($themeHelper->isSidebarTheme()) {
echo generate_sidebar_icon_css($taskPages, $buttonPages);
echo generate_sidebar_icon_css($taskPages, $buttonPages);
}
?>
</style>
@@ -101,24 +111,46 @@ if ($themeHelper->isSidebarTheme()) {
<script src="<?autov('/webGui/javascript/dynamix.js')?>"></script>
<script src="<?autov('/webGui/javascript/translate.'.($locale?:'en_US').'.js')?>"></script>
<? require_once "$docroot/plugins/dynamix/include/DefaultPageLayout/HeadInlineJS.php"; ?>
<?php require_once "$docroot/plugins/dynamix/include/DefaultPageLayout/HeadInlineJS.php"; ?>
<?
<?php
foreach ($buttonPages as $button) {
annotate($button['file']);
// include page specific stylesheets (if existing)
$css = "/{$button['root']}/sheets/{$button['name']}";
$css_stock = "$css.css";
$css_theme = "$css-$theme.css"; // @todo add syslog for deprecation notice
if (is_file($docroot.$css_stock)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_stock),'">',"\n";
if (is_file($docroot.$css_theme)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_theme),'">',"\n";
// create page content
eval('?>'.parse_text($button['text']));
annotate($button['file']);
// include page specific stylesheets (if existing)
$css = "/{$button['root']}/sheets/{$button['name']}";
$css_stock = "$css.css";
$css_theme = "$css-$theme.css"; // @todo add syslog for deprecation notice
if (is_file($docroot.$css_stock)) {
echo '<link type="text/css" rel="stylesheet" href="',autov($css_stock),'">',"\n";
}
if (is_file($docroot.$css_theme)) {
echo '<link type="text/css" rel="stylesheet" href="',autov($css_theme),'">',"\n";
}
// create page content
eval('?>'.parse_text($button['text']));
}
// Reload page every X minutes during extended viewing?
if (isset($myPage['Load'])) {
echo generateReloadScript($myPage['Load']);
if (isset($myPage['Load']) && $myPage['Load'] > 0) {
?>
<script>
function setTimerReload() {
timers.reload = setInterval(function(){
if (nchanPaused === false && ! dialogOpen() ) {
location.reload();
}
},<?=$myPage['Load'] * 60000?>);
}
$(document).click(function(e) {
clearInterval(timers.reload);
setTimerReload();
});
function dialogOpen() {
return ($('.sweet-alert').is(':visible') || $('.swal-overlay--show-modal').is(':visible') );
}
setTimerReload();
</script>
<?php
}
?>
@@ -136,51 +168,63 @@ if (isset($myPage['Load'])) {
</div>
<a href="#" class="move_to_end" title="<?=_('Move To End')?>"><i class="fa fa-arrow-circle-down"></i></a>
<a href="#" class="back_to_top" title="<?=_('Back To Top')?>"><i class="fa fa-arrow-circle-up"></i></a>
<?
<?php
// Build page menus
echo "<div id='menu'>";
if ($themeHelper->isSidebarTheme()) echo "<div id='nav-block'>";
if ($themeHelper->isSidebarTheme()) {
echo "<div id='nav-block'>";
}
echo "<div class='nav-tile'>";
foreach ($taskPages as $button) {
$page = $button['name'];
$play = $task==$page ? " active" : "";
echo "<div class='nav-item{$play}'>";
echo "<a href=\"/$page\" onclick=\"initab('/$page')\">"._(_var($button,'Name',$page))."</a></div>";
// create list of nchan scripts to be started
if (isset($button['Nchan'])) nchan_merge($button['root'], $button['Nchan']);
$page = $button['name'];
$play = $task == $page ? " active" : "";
echo "<div class='nav-item{$play}'>";
echo "<a href=\"/$page\" onclick=\"initab('/$page')\">"._(_var($button, 'Name', $page))."</a></div>";
// create list of nchan scripts to be started
if (isset($button['Nchan'])) {
nchan_merge($button['root'], $button['Nchan']);
}
}
unset($taskPages);
echo "</div>";
echo "<div class='nav-tile right'>";
if (isset($myPage['Lock'])) {
$title = $themeHelper->isSidebarTheme() ? "" : _('Unlock sortable items');
echo "<div class='nav-item LockButton util'><a href='#' class='hand' onclick='LockButton();return false;' title=\"$title\"><b class='icon-u-lock system green-text'></b><span>"._('Unlock sortable items')."</span></a></div>";
$title = $themeHelper->isSidebarTheme() ? "" : _('Unlock sortable items');
echo "<div class='nav-item LockButton util'><a href='#' class='hand' onclick='LockButton();return false;' title=\"$title\"><b class='icon-u-lock system green-text'></b><span>"._('Unlock sortable items')."</span></a></div>";
}
if ($display['usage']) {
my_usage();
}
if ($display['usage']) my_usage();
foreach ($buttonPages as $button) {
if (empty($button['Link'])) {
$icon = $button['Icon'];
if (substr($icon,-4)=='.png') {
$icon = "<img src='/{$button['root']}/icons/$icon' class='system'>";
} elseif (substr($icon,0,5)=='icon-') {
$icon = "<b class='$icon system'></b>";
if (empty($button['Link'])) {
$icon = $button['Icon'];
if (substr($icon, -4) == '.png') {
$icon = "<img src='/{$button['root']}/icons/$icon' class='system'>";
} elseif (substr($icon, 0, 5) == 'icon-') {
$icon = "<b class='$icon system'></b>";
} else {
if (substr($icon, 0, 3) != 'fa-') {
$icon = "fa-$icon";
}
$icon = "<b class='fa $icon system'></b>";
}
$title = $themeHelper->isSidebarTheme() ? "" : " title=\""._($button['Title'])."\"";
echo "<div class='nav-item {$button['name']} util'><a href='"._var($button, 'Href', '#')."' onclick='{$button['name']}();return false;'{$title}>$icon<span>"._($button['Title'])."</span></a></div>";
} else {
if (substr($icon,0,3)!='fa-') $icon = "fa-$icon";
$icon = "<b class='fa $icon system'></b>";
echo "<div class='{$button['Link']}'></div>";
}
// create list of nchan scripts to be started
if (isset($button['Nchan'])) {
nchan_merge($button['root'], $button['Nchan']);
}
$title = $themeHelper->isSidebarTheme() ? "" : " title=\""._($button['Title'])."\"";
echo "<div class='nav-item {$button['name']} util'><a href='"._var($button,'Href','#')."' onclick='{$button['name']}();return false;'{$title}>$icon<span>"._($button['Title'])."</span></a></div>";
} else {
echo "<div class='{$button['Link']}'></div>";
}
// create list of nchan scripts to be started
if (isset($button['Nchan'])) nchan_merge($button['root'], $button['Nchan']);
}
echo "<div class='nav-user show'><a id='board' href='#' class='hand'><b id='bell' class='icon-u-bell system'></b></a></div>";
if ($themeHelper->isSidebarTheme()) echo "</div>";
if ($themeHelper->isSidebarTheme()) {
echo "</div>";
}
echo "</div></div>";
unset($buttonPages,$button);
@@ -189,83 +233,105 @@ unset($buttonPages,$button);
echo "<div class='tabs'>";
$tab = 1;
$pages = [];
if (!empty($myPage['text'])) $pages[$myPage['name']] = $myPage;
if (_var($myPage,'Type')=='xmenu') $pages = array_merge($pages, find_pages($myPage['name']));
if (isset($myPage['Tabs'])) $display['tabs'] = strtolower($myPage['Tabs'])=='true' ? 0 : 1;
$tabbed = $display['tabs']==0 && count($pages)>1;
if (!empty($myPage['text'])) {
$pages[$myPage['name']] = $myPage;
}
if (_var($myPage, 'Type') == 'xmenu') {
$pages = array_merge($pages, find_pages($myPage['name']));
}
if (isset($myPage['Tabs'])) {
$display['tabs'] = strtolower($myPage['Tabs']) == 'true' ? 0 : 1;
}
$tabbed = $display['tabs'] == 0 && count($pages) > 1;
foreach ($pages as $page) {
$close = false;
if (isset($page['Title'])) {
eval("\$title=\"".htmlspecialchars($page['Title'])."\";");
if ($tabbed) {
echo "<div class='tab'><input type='radio' id='tab{$tab}' name='tabs' onclick='settab(this.id)'><label for='tab{$tab}'>";
echo tab_title($title,$page['root'],_var($page,'Tag',false));
echo "</label><div class='content'>";
$close = true;
} else {
if ($tab==1) echo "<div class='tab'><input type='radio' id='tab{$tab}' name='tabs'><div class='content shift'>";
echo "<div class='title'><span class='left'>";
echo tab_title($title,$page['root'],_var($page,'Tag',false));
echo "</span></div>";
}
$tab++;
}
if (isset($page['Type']) && $page['Type']=='menu') {
$pgs = find_pages($page['name']);
foreach ($pgs as $pg) {
@eval("\$title=\"".htmlspecialchars($pg['Title'])."\";");
$icon = _var($pg,'Icon',"<i class='icon-app PanelIcon'></i>");
if (substr($icon,-4)=='.png') {
$root = $pg['root'];
if (file_exists("$docroot/$root/images/$icon")) {
$icon = "<img src='/$root/images/$icon' class='PanelImg'>";
} elseif (file_exists("$docroot/$root/$icon")) {
$icon = "<img src='/$root/$icon' class='PanelImg'>";
$close = false;
if (isset($page['Title'])) {
eval("\$title=\"".htmlspecialchars($page['Title'])."\";");
if ($tabbed) {
echo "<div class='tab'><input type='radio' id='tab{$tab}' name='tabs' onclick='settab(this.id)'><label for='tab{$tab}'>";
echo tab_title($title, $page['root'], _var($page, 'Tag', false));
echo "</label><div class='content'>";
$close = true;
} else {
$icon = "<i class='icon-app PanelIcon'></i>";
if ($tab == 1) {
echo "<div class='tab'><input type='radio' id='tab{$tab}' name='tabs'><div class='content shift'>";
}
echo "<div class='title'><span class='left'>";
echo tab_title($title, $page['root'], _var($page, 'Tag', false));
echo "</span></div>";
}
} elseif (substr($icon,0,5)=='icon-') {
$icon = "<i class='$icon PanelIcon'></i>";
} elseif ($icon[0]!='<') {
if (substr($icon,0,3)!='fa-') $icon = "fa-$icon";
$icon = "<i class='fa $icon PanelIcon'></i>";
}
echo "<div class=\"Panel\"><a href=\"/$path/{$pg['name']}\" onclick=\"$.cookie('one','tab1')\"><span>$icon</span><div class=\"PanelText\">"._($title)."</div></a></div>";
$tab++;
}
if (isset($page['Type']) && $page['Type'] == 'menu') {
$pgs = find_pages($page['name']);
foreach ($pgs as $pg) {
@eval("\$title=\"".htmlspecialchars($pg['Title'])."\";");
$icon = _var($pg, 'Icon', "<i class='icon-app PanelIcon'></i>");
if (substr($icon, -4) == '.png') {
$root = $pg['root'];
if (file_exists("$docroot/$root/images/$icon")) {
$icon = "<img src='/$root/images/$icon' class='PanelImg'>";
} elseif (file_exists("$docroot/$root/$icon")) {
$icon = "<img src='/$root/$icon' class='PanelImg'>";
} else {
$icon = "<i class='icon-app PanelIcon'></i>";
}
} elseif (substr($icon, 0, 5) == 'icon-') {
$icon = "<i class='$icon PanelIcon'></i>";
} elseif ($icon[0] != '<') {
if (substr($icon, 0, 3) != 'fa-') {
$icon = "fa-$icon";
}
$icon = "<i class='fa $icon PanelIcon'></i>";
}
echo "<div class=\"Panel\"><a href=\"/$path/{$pg['name']}\" onclick=\"$.cookie('one','tab1')\"><span>$icon</span><div class=\"PanelText\">"._($title)."</div></a></div>";
}
}
// create list of nchan scripts to be started
if (isset($page['Nchan'])) {
nchan_merge($page['root'], $page['Nchan']);
}
annotate($page['file']);
// include page specific stylesheets (if existing)
$css = "/{$page['root']}/sheets/{$page['name']}";
$css_stock = "$css.css";
$css_theme = "$css-$theme.css";
if (is_file($docroot.$css_stock)) {
echo '<link type="text/css" rel="stylesheet" href="',autov($css_stock),'">',"\n";
}
if (is_file($docroot.$css_theme)) {
echo '<link type="text/css" rel="stylesheet" href="',autov($css_theme),'">',"\n";
}
// create page content
empty($page['Markdown']) || $page['Markdown'] == 'true' ? eval('?>'.Markdown(parse_text($page['text']))) : eval('?>'.parse_text($page['text']));
if ($close) {
echo "</div></div>";
}
}
// create list of nchan scripts to be started
if (isset($page['Nchan'])) nchan_merge($page['root'], $page['Nchan']);
annotate($page['file']);
// include page specific stylesheets (if existing)
$css = "/{$page['root']}/sheets/{$page['name']}";
$css_stock = "$css.css";
$css_theme = "$css-$theme.css";
if (is_file($docroot.$css_stock)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_stock),'">',"\n";
if (is_file($docroot.$css_theme)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_theme),'">',"\n";
// create page content
empty($page['Markdown']) || $page['Markdown']=='true' ? eval('?>'.Markdown(parse_text($page['text']))) : eval('?>'.parse_text($page['text']));
if ($close) echo "</div></div>";
}
if (count($pages)) {
$running = file_exists($nchan_pid) ? file($nchan_pid,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) : [];
$start = array_diff($nchan, $running); // returns any new scripts to be started
$stop = array_diff($running, $nchan); // returns any old scripts to be stopped
$running = array_merge($start, $running); // update list of current running nchan scripts
// start nchan scripts which are new
foreach ($start as $row) {
$script = explode(':',$row)[0];
exec("$docroot/$script &>/dev/null &");
}
// stop nchan scripts with the :stop option
foreach ($stop as $row) {
[$script,$opt] = my_explode(':',$row);
if ($opt == 'stop') {
exec("pkill -f $docroot/$script &>/dev/null &");
array_splice($running,array_search($row,$running),1);
$running = file_exists($nchan_pid) ? file($nchan_pid, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : [];
$start = array_diff($nchan, $running); // returns any new scripts to be started
$stop = array_diff($running, $nchan); // returns any old scripts to be stopped
$running = array_merge($start, $running); // update list of current running nchan scripts
// start nchan scripts which are new
foreach ($start as $row) {
$script = explode(':', $row)[0];
exec("$docroot/$script &>/dev/null &");
}
// stop nchan scripts with the :stop option
foreach ($stop as $row) {
[$script,$opt] = my_explode(':', $row);
if ($opt == 'stop') {
exec("pkill -f $docroot/$script &>/dev/null &");
array_splice($running, array_search($row, $running), 1);
}
}
if (count($running)) {
file_put_contents($nchan_pid, implode("\n", $running)."\n");
} else {
@unlink($nchan_pid);
}
}
if (count($running)) file_put_contents($nchan_pid,implode("\n",$running)."\n"); else @unlink($nchan_pid);
}
unset($pages,$page,$pgs,$pg,$icon,$nchan,$running,$start,$stop,$row,$script,$opt,$nchan_run);
?>
@@ -274,7 +340,7 @@ unset($pages,$page,$pgs,$pg,$icon,$nchan,$running,$start,$stop,$row,$script,$opt
<form name="rebootNow" method="POST" action="/webGui/include/Boot.php"><input type="hidden" name="cmd" value="reboot"></form>
<iframe id="progressFrame" name="progressFrame" frameborder="0"></iframe>
<? require_once "$docroot/webGui/include/DefaultPageLayout/Footer.php"; ?>
<? require_once "$docroot/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php"; ?>
<?php require_once "$docroot/webGui/include/DefaultPageLayout/Footer.php"; ?>
<?php require_once "$docroot/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php"; ?>
</body>
</html>

View File

@@ -434,7 +434,13 @@ document.addEventListener("visibilitychange", (event) => {
nchanFocusStop();
} else {
<? if (isset($myPage['Load']) && $myPage['Load'] > 0):?>
window.location.reload();
if ( dialogOpen() ) {
clearInterval(timers.reload);
setTimerReload();
nchanFocusStart();
} else {
window.location.reload();
}
<?else:?>
nchanFocusStart();
<?endif;?>