This repository has been archived by the owner on Oct 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.js
110 lines (95 loc) · 3.18 KB
/
tasks.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
101
102
103
104
105
106
107
108
109
110
/**
* Author : Thophile
* Project : Deskapp
*/
/** Tasks **/
function loadTasks() {
if (details !== undefined) {
var tbody = document.getElementById('tasks')
tbody.innerHTML = ''
for (let index = 0; index < details.tasks.length; index++) {
var tr = document.createElement('tr')
var td = document.createElement('td')
td.className = 'truncate w-100 align-middle'
td.innerHTML = details.tasks[index].name
tr.appendChild(td)
var td = document.createElement('td')
td.className = 'btn-group'
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.innerHTML = '<i class="far fa-sticky-note"></i>'
button.addEventListener('click', () => {
addNote(index)
})
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.innerHTML = '<i class="fas fa-edit"></i>'
button.addEventListener('click', () => {
editTask(index)
})
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.innerHTML = '<i class="fas fa-sort-up"></i>'
button.addEventListener('click', () => {
sortUp(index)
})
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.innerHTML = '<i class="fas fa-sort-down"></i>'
button.addEventListener('click', () => {
sortDown(index)
})
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.innerHTML = '<i class="fas fa-check-square"></i>'
button.addEventListener('click', () => {
removeTask(index)
})
td.appendChild(button)
tr.appendChild(td)
tbody.appendChild(tr)
}
}
saveData()
}
function addTask() {
var task = {
name: document.getElementById('_name').value
}
details.tasks.splice(0, 0, task)
loadTasks()
$('#form_row').load('./tasks_form.html')
log("New task added")
}
function removeTask(index) {
details.tasks.splice(index, 1)
loadTasks()
}
function editTask(index) {
$('#form_row').load('./tasks_form.html', () => {
var task = details.tasks[index]
document.getElementById('_name').setAttribute('value', task.name)
removeTask(index)
log("Editing \"" + task.name + "\"")
})
}
function sortUp(index) {
if (index > 0) {
var task = details.tasks[index]
removeTask(index)
details.tasks.splice(index - 1, 0, task)
loadTasks()
}
}
function sortDown(index) {
if (index < details.tasks.length) {
var task = details.tasks[index]
removeTask(index)
details.tasks.splice(index + 1, 0, task)
loadTasks()
}
}