mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add todoapp
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { TodoItem } from "./TodoItem.js";
|
||||
|
||||
const { StoreMixin, Component } = odoo.core;
|
||||
|
||||
export class TodoApp extends StoreMixin(Component) {
|
||||
template = "todoapp";
|
||||
widgets = { TodoItem };
|
||||
state = { filter: "all" };
|
||||
|
||||
get todos() {
|
||||
return this.env.store.state.todos;
|
||||
}
|
||||
|
||||
get allChecked() {
|
||||
return this.todos.every(todo => todo.done);
|
||||
}
|
||||
|
||||
get remaining() {
|
||||
return this.todos.filter(todo => !todo.done).length;
|
||||
}
|
||||
|
||||
get remainingText() {
|
||||
return (this.remaining < 2 ? "item" : "items") + " left";
|
||||
}
|
||||
|
||||
addTodo(ev) {
|
||||
if (ev.keyCode === 13) {
|
||||
const text = ev.target.value;
|
||||
if (text.trim()) {
|
||||
this.env.store.dispatch("addTodo", text);
|
||||
}
|
||||
ev.target.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
clearCompleted() {
|
||||
this.env.store.dispatch("clearCompleted");
|
||||
}
|
||||
|
||||
toggleAll() {
|
||||
this.env.store.dispatch("toggleAll", !this.allChecked);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export class TodoItem extends odoo.core.Component {
|
||||
template = "todoitem";
|
||||
|
||||
removeTodo() {
|
||||
this.env.store.dispatch("removeTodo", this.props.id);
|
||||
}
|
||||
|
||||
toggleTodo() {
|
||||
this.env.store.dispatch("toggleTodo", this.props.id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user