Compare commits

...

3 Commits

Author SHA1 Message Date
Vincent Schippefilt
e9a8e1790e Added changelog 2022-09-20 15:19:37 +02:00
Vincent Schippefilt
c4fda89c5c wip 2022-09-15 17:54:27 +02:00
Gorash
06e9a25481 [IMP] web: update documentation about bundle and statics templates 2022-09-14 13:19:05 +02:00
4 changed files with 69 additions and 24 deletions

View File

@@ -35,6 +35,13 @@ dictionary, where each key specifies module metadatum.
'demo': [
'demo/demo_data.xml',
],
'assets': {
'module.bundle_name': [
'module/static/src/*.js'
'module/static/src/*.scss'
'module/static/src/*.xml'
]
}
}
Available manifest fields are:

View File

@@ -4,6 +4,49 @@
Changelog
=========
Odoo version 16.0
=================
- The change with static XML into bundle asset impacting all modules has just been merged.
https://github.com/odoo/odoo/commit/f05adbc8b59c67cbec4847687a1ee07e620c2a7a
Assets declared in "__manifest__.py" can now contain static xml files (for owl & qweb templates).
The "web.assets_qweb" bundle including almost all the static xml and the widget attributes `xmlDependencies` have been removed.
The file `@web/core/assets.js` now contains more general asset utility functions (loadJS, loadCSS, getBundle, loadBundle).
Legacy file `ajax.js` is deprecated and will be removed and should not be used anymore.
When a bundle is lazy loaded (from loadBundle), it is considered to be loaded when the JS, CSS and XML templates are loaded.
Example:
Version before:
.. code-block:: python
'web.assets_qweb': [
'module_name/static/src/folder/template.xml',
],
'web.assets_backend': [
'module_name/static/src/folder/component.js',
'module_name/static/src/folder/*.scss',
],
+ xmlDependencies: ['/module_name/static/folder/template2.xml'],
+ await ajax.loadXML('/module_name/static/folder/template3.xml', qweb);
Is now:
.. code-block:: python
'web.assets_backend': [
'module_name/static/src/folder/component.js',
'module_name/static/src/folder/*.scss',
'module_name/static/src/folder/*.xml',
],
or simplify into:
.. code-block:: python
'web.assets_backend': [
'module_name/static/src/folder/*',
],
Odoo Online version 15.4
========================

View File

@@ -38,7 +38,7 @@ Template
Templates (static `xml` files) are handled in a different way: they are simply
read from the file system whenever they are needed, and concatenated.
Whenever the browser loads odoo, it calls the `/web/webclient/qweb/` controller
Whenever the browser loads odoo, it calls the `/web/webclient/qweb?bundle=module.bundle_name` controller
to fetch the :ref:`templates <reference/qweb>`.
It is useful to know that in most cases, a browser only performs a request the
@@ -67,6 +67,7 @@ like this:
'assets': {
'web.assets_backend': [
'web/static/src/core/**/*',
'web/static/src/xml/**/*',
],
'web.assets_common': [
@@ -93,9 +94,6 @@ know:
- `web.assets_frontend`: this bundle is about all that is specific to the public
website: ecommerce, portal, forum, blog, ...
- `web.assets_qweb`: all static XML templates used in the backend environment
and in the point of sale.
- `web.qunit_suite_tests`: all javascript qunit testing code (tests, helpers, mocks)
- `web.qunit_mobile_suite_tests`: mobile specific qunit testing code
@@ -367,4 +365,3 @@ manifest counterparts.
`sequence` (default= `16`)
Loading order of the asset records (ascending). A sequence lower than 16 means
that the asset will be processed *before* the ones declared in the manifest.

View File

@@ -311,8 +311,8 @@ Here is an example of a basic counter widget:
});
For this example, assume that the template *some.template* (and is properly
loaded: the template is in a file, which is properly defined in the assets of
the module manifest ``'assets': {'web.assets_qweb': [...]}``, see
loaded: the template is in a file, which is properly defined in the bundle of
the module manifest, in the same bundle as the JavaScript file, see
:ref:`assets <reference/assets>`.) is given by:
.. code-block:: xml
@@ -444,18 +444,18 @@ Widget API
initialized but before it has been started. The root element generated by
the template will be set as the DOM root of the widget.
.. attribute:: Widget.xmlDependencies
.. attribute:: Widget.assetLibs
List of paths to xml files that need to be loaded before the
List of paths to bundle assets that need to be loaded before the
widget can be rendered. This will not induce loading anything that has already
been loaded. This is useful when you want to load your templates lazily,
been loaded. This is useful when you want to load your module ans files lazily,
or if you want to share a widget between the website and the web client
interface.
.. code-block:: javascript
var EditorMenuBar = Widget.extend({
xmlDependencies: ['/web_editor/static/src/xml/editor.xml'],
assetLibs: ['web_editor.assets_wysiwyg'],
...
.. attribute:: Widget.events
@@ -637,21 +637,18 @@ override the *renderElement* method to do something else).
The Qweb JS template engine is based on XML, and is mostly compatible with the
python implementation.
Now, let us explain how the templates are loaded. Whenever the web client
starts, a rpc is made to the */web/webclient/qweb* route. The server will then
return a list of all templates defined in data files for each installed modules.
The correct files are listed in the *web.assets_qweb* entry in each module
manifest. It is also possible to lazy-load another bundle's templates by calling
this same route and giving it the corresponding "bundle" query parameter.
The bundle contains the JavaScript code, the CSS files and the xml templates
from the manifest. It is also possible to lazy-load another bundle's from
`getBundle` and `loadBundle` defined in `@web/core/assets.js` file.
The web client will wait for that list of template to be loaded, before starting
its first widget.
This mechanism works quite well for our needs, but sometimes, we want to lazy
load a template. For example, imagine that we have a widget which is rarely
used. In that case, maybe we prefer to not load its template in the main file,
in order to make the web client slightly lighter. In that case, we can use the
*xmlDependencies* key of the Widget:
load a template and JavaScript. For example, imagine that we have a widget
which is rarely used. In that case, maybe we prefer to not load its files in
the main file, in order to make the web client slightly lighter. In that case,
we can use the *assetLibs* key of the Widget:
.. code-block:: javascript
@@ -659,14 +656,15 @@ in order to make the web client slightly lighter. In that case, we can use the
var Counter = Widget.extend({
template: 'some.template',
xmlDependencies: ['/myaddon/path/to/my/file.xml'],
assetLibs: ['module.bundle_name'],
...
});
With this, the *Counter* widget will load the xmlDependencies files in its
*willStart* method, so the template will be ready when the rendering is performed.
With this, the *Counter* widget will get the file list and load the files and
wait that the template is fully loaded in its *willStart* method, so the
template will be ready when the rendering is performed.
Event system