1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Update note infos

This commit is contained in:
Yohann D'ANELLO 2020-03-11 23:35:38 +01:00
parent c4f54d9d5b
commit f748f533b2

View File

@ -12,12 +12,10 @@
{# User details column #} {# User details column #}
<div class="col-xl-5"> <div class="col-xl-5">
<div class="card border-success shadow mb-4"> <div class="card border-success shadow mb-4">
<img src="https://perso.crans.org/erdnaxe/site-crans/img/logo.svg" <img src="/media/pic/default.png"
alt="" class="img-fluid rounded mx-auto d-block"> id="profile_pic" alt="" class="img-fluid rounded mx-auto d-block">
<div class="card-body text-center"> <div class="card-body text-center">
<span id="user_note"> <span id="user_note"></span>
Paquito (aka. PAC) : -230 €
</span>
</div> </div>
</div> </div>
</div> </div>
@ -145,6 +143,13 @@
{% block extrajavascript %} {% block extrajavascript %}
<script type="text/javascript"> <script type="text/javascript">
function pretty_money(value) {
if (value % 100 === 0)
return (value < 0 ? "- " : "") + Math.round(Math.abs(value) / 100) + " ";
else
return (value < 0 ? "- " : "") + Math.round(Math.abs(value) / 100) + " " + (Math.abs(value) % 100);
}
var consos = []; var consos = [];
$(document).ready(function() { $(document).ready(function() {
@ -161,30 +166,46 @@
location.hash = this.getAttribute("href"); location.hash = this.getAttribute("href");
}); });
$("#note").change(function(obj) { let note_obj = $("#note");
note_obj.change(function() {
let name = $("#note option:selected").text(); let name = $("#note option:selected").text();
note_obj = $("#note"); let note = note_obj.val();
note = note_obj.val();
note_obj.val(0); note_obj.val(0);
note_obj.text(""); note_obj.text("");
consos = consos.concat([[name, note]]); var conso = null;
note_list = $("#note_list"); consos.forEach(function(c) {
note_list.html(note_list.html() + if (c[1] === note) {
"<li class=\"list-group-item py-1 d-flex justify-content-between align-items-center\">\n" + c[2] += 1;
" " + name + "\n" + conso = c;
" <span class=\"badge badge-dark badge-pill\">1</span>\n" + }
" </li>"); });
if (conso == null)
consos = consos.concat([[name, note, 1]]);
let note_list = $("#note_list");
var html = "";
consos.forEach(function(conso) {
html += "<li class=\"list-group-item py-1 d-flex justify-content-between align-items-center\">" + conso[0] + "<span class=\"badge badge-dark badge-pill\">" + conso[2] + "</span></li>\n";
});
note_list.html(html);
$.getJSON("/api/note/note/" + note + "/?format=json", function(note) {
console.log(note);
$("#user_note").text(name + " : " + pretty_money(note.balance));
if (note.display_image == null)
$("#profile_pic").attr('src', '/media/pic/default.png');
else
$("#profile_pic").attr('src', note.display_image);
});
}); });
{% for button in transaction_templates %} {% for button in transaction_templates %}
{% if button.display %} {% if button.display %}
$("#button{{ button.id }}").click(function() { $("#button{{ button.id }}").click(function() {
consos.forEach(function(conso) { consos.forEach(function(conso) {
console.log(conso);
$.post("/api/note/transaction/transaction/", $.post("/api/note/transaction/transaction/",
{ {
"csrfmiddlewaretoken": "{{ csrf_token }}", "csrfmiddlewaretoken": "{{ csrf_token }}",
"quantity": 1, "quantity": conso[2],
"amount": {{ button.amount }}, "amount": {{ button.amount }},
"reason": "{{ button.name }} ({{ button.category.name }})", "reason": "{{ button.name }} ({{ button.category.name }})",
"valid": true, "valid": true,