mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +02:00
frontend updates. Code cleanup
This commit is contained in:
parent
6dc7d6f673
commit
cc4a52c32a
2 changed files with 27 additions and 39 deletions
|
@ -2826,35 +2826,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
* An IIFE that handles the modal associated with adding a new member to a portfolio.
|
* An IIFE that handles the modal associated with adding a new member to a portfolio.
|
||||||
*/
|
*/
|
||||||
(function handleNewMemberModal() {
|
(function handleNewMemberModal() {
|
||||||
|
|
||||||
// Validate the form
|
|
||||||
function validateForm() {
|
|
||||||
// Perform an AJAX POST request to validate form data
|
|
||||||
const form = document.getElementById("add_member_form");
|
|
||||||
if (!form) {
|
|
||||||
console.error("Form element not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const formData = new FormData(form); // Use the form element for FormData
|
|
||||||
fetch("/members/new-member/validate", {
|
|
||||||
method: "POST",
|
|
||||||
body: formData,
|
|
||||||
headers: {
|
|
||||||
"X-Requested-With": "XMLHttpRequest"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.is_valid) {
|
|
||||||
// If validation passes, display the modal and set values
|
|
||||||
openAddMemberConfirmationModal();
|
|
||||||
} else {
|
|
||||||
// Handle validation errors
|
|
||||||
form.submit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
@ -2881,11 +2858,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new elements for the modal content
|
// Create new elements for the modal content
|
||||||
const titleElement = document.createElement("h3");
|
const titleElement = document.createElement("h4");
|
||||||
titleElement.textContent = sectionTitle;
|
titleElement.textContent = sectionTitle;
|
||||||
|
titleElement.classList.add("text-primary");
|
||||||
|
titleElement.classList.add("margin-bottom-0");
|
||||||
|
|
||||||
const permissionElement = document.createElement("p");
|
const permissionElement = document.createElement("p");
|
||||||
permissionElement.textContent = selectedPermission;
|
permissionElement.textContent = selectedPermission;
|
||||||
|
permissionElement.classList.add("margin-top-0");
|
||||||
|
|
||||||
// Append to the modal content container
|
// Append to the modal content container
|
||||||
permissionDetailsContainer.appendChild(titleElement);
|
permissionDetailsContainer.appendChild(titleElement);
|
||||||
|
@ -2894,9 +2874,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the modal
|
/*
|
||||||
|
Updates and opens the "Add Member" confirmation modal.
|
||||||
|
*/
|
||||||
function openAddMemberConfirmationModal() {
|
function openAddMemberConfirmationModal() {
|
||||||
|
//------- Populate modal details
|
||||||
// Get email value
|
// Get email value
|
||||||
let emailValue = document.getElementById('id_email').value;
|
let emailValue = document.getElementById('id_email').value;
|
||||||
document.getElementById('modalEmail').textContent = emailValue;
|
document.getElementById('modalEmail').textContent = emailValue;
|
||||||
|
@ -2913,7 +2895,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
populatePermissionDetails('new-member-basic-permissions')
|
populatePermissionDetails('new-member-basic-permissions')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the modal
|
//------- Show the modal
|
||||||
let modalTrigger = document.querySelector("#invite_member_trigger");
|
let modalTrigger = document.querySelector("#invite_member_trigger");
|
||||||
if (modalTrigger) {
|
if (modalTrigger) {
|
||||||
modalTrigger.click()
|
modalTrigger.click()
|
||||||
|
|
|
@ -81,12 +81,17 @@
|
||||||
<h2>Admin access permissions</h2>
|
<h2>Admin access permissions</h2>
|
||||||
<p>Member permissions available for admin-level acccess.</p>
|
<p>Member permissions available for admin-level acccess.</p>
|
||||||
|
|
||||||
<h3 class="margin-bottom-0">Organization domain requests</h3>
|
<h3 class="summary-item__title
|
||||||
|
text-primary-dark
|
||||||
|
margin-bottom-0">Organization domain requests</h3>
|
||||||
{% with group_classes="usa-form-editable usa-form-editable--no-border padding-top-0" %}
|
{% with group_classes="usa-form-editable usa-form-editable--no-border padding-top-0" %}
|
||||||
{% input_with_errors form.admin_org_domain_request_permissions %}
|
{% input_with_errors form.admin_org_domain_request_permissions %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
<h3 class="margin-bottom-0 margin-top-3">Organization members</h3>
|
<h3 class="summary-item__title
|
||||||
|
text-primary-dark
|
||||||
|
margin-bottom-0
|
||||||
|
margin-top-3">Organization members</h3>
|
||||||
{% with group_classes="usa-form-editable usa-form-editable--no-border padding-top-0" %}
|
{% with group_classes="usa-form-editable usa-form-editable--no-border padding-top-0" %}
|
||||||
{% input_with_errors form.admin_org_members_permissions %}
|
{% input_with_errors form.admin_org_members_permissions %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
@ -136,14 +141,15 @@
|
||||||
<h2 class="usa-modal__heading" id="invite-member-heading">
|
<h2 class="usa-modal__heading" id="invite-member-heading">
|
||||||
Invite this member to the organization?
|
Invite this member to the organization?
|
||||||
</h2>
|
</h2>
|
||||||
<h3>Member information and permissions</h3>
|
<h3 class="summary-item__title
|
||||||
|
text-primary-dark">Member information and permissions</h3>
|
||||||
<div class="usa-prose">
|
<div class="usa-prose">
|
||||||
<!-- Display email as a header and access level -->
|
<!-- Display email as a header and access level -->
|
||||||
<h4>Email</h4>
|
<h4 class="text-primary">Email</h4>
|
||||||
<p id="modalEmail"></p>
|
<p class="margin-top-0" id="modalEmail"></p>
|
||||||
|
|
||||||
<h4>Member Access</h4>
|
<h4 class="text-primary">Member Access</h4>
|
||||||
<p id="modalAccessLevel"></p>
|
<p class="margin-top-0" id="modalAccessLevel"></p>
|
||||||
|
|
||||||
<!-- Dynamic Permissions Details -->
|
<!-- Dynamic Permissions Details -->
|
||||||
<div id="permission_details"></div>
|
<div id="permission_details"></div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue