@@ -239,14 +264,42 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
background-color: #f1f3f5;
}
+ /* Stile per il dropdown dei tag */
+ .dropdown-menu {
+ max-height: 200px;
+ overflow-y: auto;
+ }
+
+ .tag-option:hover {
+ background-color: #f1f3f5;
+ cursor: pointer;
+ }
+
+ /* Stile per i badge selezionati */
+ #selectedTags .tag-badge {
+ background-color: #e6f0fa;
+ /* Colore chiaro per i badge selezionati */
+ color: #2c3e50;
+ font-size: 0.9rem;
+ padding: 0.4em 0.8em;
+ border-radius: 10px;
+ display: flex;
+ align-items: center;
+ margin-bottom: 5px;
+ }
+
+ #selectedTags .tag-badge .remove-tag {
+ font-size: 0.7rem;
+ margin-left: 5px;
+ cursor: pointer;
+ color: #dc3545;
+ }
+
/* Stile per il titolo del documento */
.document-title {
font-weight: bold;
- /* Grassetto per maggiore risalto */
font-size: 1.1rem;
- /* Aumenta leggermente la dimensione */
color: #2c3e50;
- /* Colore scuro per contrasto */
}
/* Stile per il preloader */
@@ -307,7 +360,11 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
.document-title {
font-size: 1rem;
- /* Riduci leggermente su mobile */
+ }
+
+ .tag-badge {
+ font-size: 0.8rem;
+ padding: 0.3em 0.6em;
}
}
@@ -317,9 +374,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
let idhome = ;
let currentCategory = '';
let currentSection = null;
+ let selectedTags = []; // Array per tenere traccia dei tag selezionati
- // Caricamento iniziale: non carichiamo documenti finché non selezioniamo una sezione
- // loadDocuments(currentCategory); // Rimuoviamo questa chiamata
+ // Caricamento iniziale: non carichiamo documenti finché non selezioniamo una categoria o cerchiamo
// Gestione del clic sulle icone delle categorie
$('.category-icon').on('click', function() {
@@ -331,29 +388,29 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
$('.category-icon').removeClass('active');
$(this).addClass('active');
$('.section-icons-container').hide().empty();
- $('#documentSections').empty(); // Svuota i documenti quando selezioni una categoria
- $('.preloader').show(); // Mostra il preloader
+ $('#documentSections').empty();
+ $('.preloader').show();
loadSections(slug);
});
// Gestione del clic sulle icone delle sezioni
$(document).on('click', '.section-icon', function() {
const sectionId = $(this).data('section-id');
- const sectionName = $(this).find('.section-name').text(); // Recupera il nome della sezione
+ const sectionName = $(this).find('.section-name').text();
if (currentSection === sectionId) return;
currentSection = sectionId;
$('.section-icon').removeClass('active');
$(this).addClass('active');
- $('.document-preloader').show(); // Mostra il preloader per i documenti
- loadDocuments(currentCategory, sectionId, sectionName); // Carica i documenti della sezione
+ $('.document-preloader').show();
+ loadDocuments(currentCategory, sectionId, sectionName);
});
// Gestione del checkbox "Solo obbligatori"
$("#showOnlyRequired").on('change', function() {
- if (currentSection) { // Carica solo se una sezione è selezionata
+ if (currentSection) {
const sectionName = $('.section-icon.active .section-name').text();
- $('.document-preloader').show(); // Mostra il preloader
+ $('.document-preloader').show();
loadDocuments(currentCategory, currentSection, sectionName);
}
});
@@ -369,7 +426,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
},
dataType: 'json',
success: function(response) {
- $('.preloader').hide(); // Nascondi il preloader
+ $('.preloader').hide();
if (response.error) {
console.error(response.error);
return;
@@ -385,7 +442,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
$('.section-icons-container').html(html).slideDown();
},
error: function(xhr, status, error) {
- $('.preloader').hide(); // Nascondi il preloader in caso di errore
+ $('.preloader').hide();
console.error('Errore nel caricamento delle sezioni:', error);
}
});
@@ -395,23 +452,28 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
let allDocuments = [];
query("
- SELECT d.document_id, d.document_name, p.slug, s.section_name
+ SELECT d.document_id, d.document_name, p.slug, s.section_name, GROUP_CONCAT(t.tag_name) AS tags
FROM documents d
LEFT JOIN sections s ON d.idsections = s.idsections
LEFT JOIN pages p ON d.page_id = p.idpages
+ LEFT JOIN document_tags dt ON d.document_id = dt.document_id
+ LEFT JOIN tags t ON dt.tag_id = t.tag_id
+ GROUP BY d.document_id, d.document_name, p.slug, s.section_name
ORDER BY s.section_name, d.document_name
");
while ($doc = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $tags = $doc['tags'] ? addslashes(htmlspecialchars($doc['tags'])) : '';
echo "allDocuments.push({
id: '{$doc['document_id']}',
name: '" . addslashes(htmlspecialchars($doc['document_name'])) . "',
section: '" . addslashes(htmlspecialchars($doc['section_name'])) . "',
- slug: '" . addslashes(htmlspecialchars($doc['slug'])) . "'
+ slug: '" . addslashes(htmlspecialchars($doc['slug'])) . "',
+ tags: '{$tags}'
});\n";
}
?>
- // Gestione della ricerca dinamica
+ // Gestione della ricerca dinamica per nome/sezione
$('#documentSearch').on('input', function() {
const searchTerm = $(this).val().toLowerCase().trim();
$('#searchResults').empty().hide();
@@ -428,8 +490,8 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
if (results.length > 0) {
let html = '';
results.forEach(result => {
- html += `
- ${result.name} (Sezione: ${result.section})
+ html += `
+ ${result.name} (Sezione: ${result.section}${result.tags ? ', Tag: ' + result.tags : ''})
`;
});
$('#searchResults').html(html).show();
@@ -438,33 +500,69 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
e.preventDefault();
const slug = $(this).data('slug');
const sectionId = $(this).data('section');
+ const documentName = $(this).data('name');
currentCategory = slug;
currentSection = sectionId;
$('.category-icon').removeClass('active');
$('.category-icon[data-slug="' + slug + '"]').addClass('active');
$('.section-icons-container').hide().empty();
- $('.preloader').show(); // Mostra il preloader durante la ricerca
- loadSections(slug);
+ $('#documentSections').empty();
+ $('.document-preloader').show();
+
+ // Carica direttamente i documenti senza passare per le sezioni
+ loadDocuments(slug, sectionId, null, documentName);
$('#documentSearch').val('');
$('#searchResults').hide();
-
- // Trova il nome della sezione e carica i documenti
- setTimeout(() => {
- const sectionElement = $(`.section-icon[data-section-id="${sectionId}"]`);
- if (sectionElement.length) {
- $('.section-icon').removeClass('active');
- sectionElement.addClass('active');
- const sectionName = sectionElement.find('.section-name').text();
- $('.document-preloader').show(); // Mostra il preloader
- loadDocuments(slug, sectionId, sectionName);
- }
- }, 500);
});
}
});
+ // Gestione del dropdown dei tag
+ $('.tag-option').on('click', function(e) {
+ e.preventDefault();
+ const tagId = $(this).data('tag-id');
+ const tagName = $(this).data('tag-name');
+
+ if (!selectedTags.some(t => t.id === tagId)) {
+ selectedTags.push({
+ id: tagId,
+ name: tagName
+ });
+ updateSelectedTags();
+ if (currentSection) {
+ const sectionName = $('.section-icon.active .section-name').text();
+ $('.document-preloader').show();
+ loadDocuments(currentCategory, currentSection, sectionName);
+ }
+ }
+ });
+
+ // Funzione per aggiornare i badge dei tag selezionati
+ function updateSelectedTags() {
+ $('#selectedTags').empty();
+ selectedTags.forEach(tag => {
+ $('#selectedTags').append(`
+
+ ${tag.name}
+ ×
+
+ `);
+ });
+ $('.remove-tag').on('click', function(e) {
+ e.preventDefault();
+ const tagId = $(this).data('tag-id');
+ selectedTags = selectedTags.filter(t => t.id !== tagId);
+ updateSelectedTags();
+ if (currentSection) {
+ const sectionName = $('.section-icon.active .section-name').text();
+ $('.document-preloader').show();
+ loadDocuments(currentCategory, currentSection, sectionName);
+ }
+ });
+ }
+
// Chiudi i risultati della ricerca se clicchi fuori
$(document).on('click', function(e) {
if (!$(e.target).closest('.input-group, #searchResults').length) {
@@ -472,8 +570,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
}
});
- function loadDocuments(slug, targetSectionId = null, sectionName = null) {
+ function loadDocuments(slug, targetSectionId = null, sectionName = null, searchName = null) {
const showOnlyRequired = $("#showOnlyRequired").is(":checked");
+ const tagIds = selectedTags.map(t => t.id);
$.ajax({
url: 'get-documents.php',
@@ -482,11 +581,13 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
slug: slug,
idhome: idhome,
showOnlyRequired: showOnlyRequired,
- sectionId: targetSectionId ? targetSectionId : null
+ sectionId: targetSectionId ? targetSectionId : null,
+ tags: tagIds.length > 0 ? tagIds.join(',') : null,
+ searchName: searchName ? searchName : null
},
dataType: 'json',
success: function(response) {
- $('.document-preloader').hide(); // Nascondi il preloader
+ $('.document-preloader').hide();
if (response.error) {
Swal.fire({
icon: 'error',
@@ -515,7 +616,6 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
}
sectionCount++;
- // Usa il nome della sezione passato come parametro
const displaySectionName = sectionName || sectionKey;
html += `
@@ -540,6 +640,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
${document.document_name || 'Documento senza nome'}
${document.is_required ? '
Obbligatorio' : ''}
${document.max_documents > 0 ? `
Max: ${document.max_documents}` : ''}
+ ${document.tags ? `
Tag: ${document.tags}` : ''}