* mass_mailing, payment, point_of_sale, portal, survey, web, web_tour, website_blog, website_crm_partner_assign, website_event, website_event_questions, website_form, website_forum, website_gengo, website_hr_recruitment, website_links, website_mail, website_mail_channel, website_mass_mailing, website_quote, website_sale, website_sale_options, website_slides, website_twitter This commit reviews the whole "JS side" of the web_editor and website apps. This is a first step to be able to improve them with new and better functionnalities; this commit is not supposed to change any visual behavior. The main goal was to achieve a structure similar to the backend one. Now, the frontend side also has a root widget (like the WebClient) and all other widgets are attached to it one way or another. This allows the benefits of using the 'trigger_up' functionnality for example. As RPC are now mainly done with the `this._rpc` functionnality (being possible thanks to the parent hierarchy), the frontend will also be possible to test thanks to QUnit in a future update (besides the "text" editor side which still requires a refactoring to be able to do that). --- Here are some of the changes: (-) conventions and documentation The code has been updated to follow JS conventions and a lot of code has been commented (around +2000 lines of comment). This also means that lots of functions have been renamed to use camelCase or simply to make their name understandable. See https://github.com/odoo/odoo/wiki/Javascript-coding-guidelines. (-) deprecated: web_editor.base The "web_editor.base" module has been split and does not force the modules which require it to wait for DOM ready anymore. This was indeed slowing loading times, but also prevented to use some modules in some contexts (see the LESS editor use in web_studio which is the subject of another task). Now the "editor context" can be got thanks to the "web_editor.context" JS module with its "get" function. The "web_editor.base" module should probably not be used anymore (see its code and recent updates). (-) new: web.dom_ready If a JS module should wait for the DOM to be ready to be executed, a new JS module has been created: "web.dom_ready". This should always be used in a module which only want to instantiate stuff. Do not extend (or worst, include) classes after DOM ready. (-) website.website The "website.website" module has been split. "website.website" does not return anything useful anymore, it just initialize some miscellaneous stuff, without waiting for the DOM to be ready. You might want to check "website.utils", "website.content.compatibility" or `WebsiteRoot`. Also `website.form` has been deleted (use `this._rpc`), so has been `website.error`. `website.prompt` will be removed in a future update to be replaced by `Dialog.prompt`. (-) widgets are great Many classes which were not widgets are now widgets. This allows them to use the 'events', the 'xmlDependencies' and the 'this._rpc' features for example. Here are some of the main ones: - Snippet options: these were classes with a `$el` for the menu element and `$target` for the customized element. This is still the case but following standard `Widget` structure (one exception: using `this.$(...)` searches in the `$target` as before this update). - Snippet animations: instead of class instances with a `$target` element which can be `start` and `stop`, these are now standard widgets which can be `start` and `destroy`. `this.$target` is an alias to `this.$el` for ease of compatibility. - Snippet editors: instead of class instances in charge of an editor overlay, these are now widgets. Each "child" snippet editor is properly attached as a "child", which allows editors to communicate and to be properly destroyed. (-) root widgets and website navbar The frontend is different of the backend. In the backend, the page has an empty <body/> element and all the components are instantiated from parent to children (i.e. the `WebClient` is instantiated and is in charge of instantiating the `ControlPanel`, etc). The frontend cannot work like that on page loadings as they are way more frequent than in the backend and we do not want them to flicker. A frontend page is loaded as a <body/> element which already contains the website navbar and its menus and the whole content page. JS code has to be "attached" to these existing elements. This is possible thanks to the `RootWidget` instances and the specialized `WebsiteRoot`, `IframeRoot` and `WebsiteNavbar` (see code for details). (-) lazy loading No more (or at least a lot less) XML/JS has to be loaded on page loading, thanks to the use of the `Widget.xmlDependencies` feature. XML which have to be lazy loaded is loaded only on related Widget instantiation if necessary, which allows to execute a lot of JS code before the DOM is ready and to start many widgets on DOM ready (not later). A visual benefit of this is clicking on the 'edit' button as soon as it is possible: before this commit, this was sometimes not doing anything as event handlers were not binded yet. Still a possible exception: loading the session and locales. This may be asynchronous stuff which is still required before widget instantiations but this will be the subject of another task. (-) deprecated code and code location More than reviewing code and organizing it, many apparent dead code was removed. More importantly, mislocated code was put in the right app. This is the case for snippet animations which is a concept for website apps but was defined in the web_editor app, or some translation concepts which were part of website but should have been part of web_editor. --- There are probably more things to say about this commit but I will let the comments speak for those.
154 lines
5.6 KiB
ReStructuredText
154 lines
5.6 KiB
ReStructuredText
Website Snippet & Blocks
|
|
========================
|
|
|
|
The building blocks appear in the edit bar website. These prebuilt html block
|
|
allowing the designer to easily generate content on a page (drag and drop).
|
|
Snippets bind javascript object on custom part html code according to their
|
|
selector (jQuery) and javascript object. The snippets is also used to create
|
|
the drop zone.
|
|
|
|
|
|
Building Blocks
|
|
+++++++++++++++
|
|
|
|
Overwrite ``_getSnippetURL`` to set an other file to load the snippets (use by
|
|
website_mail for example)
|
|
Overwrite ``_computeSelectorFunctions`` to enable or disable other snippets. By default
|
|
the builder check if the node or his parent have the attribute data-oe-model
|
|
|
|
Trigger:
|
|
- ``snippet-dropped`` is triggered on ``#oe_snippets`` whith $target as attribute when a snippet is dropped
|
|
- ``snippet-activated`` is triggered on ``#oe_snippets`` (and on snippet) when a snippet is activated
|
|
|
|
|
|
Blocks
|
|
++++++
|
|
|
|
The ``blocks`` are the HTML code that can be drop in the page. The blocks consist
|
|
of a body and a thumbnail:
|
|
- thumbnail:
|
|
(have class ``oe_snippet_thumbnail``) contains a picture and a text used to
|
|
display a preview in the edit bar that contains all the block list
|
|
- body:
|
|
(have class ``oe_snippet_body``) is the real part dropped in the page. The class
|
|
``oe_snippet_body`` is removed before inserting the block in the page.
|
|
e.g.:
|
|
<div>
|
|
<div class="oe_snippet_thumbnail">
|
|
<img class="oe_snippet_thumbnail_img" src="...image src..."/>
|
|
<span class="oe_snippet_thumbnail_title">...Block Name...</span>
|
|
</div>
|
|
<div class="oe_snippet_body">
|
|
<!--
|
|
The block with class 'oe_snippet_body' is inserted in the page.
|
|
This class is removed when the block is dropped.
|
|
The block can be made of any html tag and content. -->
|
|
</div>
|
|
</div>
|
|
|
|
|
|
Editor
|
|
++++++
|
|
|
|
The ``editor`` is the frame placed above the block being edited who contains buttons
|
|
(move, delete, clone) and customize menu. The ``editor`` load ``options`` based on
|
|
selectors defined in snippets
|
|
|
|
|
|
Options
|
|
+++++++
|
|
|
|
The ``option`` is the javascript object used to customize the HTML code.
|
|
|
|
Object:
|
|
- this.``$target``:
|
|
block html inserted inside the page
|
|
- this.``$el``:
|
|
html li list of this options
|
|
- this.``$overlay``:
|
|
html editor overlay who content resize bar, customize menu...
|
|
|
|
Methods:
|
|
- ``_setActive``:
|
|
highlight the customize menu item when the user click on customize, and click on
|
|
an item.
|
|
- ``start``:
|
|
called when the editor is created on the DOM
|
|
- ``onFocus``:
|
|
called when the user click inside the block inserted in page and when the
|
|
user drop on block into the page
|
|
- ``onBlur``:
|
|
called when the user click outside the block inserted in page, if the block
|
|
is focused
|
|
- ``onClone``:
|
|
called when the snippet is duplicate
|
|
- ``onRemove``:
|
|
called when the snippet is removed (dom is removing after this tigger)
|
|
- ``onBuilt:
|
|
called just after that a thumbnail is drag and dropped into a drop zone.
|
|
The content is already inserted in the page.
|
|
- ``cleanForSave``:
|
|
is called just before to save the vue. Sometime it's important to remove or add
|
|
some datas (contentEditable, added classes to a running animation...)
|
|
|
|
Customize Methods:
|
|
All javascript option can defiend method call from the template on mouse over, on
|
|
click or to reset the default value (<li data-your_js_method="your_value"><a>...</a></li>).
|
|
The method receive the variable type (``over``, ``click`` or ``reset``), the method
|
|
value and the jQuery object of the HTML li item. (can be use for multi methods)
|
|
|
|
By default to custom method are defined:
|
|
|
|
- ``check_class(type, className, $li)``:
|
|
li must have data-check_class="a_classname_for_test" to call this method. This method
|
|
toggle the className on $target
|
|
- ``selectClass(type, className, $li)``:
|
|
This method remove all other selectClass value (for this option) and add this current ClassName
|
|
|
|
|
|
|
|
Snippet
|
|
+++++++
|
|
|
|
The ``snippets`` are the HTML code to defined the drop zone and the linked javascript object.
|
|
All HTML li tag defined inside the snippets HTML are insert into the customize menu. All
|
|
data attributes is optional:
|
|
|
|
- ``data-selector``:
|
|
Apply options on all The part of html who match with this jQuery selector.
|
|
E.g.: If the selector is div, all div will be selected and can be highlighted and assigned an editor.
|
|
- ``data-js``:
|
|
javascript to call when the ``editor`` is loaded
|
|
- ``data-drop-in``:
|
|
The html part can be insert or move beside the selected html block (jQuery selector)
|
|
- ``data-drop-near``:
|
|
The html part can be insert or move inside the selected html block (jQuery selector)
|
|
- HTML content like <li data-your_js_method="your_value"><a>...</a></li>:
|
|
List of HTML li menu items displayed in customize menu. If the li tag have datas the methods are
|
|
automatically called
|
|
- ``no-check``:
|
|
The selectors are automatically compute to have elements inside the branding. If you use this option
|
|
the check is not apply (for e.g.: to have a snippet for the grid view of website_sale)
|
|
|
|
t-snippet and data-snippet
|
|
++++++++++++++++++++++++++
|
|
|
|
User can call a snippet template with qweb or inside a demo page.
|
|
|
|
e.g.:
|
|
|
|
<template id="website.name_of_the_snippet" name="Name of the snippet">
|
|
<hr/>
|
|
</template>
|
|
|
|
Inside #snippet_structure for e.g.: ``<t t-snippet="website.name_of_the_snippet" t-thumbnail="/image_path"/>``
|
|
The container of the snippet became not editable (with branding)
|
|
|
|
Inside a demo page call the snippet with: ``<div data-oe-call="website.name_of_the_template"/>``
|
|
The snippets are loaded in one time by js and the page stay editable.
|
|
|
|
More
|
|
++++
|
|
|
|
- Use the class ``o_not_editable`` to prevent the edition from an area.
|