diff --git a/apps/member/views.py b/apps/member/views.py index 82c15b99..dacfde33 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -124,7 +124,7 @@ class UserDetailView(LoginRequiredMixin, DetailView): context = super().get_context_data(**kwargs) user = context['user_object'] history_list = \ - Transaction.objects.all().filter(Q(source=user.note) | Q(destination=user.note)) + Transaction.objects.all().filter(Q(source=user.note) | Q(destination=user.note)).order_by("-id") context['history_list'] = HistoryTable(history_list) club_list = \ Membership.objects.all().filter(user=user).only("club") diff --git a/static/js/base.js b/static/js/base.js index 882ef1d8..3105764e 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -229,3 +229,42 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes }); }); } + +// 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 + $.ajax({ + "url": "/api/note/transaction/transaction/" + id + "/", + type: "PATCH", + dataType: "json", + headers: { + "X-CSRFTOKEN": CSRF_TOKEN + }, + data: { + "resourcetype": "TemplateTransaction", + valid: !validated + }, + success: function () { + // Refresh jQuery objects + $(".validate").click(de_validate); + + refreshBalance(); + // error if this method doesn't exist. Please define it. + refreshHistory(); + }, + error: function(err) { + let msgDiv = $("#messages"); + let html = msgDiv.html(); + html += "