-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathTODO List
203 lines (188 loc) · 8.42 KB
/
TODO List
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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>TODO List</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">TODOs List</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Items
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Contact</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<div class="container my-4">
<h2 class="text-center">
TODO List
</h2>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" aria-describedby="emailHelp" >
<small id="emailHelp" class="form-text text-muted">Add an item to the list</small>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" rows="3"></textarea>
</div>
<button type="submit" id="add" class="btn btn-primary">Add to list</button>
<button type="submit" id="clear" class="btn btn-primary" onclick="clearStorage()">Clear list</button>
<div id="items" class="my-4">
<h2>Your Items</h2>
<table class="table">
<thead>
<tr>
<th scope="col">SNo</th>
<th scope="col">Item Title</th>
<th scope="col">Item Description</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody id="tablebody">
<tr>
<th scope="row">1</th>
<td>Coffee</td>
<td>You need coffee as you are a coder</td>
<td><button class="btn btn-sm btn-primary">Delete</button></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script>
function getandupdate(){
console.log('Updating List') ;
tit= document.getElementById('title').value;
desc= document.getElementById('description').value ;
if(localStorage.getItem('itemsJson')==null){
newitemarray=[] ;
newitemarray.push([tit,desc]) ;
localStorage.setItem('itemsJson', JSON.stringify(newitemarray)) ;
}
else{
newitemarraystr = localStorage.getItem('itemsJson') ;
newitemarray= JSON.parse(newitemarraystr) ;
newitemarray.push([tit,desc]) ;
localStorage.setItem('itemsJson', JSON.stringify(newitemarray)) ;
}
update() ;
}
function update(){
if(localStorage.getItem('itemsJson')==null){
newitemarray=[] ;
localStorage.setItem('itemsJson', JSON.stringify(newitemarray)) ;
}
else{
newitemarraystr = localStorage.getItem('itemsJson') ;
newitemarray= JSON.parse(newitemarraystr) ;
}
let tablebody = document.getElementById('tablebody') ;
let str="" ;
newitemarray.forEach((element,index) => {
str+=`
<tr>
<th scope="row">${index+1}</th>
<td>${element[0]}</td>
<td>${element[1]}</td>
<td><button class="btn btn-sm btn-primary" onclick=deleted('${index}')>Delete</button></td>
</tr>`
});
tablebody.innerHTML=str ;
}
add= document.getElementById("add") ;
add.addEventListener('click',getandupdate) ;
update();
function deleted(itemind){
console.log("Delete",itemind) ;
newitemarraystr = localStorage.getItem('itemsJson') ;
newitemarray= JSON.parse(newitemarraystr) ;
newitemarray.splice(itemind,1) ;
localStorage.setItem('itemsJson', JSON.stringify(newitemarray)) ;
update() ;
}
function clearStorage(){
if(confirm("Do you want to clear it all?")){
console.log("it is cleared") ;
localStorage.clear() ;
update() ;
}
}
</script>
<!-- Code injected by live-server -->
<script>
// <![CDATA[ <-- For SVG support
if ('WebSocket' in window) {
(function () {
function refreshCSS() {
var sheets = [].slice.call(document.getElementsByTagName("link"));
var head = document.getElementsByTagName("head")[0];
for (var i = 0; i < sheets.length; ++i) {
var elem = sheets[i];
var parent = elem.parentElement || head;
parent.removeChild(elem);
var rel = elem.rel;
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
}
parent.appendChild(elem);
}
}
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
var address = protocol + window.location.host + window.location.pathname + '/ws';
var socket = new WebSocket(address);
socket.onmessage = function (msg) {
if (msg.data == 'reload') window.location.reload();
else if (msg.data == 'refreshcss') refreshCSS();
};
if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) {
console.log('Live reload enabled.');
sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true);
}
})();
}
else {
console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.');
}
// ]]>
</script>
</body>
</html>