-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiSelectAndDelete.js
47 lines (42 loc) · 1.86 KB
/
MultiSelectAndDelete.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { filterMembersArrayDataAndRerender } from './AdminUIScript.js'
const multiDeleteButtonElement = document.getElementById('multiDeleteButton');
const parentCheckBoxElement = document.getElementById('parentCheckBox');
function highlightRow(memberId,enableStatus) {
if (enableStatus == true) {
document.getElementById(`member${memberId}`).style.backgroundColor = '#e8e8e8';
}
else {
document.getElementById(`member${memberId}`).style.backgroundColor = 'white';
}
}
parentCheckBoxElement.addEventListener('click', function () {
if (parentCheckBoxElement.checked) {
const currentPageCheckboxes = document.querySelectorAll('input[name="memberCheckBox"]');
currentPageCheckboxes.forEach(checkBoxElement => {
checkBoxElement.checked = true;
let memberId = checkBoxElement.id.split('checkbox')[1]
highlightRow(memberId,checkBoxElement.checked)
})
}
else {
const currentPageCheckboxes = document.querySelectorAll('input[name="memberCheckBox"]');
currentPageCheckboxes.forEach(checkBoxElement => {
checkBoxElement.checked = false;
let memberId = checkBoxElement.id.split('checkbox')[1]
highlightRow(memberId,checkBoxElement.checked)
})
}
})
multiDeleteButtonElement.addEventListener('click', function () {
console.log('delete');
const checkedBoxes = document.querySelectorAll('input[name="memberCheckBox"]:checked');
const checkedMemberRowsIds = []
checkedBoxes.forEach(checkbox => {
let checkBoxId = checkbox.id
let memberId = parseInt(checkBoxId.split('checkbox')[1]);
console.log(memberId);
checkedMemberRowsIds.push(memberId);
})
parentCheckBoxElement.checked = false;
filterMembersArrayDataAndRerender(checkedMemberRowsIds);
})