added multiple column option template with color

This commit is contained in:
Claudio 2026-03-27 15:36:57 +01:00
parent cc96ecb67f
commit e96f538a47

View File

@ -163,6 +163,12 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
width: 100% !important; width: 100% !important;
} }
.xls-columns option.used-option {
background-color: #fff3cd;
color: #856404;
font-weight: 600;
}
/* Make Title column narrower + ellipsis */ /* Make Title column narrower + ellipsis */
#schemaFieldsTable td.title-col { #schemaFieldsTable td.title-col {
max-width: 320px; max-width: 320px;
@ -554,21 +560,25 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
function updateXlsDropdowns() { function updateXlsDropdowns() {
let usedColumns = Array.from(document.querySelectorAll('select.xls-columns')) let usedColumns = Array.from(document.querySelectorAll('select.xls-columns'))
.filter(select => select.style.display === 'block' && select.value) .map(select => select.value || select.dataset.currentXls || '')
.map(select => select.value) .filter(Boolean)
.concat(usedColumnsFromDB); .concat(usedColumnsFromDB);
let uniqueUsedColumns = [...new Set(usedColumns)];
document.querySelectorAll('select.xls-columns').forEach(select => { document.querySelectorAll('select.xls-columns').forEach(select => {
let currentValue = select.value || select.dataset.currentXls || ''; let currentValue = select.value || select.dataset.currentXls || '';
let options = availableXlsColumns let options = availableXlsColumns
.filter(col => !usedColumns.includes(col) || col === currentValue) .map(col => {
.map(col => `<option value="${col}" ${col === currentValue ? 'selected' : ''}>${col}</option>`) const isUsed = uniqueUsedColumns.includes(col) && col !== currentValue;
const label = isUsed ? `⚠ ${col} (already used)` : col;
return `<option value="${col}" class="${isUsed ? 'used-option' : ''}" ${col === currentValue ? 'selected' : ''}>${label}</option>`;
})
.join(''); .join('');
select.innerHTML = '<option value="">Select XLS Column</option>' + options; select.innerHTML = '<option value="">Select XLS Column</option>' + options;
select.dataset.currentXls = currentValue; select.dataset.currentXls = currentValue;
if (currentValue && !options.includes(currentValue)) {
select.value = '';
}
}); });
} }
@ -1015,33 +1025,6 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
checkbox.checked = !prevChecked; checkbox.checked = !prevChecked;
location.reload(); location.reload();
}); });
} 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;
});
} }
}); });
@ -1081,7 +1064,7 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
mappedColumn = document.createElement('span'); mappedColumn = document.createElement('span');
mappedColumn.className = 'mapped-column'; mappedColumn.className = 'mapped-column';
mappedColumn.style.marginLeft = '5px'; mappedColumn.style.marginLeft = '5px';
tr.querySelector('td:nth-child(5)').appendChild(mappedColumn); tr.querySelector('td:nth-child(6)').appendChild(mappedColumn);
} }
if (!removeBtn) { if (!removeBtn) {
removeBtn = document.createElement('button'); removeBtn = document.createElement('button');
@ -1089,7 +1072,7 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
removeBtn.textContent = 'X'; removeBtn.textContent = 'X';
removeBtn.style.marginLeft = '5px'; removeBtn.style.marginLeft = '5px';
removeBtn.setAttribute('data-id', mappingId); removeBtn.setAttribute('data-id', mappingId);
tr.querySelector('td:nth-child(5)').appendChild(removeBtn); tr.querySelector('td:nth-child(6)').appendChild(removeBtn);
removeBtn.addEventListener('click', function(e) { removeBtn.addEventListener('click', function(e) {
let tr = e.target.closest('tr'); let tr = e.target.closest('tr');