diff --git a/CHANGELOG.md b/CHANGELOG.md index 825e679..f1be6b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Use translated itemtype name for reservation item select groups - Filter the '0' empty-selection sentinel in Table and LDAP select questions - Fix Table question column type edge cases diff --git a/public/js/modules/ReservationQuestionWidget.js b/public/js/modules/ReservationQuestionWidget.js index fd176a6..8ff5e92 100644 --- a/public/js/modules/ReservationQuestionWidget.js +++ b/public/js/modules/ReservationQuestionWidget.js @@ -93,22 +93,22 @@ export class ReservationQuestionWidget { $select.on('select2:clear select2:unselecting', () => this.#onItemCleared()); } - /** Groups flat {id, text, itemtype} results into Select2 optgroups per itemtype. */ + /** Groups flat {id, text, itemtype, itemtype_label} results into Select2 optgroups per itemtype. */ #groupResultsByItemtype(data) { const groups = new Map(); for (const item of data) { - const group_label = item.itemtype || ''; - if (!groups.has(group_label)) { - groups.set(group_label, []); + const key = item.itemtype || ''; + if (!groups.has(key)) { + groups.set(key, { text: item.itemtype_label || key, children: [] }); } - groups.get(group_label).push({ + groups.get(key).children.push({ id: item.id, text: item.text, }); } - return Array.from(groups, ([text, children]) => ({ text, children })); + return Array.from(groups.values()); } #onItemSelected() { diff --git a/src/Controller/ReservableItemsController.php b/src/Controller/ReservableItemsController.php index 92bb148..bc64c36 100644 --- a/src/Controller/ReservableItemsController.php +++ b/src/Controller/ReservableItemsController.php @@ -78,7 +78,7 @@ public function __invoke(Request $request): Response /** * @param class-string $itemtype - * @return array + * @return array */ private function getReservableItemsForType(string $itemtype, string $search): array { @@ -114,10 +114,12 @@ private function getReservableItemsForType(string $itemtype, string $search): ar } $id = $row['id'] ?? null; + $itemtype_label = $itemtype::getTypeName(1); $results[] = [ 'id' => is_numeric($id) ? (int) $id : 0, - 'text' => sprintf('%s (%s)', $item->getName(), $itemtype::getTypeName(1)), + 'text' => sprintf('%s (%s)', $item->getName(), $itemtype_label), 'itemtype' => $itemtype, + 'itemtype_label' => $itemtype_label, ]; }