Ajoute un sélecteur de tags existants dans la modale fiche idée
This commit is contained in:
+36
-1
@@ -428,6 +428,7 @@ function openNew() {
|
||||
document.getElementById('modal-label').textContent = 'Nouvelle idee';
|
||||
document.getElementById('f-title').value = '';
|
||||
renderModalTags(['À étudier']);
|
||||
updateTagSuggestions();
|
||||
document.getElementById('f-tags-input').value = '';
|
||||
document.getElementById('f-acte').value = 'En attente';
|
||||
document.getElementById('f-resume').value = '';
|
||||
@@ -452,6 +453,7 @@ function openEdit(id) {
|
||||
document.getElementById('modal-label').textContent = 'Modifier';
|
||||
document.getElementById('f-title').value = r.Title || '';
|
||||
renderModalTags((r.Tags || '').split(',').map(s => s.trim()).filter(Boolean));
|
||||
updateTagSuggestions();
|
||||
document.getElementById('f-tags-input').value = '';
|
||||
document.getElementById('f-acte').value = r.Acte || '';
|
||||
document.getElementById('f-resume').value = r['Résumé'] || '';
|
||||
@@ -579,6 +581,38 @@ function getModalTags() {
|
||||
return [...document.querySelectorAll('#f-tags .tag-chip')].map(c => c.dataset.tag);
|
||||
}
|
||||
|
||||
function collectExistingTags() {
|
||||
const tagSet = new Set();
|
||||
records.forEach(r => {
|
||||
if (r.Tags) r.Tags.split(',').forEach(t => { const trimmed = t.trim(); if (trimmed) tagSet.add(trimmed); });
|
||||
});
|
||||
return [...tagSet].sort((a, b) => a.localeCompare(b, 'fr'));
|
||||
}
|
||||
|
||||
function updateTagSuggestions() {
|
||||
const select = document.getElementById('f-tags-select');
|
||||
const current = getModalTags();
|
||||
const existing = collectExistingTags().filter(t => !current.includes(t));
|
||||
select.innerHTML = '<option value="">Tags existants...</option>';
|
||||
existing.forEach(t => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = t; opt.textContent = t;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
}
|
||||
|
||||
function addExistingTag() {
|
||||
const select = document.getElementById('f-tags-select');
|
||||
const val = select.value;
|
||||
if (!val) return;
|
||||
const current = getModalTags();
|
||||
if (!current.includes(val)) {
|
||||
renderModalTags([...current, val]);
|
||||
}
|
||||
select.value = '';
|
||||
updateTagSuggestions();
|
||||
}
|
||||
|
||||
function renderModalTags(tags) {
|
||||
const container = document.getElementById('f-tags');
|
||||
container.querySelectorAll('.tag-chip').forEach(c => c.remove());
|
||||
@@ -587,7 +621,7 @@ function renderModalTags(tags) {
|
||||
const chip = document.createElement('span');
|
||||
chip.className = 'tag-chip';
|
||||
chip.dataset.tag = tag;
|
||||
chip.innerHTML = `${esc(tag)}<span class="tag-chip-remove" onclick="this.parentElement.remove()">×</span>`;
|
||||
chip.innerHTML = `${esc(tag)}<span class="tag-chip-remove" onclick="this.parentElement.remove(); updateTagSuggestions();">×</span>`;
|
||||
container.insertBefore(chip, input);
|
||||
});
|
||||
}
|
||||
@@ -601,6 +635,7 @@ function addTag() {
|
||||
renderModalTags([...current, val]);
|
||||
}
|
||||
input.value = '';
|
||||
updateTagSuggestions();
|
||||
}
|
||||
|
||||
document.getElementById('modal').addEventListener('click', e => {
|
||||
|
||||
Reference in New Issue
Block a user