-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPermit.js
89 lines (78 loc) · 3.07 KB
/
Permit.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class PermitManager
{
static permits = ["Permit 1", "Permit 2", "Permit 3"];
// Add a row to permit-list, the user will then select an option
static addPermitToList()
{
const permitListStr = PermitManager.permits.reduce((acc, cur, i) =>
{
return acc = acc + `<option value="${i}">${cur}</option>`
}, ``);
const list = document.querySelector('#permit-list');
const row = document.createElement('tr');
row.className = "grey-row";
row.innerHTML = `
<td>
<select class="form-select form-select-lg mb-1 mt-1" aria-label=".form-select-lg example">
<option class="def-opt" selected>Select Permit Type</option>
${permitListStr}
</select>
</td>
<td><a class="btn btn-danger btn-sm mt-2 delete">${deleteButtonSvg}</a></td>
`;
list.appendChild(row);
}
static deletePermit(e)
{
e.stopPropagation();
let el = e.target;
// we come here from an event handler placed on the permit list
// so, we first verify that the delete button was clicked
if (el.classList.contains('delete'))
{
el.parentElement.parentElement.remove(); // remove the tr
}
if (el.parentElement.classList.contains('delete')) // hit svg
{
el.parentElement.parentElement.parentElement.remove(); // remove the tr
}
if (el.parentElement.parentElement.classList.contains('delete')) // hit svg path
{
el.parentElement.parentElement.parentElement.parentElement.remove(); // remove the tr
}
}
static populatePermits(permits)
{
const permitList = document.querySelector('#permit-list');
// Clear any permits that may have been previously populated
permitList.innerHTML = '';
// Populate permit-list with the permits that were stored for this queue
for (let permit of permits)
{
const permitListStr = PermitManager.permits.reduce((acc, cur, i) =>
{
return acc = acc + `<option value="${i}" ${permit === cur ? "selected" : ''}>${cur}</option>`
}, ``);
const row = document.createElement('tr');
row.className = "grey-row";
row.innerHTML = `
<td>
<select class="form-select form-select-lg mb-3 w-75" aria-label=".form-select-lg example">
<option>Select Permit Type</option>
${permitListStr}
</select>
</td>
<td><a class="btn btn-danger btn-sm mt-2 delete">${deleteButtonSvg}</a></td>
`;
permitList.appendChild(row);
}
}
}
// Event: Remove a permit
document.querySelector('#permit-list')
.addEventListener('click', (e) => PermitManager.deletePermit(e));
// Event: Add new permit
document.querySelector("#addPermit").addEventListener('click', (e) =>
{
PermitManager.addPermitToList();
});