mapping fixed

This commit is contained in:
2026-02-24 09:06:45 +01:00
parent b9852ba226
commit b0024edb70
6 changed files with 365 additions and 8 deletions
@@ -21,7 +21,7 @@ $schemajson = $template['schemajson'] ? json_decode($template['schemajson'], tru
$isSchemajsonEmpty = empty(trim($template['schemajson']));
// Recupera i campi dalla tabella template_mapping
$stmt = $pdo->prepare("SELECT id, field_id, excel_column, is_manual, manual_default, data_type, is_required, default_value, has_list, length, decimals, min_value, max_value, default_curr_date, tablename, field_label, main_field, is_visible_import FROM template_mapping WHERE template_id = ?");
$stmt = $pdo->prepare("SELECT id, field_id, excel_column, is_manual, manual_default, data_type, is_required, default_value, has_list, length, decimals, min_value, max_value, default_curr_date, tablename, field_label, main_field, is_visible_import, is_visible_parts FROM template_mapping WHERE template_id = ?");
$stmt->execute([$id]);
$mappings = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -108,6 +108,14 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
.select2-container {
width: 100% !important;
}
/* Make Title column narrower + ellipsis */
#schemaFieldsTable td.title-col {
max-width: 320px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
@@ -157,9 +165,10 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
<table id="schemaFieldsTable" class="table table-striped">
<thead>
<tr>
<th style="width:100px; text-align:center;">Main</th>
<th style="width:120px; text-align:center;">Visible on Import</th>
<th>Title</th>
<th style="width:90px; text-align:center;">Main</th>
<th style="width:110px; text-align:center;">Import</th>
<th style="width:110px; text-align:center;">Parts</th>
<th style="width:320px;">Title</th>
<th style="width:140px;">Type</th>
<th>Mapping</th>
<th>Default Value</th>
@@ -169,6 +178,7 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
<tbody id="schemaFieldsBody">
<?php foreach ($mappings as $mapping): ?>
<tr>
@@ -185,14 +195,22 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
data-mapping-id="<?php echo (int)$mapping['id']; ?>"
<?php echo ((int)($mapping['is_visible_import'] ?? 1) === 1) ? 'checked' : ''; ?>>
</td>
<td class="text-center">
<input type="checkbox"
class="visible-parts-checkbox"
data-mapping-id="<?php echo (int)$mapping['id']; ?>"
<?php echo ((int)($mapping['is_visible_parts'] ?? 0) === 1) ? 'checked' : ''; ?>>
</td>
<td>
<td class="title-col">
<?php echo htmlspecialchars($mapping['field_label'] ?? 'N/A'); ?>
<?php if ((int)$mapping['is_required'] === 1): ?>
<span class="badge bg-danger ms-2">Required</span>
<?php endif; ?>
</td>
<td><?php echo htmlspecialchars($mapping['data_type'] ?? 'N/A'); ?></td>
<td>
@@ -877,7 +895,35 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
console.error("❌ Fetch error:", error);
checkbox.checked = !checkbox.checked;
});
} else if (event.target.classList.contains('visible-parts-checkbox')) {
const checkbox = event.target;
const mappingId = checkbox.dataset.mappingId;
const value = checkbox.checked ? 1 : 0;
fetch('update_visible_parts.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
template_id: <?php echo $id; ?>,
mapping_id: mappingId,
value: value
})
})
.then(response => response.json())
.then(data => {
if (!data.success) {
console.error("❌ Error updating is_visible_parts:", data.message);
checkbox.checked = !checkbox.checked;
}
})
.catch(error => {
console.error("❌ Fetch error:", error);
checkbox.checked = !checkbox.checked;
});
}
});
// Salva lo stato originale dei checkbox al caricamento