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', () => {
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 @@
</button>
</div>
`;
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 = `
<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
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);
});
}

View file

@ -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);
}

View file

@ -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);
}