From a8d23f91f6cfd803be1ecaae4c8d1b5e1268a699 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 18 Jul 2025 16:35:46 +0200 Subject: [locationinfo] Parametrize panel type configuration Avoids a lot of copy and paste and duplicate work in php and html part, for example explicitly handling every config variable for a specific panel when displaying the config dialog, when saving the config, and when loading the config for displaying the panel. This also parametrizes enums, limits and ranges, so dropdowns can be rendered automatically, validity of selected option can be checked, and putting numeric settings into bounds all happens generically. Edit dialog for DEFAULT panel is still completely custom, as it has too much special sauce going on with the room config overrides. URL-panel is half-half, but SUMMARY and UPCOMING are entirely generic now. --- inc/request.inc.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'inc/request.inc.php') diff --git a/inc/request.inc.php b/inc/request.inc.php index 0b0600da..7edb8140 100644 --- a/inc/request.inc.php +++ b/inc/request.inc.php @@ -123,7 +123,14 @@ class Request } foreach ($params as $type => $list) { foreach ($list as $field => $limits) { - $default = $limits['default'] ?? false; + if ($type === 'bool') { + // An unchecked checkbox will not have its key in the post data, so self::handle would fall back + // to the default value. If the default is true, this would mean the parameter would be set to + // true, which is incorrect. + $default = false; + } else { + $default = $limits['default'] ?? false; + } $value = self::handle($input, $field, $default, $type); if (isset($limits['min']) && $value < $limits['min']) { $value = $limits['min']; @@ -132,7 +139,7 @@ class Request $value = $limits['max']; } if (isset($limits['enum']) && !in_array($value, $limits['enum'])) { - $value = array_shift($limits['enum']); + $value = $limits['default'] ?? array_shift($limits['enum']); } $out[$field] = $value; } -- cgit v1.2.3-55-g7522