mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 18:39:21 +02:00
Fix bugs
This commit is contained in:
parent
2bb2af5089
commit
646e375708
2 changed files with 42 additions and 26 deletions
|
@ -1735,17 +1735,17 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
original_obj = models.DomainRequest.objects.get(pk=obj.pk)
|
original_obj = models.DomainRequest.objects.get(pk=obj.pk)
|
||||||
|
|
||||||
# == Handle action_needed_reason == #
|
# == 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)
|
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.
|
# Set the action_needed_reason_email to the default.
|
||||||
# Since this check occurs after save, if the user enters a value then
|
# Since this check occurs after save, if the user enters a value then
|
||||||
# we won't update.
|
# we won't update.
|
||||||
reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
|
if default_email and default_email == obj.action_needed_reason_email:
|
||||||
if reason_changed:
|
|
||||||
request.session["action_needed_email_sent"] = True
|
|
||||||
logger.info("added session object")
|
|
||||||
if default_email == obj.action_needed_reason_email:
|
|
||||||
obj.action_needed_reason_email = default_email
|
obj.action_needed_reason_email = default_email
|
||||||
|
|
||||||
# == Handle status == #
|
# == Handle status == #
|
||||||
|
@ -1960,7 +1960,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
email_sent = request.session.get("action_needed_email_sent", False)
|
email_sent = request.session.get("action_needed_email_sent", False)
|
||||||
extra_context["action_needed_email_sent"] = email_sent
|
extra_context["action_needed_email_sent"] = email_sent
|
||||||
if 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
|
# Call the superclass method with updated extra_context
|
||||||
return super().change_view(request, object_id, form_url, extra_context)
|
return super().change_view(request, object_id, form_url, extra_context)
|
||||||
|
|
|
@ -535,10 +535,11 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
const emptyReasonText = "-";
|
const emptyReasonText = "-";
|
||||||
const noEmailText = "No email will be sent.";
|
const noEmailText = "No email will be sent.";
|
||||||
const domainRequestId = actionNeededReasonDropdown ? document.querySelector("#domain_request_id").value : null
|
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
|
// Add a change listener to the action needed reason dropdown
|
||||||
handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail, actionNeededEmailData);
|
handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail, actionNeededEmailData);
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
let reason = actionNeededReasonDropdown.value;
|
let reason = actionNeededReasonDropdown.value;
|
||||||
noEmailMessage.innerHTML = reason ? noEmailText : emptyReasonText;
|
noEmailMessage.innerHTML = reason ? noEmailText : emptyReasonText;
|
||||||
|
@ -552,14 +553,21 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
showElement(noEmailMessage);
|
showElement(noEmailMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let emailWasSent = document.getElementById("action-needed-email-sent")
|
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 === "True") {
|
||||||
if (emailWasSent && emailWasSent.value) {
|
// An email was sent out - store that information in a session variable
|
||||||
// add the session object
|
addOrRemoveSessionBoolean(emailSentSessionVariableName, add=true)
|
||||||
if (sessionStorage.getItem(`actionNeededEmailSent-${domainRequestId}`) === null) {
|
|
||||||
sessionStorage.setItem(`actionNeededEmailSent-${domainRequestId}`, domainRequestId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
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.
|
// 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:
|
// Only do this if we change the action needed reason, or if we:
|
||||||
// change the reason => modify email content => change back to old reason.
|
// change the reason => modify email content => change back to old reason.
|
||||||
if (oldDropdownValue != actionNeededReasonDropdown.value || oldEmailValue != actionNeededEmail.value) {
|
if (oldDropdownValue !== actionNeededReasonDropdown.value || oldEmailValue !== actionNeededEmail.value) {
|
||||||
let emailSent = sessionStorage.getItem(`actionNeededEmailSent-${domainRequestId}`)
|
let emailSent = sessionStorage.getItem(emailSentSessionVariableName)
|
||||||
if (emailSent !== null){
|
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)
|
showReadonly(actionNeededEmail.parentElement)
|
||||||
|
}else {
|
||||||
|
// No email was sent out -- show the editable field
|
||||||
|
hideReadonly(actionNeededEmail.parentElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
// Show the no email message
|
// Show the no email message
|
||||||
hideElement(actionNeededEmail);
|
hideElement(actionNeededEmail);
|
||||||
|
@ -605,17 +622,16 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
function showReadonly(actionNeededEmailParent) {
|
function showReadonly(actionNeededEmailParent) {
|
||||||
let readonlyView = document.querySelector("#action-needed-reason-email-readonly")
|
let readonlyView = document.querySelector("#action-needed-reason-email-readonly")
|
||||||
if (readonlyView) {
|
if (readonlyView) {
|
||||||
hideElement(readonlyView)
|
showElement(readonlyView)
|
||||||
showElement(actionNeededEmailParent)
|
hideElement(actionNeededEmailParent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideReadonly(actionNeededEmailParent) {
|
function hideReadonly(actionNeededEmailParent) {
|
||||||
let readonlyView = document.querySelector("#action-needed-reason-email-readonly")
|
let readonlyView = document.querySelector("#action-needed-reason-email-readonly")
|
||||||
if (readonlyView) {
|
if (readonlyView) {
|
||||||
showElement(readonlyView)
|
hideElement(readonlyView)
|
||||||
hideElement(actionNeededEmailParent)
|
showElement(actionNeededEmailParent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue