mirror of https://gitlab.crans.org/bde/nk20
Validation/devalidation of a transaction on profile page
This commit is contained in:
parent
da12733508
commit
a1f37f0eea
|
@ -124,7 +124,7 @@ class UserDetailView(LoginRequiredMixin, DetailView):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
user = context['user_object']
|
user = context['user_object']
|
||||||
history_list = \
|
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)
|
context['history_list'] = HistoryTable(history_list)
|
||||||
club_list = \
|
club_list = \
|
||||||
Membership.objects.all().filter(user=user).only("club")
|
Membership.objects.all().filter(user=user).only("club")
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -177,31 +177,3 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
|
||||||
refreshBalance();
|
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -53,6 +53,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
{{ form.media }}
|
{{ form.media }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.validate:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
{% block extracss %}{% endblock %}
|
{% block extracss %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body class="d-flex w-100 h-100 flex-column">
|
<body class="d-flex w-100 h-100 flex-column">
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<img src="{{ object.note.display_image.url }}" class="img-thumbnail mt-2" >
|
<img src="{{ object.note.display_image.url }}" class="img-thumbnail mt-2" >
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body" id="profile_infos">
|
||||||
<dl class="row">
|
<dl class="row">
|
||||||
<dt class="col-xl-6">{% trans 'name'|capfirst %}, {% trans 'first name' %}</dt>
|
<dt class="col-xl-6">{% trans 'name'|capfirst %}, {% trans 'first name' %}</dt>
|
||||||
<dd class="col-xl-6">{{ object.last_name }} {{ object.first_name }}</dd>
|
<dd class="col-xl-6">{{ object.last_name }} {{ object.first_name }}</dd>
|
||||||
|
@ -76,11 +76,22 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="historyListCollapse" class="collapse" style="overflow:auto hidden" aria-labelledby="historyListHeading" data-parent="#accordionProfile">
|
<div id="historyListCollapse" class="collapse" style="overflow:auto hidden" aria-labelledby="historyListHeading" data-parent="#accordionProfile">
|
||||||
|
<div id="history_list">
|
||||||
{% render_table history_list %}
|
{% render_table history_list %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% 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 %}
|
||||||
|
|
|
@ -145,15 +145,6 @@
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extracss %}
|
|
||||||
<style>
|
|
||||||
.validate:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block extrajavascript %}
|
{% block extrajavascript %}
|
||||||
<script type="text/javascript" src="/static/js/consos.js"></script>
|
<script type="text/javascript" src="/static/js/consos.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
Loading…
Reference in New Issue