Skip to content

Commit

Permalink
Fix issue with close button not working on the first click (#4055)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Jul 10, 2024
1 parent 6d94119 commit 5c887a5
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions bims/static/js/non_requirejs/dashboard_buttons.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let closeClicked = false;

function dashboardClose(e, storageKey = '') {
let button = $(e.target);
if (!button.hasClass('dashboard-close')) {
Expand Down Expand Up @@ -43,13 +45,30 @@ function dashboardClose(e, storageKey = '') {
} else if (previousUrl.indexOf('/abiotic/?') > -1) {
window.history.go(-6);
} else {
e.preventDefault();
window.history.back();
closeClicked = true;
return true
}
}

$(function () {
$('.dashboard-close').click((e) => dashboardClose(e, ''));
$('.site-form-close').click((e) => dashboardClose(e, ''));
$('.sass-form-edit-close').click((e) => dashboardClose(e, 'site-visit-list'));
$('.upload-form-close').click((e) => dashboardClose(e, 'last-map-upload'));
$(document).ready(function () {
attachEventHandlers();
});

$(window).on('pageshow', function () {
attachEventHandlers();
});

function attachEventHandlers() {
$('.dashboard-close').off('click').on('click', (e) => dashboardClose(e, ''));
$('.site-form-close').off('click').on('click', (e) => dashboardClose(e, ''));
$('.sass-form-edit-close').off('click').on('click', (e) => dashboardClose(e, 'site-visit-list'));
$('.upload-form-close').off('click').on('click', (e) => dashboardClose(e, 'last-map-upload'));
}

window.onpopstate = function(event) {
if (closeClicked) {
window.history.back()
}
};

0 comments on commit 5c887a5

Please sign in to comment.