mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-05 10:43:23 +02:00
cleanup
This commit is contained in:
parent
94b5c0642c
commit
e33daf7cc3
1 changed files with 87 additions and 103 deletions
|
@ -510,9 +510,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
const dropdown = document.getElementById("id_action_needed_reason");
|
const dropdown = document.getElementById("id_action_needed_reason");
|
||||||
const textarea = document.getElementById("id_action_needed_reason_email")
|
const textarea = document.getElementById("id_action_needed_reason_email")
|
||||||
const domainRequestId = dropdown ? document.getElementById("domain_request_id").value : null
|
const domainRequestId = dropdown ? document.getElementById("domain_request_id").value : null
|
||||||
|
|
||||||
if(dropdown && textarea && domainRequestId) {
|
|
||||||
|
|
||||||
const texareaPlaceholder = document.querySelector(".field-action_needed_reason_email__placeholder");
|
const texareaPlaceholder = document.querySelector(".field-action_needed_reason_email__placeholder");
|
||||||
const directEditButton = document.querySelector('.field-action_needed_reason_email__edit');
|
const directEditButton = document.querySelector('.field-action_needed_reason_email__edit');
|
||||||
const modalTrigger = document.querySelector('.field-action_needed_reason_email__modal-trigger');
|
const modalTrigger = document.querySelector('.field-action_needed_reason_email__modal-trigger');
|
||||||
|
@ -522,24 +519,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
<use xlink:href="/public/img/sprite.svg#check_circle"></use>
|
<use xlink:href="/public/img/sprite.svg#check_circle"></use>
|
||||||
</svg>`;
|
</svg>`;
|
||||||
let lastSentEmailContent = document.getElementById("last-sent-email-content");
|
let lastSentEmailContent = document.getElementById("last-sent-email-content");
|
||||||
|
|
||||||
const helpText = document.querySelector('.field-action_needed_reason_email .help');
|
const helpText = document.querySelector('.field-action_needed_reason_email .help');
|
||||||
|
|
||||||
// Get the list of emails associated with each action-needed dropdown value
|
|
||||||
const emailData = document.getElementById('action-needed-emails-data');
|
const emailData = document.getElementById('action-needed-emails-data');
|
||||||
const actionNeededEmailData = emailData.textContent;
|
const actionNeededEmailData = emailData.textContent;
|
||||||
const actionNeededEmailsJson = JSON.parse(actionNeededEmailData);
|
const actionNeededEmailsJson = JSON.parse(actionNeededEmailData);
|
||||||
// Get initial dropdown and email
|
|
||||||
const initialDropdownValue = dropdown ? dropdown.value : null;
|
const initialDropdownValue = dropdown ? dropdown.value : null;
|
||||||
const initialEmailValue = actionNeededEmailData ? actionNeededEmailData.value : null;
|
const initialEmailValue = actionNeededEmailData ? actionNeededEmailData.value : null;
|
||||||
|
// We will use the const to control the modal
|
||||||
if(
|
let isEmailAlreadySentConst = lastSentEmailContent.value.replace(/\s+/g, '') === textarea.value.replace(/\s+/g, '');
|
||||||
!formLabel ||
|
// We will use the function to control the label and help
|
||||||
!modalConfirm ||
|
function isEmailAlreadySent() {
|
||||||
!actionNeededEmailData) {
|
return lastSentEmailContent.value.replace(/\s+/g, '') === textarea.value.replace(/\s+/g, '');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dropdown || !textarea || !domainRequestId || !formLabel || !modalConfirm || !emailData) return;
|
||||||
|
|
||||||
function updateUserInterface(reason) {
|
function updateUserInterface(reason) {
|
||||||
if (!reason) {
|
if (!reason) {
|
||||||
// No reason selected, we will set the label to "Email", show the "Make a selection" placeholder, hide the trigger, textarea, hide the help text
|
// No reason selected, we will set the label to "Email", show the "Make a selection" placeholder, hide the trigger, textarea, hide the help text
|
||||||
|
@ -566,33 +560,29 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
showElement(textarea);
|
showElement(textarea);
|
||||||
textarea.setAttribute('readonly', true);
|
textarea.setAttribute('readonly', true);
|
||||||
showElement(helpText);
|
showElement(helpText);
|
||||||
if (checkEmailAlreadySent()) {
|
if (isEmailAlreadySentConst) {
|
||||||
hideElement(directEditButton);
|
hideElement(directEditButton);
|
||||||
showElement(modalTrigger);
|
showElement(modalTrigger);
|
||||||
formLabel.innerHTML = greenCheckMark + "Email sent to the creator:"
|
|
||||||
helpText.innerHTML = "This email has been sent to the creator of this request"
|
|
||||||
} else {
|
} else {
|
||||||
showElement(directEditButton);
|
showElement(directEditButton);
|
||||||
hideElement(modalTrigger);
|
hideElement(modalTrigger);
|
||||||
|
}
|
||||||
|
if (isEmailAlreadySent()) {
|
||||||
|
formLabel.innerHTML = greenCheckMark + "Email sent to the creator:"
|
||||||
|
helpText.innerHTML = "This email has been sent to the creator of this request"
|
||||||
|
} else {
|
||||||
formLabel.innerHTML = "Auto-generated email that will be sent to the creator";
|
formLabel.innerHTML = "Auto-generated email that will be sent to the creator";
|
||||||
helpText.innerHTML = "This email will be sent to the creator of this request after saving";
|
helpText.innerHTML = "This email will be sent to the creator of this request after saving";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkEmailAlreadySent() {
|
// Initialize UI
|
||||||
lastEmailSent = lastSentEmailContent.value.replace(/\s+/g, '')
|
|
||||||
currentEmailInTextArea = textarea.value.replace(/\s+/g, '')
|
|
||||||
return lastEmailSent === currentEmailInTextArea
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init the UI
|
|
||||||
updateUserInterface(dropdown.value);
|
updateUserInterface(dropdown.value);
|
||||||
|
|
||||||
// Add a change listener to the action needed reason dropdown
|
|
||||||
dropdown.addEventListener("change", function() {
|
dropdown.addEventListener("change", function() {
|
||||||
let reason = dropdown.value;
|
const reason = dropdown.value;
|
||||||
let emailBody = reason in actionNeededEmailsJson ? actionNeededEmailsJson[reason] : null;
|
const emailBody = reason in actionNeededEmailsJson ? actionNeededEmailsJson[reason] : null;
|
||||||
|
|
||||||
if (reason && emailBody) {
|
if (reason && emailBody) {
|
||||||
// If it's not the initial value
|
// If it's not the initial value
|
||||||
|
@ -606,14 +596,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
updateUserInterface(reason);
|
updateUserInterface(reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
modalConfirm.addEventListener("click", function() {
|
modalConfirm.addEventListener("click", () => textarea.removeAttribute('readonly'));
|
||||||
textarea.removeAttribute('readonly');
|
directEditButton.addEventListener("click", () => textarea.removeAttribute('readonly'));
|
||||||
});
|
|
||||||
|
|
||||||
directEditButton.addEventListener("click", function() {
|
|
||||||
textarea.removeAttribute('readonly');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue