mirror of
https://github.com/itflow-org/itflow
synced 2026-11-22 04:17: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:
@@ -1166,7 +1166,9 @@ itflowBindOnce('itflowCategoryAdd', 'click', '[data-category-add]', function ()
|
||||
*
|
||||
* Editors inside an open modal are skipped, as before: the modal is where that
|
||||
* work gets submitted or discarded. Editors from a closed ajax modal are removed
|
||||
* by js/ajax_modal.js, so tinymce.get() no longer returns them.
|
||||
* by js/ajax_modal.js, so tinymce.get() no longer returns them. So is one whose
|
||||
* text is kept as a draft (data-draft-kept - the ticket reply, agent/js/ticket_reply_extras.js),
|
||||
* where leaving loses nothing.
|
||||
*
|
||||
* Flagged on window because modal_footer.php re-loads this file on every ajax
|
||||
* modal open.
|
||||
@@ -1179,7 +1181,8 @@ if (!window.itflowEditorUnloadGuard) {
|
||||
}
|
||||
const unsaved = tinymce.get().some(function (editor) {
|
||||
const inVisibleModal = editor.getContainer()?.closest('.modal.show');
|
||||
return !inVisibleModal && editor.isDirty();
|
||||
const keptAsDraft = editor.getElement()?.dataset.draftKept === '1';
|
||||
return !inVisibleModal && !keptAsDraft && editor.isDirty();
|
||||
});
|
||||
if (unsaved) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -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