forked from iamvijaydev/TaskTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
115 lines (93 loc) · 2.34 KB
/
controller.js
File metadata and controls
115 lines (93 loc) · 2.34 KB
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
111
112
113
114
115
function log(m) {
console.log(m);
}
var acceptTask,
taskList,
view;
/* Returns Date.now()
* @private
* @return {Number} time in seconds
*/
var now = function() {
return Date.now();
};
var exec = function() {
acceptTask.addEventListener('keyup', function(e) {
if(e.keyCode === 13 && this.value != '') {
var tEvent = document.createEvent('Event');
tEvent.initEvent('newTask', true, true);
tEvent.data = {
'title': this.value
}
window.dispatchEvent(tEvent);
this.value = '';
log('C: user entered a new task');
} else {
return;
}
}, false);
taskList.addEventListener('click', function(e) {
var target = e.target;
var taskID = target.parentNode.parentNode.id;
switch(target.className){
case 'start':
// check if there is a current timer running
if(view.timer) {
//get the task by accessing view
var parent = view.hhmmss.parentNode;
// let model know that he needs to save the new duration
var tEvent = document.createEvent('Event');
tEvent.initEvent('updateTask', true, true);
tEvent.data = {
'id': parent.id,
'status': 'pause',
'time': now()
}
window.dispatchEvent(tEvent);
}
var tEvent = document.createEvent('Event');
tEvent.initEvent('updateTask', true, true);
tEvent.data = {
'id': taskID,
'status': 'active',
'time': now()
}
window.dispatchEvent(tEvent);
break;
case 'discard':
var tEvent = document.createEvent('Event');
tEvent.initEvent('discardTask', true, true);
tEvent.data = {
'id': taskID
}
window.dispatchEvent(tEvent);
break;
case 'complete':
var tEvent = document.createEvent('Event');
tEvent.initEvent('updateTask', true, true);
tEvent.data = {
'id': taskID,
'status': 'complete',
'time': now()
}
window.dispatchEvent(tEvent);
break;
case 'pause':
var tEvent = document.createEvent('Event');
tEvent.initEvent('updateTask', true, true);
tEvent.data = {
'id': taskID,
'status': 'pause',
'time': now()
}
window.dispatchEvent(tEvent);
break;
}
}, false);
};
document.addEventListener('DOMContentLoaded', function () {
acceptTask = document.getElementById('accept_task');
taskList = document.getElementById('task_list');
view = new View(taskList);
exec();
}, false);