-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
71 lines (58 loc) · 1.93 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Recupera i riferimenti agli elementi del DOM
const taskForm = document.getElementById('taskForm');
const descriptionInput = document.getElementById('descriptionInput');
const deadlineInput = document.getElementById('deadlineInput');
const statusSelect = document.getElementById('statusSelect');
const taskList = document.getElementById('taskList');
// Array per memorizzare i compiti
let tasks = [];
// Funzione per aggiungere un nuovo compito
function addTask(event) {
event.preventDefault();
// Recupera i valori dai campi di input
const description = descriptionInput.value;
const deadline = deadlineInput.value;
const status = statusSelect.value;
// Crea un nuovo oggetto compito
const newTask = {
id: Date.now(),
description,
deadline,
status
};
// Aggiungi il nuovo compito all'array
tasks.push(newTask);
// Aggiorna l'interfaccia utente
renderTasks();
// Resetta i campi di input
descriptionInput.value = '';
deadlineInput.value = '';
statusSelect.value = 'inCorso';
}
// Funzione per renderizzare i compiti nell'interfaccia utente
function renderTasks() {
// Svuota la lista dei compiti
taskList.innerHTML = '';
// Itera attraverso l'array dei compiti e crea gli elementi della lista
tasks.forEach(task => {
const li = document.createElement('li');
li.innerHTML = `
<span>${task.description}</span>
<span>${task.deadline}</span>
<span>${task.status}</span>
<button onclick="deleteTask(${task.id})">Elimina</button>
`;
taskList.appendChild(li);
});
}
// Funzione per eliminare un compito
function deleteTask(id) {
// Filtra l'array dei compiti per escludere quello con l'id specificato
tasks = tasks.filter(task => task.id !== id);
// Aggiorna l'interfaccia utente
renderTasks();
}
// Aggiungi un listener per la sottomissione del modulo
taskForm.addEventListener('submit', addTask);
// Inizializza l'interfaccia utente dei compiti
renderTasks();