Skip to content

Commit

Permalink
Made banners fixed position #3264
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Jul 29, 2024
1 parent dae1d9d commit d44e960
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
42 changes: 36 additions & 6 deletions grails-app/assets/javascripts/base-bs4.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,52 @@ function setupTimeoutWarning(options) {
var $loginButton = $(options.loginButtonSelector);

// Set up a timer that will periodically poll the server to keep the session alive
var intervalSeconds = 5 * 60;
var intervalSeconds = 5 //* 60;

function fireKeepAlive() {
$.ajax(options.keepSessionAliveUrl).fail(function (xhr) {
if (xhr.status == 0) {
// Network outage?
$networkWarningBanner.show();
showNetworkBanner();
} else if (xhr.status == 401) {
$networkWarningBanner.hide();
hideNetworkBanner();
// Session timed out.
$logoutWarningBanner.show();
showTimeoutBanner();
}
}).done(function (xhr) {
$networkWarningBanner.hide();
$logoutWarningBanner.hide();
hideNetworkBanner();
hideTimeoutBanner();
});
}

function showBanner(banner) {
banner.show();
var height = banner.height();
$(document).css("margin-top", height);
}

function hideBanner(banner) {
banner.hide();
$(document).css("margin-top", "0");
}

function showTimeoutBanner() {
showBanner($logoutWarningBanner);
}

function hideTimeoutBanner() {
hideBanner($logoutWarningBanner);
}

function showNetworkBanner() {
showBanner($networkWarningBanner);
hideBanner($logoutWarningBanner)
}

function hideNetworkBanner() {
hideBanner($networkWarningBanner);
}

setInterval(fireKeepAlive, intervalSeconds * 1000);

if (!window.localStorage) {
Expand Down Expand Up @@ -63,4 +91,6 @@ function setupTimeoutWarning(options) {
window.addEventListener('offline', function() {
fireKeepAlive();
});


}
4 changes: 4 additions & 0 deletions grails-app/assets/stylesheets/nrm/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -2445,13 +2445,17 @@ div#announcement p {
}

div#logout-warning, div#network-warning {
position: fixed;
width: 100%;
top: 0;
padding: 15px;
font-size: 20px;
font-weight: bold;
text-align: center;
color: white;
background-color: red;
border-bottom: 0px solid red;
z-index: 1000;
}
#logout-warning a, #network-warning a {
color:white;
Expand Down
4 changes: 2 additions & 2 deletions grails-app/views/layouts/nrm_bs4.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
keepSessionAliveUrl: "${g.createLink(controller: 'ajax', action:'keepSessionAlive')}",
logoutWarningBannerId: 'logout-warning',
networkWarningBannerId: 'network-warning',
logoutButtonSelector: 'a.btnLogin', // Not a typo, same class as login button.
loginButtonSelector: 'a.btnLogin'
logoutButtonSelector: 'a.btn-login', // Not a typo, same class as login button.
loginButtonSelector: 'a.btn-login'
};
var loggedIn = false;
<auth:ifLoggedIn>
Expand Down

0 comments on commit d44e960

Please sign in to comment.