-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathindex.js
95 lines (73 loc) · 1.85 KB
/
index.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
let todos = [
{
id: 1,
name: "Complete The Budget App",
done: false,
deadline: new Date(2019, 11, 24)
},
{
id: 2,
name: "Fork Github Repository",
done: false,
deadline: new Date(2019, 10, 11)
},
{
id: 3,
name: "Implement Data Structures in java",
done: false,
deadline: new Date(2019, 10, 11)
}
];
function render(state) {
return state
.map(todo => {
const classString = todo.done ? `list-group-item striked` : `list-group-item`
return `<li data-todo="${todo.id}" class="draggable ${classString}" draggable="true"> ${todo.name} <span style="float: right">${todo.deadline}</span></li>`;
})
.join("");
}
function paint() {
$("ul").html(render(todos));
}
function addTodo() {
// document.getElementById('newTodo') != $('#newTodo')
const inputBox = $('#newTodo')
const deadlinedate = $('#newTododate')
todos.push({
id: todos.length + 1,
name: inputBox.val(),
done: false,
deadline: new Date(deadlinedate.val())
})
inputBox.val('')
deadlinedate.val('')
paint()
}
function removeTodos() {
todos = todos.filter(todo => !todo.done)
paint()
}
function sortTodos() {
todos.sort(function (a, b) {
return (new Date(a.deadline) - new Date(b.deadline))
});
paint()
}
$("#sortable").sortable(function(){
});
function reset() {
$("#newTodo").val('');
$("#newTododate").val('');
}
$('ul').on("click", function (e) {
const idToFind = e.target.dataset.todo
const todo = todos.find(todo => todo.id == idToFind)
todo.done = !todo.done
paint()
})
$('#newTodo, #newTododate').on("keypress", function (e) {
if (e.which == 13) {
addTodo()
}
})
paint();