-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
240 lines (189 loc) · 6.57 KB
/
index.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>TODO APP</title>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">TODO APP</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Dropdown</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
<li><a class="dropdown-item" href="#">A third link</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-3">
<h1 class="text-center">TODO APP</h1>
<form>
<div class="mb-3 mt-3">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" placeholder="" name="title" required>
<div id="" class="form-text">Add an item to the list</div>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" rows="3" required></textarea>
</div>
<button class="btn btn-primary" id="add">Add to list</button>
<a class="btn btn-primary" id="" onclick="clearAll()">Clear All</a>
</form>
<div class="mt-4">
<h2 class="mb-2">Incomplete Tasks</h2>
<table class="table">
<thead>
<tr>
<th scope="col">SNO</th>
<th scope="col">Title</th>
<th scope="col">Description</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody id="tablebody">
<!--table data came here from local storage-->
</tbody>
</table>
</div><!--ends items-->
<div class="mt-4">
<h2 class="mb-2">Completed Tasks</h2>
<table class="table">
<thead>
<tr>
<th scope="col">SNO</th>
<th scope="col">Title</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody id="tablebody2">
<!--table data came here from local storage-->
</tbody>
</table>
</div><!--ends items-->
</div>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script>
function update(){
var tit=document.getElementById("title").value;
var desc=document.getElementById("description").value;
if(localStorage.getItem("itemsJson")==null){
itemJsonArr=[];
if(tit!="" && desc!=""){
itemJsonArr.push([tit,desc]);
localStorage.setItem('itemsJson',JSON.stringify(itemJsonArr));
}
}
else{
itemJsonArrStr=localStorage.getItem("itemsJson");
itemJsonArr = JSON.parse(itemJsonArrStr);
if(tit!="" && desc!=""){
itemJsonArr.push([tit,desc]);
localStorage.setItem('itemsJson',JSON.stringify(itemJsonArr));
}
}
/*display incomplete task*/
var tablebody = document.getElementById("tablebody");
str= " ";
itemJsonArr.forEach((value,index)=>{
str+=`
<tr>
<th scope="row">${index+1}</th>
<td>${value[0]}</td>
<td>${value[1]}</td>
<td>
<button class="btn btn-danger btn-sm" onclick="remove(${index})">Delete</button>
<button class="btn btn-success btn-sm" onclick="complete(${index})">Complete</button>
</td>
</tr>
`;
});
tablebody.innerHTML=str;
};
var add = document.getElementById("add");
add.addEventListener("click",update);
update();
function clearAll(){
if(confirm("Are you sure ?")){
localStorage.clear();
update();
update2();
}
}
function remove(index){
if(confirm("Are you sure ?")){
itemJsonArrStr=localStorage.getItem("itemsJson");
itemJsonArr = JSON.parse(itemJsonArrStr);
itemJsonArr.splice(index,1);
localStorage.setItem('itemsJson',JSON.stringify(itemJsonArr));
update();
}
}
function complete(index){
<!--adding task into complete list-->
if(localStorage.getItem("itemsJson2")==null){
itemJsonArr2=[];
itemJsonArr2.push(itemJsonArr[index]);
localStorage.setItem('itemsJson2',JSON.stringify(itemJsonArr2));
}
else{
if(itemJsonArr2!=""){
itemJsonArrStr2=localStorage.getItem("itemsJson2");
itemJsonArr2 = JSON.parse(itemJsonArrStr2);
itemJsonArr2.push(itemJsonArr[index]);
localStorage.setItem('itemsJson2',JSON.stringify(itemJsonArr2));
}
}
update2();
<!--removing task from incomplete list-->
itemJsonArr.splice(index,1);
localStorage.setItem('itemsJson',JSON.stringify(itemJsonArr));
update();
}
function update2(){
if(localStorage.getItem("itemsJson2")!=null){
itemJsonArrStr2=localStorage.getItem("itemsJson2");
itemJsonArr2 = JSON.parse(itemJsonArrStr2);
<!--display complete task-->
let tablebody2 = document.getElementById("tablebody2");
str2= " ";
itemJsonArr2.forEach((value,index)=>{
str2+=`
<tr class="text-muted">
<th scope="row">${index+1}</th>
<td>${value[0]}</td>
<td>${value[1]}</td>
</tr>
`;
});
tablebody2.innerHTML=str2;
}
}
update2();
</script>
</body>
</html>