-
Notifications
You must be signed in to change notification settings - Fork 0
/
DartTODO.dart
60 lines (49 loc) · 1.58 KB
/
DartTODO.dart
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
#import('dart:html');
#import('Cookies.dart');
class DartTODO {
var count = 0;
DartTODO() {
}
void run() {
document.query('#addNewTask').on.click.add((e) => addTask());
for (var i = 0; i < 30; i++) {
var taksList = new Cookies().readCookie('task'+i);
if (taksList != null) {
var element = new Element.html('<div>' + taksList + ' </div>');
var span = new Element.html('<span class="delete-task">X</span>');
span.on.click.add((e) => deleteTask(element));
element.nodes.add(span);
document.query('#tasks').nodes.add(element);
}
}
var tmpCount = new Cookies().readCookie('count');
if (tmpCount != null) {
count = Math.parseInt(tmpCount);
}
}
void addTask() {
document.query('#messages').nodes.clear();
InputElement input = document.query('#newTask');
String task = input.value;
if (task == "") {
var message = new Element.html('<div>Task cannot be empty.</div>');
document.query('#messages').nodes.add(message);
} else {
var element = new Element.html('<div>' + task + ' </div>');
var span = new Element.html('<span class="delete-task">X</span>');
span.on.click.add((e) => deleteTask(element));
element.nodes.add(span);
document.query('#tasks').nodes.add(element);
input.value = '';
new Cookies().createCookie('task'+count,task,360);
count += 1;
new Cookies().createCookie('count', count ,360);
}
}
void deleteTask(Element element) {
element.remove();
}
}
void main() {
new DartTODO().run();
}