Skip to content

Commit 383d906

Browse files
committed
[IMP] awesome_owl: allow to delete todoitem
1 parent 00c9d0f commit 383d906

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

awesome_owl/static/src/todoitem.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export class TodoItem extends Component {
55
static props = {
66
todo: Object,
77
onToggleState: Function,
8+
onRemoveTodo: Function,
89
}
910
}

awesome_owl/static/src/todoitem.xml

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.todoitem">
5-
<input type="checkbox" t-on-change="()=> props.onToggleState(props.todo.id)"/>
6-
<t t-out="props.todo.id+'. '+props.todo.description"/>
5+
<input type="checkbox" t-on-change="() => props.onToggleState(props.todo.id)"/>
6+
<div t-att-class="{'text-muted': props.todo.isCompleted, 'text-decoration-line-through': props.todo.isCompleted}">
7+
<t t-out="props.todo.id + '. ' + props.todo.description"/>
8+
</div>
9+
<span t-on-click="() => props.onRemoveTodo(props.todo.id)" class="fa fa-remove"></span>
710
</t>
811

912
</templates>

awesome_owl/static/src/todolist.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ export class TodoList extends Component {
2525
};
2626

2727
toggleState(todoId) {
28-
let todo = this.state.todos.find(todo => todo.id === todoId);
28+
const todo = this.state.todos.find(todo => todo.id === todoId);
2929
todo.isCompleted = !todo.isCompleted;
3030
}
31+
32+
removeTodo(todoId) {
33+
const index = this.state.todos.findIndex(todo => todo.id === todoId);
34+
if (index >= 0) {
35+
this.state.todos.splice(index, 1);
36+
}
37+
}
3138
}

awesome_owl/static/src/todolist.xml

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
<t t-name="awesome_owl.todolist">
55
<br/>
66
<input t-ref="input_todo" t-on-keyup="ev => this.addTodo(ev)" type="text" placeholder="Enter a new task"/>
7-
<t t-foreach="state.todos" t-as="i" t-key="i.id">
7+
<t t-foreach="state.todos" t-as="todo" t-key="todo.id">
88
<div style="border: 1px solid black">
9-
<div t-att-class="{'text-muted': i.isCompleted, 'text-decoration-line-through': i.isCompleted}">
10-
<TodoItem todo= "i" onToggleState.bind="toggleState"/>
11-
</div>
9+
<TodoItem todo="todo" onToggleState.bind="toggleState" onRemoveTodo.bind="removeTodo"/>
1210
</div>
1311
</t>
1412
</t>

0 commit comments

Comments
 (0)