Show a saving indicator on estimates and invoices

Clicking Save, Save and send or Save draft shows a spinner in the action bar and locks the buttons until the page reloads, so a second click can't save or send twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-06 10:44:25 -05:00
1 parent 2fb21c34bb
commit 461fa79bc5
4 files changed
+56 -3

No files matched your search

+6 -3
View File
@@ -298,10 +298,12 @@
</fieldset> </fieldset>
<%# Action bar, like the bar along the bottom of QuickBooks' estimate screen %> <%# Action bar, like the bar along the bottom of QuickBooks' estimate screen %>
<div class="qbo-estimate-actions"> <div class="qbo-estimate-actions" data-saving-text="<%= l(:text_qbo_saving) %>">
<%= link_to l(:button_cancel), cancel_path, class: 'qbo-button qbo-button-dark', id: 'qbo-estimate-cancel' %> <%= link_to l(:button_cancel), cancel_path, class: 'qbo-button qbo-button-dark', id: 'qbo-estimate-cancel' %>
<% unless form.locked %> <% unless form.locked %>
<span class="qbo-estimate-actions-save"> <span class="qbo-estimate-actions-save">
<%# Shown while a save is on its way to QuickBooks (qbo_estimates/_script) %>
<span class="qbo-saving-status" role="status" aria-live="polite" hidden></span>
<% unless form.persisted? %> <% unless form.persisted? %>
<%# Kept in Redmine only, however incomplete (QboDraftHandling) %> <%# Kept in Redmine only, however incomplete (QboDraftHandling) %>
<% if draft %> <% if draft %>
@@ -309,12 +311,13 @@
data: { confirm: l(:text_are_you_sure) }, class: 'qbo-button qbo-button-dark', id: 'qbo-delete-draft' %> data: { confirm: l(:text_are_you_sure) }, class: 'qbo-button qbo-button-dark', id: 'qbo-delete-draft' %>
<% end %> <% end %>
<%= submit_tag l(:button_qbo_save_draft), name: 'save_draft', class: 'qbo-button qbo-button-dark', <%= submit_tag l(:button_qbo_save_draft), name: 'save_draft', class: 'qbo-button qbo-button-dark',
id: 'qbo-save-draft', formnovalidate: true %> id: 'qbo-save-draft', formnovalidate: true, data: { saving_text: l(:text_qbo_saving_draft) } %>
<% end %> <% end %>
<%= submit_tag l(:button_save), name: 'save', class: 'qbo-button qbo-button-dark' %> <%= submit_tag l(:button_save), name: 'save', class: 'qbo-button qbo-button-dark' %>
<% if sender %> <% if sender %>
<%= submit_tag l(:button_save_and_send), name: 'save_and_send', class: 'qbo-button qbo-button-primary', <%= submit_tag l(:button_save_and_send), name: 'save_and_send', class: 'qbo-button qbo-button-primary',
id: 'qbo-estimate-save-and-send', data: { needs_email_text: l(:text_estimate_send_needs_email) } %> id: 'qbo-estimate-save-and-send',
data: { needs_email_text: l(:text_estimate_send_needs_email), saving_text: l(:text_qbo_saving_and_sending) } %>
<% end %> <% end %>
</span> </span>
<% end %> <% end %>
+35
View File
@@ -773,7 +773,11 @@ $(function () {
if (event.key === 'Enter' && !$(this).closest('.ui-autocomplete').length) event.preventDefault(); if (event.key === 'Enter' && !$(this).closest('.ui-autocomplete').length) event.preventDefault();
}); });
// Set once a save is on its way, so more clicks don't save (or send) it twice
var saving = false;
$form.on('submit', function (event) { $form.on('submit', function (event) {
if (saving) { event.preventDefault(); return; }
var submitter = event.originalEvent && event.originalEvent.submitter; var submitter = event.originalEvent && event.originalEvent.submitter;
if (submitter && submitter.id === 'qbo-estimate-save-and-send' && !$email.val().trim()) { if (submitter && submitter.id === 'qbo-estimate-save-and-send' && !$email.val().trim()) {
event.preventDefault(); event.preventDefault();
@@ -785,6 +789,37 @@ $(function () {
rows().each(function () { tidyNumbers($(this)); }); rows().each(function () { tidyNumbers($(this)); });
tidyDiscount(); tidyDiscount();
dirty = false; dirty = false;
// After every submit handler has run (and the form's values are already taken, so disabling the buttons
// doesn't drop which one was clicked): unless one stopped the save, show it's saving and lock the buttons
setTimeout(function () {
var stopped = event.originalEvent ? event.originalEvent.defaultPrevented : event.isDefaultPrevented();
if (stopped) return;
saving = true;
showSaving(submitter);
}, 0);
});
function showSaving(submitter) {
var $bar = $form.find('.qbo-estimate-actions');
var $clicked = submitter ? $(submitter) : $bar.find('input[type=submit][name=save]');
var text = $clicked.data('savingText') || $bar.data('savingText');
$bar.addClass('qbo-saving');
$bar.find('input[type=submit]').prop('disabled', true);
$bar.find('a.qbo-button').addClass('qbo-button-disabled').attr('aria-disabled', 'true');
$bar.find('.qbo-saving-status').text(text).prop('hidden', false);
}
// Coming back with the browser's Back button can show the page as it was left, still "saving"
window.addEventListener('pageshow', function (event) {
if (!event.persisted || !saving) return;
saving = false;
var $bar = $form.find('.qbo-estimate-actions');
$bar.removeClass('qbo-saving');
$bar.find('input[type=submit]').prop('disabled', false);
$bar.find('a.qbo-button').removeClass('qbo-button-disabled').removeAttr('aria-disabled');
$bar.find('.qbo-saving-status').prop('hidden', true);
}); });
window.addEventListener('beforeunload', function (event) { window.addEventListener('beforeunload', function (event) {
+11
View File
@@ -119,6 +119,17 @@
.qbo-estimate .qbo-button-primary { background: var(--qbo-green); border-color: var(--qbo-green); color: #fff; } .qbo-estimate .qbo-button-primary { background: var(--qbo-green); border-color: var(--qbo-green); color: #fff; }
.qbo-estimate .qbo-button-primary:hover { background: var(--qbo-green-dark); border-color: var(--qbo-green-dark); color: #fff; } .qbo-estimate .qbo-button-primary:hover { background: var(--qbo-green-dark); border-color: var(--qbo-green-dark); color: #fff; }
/* While saving: the buttons are locked and a spinner says what's happening */
.qbo-estimate .qbo-saving .qbo-button[disabled],
.qbo-estimate .qbo-saving .qbo-button-disabled { opacity: .6; cursor: progress; pointer-events: none; }
.qbo-estimate .qbo-saving-status { display: inline-flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; margin-right: 8px; }
.qbo-estimate .qbo-saving-status[hidden] { display: none; }
.qbo-estimate .qbo-saving-status::before { content: ""; width: 16px; height: 16px; border-radius: 50%; box-sizing: border-box;
border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: qbo-saving-spin .8s linear infinite; }
@keyframes qbo-saving-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .qbo-estimate .qbo-saving-status::before { animation-duration: 2.4s; } }
.qbo-estimate .qbo-saving { cursor: progress; }
/* Warnings with a list (linked issues, invoices): the text, then one item per line */ /* Warnings with a list (linked issues, invoices): the text, then one item per line */
div.warning.qbo-estimate-notice { text-align: left; } div.warning.qbo-estimate-notice { text-align: left; }
div.warning.qbo-estimate-notice ul { margin: 6px 0 0; padding-left: 22px; } div.warning.qbo-estimate-notice ul { margin: 6px 0 0; padding-left: 22px; }
+4
View File
@@ -161,6 +161,10 @@ en:
text_qbo_hidden_custom_fields: "Ticked fields are left off estimates and invoices. QuickBooks doesn't tell apps which custom fields are inactive, and a field stays on its old estimates after it's turned off, so tick ones you no longer use (e.g. a renamed \"Sales Rep old\"). The sales person goes in the first field shown whose name has \"sales\" or \"rep\" in it." text_qbo_hidden_custom_fields: "Ticked fields are left off estimates and invoices. QuickBooks doesn't tell apps which custom fields are inactive, and a field stays on its old estimates after it's turned off, so tick ones you no longer use (e.g. a renamed \"Sales Rep old\"). The sales person goes in the first field shown whose name has \"sales\" or \"rep\" in it."
button_reload_estimate: "Reload the estimate" button_reload_estimate: "Reload the estimate"
button_save_and_send: "Save and send" button_save_and_send: "Save and send"
# Shown in the action bar while a save is on its way, with the buttons locked
text_qbo_saving: "Saving to QuickBooks…"
text_qbo_saving_and_sending: "Saving and sending…"
text_qbo_saving_draft: "Saving draft…"
error_estimate_changed_in_quickbooks: "This estimate was changed in QuickBooks after you opened it, so it wasn't saved." error_estimate_changed_in_quickbooks: "This estimate was changed in QuickBooks after you opened it, so it wasn't saved."
error_estimate_field_invalid: "%{field} is not valid" error_estimate_field_invalid: "%{field} is not valid"