refactor: rename dxfFiles to availableDxfFiles and add fallback to window scope

This commit is contained in:
kdeterme 2026-09-21 11:44:09 +02:00
parent 090c7dd03c
commit e30faa6ad6
2 changed files with 11 additions and 9 deletions

View file

@ -855,14 +855,17 @@ if (georeferencedDocumentsDataEl) {
} }
const dxfFilesDataEl = document.getElementById('dxfFilesData'); const dxfFilesDataEl = document.getElementById('dxfFilesData');
let dxfFiles = []; let availableDxfFiles = [];
if (dxfFilesDataEl) { if (dxfFilesDataEl) {
try { try {
dxfFiles = JSON.parse(dxfFilesDataEl.textContent); availableDxfFiles = JSON.parse(dxfFilesDataEl.textContent);
} catch (e) { } catch (e) {
console.error("Error parsing dxf files data:", e); console.error("Error parsing dxf files data:", e);
} }
} }
if (!availableDxfFiles.length && typeof window.dxfFiles !== 'undefined' && Array.isArray(window.dxfFiles)) {
availableDxfFiles = window.dxfFiles;
}
const crossroadPlansConfigEl = document.getElementById('crossroadPlansConfig'); const crossroadPlansConfigEl = document.getElementById('crossroadPlansConfig');
let crossroadPlansConfig = {}; let crossroadPlansConfig = {};
@ -1117,7 +1120,7 @@ function updatePlansActiveState() {
function renderCrossroadPlansSection(container, control) { function renderCrossroadPlansSection(container, control) {
const importDxfUrl = crossroadPlansConfig && crossroadPlansConfig.importDxfUrl; const importDxfUrl = crossroadPlansConfig && crossroadPlansConfig.importDxfUrl;
const hasImages = georeferencedDocuments && georeferencedDocuments.length > 0; const hasImages = georeferencedDocuments && georeferencedDocuments.length > 0;
const hasDxf = dxfFiles && dxfFiles.length > 0; const hasDxf = availableDxfFiles && availableDxfFiles.length > 0;
// 1. Header with title & active badge // 1. Header with title & active badge
const headerEl = document.createElement('div'); const headerEl = document.createElement('div');
@ -1212,12 +1215,12 @@ function renderCrossroadPlansSection(container, control) {
dxfCard.id = 'plan-dxf-card'; dxfCard.id = 'plan-dxf-card';
let dxfSelectHtml = ''; let dxfSelectHtml = '';
if (dxfFiles.length === 1) { if (availableDxfFiles.length === 1) {
dxfSelectHtml = ` dxfSelectHtml = `
<input type="hidden" id="select-dxf-file" value="${dxfFiles[0]}"> <input type="hidden" id="select-dxf-file" value="${availableDxfFiles[0]}">
<div class="d-flex align-items-center justify-content-between mb-1"> <div class="d-flex align-items-center justify-content-between mb-1">
<span class="small font-weight-bold text-dark text-truncate" style="font-size: 11.5px; max-width: 190px;" title="${dxfFiles[0]}"> <span class="small font-weight-bold text-dark text-truncate" style="font-size: 11.5px; max-width: 190px;" title="${availableDxfFiles[0]}">
<i class="bi bi-file-earmark-check-fill text-success me-1"></i>${dxfFiles[0]} <i class="bi bi-file-earmark-check-fill text-success me-1"></i>${availableDxfFiles[0]}
</span> </span>
<div class="form-check form-switch mb-0" style="padding-left: 2em;"> <div class="form-check form-switch mb-0" style="padding-left: 2em;">
<input class="form-check-input" type="checkbox" role="switch" id="switch-dxf-master" style="cursor: pointer; width: 28px; height: 14px;" title="Afficher/masquer le plan CAO"> <input class="form-check-input" type="checkbox" role="switch" id="switch-dxf-master" style="cursor: pointer; width: 28px; height: 14px;" title="Afficher/masquer le plan CAO">
@ -1229,7 +1232,7 @@ function renderCrossroadPlansSection(container, control) {
<div class="d-flex align-items-center justify-content-between gap-1 mb-2"> <div class="d-flex align-items-center justify-content-between gap-1 mb-2">
<select id="select-dxf-file" class="form-select form-select-sm" style="font-size: 11px; padding: 2px 6px; flex-grow: 1;"> <select id="select-dxf-file" class="form-select form-select-sm" style="font-size: 11px; padding: 2px 6px; flex-grow: 1;">
<option value="">-- Sélectionner un fichier DXF --</option> <option value="">-- Sélectionner un fichier DXF --</option>
${dxfFiles.map(f => `<option value="${f}">${f}</option>`).join('')} ${availableDxfFiles.map(f => `<option value="${f}">${f}</option>`).join('')}
</select> </select>
<div class="form-check form-switch mb-0 ps-2"> <div class="form-check form-switch mb-0 ps-2">
<input class="form-check-input" type="checkbox" role="switch" id="switch-dxf-master" style="cursor: pointer; width: 28px; height: 14px;" title="Afficher/masquer le plan CAO"> <input class="form-check-input" type="checkbox" role="switch" id="switch-dxf-master" style="cursor: pointer; width: 28px; height: 14px;" title="Afficher/masquer le plan CAO">

View file

@ -1137,7 +1137,6 @@
const radar_preventif_icon_url = "{% static 'assets/radar_preventif_icon.svg' %}?v=20260710"; const radar_preventif_icon_url = "{% static 'assets/radar_preventif_icon.svg' %}?v=20260710";
const thematicCode = "{{ thematic_code }}"; const thematicCode = "{{ thematic_code }}";
const intersectionId = "{{ intersection.id }}"; const intersectionId = "{{ intersection.id }}";
const dxfFiles = {% if dxf_files %}{{ dxf_files|safe }}{% else %}[]{% endif %};
</script> </script>
<script src="{% static 'common/layer-switcher-control.js' %}"></script> <script src="{% static 'common/layer-switcher-control.js' %}"></script>
<script src="{% static 'assets/trafficlights_intersection_detail.js' %}"></script> <script src="{% static 'assets/trafficlights_intersection_detail.js' %}"></script>