File tree Expand file tree Collapse file tree 10 files changed +81
-15
lines changed Expand file tree Collapse file tree 10 files changed +81
-15
lines changed Original file line number Diff line number Diff line change 1
- import { Component , useState } from "@odoo/owl"
1
+ import { Component } from "@odoo/owl"
2
2
3
3
export class Card extends Component {
4
4
static template = "awesome_owl.card" ;
5
5
static props = {
6
6
title : String ,
7
7
content : String ,
8
8
}
9
- }
9
+ }
Original file line number Diff line number Diff line change 2
2
<templates xml : space =" preserve" >
3
3
4
4
<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;" >
6
6
<div class =" card-body" >
7
7
<h5 class =" card-title" >
8
8
<t t-esc =" props.title" />
Original file line number Diff line number Diff line change 1
- /** @odoo -module **/
2
-
3
1
import { Component , useState } from "@odoo/owl" ;
4
2
5
3
export class Counter extends Component {
6
4
static template = "awesome_owl.counter" ;
5
+ static props = {
6
+ onChange : { type : Function , optional : true }
7
+ } ;
7
8
8
9
setup ( ) {
9
10
this . state = useState ( { value : 0 } ) ;
10
11
}
11
12
12
13
increment ( ) {
13
14
this . state . value ++ ;
15
+ this . props . onChange ( ) ;
14
16
}
15
- }
17
+ }
Original file line number Diff line number Diff line change 2
2
<templates xml : space =" preserve" >
3
3
4
4
<t t-name =" awesome_owl.counter" >
5
- <div >Hello World
5
+ <div style = " border:1px solid black; width: 10rem; " >Hello World
6
6
<p >Counter: <t t-esc =" state.value" />
7
7
</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 >
9
9
</div >
10
10
</t >
11
11
Original file line number Diff line number Diff line change 1
- /** @odoo -module **/
2
-
3
- import { Component , markup } from "@odoo/owl" ;
1
+ import { Component , useState , markup } from "@odoo/owl" ;
4
2
import { Counter } from "./counter" ;
5
3
import { Card } from "./card" ;
4
+ import { TodoList } from "./todolist" ;
6
5
7
6
export class Playground extends Component {
8
7
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
+ }
10
13
11
14
card1Content = markup ( "<div>Some Text in div Tag</div>" ) ;
12
15
card2Content = "<div>Some Text in div Tag</div>" ;
13
- }
16
+
17
+ incrementSum ( ) {
18
+ this . state . sum ++ ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change 2
2
<templates xml : space =" preserve" >
3
3
4
4
<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 >
7
9
<Card title =" 'my title'" content =" card1Content" />
8
10
<Card title =" 'my title'" content =" card2Content" />
11
+ <TodoList />
9
12
</t >
10
13
11
14
</templates >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 >
You can’t perform that action at this time.
0 commit comments