core: add macro that selects/unselect all checkbox

This commit is contained in:
2019-04-22 14:59:32 +02:00
parent 96e33815f5
commit 2ae10ee2fb
3 changed files with 36 additions and 10 deletions

View File

@ -1,4 +1,5 @@
{% extends "core/base.jinja" %}
{% from "core/macros.jinja" import select_all_checkbox %}
{% block title %}
{% trans %}Group detail{% endtrans %}
@ -11,6 +12,8 @@
<p>{% trans %}No user in this group{% endtrans %}</p>
{% else %}
<form action="{{ url('core:group_detail', object.id) }}" method="post" id="add_users">
{{ select_all_checkbox("add_users") }}
<hr>
{% csrf_token %}
<label for="{{ form.users_removed.id_for_label }}">{{ form.users_removed.label }} :</label>
{{ form.users_removed.errors }}

View File

@ -132,3 +132,18 @@
<span class="disabled">{% trans %}Next{% endtrans %}</span>
{% endif %}
{% endmacro %}
{% macro select_all_checkbox(form_id) %}
<script type="text/javascript">
function checkbox_{{form_id}}(value) {
list = document.getElementById("{{ form_id }}").getElementsByTagName("input");
for (let element of list){
if (element.type == "checkbox"){
element.checked = value;
}
}
}
</script>
<button type="button" onclick="checkbox_{{form_id}}(true);">{% trans %}Select All{% endtrans %}</button>
<button type="button" onclick="checkbox_{{form_id}}(false);">{% trans %}Unselect All{% endtrans %}</button>
{% endmacro %}