.
This commit is contained in:
@@ -1,15 +1,124 @@
|
||||
{% extends 'generic/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
Attempted to send {{users_count}} emails.
|
||||
{{users_count}} emails to send.
|
||||
|
||||
<h2>Emails to send:</h2>
|
||||
<div class="sending"><div class="lds-ripple"><div></div><div></div></div> Emailing <span id="active-email"></span></div>
|
||||
<ul id="user-list">
|
||||
{% for user in users %}
|
||||
<li data-email={{user.email}} data-posturl='{{user.get_email_results_url}}'>{{user.cid}}/{{user.name}}: {{user.email}} [{{user.supervisor_email}}] </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<button id="send-emails">Send emails</button>
|
||||
|
||||
<script>
|
||||
$('document').ready(() => {
|
||||
|
||||
$("#send-emails").click(() => {
|
||||
//$("#user-list li").each((n, el) => {
|
||||
// console.log(n, el);
|
||||
//})
|
||||
li_list = $("#user-list li").get();
|
||||
sendEmail(li_list);
|
||||
});
|
||||
})
|
||||
|
||||
function sendEmail(li_list) {
|
||||
//console.log(li_list)
|
||||
$(".sending").show()
|
||||
li = li_list.shift();
|
||||
//console.log(li)
|
||||
url = li.dataset.posturl;
|
||||
|
||||
$("#active-email").text(li.dataset.email)
|
||||
|
||||
console.log(url)
|
||||
|
||||
$.get(url, function(data, status) {
|
||||
if (status == "success") {
|
||||
if (data.sent) {
|
||||
$(li).append("Email Sent");
|
||||
$(li).addClass("email-sent");
|
||||
} else {
|
||||
$(li).append(`Error ${data.comment}`);
|
||||
$(li).addClass("email-error");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$(li).append(`Error ${status}`);
|
||||
$(li).addClass("email-error");
|
||||
|
||||
}
|
||||
|
||||
}).fail(function(jqXHR, textStatus, errorThrown) {
|
||||
$(li).append(`Error ${textStatus} / ${errorThrown}`);
|
||||
$(li).addClass("email-error");
|
||||
}).always(() => {
|
||||
if (li_list.length > 0) {
|
||||
sendEmail(li_list)
|
||||
} else {
|
||||
$(".sending").hide()
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
<style>
|
||||
.email-sent {
|
||||
color: purple;
|
||||
}
|
||||
.email-error {
|
||||
color: red;
|
||||
}
|
||||
.sending {
|
||||
display: none;
|
||||
color: darkblue;
|
||||
font-size: larger;
|
||||
|
||||
}
|
||||
|
||||
.lds-ripple {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
}
|
||||
.lds-ripple div {
|
||||
position: absolute;
|
||||
border: 4px solid blue;
|
||||
opacity: 1;
|
||||
border-radius: 50%;
|
||||
animation: lds-ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
|
||||
}
|
||||
.lds-ripple div:nth-child(2) {
|
||||
animation-delay: -0.5s;
|
||||
}
|
||||
@keyframes lds-ripple {
|
||||
0% {
|
||||
top: 36px;
|
||||
left: 36px;
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<h2>Emails sent:</h2>
|
||||
{% for u in sent %}
|
||||
<p>{{u.cid}}: {{u.email}}</p>
|
||||
{% endfor %}
|
||||
|
||||
<h2>Emails not sent:</h2>
|
||||
{% for u, msg in not_sent %}
|
||||
<p>{{u.cid}}: {{u.email}} [{{msg}}]</p>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user