-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (49 loc) · 1.92 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
let taskManager = new TaskManager(0);
taskManager.load();
taskManager.render();
const newTaskForm = document.querySelector('#newTaskForm');
newTaskForm.addEventListener('submit', (event) => {
event.preventDefault();
const newTaskNameInput = document.querySelector('#newTaskNameInput');
const newTaskDescription = document.querySelector('#newTaskDescription');
const newTaskAssignedTo = document.querySelector('#newTaskAssignedTo');
const newTaskDueDate = document.querySelector('#newTaskDueDate');
/*
Validation code here
*/
const name = newTaskNameInput.value;
const description = newTaskDescription.value;
const assignedTo = newTaskAssignedTo.value;
const dueDate = newTaskDueDate.value;
taskManager.addTask(name, description, assignedTo, dueDate);
taskManager.save();
taskManager.render();
newTaskNameInput.value = '';
newTaskDescription.value = '';
newTaskAssignedTo.value = '';
newTaskDueDate.value = '';
});
const tasksList = document.querySelector('#tasksList');
tasksList.addEventListener('click', (event) => {
if (event.target.classList.contains('done-button')) {
const parentTask = event.target.parentElement.parentElement;
const taskId = Number(parentTask.dataset.taskId);
const task = taskManager.getTaskById(taskId);
task.status = 'DONE';
taskManager.save();
taskManager.render();
}
// Check if a "Delete" button was clicked
if (event.target.classList.contains('delete-button')) {
// Get the parent Task
const parentTask = event.target.parentElement.parentElement;
// Get the taskId of the parent Task.
const taskId = Number(parentTask.dataset.taskId);
// Delete the task
taskManager.deleteTask(taskId);
// Save the tasks to localStorage
taskManager.save();
// Render the tasks
taskManager.render();
}
});