mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
checkbox listeners
This commit is contained in:
parent
a965ee1844
commit
f6bf5fd09b
2 changed files with 41 additions and 4 deletions
|
@ -416,6 +416,11 @@ export class BaseTable {
|
||||||
*/
|
*/
|
||||||
initShowMoreButtons(){}
|
initShowMoreButtons(){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See function for more details
|
||||||
|
*/
|
||||||
|
initCheckboxListeners(){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads rows in the members list, as well as updates pagination around the members list
|
* Loads rows in the members list, as well as updates pagination around the members list
|
||||||
* based on the supplied attributes.
|
* based on the supplied attributes.
|
||||||
|
@ -462,6 +467,7 @@ export class BaseTable {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.initShowMoreButtons();
|
this.initShowMoreButtons();
|
||||||
|
this.initCheckboxListeners();
|
||||||
|
|
||||||
this.loadModals(data.page, data.total, data.unfiltered_total);
|
this.loadModals(data.page, data.total, data.unfiltered_total);
|
||||||
|
|
||||||
|
|
|
@ -46,12 +46,14 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
// console.log("initialDomainAssignments: " + this.initialDomainAssignments);
|
// console.log("initialDomainAssignments: " + this.initialDomainAssignments);
|
||||||
// console.log("testing domain: " + domain.id);
|
// console.log("testing domain: " + domain.id);
|
||||||
|
// console.log(`this.addedDomains ${JSON.stringify(this.addedDomains)}`)
|
||||||
|
// console.log(`this.removedDomains ${JSON.stringify(this.removedDomains)}`)
|
||||||
let checked = false;
|
let checked = false;
|
||||||
let disabled = false;
|
let disabled = false;
|
||||||
if (
|
if (
|
||||||
(this.initialDomainAssignments.includes(domain.id) ||
|
(this.initialDomainAssignments.includes(domain.id) ||
|
||||||
this.addedDomains.map(obj => obj.id).includes(domain.id)) &&
|
this.addedDomains.map(obj => obj.id).includes(domain.id.toString())) &&
|
||||||
!this.removedDomains.map(obj => obj.id).includes(domain.id)
|
!this.removedDomains.map(obj => obj.id).includes(domain.id.toString())
|
||||||
) {
|
) {
|
||||||
console.log("checked domain: " + domain.id);
|
console.log("checked domain: " + domain.id);
|
||||||
checked = true;
|
checked = true;
|
||||||
|
@ -106,6 +108,35 @@ export class EditMemberDomainsTable extends BaseTable {
|
||||||
.catch(error => console.error('Error fetching domain assignments:', error));
|
.catch(error => console.error('Error fetching domain assignments:', error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initCheckboxListeners() {
|
||||||
|
const checkboxes = this.tableWrapper.querySelectorAll('input[type="checkbox"]');
|
||||||
|
checkboxes.forEach(checkbox => {
|
||||||
|
checkbox.addEventListener('change', () => {
|
||||||
|
const domain = { id: checkbox.value, name: checkbox.name };
|
||||||
|
|
||||||
|
if (checkbox.checked) {
|
||||||
|
this.updateDomainLists(domain, this.removedDomains, this.addedDomains);
|
||||||
|
} else {
|
||||||
|
this.updateDomainLists(domain, this.addedDomains, this.removedDomains);
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(`this.addedDomains ${JSON.stringify(this.addedDomains)}`)
|
||||||
|
// console.log(`this.removedDomains ${JSON.stringify(this.removedDomains)}`)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDomainLists(domain, fromList, toList) {
|
||||||
|
const index = fromList.findIndex(item => item.id === domain.id && item.name === domain.name);
|
||||||
|
|
||||||
|
if (index > -1) {
|
||||||
|
fromList.splice(index, 1); // Remove from the `fromList` if it exists
|
||||||
|
} else {
|
||||||
|
toList.push(domain); // Add to the `toList` if not already there
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initEditMemberDomainsTable() {
|
export function initEditMemberDomainsTable() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue