-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
130 lines (109 loc) · 3.24 KB
/
main.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Se crea lista de Tareas
class taskList {
constructor({
// lista, //Nombre de la lista
tareas = [], // Tareas pendientes
tareasCompletadas = [], //Tereas Completadas
}) {
// this.lista = lista;
this.tareas = tareas;
this.tareasCompletadas = tareasCompletadas;
}
agregarTarea(newTarea){
this.tareas.push(newTarea);
}
completeTask(element){
this.tareasCompletadas.push(element);
let value = this.tareas.indexOf(element);
this.tareas.splice(value, 1);
}
deleteTask(element){
let value = this.tareas.indexOf(element);
this.tareas.splice(value, 1);
}
deleteAll(){
this.tareas = [];
this.tareasCompletadas = [];
}
}
const tareaDelHogar = new taskList({
// lista: "Tareas del Hogar",
tareas: [
"Clean bathroom",
"wash restroom",
"wash clothes",
"clean the house",
"destroid the universe"
],
});
// Show task in html
function showData(){
const elementList = document.getElementById('taskList-ul');
const list = tareaDelHogar.tareas.map((tareaDelHogar, index) => {
return `<li>
<span class='algo' onclick="taskCompleted(item_${index})"><i class="fa fa-check-circle-o" aria-hidden="true"></i></span>
<p id="item_${index}">${tareaDelHogar}</p>
<span class='deleteTask' onclick="taskDelete(item_${index})"><i class="fa fa-minus-square" aria-hidden="true"></i></span>
</li>`;
});
elementList.innerHTML = list.join('');
}
function showDataComplete(){
const elementList = document.getElementById('taskCompleted-ul');
const list = tareaDelHogar.tareasCompletadas.map(tareaDelHogar => {
return `<li>${tareaDelHogar}</li>`;
});
elementList.innerHTML = list.join('');
}
// add new task.
function newElement(){
const newTask = document.getElementById('labelTask').value;
if(newTask === ''){
alert('You need write Something');
} else {
tareaDelHogar.agregarTarea(newTask);
document.getElementById('labelTask').value = '';
showData()
}
}
// Select list element
// var list = document.querySelector('ul');
// list.addEventListener('click', function(ev) {
// if (ev.target.tagName === 'LI') {
// let item = ev.target.classList.toggle('checked');
// let value = ev.target.innerHTML;
// if(item){
// tareaDelHogar.deleteTask(value);
// console.log(value);
// }
// }
// });
// function taskCompleted(indexItem){
// let algo = document.getElementById('indexItem').value;
// console.log(indexItem)
// let dropItem = tareaDelHogar.deleteTask(indexItem);
// showData();
// showDataComplete();
// }
function taskCompleted(indexItem){
let droop = indexItem.innerText;
console.log(droop)
let dropItem = tareaDelHogar.completeTask(droop);
showData();
showDataComplete();
}
function taskDelete(indexItem){
let droop = indexItem.innerText;
console.log(droop)
let dropItem = tareaDelHogar.deleteTask(droop);
showData();
showDataComplete();
}
function clearAll(){
tareaDelHogar.deleteAll();
showData();
showDataComplete();
}
{/* <span class='algo' onclick="taskCompleted(item_${index})">✔</span>$ */}
showData();
showDataComplete();