From 97ecd8d9fb715cf5e52d4c39c62fe6783cda8de4 Mon Sep 17 00:00:00 2001 From: kdeterme Date: Fri, 25 Sep 2026 11:47:57 +0200 Subject: [PATCH] fix(inspections): prevent modal event bubbling and add bottom add-ouvrage button in GIEP --- .../components/asset_fields/_naturerwiz.html | 55 +++++++++++++++---- .../components/edit_inspection_modal.html | 3 +- .../components/inspection_form_modal.html | 3 +- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/loko/inspections/templates/inspections/components/asset_fields/_naturerwiz.html b/loko/inspections/templates/inspections/components/asset_fields/_naturerwiz.html index 5e2370e..9dfe0df 100644 --- a/loko/inspections/templates/inspections/components/asset_fields/_naturerwiz.html +++ b/loko/inspections/templates/inspections/components/asset_fields/_naturerwiz.html @@ -493,8 +493,8 @@ popupNode.querySelector('.select-popup-btn').addEventListener('click', () => { selectAssetForOuvrage(activeOuvrageIdxForMap, asset); - const modalEl = document.getElementById('giepAssetMapModal'); - const modalInstance = bootstrap.Modal.getInstance(modalEl); + const mapModalEl = rootModal.querySelector('.giep-asset-map-modal') || document.getElementById('giepAssetMapModal'); + const modalInstance = bootstrap.Modal.getInstance(mapModalEl); if (modalInstance) modalInstance.hide(); }); @@ -514,6 +514,7 @@ giepOuvrages[idx].device_type = inferred; } renderOuvrages(); + toggleParentGlobalSections(true); } function syncHiddenFileInputs() { @@ -1257,6 +1258,18 @@ }); } + function addNewOuvrage() { + giepOuvrages.push(createEmptyOuvrage(giepOuvrages.length, "evc")); + renderOuvrages(); + setTimeout(() => { + const cards = container.querySelectorAll('.card'); + const lastCard = cards[cards.length - 1]; + if (lastCard && typeof lastCard.scrollIntoView === 'function') { + lastCard.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); + } + }, 50); + } + function renderOuvrages() { if (!container) return; container.innerHTML = ''; @@ -1272,10 +1285,7 @@ `; - container.querySelector('#giep_add_first_ouvrage_btn')?.addEventListener('click', () => { - giepOuvrages.push(createEmptyOuvrage(0, "evc")); - renderOuvrages(); - }); + container.querySelector('#giep_add_first_ouvrage_btn')?.addEventListener('click', addNewOuvrage); updateSerializedGiepData(); return; } @@ -1781,6 +1791,18 @@ container.appendChild(card); }); + if (giepOuvrages.length > 0) { + const bottomAddDiv = document.createElement('div'); + bottomAddDiv.className = 'text-center pt-2 pb-1 giep-bottom-add-container'; + bottomAddDiv.innerHTML = ` + + `; + bottomAddDiv.querySelector('.giep-add-ouvrage-bottom-btn')?.addEventListener('click', addNewOuvrage); + container.appendChild(bottomAddDiv); + } + // Event listeners pour la carte et l'autocomplétion container.querySelectorAll('.open-map-modal-btn').forEach(btn => { btn.addEventListener('click', (e) => { @@ -1991,18 +2013,26 @@ } if (addBtn) { - addBtn.addEventListener('click', () => { - giepOuvrages.push(createEmptyOuvrage(giepOuvrages.length, "evc")); - renderOuvrages(); - }); + addBtn.addEventListener('click', addNewOuvrage); } // Modal filter & shown listeners const modalEl = rootModal.querySelector('.giep-asset-map-modal') || document.getElementById('giepAssetMapModal'); if (modalEl) { - modalEl.addEventListener('shown.bs.modal', () => { + modalEl.addEventListener('show.bs.modal', (e) => { + e.stopPropagation(); + }); + modalEl.addEventListener('shown.bs.modal', (e) => { + e.stopPropagation(); initOrUpdateModalMap(); }); + modalEl.addEventListener('hide.bs.modal', (e) => { + e.stopPropagation(); + }); + modalEl.addEventListener('hidden.bs.modal', (e) => { + e.stopPropagation(); + toggleParentGlobalSections(true); + }); } const searchInput = rootModal.querySelector('#giep_modal_search_input, .giep-modal-search-input'); @@ -2075,7 +2105,8 @@ if (rootModal) { rootModal.setGiepFormData = window.setGiepFormData; - rootModal.addEventListener('hidden.bs.modal', () => { + rootModal.addEventListener('hidden.bs.modal', (e) => { + if (e && e.target !== rootModal) return; toggleParentGlobalSections(false); }); } diff --git a/loko/inspections/templates/inspections/components/edit_inspection_modal.html b/loko/inspections/templates/inspections/components/edit_inspection_modal.html index e2e738b..53b190c 100644 --- a/loko/inspections/templates/inspections/components/edit_inspection_modal.html +++ b/loko/inspections/templates/inspections/components/edit_inspection_modal.html @@ -1039,7 +1039,8 @@ document.addEventListener('DOMContentLoaded', function() { } if (editModalEl) { - editModalEl.addEventListener('hidden.bs.modal', function() { + editModalEl.addEventListener('hidden.bs.modal', function(e) { + if (e && e.target !== editModalEl) return; if (typeof window.toggleEditMissingResultChoice === 'function') { window.toggleEditMissingResultChoice(false); } diff --git a/loko/inspections/templates/inspections/components/inspection_form_modal.html b/loko/inspections/templates/inspections/components/inspection_form_modal.html index 6e899b1..d3ba28d 100644 --- a/loko/inspections/templates/inspections/components/inspection_form_modal.html +++ b/loko/inspections/templates/inspections/components/inspection_form_modal.html @@ -212,7 +212,8 @@ window.toggleMissingResultChoice = function(isDisabled, tooltipText) { document.addEventListener('DOMContentLoaded', function() { const modalEl = document.getElementById('quickInspectionModal'); if (modalEl) { - modalEl.addEventListener('hidden.bs.modal', function() { + modalEl.addEventListener('hidden.bs.modal', function(e) { + if (e && e.target !== modalEl) return; if (typeof window.toggleMissingResultChoice === 'function') { window.toggleMissingResultChoice(false); }