-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
114 lines (88 loc) · 2.98 KB
/
Copy pathscript.js
File metadata and controls
114 lines (88 loc) · 2.98 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const champSaisi = document.getElementById("saisiInput");
const btnAjouter = document.getElementById("btnAjouter");
const listeAffaire = document.getElementById("listeAffaire");
const buttonfiltre = document.querySelectorAll(".filter-btn");
const compteurTache = document.getElementById("compteurTache");
let taches = [];
let filtreActuel = "toutes";
let prochainId = 0;
function ajouterTache(){
const texte = champSaisi.value.trim();
if(texte){
taches.push({
id: prochainId++,
texte: texte,
terminer: false
});
}
champSaisi.value = "";
champSaisi.focus();
afficher();
}
function basculerTache(id){
const tache = taches.find(t => t.id === id);
if(tache){
tache.terminer = !tache.terminer;
afficher();
}
}
function supprimerTache(id){
taches = taches.filter(t => t.id !== id);
afficher();
}
function obtenirTacheFiltre(){
if(filtreActuel === "actif"){
return taches.filter(t => !t.terminer);
}
if(filtreActuel === "terminer"){
return taches.filter(t => t.terminer);
}
return taches;
}
function mettreCompteurAjour(){
const restantes = taches.filter(t => !t.terminer).length;
compteurTache.textContent = (restantes <= 1) ? `${restantes} tache restante `: `${restantes} taches restantes`;
}
function afficher(){
listeAffaire.innerHTML = "";
const tachesFiltre = obtenirTacheFiltre();
if(tachesFiltre.length === 0){
const message = document.createElement("li");
message.textContent = "Aucune tache a affaire";
message.className = "empty-msg";
listeAffaire.appendChild(message);
}
tachesFiltre.forEach(tache => {
const ligne = document.createElement("li");
ligne.className = "task-item";
const caseAccocher = document.createElement("input");
caseAccocher.type = "checkbox";
caseAccocher.checked = tache.terminer;
caseAccocher.addEventListener("click", () => basculerTache(tache.id));
const texteTAche = document.createElement("span");
texteTAche.className = "task-text";
texteTAche.textContent = tache.texte;
const btnSupprimer = document.createElement("button");
btnSupprimer.className = "delete-btn";
btnSupprimer.innerHTML = "x";
btnSupprimer.addEventListener("click", () => supprimerTache(tache.id));
ligne.appendChild(caseAccocher);
ligne.appendChild(texteTAche);
ligne.appendChild(btnSupprimer);
listeAffaire.appendChild(ligne);
});
mettreCompteurAjour();
}
buttonfiltre.forEach(bouton => {
bouton.addEventListener("click", () => {
buttonfiltre.forEach(b => b.classList.remove("actif"));
bouton.classList.add("actif");
filtreActuel = bouton.dataset.filtre;
afficher();
});
});
btnAjouter.addEventListener("click", ajouterTache);
champSaisi.addEventListener("keydown", e => {
if(e.key === "Enter") ajouterTache();
});
afficher();