From 5d15b8c6138809f9cd8c942e2aa9bf00781e2cb0 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 14 Mar 2020 12:07:03 +0100 Subject: [PATCH] Fix (de)validation of transactions --- apps/note/tables.py | 4 +++- templates/note/conso_form.html | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 9309e14c..ceb710df 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -27,7 +27,9 @@ class HistoryTable(tables.Table): total = tables.Column() # will use Transaction.total() !! valid = tables.Column(attrs={"td": {"id": lambda record: "validate_" + str(record.id), - "class": lambda record: str(record.valid).lower() + ' validate'}}) + "class": lambda record: str(record.valid).lower() + ' validate', + "onclick": lambda record: 'de_validate(' + str(record.id) + ', ' + + str(record.valid).lower() + ')'}}) def order_total(self, queryset, is_descending): # needed for rendering diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 46a3b453..596b3d82 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -192,10 +192,9 @@ {% endif %} {% endfor %} - // When we click on the validate button, the validation status is switched - $(".validate").click(function(e) { - let id = e.target.id.substring(9); - let validated = e.target.classList.contains("true"); + // When a validate button is clicked, we switch the validation status + function de_validate(id, validated) { + $("#validate_" + id).html("⟳ ..."); // Perform a PATCH request to the API in order to update the transaction // If the user has insuffisent rights, an error message will appear @@ -211,11 +210,14 @@ "resourcetype": "TemplateTransaction", valid: !validated }, - success: function() { + success: function () { refreshHistory(); refreshBalance(); + + // Refresh jQuery objects + $(".validate").click(de_validate); } }); - }); + } {% endblock %}