Refactor JS to account for changes to select then back/forward navigation

This commit is contained in:
Rachid Mrad 2024-02-20 15:30:54 -05:00
parent 167634cc99
commit 5b2ca61de6
No known key found for this signature in database
2 changed files with 21 additions and 23 deletions

View file

@ -317,22 +317,37 @@ function enableRelatedWidgetButtons(changeLink, deleteLink, viewLink, elementPk,
* status select amd to show/hide the rejection reason
*/
(function (){
// Get the rejection reason form row
let rejectionReasonFormGroup = document.querySelector('.field-rejection_reason')
if (rejectionReasonFormGroup) {
// Get the status select
let statusSelect = document.getElementById('id_status')
// If status is rejected, hide the rejection reason on load
// Initial handling of rejectionReasonFormGroup display
if (statusSelect.value != 'rejected')
rejectionReasonFormGroup.style.display = 'none';
// Listen to status changes and toggle rejection reason
// Listen to change events and handle rejectionReasonFormGroup display, then save status to session storage
statusSelect.addEventListener('change', function() {
rejectionReasonFormGroup.style.display = statusSelect.value !== 'rejected' ? 'none' : 'block';
if (statusSelect.value == 'rejected') {
rejectionReasonFormGroup.style.display = 'block';
sessionStorage.removeItem('hideRejectionReason');
} else {
rejectionReasonFormGroup.style.display = 'none';
sessionStorage.setItem('hideRejectionReason', 'true');
}
});
}
// Listen to Back/Forward button navigation and handle rejectionReasonFormGroup display based on session storage
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.type === "back_forward") {
if (sessionStorage.getItem('hideRejectionReason'))
document.querySelector('.field-rejection_reason').style.display = 'none';
else
document.querySelector('.field-rejection_reason').style.display = 'block';
}
});
});
observer.observe({ type: "navigation" });
})();

View file

@ -699,23 +699,6 @@ class TestDomainApplicationAdmin(MockEppLib):
application.refresh_from_db()
self.assertEqual(application.status, DomainApplication.ApplicationStatus.REJECTED)
def test_save_model_clear_rejected_reason(self):
"""When transitioning from rejected on a domain request,
the rejected_reason is cleared."""
# Create a sample application
application = completed_application(status=DomainApplication.ApplicationStatus.REJECTED)
application.rejected_reason = DomainApplication.RejectionReasons.DOMAIN_PURPOSE
application.save()
# Approve
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
application.approve()
application.refresh_from_db()
self.assertEqual(application.rejected_reason, None)
def test_save_model_sends_withdrawn_email(self):
"""When transitioning to withdrawn on a domain request,
an email is sent out every time."""