refactor: rename dxfFiles to availableDxfFiles and add fallback to window scope
This commit is contained in:
parent
090c7dd03c
commit
e30faa6ad6
2 changed files with 11 additions and 9 deletions
|
|
@ -855,14 +855,17 @@ if (georeferencedDocumentsDataEl) {
|
|||
}
|
||||
|
||||
const dxfFilesDataEl = document.getElementById('dxfFilesData');
|
||||
let dxfFiles = [];
|
||||
let availableDxfFiles = [];
|
||||
if (dxfFilesDataEl) {
|
||||
try {
|
||||
dxfFiles = JSON.parse(dxfFilesDataEl.textContent);
|
||||
availableDxfFiles = JSON.parse(dxfFilesDataEl.textContent);
|
||||
} catch (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');
|
||||
let crossroadPlansConfig = {};
|
||||
|
|
@ -1117,7 +1120,7 @@ function updatePlansActiveState() {
|
|||
function renderCrossroadPlansSection(container, control) {
|
||||
const importDxfUrl = crossroadPlansConfig && crossroadPlansConfig.importDxfUrl;
|
||||
const hasImages = georeferencedDocuments && georeferencedDocuments.length > 0;
|
||||
const hasDxf = dxfFiles && dxfFiles.length > 0;
|
||||
const hasDxf = availableDxfFiles && availableDxfFiles.length > 0;
|
||||
|
||||
// 1. Header with title & active badge
|
||||
const headerEl = document.createElement('div');
|
||||
|
|
@ -1212,12 +1215,12 @@ function renderCrossroadPlansSection(container, control) {
|
|||
dxfCard.id = 'plan-dxf-card';
|
||||
|
||||
let dxfSelectHtml = '';
|
||||
if (dxfFiles.length === 1) {
|
||||
if (availableDxfFiles.length === 1) {
|
||||
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">
|
||||
<span class="small font-weight-bold text-dark text-truncate" style="font-size: 11.5px; max-width: 190px;" title="${dxfFiles[0]}">
|
||||
<i class="bi bi-file-earmark-check-fill text-success me-1"></i>${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>${availableDxfFiles[0]}
|
||||
</span>
|
||||
<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">
|
||||
|
|
@ -1229,7 +1232,7 @@ function renderCrossroadPlansSection(container, control) {
|
|||
<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;">
|
||||
<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>
|
||||
<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">
|
||||
|
|
|
|||
|
|
@ -1137,7 +1137,6 @@
|
|||
const radar_preventif_icon_url = "{% static 'assets/radar_preventif_icon.svg' %}?v=20260710";
|
||||
const thematicCode = "{{ thematic_code }}";
|
||||
const intersectionId = "{{ intersection.id }}";
|
||||
const dxfFiles = {% if dxf_files %}{{ dxf_files|safe }}{% else %}[]{% endif %};
|
||||
</script>
|
||||
<script src="{% static 'common/layer-switcher-control.js' %}"></script>
|
||||
<script src="{% static 'assets/trafficlights_intersection_detail.js' %}"></script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue