nk20/templates/note/conso_form.html

246 lines
11 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">
<div class="row">
{# User details column #}
<div class="col-xl-5">
<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">
<div class="card border-success shadow mb-4">
<div class="card-header">
<p class="card-text font-weight-bold">
Sélection des émitteurs
</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">
2020-03-11 21:51:46 +00:00
<select name="source" data-placeholder="Note ..." data-minimum-input-length="1"
required id="note" data-autocomplete-light-language="fr"
data-autocomplete-light-url="/note/note-autocomplete/"
data-autocomplete-light-function="select2">
<option value="" selected>---------</option>
</select>
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>
</div>
{# Buttons column #}
<div class="col-sm-7 col-md-8">
{# 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-10 07:11:43 +00:00
<button class="btn btn-outline-dark rounded-0 flex-fill"
id="button{{ button.id }}" name="button" value="{{ button.name }}">
2020-03-10 07:11:43 +00:00
{{ 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="options" id="option1" checked>
Consomations simples
</label>
<label class="btn btn-sm btn-outline-primary">
<input type="radio" name="options" id="option2">
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>
<div class="card shadow mb-4">
<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>
.select2-container{
max-width: 100%;
min-width: 100%;
}
</style>
2020-03-11 21:51:46 +00:00
<link href="/static/vendor/select2/dist/css/select2.css" type="text/css" media="screen" rel="stylesheet">
<link href="/static/admin/css/autocomplete.css" type="text/css" media="screen" rel="stylesheet">
<link href="/static/autocomplete_light/select2.css" type="text/css" media="screen" rel="stylesheet">
<script type="text/javascript" src="/static/autocomplete_light/jquery.init.js"></script>
<script type="text/javascript" src="/static/vendor/select2/dist/js/select2.full.js"></script>
<script type="text/javascript" src="/static/vendor/select2/dist/js/i18n/fr.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/autocomplete.init.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/forward.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/select2.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/jquery.post-setup.js"></script>
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-02-21 21:40:58 +00:00
<script type="text/javascript">
2020-03-11 22:35:38 +00:00
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);
}
2020-03-11 21:51:46 +00:00
var consos = [];
2020-02-21 21:40:58 +00:00
$(document).ready(function() {
// If hash of a category in the URL, then select this category
// else select the first one
if (location.hash) {
$("a[href='" + location.hash + "']").tab("show");
} else {
$("a[data-toggle='tab']").first().tab("show");
}
// When selecting a category, change URL
$(document.body).on("click", "a[data-toggle='tab']", function(event) {
location.hash = this.getAttribute("href");
});
2020-03-11 22:35:38 +00:00
let note_obj = $("#note");
note_obj.change(function() {
2020-03-11 21:51:46 +00:00
let name = $("#note option:selected").text();
2020-03-11 22:35:38 +00:00
let note = note_obj.val();
2020-03-11 21:51:46 +00:00
note_obj.val(0);
note_obj.text("");
2020-03-11 22:35:38 +00:00
var conso = null;
consos.forEach(function(c) {
if (c[1] === note) {
c[2] += 1;
conso = c;
}
});
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);
});
2020-03-11 21:51:46 +00:00
});
{% for button in transaction_templates %}
2020-03-11 21:51:46 +00:00
{% if button.display %}
2020-03-11 22:35:38 +00:00
$("#button{{ button.id }}").click(function() {
consos.forEach(function(conso) {
$.post("/api/note/transaction/transaction/",
{
"csrfmiddlewaretoken": "{{ csrf_token }}",
"quantity": conso[2],
"amount": {{ button.amount }},
"reason": "{{ button.name }} ({{ button.category.name }})",
"valid": true,
"polymorphic_ctype": {{ polymorphic_ctype }},
"resourcetype": "TemplateTransaction",
"source": conso[1],
"destination": {{ button.destination.pk }},
"category": {{ button.category.id }},
"template": {{ button.id }}
}, reloadWithTurbolinks);
});
reloadWithTurbolinks();
});
2020-03-11 21:51:46 +00:00
{% endif %}
{% endfor %}
2020-02-21 21:40:58 +00:00
});
var reloadWithTurbolinks = (function () {
var scrollPosition;
function reload () {
scrollPosition = [window.scrollX, window.scrollY];
Turbolinks.visit(window.location.toString(), { action: 'replace' })
}
document.addEventListener('turbolinks:load', function () {
if (scrollPosition) {
window.scrollTo.apply(window, scrollPosition);
scrollPosition = null;
}
});
return reload;
})();
2020-02-21 21:40:58 +00:00
</script>
2020-02-04 00:18:03 +00:00
{% endblock %}