Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component, xml, useState } from "@odoo/owl";

export class Card extends Component {
static template = xml`
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">

<div class="d-flex justify-content-between align-items-center mb-3">
<h5 class="card-title mb-0"><t t-esc="props.title"/></h5>
<button class="btn btn-sm btn-outline-primary" t-on-click="toggle">
<t t-if="state.isOpen">Hide</t>
<t t-else="">Show</t>
</button>
</div>

<div t-if="state.isOpen">
<t t-slot="default"/>
</div>

</div>
</div>
`;

static props = {
title: { type: String },
slots: { type: Object, optional: true }
};

setup() {
this.state = useState({
isOpen: true
});
}

toggle() {
this.state.isOpen = !this.state.isOpen;
}
}
21 changes: 21 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = "awesome_owl.counter";

setup() {
this.state = useState({ value: 0 });
}

increment() {
this.state.value++

if (this.props.onChange) {
this.props.onChange();
}
}

static props = {
onChange: { type: Function, optional: true }
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.counter">
<div class="p-3">
<p>Counter: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>

</templates>
20 changes: 19 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { Component } from "@odoo/owl";
import { Component, markup, useState } from "@odoo/owl";
import { Counter } from "./counter/counter";
import { Card } from "./card/card";
import { TodoList } from "./todo_list/todo_list";

export class Playground extends Component {
static template = "awesome_owl.playground";
static components = { Counter, Card, TodoList };

setup() {
const productDescriptionFromDB = "<p>This is a <strong>great</strong> product!</p>";
this.description = markup(productDescriptionFromDB);
this.sum = useState({ value: 0 });

this.someExpression = () => {
return true;
}
}

incrementSum() {
this.sum.value++;
}
}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
<div class="p-3">
hello world
</div>
<Counter onChange.bind="incrementSum"/>
<Counter onChange.bind="incrementSum"/>
<div class="mt-3 font-weight-bold">
Total Sum: <t t-esc="sum.value"/>
</div>
<Card title="'test'">
<p class="card-text">test</p>
<div>description</div>
</Card>
<Card title="'Card 2'">
<p>Content of card 2</p>
<Counter onChange.bind="incrementSum"/>
</Card>
<TodoList/>
</t>

</templates>
21 changes: 21 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, useState } from "@odoo/owl";

export class TodoItem extends Component {
static template = "awesome_owl.todo_item";
static props = {
id: { type: Number },
description: { type: String },
isCompleted: { type: Boolean }
};

onChange() {
this.state.isCompleted = !this.state.isCompleted;
}

setup() {
this.state = useState({
isCompleted: this.props.isCompleted
})
}

};
13 changes: 13 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todo_item">
<div class="p-3" t-att-class="{ 'text-decoration-line-through': state.isCompleted }" >
<input class="form-check-input" type="checkbox" t-att-id="props.id" t-att-checked="state.isCompleted" t-on-change="onChange"/>
<p>ID: <t t-esc="props.id"/></p>
<p t-att-class="props.isCompleted ? 'text-decoration-line-through text-muted' : '' " >Description: <t t-esc="props.description"/></p>
<p>Completed: <t t-esc="state.isCompleted"/></p>
</div>
</t>

</templates>
38 changes: 38 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component, useState, onMounted, useRef } from "@odoo/owl";
import { TodoItem } from "./todo_item";

export class TodoList extends Component {
static template = "awesome_owl.todo_list";
static components = { TodoItem };

setup() {
this.nextId = 0;
this.todos = useState([]);

this.inputRef = useRef("input");
onMounted(() => {
this.inputRef.el.focus();
});
}

addTodo(ev) {
if (ev.keyCode === 13 && ev.target.value != "") {
this.todos.push(
{
"id": this.nextId++,
"description": ev.target.value,
"isCompleted": false
}
)
ev.target.value = "";
}
}

delete(todoId) {
const index = this.todos.findIndex((todo) => todo.id === todoId);
if (index !== -1) {
this.todos.splice(index, 1);
}
}

}
12 changes: 12 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todo_list">
<input class="form-control mb-3" type="text" placeholder="Add a todo" t-on-keyup="addTodo" t-ref="input"/>
<div t-foreach="todos" t-as="i" t-key="i.id">
<TodoItem id="i.id" description="i.description" isCompleted="i.isCompleted"/>
<span class="fa fa-remove" t-on-click="() => this.delete(i.id)" style="cursor: pointer;" />
</div>
</t>

</templates>