prova1 / index.html
valsi's picture
Add 3 files
c5adc7e verified
Raw History Blame Contribute Delete
37.2 kB
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diario Lavoro - Gestione Squadre</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<style>
/* Stili personalizzati */
.edit-mode .editable {
outline: 2px dashed #3b82f6;
position: relative;
}
.edit-mode .resize-handle {
width: 10px;
height: 10px;
background-color: #3b82f6;
position: absolute;
z-index: 10;
}
.resize-handle-tl { top: -5px; left: -5px; cursor: nwse-resize; }
.resize-handle-tr { top: -5px; right: -5px; cursor: nesw-resize; }
.resize-handle-bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.resize-handle-br { bottom: -5px; right: -5px; cursor: nwse-resize; }
.table-container {
position: relative;
width: 100%;
height: 300px;
background-color: #f3f4f6;
border: 1px solid #d1d5db;
}
.table-seat {
position: absolute;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: white;
border: 1px solid #e5e7eb;
border-radius: 4px;
padding: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.worker-name {
font-weight: bold;
margin-bottom: 4px;
color: #1f2937;
}
.worker-task {
font-size: 0.875rem;
color: #4b5563;
}
.draggable {
cursor: move;
}
.dropdown-content {
display: none;
position: absolute;
background-color: white;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 100;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Stili per il tema blu carta da zucchero */
.bg-sugar-blue {
background-color: #e6f0ff;
}
.border-sugar-blue {
border-color: #b3d1ff;
}
.text-sugar-blue {
color: #0066cc;
}
.hover-sugar-blue:hover {
background-color: #cce0ff;
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<div class="container mx-auto px-4 py-8">
<!-- Header con titolo e pulsanti -->
<header class="flex justify-between items-center mb-8">
<h1 class="text-3xl font-bold text-gray-800">Diario di Lavoro</h1>
<div class="flex space-x-4">
<!-- Pulsante modalità modifica -->
<button id="editModeBtn" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">
<i class="fas fa-edit mr-2"></i>Modalità Modifica
</button>
<!-- Pulsanti import/export -->
<div class="relative">
<button id="importExportBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition flex items-center">
<i class="fas fa-file-excel mr-2"></i>Excel
<i class="fas fa-caret-down ml-2"></i>
</button>
<div class="dropdown-content hidden absolute right-0 mt-2 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5">
<input type="file" id="fileInput" class="hidden" accept=".xlsx,.xls">
<a href="#" id="importBtn" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Importa da Excel</a>
<a href="#" id="exportBtn" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Esporta in Excel</a>
</div>
</div>
<!-- Pulsante salva modifiche (visibile solo in modalità modifica) -->
<button id="saveChangesBtn" class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition hidden">
<i class="fas fa-save mr-2"></i>Salva Modifiche
</button>
</div>
</header>
<!-- Sezione selezione squadra e data -->
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
<div class="flex flex-wrap items-center gap-6">
<!-- Selezione squadra -->
<div class="flex-1 min-w-[200px]">
<label for="teamSelect" class="block text-sm font-medium text-gray-700 mb-1">Squadra</label>
<select id="teamSelect" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
<option value="morning">Mattina</option>
<option value="afternoon">Pomeriggio</option>
</select>
</div>
<!-- Selezione data -->
<div class="flex-1 min-w-[200px]">
<label for="dateSelect" class="block text-sm font-medium text-gray-700 mb-1">Data</label>
<input type="date" id="dateSelect" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<!-- Pulsante aggiungi operaio -->
<div class="flex-1 min-w-[200px]">
<label class="block text-sm font-medium text-gray-700 mb-1">Aggiungi Operaio</label>
<button id="addWorkerBtn" class="w-full px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">
<i class="fas fa-user-plus mr-2"></i>Aggiungi
</button>
</div>
</div>
</div>
<!-- Contenitore principale con tavolo e lista lavori -->
<div class="flex flex-col lg:flex-row gap-8">
<!-- Sezione tavolo di lavoro -->
<div class="flex-1 bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Tavolo di Lavoro</h2>
<!-- Contenitore del tavolo (rettangolo con postazioni) -->
<div id="tableContainer" class="table-container relative mx-auto my-4" style="width: 80%; height: 300px;">
<!-- Postazioni del tavolo (6 zone) -->
<!-- Lato superiore (3 postazioni) -->
<div id="seat1" class="table-seat editable draggable" style="top: 10%; left: 20%; width: 100px; height: 80px;">
<div class="worker-name dropdown">
<span class="current-value">Postazione 1</span>
<div class="dropdown-content">
<!-- Popolato dinamicamente con JavaScript -->
</div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Mansione</span>
<div class="dropdown-content">
<!-- Popolato dinamicamente con JavaScript -->
</div>
</div>
</div>
<div id="seat2" class="table-seat editable draggable" style="top: 10%; left: 45%; width: 100px; height: 80px;">
<div class="worker-name dropdown">
<span class="current-value">Postazione 2</span>
<div class="dropdown-content"></div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Mansione</span>
<div class="dropdown-content"></div>
</div>
</div>
<div id="seat3" class="table-seat editable draggable" style="top: 10%; right: 20%; width: 100px; height: 80px;">
<div class="worker-name dropdown">
<span class="current-value">Postazione 3</span>
<div class="dropdown-content"></div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Mansione</span>
<div class="dropdown-content"></div>
</div>
</div>
<!-- Lato inferiore (3 postazioni) -->
<div id="seat4" class="table-seat editable draggable" style="bottom: 10%; left: 20%; width: 100px; height: 80px;">
<div class="worker-name dropdown">
<span class="current-value">Postazione 4</span>
<div class="dropdown-content"></div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Mansione</span>
<div class="dropdown-content"></div>
</div>
</div>
<div id="seat5" class="table-seat editable draggable" style="bottom: 10%; left: 45%; width: 100px; height: 80px;">
<div class="worker-name dropdown">
<span class="current-value">Postazione 5</span>
<div class="dropdown-content"></div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Mansione</span>
<div class="dropdown-content"></div>
</div>
</div>
<div id="seat6" class="table-seat editable draggable" style="bottom: 10%; right: 20%; width: 100px; height: 80px;">
<div class="worker-name dropdown">
<span class="current-value">Postazione 6</span>
<div class="dropdown-content"></div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Mansione</span>
<div class="dropdown-content"></div>
</div>
</div>
</div>
</div>
<!-- Sezione lavori esterni -->
<div class="flex-1 bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Lavori Esterni</h2>
<!-- Lista lavori esterni -->
<div id="externalWorkList" class="space-y-3">
<div class="external-worker-item p-3 border border-gray-200 rounded-lg hover:bg-gray-50">
<div class="flex justify-between items-center">
<div class="worker-name dropdown">
<span class="current-value">Operaio Esterno 1</span>
<div class="dropdown-content">
<!-- Popolato dinamicamente con JavaScript -->
</div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Mansione Esterna</span>
<div class="dropdown-content">
<!-- Popolato dinamicamente con JavaScript -->
</div>
</div>
<button class="text-red-500 hover:text-red-700">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- Altri elementi verranno aggiunti dinamicamente -->
</div>
<!-- Pulsante aggiungi lavoro esterno -->
<button id="addExternalWorkBtn" class="mt-4 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition w-full">
<i class="fas fa-plus mr-2"></i>Aggiungi Lavoro Esterno
</button>
</div>
</div>
<!-- Sezione note -->
<div class="bg-white rounded-lg shadow-md p-6 mt-8">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Note</h2>
<textarea id="notesArea" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 min-h-[100px]" placeholder="Aggiungi qui le note importanti..."></textarea>
</div>
</div>
<!-- Modale per aggiungere nuovo operaio -->
<div id="addWorkerModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-white rounded-lg shadow-xl p-6 w-full max-w-md">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Aggiungi Nuovo Operaio</h3>
<div class="space-y-4">
<div>
<label for="newWorkerName" class="block text-sm font-medium text-gray-700 mb-1">Nome</label>
<input type="text" id="newWorkerName" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="newWorkerTasks" class="block text-sm font-medium text-gray-700 mb-1">Mansioni (separate da virgola)</label>
<textarea id="newWorkerTasks" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 min-h-[80px]"></textarea>
</div>
</div>
<div class="mt-6 flex justify-end space-x-3">
<button id="cancelAddWorkerBtn" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg hover:bg-gray-400 transition">Annulla</button>
<button id="confirmAddWorkerBtn" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">Conferma</button>
</div>
</div>
</div>
<script>
// Variabili globali
let editMode = false;
let workers = [
{ id: 1, name: "Mario Rossi", tasks: ["Taglio legno", "Assemblaggio", "Verniciatura"] },
{ id: 2, name: "Luigi Bianchi", tasks: ["Assemblaggio", "Controllo qualità", "Imballaggio"] },
{ id: 3, name: "Giovanni Verdi", tasks: ["Taglio legno", "Verniciatura", "Imballaggio"] },
{ id: 4, name: "Paolo Neri", tasks: ["Progettazione", "Controllo qualità", "Assemblaggio"] },
{ id: 5, name: "Antonio Gialli", tasks: ["Verniciatura", "Imballaggio", "Spedizione"] },
{ id: 6, name: "Marco Blu", tasks: ["Taglio legno", "Assemblaggio", "Spedizione"] }
];
let tasks = [
"Taglio legno", "Assemblaggio", "Verniciatura",
"Controllo qualità", "Imballaggio", "Spedizione",
"Progettazione", "Manutenzione", "Logistica"
];
let externalWorkers = [];
let currentData = {};
// Elementi selezionati per il drag & drop
let selectedElement = null;
let selectedHandle = null;
let startX, startY, startWidth, startHeight, startLeft, startTop;
// Inizializzazione dell'applicazione
document.addEventListener('DOMContentLoaded', function() {
// Imposta la data odierna come default
const today = new Date().toISOString().split('T')[0];
document.getElementById('dateSelect').value = today;
// Carica i dati salvati (se presenti)
loadSavedData();
// Popola i dropdown degli operai e delle mansioni
populateDropdowns();
// Setup event listeners
setupEventListeners();
});
// Funzione per caricare i dati salvati
function loadSavedData() {
// Qui dovresti implementare il caricamento da localStorage o da file
// Per ora usiamo dati di esempio
currentData = {
date: document.getElementById('dateSelect').value,
team: document.getElementById('teamSelect').value,
seats: {},
externalWork: [],
notes: ""
};
// Aggiorna l'interfaccia con i dati caricati
updateUI();
}
// Funzione per popolare i dropdown
function populateDropdowns() {
const nameDropdowns = document.querySelectorAll('.worker-name .dropdown-content');
const taskDropdowns = document.querySelectorAll('.worker-task .dropdown-content');
// Popola dropdown nomi
nameDropdowns.forEach(dropdown => {
dropdown.innerHTML = '';
workers.forEach(worker => {
const option = document.createElement('div');
option.className = 'px-4 py-2 hover:bg-gray-100 cursor-pointer';
option.textContent = worker.name;
option.addEventListener('click', function() {
this.closest('.dropdown').querySelector('.current-value').textContent = worker.name;
// Potremmo voler aggiornare anche le mansioni disponibili per questo operaio
});
dropdown.appendChild(option);
});
});
// Popola dropdown mansioni
taskDropdowns.forEach(dropdown => {
dropdown.innerHTML = '';
tasks.forEach(task => {
const option = document.createElement('div');
option.className = 'px-4 py-2 hover:bg-gray-100 cursor-pointer';
option.textContent = task;
option.addEventListener('click', function() {
this.closest('.dropdown').querySelector('.current-value').textContent = task;
});
dropdown.appendChild(option);
});
});
}
// Funzione per aggiornare l'interfaccia con i dati correnti
function updateUI() {
// Qui implementeresti l'aggiornamento dell'UI con i dati in currentData
// Per ora è vuoto perché usiamo i valori di default
}
// Funzione per impostare tutti gli event listeners
function setupEventListeners() {
// Pulsante modalità modifica
document.getElementById('editModeBtn').addEventListener('click', toggleEditMode);
// Pulsante salva modifiche
document.getElementById('saveChangesBtn').addEventListener('click', saveChanges);
// Pulsanti import/export Excel
document.getElementById('importBtn').addEventListener('click', function() {
document.getElementById('fileInput').click();
});
document.getElementById('exportBtn').addEventListener('click', exportToExcel);
document.getElementById('fileInput').addEventListener('change', importFromExcel);
// Pulsante aggiungi operaio
document.getElementById('addWorkerBtn').addEventListener('click', showAddWorkerModal);
document.getElementById('cancelAddWorkerBtn').addEventListener('click', hideAddWorkerModal);
document.getElementById('confirmAddWorkerBtn').addEventListener('click', confirmAddWorker);
// Pulsante aggiungi lavoro esterno
document.getElementById('addExternalWorkBtn').addEventListener('click', addExternalWorkItem);
// Mostra/nascondi dropdown al click
document.querySelectorAll('.dropdown .current-value').forEach(el => {
el.addEventListener('click', function() {
if (editMode) return; // In modalità modifica, gestiamo il drag & drop
const dropdownContent = this.nextElementSibling;
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
});
// Chiudi dropdown quando si clicca altrove
document.addEventListener('click', function(e) {
if (!e.target.closest('.dropdown')) {
document.querySelectorAll('.dropdown-content').forEach(dropdown => {
dropdown.style.display = 'none';
});
}
});
// Setup per il drag & drop e ridimensionamento
setupDragAndDrop();
}
// Funzione per attivare/disattivare la modalità modifica
function toggleEditMode() {
editMode = !editMode;
const editBtn = document.getElementById('editModeBtn');
const saveBtn = document.getElementById('saveChangesBtn');
if (editMode) {
// Attiva modalità modifica
document.body.classList.add('edit-mode');
editBtn.innerHTML = '<i class="fas fa-times mr-2"></i>Esci da Modifica';
editBtn.classList.remove('bg-blue-600');
editBtn.classList.add('bg-red-600');
saveBtn.classList.remove('hidden');
// Aggiungi handle di ridimensionamento agli elementi modificabili
addResizeHandles();
} else {
// Disattiva modalità modifica
document.body.classList.remove('edit-mode');
editBtn.innerHTML = '<i class="fas fa-edit mr-2"></i>Modalità Modifica';
editBtn.classList.remove('bg-red-600');
editBtn.classList.add('bg-blue-600');
saveBtn.classList.add('hidden');
// Rimuovi handle di ridimensionamento
removeResizeHandles();
}
}
// Funzione per aggiungere handle di ridimensionamento
function addResizeHandles() {
document.querySelectorAll('.editable').forEach(el => {
// Crea gli handle per i 4 angoli
const handles = [
{ position: 'tl', class: 'resize-handle-tl' },
{ position: 'tr', class: 'resize-handle-tr' },
{ position: 'bl', class: 'resize-handle-bl' },
{ position: 'br', class: 'resize-handle-br' }
];
handles.forEach(handle => {
const handleEl = document.createElement('div');
handleEl.className = `resize-handle ${handle.class}`;
handleEl.dataset.position = handle.position;
el.appendChild(handleEl);
});
});
}
// Funzione per rimuovere handle di ridimensionamento
function removeResizeHandles() {
document.querySelectorAll('.resize-handle').forEach(handle => {
handle.remove();
});
}
// Funzione per impostare il drag & drop e il ridimensionamento
function setupDragAndDrop() {
// Mousedown sugli elementi modificabili
document.addEventListener('mousedown', function(e) {
if (!editMode) return;
const target = e.target;
// Verifica se è un handle di ridimensionamento
if (target.classList.contains('resize-handle')) {
selectedHandle = target;
selectedElement = target.parentElement;
// Salva le dimensioni e posizione iniziali
const style = window.getComputedStyle(selectedElement);
startWidth = parseInt(style.width, 10);
startHeight = parseInt(style.height, 10);
startLeft = parseInt(style.left, 10);
startTop = parseInt(style.top, 10);
startX = e.clientX;
startY = e.clientY;
e.preventDefault();
return;
}
// Verifica se è un elemento modificabile
if (target.closest('.editable')) {
selectedElement = target.closest('.editable');
// Salva la posizione iniziale
const style = window.getComputedStyle(selectedElement);
startLeft = parseInt(style.left, 10);
startTop = parseInt(style.top, 10);
startX = e.clientX;
startY = e.clientY;
e.preventDefault();
}
});
// Mousemove per il drag e il ridimensionamento
document.addEventListener('mousemove', function(e) {
if (!editMode || !selectedElement) return;
if (selectedHandle) {
// Ridimensionamento
const dx = e.clientX - startX;
const dy = e.clientY - startY;
const position = selectedHandle.dataset.position;
let newWidth = startWidth;
let newHeight = startHeight;
let newLeft = startLeft;
let newTop = startTop;
// Calcola nuove dimensioni e posizione in base all'handle
if (position.includes('r')) {
newWidth = startWidth + dx;
}
if (position.includes('l')) {
newWidth = startWidth - dx;
newLeft = startLeft + dx;
}
if (position.includes('b')) {
newHeight = startHeight + dy;
}
if (position.includes('t')) {
newHeight = startHeight - dy;
newTop = startTop + dy;
}
// Applica le nuove dimensioni (con limiti minimi)
selectedElement.style.width = Math.max(80, newWidth) + 'px';
selectedElement.style.height = Math.max(60, newHeight) + 'px';
selectedElement.style.left = newLeft + 'px';
selectedElement.style.top = newTop + 'px';
} else {
// Spostamento
const dx = e.clientX - startX;
const dy = e.clientY - startY;
selectedElement.style.left = (startLeft + dx) + 'px';
selectedElement.style.top = (startTop + dy) + 'px';
}
});
// Mouseup per terminare il drag/ridimensionamento
document.addEventListener('mouseup', function() {
selectedElement = null;
selectedHandle = null;
});
}
// Funzione per salvare le modifiche
function saveChanges() {
// Qui implementeresti il salvataggio dei dati
// Per ora simuliamo il salvataggio
console.log("Modifiche salvate");
// Esci dalla modalità modifica
toggleEditMode();
}
// Funzione per esportare in Excel
function exportToExcel() {
// Crea un workbook con 3 fogli: operai, mansioni, assegnazioni
const wb = XLSX.utils.book_new();
// Foglio operai
const workersSheet = XLSX.utils.json_to_sheet(
workers.map(w => ({
"ID": w.id,
"Nome": w.name,
"Mansioni": w.tasks.join(", ")
}))
);
XLSX.utils.book_append_sheet(wb, workersSheet, "Operai");
// Foglio mansioni
const tasksSheet = XLSX.utils.json_to_sheet(
tasks.map(t => ({ "Mansione": t }))
);
XLSX.utils.book_append_sheet(wb, tasksSheet, "Mansioni");
// Foglio assegnazioni (dati correnti)
// Qui dovresti implementare la logica per salvare le assegnazioni attuali
const assignments = [];
XLSX.utils.book_append_sheet(wb, XLSX.utils.json_to_sheet(assignments), "Assegnazioni");
// Esporta il file
const date = new Date().toISOString().slice(0, 10);
XLSX.writeFile(wb, `Diario_Lavoro_${date}.xlsx`);
// Simula l'invio via email (nella realtà dovresti usare un API)
console.log("Inviando copia a sam.balest@gmail.com...");
}
// Funzione per importare da Excel
function importFromExcel(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
// Leggi il foglio operai
if (workbook.Sheets["Operai"]) {
const workersData = XLSX.utils.sheet_to_json(workbook.Sheets["Operai"]);
workers = workersData.map(w => ({
id: w["ID"],
name: w["Nome"],
tasks: w["Mansioni"] ? w["Mansioni"].split(", ") : []
}));
}
// Leggi il foglio mansioni
if (workbook.Sheets["Mansioni"]) {
const tasksData = XLSX.utils.sheet_to_json(workbook.Sheets["Mansioni"]);
tasks = tasksData.map(t => t["Mansione"]);
}
// Leggi il foglio assegnazioni (se presente)
if (workbook.Sheets["Assegnazioni"]) {
// Qui dovresti implementare il caricamento delle assegnazioni
}
// Aggiorna l'interfaccia
populateDropdowns();
updateUI();
alert("Dati importati con successo!");
};
reader.readAsArrayBuffer(file);
}
// Funzioni per la gestione degli operai esterni
function addExternalWorkItem() {
const container = document.getElementById('externalWorkList');
const newItem = document.createElement('div');
newItem.className = 'external-worker-item p-3 border border-gray-200 rounded-lg hover:bg-gray-50 editable draggable';
newItem.innerHTML = `
<div class="flex justify-between items-center">
<div class="worker-name dropdown">
<span class="current-value">Nuovo Operaio</span>
<div class="dropdown-content">
${workers.map(w => `<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer">${w.name}</div>`).join('')}
</div>
</div>
<div class="worker-task dropdown">
<span class="current-value">Nuova Mansione</span>
<div class="dropdown-content">
${tasks.map(t => `<div class="px-4 py-2 hover:bg-gray-100 cursor-pointer">${t}</div>`).join('')}
</div>
</div>
<button class="text-red-500 hover:text-red-700 remove-external-btn">
<i class="fas fa-times"></i>
</button>
</div>
`;
container.appendChild(newItem);
// Aggiungi event listener per il dropdown
newItem.querySelector('.worker-name .current-value').addEventListener('click', function() {
if (editMode) return;
const dropdownContent = this.nextElementSibling;
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
newItem.querySelector('.worker-task .current-value').addEventListener('click', function() {
if (editMode) return;
const dropdownContent = this.nextElementSibling;
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
// Aggiungi event listener per la rimozione
newItem.querySelector('.remove-external-btn').addEventListener('click', function() {
newItem.remove();
});
// Aggiungi opzioni dropdown
newItem.querySelectorAll('.dropdown-content div').forEach(option => {
option.addEventListener('click', function() {
this.closest('.dropdown').querySelector('.current-value').textContent = this.textContent;
});
});
}
// Funzioni per la gestione della modale aggiungi operaio
function showAddWorkerModal() {
document.getElementById('addWorkerModal').classList.remove('hidden');
}
function hideAddWorkerModal() {
document.getElementById('addWorkerModal').classList.add('hidden');
document.getElementById('newWorkerName').value = '';
document.getElementById('newWorkerTasks').value = '';
}
function confirmAddWorker() {
const name = document.getElementById('newWorkerName').value.trim();
const tasksStr = document.getElementById('newWorkerTasks').value.trim();
if (!name) {
alert("Inserisci un nome per l'operaio");
return;
}
const newWorker = {
id: workers.length > 0 ? Math.max(...workers.map(w => w.id)) + 1 : 1,
name: name,
tasks: tasksStr ? tasksStr.split(',').map(t => t.trim()) : []
};
workers.push(newWorker);
// Aggiungi nuove mansioni alla lista globale se non presenti
newWorker.tasks.forEach(task => {
if (!tasks.includes(task)) {
tasks.push(task);
}
});
// Aggiorna i dropdown
populateDropdowns();
// Chiudi la modale e resetta i campi
hideAddWorkerModal();
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=valsi/prova1" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>