Skip to content

Commit c1b4817

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

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<t t-name="awesome_owl.todoitem">
55
<input type="checkbox" t-on-change="()=> props.onToggleState(props.todo.id)"/>
66
<t t-out="props.todo.id+'. '+props.todo.description"/>
7+
<span t-on-click="()=> props.onRemoveTodo(props.todo.id)" class="fa fa-remove"></span>
78
</t>
89

910
</templates>

awesome_owl/static/src/todolist.js

+7
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ export class TodoList extends Component {
2828
let todo = this.state.todos.find(todo => todo.id === todoId);
2929
todo.isCompleted = !todo.isCompleted;
3030
}
31+
32+
removeTodo(todoId) {
33+
let 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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<t t-foreach="state.todos" t-as="i" t-key="i.id">
88
<div style="border: 1px solid black">
99
<div t-att-class="{'text-muted': i.isCompleted, 'text-decoration-line-through': i.isCompleted}">
10-
<TodoItem todo= "i" onToggleState.bind="toggleState"/>
10+
<TodoItem todo= "i" onToggleState.bind="toggleState" onRemoveTodo.bind="removeTodo"/>
1111
</div>
1212
</div>
1313
</t>

0 commit comments

Comments
 (0)