{% extends "account/base.html" %}

{% load i18n %}
{% load bootstrap_tags %}

{% block head_title %}{% trans "Account" %}{% endblock %}

{% block body %}
    <h2>{% trans "Email Addresses" %}</h2>
    
    {% if user.emailaddress_set.all %}
        <table class="zebra-striped">
            {% for emailaddress in user.emailaddress_set.all %}
                <tr>
                    <td>{% if emailaddress.primary %}<b>{{ emailaddress.email }}</b>{% else %}{{ emailaddress.email }}{% endif %}</td>
                    {% if emailaddress.verified %}
                        <td>
                            <span class="verified">{% trans "verified" %}</span>
                            {% if emailaddress.primary %}
                                - <span class="primary">{% trans "primary" %}</span>
                            {% else %}
                                <form style="display: none;" id="primary_{{ forloop.counter }}" method="post" action="">
                                    {% csrf_token %}
                                    <input type="hidden" name="email" value="{{ emailaddress.email }}"/>
                                    <input type="hidden" name="action" value="primary"/>
                                </form>
                                -
                                <a href="#" onclick="$('#primary_{{ forloop.counter }}').submit();">{% trans "make primary" %}</a>
                            {% endif %}
                        </td>
                    {% else %}
                        <td>
                            <span class="unverified">{% trans "unverified" %}</span>
                            <form style="display: none;" id="send_{{ forloop.counter }}" method="post" action="">
                                {% csrf_token %}
                                <input type="hidden" name="email" value="{{ emailaddress.email }}"/>
                                <input type="hidden" name="action" value="send"/>
                            </form>
                            -
                            <a href="#" onclick="$('#send_{{ forloop.counter }}').submit();">{% trans "re-send verification email" %}</a>
                        </td>
                    {% endif %}
                    <td>
                        {% if emailaddress.primary %}
                        {% else %}
                            <form style="display: none;" id="remove_{{ forloop.counter }}" method="post" action="">
                                {% csrf_token %}
                                <input type="hidden" name="email" value="{{ emailaddress.email }}"/>
                                <input type="hidden" name="action" value="remove"/>
                            </form>
                            <a class="remove" href="#" onclick="$('#remove_{{ forloop.counter }}').submit()">{% trans "remove" %}</a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </table>
    {% else %} {# no user.emailaddress_set.all #}
        <div class="alert-message warning">
            <p>{% trans "You should really add an email address so you can receive notifications, reset your password if you forget it, etc." %}</p>
        </div>
    {% endif %}
    
    <h3>{% trans "Add Email Address" %}</h3>
    
    <form method="post" action="" autocapitalize="off">
        {% csrf_token %}
        <fieldset>
            {{ add_email_form|as_bootstrap }}
        </fieldset>
        <input type="hidden" name="action" value="add"/>
         <div class="actions">
             <button type="submit" class="btn primary">{% trans "add" %}</button>
        </div>
    </form>
    
{% endblock %}
