diff --git a/content/developer/howtos/frontend_owl_components.rst b/content/developer/howtos/frontend_owl_components.rst index add8cbebb..d1ab14b9b 100644 --- a/content/developer/howtos/frontend_owl_components.rst +++ b/content/developer/howtos/frontend_owl_components.rst @@ -36,7 +36,6 @@ and add it to the `public_components` registry: .. code-block:: js - /** @odoo-module */ import { Component } from "@odoo/owl"; import { registry } from "@web/core/registry" diff --git a/content/developer/howtos/javascript_client_action.rst b/content/developer/howtos/javascript_client_action.rst index 8ae72eacb..e3e4f0b34 100644 --- a/content/developer/howtos/javascript_client_action.rst +++ b/content/developer/howtos/javascript_client_action.rst @@ -29,8 +29,9 @@ framework and use services, core components, hooks,... import { Component } from "@odoo/owl"; - class MyClientAction extends Component {} - MyClientAction.template = "my_module.clientaction"; + class MyClientAction extends Component { + static template = "my_module.clientaction"; + } // remember the tag name we put in the first step registry.category("actions").add("my_module.MyClientAction", MyClientAction); diff --git a/content/developer/howtos/javascript_field.rst b/content/developer/howtos/javascript_field.rst index 70df6edc3..7f6764e0b 100644 --- a/content/developer/howtos/javascript_field.rst +++ b/content/developer/howtos/javascript_field.rst @@ -18,8 +18,9 @@ displaying "Late!" in red whenever the checkbox is checked. import { BooleanField } from "@web/views/fields/boolean/boolean_field"; import { Component, xml } from "@odoo/owl"; - class LateOrderBooleanField extends BooleanField {} - LateOrderBooleanField.template = "my_module.LateOrderBooleanField"; + class LateOrderBooleanField extends BooleanField { + static template = "my_module.LateOrderBooleanField"; + } #. Create the field template. @@ -66,23 +67,20 @@ Assume that we want to create a field that displays a simple text in red. import { registry } from "@web/core/registry"; export class MyTextField extends Component { + static template = xml` + + `; + static props = { ...standardFieldProps }; + static supportedTypes = ["char"]; - /** - * @param {boolean} newValue - */ - onChange(newValue) { - this.props.update(newValue); - } + /** + * @param {boolean} newValue + */ + onChange(newValue) { + this.props.update(newValue); + } } - MyTextField.template = xml` - - `; - MyTextField.props = { - ...standardFieldProps, - }; - MyTextField.supportedTypes = ["char"]; - The imported `standardFieldProps` contains the standard props passed by the `View` such as the `update` function to update the value, the `type` of the field in the model, the `readonly` boolean, and others. diff --git a/content/developer/howtos/javascript_view.rst b/content/developer/howtos/javascript_view.rst index 530e51482..a939054fd 100644 --- a/content/developer/howtos/javascript_view.rst +++ b/content/developer/howtos/javascript_view.rst @@ -20,12 +20,12 @@ can be done in a few steps: // the controller usually contains the Layout and the renderer. class CustomKanbanController extends KanbanController { + static template = "my_module.CustomKanbanView"; + // Your logic here, override or insert new methods... // if you override setup(), don't forget to call super.setup() } - CustomKanbanController.template = "my_module.CustomKanbanView"; - export const customKanbanView = { ...kanbanView, // contains the default Renderer/Controller/Model Controller: CustomKanbanController, @@ -85,6 +85,9 @@ Creating a new view is an advanced topic. This guide highlight only the essentia import { Component, onWillStart, useState} from "@odoo/owl"; export class BeautifulController extends Component { + static template = "my_module.View"; + static components = { Layout }; + setup() { this.orm = useService("orm"); @@ -106,9 +109,6 @@ Creating a new view is an advanced topic. This guide highlight only the essentia } } - BeautifulController.template = "my_module.View"; - BeautifulController.components = { Layout }; - The template of the Controller displays the control panel with Layout and also the renderer. @@ -133,9 +133,9 @@ Creating a new view is an advanced topic. This guide highlight only the essentia :caption: :file:`beautiful_renderer.js` import { Component } from "@odoo/owl"; - export class BeautifulRenderer extends Component {} - - BeautifulRenderer.template = "my_module.Renderer"; + export class BeautifulRenderer extends Component { + static template = "my_module.Renderer"; + } .. code-block:: xml :caption: :file:`beautiful_renderer.xml` diff --git a/content/developer/howtos/website_themes/building_blocks.rst b/content/developer/howtos/website_themes/building_blocks.rst index 2e6735776..255fbfff0 100644 --- a/content/developer/howtos/website_themes/building_blocks.rst +++ b/content/developer/howtos/website_themes/building_blocks.rst @@ -380,8 +380,6 @@ The `data-js` attribute can be assigned to an options group in order to define a .. code-block:: javascript - /** @odoo-module */ - import options from 'web_editor.snippets.options'; options.registry.CustomMethodName = options.Class.extend({ diff --git a/content/developer/reference/frontend/framework_overview.rst b/content/developer/reference/frontend/framework_overview.rst index 4976f30bf..63d155395 100644 --- a/content/developer/reference/frontend/framework_overview.rst +++ b/content/developer/reference/frontend/framework_overview.rst @@ -152,9 +152,10 @@ client can use it. For example, the field registry contains all field components .. code-block:: javascript + import { Component } from "@odoo/owl"; import { registry } from "./core/registry"; - class MyFieldChar extends owl.Component { + class MyFieldChar extends Component { // some code } diff --git a/content/developer/reference/frontend/hooks.rst b/content/developer/reference/frontend/hooks.rst index ba240153d..5fd866a4e 100644 --- a/content/developer/reference/frontend/hooks.rst +++ b/content/developer/reference/frontend/hooks.rst @@ -193,18 +193,20 @@ the window is resized/scrolled. .. code-block:: javascript import { usePosition } from "@web/core/position_hook"; + import { Component, xml } from "@odoo/owl"; + + class MyPopover extends Component { + static template = xml` +
+ I am positioned through a wonderful hook! +
+ `; - class MyPopover extends owl.Component { setup() { // Here, the reference is the target props, which is an HTMLElement usePosition(this.props.target); } } - MyPopover.template = owl.tags.xml` -
- I am positioned through a wonderful hook! -
- `; .. important:: You should indicate your `popper` element using a `t-ref directive `_. @@ -260,11 +262,21 @@ API .. code-block:: javascript + import { Component, xml, useRef } from "@odoo/owl"; import { usePosition } from "@web/core/position_hook"; - class DropMenu extends owl.Component { + class DropMenu extends Component { + static template = xml` + +
+ + This is the menu default content. + +
+ `; + setup() { - const toggler = owl.useRef("toggler"); + const toggler = useRef("toggler"); usePosition( () => toggler.el, { @@ -278,14 +290,6 @@ API ); } } - DropMenu.template = owl.tags.xml` - -
- - This is the menu default content. - -
- `; .. _frontend/hooks/useSpellCheck: diff --git a/content/developer/reference/frontend/javascript_reference.rst b/content/developer/reference/frontend/javascript_reference.rst index 40c40cfa7..a298de52f 100644 --- a/content/developer/reference/frontend/javascript_reference.rst +++ b/content/developer/reference/frontend/javascript_reference.rst @@ -154,7 +154,6 @@ This is done by using the `patch` utility function: .. code-block:: javascript - /** @odoo-module */ import { Hamster } from "@web/core/hamster" import { patch } from "@web/core/utils/patch"; diff --git a/content/developer/reference/frontend/owl_components.rst b/content/developer/reference/frontend/owl_components.rst index 47c78fc76..3d465335e 100644 --- a/content/developer/reference/frontend/owl_components.rst +++ b/content/developer/reference/frontend/owl_components.rst @@ -29,10 +29,15 @@ can make a simple component in Odoo. .. code-block:: javascript - const { useState } = owl.hooks; - const { xml } = owl.tags; + import { Component, xml, useState } from "@odoo/owl"; class MyComponent extends Component { + static template = xml` +
+ +
+ `; + setup() { this.state = useState({ value: 1 }); } @@ -41,10 +46,6 @@ can make a simple component in Odoo. this.state.value++; } } - MyComponent.template = xml - `
- -
`; This example shows that Owl is available as a library in the global namespace as `owl`: it can simply be used like most libraries in Odoo. Note that we @@ -67,12 +68,13 @@ Here is how the component above should be defined: .. code-block:: javascript - const { useState } = owl.hooks; + import { Component, useState } from "@odoo/owl"; class MyComponent extends Component { + static template = 'myaddon.MyComponent'; + ... } - MyComponent.template = 'myaddon.MyComponent'; And the template is now located in the corresponding xml file: @@ -768,16 +770,21 @@ Props .. code-block:: javascript + import { Component, xml } from "@odoo/owl"; import { Notebook } from "@web/core/notebook/notebook"; - class MyTemplateComponent extends owl.Component { - static template = owl.tags.xml` + class MyTemplateComponent extends Component { + static template = xml`

`; } - class MyComponent extends owl.Component { + class MyComponent extends Component { + static template = xml` + + `; + get pages() { return [ { @@ -800,9 +807,6 @@ Props ] } } - MyComponent.template = owl.tags.xml` - - `; Both examples are shown here: @@ -941,9 +945,18 @@ The shape of a `group` is the following: .. code-block:: javascript + import { Component, xml } from "@odoo/owl"; import { SelectMenu } from "@web/core/select_menu/select_menu"; - class MyComponent extends owl.Component { + class MyComponent extends Component { + static template = xml` + + `; + get choices() { return [ { @@ -979,30 +992,21 @@ The shape of a `group` is the following: ] } } - MyComponent.template = owl.tags.xml` - - `; You can also customize the appearance of the toggler and set a custom template for the choices, using the appropriate component `slot`'s. - .. code-block:: javascript + .. code-block:: xml - MyComponent.template = owl.tags.xml` - - Make a choice! - - - - - `; + + Make a choice! + + + + .. image:: owl_components/select_menu.png :width: 400 px @@ -1019,22 +1023,20 @@ The shape of a `group` is the following: For more advanced use cases, you can customize the bottom area of the dropdown, using the `bottomArea` slot. Here, we choose to display a button with the corresponding value set in the search input. - .. code-block:: javascript + .. code-block:: xml - MyComponent.template = owl.tags.xml` - - Select something - -

- -
- - - `; + + Select something + +
+ +
+
+
.. image:: owl_components/select_menu_bottomArea.png :width: 400 px @@ -1098,9 +1100,13 @@ The shape of a `tag` is the following: .. code-block:: javascript + import { Component, xml } from "@odoo/owl"; import { TagsList } from "@web/core/tags_list/tags_list"; class Parent extends Component { + static template = xml``; + static components = { TagsList }; + setup() { this.tags = [{ id: "tag1", @@ -1119,8 +1125,6 @@ The shape of a `tag` is the following: }]; } } - Parent.components = { TagsList }; - Parent.template = xml``; Depending the attributes given to each tag, their appearance and behavior will differ. diff --git a/content/developer/reference/frontend/services.rst b/content/developer/reference/frontend/services.rst index f786e7951..c09dbce7e 100644 --- a/content/developer/reference/frontend/services.rst +++ b/content/developer/reference/frontend/services.rst @@ -313,10 +313,10 @@ Let's say we want to add an effect that add a sepia look at the page. .. code-block:: javascript import { registry } from "@web/core/registry"; - const { Component, tags } = owl; + import { Component, xml } from "@odoo/owl"; - class SepiaEffect extends Component {} - SepiaEffect.template = tags.xml` + class SepiaEffect extends Component { + static template = xml`
- `; + `; + } export function sepiaEffectProvider(env, params = {}) { return {