139 lines
No EOL
4.1 KiB
JavaScript
139 lines
No EOL
4.1 KiB
JavaScript
|
|
|
|
const map = new maplibregl.Map({
|
|
style: window.MAP_STYLE_LIGHT,
|
|
center: [feature_lon, feature_lat],
|
|
zoom: 16,
|
|
pitch: 45,
|
|
// bearing: -17.6,
|
|
container: 'map',
|
|
antialias: true
|
|
});
|
|
|
|
map.on('load', () => {
|
|
|
|
const street_data = {
|
|
type: 'FeatureCollection',
|
|
features: [
|
|
{
|
|
type: 'Feature',
|
|
geometry: geom,
|
|
properties: {
|
|
name: '...'
|
|
}
|
|
}
|
|
]
|
|
};
|
|
|
|
street_source = map.addSource('street', {
|
|
type: 'geojson',
|
|
data: street_data
|
|
});
|
|
|
|
map.addLayer({
|
|
'id': 'street',
|
|
'type': 'fill',
|
|
'source': 'street',
|
|
'paint': {
|
|
'fill-color': '#0094ff',
|
|
'fill-opacity': 0.7,
|
|
}
|
|
});
|
|
|
|
const bounds = turf.bbox(street_data);
|
|
map.fitBounds(bounds, {
|
|
// duration: 300
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const fileInput = document.getElementById('fileInput');
|
|
const fileContainer = document.getElementById('fileFieldsContainer');
|
|
|
|
const documentTypeChoices = {
|
|
'as_built': 'As Built',
|
|
'sign_plan': 'Plan de signalisation',
|
|
'other': 'Autre',
|
|
};
|
|
|
|
fileInput.addEventListener('change', function () {
|
|
fileContainer.innerHTML = '';
|
|
|
|
const files = Array.from(fileInput.files);
|
|
files.forEach((file, index) => {
|
|
const row = document.createElement('div');
|
|
row.classList.add('d-flex', 'align-items-center', 'gap-3');
|
|
|
|
// Nom du fichier (en lecture seule)
|
|
const fileName = document.createElement('span');
|
|
fileName.classList.add('flex-grow-1');
|
|
fileName.textContent = file.name;
|
|
row.appendChild(fileName);
|
|
|
|
// Select type de document
|
|
const select = document.createElement('select');
|
|
select.name = `document_type_${index}`;
|
|
select.classList.add('form-select', 'w-25');
|
|
for (const [value, label] of Object.entries(documentTypeChoices)) {
|
|
const option = document.createElement('option');
|
|
option.value = value;
|
|
option.textContent = label;
|
|
if (value === 'other') {
|
|
option.selected = true;
|
|
}
|
|
select.appendChild(option);
|
|
}
|
|
row.appendChild(select);
|
|
|
|
// Bouton de suppression
|
|
const deleteBtn = document.createElement('button');
|
|
deleteBtn.type = 'button';
|
|
deleteBtn.classList.add('btn', 'btn-danger', 'btn-sm');
|
|
deleteBtn.innerHTML = '<i class="bi bi-x-lg"></i>'; // nécessite Bootstrap Icons ou tu peux mettre "✖"
|
|
deleteBtn.onclick = () => {
|
|
files.splice(index, 1);
|
|
const dt = new DataTransfer();
|
|
files.forEach(f => dt.items.add(f));
|
|
fileInput.files = dt.files;
|
|
fileInput.dispatchEvent(new Event('change')); // re-render
|
|
};
|
|
row.appendChild(deleteBtn);
|
|
|
|
fileContainer.appendChild(row);
|
|
});
|
|
|
|
// Total
|
|
const countInput = document.createElement('input');
|
|
countInput.type = 'hidden';
|
|
countInput.name = 'file_count';
|
|
countInput.value = files.length;
|
|
fileContainer.appendChild(countInput);
|
|
});
|
|
|
|
|
|
const deleteDocumentModal = document.getElementById('documentDeleteModal');
|
|
deleteDocumentModal.addEventListener('show.bs.modal', function (event) {
|
|
const button = event.relatedTarget;
|
|
const fileName = button.getAttribute('data-filename');
|
|
const deleteUrl = button.getAttribute('data-delete-url');
|
|
|
|
const fileNameContainer = document.getElementById('deleteDocumentFileName');
|
|
const deleteForm = document.getElementById('deleteDocumentForm');
|
|
|
|
fileNameContainer.textContent = fileName;
|
|
deleteForm.action = deleteUrl;
|
|
});
|
|
|
|
|
|
document.getElementById('documentHistoryModal').addEventListener('show.bs.modal', function (event) {
|
|
const button = event.relatedTarget;
|
|
const type = button.getAttribute('data-document-type');
|
|
const streetId = button.getAttribute('data-street-id');
|
|
|
|
fetch(`${document_history_url}?street_id=${streetId}&document_type=${type}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
document.getElementById('documentHistoryContent').innerHTML = data.html;
|
|
});
|
|
}); |