feat: add thematic code input to location form and add null checks for modal elements

This commit is contained in:
kdeterme 2026-08-28 16:15:53 +02:00
parent 1df0c1b8c1
commit a364b6161d
2 changed files with 18 additions and 7 deletions

View file

@ -295,9 +295,11 @@ async function openUnifiedAssetModal(thematicCode) {
if (!thematic) return; if (!thematic) return;
unifiedAddAssetThematic = thematic; unifiedAddAssetThematic = thematic;
document.getElementById('unifiedAddAssetModalLabel').textContent = `${gettext('Créer un asset')} - ${thematic.name}`; const modalLabel = document.getElementById('unifiedAddAssetModalLabel');
if (modalLabel) modalLabel.textContent = `${gettext('Créer un asset')} - ${thematic.name}`;
resetUnifiedAssetForm(); resetUnifiedAssetForm();
document.getElementById('unified-add-asset-thematic-code').value = thematic.code; const thematicInput = document.getElementById('unified-add-asset-thematic-code');
if (thematicInput) thematicInput.value = thematic.code;
await loadUnifiedAssetCategories(thematic.code); await loadUnifiedAssetCategories(thematic.code);
const codeGroup = document.getElementById('unifiedAddAssetCodeGroup'); const codeGroup = document.getElementById('unifiedAddAssetCodeGroup');
@ -314,7 +316,10 @@ async function openUnifiedAssetModal(thematicCode) {
} }
} }
bootstrap.Modal.getOrCreateInstance(document.getElementById('unifiedAddAssetModal')).show(); const modalEl = document.getElementById('unifiedAddAssetModal');
if (modalEl) {
bootstrap.Modal.getOrCreateInstance(modalEl).show();
}
} }
function initUnifiedLocationPickerMap() { function initUnifiedLocationPickerMap() {
@ -468,14 +473,19 @@ async function openUnifiedLocationModal(thematicCode) {
if (!thematic) return; if (!thematic) return;
unifiedAddLocationThematic = thematic; unifiedAddLocationThematic = thematic;
document.getElementById('unifiedAddLocationModalLabel').textContent = `${gettext('Créer une localisation')} - ${thematic.name}`; const modalLabel = document.getElementById('unifiedAddLocationModalLabel');
document.getElementById('unifiedAddLocationMeta').textContent = `${gettext('Type')}: ${thematic.location_label}`; if (modalLabel) modalLabel.textContent = `${gettext('Créer une localisation')} - ${thematic.name}`;
const modalMeta = document.getElementById('unifiedAddLocationMeta');
if (modalMeta) modalMeta.textContent = `${gettext('Type')}: ${thematic.location_label}`;
resetUnifiedLocationForm(); resetUnifiedLocationForm();
document.getElementById('unified-add-location-thematic-code').value = thematic.code; const thematicCodeInput = document.getElementById('unified-add-location-thematic-code');
document.getElementById('unified-add-location-type').value = thematic.location_type; if (thematicCodeInput) thematicCodeInput.value = thematic.code;
const locationTypeInput = document.getElementById('unified-add-location-type');
if (locationTypeInput) locationTypeInput.value = thematic.location_type;
await loadUnifiedLocationForm(thematic.code, thematic.location_type); await loadUnifiedLocationForm(thematic.code, thematic.location_type);
const modalEl = document.getElementById('unifiedAddLocationModal'); const modalEl = document.getElementById('unifiedAddLocationModal');
if (!modalEl) return;
const onShown = () => { const onShown = () => {
initUnifiedLocationPickerMap(); initUnifiedLocationPickerMap();
bootstrap.Modal.getOrCreateInstance(modalEl).handleUpdate(); bootstrap.Modal.getOrCreateInstance(modalEl).handleUpdate();

View file

@ -337,6 +337,7 @@
<div class="modal-dialog modal-lg modal-dialog-scrollable"> <div class="modal-dialog modal-lg modal-dialog-scrollable">
<form id="unifiedAddLocationForm" class="modal-content"> <form id="unifiedAddLocationForm" class="modal-content">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="thematic_code" id="unified-add-location-thematic-code">
<input type="hidden" id="unified-add-location-type" name="location_type"> <input type="hidden" id="unified-add-location-type" name="location_type">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="unifiedAddLocationModalLabel">{% translate "Créer une localisation" %}</h5> <h5 class="modal-title" id="unifiedAddLocationModalLabel">{% translate "Créer une localisation" %}</h5>