-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
72 lines (56 loc) · 2.16 KB
/
Copy pathcontroller.js
File metadata and controls
72 lines (56 loc) · 2.16 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
class Controller{
constructor(model, view) {
this.model = model;
this.view = view;
this.init();
}
init() {
this.applyListenersForInput();
this.applyListenersForTaskBlock();
}
applyListenersForInput() {
const input = this.view.elements.inputTodo;
const handlerForInput = (e) => {
if(e.keyCode == 13) {
const valueLenght = input.value.length;
const VALUE = input.value;
if(valueLenght < 3) {
alert('So short task name, please text real task');
return;
}
input.value = '';
this.model.setTask(VALUE);
this.view.render();
}
}
input.addEventListener('keydown', handlerForInput);
}
applyListenersForTaskBlock() {
const tasksBlock = this.view.elements.tasksBlock;
const handlerForTasksBlock = (e) => {
if(e.target.classList.contains('mark-done')) {
const value = e.target.nextElementSibling.textContent;
const span = e.target.nextElementSibling;
e.target.checked === true
? span.outerHTML = /*html*/`<strike class="task-name">${value}</strike>`
: span.outerHTML = /*html*/`<span class="task-name">${value}</span>`
}
if(e.target.classList.contains('fa-edit')) {
const ID = e.target.parentElement.parentElement.id;
const NEW_VALUE = prompt('New task name', '');
if(NEW_VALUE.length < 3) {
alert('So short task name, please text real task');
return;
}
this.model.editTask(ID, NEW_VALUE);
this.view.render();
}
if(e.target.classList.contains('fa-times')) {
const ID = e.target.parentElement.parentElement.id;
this.model.removeTask(ID);
this.view.render();
}
}
tasksBlock.addEventListener('click', handlerForTasksBlock);
}
}