-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (81 loc) · 2.74 KB
/
index.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
/*eslint-disable*/
import _ from 'lodash'; /*eslint-disable*/
import './style.css';
import { CRUD } from './Assets/CRUD.js';
const taskContainer = document.getElementById('task-container');
const submitButton = document.getElementById('addButton');
const clearAllDone = document.getElementById('clearComplete');
let editButtonStats=false;
window.onload = function windowReady() {
CRUD.showTask();
submitButton.onclick = function () {
CRUD.createTask();
};
taskContainer.addEventListener('click', (e) => {
if (e.target !== null && e.target !== 'NaN' && e.target !== '') {
if (e.target.className === 'checkbox-class') {
const ids = e.target.id.replace('checkbox-', '');
const description = document.getElementById('d' + ids);
const data = CRUD.getAllTasks();
const index = parseInt(ids, 10);
if (data !== []) {
if (data[index].completed) {
data[index].completed = false;
description.style.textDecoration = 'none';
} else {
data[index].completed = true;
description.style.textDecoration = 'line-through';
}
CRUD.updateTask(data);
}
}
}
});
// ! EDTING
taskContainer.addEventListener('click', (e) => {
if (e.target !== null && e.target !== 'NaN' && e.target !== '') {
if (e.target.className === 'editButton') {
const ids = e.target.id.replace('editBttn-', '');
let description = document.getElementById('d' + ids);
let data = CRUD.getAllTasks();
const index = parseInt(ids, 10);
let editInput = document.getElementById('edit-'+ ids);
description.style.display='none';
editInput.style.display='block';
if (editButtonStats !== false) {
data[index].description=editInput.value;
description.style.display='block';
editInput.style.display='none';
CRUD.updateTask(data);
CRUD.showTask();
editButtonStats = false;
}else{
editButtonStats = true;
}
}
}
});
//! REMOVING
CRUD.showTask();
taskContainer.addEventListener('click', (e) => {
if (e.target !== null && e.target !== 'NaN' && e.target !== '') {
if (e.target.className === 'deleteButton') {
const ids = e.target.id.replace('delete-', '');
const data = CRUD.getAllTasks();
const index = parseInt(ids, 10);
if (data !== []) {
CRUD.removeTask(index);
}
}
}
});
clearAllDone.addEventListener('click',(e)=>{
const data= CRUD.getAllTasks();
const storage=data.filter((todo)=>todo.completed===false);
for(let i=0; i<storage.length; i=+1) {
storage[i].index=i+1;
}
CRUD.updateTask(storage);
CRUD.showTask();
})
};