diff --git a/static/index.html b/static/index.html index 7079c82..c891294 100644 --- a/static/index.html +++ b/static/index.html @@ -5177,8 +5177,7 @@ async function rpLoadTechs() { const savedTechs = JSON.parse(localStorage.getItem('rpTechs') || '[]'); try { - const r = await fetch('/api/workorders/technicians'); - const data = await r.json(); + const data = await api('/api/workorders/technicians'); const container = document.getElementById('rpTechCheckboxes'); // Keep the "All" checkbox, remove existing tech checkboxes container.querySelectorAll('label:not(:first-child)').forEach(el => el.remove()); @@ -5270,8 +5269,7 @@ if (q.length < 2) { container.innerHTML = ''; return; } container.innerHTML = '
Searching...
'; try { - const r = await fetch('/api/workorders/search?q=' + encodeURIComponent(q) + '&limit=30'); - const data = await r.json(); + const data = await api('/api/workorders/search?q=' + encodeURIComponent(q) + '&limit=30'); if (!data.results || data.results.length === 0) { container.innerHTML = '
No results
'; return; @@ -5330,8 +5328,7 @@ rpShowLoading('Loading today\u2019s work orders...'); try { const params = techs.map(t => 'tech=' + encodeURIComponent(t)).join('&'); - const r = await fetch('/api/workorders/today?' + params); - const data = await r.json(); + const data = await api('/api/workorders/today?' + params); if (!data.workorders || data.workorders.length === 0) { rpHideLoading(); return alert('No work orders found for today'); @@ -5368,12 +5365,11 @@ let woDetails = preloaded || null; if (!woDetails) { try { - const r = await fetch('/api/workorders/lookup', { + const data = await api('/api/workorders/lookup', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ids: woIds }), }); - const data = await r.json(); woDetails = data.found || []; } catch (e) { rpHideLoading(); @@ -5388,12 +5384,11 @@ }; try { - const r = await fetch('/api/route/optimize', { + const data = await api('/api/route/optimize', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), }); - const data = await r.json(); rpHideLoading(); rpDisplayRoute(data, woDetails); } catch (e) { @@ -5514,8 +5509,7 @@ overlay.style.display = ''; modal.style.display = ''; try { - const r = await fetch('/api/workorders/' + encodeURIComponent(woName) + '/asset'); - const data = await r.json(); + const data = await api('/api/workorders/' + encodeURIComponent(woName) + '/asset'); const d = data.details || {}; let html = '
' + esc(data.asset_name || woName) + '
'; const sections = {};