-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreports.hbs
52 lines (43 loc) · 1.49 KB
/
reports.hbs
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
<section class='adminSection'>
<div class='adminItem'>
<h2>Generate Report</h2>
<div class='formContainer'>
<form action='/admin/report/generate' method='post'>
<select name='type' id='type' required>
<option disabled hidden selected value=''>Select report type</option>
{{#each types}}
<option value='{{key}}'>{{value}}</option>
{{/each}}
</select>
<select name='target' id='target' required>
<option disabled hidden selected value=''>Select report target</option>
</select>
<input type='submit' class='btn btn--primary btn--full' value='Generate report'/>
</form>
</div>
</div>
</section>
<script>
const targets = {{{targets}}};
const cache = {};
const typeSelect = document.querySelector('form select[name="type"]');
const targetSelect = document.querySelector('form select[name="target"]');
typeSelect.addEventListener('change', (e) => {
const type = typeSelect.value;
const placeholder = document.createElement('option');
placeholder.setAttribute('disabled', true);
placeholder.setAttribute('hidden', true);
placeholder.setAttribute('selected', true);
placeholder.setAttribute('value', '');
placeholder.innerText = 'Select report target';
if (!cache[type]) {
cache[type] = targets[type].map(({ id, name }) => {
const elem = document.createElement('option');
elem.setAttribute('value', id);
elem.innerText = name;
return elem;
});
}
targetSelect.replaceChildren(placeholder, ...cache[type]);
});
</script>