-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecklist_script.js
94 lines (86 loc) · 2.89 KB
/
checklist_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
function fn1(cid){
//window.alert("fn");
document.getElementById("myInput").focus();
// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) {
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}
// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
for (i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.display = "none";
delitem(div.id, cid);
}
}
// Add a "checked" symbol when clicking on a list item
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if (ev.target.tagName === 'LI') {
ev.target.classList.toggle('checked');
//window.alert(ev.target.id + cid + ev.target.classList.contains("checked"));
var xhhtp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
this.responseText;
}
}
//window.alert(ev.target.id + cid + ev.target.classList.contains("checked"));
if(ev.target.classList.contains("checked")){
//window.alert("hide")
xhttp.open("GET", "HideChecklistItem?cid="+cid+"&cno="+ev.target.id+"&hide="+1, true);
}
else{
xhttp.open("GET", "HideChecklistItem?cid="+cid+"&cno="+ev.target.id+"&hide="+0, true);
}
xhttp.send();
}
}, false);
}
function delitem(cno, cid){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//window.alert(this.responseText);
//window.alert("del");
this.responseText;
get_contents(paramValue, cid);
}
}
xhttp.open("GET", "DelChecklistItem?cid="+cid+"&cno="+cno, true);
xhttp.send();
}
// Create a new list item when clicking on the "Add" button
function newElement(cid) {
var inputValue = document.getElementById("myInput").value;
if (inputValue === '') {
alert("You must write something!");
}
else{
document.getElementById("myInput").value = "";
var cno = document.getElementsByTagName("li").length;
//window.alert(" 1:"+cid +" 2:"+cno + " 3:"+inputValue);
additem(cid, (cno+1), inputValue);
}
}
function additem(cid, cno, inputValue){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
//window.alert(xhttp.readyState+ xhttp.status);
if (this.readyState == 4 && this.status == 200) {
//window.alert("additem");
this.responseText;
get_contents(paramValue, cid);
}
}
xhttp.open("GET", "AddItem?cid="+cid+"&cno="+cno+"&name="+inputValue, true);
xhttp.send();
}