use javascript
{% for emailaddress in user.emailaddress_set.all %}
<div class="ctrlHolder">
<label 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 }}
</form>
{% else %}
+
<p><strong>{% trans 'Warning:'%}</strong>{% trans "You currently do not have any email address set up. You should really add an email address so you can receive notifications, reset your password, etc." %}</p>
{% endif %}
-
<h2>{% trans "Add E-mail Address" %}</h2>
<form method="post" action="{% url 'account_email' %}" class="add_email">
{% endblock %}
+{% block footerjs %}
-{% block extra_body %}
-<script type="text/javascript">
(function() {
var message = "{% trans 'Do you really want to remove the selected email address?' %}";
var actions = document.getElementsByName('action_remove');
});
}
})();
-</script>
+
+ (function() {
+ var primaryButton = document.querySelector("button[name=action_primary]");
+ var sendVerificationButton = document.querySelector("button[name=action_send");
+
+ {% if user.emailaddress_set.all %}
+ {% for emailaddress in user.emailaddress_set.all %}
+ var email_{{ forloop.counter }} = document.querySelector("input[value='{{ emailaddress.email }}']")
+ if (email_{{ forloop.counter }}.checked == true) {
+ {% if emailaddress.primary %}
+ primaryButton.style.display = 'None';
+ {% else %}
+ primaryButton.style.display = 'block';
+ {% endif %}
+ {% if emailaddress.verified %}
+ sendVerificationButton.style.display = 'None';
+ {% else %}
+ sendVerificationButton.style.display = 'block';
+ primaryButton.style.display = 'None';
+ {% endif %}
+ }
+
+ email_{{ forloop.counter }}.addEventListener('change', function() {
+ {% if emailaddress.primary %}
+ primaryButton.style.display = 'None';
+ {% else %}
+ primaryButton.style.display = 'block';
+ {% endif %}
+ {% if emailaddress.verified %}
+ sendVerificationButton.style.display = 'None';
+ {% else %}
+ sendVerificationButton.style.display = 'block';
+ primaryButton.style.display = 'None';
+ {% endif %}
+ })
+ {% endfor %}
+ {% endif %}
+ })();
+
{% endblock %}
