{% extends "layout.html" %}
{% block content %}
<h1>Přehled ignorovaných dárců</h1>
{% with form=ignore_form %}

<form id="ignoreDonorForm" action="{{ url_for('donor.ignore_donor') }}" method="POST" class="form-inline mb-md-3" role="form">
{{ form.csrf_token }}
    {{ form.rodne_cislo(placeholder="Rodné číslo", class_="form-control mr-sm-2 my-auto") }} {{ form.reason(placeholder="Důvod ignorace",
    class_="form-control mr-sm-2 my-auto") }}
    <button class="btn btn-success" type="submit">Ignorovat</button>
</form>

{% endwith %}

<table id="ignored" class="table table-striped table-hovered table-hover">
    <thead class="thead-dark">
        <tr>
            <th scope="col">Rodné číslo</th>
            <th scope="col">Důvod ignorace</th>
            <th scope="col">Ignorováno od</th>
            <th scope="col">Přestat ignorovat</th>
        </tr>
    </thead>
    <tbody>
        {% for donor in ignored %}
        <tr>
            <td>{{ donor.rodne_cislo }}</td>
            <td>{{ donor.reason }}</td>
            <td>{{ donor.ignored_since|format_time }}</td>
            <td>
                {% with form=unignore_form %}
                <form id="unignoreDonorForm_{{ donor.rodne_cislo }}" action="{{ url_for('donor.unignore_donor') }}" method="POST"
                    class="form-inline" role="form">
                    <div class="form-group">
                        {{ form.csrf_token }}
                        {{ form.rodne_cislo(value=donor.rodne_cislo, id="rodne_cislo_" ~ donor.rodne_cislo) }}
                        <input type="submit" class="btn btn-sm btn-danger" value="🗑">
                    </div>
                </form>
                {% endwith %}
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>

{% endblock %}

{% block js %}
<script type="text/javascript">
    $(document).ready( function () {
        $.fn.dataTable.ext.order.intl('cs-CZ');

        $('#ignored').DataTable({
            stateSave: true,
            stateDuration: -1, // -1 means session storage in the current browser window
            language: {
                url: '//cdn.datatables.net/plug-ins/1.10.21/i18n/Czech.json'
            },
            lengthMenu: [
                [10, 25, 50, 100, -1],
                [10, 25, 50, 100, 'Všechny']
            ],
        });
    });
</script>
{% endblock %}
