|
159 | 159 |
|
160 | 160 | if ($clang_id === rex_clang::getStartId() || true !== $form->isEditMode()) { |
161 | 161 | if ([] !== $cookies) { |
162 | | - // Eigene HTML-Darstellung mit Toggles und Config-Buttons |
163 | | - $serviceHtml = RexFormSupport::getActiveServiceToggleList(rex_i18n::msg('consent_manager_cookies'), $cookies, $clang_id, 'cookie', $form); |
164 | | - $form->addRawField($serviceHtml); |
| 162 | + // Styling und Buttons |
| 163 | + $html = '<div id="cm-cookie-buttons-wrapper" class="btn-group btn-group-xs" style="margin-bottom: 5px;">'; |
| 164 | + $html .= '<button type="button" class="btn btn-info cm-select-all"><i class="fa fa-check-square-o"></i> Alle auswählen</button>'; |
| 165 | + $html .= '<button type="button" class="btn btn-default cm-deselect-all"><i class="fa fa-square-o"></i> Alle abwählen</button>'; |
| 166 | + $html .= '</div>'; |
| 167 | + |
| 168 | + $html .= '<script nonce="' . rex_response::getNonce() . '"> |
| 169 | + jQuery(function($) { |
| 170 | + // Checkboxen selektieren via Klasse |
| 171 | + var $checkboxes = $(".cm-cookie-checkbox-item"); |
| 172 | + |
| 173 | + // Styling Klasse auf das Container-Element der Checkboxen anwenden |
| 174 | + if ($checkboxes.length > 0) { |
| 175 | + $checkboxes.first().closest(".rex-form-group").addClass("consent-manager-cookie-list"); |
| 176 | + } |
| 177 | + |
| 178 | + // Buttons Wrapper |
| 179 | + var $btnWrapper = $("#cm-cookie-buttons-wrapper"); |
| 180 | + |
| 181 | + // Optional: Label des Button-Containers leeren, falls vorhanden |
| 182 | + $btnWrapper.closest(".rex-form-group").find("dt").html(" "); |
| 183 | + |
| 184 | + // Select All Handler |
| 185 | + $btnWrapper.on("click", ".cm-select-all", function() { |
| 186 | + $checkboxes.prop("checked", true); |
| 187 | + }); |
| 188 | + |
| 189 | + // Deselect All Handler |
| 190 | + $btnWrapper.on("click", ".cm-deselect-all", function() { |
| 191 | + $checkboxes.prop("checked", false); |
| 192 | + }); |
| 193 | + }); |
| 194 | + </script>'; |
| 195 | + |
| 196 | + $html .= '<style nonce="' . rex_response::getNonce() . '"> |
| 197 | + .consent-manager-cookie-list .checkbox { |
| 198 | + display: inline-block; |
| 199 | + width: 49%; |
| 200 | + margin: 5px 0; |
| 201 | + vertical-align: top; |
| 202 | + padding-right: 10px; |
| 203 | + box-sizing: border-box; |
| 204 | + background: #f9f9f9; |
| 205 | + padding: 8px; |
| 206 | + border-radius: 4px; |
| 207 | + border: 1px solid #e0e0e0; |
| 208 | + } |
| 209 | + .consent-manager-cookie-list .checkbox:hover { |
| 210 | + background: #f0f0f0; |
| 211 | + } |
| 212 | + .consent-manager-cookie-list .checkbox label { |
| 213 | + width: 100%; |
| 214 | + cursor: pointer; |
| 215 | + } |
| 216 | + </style>'; |
| 217 | + |
| 218 | + $form->addRawField($html); |
| 219 | + |
| 220 | + $field = $form->addCheckboxField('cookie'); |
| 221 | + $field->setAttribute('class', 'cm-cookie-checkbox-item'); // Klasse für JS-Selektor |
| 222 | + $field->setLabel(rex_i18n::msg('consent_manager_cookies')); |
| 223 | + foreach ($cookies as $v) { |
| 224 | + // Name und UID speichern |
| 225 | + $field->addOption(rex_escape($v['service_name']), $v['uid']); |
| 226 | + } |
165 | 227 | } |
166 | 228 | } else { |
167 | 229 | if ([] !== $cookies) { |
|
175 | 237 | } |
176 | 238 | foreach ($cookies as $v) { |
177 | 239 | $checked = (in_array((string) $v['uid'], $checkedBoxes, true)) ? '|1|' : ''; |
178 | | - $checkboxes[] = [$checked, $v['uid']]; |
| 240 | + $checkboxes[] = [$checked, rex_escape($v['service_name'])]; |
179 | 241 | } |
180 | | - $form->addRawField(RexFormSupport::getServiceToggleList(rex_i18n::msg('consent_manager_cookies'), $checkboxes, $clang_id)); /** @phpstan-ignore-line */ |
| 242 | + $form->addRawField(RexFormSupport::getFakeCheckbox(rex_i18n::msg('consent_manager_cookies'), $checkboxes)); /** @phpstan-ignore-line */ |
181 | 243 | } |
182 | 244 | } |
183 | 245 |
|
184 | | - // Bugfix: Cookie-Auswahl speichern (da addRawField genutzt wird, muss manuell gespeichert werden) |
185 | | - if ($clang_id === rex_clang::getStartId() || true !== $form->isEditMode()) { |
186 | | - rex_extension::register('REX_FORM_SAVING', static function (rex_extension_point $ep) { |
187 | | - $form = $ep->getParam('form'); |
188 | | - if ($form->getTableName() !== rex::getTable('consent_manager_cookiegroup')) { |
189 | | - return; |
190 | | - } |
191 | | - |
192 | | - $cookies = rex_request('cookie', 'array', []); |
193 | | - $cookieString = ''; |
194 | | - if ([] !== $cookies) { |
195 | | - $cookieString = '|' . implode('|', $cookies) . '|'; |
196 | | - } |
197 | | - |
198 | | - $sql = $ep->getParam('sql'); |
199 | | - $sql->setValue('cookie', $cookieString); |
200 | | - }); |
201 | | - } |
202 | | - |
203 | 246 | $title = $form->isEditMode() ? rex_i18n::msg('consent_manager_cookiegroup_edit') : rex_i18n::msg('consent_manager_cookiegroup_add'); |
204 | 247 | $content = $form->get(); |
205 | 248 |
|
|
0 commit comments