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

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

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

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

toggle() {
this.state.open = !this.state.open;
}
}
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; vertical-align: top;">
<div class="card-body">
<h5 class="card-title"><t t-out="props.title"/></h5>
<button class="btn btn-sm btn-light" t-on-click="toggle">Toggle</button>
<div class="card-text">
<t t-slot="default" t-if="this.state.open"/>
</div>
</div>
</div>
</t>

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

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

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

increment() {
this.state.value++;
if (this.props.onChange) {
this.props.onChange();
}
}
}
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-2 border m-2">
<p>Counter: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>

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

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

setup() {
this.html = markup("<em style='color:red;'>Hello Red World</em>");
this.state = useState({ sum: 0 });
}

incrementSum() {
this.state.sum++;
}

}
27 changes: 26 additions & 1 deletion awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<t t-name="awesome_owl.Playground">
<div class="p-3">
hello world
<h2>My Playground</h2>
<Counter/>
<Counter/>
</div>

<div class="p-3">
<h2>Sum of Counters: <t t-esc="state.sum"/></h2>

<Counter onChange="incrementSum.bind(this)"/>
<Counter onChange="incrementSum.bind(this)"/>
</div>

<div class="p-3">
<TodoList/>
</div>

<Card title="'My Tasks'">
<TodoList/>
</Card>

<Card title="'Interactive Card'">
<div class="text-center">
<p>You can even put components here:</p>
<Counter/>
</div>
</Card>
</t>

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

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

static props = {
todo: {
type: Object,
shape: {
id: Number,
description: String,
isCompleted: Boolean,
},
},
toggleState: { type: Function },
delTodo: { type: Function },
};

onChange() {
this.props.toggleState(this.props.todo.id);
}

delete() {
this.props.delTodo(this.props.todo.id);
}
}
19 changes: 19 additions & 0 deletions awesome_owl/static/src/todo/todoitem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.TodoItem">
<div class="p-2 border-bottom"
t-att-class="{'text-muted text-decoration-line-through': props.todo.isCompleted}">
<input
type="checkbox"
class="form-check-input me-2"
t-att-checked="props.todo.isCompleted"
t-on-change="onChange"
/>
<t t-esc="props.todo.id"/>.
<t t-esc="props.todo.description"/>
<span class="fa fa-remove text-danger"
t-on-click="delete"
style="cursor: pointer;"/>
</div>
</t>
</templates>
50 changes: 50 additions & 0 deletions awesome_owl/static/src/todo/todolist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Component, useState, useRef, onMounted } from "@odoo/owl";
import { TodoItem } from "./todoitem";

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

setup() {
this.nextId = 1;
this.state = useState({
newTodoName: "",
todos: []
});
this.myRef = useRef('inputTodo');
onMounted(() => {
this.myRef.el.focus();
});
}

toggleTodo(todoId) {
const todo = this.state.todos.find((t) => t.id === todoId);
if (todo) {
todo.isCompleted = !todo.isCompleted;
}
}

addTodo(ev) {
if (ev.keyCode === 13) {
const description = this.state.newTodoName.trim();
if (description) {
this.state.todos.push({
id: this.nextId++,
description: description,
isCompleted: false,
});

this.state.newTodoName = "";
}
}
}

removeTodo(todoId) {
const index = this.state.todos.findIndex((elem) => elem.id === todoId);
if (index >= 0) {
this.state.todos.splice(index, 1);
}
}

}
20 changes: 20 additions & 0 deletions awesome_owl/static/src/todo/todolist.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.TodoList">
<div>
<input
class="o_section_input py-1"
t-ref="inputTodo"
type="text"
placeholder="Enter a new task"
t-model="this.state.newTodoName"
t-on-keyup="addTodo"
/>
<t t-foreach="state.todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo" toggleState="toggleTodo.bind(this)" delTodo="removeTodo.bind(this)"/>
</t>
</div>
</t>

</templates>
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
28 changes: 28 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
'name': "Estate",
'summary': """
The Real Estate Advertisement module
""",

'description': """
The Real Estate Advertisement module
""",
'author': "Odoo",
'website': "https://www.odoo.com/",
'category': 'Tutorials',
'version': '19.0.0.1.0',
'application': True,
'depends': [
'base',
],
'data': [
'data/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_menus.xml',
'views/res_users.xml',
],
'license': 'LGPL-3',
}
5 changes: 5 additions & 0 deletions estate/data/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
estate_property_access_user,estate.property.user,model_estate_property,base.group_user,1,1,1,1
estate_property_type_access_user,estate.property.type.user,model_estate_property_type,base.group_user,1,1,1,1
estate_property_tag_access_user,estate.property.tag.user,model_estate_property_tag,base.group_user,1,1,1,1
estate_property_offer_access_user,estate.property.offer.user,model_estate_property_offer,base.group_user,1,1,1,1
1 change: 1 addition & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer, res_users
Loading