mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Cleanup + send email logic
This commit is contained in:
parent
9b23262d61
commit
1ce0724d34
4 changed files with 13 additions and 81 deletions
|
@ -344,69 +344,6 @@ function initializeWidgetOnList(list, parentId) {
|
|||
}
|
||||
}
|
||||
|
||||
/** An IIFE for admin in DjangoAdmin to listen to changes on the domain request
|
||||
* status select and to show/hide the rejection reason
|
||||
*/
|
||||
(function (){
|
||||
let rejectionReasonFormGroup = document.querySelector('.field-rejection_reason');
|
||||
// This is the "action needed reason" field
|
||||
let actionNeededReasonFormGroup = document.querySelector('.field-action_needed_reason');
|
||||
// This is the "Email" field
|
||||
let actionNeededReasonEmailFormGroup = document.querySelector('.field-action_needed_reason_email')
|
||||
|
||||
if (rejectionReasonFormGroup && actionNeededReasonFormGroup && actionNeededReasonEmailFormGroup) {
|
||||
let statusSelect = document.getElementById('id_status')
|
||||
let isRejected = statusSelect.value == "rejected"
|
||||
let isActionNeeded = statusSelect.value == "action needed"
|
||||
|
||||
// Initial handling of rejectionReasonFormGroup display
|
||||
showOrHideObject(rejectionReasonFormGroup, show=isRejected)
|
||||
showOrHideObject(actionNeededReasonFormGroup, show=isActionNeeded)
|
||||
showOrHideObject(actionNeededReasonEmailFormGroup, show=isActionNeeded)
|
||||
|
||||
// Listen to change events and handle rejectionReasonFormGroup display, then save status to session storage
|
||||
statusSelect.addEventListener('change', function() {
|
||||
// Show the rejection reason field if the status is rejected.
|
||||
// Then track if its shown or hidden in our session cache.
|
||||
isRejected = statusSelect.value == "rejected"
|
||||
showOrHideObject(rejectionReasonFormGroup, show=isRejected)
|
||||
addOrRemoveSessionBoolean("showRejectionReason", add=isRejected)
|
||||
|
||||
isActionNeeded = statusSelect.value == "action needed"
|
||||
showOrHideObject(actionNeededReasonFormGroup, show=isActionNeeded)
|
||||
showOrHideObject(actionNeededReasonEmailFormGroup, show=isActionNeeded)
|
||||
addOrRemoveSessionBoolean("showActionNeededReason", add=isActionNeeded)
|
||||
});
|
||||
|
||||
// Listen to Back/Forward button navigation and handle rejectionReasonFormGroup display based on session storage
|
||||
|
||||
// When you navigate using forward/back after changing status but not saving, when you land back on the DA page the
|
||||
// status select will say (for example) Rejected but the selected option can be something else. To manage the show/hide
|
||||
// accurately for this edge case, we use cache and test for the back/forward navigation.
|
||||
const observer = new PerformanceObserver((list) => {
|
||||
list.getEntries().forEach((entry) => {
|
||||
if (entry.type === "back_forward") {
|
||||
let showRejectionReason = sessionStorage.getItem("showRejectionReason") !== null
|
||||
showOrHideObject(rejectionReasonFormGroup, show=showRejectionReason)
|
||||
|
||||
let showActionNeededReason = sessionStorage.getItem("showActionNeededReason") !== null
|
||||
showOrHideObject(actionNeededReasonFormGroup, show=showActionNeededReason)
|
||||
showOrHideObject(actionNeededReasonEmailFormGroup, show=isActionNeeded)
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe({ type: "navigation" });
|
||||
}
|
||||
|
||||
// Adds or removes the display-none class to object depending on the value of boolean show
|
||||
function showOrHideObject(object, show){
|
||||
if (show){
|
||||
object.classList.remove("display-none");
|
||||
}else {
|
||||
object.classList.add("display-none");
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
/** An IIFE for toggling the submit bar on domain request forms
|
||||
*/
|
||||
|
@ -530,17 +467,17 @@ class CustomizableEmailBase {
|
|||
|
||||
// Handle showing/hiding the related fields on page load.
|
||||
initializeFormGroups(statusToCheck, sessionVariableName) {
|
||||
let isStatus = statusSelect.value == statusToCheck;
|
||||
let isStatus = this.statusSelect.value == statusToCheck;
|
||||
|
||||
// Initial handling of these groups.
|
||||
updateFormGroupVisibility(isStatus, isStatus);
|
||||
this.updateFormGroupVisibility(isStatus, isStatus);
|
||||
|
||||
// Listen to change events and handle rejectionReasonFormGroup display, then save status to session storage
|
||||
this.statusSelect.addEventListener('change', () => {
|
||||
// Show the action needed field if the status is what we expect.
|
||||
// Then track if its shown or hidden in our session cache.
|
||||
isStatus = statusSelect.value == statusToCheck;
|
||||
updateFormGroupVisibility(isStatus, isStatus);
|
||||
isStatus = this.statusSelect.value == statusToCheck;
|
||||
this.updateFormGroupVisibility(isStatus, isStatus);
|
||||
addOrRemoveSessionBoolean(sessionVariableName, add=isStatus);
|
||||
});
|
||||
|
||||
|
@ -552,7 +489,7 @@ class CustomizableEmailBase {
|
|||
list.getEntries().forEach((entry) => {
|
||||
if (entry.type === "back_forward") {
|
||||
let showTextAreaFormGroup = sessionStorage.getItem(sessionVariableName) !== null;
|
||||
updateFormGroupVisibility(showTextAreaFormGroup, isStatus);
|
||||
this.updateFormGroupVisibility(showTextAreaFormGroup, isStatus);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -681,7 +618,7 @@ class customActionNeededEmail extends CustomizableEmailBase {
|
|||
const modalTrigger = document.querySelector('.field-action_needed_reason_email__modal-trigger');
|
||||
const modalConfirm = document.getElementById('confirm-edit-email');
|
||||
const formLabel = document.querySelector('label[for="id_action_needed_reason_email"]');
|
||||
const lastSentEmailContent = document.getElementById("last-sent-email-content");
|
||||
const lastSentEmailContent = document.getElementById("last-sent-action-needed-email-content");
|
||||
|
||||
let apiContainer = document.getElementById("get-action-needed-email-for-user-json")
|
||||
const apiUrl = apiContainer ? apiContainer.value : null;
|
||||
|
@ -750,7 +687,7 @@ class customRejectedEmail extends CustomizableEmailBase {
|
|||
const modalTrigger = document.querySelector('.field-rejection_reason_email__modal-trigger');
|
||||
const modalConfirm = document.getElementById('confirm-edit-email');
|
||||
const formLabel = document.querySelector('label[for="id_rejection_reason_email"]');
|
||||
const lastSentEmailContent = document.getElementById("last-sent-email-content");
|
||||
const lastSentEmailContent = document.getElementById("last-sent-rejection-email-content");
|
||||
|
||||
let apiContainer = document.getElementById("get-rejection-email-for-user-json");
|
||||
const apiUrl = apiContainer ? apiContainer.value : null;
|
||||
|
@ -776,6 +713,7 @@ class customRejectedEmail extends CustomizableEmailBase {
|
|||
|
||||
loadRejectedEmail() {
|
||||
if (this.textAreaFormGroup && this.dropdownFormGroup) {
|
||||
// TODO: fix this for rejected
|
||||
this.initializeFormGroups("rejected", "showRejectionReason");
|
||||
}
|
||||
this.updateUserInterface(this.dropdown.value);
|
||||
|
|
|
@ -1065,12 +1065,6 @@ class DomainRequest(TimeStampedModel):
|
|||
if self.status == self.DomainRequestStatus.APPROVED:
|
||||
self.delete_and_clean_up_domain("reject")
|
||||
|
||||
self._send_status_update_email(
|
||||
"action needed",
|
||||
"emails/status_change_rejected.txt",
|
||||
"emails/status_change_rejected_subject.txt",
|
||||
)
|
||||
|
||||
# Send out an email if a rejection reason exists
|
||||
if self.rejection_reason:
|
||||
email_content = self.rejection_reason_email
|
||||
|
|
|
@ -221,9 +221,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
|||
</div>
|
||||
|
||||
{% if original_object.action_needed_reason_email %}
|
||||
<input id="last-sent-email-content" class="display-none" value="{{original_object.action_needed_reason_email}}">
|
||||
<input id="last-sent-action-needed-email-content" class="display-none" value="{{original_object.action_needed_reason_email}}">
|
||||
{% else %}
|
||||
<input id="last-sent-email-content" class="display-none" value="None">
|
||||
<input id="last-sent-action-needed-email-content" class="display-none" value="None">
|
||||
{% endif %}
|
||||
|
||||
{% elif field.field.name == "rejection_reason_email" %}
|
||||
|
@ -310,9 +310,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
|||
</div>
|
||||
|
||||
{% if original_object.rejection_reason_reason_email %}
|
||||
<input id="last-sent-email-content" class="display-none" value="{{original_object.action_needed_reason_email}}">
|
||||
<input id="last-sent-rejection-email-content" class="display-none" value="{{original_object.rejection_reason_email}}">
|
||||
{% else %}
|
||||
<input id="last-sent-email-content" class="display-none" value="None">
|
||||
<input id="last-sent-rejection-email-content" class="display-none" value="None">
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ field.field }}
|
||||
|
|
|
@ -78,7 +78,7 @@ def send_templated_email(
|
|||
# Wrap the email body to a maximum width of 80 characters per line.
|
||||
# Not all email clients support CSS to do this, and our .txt files require parsing.
|
||||
if wrap_email:
|
||||
email_body = wrap_text_and_preserve_paragraphs(email_body, width=80)
|
||||
email_body = wrap_text_and_preserve_paragraphs(email_body, width=110)
|
||||
|
||||
ses_client.send_email(
|
||||
FromEmailAddress=settings.DEFAULT_FROM_EMAIL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue