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
25 changes: 25 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component, useState } from "@odoo/owl";

export class Card extends Component {
static props = {
label: {type: String},
slots: {
type: Object,
shape: {
default: Object,
},
optional: true,
},
};
static template = "awesome_owl.card";

setup() {
this.state = useState({
showContent: true,
})
}

toggleShowContent() {
this.state.showContent = !this.state.showContent;
}
}
16 changes: 16 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.card">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-header">
<h5 class="card-title"><t t-esc="props.label"/> <button t-on-click="toggleShowContent">Toggle</button></h5>

</div>
<div t-if="state.showContent" class="card-body">
<p class="card-text">
<t t-slot="default"/>
</p>
</div>
</div>
</t>
</templates>
19 changes: 19 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static props = {
onChange: {optional: true}
};
static template = "awesome_owl.counter";

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

increment() {
this.state.counter++;
if (this.props.onChange) {
this.props.onChange();
}
}
}
8 changes: 8 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.counter">
<button class="btn btn-primary" t-on-click="increment">&lt; <t t-esc="state.counter"/> &gt;</button>
</t>

</templates>
25 changes: 24 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
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/todo_list";

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

content1 = markup("<b>This is the content for card 1</b>");

setup() {
super.setup();
this.state = useState({
total: 0,
});
}

onCounterIncremeneted = () => {
console.log(this.state)
this.state.total ++;
}
}
11 changes: 8 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
</div>
<Card label="'Counter 1'">
<Counter onChange="onCounterIncremeneted"/>
</Card> VS
<Card label="'Counter 2'">
<Counter onChange="onCounterIncremeneted"/>
</Card>
<div><Card label="'Total Count'"><p>Bienvenue</p></Card></div>
<div><TodoList/></div>
</t>

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

export class TodoItem extends Component {
static props = {
todo: {
type: Object,
shape: {
id: {type: Number},
description: {type: String},
isCompleted: {type: Boolean},
}
},
toggleState: {type: Function},
handleDeleteTodo: {type: Function},
};

static components = {
Card,
};

static template = "awesome_owl.todo_item";

onToggleChange = () => {
this.props.toggleState(this.props.todo.id);
}

onDelete = () => {
this.props.handleDeleteTodo(this.props.todo.id);
}
}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/todo/todo_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todo_item">
<div t-att-class="{
'text-muted text-decoration-line-through': props.todo.isCompleted
}">
<input type="checkbox" t-on-click="onToggleChange" />
<t t-esc="props.todo.id"/>. <t t-esc="props.todo.description"/>
<span class="fa fa-remove" t-on-click="onDelete"/>
</div>
</t>

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

export class TodoList extends Component {
static components = {
TodoItem,
};

static template = "awesome_owl.todo_list";

setup() {
this.todos = useState([]);
useAutofocus('todo_input');
this.nextId = 0;
}

createTodo = (ev) => {
if (ev.keyCode != 13)
return;

const text = ev.target.value.trim();

if (!text)
return;

this.todos.push({
id: ++this.nextId,
description: text,
isCompleted: false,
});

ev.target.value = "";
}

handleTodoStateChanged = (todoId) => {
const toChange = this.todos.find(t => t.id == todoId);
toChange.isCompleted = !toChange.isCompleted;
}

handleDeleteTodo = (todoId) => {
const index = this.todos.findIndex(t => t.id === todoId);
if (index !== -1) {
this.todos.splice(index, 1);
}
}
}
20 changes: 20 additions & 0 deletions awesome_owl/static/src/todo/todo_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todo_list">
<input type="text"
id="todo_input"
t-ref="todo_input"
placeholder="Add a todo"
t-on-keyup="createTodo"
/>
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem
todo="todo"
toggleState="handleTodoStateChanged"
handleDeleteTodo="handleDeleteTodo"
/>
</t>
</t>

</templates>
10 changes: 10 additions & 0 deletions awesome_owl/static/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useRef, onMounted } from "@odoo/owl"

export function useAutofocus(refName) {
const ref = useRef(refName);

onMounted(() => {
if (ref.el)
ref.el.focus();
})
}