{% extends postorius_base_template %}
{% load i18n %}
{% load bootstrap_tags %}
{% load nav_helpers %}

{% block subtitle %}
{% trans 'Banned addresses' %} | {{ list.fqdn_listname }}
{% endblock %}

{% block main %}

    {% list_nav 'list_bans' 'Banned addresses' %}

    <!-- Add ban -->
    <form action="{% url 'list_bans' list.list_id %}" method="POST" class="form-inline bans-add-form">
        {% csrf_token %}
        <div class="form-group {% if addban_form.email.errors %}has-error{% endif %}">
            {% if addban_form.email.errors %}
                <div class="alert alert-danger">{{ addban_form.email.errors }}</div>
            {% endif %}
            {{ addban_form.email.label_tag }}
            {{ addban_form.email|add_form_control }}
        </div>
        <div class="form-group">
            <button class="btn btn-primary" type="submit" name="add">{% trans 'Ban email' %}</button>
        </div>
        <p id="help-{{ addban_form.email.id_for_label }}" class="help-block">
            {{ addban_form.email.help_text }}
        </p>
    </form>

    <!-- Unban -->
    <h4>{% trans 'Currently banned addresses' %}</h4>

    {% with list_bans=list.bans %}

    {% if list_bans|length > 0 %}
    <table class="table bans-current">
        <tbody>
            {% for ban in list.bans %}
            <tr>
                <td>{{ ban.email }}</td>
                <td>
                <form action="{% url 'list_bans' list.list_id %}" method="POST">
                    {% csrf_token %}
                    <input type="hidden" name="email" value="{{ ban.email }}" />
                    <button class="btn btn-danger btn-xs" type="submit" name="del"
                            title="{% trans 'Un-ban this address' %}">
                        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                    </button>
                </form>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% else %}
    <p>{% trans 'No addresses are currently banned.' %}</p>
    {% endif %}

    {% endwith %}

{% endblock %}

