Leaving a page: a ticket's reply no longer asks Leave page first, as it is kept as a draft, and invoice, quote and recurring invoice notes save on the way out instead of asking; the document editor, signature and settings pages still ask

This commit is contained in:
johnnyq
2026-11-19 23:26:02 -05:00
parent 6a5bc6cf55
commit 3d2bfbcad5
4 changed files with 25 additions and 9 deletions

View File

@@ -71,12 +71,18 @@ function itflowInlineNotes(textarea) {
}
});
// Warn rather than lose the text if the page is closed mid-edit
window.addEventListener('beforeunload', function (e) {
if (textarea.value !== lastSaved) {
e.preventDefault();
e.returnValue = '';
// Leaving mid-edit saves it on the way out rather than asking first
window.addEventListener('pagehide', function () {
if (textarea.value === lastSaved || !navigator.sendBeacon) {
return;
}
const data = new FormData();
data.append('csrf_token', textarea.dataset.csrf);
data.append('note', textarea.value);
data.append(textarea.dataset.endpoint, 'TRUE');
data.append(textarea.dataset.idField, textarea.dataset.id);
navigator.sendBeacon('ajax.php', data);
lastSaved = textarea.value;
});
}