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

{% load url from future %}
{% load i18n %}
{% load bootstrap %}

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

{% block account_nav_email %}active{% endblock %}

{% block account_content %}

{% if user.emailaddress_set.all %}
<p>{% trans 'The following e-mail addresses are associated to your account:' %}</p>
    
<form action="{% url 'account_email' %}" class="email_list uniForm" method="post">
{% csrf_token %}

<table class="table">
  <thead>
    <tr>
      <th>
	{% trans 'E-mail' %}
      </th>
      <th>
	{% trans 'Status' %}
      </th>
    </tr>
  </thead>
  <tbody>
    {% for emailaddress in user.emailaddress_set.all %}
    <tr>
      <td>
        <label class="radio" for="email_radio_{{forloop.counter}}" class="{% if emailaddress.primary %}primary_email{%endif%}">
  	<input id="email_radio_{{forloop.counter}}" type="radio" name="email" {% if emailaddress.primary %}checked="checked"{%endif %} value="{{emailaddress.email}}"/>
  	{{ emailaddress.email }}
        </label>
      </td>
      <td>
        {% if emailaddress.verified %}
        <span class="label label-info">{% trans "Verified" %}</span>
        {% else %}
        <span class="label label-warning">{% trans "Unverified" %}</span>
        {% endif %}
        {% if emailaddress.primary %}<span class="label label-success">{% trans "Primary" %}</span>{% endif %}
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>

<div class="form-actions">
      <button class="btn btn-success" type="submit" name="action_primary" >{% trans 'Make Primary' %}</button>
      <button class="btn" type="submit" name="action_send" >{% trans 'Re-send Verification' %}</button>
      <button class="btn btn-danger" type="submit" name="action_remove" >{% trans 'Remove' %}</button>
</div>

</fieldset>
</form>

{% else %} 
<p><strong>{% trans 'Warning:'%}</strong> {% trans "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}</p>

{% endif %}


    <h2>{% trans "Add E-mail Address" %}</h2>
    
    <form method="post" action="" class="form-horizontal">
        {% csrf_token %}
        {{ add_email_form|bootstrap_horizontal }}
        <div class="form-actions">
          <button class="btn btn-primary" name="action_add" type="submit">{% trans "Add E-mail" %}</button>
        </div>
    </form>
    
{% endblock %}


{% block extra_body %}
<script type="text/javascript">
$(function(){
$("button[name='action_remove']").click(function(){
if (confirm("{% trans 'Do you really want to remove the selected e-mail address?' %}")) {
return true;
}
return false;
});
});
</script>
{% endblock %}
