From 76ac5aada8fb8cac2da31c0943ffee886f7f70e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Gla=CC=88ser?= Date: Mon, 15 Jun 2026 16:48:50 +0200 Subject: [PATCH] Bestellungen-Suche wieder auf Fragment laden --- modules/shared/auth/ui/home.php | 42 +++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/modules/shared/auth/ui/home.php b/modules/shared/auth/ui/home.php index c6d1553..0579f7b 100644 --- a/modules/shared/auth/ui/home.php +++ b/modules/shared/auth/ui/home.php @@ -603,15 +603,43 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo " });"; echo " return url;"; echo " };"; + echo " const replaceFragment = (html) => {"; + echo " const doc = new DOMParser().parseFromString(html, 'text/html');"; + echo " const fragment = doc.querySelector('[data-bestellungen-content]');"; + echo " if (!fragment) {"; + echo " return false;"; + echo " }"; + echo " contentRoot.innerHTML = fragment.innerHTML;"; + echo " table = getTable();"; + echo " return !!table;"; + echo " };"; echo " const loadFragment = async (params, updateHistory = true) => {"; echo " if (searchTimer) { window.clearTimeout(searchTimer); searchTimer = null; }"; echo " const url = buildUrl(params);"; - echo " const targetUrl = url.toString();"; - echo " if (updateHistory) {"; - echo " window.location.assign(targetUrl);"; - echo " return;"; + echo " const activeRequest = ++requestToken;"; + echo " const currentTable = getTable();"; + echo " if (currentTable) { currentTable.setAttribute('aria-busy', 'true'); }"; + echo " try {"; + echo " const response = await fetch(url.toString(), { credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } });"; + echo " const html = await response.text();"; + echo " if (activeRequest !== requestToken) {"; + echo " return;"; + echo " }"; + echo " const replaced = replaceFragment(html);"; + echo " if (replaced && updateHistory) {"; + echo " const historyUrl = new URL(url.toString());"; + echo " historyUrl.searchParams.delete('bestellungen_fragment');"; + echo " window.history.replaceState({}, '', historyUrl);"; + echo " }"; + echo " bindTable();"; + echo " } finally {"; + echo " if (activeRequest === requestToken) {"; + echo " table = getTable();"; + echo " if (table) {"; + echo " table.removeAttribute('aria-busy');"; + echo " }"; + echo " }"; echo " }"; - echo " window.location.replace(targetUrl);"; echo " };"; echo " const bindTable = () => {"; echo " table = getTable();"; @@ -629,7 +657,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo " bestellungen_sort: getSortColumn(),"; echo " bestellungen_dir: getSortDirection(),"; echo " bestellungen_limit: getPageSize(),"; - echo " }, false);"; + echo " });"; echo " }, 250);"; echo " });"; echo " }"; @@ -703,7 +731,7 @@ function render_auth_home_page(array $user, array $otcProducts = [], array $best echo " bestellungen_sort: getSortColumn(),"; echo " bestellungen_dir: getSortDirection(),"; echo " bestellungen_limit: getPageSize(),"; - echo " }, false);"; + echo " });"; echo " }, 250);"; echo " });"; echo " document.addEventListener('keydown', (event) => {";