mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-20 01:36:00 +02:00
Remove functions for ease of reading
This commit is contained in:
parent
c4449c8f6c
commit
f4439925b5
1 changed files with 7 additions and 17 deletions
|
@ -531,30 +531,21 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
var actionNeededEmail = document.querySelector("#id_action_needed_reason_email");
|
var actionNeededEmail = document.querySelector("#id_action_needed_reason_email");
|
||||||
var readonlyView = document.querySelector("#action-needed-reason-email-readonly");
|
var readonlyView = document.querySelector("#action-needed-reason-email-readonly");
|
||||||
|
|
||||||
|
let emailWasSent = document.getElementById("action-needed-email-sent");
|
||||||
let actionNeededEmailData = document.getElementById('action-needed-emails-data').textContent;
|
let actionNeededEmailData = document.getElementById('action-needed-emails-data').textContent;
|
||||||
const oldDropdownValue = actionNeededReasonDropdown ? actionNeededReasonDropdown.value : null;
|
let actionNeededEmailsJson = JSON.parse(actionNeededEmailData);
|
||||||
const oldEmailValue = actionNeededEmailData ? actionNeededEmailData.value : null;
|
|
||||||
|
|
||||||
const domainRequestId = actionNeededReasonDropdown ? document.querySelector("#domain_request_id").value : null
|
const domainRequestId = actionNeededReasonDropdown ? document.querySelector("#domain_request_id").value : null
|
||||||
const emailSentSessionVariableName = `actionNeededEmailSent-${domainRequestId}`;
|
const emailSentSessionVariableName = `actionNeededEmailSent-${domainRequestId}`;
|
||||||
const emptyReasonText = "-";
|
const oldDropdownValue = actionNeededReasonDropdown ? actionNeededReasonDropdown.value : null;
|
||||||
const noEmailText = "No email will be sent.";
|
const oldEmailValue = actionNeededEmailData ? actionNeededEmailData.value : null;
|
||||||
|
|
||||||
if(actionNeededReasonDropdown && actionNeededEmail && domainRequestId) {
|
if(actionNeededReasonDropdown && actionNeededEmail && domainRequestId) {
|
||||||
// Add a change listener to dom load
|
// Add a change listener to dom load
|
||||||
handleDomLoadActionNeededEmail();
|
|
||||||
|
|
||||||
// Add a change listener to the action needed reason dropdown
|
|
||||||
let actionNeededEmailsJson = JSON.parse(actionNeededEmailData)
|
|
||||||
handleChangeActionNeededEmail(actionNeededEmailsJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDomLoadActionNeededEmail() {
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
let reason = actionNeededReasonDropdown.value;
|
let reason = actionNeededReasonDropdown.value;
|
||||||
|
|
||||||
// Handle the session boolean (to enable/disable editing)
|
// Handle the session boolean (to enable/disable editing)
|
||||||
let emailWasSent = document.getElementById("action-needed-email-sent");
|
|
||||||
if (emailWasSent && emailWasSent.value === "True") {
|
if (emailWasSent && emailWasSent.value === "True") {
|
||||||
// An email was sent out - store that information in a session variable
|
// An email was sent out - store that information in a session variable
|
||||||
addOrRemoveSessionBoolean(emailSentSessionVariableName, add=true);
|
addOrRemoveSessionBoolean(emailSentSessionVariableName, add=true);
|
||||||
|
@ -563,9 +554,8 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
// Show an editable email field or a readonly one
|
// Show an editable email field or a readonly one
|
||||||
updateActionNeededEmailDisplay(reason)
|
updateActionNeededEmailDisplay(reason)
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function handleChangeActionNeededEmail(actionNeededEmailsJson) {
|
// Add a change listener to the action needed reason dropdown
|
||||||
actionNeededReasonDropdown.addEventListener("change", function() {
|
actionNeededReasonDropdown.addEventListener("change", function() {
|
||||||
let reason = actionNeededReasonDropdown.value;
|
let reason = actionNeededReasonDropdown.value;
|
||||||
let emailBody = reason in actionNeededEmailsJson ? actionNeededEmailsJson[reason] : null;
|
let emailBody = reason in actionNeededEmailsJson ? actionNeededEmailsJson[reason] : null;
|
||||||
|
@ -592,13 +582,13 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
// Likewise, if we've sent this email before, we should just display the content.
|
// Likewise, if we've sent this email before, we should just display the content.
|
||||||
function updateActionNeededEmailDisplay(reason) {
|
function updateActionNeededEmailDisplay(reason) {
|
||||||
let emailHasBeenSentBefore = sessionStorage.getItem(emailSentSessionVariableName) !== null;
|
let emailHasBeenSentBefore = sessionStorage.getItem(emailSentSessionVariableName) !== null;
|
||||||
let collapseableDiv = readonlyView.querySelector('.collapse--dgsimple');
|
let collapseableDiv = readonlyView.querySelector(".collapse--dgsimple");
|
||||||
if ((reason && reason != "other") && !emailHasBeenSentBefore) {
|
if ((reason && reason != "other") && !emailHasBeenSentBefore) {
|
||||||
showElement(actionNeededEmail.parentElement)
|
showElement(actionNeededEmail.parentElement)
|
||||||
hideElement(readonlyView)
|
hideElement(readonlyView)
|
||||||
} else {
|
} else {
|
||||||
if (!reason || reason === "other") {
|
if (!reason || reason === "other") {
|
||||||
collapseableDiv.innerHTML = reason ? noEmailText : emptyReasonText;
|
collapseableDiv.innerHTML = reason ? "No email will be sent." : "-";
|
||||||
}
|
}
|
||||||
hideElement(actionNeededEmail.parentElement)
|
hideElement(actionNeededEmail.parentElement)
|
||||||
showElement(readonlyView)
|
showElement(readonlyView)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue