forked from jchadwick/EssentialTypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TodoListComponent.ts
53 lines (44 loc) · 1.81 KB
/
TodoListComponent.ts
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
import { Todo, TodoState } from './Model';
import '//code.jquery.com/jquery-1.12.1.min.js';
export default class TodoListComponent {
private $el: JQuery;
constructor(el: HTMLElement) {
this.$el = $(el);
}
render(todos) {
this.$el.html('');
if (!todos.length) {
this.$el.html(
"<div class='list-group-item text-center text-giant'>" +
" <strong>You've completed everything you needed to do!</strong>" +
"</div>"
);
return;
}
for(var index in todos) {
var todo = todos[index];
this.renderTodo(todo).appendTo(this.$el);
}
}
private renderTodo(todo) {
return $(
"<div class='todo-item list-group-item "+ (todo.state == 2 ? 'completed' : '') +"'>" +
" <div class='row'>" +
" <div class='col-md-2 text-center'>" +
" <i class='incomplete glyphicon glyphicon-unchecked text-muted text-giant'></i>" +
" <i class='completed-indicator completed glyphicon glyphicon-ok text-giant'></i>" +
" </div>" +
" <div class='col-md-10'>" +
" <span class='incomplete text-giant'>" + todo.name + "</span>" +
" <span class='completed text-strikethrough text-muted text-giant'>" + todo.name + "</span>" +
" </div>" +
" </div>" +
" <div class='clearfix'></div>" +
"</div>"
).on('click', function() {
var event = document.createEvent('CustomEvent');
event.initCustomEvent('todo-toggle', true, true, { todoId: todo.id });
this.dispatchEvent(event);
});
}
}