-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
100 lines (86 loc) · 2.39 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
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
function validate(username,password,callback){
let err = false;
if( username.value == "admin" && password.value == 12345){
err = true;
}
callback(err);
}
function redirect(err){
if(err){
window.open("./main.html");
}
else{
alert("error");
}
}
function displaylist(){
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange=function(){
try{
if(httpRequest.readyState===XMLHttpRequest.DONE){
if(httpRequest.status ===200){
console.log(httpRequest.responseText);
display(httpRequest.responseText)
}
else{
alert("Error from API");
}
}
}
catch(e){
alert(e.description);
}
};
try{
httpRequest.open('GET', 'https://jsonplaceholder.typicode.com/todos',true);
httpRequest.send();
}
catch(e){
alert(e.description);
}
}
function logout(){
window.location.href="login.html";
}
function display(data){
var list = JSON.parse(data);
let table = document.getElementById("todotable");
for(var i=0;i<list.length;i++){
let rowcount = table.rows.length;
var row = table.insertRow(rowcount);
var cell1 = row.insertCell(0);
cell1.innerHTML=list[i].id;
var cell2 = row.insertCell(1);
cell2.innerHTML=list[i].title;
var cell3 = row.insertCell(2);
var element= document.createElement("input");
element.type="checkbox";
if(list[i].completed==true){
element.setAttribute("checked","true");
element.setAttribute("disabled","true");
}
element.addEventListener('change',(event)=>{
if(event.currentTarget.checked){
count++;
checkCounter();
}
else{
count--;
}
})
cell3.appendChild(element);
}
}
var count = 0;
function checkCounter(){
let promise = new Promise(function(resolve,reject){
if(count==5){
resolve("Congrats. 5 Tasks have been Successfully Completed");
}
})
promise.then(function(msg){
alert(msg);
})
}