|
34 | 34 | white-space: nowrap; |
35 | 35 | cursor: pointer; |
36 | 36 | } |
| 37 | +.apt-type-dropdown-menu input[type="checkbox"] { |
| 38 | + vertical-align: middle; |
| 39 | + margin-right: 4px; |
| 40 | + position: relative; |
| 41 | + top: -1px; |
| 42 | +} |
37 | 43 | .apt-type-dropdown-menu label:hover { |
38 | 44 | background: #0069d9; |
39 | 45 | color: #fff; |
|
68 | 74 | }); |
69 | 75 |
|
70 | 76 | if (!isOpen) { |
| 77 | + var checkboxes = menu.querySelectorAll('input[type="checkbox"]'); |
| 78 | + var allTypesCheckbox = checkboxes[0]; |
| 79 | + |
| 80 | + // If "alle Typen" is selected, visually select all other checkboxes too |
| 81 | + if (allTypesCheckbox.checked) { |
| 82 | + checkboxes.forEach(function(cb) { |
| 83 | + cb.checked = true; |
| 84 | + }); |
| 85 | + } |
| 86 | + |
71 | 87 | // Save original state before opening |
72 | 88 | originalAptTypeState = []; |
73 | | - menu.querySelectorAll('input[type="checkbox"]').forEach(function(cb) { |
| 89 | + checkboxes.forEach(function(cb) { |
74 | 90 | originalAptTypeState.push(cb.checked); |
75 | 91 | }); |
76 | 92 | menu.style.display = 'block'; |
|
84 | 100 | function onAptTypeChanged(checkbox, isAllTypes) { |
85 | 101 | var menu = checkbox.closest('.apt-type-dropdown-menu'); |
86 | 102 | var checkboxes = menu.querySelectorAll('input[type="checkbox"]'); |
| 103 | + var allTypesCheckbox = checkboxes[0]; |
87 | 104 |
|
88 | 105 | if (isAllTypes) { |
89 | 106 | // "alle Typen" toggled - sync all others to same state |
90 | 107 | var newState = checkbox.checked; |
91 | 108 | checkboxes.forEach(function(cb) { |
92 | | - if (cb !== checkbox) cb.checked = newState; |
| 109 | + if (cb !== allTypesCheckbox) cb.checked = newState; |
| 110 | + }); |
| 111 | + // Never allow empty selection - if unchecking all, recheck "alle Typen" |
| 112 | + if (!newState) { |
| 113 | + allTypesCheckbox.checked = true; |
| 114 | + } |
| 115 | + } |
| 116 | + else { |
| 117 | + // Check if all or none of the regular checkboxes are selected |
| 118 | + var allSelected = true; |
| 119 | + var noneSelected = true; |
| 120 | + checkboxes.forEach(function(cb) { |
| 121 | + if (cb !== allTypesCheckbox) { |
| 122 | + if (!cb.checked) allSelected = false; |
| 123 | + if (cb.checked) noneSelected = false; |
| 124 | + } |
93 | 125 | }); |
| 126 | + // If none selected, auto-select "alle Typen" (and all others) |
| 127 | + if (noneSelected) { |
| 128 | + checkboxes.forEach(function(cb) { |
| 129 | + cb.checked = true; |
| 130 | + }); |
| 131 | + } |
| 132 | + else { |
| 133 | + allTypesCheckbox.checked = allSelected; |
| 134 | + } |
94 | 135 | } |
95 | 136 | // Don't submit - wait for OK/Cancel/outside click |
96 | 137 | } |
|
139 | 180 | ><#AptTypeCheckbox/> <#AptTypeLabel/></label |
140 | 181 | ></#AptTypesRepetition |
141 | 182 | ><div class="apt-type-buttons" |
142 | | - ><button type="button" onclick="submitAptTypes()">OK</button |
143 | 183 | ><button type="button" |
144 | 184 | onclick="cancelAptTypes(this)">Cancel</button |
| 185 | + ><button type="button" onclick="submitAptTypes()">OK</button |
145 | 186 | ></div |
146 | 187 | ></div |
147 | 188 | ></div |
|
0 commit comments