{% extends "pretixcontrol/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% block title %}{% trans "Notification settings" %}{% endblock %}
{% block content %}
    <h1>{% trans "Notification settings" %}</h1>
    <form method="post">
        {% csrf_token %}
        <fieldset>
            {% if request.user.notifications_send %}
                <div class="alert alert-info">
                    <button name="notifications_send" value="off" type="submit" class="pull-right flip btn btn-default">
                        <span class="fa fa-bell-slash"></span>
                        {% trans "Disable" %}
                    </button>
                    {% trans "Notifications are turned on according to the settings below." %}
                    <div class="clearfix"></div>
                </div>
            {% else %}
                <div class="alert alert-warning">
                    <button name="notifications_send" value="on" type="submit" class="pull-right flip btn btn-default">
                        <span class="fa fa-bell"></span>
                        {% trans "Enable" %}
                    </button>
                    {% trans "All notifications are turned off globally." %}
                    <div class="clearfix"></div>
                </div>
            {% endif %}
        </fieldset>
    </form>
    <form class="form-inline" method="get">
        <fieldset>
            <legend>{% trans "Choose event" %}</legend>
            <p>
                <select name="event" class="form-control simple-subevent-choice"
                    data-model-select2="event"
                    data-placeholder="{% trans "All my events" %}"
                    data-select2-url="{% url "control:events.typeahead" %}">
                    {% if event %}
                        <option value="{{ event.pk }}" selected>
                            {{ event.name }}
                        </option>
                    {% endif %}
                </select>
                <span class="help-block">{% trans "Save your modifications before switching events." %}</span>
            </p>
        </fieldset>
    </form>
    <form method="post">
        {% csrf_token %}
        <fieldset>
            <legend>{% trans "Choose notifications to get" %}</legend>
            <table class="table">
                <thead>
                <tr>
                    <th>{% trans "Notification type" %}</th>
                    <th class="text-center">{% trans "E-Mail notification" %}</th>
                </tr>
                </thead>
                <tbody>
                {% for type, enabled, global in types %}
                    <tr>
                        <td>
                            {{ type.verbose_name }}
                        </td>
                        <td class="text-center">
                            {% if not event or type.required_permission in permset %}
                                <select name="mail:{{ type.action_type }}" class="form-control">
                                    {% if event %}
                                        <option value="global">{% trans "Global" %} ({% if global.mail %}{% trans "On" %}{% else %}{% trans "Off" %}{% endif %})</option>{% endif %}
                                    <option value="off" {% if "mail" in enabled and enabled.mail == False %}selected{% endif %}>{% trans "Off" %}</option>
                                    <option value="on" {% if enabled.mail %}selected{% endif %}>{% trans "On" %}</option>
                                </select>
                            {% else %}
                                <span class="fa fa-lock" data-toggle="tooltip" title="{% trans "You have no permission to receive this notification" %}"></span>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </fieldset>
        <div class="form-group submit-group">
            <button type="submit" class="btn btn-primary btn-save">
                {% trans "Save" %}
            </button>
        </div>
    </form>
{% endblock %}
