|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +const selectAllCheckbox = document.getElementById('select-all'); |
3 | 4 | let ROW_CHECKBOXES = null; |
4 | 5 | let PAGE = 1; |
5 | 6 |
|
6 | 7 | document.addEventListener('DOMContentLoaded', function () { |
7 | 8 |
|
8 | 9 | // enabling/disabling the edit button based on checkbox selection |
9 | | - const selectAllCheckbox = document.getElementById('select-all'); |
10 | 10 | ROW_CHECKBOXES = document.querySelectorAll('.row-checkbox'); |
11 | | - |
12 | | - selectAllCheckbox.addEventListener('change', function () { |
13 | | - ROW_CHECKBOXES.forEach(checkbox => { |
14 | | - checkbox.checked = selectAllCheckbox.checked; |
15 | | - }); |
16 | | - updateEditButtonState(); |
17 | | - listTxElements(); |
18 | | - }); |
19 | | - |
20 | | - ROW_CHECKBOXES.forEach(checkbox => { |
21 | | - checkbox.checked = false; |
22 | | - checkbox.addEventListener('change', function () { |
23 | | - if (!this.checked) { |
24 | | - selectAllCheckbox.checked = false; |
25 | | - } else if (Array.from(ROW_CHECKBOXES).every(cb => cb.checked)) { |
26 | | - selectAllCheckbox.checked = true; |
27 | | - } |
28 | | - updateEditButtonState(); |
29 | | - listTxElements(); |
30 | | - }); |
31 | | - }); |
| 11 | + selectAllCheckbox.addEventListener('change', set_all_checkboxes); |
| 12 | + ROW_CHECKBOXES.forEach(checkbox => set_row_checkboxes(checkbox)); |
32 | 13 |
|
33 | 14 | // Tag Chip Bullets |
34 | 15 | const inputTagContainers = [ |
@@ -68,6 +49,35 @@ document.addEventListener('DOMContentLoaded', function () { |
68 | 49 | // -- DOM Functions ----------------------------------------------------------- |
69 | 50 | // ---------------------------------------------------------------------------- |
70 | 51 |
|
| 52 | +/** |
| 53 | + * Set all checkboxes to the state of the headerbox |
| 54 | + */ |
| 55 | +function set_all_checkboxes() { |
| 56 | + ROW_CHECKBOXES.forEach(checkbox => { |
| 57 | + checkbox.checked = this.checked; |
| 58 | + }); |
| 59 | + updateEditButtonState(); |
| 60 | + listTxElements(); |
| 61 | +} |
| 62 | + |
| 63 | +/** |
| 64 | + * Set an eventlistener for every box and change the header when unselected |
| 65 | + * |
| 66 | + * @param {DOMElement} checkbox |
| 67 | + */ |
| 68 | +function set_row_checkboxes(checkbox){ |
| 69 | + checkbox.checked = false; |
| 70 | + checkbox.addEventListener('change', function () { |
| 71 | + if (!this.checked) { |
| 72 | + selectAllCheckbox.checked = false; |
| 73 | + } else if (Array.from(ROW_CHECKBOXES).every(cb => cb.checked)) { |
| 74 | + selectAllCheckbox.checked = true; |
| 75 | + } |
| 76 | + updateEditButtonState(); |
| 77 | + listTxElements(); |
| 78 | + }); |
| 79 | +} |
| 80 | + |
71 | 81 | /** |
72 | 82 | * Clears information from a result Box |
73 | 83 | * |
@@ -384,6 +394,12 @@ function loadMore() { |
384 | 394 |
|
385 | 395 | // Append new Rows |
386 | 396 | document.querySelector('.transactions tbody').innerHTML += responseText; |
| 397 | + |
| 398 | + // enabling/disabling the edit button based on checkbox selection |
| 399 | + const selectAllCheckbox = document.getElementById('select-all'); |
| 400 | + ROW_CHECKBOXES = document.querySelectorAll('.row-checkbox'); |
| 401 | + selectAllCheckbox.addEventListener('change', set_all_checkboxes); |
| 402 | + ROW_CHECKBOXES.forEach(checkbox => set_row_checkboxes(checkbox)); |
387 | 403 | }); |
388 | 404 |
|
389 | 405 | // Call URI |
|
0 commit comments