fix(inspections): prevent modal event bubbling and add bottom add-ouvrage button in GIEP

This commit is contained in:
kdeterme 2026-09-25 11:47:57 +02:00
parent ca8d8187c1
commit 97ecd8d9fb
3 changed files with 47 additions and 14 deletions

View file

@ -493,8 +493,8 @@
popupNode.querySelector('.select-popup-btn').addEventListener('click', () => { popupNode.querySelector('.select-popup-btn').addEventListener('click', () => {
selectAssetForOuvrage(activeOuvrageIdxForMap, asset); selectAssetForOuvrage(activeOuvrageIdxForMap, asset);
const modalEl = document.getElementById('giepAssetMapModal'); const mapModalEl = rootModal.querySelector('.giep-asset-map-modal') || document.getElementById('giepAssetMapModal');
const modalInstance = bootstrap.Modal.getInstance(modalEl); const modalInstance = bootstrap.Modal.getInstance(mapModalEl);
if (modalInstance) modalInstance.hide(); if (modalInstance) modalInstance.hide();
}); });
@ -514,6 +514,7 @@
giepOuvrages[idx].device_type = inferred; giepOuvrages[idx].device_type = inferred;
} }
renderOuvrages(); renderOuvrages();
toggleParentGlobalSections(true);
} }
function syncHiddenFileInputs() { 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() { function renderOuvrages() {
if (!container) return; if (!container) return;
container.innerHTML = ''; container.innerHTML = '';
@ -1272,10 +1285,7 @@
</button> </button>
</div> </div>
`; `;
container.querySelector('#giep_add_first_ouvrage_btn')?.addEventListener('click', () => { container.querySelector('#giep_add_first_ouvrage_btn')?.addEventListener('click', addNewOuvrage);
giepOuvrages.push(createEmptyOuvrage(0, "evc"));
renderOuvrages();
});
updateSerializedGiepData(); updateSerializedGiepData();
return; return;
} }
@ -1781,6 +1791,18 @@
container.appendChild(card); 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 = `
<button type="button" class="btn btn-outline-success btn-sm py-2 px-3.5 fw-semibold rounded-pill shadow-sm giep-add-ouvrage-bottom-btn">
<i class="bi bi-plus-circle me-1.5"></i>{% filter escapejs %}{% translate "Ajouter un ouvrage" %}{% endfilter %}
</button>
`;
bottomAddDiv.querySelector('.giep-add-ouvrage-bottom-btn')?.addEventListener('click', addNewOuvrage);
container.appendChild(bottomAddDiv);
}
// Event listeners pour la carte et l'autocomplétion // Event listeners pour la carte et l'autocomplétion
container.querySelectorAll('.open-map-modal-btn').forEach(btn => { container.querySelectorAll('.open-map-modal-btn').forEach(btn => {
btn.addEventListener('click', (e) => { btn.addEventListener('click', (e) => {
@ -1991,18 +2013,26 @@
} }
if (addBtn) { if (addBtn) {
addBtn.addEventListener('click', () => { addBtn.addEventListener('click', addNewOuvrage);
giepOuvrages.push(createEmptyOuvrage(giepOuvrages.length, "evc"));
renderOuvrages();
});
} }
// Modal filter & shown listeners // Modal filter & shown listeners
const modalEl = rootModal.querySelector('.giep-asset-map-modal') || document.getElementById('giepAssetMapModal'); const modalEl = rootModal.querySelector('.giep-asset-map-modal') || document.getElementById('giepAssetMapModal');
if (modalEl) { if (modalEl) {
modalEl.addEventListener('shown.bs.modal', () => { modalEl.addEventListener('show.bs.modal', (e) => {
e.stopPropagation();
});
modalEl.addEventListener('shown.bs.modal', (e) => {
e.stopPropagation();
initOrUpdateModalMap(); 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'); const searchInput = rootModal.querySelector('#giep_modal_search_input, .giep-modal-search-input');
@ -2075,7 +2105,8 @@
if (rootModal) { if (rootModal) {
rootModal.setGiepFormData = window.setGiepFormData; rootModal.setGiepFormData = window.setGiepFormData;
rootModal.addEventListener('hidden.bs.modal', () => { rootModal.addEventListener('hidden.bs.modal', (e) => {
if (e && e.target !== rootModal) return;
toggleParentGlobalSections(false); toggleParentGlobalSections(false);
}); });
} }

View file

@ -1039,7 +1039,8 @@ document.addEventListener('DOMContentLoaded', function() {
} }
if (editModalEl) { 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') { if (typeof window.toggleEditMissingResultChoice === 'function') {
window.toggleEditMissingResultChoice(false); window.toggleEditMissingResultChoice(false);
} }

View file

@ -212,7 +212,8 @@ window.toggleMissingResultChoice = function(isDisabled, tooltipText) {
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const modalEl = document.getElementById('quickInspectionModal'); const modalEl = document.getElementById('quickInspectionModal');
if (modalEl) { 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') { if (typeof window.toggleMissingResultChoice === 'function') {
window.toggleMissingResultChoice(false); window.toggleMissingResultChoice(false);
} }