-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
99 lines (75 loc) · 3.08 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
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
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('input[name="category"]').forEach(checkbox => {
checkbox.addEventListener('change', function() {
const taskColumn = document.getElementById(`${checkbox.value}-tasks`);
if (checkbox.checked) {
taskColumn.style.display = 'block';
} else {
taskColumn.style.display = 'none';
}
});
});
document.querySelectorAll('.tasks-column').forEach(column => {
column.style.display = 'none';
});
document.querySelectorAll('input[name="category"]:checked').forEach(checkbox => {
checkbox.dispatchEvent(new Event('change'));
});
});
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
const taskType = document.getElementById('task-type').value;
const taskDesc = document.getElementById('task').value;
if (taskDesc.trim() === '') {
alert('Please enter a task description.');
return;
}
const taskItem = document.createElement('li');
taskItem.textContent = taskDesc;
const taskList = document.getElementById(`${taskType}-tasks`).querySelector('ul');
taskList.appendChild(taskItem);
updateDeleteSelect();
document.getElementById('task').value = '';
});
});
//Update the select element when you change Task Type in the delete section
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelector('select#task-type-del').addEventListener('change', function(e) {
updateDeleteSelect();
})
});
//Delete selected task
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelector('form#delete').addEventListener('submit', function(e) {
e.preventDefault();
const taskType = document.getElementById('task-type-del').value;
const tasks = document.getElementById(`${taskType}-tasks`).querySelector('ul').querySelectorAll('li');
const taskToDelete = document.getElementById('task-del').value;
tasks.forEach(li => {
if (li.textContent === taskToDelete) {
li.remove();
}
});
updateDeleteSelect();
})
});
function updateDeleteSelect(){
const taskType = document.getElementById('task-type-del').value;
const taskDesc = document.getElementById('task-del');
const taskList = document.getElementById(`${taskType}-tasks`).querySelector('ul');
taskDesc.innerHTML = '';
taskList.querySelectorAll('li').forEach(task => {
const option = document.createElement('option');
option.value = task.textContent;
option.textContent = task.textContent;
taskDesc.appendChild(option);
})
}
function resetTaskList(){
const tasksContainer = document.querySelectorAll('.task-list ul');
tasksContainer.forEach(ul => {
ul.innerHTML = '';
})
console.log("Task list has been reset.");
}