From ca6a28e817a28f7e403a513205717b295c6793e2 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 21 Mar 2017 11:08:57 +0200 Subject: [PATCH] Handle save invoice token error --- resources/views/invoices/edit.blade.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 88d463da2e21..3ccd975ff9d0 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -1429,13 +1429,14 @@ $('#saveButton, #emailButton, #draftButton').attr('disabled', true); // if save fails ensure user can try again $.post('{{ url($url) }}', $('.main-form').serialize(), function(data) { - NINJA.formIsChanged = false; - location.href = data; + if (data && data.startsWith('http')) { + NINJA.formIsChanged = false; + location.href = data; + } else { + handleSaveFailed(); + } }).fail(function(data) { - $('#saveButton, #emailButton, #draftButton').attr('disabled', false); - $('#emailModal div.modal-footer button').attr('disabled', false); - var error = firstJSONError(data.responseJSON) || data.statusText; - swal("{!! trans('texts.invoice_save_error') !!}", error); + handleSaveFailed(data); }); return false; @else @@ -1443,6 +1444,16 @@ @endif } + function handleSaveFailed(data) { + $('#saveButton, #emailButton, #draftButton').attr('disabled', false); + $('#emailModal div.modal-footer button').attr('disabled', false); + var error = ''; + if (data) { + var error = firstJSONError(data.responseJSON) || data.statusText; + } + swal("{!! trans('texts.invoice_save_error') !!}", error); + } + function submitBulkAction(value) { $('#bulk_action').val(value); $('.bulkForm')[0].submit();