fixed validation per dup0licate parts, client inactive, fixed flags scheme, update schema json

This commit is contained in:
2026-07-01 11:43:17 +02:00
parent e0654b4847
commit 6ad10c4d8f
9 changed files with 623 additions and 18 deletions
@@ -1874,7 +1874,70 @@ $apiSampleJson = $template['api_sample_json'] ?? '';
document.querySelectorAll('#schemaFieldsBody .main-field-checkbox').forEach(cb => {
cb.dataset.originalChecked = cb.checked ? 'true' : 'false';
});
// =======================
// SAVE: Main / Import / Parts checkboxes
// =======================
function saveMappingFlag(checkboxEl, field) {
const mappingId = checkboxEl.getAttribute('data-mapping-id');
const checked = checkboxEl.checked;
fetch('update_mapping_flag.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: mappingId,
field: field,
value: checked ? 1 : 0
})
})
.then(response => response.json())
.then(data => {
if (!data.success) {
console.error("❌ Error saving flag:", field, data.message);
if (data.limit_reached) {
alert(data.message);
}
// Revert: il server ha rifiutato, riporto la checkbox allo stato precedente
checkboxEl.checked = !checked;
return;
}
console.log("✅ Flag saved:", field, "=", checked ? 1 : 0, "for id", mappingId);
// Se il server ha deselezionato un'altra riga (caso "parts"), rifletto anche in UI
if (data.unchecked_others && field === 'is_visible_parts') {
document.querySelectorAll('#schemaFieldsBody .visible-parts-checkbox').forEach(cb => {
if (cb !== checkboxEl) {
cb.checked = false;
}
});
}
})
.catch(error => {
console.error("❌ Fetch error saving flag:", field, error);
checkboxEl.checked = !checked;
});
}
document.getElementById('schemaFieldsBody').addEventListener('change', function(event) {
const el = event.target;
if (el.classList.contains('main-field-checkbox')) {
saveMappingFlag(el, 'main_field');
}
if (el.classList.contains('visible-import-checkbox')) {
saveMappingFlag(el, 'is_visible_import');
}
if (el.classList.contains('visible-parts-checkbox')) {
saveMappingFlag(el, 'is_visible_parts');
}
});
// AUTO VALUE select change -> save auto_value
document.getElementById('schemaFieldsBody').addEventListener('change', function(event) {
if (!event.target.classList.contains('auto-value-select')) return;