Corriger les liens et la synchronisation i-CAD

This commit is contained in:
Alexandre NOEL 2026-10-01 22:33:41 +02:00
commit 9ff26ad9be
10 changed files with 83 additions and 23 deletions

View file

@ -1160,6 +1160,7 @@ document.addEventListener('DOMContentLoaded', () => {
</script>
<script>
(function() {
const form = document.getElementById('form-icad-refresh');
const btn = document.getElementById('btn-icad-refresh');
const body = document.getElementById('icad-card-body');
const tr = <?= json_encode(['error' => t('animal.icad_error'), 'empty' => t('animal.no_icad'), 'date' =>
@ -1170,7 +1171,7 @@ document.addEventListener('DOMContentLoaded', () => {
'appearance' => t('animal.appearance'), 'history' => t('animal.icad_history'), 'fetching' => t(
'animal.icad_fetching'), 'fetchError' => t('animal.icad_fetch_error')
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?> ;
if (!btn || !body) return;
if (!form || !btn || !body) return;
function esc(s) {
return (s ?? '').toString()
@ -1240,8 +1241,8 @@ ${ownerHtml}
`;
}
async function refresh() {
const id = btn.dataset.animalId;
async function refresh(event) {
event.preventDefault();
btn.disabled = true;
const oldTxt = btn.innerText;
btn.innerText = '…';
@ -1256,12 +1257,12 @@ ${ownerHtml}
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
id,
force: '1',
csrf: <?= json_encode(Auth::csrf()) ?>
})
credentials: 'same-origin',
body: new URLSearchParams(new FormData(form))
});
if (!r.ok) {
throw new Error(`HTTP ${r.status}: ${await r.text()}`);
}
const j = await r.json();
body.innerHTML = renderIcad(j);
} catch (e) {
@ -1274,7 +1275,7 @@ ${ownerHtml}
}
}
btn.addEventListener('click', refresh);
form.addEventListener('submit', refresh);
})();
</script>