|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toggleElementsEnabled(elementIds, enabled = true) { |
|
elementIds.forEach(id => { |
|
const element = document.getElementById(id); |
|
if (element) { |
|
if (enabled) { |
|
element.removeAttribute('disabled'); |
|
} else { |
|
element.setAttribute('disabled', 'true'); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function toggleContainersVisibility(containerIds, visible = true) { |
|
containerIds.forEach(id => { |
|
const container = document.getElementById(id); |
|
if (container) { |
|
if (visible) { |
|
container.classList.remove('hidden'); |
|
} else { |
|
container.classList.add('hidden'); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function showLoadingOverlay(message = 'Chargement en cours...') { |
|
document.getElementById('progress-text').textContent = message; |
|
toggleContainersVisibility(['loading-overlay'], true); |
|
} |
|
|
|
|
|
|
|
|
|
function hideLoadingOverlay() { |
|
toggleContainersVisibility(['loading-overlay'], false); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function populateSelect(selectId, options, defaultText = 'Sélectionner...') { |
|
const select = document.getElementById(selectId); |
|
if (select) { |
|
select.innerHTML = `<option value="">${defaultText}</option>`; |
|
Object.entries(options).forEach(([text, value]) => { |
|
const option = document.createElement('option'); |
|
option.value = value; |
|
option.textContent = text; |
|
select.appendChild(option); |
|
}); |
|
} |
|
} |
|
|
|
function populateCheckboxDropdown(optionsContainerId, options, filterType, labelId, selectionSet) { |
|
const container = document.getElementById(optionsContainerId); |
|
container.innerHTML = ''; |
|
selectionSet.clear(); |
|
|
|
|
|
options.forEach(option => { |
|
const safeId = `${filterType}-${encodeURIComponent(option).replace(/[%\s]/g, '_')}`; |
|
const label = document.createElement('label'); |
|
label.className = "flex items-center gap-2 cursor-pointer py-1"; |
|
label.innerHTML = ` |
|
<input type="checkbox" class="${filterType}-checkbox option-checkbox" id="${safeId}" value="${option}"> |
|
<span>${option}</span> |
|
`; |
|
label.querySelector('input').addEventListener('change', function () { |
|
if (this.checked) { |
|
selectionSet.add(this.value); |
|
} else { |
|
selectionSet.delete(this.value); |
|
} |
|
|
|
updateCheckboxDropdownLabel(filterType, labelId, selectionSet, options.length); |
|
|
|
const allBox = document.querySelector(`.${filterType}-checkbox[value="all"]`); |
|
if (allBox && allBox.checked) allBox.checked = false; |
|
|
|
if (selectionSet.size === 0 && allBox) allBox.checked = true; |
|
applyFilters(); |
|
}); |
|
container.appendChild(label); |
|
}); |
|
|
|
|
|
updateCheckboxDropdownLabel(filterType, labelId, selectionSet, options.length); |
|
|
|
|
|
const allBox = document.querySelector(`.${filterType}-checkbox[value="all"]`); |
|
if (allBox) { |
|
allBox.addEventListener('change', function () { |
|
if (this.checked) { |
|
|
|
selectionSet.clear(); |
|
container.querySelectorAll('input[type="checkbox"]').forEach(cb => cb.checked = false); |
|
this.checked = true; |
|
updateCheckboxDropdownLabel(filterType, labelId, selectionSet, options.length); |
|
applyFilters(); |
|
} |
|
}); |
|
} |
|
} |
|
|
|
function updateCheckboxDropdownLabel(type, labelId, set, totalCount) { |
|
const label = document.getElementById(labelId); |
|
if (!set.size) { |
|
label.textContent = type.charAt(0).toUpperCase() + type.slice(1) + " (Tous)"; |
|
} else if (set.size === 1) { |
|
label.textContent = [...set][0]; |
|
} else { |
|
label.textContent = `${type.charAt(0).toUpperCase() + type.slice(1)} (${set.size}/${totalCount})`; |
|
} |
|
} |
|
|
|
function updateSelectedFilters(filterType, value, isChecked) { |
|
if (isChecked) { |
|
selectedFilters[filterType].add(value); |
|
} else { |
|
selectedFilters[filterType].delete(value); |
|
} |
|
} |
|
|
|
function populateDaisyDropdown(menuId, options, labelId, onSelect) { |
|
const menu = document.getElementById(menuId); |
|
menu.innerHTML = ''; |
|
|
|
const liAll = document.createElement('li'); |
|
liAll.innerHTML = `<a data-value="">Tous</a>`; |
|
liAll.querySelector('a').onclick = e => { |
|
e.preventDefault(); |
|
document.getElementById(labelId).textContent = "Type"; |
|
onSelect(""); |
|
}; |
|
menu.appendChild(liAll); |
|
|
|
|
|
options.forEach(opt => { |
|
const li = document.createElement('li'); |
|
li.innerHTML = `<a data-value="${opt}">${opt}</a>`; |
|
li.querySelector('a').onclick = e => { |
|
e.preventDefault(); |
|
document.getElementById(labelId).textContent = opt; |
|
onSelect(opt); |
|
}; |
|
menu.appendChild(li); |
|
}); |
|
} |
|
|
|
function updateFilterLabel(filterType) { |
|
const selectedCount = selectedFilters[filterType].size; |
|
const labelElement = document.getElementById(`${filterType}-filter-label`); |
|
|
|
if (selectedCount === 0) { |
|
labelElement.textContent = `${filterType} (Tous)`; |
|
} else { |
|
labelElement.textContent = `${filterType} (${selectedCount} sélectionné${selectedCount > 1 ? 's' : ''})`; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function extractTableData(mapping) { |
|
const tbody = document.querySelector('#data-table tbody'); |
|
const rows = tbody.querySelectorAll('tr'); |
|
const data = []; |
|
|
|
rows.forEach(row => { |
|
const checkboxes = row.querySelectorAll('input[type="checkbox"]:checked'); |
|
if (checkboxes.length > 0) { |
|
const rowData = {}; |
|
Object.entries(mapping).forEach(([columnName, propertyName]) => { |
|
const cell = row.querySelector(`td[data-column="${columnName}"]`); |
|
if (cell) { |
|
if (columnName == "URL") { |
|
rowData[propertyName] = cell.querySelector('a').getAttribute('href'); |
|
} else { |
|
rowData[propertyName] = cell.textContent.trim(); |
|
} |
|
} |
|
}); |
|
data.push(rowData); |
|
} |
|
}); |
|
|
|
return data; |
|
} |
|
|
|
const TABS = { |
|
'doc-table-tab': 'doc-table-tab-contents', |
|
'requirements-tab': 'requirements-tab-contents', |
|
'solutions-tab': 'solutions-tab-contents', |
|
'query-tab': 'query-tab-contents' |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function switchTab(newTab) { |
|
|
|
Object.keys(TABS).forEach(tabId => { |
|
const tabElement = document.getElementById(tabId); |
|
if (tabElement) { |
|
tabElement.classList.remove("tab-active"); |
|
} |
|
}); |
|
|
|
|
|
Object.values(TABS).forEach(contentId => { |
|
const contentElement = document.getElementById(contentId); |
|
if (contentElement) { |
|
contentElement.classList.add("hidden"); |
|
} |
|
}); |
|
|
|
|
|
if (newTab in TABS) { |
|
const newTabElement = document.getElementById(newTab); |
|
const newContentElement = document.getElementById(TABS[newTab]); |
|
|
|
if (newTabElement) newTabElement.classList.add("tab-active"); |
|
if (newContentElement) newContentElement.classList.remove("hidden"); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
function enableTabSwitching() { |
|
Object.keys(TABS).forEach(tabId => { |
|
const tab = document.getElementById(tabId); |
|
if (tab) |
|
tab.classList.remove("tab-disabled"); |
|
}) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function debounceAutoCategoryCount(state) { |
|
document.getElementById('category-count').disabled = state; |
|
} |
|
|
|
|