update historical trf

This commit is contained in:
Claudio 2025-08-28 09:36:16 +02:00
parent f6ef9c39d2
commit 0d2cf13524

View File

@ -982,7 +982,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
const cells = row.querySelectorAll('td');
let match = false;
cells.forEach((cell, index) => {
if (index >= 1 && index <= 3) {
if (index >= 1 && index <= 4) { // Cerca in ID, main_field, importreferencecode, filename
const text = cell.textContent.toLowerCase();
if (text.includes(filter)) {
match = true;
@ -1026,6 +1026,18 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
}
});
});
// Gestione eliminazione multipla
const bulkActionForm = document.getElementById('bulkActionForm');
bulkActionForm.addEventListener('submit', function(e) {
const selectedCheckboxes = document.querySelectorAll('input[name="selected_ids[]"]:checked');
if (selectedCheckboxes.length === 0) {
e.preventDefault();
alert('Seleziona almeno un record da eliminare.');
} else if (!confirm('Sicuro di voler eliminare i record selezionati?')) {
e.preventDefault();
}
});
<?php else: ?>
// Gestione input e celle espandibili
const inputs = document.querySelectorAll('.cell-input');
@ -1055,6 +1067,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
formData.append(name, input.value);
});
formData.append('iddatadb', iddatadb);
formData.append('mapping', JSON.stringify(<?= json_encode($allMappings) ?>));
fetch('save_edited_row.php', {
method: 'POST',
body: formData
@ -1069,7 +1082,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
cell.classList.add('flash-success');
});
setTimeout(() => cells.forEach(cell => cell.classList.remove('flash-success')), 500);
// Ricarica i dropdown dopo il salvataggio
alert('Salvataggio avvenuto con successo!');
setTimeout(populateDropdowns, 100);
} else {
alert('Errore durante il salvataggio: ' + data.message);
@ -1084,12 +1097,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
propagateButtons.forEach(button => {
button.addEventListener('click', function() {
if (this.hasAttribute('disabled')) return;
const columnIndex = this.getAttribute('data-column').replace('manual_', '');
const column = this.getAttribute('data-column');
const input = this.previousElementSibling;
const value = input.value;
const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell');
const targetTopIndex = Array.from(gridTopCells).findIndex(cell =>
cell.querySelector('.propagate-btn') === button
cell.querySelector('.propagate-btn[data-column="' + column + '"]')
);
if (targetTopIndex !== -1) {
const rows = document.querySelectorAll('.grid-row');
@ -1098,9 +1111,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
if (cells.length > targetTopIndex) {
const targetInput = cells[targetTopIndex].querySelector('input, select');
if (targetInput && !targetInput.hasAttribute('readonly')) {
if (targetInput.type === 'date') targetInput.value = value;
else if (targetInput.tagName === 'SELECT') targetInput.value = value;
else targetInput.value = value;
targetInput.value = value;
if (targetInput.tagName === 'SELECT') {
const event = new Event('change');
targetInput.dispatchEvent(event);
}
}
}
});
@ -1213,49 +1228,71 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
});
// Gestione dropdown
const dropdownData = {};
async function populateDropdowns() {
if (<?= json_encode($is_readonly) ?>) return;
const dropdowns = document.querySelectorAll('.dropdown-select');
if (dropdowns.length === 0) return;
const uniqueFieldIds = [...new Set(Array.from(dropdowns).map(d => d.getAttribute('data-field-id')))].filter(fieldId => fieldId);
if (uniqueFieldIds.length === 0) return;
console.log('Dropdown trovati:', dropdowns.length);
if (dropdowns.length === 0) {
console.warn('Nessun dropdown trovato con classe .dropdown-select');
return;
}
try {
const response = await fetch(`get_customfield_values.php?field_ids=${uniqueFieldIds.join(',')}`);
const data = await response.json();
if (data.error) {
console.error('Errore nel caricamento dei valori dei dropdown:', data.error);
const uniqueFieldIds = [...new Set(Array.from(dropdowns).map(d => d.getAttribute('data-field-id')))].filter(fieldId => fieldId);
console.log('Field IDs unici:', uniqueFieldIds);
const missingFieldIds = uniqueFieldIds.filter(fieldId => !dropdownData[fieldId]);
if (missingFieldIds.length > 0) {
try {
const response = await fetch(`get_customfield_values.php?field_ids=${missingFieldIds.join(',')}`);
if (!response.ok) {
throw new Error(`Errore HTTP: ${response.status} ${response.statusText}`);
}
const data = await response.json();
console.log('Risposta da get_customfield_values.php:', data);
if (data.error) {
console.error('Errore dal server:', data.error);
dropdowns.forEach(dropdown => {
dropdown.innerHTML = '<option value="">Errore server</option>';
});
return;
}
for (const fieldId of Object.keys(data)) {
dropdownData[fieldId] = data[fieldId] || [];
}
} catch (error) {
console.error('Errore nel fetch dei valori dei dropdown:', error);
dropdowns.forEach(dropdown => {
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
dropdown.innerHTML = '<option value="">Errore caricamento</option>';
});
return;
}
dropdowns.forEach(dropdown => {
const fieldId = dropdown.getAttribute('data-field-id');
const options = data[fieldId] || [];
const currentValue = dropdown.value;
// Rimuovi opzioni esistenti (tranne il placeholder)
dropdown.innerHTML = '<option value="">Seleziona...</option>';
// Aggiungi nuove opzioni
options.forEach(option => {
const opt = document.createElement('option');
opt.value = option.Value;
opt.textContent = option.Value;
if (currentValue === option.Value) {
opt.selected = true;
}
dropdown.appendChild(opt);
});
});
} catch (error) {
console.error('Errore nel fetch dei valori dei dropdown:', error);
dropdowns.forEach(dropdown => {
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
});
}
dropdowns.forEach(dropdown => {
const fieldId = dropdown.getAttribute('data-field-id');
const mappingId = dropdown.getAttribute('data-mapping-id');
const currentValue = dropdown.value || '';
console.log(`Popolamento dropdown field_id=${fieldId}, mapping_id=${mappingId}, valore corrente=${currentValue}`);
if (!fieldId || !dropdownData[fieldId]) {
dropdown.innerHTML = '<option value="">Nessun dato</option>';
return;
}
dropdown.innerHTML = '<option value="">Seleziona...</option>';
dropdownData[fieldId].forEach(value => {
const option = document.createElement('option');
option.value = value.IdCustomFieldsValue;
option.textContent = value.Valore;
if (currentValue === String(value.IdCustomFieldsValue)) {
option.selected = true;
}
dropdown.appendChild(option);
});
});
}
populateDropdowns();
saveButtons.forEach(btn => {