Skip to content

Commit 1d61c05

Browse files
committed
[IMP] awesome_owl: add input text to add todoitems dynamically
1 parent 459b6a5 commit 1d61c05

File tree

10 files changed

+81
-15
lines changed

10 files changed

+81
-15
lines changed

awesome_owl/static/src/card.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component, useState } from "@odoo/owl"
1+
import { Component } from "@odoo/owl"
22

33
export class Card extends Component {
44
static template = "awesome_owl.card";
55
static props = {
66
title: String,
77
content: String,
88
}
9-
}
9+
}

awesome_owl/static/src/card.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.card">
5-
<div class="card d-inline-block m-2" style="width: 18rem;">
5+
<div class="card d-inline-block m-2" style="border:1px solid black; width: 18rem;">
66
<div class="card-body">
77
<h5 class="card-title">
88
<t t-esc="props.title"/>

awesome_owl/static/src/counter.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
/** @odoo-module **/
2-
31
import { Component, useState } from "@odoo/owl";
42

53
export class Counter extends Component {
64
static template = "awesome_owl.counter";
5+
static props = {
6+
onChange: { type: Function, optional: true }
7+
};
78

89
setup() {
910
this.state = useState({ value: 0 });
1011
}
1112

1213
increment() {
1314
this.state.value++;
15+
this.props.onChange();
1416
}
15-
}
17+
}

awesome_owl/static/src/counter.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.counter">
5-
<div>Hello World
5+
<div style="border:1px solid black; width: 10rem;">Hello World
66
<p>Counter: <t t-esc="state.value"/>
77
</p>
8-
<button class="btn btn-primary" t-on-click="increment">Increment</button>
8+
<button style="border:0.5px solid black;" class="btn btn-primary" t-on-click="increment">Increment</button>
99
</div>
1010
</t>
1111

awesome_owl/static/src/playground.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
/** @odoo-module **/
2-
3-
import { Component, markup } from "@odoo/owl";
1+
import { Component, useState, markup } from "@odoo/owl";
42
import { Counter } from "./counter";
53
import { Card } from "./card";
4+
import { TodoList } from "./todolist";
65

76
export class Playground extends Component {
87
static template = "awesome_owl.playground";
9-
static components = { Counter, Card };
8+
static components = { Counter, Card, TodoList };
9+
10+
setup() {
11+
this.state = useState({ sum: 0 });
12+
}
1013

1114
card1Content = markup("<div>Some Text in div Tag</div>");
1215
card2Content = "<div>Some Text in div Tag</div>";
13-
}
16+
17+
incrementSum() {
18+
this.state.sum++;
19+
}
20+
}

awesome_owl/static/src/playground.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.playground">
5-
<Counter></Counter>
6-
<Counter></Counter>
5+
<Counter onChange.bind="incrementSum"></Counter>
6+
<Counter onChange.bind="incrementSum"></Counter>
7+
<p>Counters Sum: <t t-esc="state.sum"/>
8+
</p>
79
<Card title="'my title'" content="card1Content"/>
810
<Card title="'my title'" content="card2Content"/>
11+
<TodoList/>
912
</t>
1013

1114
</templates>

awesome_owl/static/src/todoitem.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component, useState } from "@odoo/owl";
2+
3+
export class TodoItem extends Component {
4+
static template = "awesome_owl.todoitem";
5+
6+
setup() {
7+
this.state = useState({
8+
todos: [],
9+
idCounter: 0
10+
});
11+
};
12+
13+
addTodo(ev) {
14+
if (ev.keyCode === 13) {
15+
this.state.idCounter++
16+
console.log(this.state.idCounter);
17+
this.state.todos.push({
18+
'id': this.state.idCounter, 'description': ev.target.value, 'isCompleted': false
19+
});
20+
ev.target.value = "";
21+
}
22+
}
23+
}

awesome_owl/static/src/todoitem.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.todoitem">
5+
<br/>
6+
<input t-on-keyup="ev => this.addTodo(ev)" type="text" placeholder="Enter a new task"/>
7+
<t t-foreach="state.todos" t-as="i" t-key="i.id">
8+
<div style="border: 1px solid black">
9+
<div t-att-class="{'text-muted': i.isCompleted, 'text-decoration-line-through': i.isCompleted}">
10+
<t t-out="i.id+'. '+i.description"/>
11+
</div>
12+
</div>
13+
</t>
14+
</t>
15+
16+
</templates>

awesome_owl/static/src/todolist.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from "@odoo/owl";
2+
import { TodoItem } from "./todoitem";
3+
4+
export class TodoList extends Component {
5+
static template = "awesome_owl.todolist";
6+
static components = { TodoItem };
7+
}

awesome_owl/static/src/todolist.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.todolist">
5+
<TodoItem/>
6+
</t>
7+
8+
</templates>

0 commit comments

Comments
 (0)