This commit is contained in:
zandercymatics 2024-07-15 09:49:46 -06:00
parent 2bb2af5089
commit 646e375708
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 42 additions and 26 deletions

View file

@ -1735,17 +1735,17 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
original_obj = models.DomainRequest.objects.get(pk=obj.pk)
# == Handle action_needed_reason == #
# Store the email that was sent out if one was sent and it isn't saved to a variable yet
default_email = self._get_action_needed_reason_default_email(obj, obj.action_needed_reason)
if default_email:
reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
if reason_changed:
# Track that we sent out an email
request.session["action_needed_email_sent"] = True
# Set the action_needed_reason_email to the default.
# Since this check occurs after save, if the user enters a value then
# we won't update.
reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
if reason_changed:
request.session["action_needed_email_sent"] = True
logger.info("added session object")
if default_email == obj.action_needed_reason_email:
if default_email and default_email == obj.action_needed_reason_email:
obj.action_needed_reason_email = default_email
# == Handle status == #
@ -1960,7 +1960,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
email_sent = request.session.get("action_needed_email_sent", False)
extra_context["action_needed_email_sent"] = email_sent
if email_sent:
email_sent = request.session["action_needed_email_sent"] = False
request.session["action_needed_email_sent"] = False
# Call the superclass method with updated extra_context
return super().change_view(request, object_id, form_url, extra_context)

View file

@ -535,10 +535,11 @@ function initializeWidgetOnList(list, parentId) {
const emptyReasonText = "-";
const noEmailText = "No email will be sent.";
const domainRequestId = actionNeededReasonDropdown ? document.querySelector("#domain_request_id").value : null
if(actionNeededReasonDropdown && actionNeededEmail && actionNeededEmailData) {
const emailSentSessionVariableName = `actionNeededEmailSent-${domainRequestId}`;
if(actionNeededReasonDropdown && actionNeededEmail && actionNeededEmailData && domainRequestId) {
// Add a change listener to the action needed reason dropdown
handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail, actionNeededEmailData);
document.addEventListener('DOMContentLoaded', function() {
let reason = actionNeededReasonDropdown.value;
noEmailMessage.innerHTML = reason ? noEmailText : emptyReasonText;
@ -552,14 +553,21 @@ function initializeWidgetOnList(list, parentId) {
showElement(noEmailMessage);
}
let emailWasSent = document.getElementById("action-needed-email-sent")
console.log(`email ${emailWasSent.value} vs session ${sessionStorage.getItem("actionNeededEmailSent")} vs id ${domainRequestId}`)
if (emailWasSent && emailWasSent.value) {
// add the session object
if (sessionStorage.getItem(`actionNeededEmailSent-${domainRequestId}`) === null) {
sessionStorage.setItem(`actionNeededEmailSent-${domainRequestId}`, domainRequestId);
if (emailWasSent && emailWasSent.value === "True") {
// An email was sent out - store that information in a session variable
addOrRemoveSessionBoolean(emailSentSessionVariableName, add=true)
}
if (sessionStorage.getItem(emailSentSessionVariableName) !== null) {
// Show the readonly field, hide the editable field
showReadonly(actionNeededEmail.parentElement)
console.log("adding data")
}else {
// No email was sent out -- show the editable field
hideReadonly(actionNeededEmail.parentElement)
console.log("removing data")
}
});
}
@ -582,13 +590,22 @@ function initializeWidgetOnList(list, parentId) {
// Reset the session object on change since change refreshes the email content.
// Only do this if we change the action needed reason, or if we:
// change the reason => modify email content => change back to old reason.
if (oldDropdownValue != actionNeededReasonDropdown.value || oldEmailValue != actionNeededEmail.value) {
let emailSent = sessionStorage.getItem(`actionNeededEmailSent-${domainRequestId}`)
if (oldDropdownValue !== actionNeededReasonDropdown.value || oldEmailValue !== actionNeededEmail.value) {
let emailSent = sessionStorage.getItem(emailSentSessionVariableName)
if (emailSent !== null){
sessionStorage.removeItem(`actionNeededEmailSent-${domainRequestId}`);
console.log("removing data")
addOrRemoveSessionBoolean(emailSentSessionVariableName, add=false)
}
}
if (sessionStorage.getItem(emailSentSessionVariableName) !== null) {
// Show the readonly field, hide the editable field
showReadonly(actionNeededEmail.parentElement)
}else {
// No email was sent out -- show the editable field
hideReadonly(actionNeededEmail.parentElement)
}
}else {
// Show the no email message
hideElement(actionNeededEmail);
@ -605,17 +622,16 @@ function initializeWidgetOnList(list, parentId) {
function showReadonly(actionNeededEmailParent) {
let readonlyView = document.querySelector("#action-needed-reason-email-readonly")
if (readonlyView) {
hideElement(readonlyView)
showElement(actionNeededEmailParent)
showElement(readonlyView)
hideElement(actionNeededEmailParent)
}
}
function hideReadonly(actionNeededEmailParent) {
let readonlyView = document.querySelector("#action-needed-reason-email-readonly")
if (readonlyView) {
showElement(readonlyView)
hideElement(actionNeededEmailParent)
hideElement(readonlyView)
showElement(actionNeededEmailParent)
}
}
})();