From 244447c57ade84969e7c604972a8edc0a90028f0 Mon Sep 17 00:00:00 2001 From: Sli Date: Fri, 20 Dec 2024 20:21:36 +0100 Subject: [PATCH] Redirect when cancelling instead of submitting a form --- counter/static/bundled/counter/counter-click-index.ts | 9 ++------- counter/templates/counter/counter_click.jinja | 3 +-- counter/views/click.py | 1 + 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/counter/static/bundled/counter/counter-click-index.ts b/counter/static/bundled/counter/counter-click-index.ts index a9294660..e05de762 100644 --- a/counter/static/bundled/counter/counter-click-index.ts +++ b/counter/static/bundled/counter/counter-click-index.ts @@ -10,12 +10,11 @@ interface InitialFormData { } interface CounterConfig { - csrfToken: string; - clickApiUrl: string; customerBalance: number; customerId: number; products: Record; formInitial: InitialFormData[]; + cancelUrl: string; } interface Product { @@ -132,11 +131,7 @@ exportToHtml("loadCounter", (config: CounterConfig) => { }, cancel() { - this.basket = new Object({}); - // We need to wait for the templated form to be removed before sending - this.$nextTick(() => { - this.finish(); - }); + location.href = config.cancelUrl; }, handleCode() { diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja index 132f395c..020f9634 100644 --- a/counter/templates/counter/counter_click.jinja +++ b/counter/templates/counter/counter_click.jinja @@ -199,11 +199,10 @@ ]; window.addEventListener("DOMContentLoaded", () => { loadCounter({ - csrfToken: "{{ csrf_token }}", - clickApiUrl: "{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}", customerBalance: {{ customer.amount }}, products: products, customerId: {{ customer.pk }}, formInitial: formInitial, + cancelUrl: "{{ cancel_url }}", }); }); diff --git a/counter/views/click.py b/counter/views/click.py index e9e2829d..75f0fcd9 100644 --- a/counter/views/click.py +++ b/counter/views/click.py @@ -260,6 +260,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, SingleObjectMixin, FormView): product ) kwargs["customer"] = self.customer + kwargs["cancel_url"] = self.get_success_url() # To get all forms errors to the javascript, we create a list of error list kwargs["form_errors"] = []