From 888c12e684af7963c06577a5bb3eae739e957aab Mon Sep 17 00:00:00 2001 From: dojutsu-user Date: Sun, 3 Feb 2019 14:30:29 +0530 Subject: [PATCH 1/2] use javascript --- readthedocs/templates/account/email.html | 146 ++++++++++++++--------- 1 file changed, 91 insertions(+), 55 deletions(-) diff --git a/readthedocs/templates/account/email.html b/readthedocs/templates/account/email.html index b56f72ac185..7c0cc3c8a1b 100644 --- a/readthedocs/templates/account/email.html +++ b/readthedocs/templates/account/email.html @@ -9,68 +9,104 @@ {% block edit_content_header %} {% trans "Change Email" %} {% endblock %} {% block edit_content %} -{% if user.emailaddress_set.all %} -

{% trans 'The following email addresses are associated with your account:' %}

- -
-{% csrf_token %} -
- - {% for emailaddress in user.emailaddress_set.all %} -
- -
- {% endfor %} - -
- - - -
+ {% if user.emailaddress_set.all %} +

{% trans 'The following email addresses are associated with your account:' %}

+ + + {% csrf_token %} +
+ + {% for emailaddress in user.emailaddress_set.all %} +
+ +
+ {% endfor %} + +
+ + + +
+ +
+ -
- + {% else %} -{% else %} -

{% trans 'Warning:'%} {% 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." %}

+

{% trans 'Warning:'%}{% 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." %}

-{% endif %} + {% endif %} +

{% trans "Add E-mail Address" %}

-

{% trans "Add E-mail Address" %}

- -
- {% csrf_token %} - {{ form.as_p}} - -
+
+ {% csrf_token %} + {{ form.as_p }} + +
{% endblock %} +{% block footerjs %} + + (function() { + var message = "{% trans 'Do you really want to remove the selected email address?' %}"; + var actions = document.getElementsByName('action_remove'); + if (actions.length) { + actions[0].addEventListener("click", function(e) { + if (! confirm(message)) { + e.preventDefault(); + } + }); + } + })(); + + (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 %} + })(); -{% block extra_body %} - {% endblock %} From 3e8a6426b0c5c9d46d52e87d64b5ffd6595dcb03 Mon Sep 17 00:00:00 2001 From: dojutsu-user Date: Thu, 9 May 2019 17:09:34 +0530 Subject: [PATCH 2/2] small lint fixes --- readthedocs/templates/account/email.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/readthedocs/templates/account/email.html b/readthedocs/templates/account/email.html index 7c0cc3c8a1b..1ae3b42fc42 100644 --- a/readthedocs/templates/account/email.html +++ b/readthedocs/templates/account/email.html @@ -10,7 +10,7 @@ {% block edit_content %} {% if user.emailaddress_set.all %} -

{% trans 'The following email addresses are associated with your account:' %}

+

{% trans "The following email addresses are associated with your account:" %}