Skip to content

Commit b287a27

Browse files
committed
[IMP] awesome_owl: add sections 10-11
1 parent 09bfd27 commit b287a27

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

awesome_owl/static/src/todo_list/todo_item.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import { Component, useState } from "@odoo/owl";
22

33
export class TodoItem extends Component {
44
static template = "awesome_owl.todo_item"
5-
static props = { todo: {type: {id: Number, description: String, isCompleted: Boolean}} }
5+
static props = {
6+
id: String,
7+
todo: {type: {description: String, isCompleted: Boolean}},
8+
toggleState: Function
9+
}
610

711
setup() {
12+
this.id = this.props.id
813
this.todo = useState(this.props.todo)
14+
this.toggleState = this.props.toggleState
915
}
1016
}

awesome_owl/static/src/todo_list/todo_item.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<t t-name="awesome_owl.todo_item">
55
<div class="todo_item-body" t-att-class="{'text-muted text-decoration-line-through': this.todo.isCompleted}">
66
<p class="todo_item-text">
7-
<t t-esc="this.todo.id"/>. <t t-out="this.todo.description"/>
7+
<input type="checkbox" t-att-checked="this.todo.isCompleted" t-on-change="this.toggleState"/>
8+
<t t-esc="this.id"/>. <t t-out="this.todo.description"/>
89
</p>
910
</div>
1011
</t>

awesome_owl/static/src/todo_list/todo_list.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ export class TodoList extends Component {
88

99
setup() {
1010
useAutoFocus("todo-input")
11-
this.state = useState({todos: [
12-
{ id: 2, description: "penser à acheter du lait", isCompleted: false },
13-
{ id: 3, description: "penser à acheter des tomates cerises", isCompleted: true }
14-
],
11+
this.state = useState({todos: {
12+
2: { description: "penser à acheter du lait", isCompleted: false },
13+
3: { description: "penser à acheter des tomates cerises", isCompleted: true }
14+
},
1515
lastId: 3
1616
});
1717
}
1818

19+
toggleState(id) {
20+
this.state.todos[id].isCompleted = !this.state.todos[id].isCompleted
21+
}
22+
1923
addTodo(ev) {
2024
if (ev.keyCode === 13 && ev.target.value != "") {
21-
this.state.todos.push({id: ++this.state.lastId, description: ev.target.value, isCompleted: false});
25+
this.state.todos[++this.state.lastId] = {description: ev.target.value, isCompleted: false};
2226
ev.target.value = ""
2327
}
2428
}

awesome_owl/static/src/todo_list/todo_list.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
placeholder="Enter something to do..."
1111
t-ref="todo-input"
1212
/>
13-
<t t-foreach="this.state.todos" t-as="i" t-key="i.id">
14-
<TodoItem todo="i"/>
13+
<t t-foreach="Object.keys(this.state.todos)" t-as="id" t-key="id">
14+
<TodoItem id="id" todo="this.state.todos[id]" toggleState.bind="() => this.toggleState(id)"/>
1515
</t>
1616
</div>
1717
</div>

0 commit comments

Comments
 (0)