mirror of
https://github.com/itflow-org/itflow
synced 2026-11-21 20:07:24 +00:00
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:
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user