diff --git a/CHANGELOG.md b/CHANGELOG.md index 604a4c478..04457320d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,7 +141,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - A list's filters that are on now stand out, tinted in your theme color, and an x at the end of the search box clears the search and every filter at once - on clients, tickets and projects too, in place of the chips that listed each filter under them. More filters on those three takes the same tint while one tucked under it is on, where it turned yellow. - Shift-click a list's tick boxes to tick, or untick, every row between two clicks. - Compact rows: Your account > Preferences can show lists with tighter rows, so more fit on screen. -- Tickets: what you type in a ticket's reply box is kept as you write. Leave the page, close the browser or get signed out, and it's back next time with a note saying so - pick how to send it to carry on, or discard it. +- Tickets: what you type in a ticket's reply box is kept as you write. Leave the page, close the browser or get signed out, and it's back next time with a note saying so - pick how to send it to carry on, or discard it. So leaving a ticket with a reply half written no longer asks "Leave page?" first. - Tickets: drop files onto a ticket's reply box to attach them to your reply. - Tickets: +15m, +30m and +1h beside Time worked add time in one click. The timer stops at the new total. - Tickets: on a billable ticket, sending a reply with no time asks first - Send without time, or Add time. @@ -204,6 +204,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u ### Bug Fixes +- Invoices, quotes and recurring invoices: leaving the page in the middle of typing a note asked "Leave page?" - even though the note saves as you go. It now saves on the way out instead. - Email replies to tickets: a client who typed below the "Please type your reply above this line" line - or whose mail program puts replies under the email it quotes, as Thunderbird and Apple Mail can, and plain text replies do - lost everything they wrote, and the ticket got an empty reply. What they wrote below the quote is now kept, as well as anything above the line. When nothing was written above the line and their words can't be told from the quote, the whole email goes on the ticket with a note saying so, rather than nothing. - Invoices: Copy Invoice and Make Recurring copied the Card Fee line of an invoice paid by card, so the copy or every invoice the recurring one made charged the fee before anyone paid - and a client who paid the copy by card was charged a second fee on top. The card fee ITFlow added is now left off, the total without it, and the Copy Invoice and Make Recurring windows say so. A line you typed yourself with that name is still copied. Releases from 26.11.4 to 26.11.8 are affected. - Quotes: Copy Quote dropped each line's link to the product it came from, so the copy's Margin left those lines out. The copy now keeps it. Found by Mountaineer IT. @@ -255,6 +256,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u ### Developer Updates +- Leaving a page: `js/app.js`'s `beforeunload` guard for TinyMCE editors skips one whose element has `data-draft-kept="1"` - the ticket reply when `ticket_reply_drafts` is in use, which `agent/js/ticket_reply_extras.js` keeps with `sendBeacon` on `pagehide`. `js/inline_notes.js` no longer warns either: on `pagehide` it posts an unsaved note to its `ajax.php` endpoint with `sendBeacon`. The document editor page, the profile signature and the settings pages still ask, as nothing keeps what was typed there. - Undo: `functions/undo.php`. A handler that can be put back calls `undoOffer()` after its `flashAlert()` with the message for afterwards and the steps that put it back; the steps are kept in `\$_SESSION['undo']` under a random token for `UNDO_SECONDS` (600, the last `UNDO_KEEP` of them), and `\$_SESSION['alert_undo']` gives the next message an Undo button (`includes/inc_alert_feedback.php`, `.itflow-toast-undo`) linking to `agent/post.php?undo=` with the CSRF token (`agent/post/undo.php`, `undoApply()`), which checks the user, the age and the permission level again. `flashAlert()` clears `alert_undo`, so only the message it was offered on carries it. `undoSnapshot()` before a change and `undoOfferChanges()` after offer the columns back as `set` steps, each only if the row still holds what the change wrote; `undoArchiveBefore()` / `undoOfferArchive()` do the same for archiving through `archivedRestore()`, with a contact's role flags, a document's link rows and a client's running recurring invoices. Steps that need their side effects go through their own code: `ticket_priority` (`ticketChangePriority()`), `ticket_category` and `ticket_project` (ticket history), `asset_status` (asset history), `folder` (no loop) and `rack` (`rackUnitConflict()`). The archive links and bulk Archive buttons of those kinds lose `confirm-link`; clients keep theirs. - Database 3.6.7: `rmm_providers` (`rmm_provider_kind` - `tactical` for now - the name it goes by, `api_url`, `web_url`, `api_key`, `api_secret` for an RMM that signs in with an id and a secret, and how the last sync went), `rmm_clients` (each provider's clients, `rmm_client_client_id` 0 until linked, `rmm_client_removed_at` once the RMM stops listing one) and `rmm_devices` (one a device: its asset, what the RMM last said - status, last seen, signed-in user, reboot, patches, checks - and `rmm_device_synced`, JSON of what the sync last wrote to the asset). Re-runnable, like 3.6.0. - `functions/rmm.php` is what every RMM shares. A kind is an entry in `rmmProviderKinds()` and a file of its own - `functions/rmm_tactical.php` for Tactical. It names the connection fields it uses, with their labels and help (the window and its checks are built from them), hints added to errors, the device links it offers, and four functions: `clients`, `devices` (each device in the shape described above `rmmDeviceFacts()`), `dashboard` and `device_urls`. `rmmHttp()` makes the request and turns a refused key, a redirect, a 404 or an answer that isn't JSON into a sentence for the person; `rmmTacticalRequest()` adds Tactical's `X-API-KEY`. Another RMM is a file like `rmm_tactical.php`, a line in `rmmProviderKinds()` and a `require_once` in `functions.php`. diff --git a/agent/js/ticket_reply_extras.js b/agent/js/ticket_reply_extras.js index 4724768a3..3686587cb 100644 --- a/agent/js/ticket_reply_extras.js +++ b/agent/js/ticket_reply_extras.js @@ -67,7 +67,6 @@ itflowPost('ajax.php', { ticket_reply_draft: 1, csrf_token: csrf, ticket_id: ticketId, html: html }, function (answer) { lastSaved = html; var ed = editor(); - // Kept, so leaving the page loses nothing - no need to warn about it if (ed && content() === html) { ed.setDirty(false); } @@ -103,6 +102,12 @@ } if (drafts) { + // What is typed is kept as it goes and as the page is left, so leaving doesn't ask first (js/app.js) + var replyBox = document.getElementById('ticket_reply'); + if (replyBox) { + replyBox.dataset.draftKept = '1'; + } + var tries = 0; (function waitForEditor() { if (watchEditor()) { diff --git a/js/app.js b/js/app.js index e034ee6a1..1ba12086d 100644 --- a/js/app.js +++ b/js/app.js @@ -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(); diff --git a/js/inline_notes.js b/js/inline_notes.js index 6a9b80a2e..ec1e5669a 100644 --- a/js/inline_notes.js +++ b/js/inline_notes.js @@ -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; }); }