nk20/templates/note/conso_form.html

222 lines
9.1 KiB
HTML
Raw Normal View History

2020-02-04 00:18:03 +00:00
{% extends "base.html" %}
2020-03-10 07:07:09 +00:00
{% load i18n static pretty_money django_tables2 %}
2020-02-04 00:18:03 +00:00
2020-02-21 21:40:58 +00:00
{# Remove page title #}
{% block contenttitle %}{% endblock %}
2020-02-04 00:18:03 +00:00
{% block content %}
2020-03-10 07:11:43 +00:00
<div class="row mt-4">
<div class="col-sm-5 col-md-4" id="infos_div">
2020-03-10 07:11:43 +00:00
<div class="row">
{# User details column #}
<div class="col-xl-5" id="note_infos_div">
2020-03-10 07:11:43 +00:00
<div class="card border-success shadow mb-4">
2020-03-11 22:35:38 +00:00
<img src="/media/pic/default.png"
id="profile_pic" alt="" class="img-fluid rounded mx-auto d-block">
2020-03-10 07:11:43 +00:00
<div class="card-body text-center">
2020-03-11 22:35:38 +00:00
<span id="user_note"></span>
2020-02-21 21:40:58 +00:00
</div>
</div>
2020-03-10 07:11:43 +00:00
</div>
2020-02-21 21:40:58 +00:00
2020-03-10 07:11:43 +00:00
{# User selection column #}
<div class="col-xl-7" id="user_select_div">
2020-03-10 07:11:43 +00:00
<div class="card border-success shadow mb-4">
<div class="card-header">
<p class="card-text font-weight-bold">
2020-03-12 15:53:35 +00:00
Sélection des émetteurs
2020-03-10 07:11:43 +00:00
</p>
</div>
2020-03-11 21:51:46 +00:00
<ul class="list-group list-group-flush" id="note_list">
2020-02-21 21:40:58 +00:00
</ul>
2020-03-10 07:11:43 +00:00
<div class="card-body">
<input class="form-control mx-auto d-block" type="text" id="note" />
2020-03-12 00:10:52 +00:00
<ul class="list-group list-group-flush" id="alias_matched">
</ul>
2020-03-10 07:11:43 +00:00
</div>
2020-02-21 21:40:58 +00:00
</div>
2020-03-10 07:11:43 +00:00
</div>
<div class="col-xl-5" id="consos_list_div">
<div class="card border-info shadow mb-4">
<div class="card-header">
<p class="card-text font-weight-bold">
Sélection des consommations
</p>
</div>
<ul class="list-group list-group-flush" id="consos_list">
</ul>
2020-03-13 00:34:20 +00:00
<button id="consume_all" class="form-control btn btn-primary">Consommer !</button>
</div>
</div>
2020-03-10 07:11:43 +00:00
</div>
</div>
{# Buttons column #}
<div class="col-sm-7 col-md-8" id="buttons_div">
2020-03-10 07:11:43 +00:00
{# Show last used buttons #}
<div class="card shadow mb-4">
<div class="card-body text-nowrap" style="overflow:auto hidden">
<p class="card-text text-muted font-weight-light font-italic">
Les boutons les plus utilisés s'afficheront ici.
</p>
</div>
</div>
{# Regroup buttons under categories #}
{% regroup transaction_templates by category as categories %}
2020-02-21 21:40:58 +00:00
2020-03-10 07:11:43 +00:00
<div class="card border-primary text-center shadow mb-4">
{# Tabs for button categories #}
<div class="card-header">
<ul class="nav nav-tabs nav-fill card-header-tabs">
{% for category in categories %}
2020-03-10 07:11:43 +00:00
<li class="nav-item">
<a class="nav-link font-weight-bold" data-toggle="tab" href="#{{ category.grouper|slugify }}">
{{ category.grouper }}
2020-03-10 07:11:43 +00:00
</a>
</li>
{% endfor %}
</ul>
</div>
{# Tabs content #}
<div class="card-body">
<div class="tab-content">
{% for category in categories %}
<div class="tab-pane" id="{{ category.grouper|slugify }}">
2020-03-10 07:11:43 +00:00
<div class="d-inline-flex flex-wrap justify-content-center">
{% for button in category.list %}
2020-03-11 21:51:46 +00:00
{% if button.display %}
2020-03-12 00:10:52 +00:00
<button class="btn btn-outline-dark rounded-0 flex-fill"
id="button{{ button.id }}" name="button" value="{{ button.name }}">
{{ button.name }} ({{ button.amount | pretty_money }})
</button>
2020-03-11 21:51:46 +00:00
{% endif %}
2020-03-10 07:11:43 +00:00
{% endfor %}
2020-02-21 21:40:58 +00:00
</div>
2020-03-10 07:11:43 +00:00
</div>
{% endfor %}
</div>
</div>
{# Mode switch #}
<div class="card-footer border-primary">
<a class="btn btn-sm btn-secondary float-left" href="{% url 'note:template_list' %}">
<i class="fa fa-edit"></i> Éditer
</a>
<div class="btn-group btn-group-toggle float-right" data-toggle="buttons">
<label class="btn btn-sm btn-outline-primary active">
<input type="radio" name="conso_type" id="single_conso" checked>
2020-03-10 07:11:43 +00:00
Consomations simples
</label>
<label class="btn btn-sm btn-outline-primary">
<input type="radio" name="conso_type" id="double_conso">
2020-03-10 07:11:43 +00:00
Consomations doubles
</label>
2020-02-04 00:18:03 +00:00
</div>
</div>
2020-02-21 21:40:58 +00:00
</div>
</div>
2020-03-10 07:11:43 +00:00
</div>
2020-03-12 09:53:06 +00:00
<div class="card shadow mb-4" id="history">
2020-03-10 07:11:43 +00:00
<div class="card-header">
<p class="card-text font-weight-bold">
Historique des transactions récentes
</p>
</div>
{% render_table table %}
</div>
{% endblock %}
{% block extracss %}
<style>
2020-03-14 01:08:23 +00:00
.validate:hover {
cursor: pointer;
text-decoration: underline;
2020-03-10 07:11:43 +00:00
}
</style>
2020-02-22 09:17:24 +00:00
{% endblock %}
2020-02-21 21:40:58 +00:00
2020-02-22 09:17:24 +00:00
{% block extrajavascript %}
2020-03-12 15:53:35 +00:00
<script type="text/javascript" src="/static/js/consos.js"></script>
2020-02-21 21:40:58 +00:00
<script type="text/javascript">
2020-03-14 01:08:23 +00:00
// Switching in double consumptions mode should update the layout
$("#double_conso").click(function() {
$("#consos_list_div").show();
$("#infos_div").attr('class', 'col-sm-5 col-xl-6');
$("#note_infos_div").attr('class', 'col-xl-3');
$("#user_select_div").attr('class', 'col-xl-4');
$("#buttons_div").attr('class', 'col-sm-7 col-xl-6');
2020-03-13 08:26:39 +00:00
if (buttons.length > 0) {
let note_list_obj = $("#note_list");
$("#consos_list").html(note_list_obj.html());
note_list_obj.html("");
}
});
$("#single_conso").click(function() {
$("#consos_list_div").hide();
$("#infos_div").attr('class', 'col-sm-5 col-md-4');
$("#note_infos_div").attr('class', 'col-xl-5');
$("#user_select_div").attr('class', 'col-xl-7');
$("#buttons_div").attr('class', 'col-sm-7 col-md-8');
2020-03-13 08:26:39 +00:00
if (buttons.length > 0) {
if (notes_display.length === 0) {
let consos_list_obj = $("#consos_list");
$("#note_list").html(consos_list_obj.html());
consos_list_obj.html("");
}
else {
buttons.length = 0;
$("#consos_list").html("");
}
}
});
$("#consos_list_div").hide();
2020-03-13 00:34:20 +00:00
$("#consume_all").click(consumeAll);
2020-03-12 15:53:35 +00:00
{% for button in transaction_templates %}
{% if button.display %}
$("#button{{ button.id }}").click(function() {
addConso({{ button.destination.id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category.id }}, "{{ button.category.name }}",
{{ button.id }}, "{{ button.name }}");
2020-03-11 22:35:38 +00:00
});
2020-03-12 15:53:35 +00:00
{% endif %}
{% endfor %}
2020-03-14 01:08:23 +00:00
// 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");
// 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();
}
2020-03-14 01:08:23 +00:00
});
});
2020-02-21 21:40:58 +00:00
</script>
2020-02-04 00:18:03 +00:00
{% endblock %}