Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions web/skins/classic/js/skin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2091,8 +2091,11 @@ function initPageGeneral() {
// The problem also occurs on some Linux (Chromium) and Android (Chrome) devices.
window.addEventListener('pageshow', (event) => {
if (event.persisted) {
// Do any checks and updates to the page
window.location.reload( true );
// Only reload if there's an actual rendering problem
if (mainContentJ && mainContentJ[0] && mainContentJ[0].clientHeight < 1) {
window.location.reload( true );
}
// Otherwise, let individual pages handle bfcache restoration
}
});

Expand Down
69 changes: 65 additions & 4 deletions web/skins/classic/views/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const exportButton = $j('#exportBtn');
const downloadButton = $j('#downloadBtn');
const deleteButton = $j('#deleteBtn');
const table = $j('#eventTable');
const FILTER_STATE_KEY = 'eventsFilterState';
var ajax = null;

/*
Expand Down Expand Up @@ -519,10 +520,70 @@ function initPage() {
initDatepickerEventsPage();
}

window.onpageshow = function(evt) {
console.log('Refreshing table');
table.bootstrapTable('refresh');
};
// Store filter state before navigating away
window.addEventListener('pagehide', function() {
try {
const filterState = {};
$j('#fieldsTable input, #fieldsTable select').each(function() {
const el = $j(this);
const name = el.attr('name');
if (name) {
filterState[name] = el.val();
}
});
sessionStorage.setItem(FILTER_STATE_KEY, JSON.stringify(filterState));
} catch (e) {
// Handle quota exceeded or sessionStorage disabled errors
console.error('Failed to save filter state:', e);
}
});

// Restore filter state when coming back via bfcache
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
const savedState = sessionStorage.getItem(FILTER_STATE_KEY);
if (savedState) {
try {
const filterState = JSON.parse(savedState);
// Iterate through actual form fields and restore their values
$j('#fieldsTable input, #fieldsTable select').each(function() {
const field = $j(this);
const name = field.attr('name');
if (name && Object.prototype.hasOwnProperty.call(filterState, name)) {
const value = filterState[name];
// For select elements, validate that the value exists in options
if (field.is('select')) {
let validOption = false;
field.find('option').each(function() {
if ($j(this).val() === value) {
validOption = true;
return false; // break
}
});
if (validOption || value === '') {
field.val(value);
}
} else {
// For input elements, restore the value directly
field.val(value);
}
}
});
// Refresh the table with the restored filter values
table.bootstrapTable('refresh');
} catch (e) {
// Handle corrupted sessionStorage data gracefully
console.error('Failed to restore filter state:', e);
sessionStorage.removeItem(FILTER_STATE_KEY);
console.log('Refreshing table');
table.bootstrapTable('refresh');
}
}
} else {
console.log('Refreshing table');
table.bootstrapTable('refresh');
}
});

table.bootstrapTable('resetSearch');
// The table is initially given a hidden style, so now that we are done rendering, show it
Expand Down