-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
123 lines (104 loc) · 3.94 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const modal = document.querySelector('.modal');
const openModal = document.querySelector('.add-task-btn')
const closeModal = document.querySelector('.close');
const addTaskForm = document.querySelector('#add-task-form');
const myBtn = document.querySelector('#add-task-btn');
populateTask() ;
openModal.addEventListener('click', ()=>{
modal.style.display = 'block';
});
closeModal.addEventListener('click', ()=>{
modal.style.display = 'none';
})
//Populate task(after reload)
function populateTask(){
let task = JSON.parse(localStorage.getItem('task'));
if(task != null){
task.forEach((item)=>{
if(item.status === 'not-started'){
var list = document.getElementById('not-started');
list.innerHTML += `
<li>
<p>${item.taskname}</p>
<p>${item.priority}</p>
<p>${item.Date}</p>
<p>${item.status}</p>
</li>`
}
if(item.status === 'in-progress'){
var list = document.getElementById('in-progress');
list.innerHTML += `
<li>
<p>${item.taskname}</p>
<p>${item.priority}</p>
<p>${item.Date}</p>
<p>${item.status}</p>
</li>
<button id="done">Mark Done </button>
`;
}
if(item.status === 'completed'){
var list = document.getElementById('completed');
list.innerHTML += `
<li>
<p>${item.taskname}</p>
<p>${item.priority}</p>
<p>${item.Date}</p>
<p>${item.status}</p>
</li>
`;
}
});
}
}
//Add task on board
myBtn.addEventListener('click',(event)=>{
event.preventDefault();
let taskName = document.getElementById('task-name').value;
let priority = document.getElementById('priority').value;
let dueDate = document.getElementById('due-date').value;
let status = document.getElementById('status').value;
addTask(taskName, priority, dueDate, status);
taskName = '';
priority = '';
dueDate = ''
status = ''
modal.style.display = 'none';
});
let task =[];
function addTask(taskName, priority, dueDate, status){
if( JSON.parse(localStorage.getItem('task')) != null){
task = JSON.parse(localStorage.getItem('task'))
}
if(status === 'not-started'){
var list = document.getElementById('not-started');
setTask(taskName, priority, dueDate, status,list)
}
if(status === 'in-progress'){
var list = document.getElementById('in-progress');
setTask(taskName, priority, dueDate, status,list)
}
if(status === 'completed'){
var list = document.getElementById('completed');
setTask(taskName, priority, dueDate, status,list)
}
}
//Add individual task
function setTask(taskName, priority, dueDate, status,list){
list.innerHTML += `
<li>
<p>${taskName}</p>
<p>${priority}</p>
<p>${dueDate}</p>
<p>${status}</p>
</li>
`;
const taskDetails = {
taskname: taskName,
priority: priority,
Date: dueDate,
status: status
};
task.push(taskDetails)
localStorage.setItem('task', JSON.stringify(task));
}