mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-26 12:38:36 +02:00
added comments to javascript
This commit is contained in:
parent
20f0a492aa
commit
7fc9815cee
1 changed files with 96 additions and 61 deletions
|
@ -1,16 +1,24 @@
|
||||||
|
|
||||||
import { BaseTable } from './table-base.js';
|
import { BaseTable } from './table-base.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EditMemberDomainsTable is used for PortfolioMember and PortfolioInvitedMember
|
||||||
|
* Domain Editing.
|
||||||
|
*
|
||||||
|
* This table has additional functionality for tracking and making changes
|
||||||
|
* to domains assigned to the member/invited member.
|
||||||
|
*/
|
||||||
export class EditMemberDomainsTable extends BaseTable {
|
export class EditMemberDomainsTable extends BaseTable {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super('edit-member-domain');
|
super('edit-member-domain');
|
||||||
this.displayName = "domain";
|
this.displayName = "domain";
|
||||||
this.currentSortBy = 'name';
|
this.currentSortBy = 'name';
|
||||||
this.initialDomainAssignments = [];
|
this.initialDomainAssignments = []; // list of initially assigned domains
|
||||||
this.initialDomainAssignmentsOnlyMember = [];
|
this.initialDomainAssignmentsOnlyMember = []; // list of initially assigned domains
|
||||||
this.addedDomains = [];
|
// which are readonly
|
||||||
this.removedDomains = [];
|
this.addedDomains = []; // list of domains added to member
|
||||||
|
this.removedDomains = []; // list of domains removed from member
|
||||||
this.initializeDomainAssignments();
|
this.initializeDomainAssignments();
|
||||||
this.initCancelEditDomainAssignmentButton();
|
this.initCancelEditDomainAssignmentButton();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +28,11 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
getDataObjects(data) {
|
getDataObjects(data) {
|
||||||
return data.domains;
|
return data.domains;
|
||||||
}
|
}
|
||||||
|
/** getDomainAssignmentSearchParams is used to prepare search to populate
|
||||||
|
* initialDomainAssignments and initialDomainAssignmentsOnlyMember
|
||||||
|
*
|
||||||
|
* searches with memberOnly True so that only domains assigned to the member are returned
|
||||||
|
*/
|
||||||
getDomainAssignmentSearchParams(portfolio) {
|
getDomainAssignmentSearchParams(portfolio) {
|
||||||
let searchParams = new URLSearchParams();
|
let searchParams = new URLSearchParams();
|
||||||
let emailValue = this.portfolioElement ? this.portfolioElement.getAttribute('data-email') : null;
|
let emailValue = this.portfolioElement ? this.portfolioElement.getAttribute('data-email') : null;
|
||||||
|
@ -35,6 +48,11 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
searchParams.append("member_only", memberOnly);
|
searchParams.append("member_only", memberOnly);
|
||||||
return searchParams;
|
return searchParams;
|
||||||
}
|
}
|
||||||
|
/** getSearchParams extends base class getSearchParams.
|
||||||
|
*
|
||||||
|
* additional searchParam for this table is checkedDomains. This is used to allow
|
||||||
|
* for backend sorting by domains which are 'checked' in the form.
|
||||||
|
*/
|
||||||
getSearchParams(page, sortBy, order, searchTerm, status, portfolio) {
|
getSearchParams(page, sortBy, order, searchTerm, status, portfolio) {
|
||||||
let searchParams = super.getSearchParams(page, sortBy, order, searchTerm, status, portfolio);
|
let searchParams = super.getSearchParams(page, sortBy, order, searchTerm, status, portfolio);
|
||||||
// Add checkedDomains to searchParams
|
// Add checkedDomains to searchParams
|
||||||
|
@ -105,6 +123,11 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
`;
|
`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* initializeDomainAssignments searches via ajax on page load for domains assigned to
|
||||||
|
* member. It populates both initialDomainAssignments and initialDomainAssignmentsOnlyMember.
|
||||||
|
* It is called once per page load, but not called with subsequent table changes.
|
||||||
|
*/
|
||||||
initializeDomainAssignments() {
|
initializeDomainAssignments() {
|
||||||
const baseUrlValue = this.getBaseUrl()?.innerHTML ?? null;
|
const baseUrlValue = this.getBaseUrl()?.innerHTML ?? null;
|
||||||
if (!baseUrlValue) return;
|
if (!baseUrlValue) return;
|
||||||
|
@ -130,7 +153,12 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
})
|
})
|
||||||
.catch(error => console.error('Error fetching domain assignments:', error));
|
.catch(error => console.error('Error fetching domain assignments:', error));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Initializes listeners on checkboxes in the table. Checkbox listeners are used
|
||||||
|
* in this case to track changes to domain assignments in js (addedDomains and removedDomains)
|
||||||
|
* before changes are saved.
|
||||||
|
* initCheckboxListeners is called each time table is loaded.
|
||||||
|
*/
|
||||||
initCheckboxListeners() {
|
initCheckboxListeners() {
|
||||||
const checkboxes = this.tableWrapper.querySelectorAll('input[type="checkbox"]');
|
const checkboxes = this.tableWrapper.querySelectorAll('input[type="checkbox"]');
|
||||||
checkboxes.forEach(checkbox => {
|
checkboxes.forEach(checkbox => {
|
||||||
|
@ -142,13 +170,16 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
} else {
|
} else {
|
||||||
this.updateDomainLists(domain, this.addedDomains, this.removedDomains);
|
this.updateDomainLists(domain, this.addedDomains, this.removedDomains);
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(`this.addedDomains ${JSON.stringify(this.addedDomains)}`)
|
|
||||||
// console.log(`this.removedDomains ${JSON.stringify(this.removedDomains)}`)
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Helper function which updates domain lists. When called, if domain is in the fromList,
|
||||||
|
* it removes it; if domain is not in the toList, it is added to the toList.
|
||||||
|
* @param {*} domain - object containing the domain id and name
|
||||||
|
* @param {*} fromList - list of domains
|
||||||
|
* @param {*} toList - list of domains
|
||||||
|
*/
|
||||||
updateDomainLists(domain, fromList, toList) {
|
updateDomainLists(domain, fromList, toList) {
|
||||||
const index = fromList.findIndex(item => item.id === domain.id && item.name === domain.name);
|
const index = fromList.findIndex(item => item.id === domain.id && item.name === domain.name);
|
||||||
|
|
||||||
|
@ -158,7 +189,11 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
toList.push(domain); // Add to the `toList` if not already there
|
toList.push(domain); // Add to the `toList` if not already there
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* initializes the Cancel button on the Edit domains page.
|
||||||
|
* Cancel triggers modal in certain conditions and the initialization for the modal is done
|
||||||
|
* in this function.
|
||||||
|
*/
|
||||||
initCancelEditDomainAssignmentButton() {
|
initCancelEditDomainAssignmentButton() {
|
||||||
const cancelEditDomainAssignmentButton = document.getElementById('cancel-edit-domain-assignments');
|
const cancelEditDomainAssignmentButton = document.getElementById('cancel-edit-domain-assignments');
|
||||||
if (!cancelEditDomainAssignmentButton) {
|
if (!cancelEditDomainAssignmentButton) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue