Compare commits

..

10 commits

Author SHA1 Message Date
Matt Marcha 5ebc65e096
Merge pull request #7 from SARL-PACIFIC-ERP/development
Development
2024-08-21 17:18:43 -10:00
Matt Marcha 1f252ac022
Merge branch 'main' into development 2024-08-21 17:17:43 -10:00
Matt Marcha 0e73d8686d sect 14 2024-08-21 17:08:11 -10:00
Matt Marcha 9cbbc8c467 sect 13 2024-08-21 16:41:01 -10:00
Matt Marcha 6396160269 Section 12 2024-08-21 16:15:54 -10:00
Matt Marcha cae25a4fa2 stage 11 2024-08-11 17:58:02 -10:00
Matt Marcha 840fa2d704 stage 10 2024-08-11 10:41:04 -10:00
Matt Marcha 48e91eba0e section 9 2024-08-10 12:47:53 -10:00
Matt Marcha 1b73b994ab sect 8 2024-08-10 11:44:44 -10:00
Matt Marcha 1210735566 Web components ch 1 sect 1-7 2024-08-10 10:48:19 -10:00
7 changed files with 46 additions and 9 deletions

View file

@ -4,5 +4,21 @@ import { Component, useState } from "@odoo/owl";
export class Card extends Component { export class Card extends Component {
static template = "awesome_owl.card"; static template = "awesome_owl.card";
static props = ['title', 'content']; static props = {
title: String,
slots: {
type: Object,
shape: {
default: true
},
}
};
setup() {
this.toggle = useState({isOpen: true});
}
toggleContent() {
this.toggle.isOpen = !this.toggle.isOpen;
}
} }

View file

@ -5,9 +5,12 @@
<section> <section>
<div class="card d-inline-block m-2" style="width: 18rem;"> <div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body"> <div class="card-body">
<h3 class="card-title"><t t-esc="props.title"/></h3> <h3 class="card-title">
<p class="card-text"> <t t-out="props.title"/>
<t t-esc="props.content"/> <button class="btn" t-on-click="toggleContent">Toggle</button>
</h3>
<p class="card-text" t-if="toggle.isOpen">
<t t-slot="default"/>
</p> </p>
</div> </div>
</div> </div>

View file

@ -6,8 +6,12 @@
<Counter onChange.bind="incrementSum"/> <Counter onChange.bind="incrementSum"/>
<p>The sum is <t t-esc="sum.value"/></p> <p>The sum is <t t-esc="sum.value"/></p>
<hr /> <hr />
<Card title="'Card 1'" content="'This is the awesome content of the card 1'" /> <Card title="'Card 1'">
<Card title="'Card, the 2nd'" content="'Here is another card content. It is the second one.'" /> <span>Hello Owl</span>
</Card>
<Card title="'Card, the 2nd'">
<Counter />
</Card>
<hr/> <hr/>
<TodoList /> <TodoList />
</t> </t>

View file

@ -10,9 +10,14 @@ export class TodoItem extends Component {
shape: { id: Number, description: String, isCompleted: Boolean } shape: { id: Number, description: String, isCompleted: Boolean }
}, },
onToggle: Function, onToggle: Function,
removeTodo: Function,
}; };
toggle() { toggle() {
this.props.onToggle(this.props.todo.id); this.props.onToggle(this.props.todo.id);
} }
remove() {
this.props.removeTodo(this.props.todo.id);
}
} }

View file

@ -7,6 +7,7 @@
<t t-esc="props.todo.id"/>. <t t-esc="props.todo.id"/>.
<t t-esc="props.todo.description"/> <t t-esc="props.todo.description"/>
</label> </label>
<span class="fa fa-remove" t-on-click="remove"/>
</div> </div>
</t> </t>
</templates> </templates>

View file

@ -10,6 +10,7 @@ export class TodoList extends Component {
static components = { TodoItem }; static components = { TodoItem };
setup() { setup() {
this.todoCounter = 1;
this.todos = useState([]); this.todos = useState([]);
useAutofocus('todo_input'); useAutofocus('todo_input');
} }
@ -19,7 +20,7 @@ export class TodoList extends Component {
if(ev.keyCode === 13) { if(ev.keyCode === 13) {
if(ev.target.value !== '') { if(ev.target.value !== '') {
// Let's create a todo // Let's create a todo
this.todos.push({ id: this.todos.length+1, description: ev.target.value, isCompleted: false }); this.todos.push({ id: this.todoCounter++, description: ev.target.value, isCompleted: false });
ev.target.value = ''; ev.target.value = '';
} }
} }
@ -31,4 +32,11 @@ export class TodoList extends Component {
todo.isCompleted = !todo.isCompleted; todo.isCompleted = !todo.isCompleted;
} }
} }
removeItem(id) {
const todoIndex = this.todos.findIndex((obj) => obj.id === id);
if (todoIndex >= 0) {
this.todos.splice(todoIndex, 1);
}
}
} }

View file

@ -4,7 +4,7 @@
<p><input t-ref="todo_input" type="text" name="new-todo" placeholder="Add new todo" t-on-keyup="addTodo" /></p> <p><input t-ref="todo_input" type="text" name="new-todo" placeholder="Add new todo" t-on-keyup="addTodo" /></p>
<div class="d-inline-block border p-2 m-2"> <div class="d-inline-block border p-2 m-2">
<t t-foreach="todos" t-as="todo" t-key="todo.id"> <t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo" onToggle.bind="toggleState"/> <TodoItem todo="todo" onToggle.bind="toggleState" removeTodo.bind="removeItem"/>
</t> </t>
</div> </div>
</t> </t>