1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-23 16:02:25 +00:00

Multiple select

This commit is contained in:
Yohann D'ANELLO 2020-03-11 22:51:46 +01:00
parent cebbe65eef
commit c4f54d9d5b
3 changed files with 59 additions and 27 deletions

View File

@ -132,6 +132,7 @@ class Transaction(PolymorphicModel):
if self.source.pk == self.destination.pk: if self.source.pk == self.destination.pk:
# When source == destination, no money is transfered # When source == destination, no money is transfered
super().save(*args, **kwargs)
return return
created = self.pk is None created = self.pk is None

View File

@ -18,7 +18,7 @@ class HistoryTable(tables.Table):
} }
model = Transaction model = Transaction
exclude = ("polymorphic_ctype", ) exclude = ("polymorphic_ctype", )
order_by = ('-created_at', ) order_by = ('-id', )
template_name = 'django_tables2/bootstrap4.html' template_name = 'django_tables2/bootstrap4.html'
sequence = ('...', 'total', 'valid') sequence = ('...', 'total', 'valid')

View File

@ -30,18 +30,15 @@
Sélection des émitteurs Sélection des émitteurs
</p> </p>
</div> </div>
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush" id="note_list">
<li class="list-group-item py-1 d-flex justify-content-between align-items-center">
Cras justo odio
<span class="badge badge-dark badge-pill">14</span>
</li>
<li class="list-group-item py-1 d-flex justify-content-between align-items-center">
Dapibus ac facilisis in
<span class="badge badge-dark badge-pill">1</span>
</li>
</ul> </ul>
<div class="card-body"> <div class="card-body">
TODO: reimplement select2 here in JS <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>
</div> </div>
</div> </div>
</div> </div>
@ -83,10 +80,12 @@
<div class="tab-pane" id="{{ category.grouper|slugify }}"> <div class="tab-pane" id="{{ category.grouper|slugify }}">
<div class="d-inline-flex flex-wrap justify-content-center"> <div class="d-inline-flex flex-wrap justify-content-center">
{% for button in category.list %} {% for button in category.list %}
{% if button.display %}
<button class="btn btn-outline-dark rounded-0 flex-fill" <button class="btn btn-outline-dark rounded-0 flex-fill"
id="button{{ button.id }}" name="button" value="{{ button.name }}"> id="button{{ button.id }}" name="button" value="{{ button.name }}">
{{ button.name }} ({{ button.amount | pretty_money }}) {{ button.name }} ({{ button.amount | pretty_money }})
</button> </button>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
@ -131,10 +130,23 @@
min-width: 100%; min-width: 100%;
} }
</style> </style>
<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>
{% endblock %} {% endblock %}
{% block extrajavascript %} {% block extrajavascript %}
<script type="text/javascript"> <script type="text/javascript">
var consos = [];
$(document).ready(function() { $(document).ready(function() {
// If hash of a category in the URL, then select this category // If hash of a category in the URL, then select this category
// else select the first one // else select the first one
@ -149,8 +161,26 @@
location.hash = this.getAttribute("href"); location.hash = this.getAttribute("href");
}); });
$("#note").change(function(obj) {
let name = $("#note option:selected").text();
note_obj = $("#note");
note = note_obj.val();
note_obj.val(0);
note_obj.text("");
consos = consos.concat([[name, note]]);
note_list = $("#note_list");
note_list.html(note_list.html() +
"<li class=\"list-group-item py-1 d-flex justify-content-between align-items-center\">\n" +
" " + name + "\n" +
" <span class=\"badge badge-dark badge-pill\">1</span>\n" +
" </li>");
});
{% for button in transaction_templates %} {% for button in transaction_templates %}
{% if button.display %}
$("#button{{ button.id }}").click(function() { $("#button{{ button.id }}").click(function() {
consos.forEach(function(conso) {
console.log(conso);
$.post("/api/note/transaction/transaction/", $.post("/api/note/transaction/transaction/",
{ {
"csrfmiddlewaretoken": "{{ csrf_token }}", "csrfmiddlewaretoken": "{{ csrf_token }}",
@ -160,15 +190,16 @@
"valid": true, "valid": true,
"polymorphic_ctype": {{ polymorphic_ctype }}, "polymorphic_ctype": {{ polymorphic_ctype }},
"resourcetype": "TemplateTransaction", "resourcetype": "TemplateTransaction",
"source": 6, "source": conso[1],
"destination": 7, "destination": {{ button.destination.pk }},
"category": {{ button.category.id }}, "category": {{ button.category.id }},
"template": {{ button.id }} "template": {{ button.id }}
}, }, reloadWithTurbolinks);
function(data, status) { });
reloadWithTurbolinks(); reloadWithTurbolinks();
}); });
}); {% endif %}
{% endfor %} {% endfor %}
}); });