Logic to show different messages depending on the state

This commit is contained in:
zandercymatics 2024-07-12 08:30:15 -06:00
parent 72000b4a9b
commit c428e8a1dd
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -528,13 +528,19 @@ function initializeWidgetOnList(list, parentId) {
(function () { (function () {
let actionNeededReasonDropdown = document.querySelector("#id_action_needed_reason"); let actionNeededReasonDropdown = document.querySelector("#id_action_needed_reason");
let actionNeededEmail = document.querySelector("#id_action_needed_reason_email"); let actionNeededEmail = document.querySelector("#id_action_needed_reason_email");
let noEmailMessage = document.getElementById("no-email-message");
const emptyReasonText = "---------"
const noEmailText = "No email will be sent."
if(actionNeededReasonDropdown && actionNeededEmail) { if(actionNeededReasonDropdown && actionNeededEmail) {
// Add a change listener to the action needed reason dropdown // Add a change listener to the action needed reason dropdown
handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail); handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail);
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
if (!actionNeededReasonDropdown.value || actionNeededReasonDropdown.value == "other") { if (!actionNeededReasonDropdown.value) {
showNoEmailMessage(actionNeededEmail); noEmailMessage.innerHTML = emptyReasonText
showNoEmailMessage(actionNeededEmail, noEmailMessage);
}else if (actionNeededReasonDropdown.value == "other") {
noEmailMessage.innerHTML = noEmailText
} }
}); });
} }
@ -547,8 +553,11 @@ function initializeWidgetOnList(list, parentId) {
// You also cannot save the model in this state. // You also cannot save the model in this state.
// This flow occurs if you switch back to the empty picker state. // This flow occurs if you switch back to the empty picker state.
if(!reason) { if(!reason) {
showNoEmailMessage(actionNeededEmail); noEmailMessage.innerHTML = emptyReasonText
showNoEmailMessage(actionNeededEmail, noEmailMessage);
return; return;
}else if (reason === "other") {
noEmailMessage.innerHTML = noEmailText
} }
let actionNeededEmails = JSON.parse(document.getElementById('action-needed-emails-data').textContent) let actionNeededEmails = JSON.parse(document.getElementById('action-needed-emails-data').textContent)
@ -557,27 +566,25 @@ function initializeWidgetOnList(list, parentId) {
let emailBody = emailData.email_body_text let emailBody = emailData.email_body_text
if (emailBody) { if (emailBody) {
actionNeededEmail.value = emailBody actionNeededEmail.value = emailBody
showActionNeededEmail(actionNeededEmail); showActionNeededEmail(actionNeededEmail, noEmailMessage);
}else { }else {
showNoEmailMessage(actionNeededEmail); showNoEmailMessage(actionNeededEmail, noEmailMessage);
} }
}else { }else {
showNoEmailMessage(actionNeededEmail); showNoEmailMessage(actionNeededEmail, noEmailMessage);
} }
}); });
} }
// Show the text field. Hide the "no email" message. // Show the text field. Hide the "no email" message.
function showActionNeededEmail(actionNeededEmail){ function showActionNeededEmail(actionNeededEmail, noEmailMessage){
let noEmailMessage = document.getElementById("no-email-message");
showElement(actionNeededEmail); showElement(actionNeededEmail);
hideElement(noEmailMessage); hideElement(noEmailMessage);
} }
// Hide the text field. Show the "no email" message. // Hide the text field. Show the "no email" message.
function showNoEmailMessage(actionNeededEmail) { function showNoEmailMessage(actionNeededEmail, noEmailMessage) {
let noEmailMessage = document.getElementById("no-email-message");
hideElement(actionNeededEmail); hideElement(actionNeededEmail);
showElement(noEmailMessage); showElement(noEmailMessage);
} }