Skip to content

Commit 0a27663

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

File tree

9 files changed

+81
-7
lines changed

9 files changed

+81
-7
lines changed

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import { Component, useState } from "@odoo/owl";
44

55
export class Counter extends Component {
66
static template = "awesome_owl.counter";
7+
static props = {
8+
onChange: { type: Function, optional: true }
9+
};
710

811
setup() {
912
this.state = useState({ value: 0 });
1013
}
1114

1215
increment() {
1316
this.state.value++;
17+
this.props.onChange();
1418
}
1519
}

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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
/** @odoo-module **/
22

3-
import { Component, markup } from "@odoo/owl";
3+
import { Component, useState, markup } from "@odoo/owl";
44
import { Counter } from "./counter";
55
import { Card } from "./card";
6+
import { TodoList } from "./todolist";
67

78
export class Playground extends Component {
89
static template = "awesome_owl.playground";
9-
static components = { Counter, Card };
10+
static components = { Counter, Card, TodoList };
11+
12+
setup() {
13+
this.state = useState({ sum: 0 });
14+
}
1015

1116
card1Content = markup("<div>Some Text in div Tag</div>");
1217
card2Content = "<div>Some Text in div Tag</div>";
18+
19+
incrementSum() {
20+
this.state.sum++;
21+
}
1322
}

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

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
import { TodoItem } from "./todoitem";
5+
6+
export class TodoList extends Component {
7+
static template = "awesome_owl.todolist";
8+
static components = { TodoItem };
9+
}

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)