diff --git a/apps/member/views.py b/apps/member/views.py index 82c15b99fd787a49adbed554999a36beb263e7a0..dacfde3331439473a9182abf49bf01bb6ffc24a2 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 882ef1d88c3897ce9275da7983b82c42ecbd0168..3105764e66a2c13509aa60b0369780a95d088617 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("<strong style=\"font-size: 16pt;\">⟳ ...</strong>"); + + // 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 += "<div class='alert alert-danger'>Une erreur est survenue lors de la validation/dévalidation " + + "de cette transaction : " + err.responseText + "</div>"; + msgDiv.html(html); + + refreshBalance(); + // error if this method doesn't exist. Please define it. + refreshHistory(); + } + }); +} diff --git a/static/js/consos.js b/static/js/consos.js index 7e04a8457d24b98d9a7103b4a09f4c7e4969806b..902ffee2fe827278af55ac725624388f1a0fd68f 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -177,31 +177,3 @@ function consume(source, dest, quantity, amount, reason, type, category, templat refreshBalance(); }); } - -// When a validate button is clicked, we switch the validation status -function de_validate(id, validated) { - $("#validate_" + id).html("<strong style=\"font-size: 16pt;\">⟳ ...</strong>"); - - // Perform a PATCH request to the API in order to update the transaction - // If the user has insuffisent rights, an error message will appear - // TODO: Add this error message - $.ajax({ - "url": "/api/note/transaction/transaction/" + id + "/", - type: "PATCH", - dataType: "json", - headers: { - "X-CSRFTOKEN": CSRF_TOKEN - }, - data: { - "resourcetype": "TemplateTransaction", - valid: !validated - }, - success: function () { - refreshHistory(); - refreshBalance(); - - // Refresh jQuery objects - $(".validate").click(de_validate); - } - }); -} diff --git a/templates/base.html b/templates/base.html index eefad7c8ffb4c2b19ec684f6a18f8e89b3872b49..e61937021c6f566f9b3125cc00dac9de9e66634c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -53,6 +53,13 @@ SPDX-License-Identifier: GPL-3.0-or-later {{ form.media }} {% endif %} + <style> + .validate:hover { + cursor: pointer; + text-decoration: underline; + } + </style> + {% block extracss %}{% endblock %} </head> <body class="d-flex w-100 h-100 flex-column"> diff --git a/templates/member/profile_detail.html b/templates/member/profile_detail.html index e997b333005d051cd33b371666ff5c6b5fd4d773..31510acfb8f8d71511880fa3126cb62f0665dcf5 100644 --- a/templates/member/profile_detail.html +++ b/templates/member/profile_detail.html @@ -10,7 +10,7 @@ <img src="{{ object.note.display_image.url }}" class="img-thumbnail mt-2" > </a> </div> - <div class="card-body"> + <div class="card-body" id="profile_infos"> <dl class="row"> <dt class="col-xl-6">{% trans 'name'|capfirst %}, {% trans 'first name' %}</dt> <dd class="col-xl-6">{{ object.last_name }} {{ object.first_name }}</dd> @@ -76,7 +76,9 @@ </a> </div> <div id="historyListCollapse" class="collapse" style="overflow:auto hidden" aria-labelledby="historyListHeading" data-parent="#accordionProfile"> - {% render_table history_list %} + <div id="history_list"> + {% render_table history_list %} + </div> </div> </div> </div> @@ -84,3 +86,12 @@ </div> </div> {% endblock %} + +{% block extrajavascript %} + <script> + function refreshHistory() { + $("#history_list").load("{% url 'member:user_detail' pk=object.pk %} #history_list"); + $("#profile_infos").load("{% url 'member:user_detail' pk=object.pk %} #profile_infos"); + } + </script> +{% endblock %} diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 9bd4919ce13c6682fdb4859f2112012b4eb5bc0b..3925241d440e3884d4045e2d3caddba35ceef3e7 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -145,15 +145,6 @@ </div> {% endblock %} -{% block extracss %} - <style> - .validate:hover { - cursor: pointer; - text-decoration: underline; - } - </style> -{% endblock %} - {% block extrajavascript %} <script type="text/javascript" src="/static/js/consos.js"></script> <script type="text/javascript">