-
Notifications
You must be signed in to change notification settings - Fork 26
/
item.js
84 lines (63 loc) · 2.16 KB
/
item.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
//convert task item from model to dom element
//need myList for registering checkbox callback
function todoDomItem(item) {
var domItem = document.createElement('li');
domItem.className = 'list-item';
item.setDomNode(domItem);
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.addEventListener('click', getCheckboxListener(item));
var text = document.createElement('span');
text.innerHTML = item.content;
domItem.appendChild(checkbox);
domItem.appendChild(text);
var timeStamp = document.createElement('span');
timeStamp.className = 'time-stamp';
timeStamp.innerHTML = "Created at " + item.birth;
domItem.appendChild(timeStamp);
var delButton = document.createElement('button');
delButton.type = "button";
delButton.className = 'btn-del';
delButton.innerHTML = "X";
delButton.addEventListener('click', getDeleteBtnListner(item));
domItem.appendChild(delButton);
return domItem;
}
function finishedDomItem(item) {
var domItem = document.createElement('li');
domItem.className = 'list-item';
item.setDomNode(domItem);
var text = document.createElement('span');
text.innerHTML = item.content;
domItem.appendChild(text);
var timeStamp = document.createElement('span');
timeStamp.className='time-stamp';
timeStamp.innerHTML = "Created at " + item.birth;
domItem.appendChild(timeStamp);
var delButton = document.createElement('button');
delButton.type = "button";
delButton.className = 'btn-del';
delButton.innerHTML = "X";
delButton.addEventListener('click', getDeleteBtnListner(item));
domItem.appendChild(delButton);
return domItem;
}
function getCheckboxListener(item) {
return function(){
setTimeout(function(){
item.finish();
//remove from todo list in dom
item.domNode.parentNode.removeChild(item.domNode);
//add to finished list in dom
var domItem = finishedDomItem(item);
document.getElementById("finished-list-content").appendChild(domItem);
}, 500);
}
}
function getDeleteBtnListner(item) {
return function(){
item.remove();
//remove from finished list
item.domNode.parentNode.removeChild(item.domNode);
}
}