mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 19:20:47 +02:00
Update portfolio-member-page.js
This commit is contained in:
parent
08082fb0aa
commit
6965607f61
1 changed files with 152 additions and 152 deletions
|
@ -41,42 +41,42 @@ export function initPortfolioNewMemberPageToggle() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hooks up specialized listeners for handling form validation and modals
|
* Hooks up specialized listeners for handling form validation and modals
|
||||||
* on the Add New Member page.
|
* on the Add New Member page.
|
||||||
*/
|
*/
|
||||||
export function initAddNewMemberPageListeners() {
|
export function initAddNewMemberPageListeners() {
|
||||||
let add_member_form = document.getElementById("add_member_form");
|
let add_member_form = document.getElementById("add_member_form");
|
||||||
if (!add_member_form){
|
if (!add_member_form){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.getElementById("confirm_new_member_submit").addEventListener("click", function() {
|
document.getElementById("confirm_new_member_submit").addEventListener("click", function() {
|
||||||
// Upon confirmation, submit the form
|
// Upon confirmation, submit the form
|
||||||
document.getElementById("add_member_form").submit();
|
document.getElementById("add_member_form").submit();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("add_member_form").addEventListener("submit", function(event) {
|
document.getElementById("add_member_form").addEventListener("submit", function(event) {
|
||||||
event.preventDefault(); // Prevents the form from submitting
|
event.preventDefault(); // Prevents the form from submitting
|
||||||
const form = document.getElementById("add_member_form")
|
const form = document.getElementById("add_member_form")
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
|
|
||||||
// Check if the form is valid
|
// Check if the form is valid
|
||||||
// If the form is valid, open the confirmation modal
|
// If the form is valid, open the confirmation modal
|
||||||
// If the form is invalid, submit it to trigger error
|
// If the form is invalid, submit it to trigger error
|
||||||
fetch(form.action, {
|
fetch(form.action, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: {
|
headers: {
|
||||||
"X-Requested-With": "XMLHttpRequest",
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
"X-CSRFToken": getCsrfToken()
|
"X-CSRFToken": getCsrfToken()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.is_valid) {
|
if (data.is_valid) {
|
||||||
// If the form is valid, show the confirmation modal before submitting
|
// If the form is valid, show the confirmation modal before submitting
|
||||||
openAddMemberConfirmationModal();
|
openAddMemberConfirmationModal();
|
||||||
|
@ -84,28 +84,28 @@ fetch(form.action, {
|
||||||
// If the form is not valid, trigger error messages by firing a submit event
|
// If the form is not valid, trigger error messages by firing a submit event
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Helper function to capitalize the first letter in a string (for display purposes)
|
Helper function to capitalize the first letter in a string (for display purposes)
|
||||||
*/
|
*/
|
||||||
function capitalizeFirstLetter(text) {
|
function capitalizeFirstLetter(text) {
|
||||||
if (!text) return ''; // Return empty string if input is falsy
|
if (!text) return ''; // Return empty string if input is falsy
|
||||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Populates contents of the "Add Member" confirmation modal
|
Populates contents of the "Add Member" confirmation modal
|
||||||
*/
|
*/
|
||||||
function populatePermissionDetails(permission_details_div_id) {
|
function populatePermissionDetails(permission_details_div_id) {
|
||||||
const permissionDetailsContainer = document.getElementById("permission_details");
|
const permissionDetailsContainer = document.getElementById("permission_details");
|
||||||
permissionDetailsContainer.innerHTML = ""; // Clear previous content
|
permissionDetailsContainer.innerHTML = ""; // Clear previous content
|
||||||
|
|
||||||
// Get all permission sections (divs with h3 and radio inputs)
|
// Get all permission sections (divs with h3 and radio inputs)
|
||||||
const permissionSections = document.querySelectorAll(`#${permission_details_div_id} > h3`);
|
const permissionSections = document.querySelectorAll(`#${permission_details_div_id} > h3`);
|
||||||
|
|
||||||
permissionSections.forEach(section => {
|
permissionSections.forEach(section => {
|
||||||
// Find the <h3> element text
|
// Find the <h3> element text
|
||||||
const sectionTitle = section.textContent;
|
const sectionTitle = section.textContent;
|
||||||
|
|
||||||
|
@ -137,13 +137,13 @@ permissionSections.forEach(section => {
|
||||||
permissionDetailsContainer.appendChild(titleElement);
|
permissionDetailsContainer.appendChild(titleElement);
|
||||||
permissionDetailsContainer.appendChild(permissionElement);
|
permissionDetailsContainer.appendChild(permissionElement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Updates and opens the "Add Member" confirmation modal.
|
Updates and opens the "Add Member" confirmation modal.
|
||||||
*/
|
*/
|
||||||
function openAddMemberConfirmationModal() {
|
function openAddMemberConfirmationModal() {
|
||||||
//------- Populate modal details
|
//------- Populate modal details
|
||||||
// Get email value
|
// Get email value
|
||||||
let emailValue = document.getElementById('id_email').value;
|
let emailValue = document.getElementById('id_email').value;
|
||||||
|
@ -168,7 +168,7 @@ function openAddMemberConfirmationModal() {
|
||||||
if (modalTrigger) {
|
if (modalTrigger) {
|
||||||
modalTrigger.click();
|
modalTrigger.click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue