Commit Graph
3111 Commits
Author SHA1 Message Date
Benoit Socias 567e5b58d5 [IMP] base, tools, web_editor, *: use original image if size increases
*: web_tour, website

When no transformation is applied on an image, changing the quality
sometimes increases its storage size.

This commit makes sure that the original image remains used if only the
image quality is modified and if this makes its storage size bigger.

Fixes #61619
task-2835144

closes odoo/odoo#103398

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-07-19 13:12:51 +02:00
Benoit Socias c512f098a7 [IMP] web_editor: introduce a tool method to compute size of data URL
This commit extracts the calculation of the number of bytes within a
base64 data URL to a method named `getDataURLBinarySize`.

task-2835144

Part-of: odoo/odoo#103398
2023-07-19 13:12:50 +02:00
Nicolas Bayet d7245d2abf [REF] web_editor,*: convert wysiwyg to owl
The goal of this commit is to remove all dependency to legacy in the
wysiwyg because the wysiwyg has to be loaded on a lot of form view
(through the html_field).

To remove the dependencies, all the legacy widget that the wysiwyg
uses had to be converted to owl. In order to finish the PR faster,
only a partial conversion of the widgets is done, changing only the
part of the code that was necessary for it to work instead of
rewriting the whole widget from scratch. Another pass should be done
to convert all those widgets to fully embrace the owl paradigm.

task-3175256

Part-of: odoo/odoo#118966
2023-07-19 11:39:44 +02:00
Nicolas Bayet a2dab27700 [REF] web_editor,*: move media_dialog_wrapper to its own file
For organisation purpose, move the media_dialog_wrapper to its own file.

task-3175256

Part-of: odoo/odoo#118966
2023-07-19 11:39:44 +02:00
Nicolas Bayet dddba97927 [REF] web_editor: rename image_crop_widget.js to image_crop.js
In a subsequent commit, the ImageCropWidget will be converted into
an Owl component called ImageCrop. To match the new name, this commit
rename the file.

task-3175256

Part-of: odoo/odoo#118966
2023-07-19 11:39:44 +02:00
abd-msyukyu-odoo c6fb5793c5 [FIX] web_editor: make urgent commitChanges quasi synchronous
In the context of an urgent htmlField `commitChanges`, there is no time to wait
the response of `rpc` calls, therefore this commit proposes to use the same
strategy as `_toInline` for `savePendingImages`  and not await the result of
the promises before a first `updateValue` if the commit is `urgent`.
This will allow to save most of the changes during a `beforeunload` scenario.

ENTERPRISE PR: https://github.com/odoo/enterprise/pull/42644

task-3372343

closes odoo/odoo#128949

X-original-commit: ba94629cb7fd1381871c37d34104f2511a4d4863
Related: odoo/enterprise#44307
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-07-18 21:48:36 +02:00
shsa-odoo 55bcdfd7d8 [FIX] web_editor: infinite loop in lists in table
Before this commit:

In table selecting a list and on deletion/backspace page crashes.

After this commit:

The selected list is now deleted.

task-3383168

closes odoo/odoo#128943

X-original-commit: c7d3d247269ce27a10da39df5848cc10f9f6627b
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-18 20:35:52 +02:00
David Beguin 6ee1d0a1f4 [IMP] web_editor: add /banner commands
Purpose
=======
Make it possible to attract attention to a small section of a text document
(e.g. task spec, knowledge article, etc.) via a new "bloc" called "Banner".

Specifications
==============

Add 4 commands in web_editor.
Each command will add a banner of the following types and will come with their
associated icons:
- Banner Info: alert-info - info-circle
- Banner Success: alert-success - check-circle
- Banner Warning: alert-warning - exclamation-triangle
- Banner Danger: alert-danger - exclamation

Task-2782426

Part-of: odoo/odoo#120690
2023-07-18 19:27:53 +02:00
David Beguin 111e20de9b [IMP] web_editor: add isSelectionInSelectors utility method
This commit add a new utility method to check if the selection (current cursor
position) starts inside one of the given selectors. This method will be used,
notably, for filtering some commands inside some HTML Elements of the web
editor. Some commands should not be available within certain elements like
table, custom behaviours (knowledge app) or banners (that will be introduced in
the next commit).

Task-2782426

Part-of: odoo/odoo#120690
2023-07-18 19:27:53 +02:00
David Monjoie 17ee75a84d [IMP] web_editor: use o_editable and o_not_editable as markers
Before this commit, the o_not_editable class was used as a way to
dynamically set contentEditable on a node. This was little more
than  a convulated way to write `node.contentEditable = false`.
Moreover, the o_editable class was not treated the same way and
did not set contentEditable to true.

This commit turns those two classes into markers for contentEditable
values in html. Once those classes are set, the contentEditable
attribute is updated accordingly. It is not updated dynamically
afterwards. For dynamically setting a node as editable or not, use
the contentEditable attribute directly.

Task-2782426

Part-of: odoo/odoo#120690
2023-07-18 19:27:53 +02:00
Rodolpho Lima 470195f140 [FIX] web_editor: current step changes on history redo
Steps to reproduce:

1. On website, drop a snippet
2. Type something, than undo it (ctrl + z or click undo button on the
sidebar)
3. On the sidebar, hover over the buttons of "Content Width" and/or
"Height" to get a preview of those actions
4. Perform a redo with ctrl + y.

Explanation:

One can only redo changes when in a state resulting from an undo, that is,
redo is the undoing of an undo. Once new changes are introduced after an
undo operation took place, a redo cannot be performed anymore.

The OdooEditor handles this at the history steps level. If there's a
a history step with state "undefined" (not resulting of undo or redo)
that is more recent than the most recent step with state "undo", a
redo is not possible.

But, before this commit, this was not handled at the current step's
mutations level. The presence of mutations in the current step did not
prevent a redo, and applying a redo on top of those changes could lead to
unexpected results, as the changes resulting from the reversion of undo
step interacted with the mutations performed subsequent to the undo
operation.

The presence of mutations in the current step when about to redo is
possible by previewing changes as described above, as they perform
DOM mutations without committing them into a history step. The same
effect can be achieved by selecting some text and hovering over the
colors of the colorpicker. Theoretically, any asynchronous compound
command (multiple calls to execCommand within historyPauseSteps/
historyUnpauseSteps) will add mutations to the current step without
committing them, while still offering the user the possibility of a redo.

This commit makes sure that mutations in the current step are treated
as an uncommitted draft and are discarded before applying a redo, mirroring
what is done for the undo operation.

task-3339304

closes odoo/odoo#128873

X-original-commit: 6ab6927c0fc4c4a1c838251953a29512dd0d3835
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-18 18:18:25 +02:00
Benoit Socias 3e8a690d10 [FIX] website, *: wait images when setting masonry images wall layout
*: web_editor

During the masonry layout calculation of the images wall snippet, the
image height is used to determine into which column each image is
inserted. Their height is zero until they are actually loaded. Because
of this, the column into which an image is inserted can be wrong.

This becomes more obvious in 16.0 because since [1] the image selection
is lost when moving it within an Image Wall because it is replaced by a
clone when using masonry mode.

This commit makes sure that the images are loaded before taking their
height into account when building the masonry layout.

This involves two changes:

1. By awaiting `wUtils.onceAllImagesLoaded(this.$target)` after the
insertion of each cloned image, we are sure that the reached height of
each column is available before deciding where to insert the next image.

2. Before re-selecting the previously selected image, we need to be
sure that it is loaded. Therefore we keep track of the last masonry
layout operation and await for it. This way, we rely on the await of
the last image as described in point 1.

Additionally, as of 16.0, there is a race condition with
`snippet_option_update`: in some situations, `notify` is called before
`snippet_option_update` is completed, and before the masonry layout is
applied.  To make sure it is completed, the whole notify is run within
the mutex through a `snippet_edition_request` event.

To uphold the stable policy, making `mode` async will only be done in
master.
In stable, a new `_modeWithImageWait` is added which is called only
for the situations that causing an issue, and which enables the fix
of the masonry layout.
In 14.0, it is used when computing the layout from `start` and
`addImages`.
In 16.0, it is also used in `notify` when images are removed or moved
around - because masonry clones the images.
In master, it is always applied.

Steps to reproduce:
- Drop an Images Wall.
- Add four images, the first one being taller than the others.

=> The fourth image sometimes appeared below the tall image.

[1]: https://github.com/odoo/odoo/commit/0d43aec24baad6420e0fe150a9c19d33c0b74198

task-2990053

X-original-commit: 9605d9ba7b26885d66e861e0e5c7dff7489031f9
Part-of: odoo/odoo#125758
2023-07-18 16:58:56 +02:00
Benoit Socias c1c20dcd08 [FIX] website, web_editor: not move images twice within image wall
Since [1] the "Images Add/Remove All" buttons are on top of the
background options in order to appear as the first option for the
"Image Wall" snippet.
This makes the JS related to the handling of the options of that
snippet created twice: once for the buttons above and once for the
options below.
Because of this, events are registered by both instances and they both
get notified on option update. Therefore, when an image is moved, it is
moved twice instead of once.

This commit differentiates both instances, and makes the one that
handles the "Add" and "Remove All" buttons be the only one that works on
the images.
In stable the differentiation is done with conditional statements.
In master the instances should be of distinct classes.

Steps to reproduce:
- Drop an "Images Wall" block.
- Switch the "Mode" option to "Grid" instead of "Masonry".
- Select the wine glass image in the third column.
- Click on "Move to previous".

=> The wine glass image ended up in the first column because it was
moved twice.

This commit also fixes a typo in the `reoder_items` name introduced
by [2].

[1]: https://github.com/odoo/odoo/commit/b6494fcf284edcddaa36b5fcfd407a6d7186fbd7
[2]: https://github.com/odoo/odoo/commit/e8713dc078b5c1799917f238a4c32b4289aceb8a

task-2990053

X-original-commit: f8724b55162b2550734dbe6e0454c406d6e4241c
Part-of: odoo/odoo#125758
2023-07-18 16:58:56 +02:00
Benoit Socias 009f259b0b [FIX] web_editor: make moving images within wall wrap around
When using the previous button in an image wall, the image wraps around
but skips the last position.
When using the next button in an image wall, the image does not wrap
around.

This commit fixes this inconsistency by using the same behavior as the
one in 15.0 since [1]: wrap through all positions in both directions.

Steps to reproduce:
- Drop an "Images Wall" snippet.
- Add 6 images.
- Select an image.
- Click repeatedly on "Move to previous".

=> The image wraps around all positions except the last one.

- Click repeatedly on "Move to next".

=> The image does not move anymore once it reached the last position.

[1]: https://github.com/odoo/odoo/commit/3931f0a67f904daea6c891a3a80aa984760a7682

task-2990053

X-original-commit: 054f480376e8d08d1582cedd6caec6455be828e2
Part-of: odoo/odoo#125758
2023-07-18 16:58:55 +02:00
Benjamin Vray 8423c0dd90 [FIX] web_editor, website: fix image link option broken
Since this commit [1], when clicking on an image that is not a link and
then clicking on an image that is a link, the first image that is not a
link becomes a link.

This issue occurred because we were triggering
'activate_image_link_tool' in 'toggleLinkTools' before the options for
the selected image were ready. As a result, 'activate_image_link_tool'
was being triggered on the previous image (the one that is not a link),
causing it to become a link.

To fix this, we now only trigger 'activate_image_link_tool' if the URL
input needs to be focused (e.g., when clicking on the "edit link" button
in the image popover).

Steps to reproduce the bug:
- Drag and drop a "Columns" Snippet onto the page.
- Click on the image of the first column.
- Click on the button to create a link in the options of the image.
- Type "/" in the url input.
- Click on the image of the second column.
- Click on the image of the first column.
- Click on the image of the second column.
- Bug: a link is added on the image of the second column.

This commit also modifies the "link_tools" test to avoid this bug
reappears.

[1]: https://github.com/odoo/odoo/commit/11ee7d5520c3a14a381b3f5b973114670f1e2edb

task-3422238

closes odoo/odoo#128806

X-original-commit: fef32aa339177a2ca008ab988cb0ac0a670c110c
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
2023-07-18 10:20:05 +02:00
Antoine Guenet 4f5ca706ca [FIX] web_editor: prevent removal of heading element
On a products category page, there is an element ready to host a heading
but it's not explicitly marked as unremovable so when the user tries to
remove any snippet inside it, the heading host is removed as well. This
fixes it by using the `isUnremovable` utility function instead of simply
checking for the `oe_unremovable` class.

Steps to reproduce the issue this commit fixes:
1. Go into the website module
2. Click "Shop"
3. Click "Furnitures"
4. Click "Edit"
5. Drop a title block in "Drag building blocks here to customize the
header for "Furnitures" category."
6. Click the trash bin on your snippet to remove it.

It doesn't get removed. Well now it does.

task-3383348

closes odoo/odoo#128744

X-original-commit: d1836d2830d098e2c29cca2643b0b354859daeca
Signed-off-by: Antoine Guenet (age) <age@odoo.com>
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-17 18:13:48 +02:00
Benoit Socias 8a20ae9b4a [IMP] web_editor: make all headings color only inherit from main heading
Colors of headings are inherited between levels. (E.g. if no color is
defined for `<h4>`, it uses the color of `<h3>`)

This commit changes it so that all levels only inherit from `<h1>`.

task-3140991

closes odoo/odoo#111621

Related: odoo/design-themes#633
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2023-07-17 10:40:33 +02:00
Benoit Socias f984d478e5 [IMP] *: make the shape option available only on custom buttons
*: web_editor, website_mass_mailing

Because the shape is now also part of the theme options for primary and
secondary button, it does not make sense to select it when the button
is either primary or secondary.

This commit makes the Shape option shown only for Custom buttons, and
therefore also nests it under the Style option.

task-3140991

Part-of: odoo/odoo#111621
2023-07-17 10:40:32 +02:00
Benoit Socias 388e4bb2bf [IMP] website, web_editor: relayout theme options
This commit reorganizes the theme options to make them easier to find.
It also adds the following options:
- 'Font size' for each of the six headings
- 'Font (family)' for each of the six headings
- 'Margins' (top & bottom) for paragraph & the 6 headings
- 'Line Height' for paragraph & the 6 headings
- Harmonize buttons options with the custom button ones

task-3140991

Part-of: odoo/odoo#111621
2023-07-17 10:40:31 +02:00
abd-msyukyu-odoo ffa36f5b20 [FIX] web_editor: prevent error with arrow keys whithout selection
Protect left/right arrow key handling against an empty selection (no
previous/next character to find without a selection).

Example of steps to reproduce the issue (= lose the selection while keeping the
focus):
- create such a configuration in the editable:
```html
<p [p1]><br></p>
<table>...</table>
<p [p2]><br></p>
```

- Place the cursor inside [p2] and delete the node with `CTRL + BACKSPACE`
- The cursor should have moved in the last cell of the table
- Place the cursor inside [p1]
- Start the table deletion process with `CTRL + DELETE`
- The table should be selected, as well as [p1]
- Type `DELETE` (this time without CTRL) a second time.
- The table and the paragraph are replaced by a single `<br>` node and the
  selection is lost.
- Type `LEFT/RIGHT ARROW KEY`
=> Traceback
- A paragraph is inserted again when clicking in the editable afterwards
- The isolated `<br>` node stays until it is deleted by pressing on `DELETE` in
  the last (reinserted) paragraph.

Typically, any other case where the selection is manipulated programatically and
not put back in the editable (be it through a bug, or because a target
selection has become obsolete and can not be found) would produce such a
taceback.

task-3425395

closes odoo/odoo#128631

X-original-commit: 2ee6e08f42f913e3102ca7340bb40b0203432b67
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-17 09:21:10 +02:00
abd-msyukyu-odoo 70b0731154 [FIX] web_editor: handle deletion process around nested editable
Fix `deleteBackward` and `deleteForward` processes around nested editable
zones, i.e.:
```html
<div class="odoo-editor-editable" contenteditable="true">
  <div class="nesting" contenteditable="false">
    <div "nested" contenteditable="true">
      <p>content</p>
    </div>
  </div>
</div>
```

- `deleteBackward`, when used:
  - just after the nesting element; should remove the nesting element
  - at the start of the nested element; should do nothing

- `deleteForward`, when used:
  - just before the nesting element; should remove the nesting element
  - at the end of the nested element; should do nothing

This commit also move some existing tests that were related to the handling of
non-editable elements in their correct `describe` section.

task-3425395

X-original-commit: a52deabecef8a5d489743b0ae07d4d32302fd76e
Part-of: odoo/odoo#128631
2023-07-17 09:21:10 +02:00
abd-msyukyu-odoo 2c84ff74f7 [FIX] web_editor: scope getFurthestUneditableParent in editable
This commit fixes the method so that it is not allowed to probe outside the
boundaries of the `root` editable element, no matter the value of `parentLimit`.
This also allows to not specify `parentLimit` (becomes the editable element by
default).

task-3425395

X-original-commit: ffeb1abcc675dd05fb9546e39aac4498e510bbbc
Part-of: odoo/odoo#128631
2023-07-17 09:21:10 +02:00
Robin Lejeune (role) 8de6fcb959 [FIX] web_editor: use placeholder constant on a forgotten line
The commit [b7b05a2] added a `PLACEHOLDER_TEXT` constant to consistently
change the text in `we-toggler` when no element is selected from "/" to
"None", but forgot to update one comparison.

Steps to reproduce the issue:
- Drag and drop an "Add to cart" button
=> The "Product" toggler menu shows "None" when nothing is selected.
With the updated code, it says "Choose a record...".

- Type a partial name (e.g. "desk") in the search box and press enter
=> It still shows "None".
It should select the first item available in the list. In this case with
demo data, "desk" would be "[FURN_118] Corner Desk Left Sit".

[b7b05a2]: https://github.com/odoo/odoo/commit/b7b05a2d1c1d5

task-3266751

closes odoo/odoo#128617

X-original-commit: f0f9094334e5a09b89c1fc50865c9da339d0605d
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2023-07-17 09:21:06 +02:00
Benoit Socias f8a9669c8d [FIX] web_editor: handle WEBP dropped image attachments
Since [1] dropped images are saved as attachments.
When such an image is a WEBP, its pre-computed resizes and conversions
to jpeg are not generated.

This commit adds the behavior of saving an `o_modified_image_to_save`
when a `o_b64_image_to_save` is a WEBP.

[1]: https://github.com/odoo/odoo/commit/3bbce756c69a206d07abd31059f0392c26b36096

task-2774352

Part-of: odoo/odoo#85494
2023-07-15 05:10:46 +02:00
Benoit Socias 0ba3617f9d [IMP] base, web_editor: precompute and use resized webp on upload
`libwebp` cannot be used to perform resize operations on webp images on
the server.

This commit uploads all resizes of webp images whenever a webp image is
uploaded:
- resized to any smaller size in 1024, 512, 256 & 128,
- each size converted to jpg as well to be usable in `wkhtmltopdf`.

When an Image field requires `_imageProcessing` to resize a webp image,
it retrieves the pre-resized image instead of running through the
Pillow toolbox.

Pre-converted images are stored as `ir.attachment`s with:
- `res_model` = ir.attachment
- `res_id` = id of transformed attachment
  i.e. id of original size webp for resized images
       id of webp for jpeg-converted images
- `description` = "format: image/jpeg" for jpeg conversions,
                  "resize: [size]" for resized images.

task-2774352

Part-of: odoo/odoo#85494
2023-07-15 05:10:46 +02:00
Benoit Socias c035d0003d [IMP] web_editor: upload a JPEG too when uploading a WEBP
The library used to generate PDFs does not support the WEBP image
format. For those images to be included in reports, they need to be
converted. For security reasons, this conversion cannot be done on the
server, therefore it was decided to keep an already converted copy of
such images.

This commit converts uploaded WEBP images to JPEG and uploads them both
so that the report generation can use the JPEG instead.

task-2774352

Part-of: odoo/odoo#85494
2023-07-15 05:10:45 +02:00
Benoit Socias 4d3819b221 [IMP] web_editor: replace Width option by Format option
Before this commit two options of images are named "Width":
- the one that adjusts the image resolution
- the one that changes the `width` CSS property

This commit makes the following changes:
- the option about the image resolution is renamed to "Format"
- the "Format" option combines the image resolution and the file format
- an option item gives access to the initially uploaded file format and
resolution
- for all sizes the image format is set to `image/webp`
- for the uploaded size, an `image/webp` version of it is available too
- upon upload, the default selection is an `image/webp` version of the
image

task-2774352

Part-of: odoo/odoo#85494
2023-07-15 05:10:45 +02:00
Benoit Socias d1292a96a6 [IMP] base,*: support image/webp image format
*: mail, mrp, test_website, web, web_editor

Before this commit '.webp' images could not be used in odoo.

After this commit '.webp' images can be uploaded to odoo.
- can be used in image field
- can be used in HTML field image
- can be used in mails and website
- can be transformed (shape mask, filter effect, crop, rotate, resize,
  adjust quality)

task-2774352

Part-of: odoo/odoo#85494
2023-07-15 05:10:45 +02:00
vishal padhiyar c1d42a42a1 [FIX] web_editor: link with / not recognized
Before this commit:

When user try to create link with / it is not recognized as a link.

After this commit:

Now when user try to create link with  /  it is recognized as a link.

Task-3347775

closes odoo/odoo#127842

X-original-commit: e99ccfa1ed7aa338f99c4142d109b2860cc9be4a
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-15 04:01:06 +02:00
Benoit Socias bbd1a48083 [FIX] web_editor, website: use theme colors on shapes in options panel
Since the edited website pages are inside an iframe, the options panel
cannot base its display on the CSS rules of the page. When changing the
theme colors, only the edited page's CSS is reloaded, not the option
one. Because of this, the background shapes are displayed using an
obsolete color palette inside the options panel.
This causes colors to be forced on background shapes within the iframe
because their default colors do not match the ones inside the options
panel when different theme colors are set. Once forced, the colors of
the background shapes within the content do not follow the theme
palette changes anymore.

This commit forces the background shapes displayed in the options panel
to use the current palette.
This is done by recovering the current edited page's shape background
images from the CSS rules. This approach was chosen as opposed to
adding a `d-none` version of the shape `div` to the edited page and
getting the background image from its computed style.
This fixes the color comparison between the background shapes of the
content and the ones of the options panel, thus not forcing colors if
the theme colors are used.

Steps to reproduce:
- Edit a website page.
- Drop a "Banner" block.
- Enable background shapes.
- Go to the theme tab.
- Select a different theme color palette.
- Select the "Banner" block.
- Open the "Shape" option's menu.

=> The shapes were displayed with the old color palette and if selected
were applied with the old color palette.

Additionally, to avoid a race condition when leaving a theme color
picker by either clicking on the BLOCKS tab or re-selecting the
snippet with a shape, a re-rendering of the existing snippet editors
is requested and the shape cache is invalidated if the palette has
changed in the meantime.

task-3370939

closes odoo/odoo#127951

X-original-commit: c511e100cad2febc0ebb9ce61b5eb52232e60f7d
Signed-off-by: Soukéina Bojabza (sobo) <sobo@odoo.com>
2023-07-12 07:39:51 +02:00
Lucas Perais 4d61085348 [FIX] web_editor: wysiwyg coherent API
Before this commit the function getContentEditableAreas passed in options
was not correctly called.

The OdooEditor which receives it too passes itself to it.

This commit corrects the call in Wysiwyg to that function and passes the odooEditor instance

Part-of: odoo/odoo#126963
2023-07-12 03:48:49 +02:00
Lucas Perais a38fd5eb2c [FIX] web_editor: html_field QWeb styling with specific class
Before this commit, whenever some nodes had some attributes similar
to QWeb (t-if, t-else, t-out etc....) the QWebPlugin's style applied.

This was unpractical when that style needed to be customized.

After this commit, the HtmlField add a class signaling that it should apply that style.

Part-of: odoo/odoo#126963
2023-07-12 03:48:49 +02:00
Lucas Perais 04b844550b [FIX] web_editor: wysiwyg color error resilient
When popping the color selector of the wysiwyg, sometimes the OdooEditor
returns an error code instead of a list of elements.
In that case, the code crashed as it expected a list (implicitly, by calling Array methods)

This commit accounts for that and tests whether the return is an Array.

Part-of: odoo/odoo#126963
2023-07-12 03:48:49 +02:00
Rodolpho Lima 17cd7fcd6d [FIX] web_editor: comment about transforming URL inside link
The previous comment referenced in this commit is no longer reflects
the code section that follows it, as it has undergone modifications in a
previous commit [1]. The code segment responsible for pasting image and
video has been relocated and is no longer positioned beneath the
comment, rendering it obsolete.

The comment has been reworded to accurately reflect the content of the
code section that follows.

[1]: https://github.com/odoo/odoo/commit/e53962594c5baaa6d644161fef7e314497dc190f

closes odoo/odoo#128025

X-original-commit: 7929389a1c2f9e6cfdf34de813abc6f8c90b8371
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-11 09:10:31 +02:00
Rodolpho Lima ec302e06d0 [FIX] web_editor: line breaks pasted as BR
Before this commit, when pasting the clipboard content as plain text
(CTRL+SHIFT+V), line breaks ('\n') got converted to `<br>` elements.
This made the behaviour of the pasted section inconsistent with the
other parts of the edited document, in which line breaks are obtained
via paragraphs (`<p>`). In particular, when converting the pasted
content to a list, the whole multi-line content would be added to a
single list item, instead of one item per line.

This commit makes sure pasted line breaks result in new paragraphs.

task-3323873

X-original-commit: 18026ed2d4efaa6323e38b53eced77b1db666453
Part-of: odoo/odoo#128025
2023-07-11 09:10:30 +02:00
Benoit Socias 62bdd7adae [IMP] website, web_editor: placeholder in empty sanitized HTML fields
When an HTML field is empty and no block can be dropped inside it, it
is very difficult to locate or even notice.

This commit adds a placeholder text inside sanitized HTML fields.

Steps to reproduce:
- Install website_crm_partner_assign.
- Go to a contact without website description.
- Go to its website page.
- Edit page.

=> The `partner.website_description` field is difficult to locate.

task-3293600

closes odoo/odoo#120588

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-07-11 03:35:39 +02:00
Benoit Socias 1bf2a891dd [IMP] *: make HTML fields with sanitized attributes edited as text-only
*: web_editor

When an HTML field sanitizes its attributes, it can still be filled with
HTML content (blocks, styling, power box commands) using the website
builder. This causes problems because those elements can then be broken
by the sanitizing.
It is possible to break elements so badly that the page cannot be
edited anymore to fix the problem.

This commit prevents the user from dropping snippet blocks inside the
content of such fields.

Steps to reproduce:
(Unless `slide.slide`'s `description` becomes
`sanitize_attributes=False` in the meantime.)
- Edit a single Course's slide.
- Drop a Carousel into the description field at the bottom.
- Save.

=> Carousel did not work.

Worse:
- Instead of the Carousel, drop a Countdown.

=> An error happens on each page reload, and the edit mode cannot be
reached anymore.

task-3293600

Part-of: odoo/odoo#120588
2023-07-11 03:35:39 +02:00
abd-msyukyu-odoo 4c111c1324 [FIX] web_editor: properly close all connections during PTP stop
Ensure to close all connections before setting the flag that prevents any
notification (notably the notification to disconnect).

task-3392096

closes odoo/odoo#127953

X-original-commit: 905307e8d08ed3595a1f965fe846f1fe6ebe9d5c
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-10 16:59:58 +02:00
Romain Derie a1aa2db7c5 [FIX] web_editor: avoid fetching optimized images which can't be shown
Before this commit, when opening the media dialog, the optimized images
would be fetched too.
An optimized image is an image related to an original one which received
some modification (crop etc).
Those optimized images are hidden by default, and can only be shown when
toggling the "Show optimized" option, which can be shown only in debug
mode.

So, fetching those images outside debug mode is:
1. Useless, as we don't do anything with those and never show them
2. Buggy sometimes, as a full patch of "Load more" images could be
   composed of only optimized images, meaning the "load more" will
   actually look like it did nothing, as all received images are (and
   will remain) hidden.

There is a tiny exception: if the edited image is an optimized one, we
still need to fetch it's attachment so we can show this image in the
media dialog as selected.

This fix thus filter out all the optimized images (except the one from
the explained exception) from the `search_read()`.

opw-3372811

closes odoo/odoo#127853

X-original-commit: 24177b5e2b56a94a51ac4b922d555beda9347611
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-07-10 16:59:18 +02:00
Antoine Guenet e47bc1115f [FIX] web_editor: prevent traceback on convert single-col align stretch
When converting a row with items that are supposed to be stretch-aligned
we need to set each of its column's height. However this failed when
the row contained less than two columns.

opw-3371134

closes odoo/odoo#127813

X-original-commit: 7df4cc0d9aaccf0dabcc4a7863549b276efaa403
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-10 15:32:53 +02:00
Deependra Solanki 6b09924147 [FIX] web_editor: change icon of table menu
Before this commit:

- The icon of table menu is fa-bars which looks like drag 'n' drop handle.
- Menu width is not 100%.

After this commit:

- Changed the icons to fa-ellipsis-h and fa-ellipsis-v.
- Made the menu 100% width so it's easier to intuit it's not a drag 'n'
  drop handle.

Task - 3297710

closes odoo/odoo#127843

X-original-commit: 479c0a87b0b676f5fa9252efdef3ede99f6d7ea7
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2023-07-10 14:08:37 +02:00
divy-odoo f645d28d0d [FIX] web_editor: prevent losing text-gradient class on gradient preview
Steps to reproduce:

- Drop a Title block in a webpage.
- Select text.
- Set the text color to a custom gradient. (Not the background color)
- Hover a gradient preset.
- Leave the gradient preset.
gradient color applied on the background.

In this commit,
1. Modified the condition which was blocking some mutations from being
   processed. Before this commit condition got executed successfully on an empty
   array(`excludedClasses`) too, which should not be.
2. Introduced new tests which were breaking before this commit to preventing
   them from breaking in the future.

task-3120090

closes odoo/odoo#127810

X-original-commit: 994fe756db8f1a45ef864cb7848644ea204539b7
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Signed-off-by: Divyesh Vyas (divy) <divy@odoo.com>
2023-07-10 06:34:39 +02:00
Robin Lejeune (role) e200eb2813 [FIX] website_editor: use background image on the right element
Commit [1] addressed the following situation: when we have a parallax on
an element, it adds the background on a `<span>` child of said element
instead of applying it directly on the element. Retargeting the `<span>`
is needed to display all the options linked to the background image.

Following [1], building blocks whose children are allowed to have a
background image are also applied their 1st child's background when one
of their children's background is modified. This happens because, when
changing the background of a child item, `BackgroundOptimize` is called
both on the child and on the main snippet due to
`_onBackgroundChanged()` bubbling up and `_loadImageInfo()` targetting
any child in the tree with the class `.oe_img_bg`.

This commit prevents `_onBackgroundChanged()` from bubbling up and
modifies the behavior from [1] by making sure the element identified as
the target within `_loadImageInfo()` can only be either the original
target or the parallax element.

Steps to reproduce:
- Drop a carousel building block
- Change its style to bordered
- Change the background image of the 2nd slide
=> the background of the entire snippet is also changed. It is then
impossible to remove the image on the snippet.

[1]: https://github.com/odoo/odoo/commit/31ba906

task-3349669

closes odoo/odoo#127756

X-original-commit: ab0ae8dadf55baa258d733835acc3a12771932be
Signed-off-by: Outagant Mehdi (mou) <mou@odoo.com>
2023-07-07 17:57:55 +02:00
Robin Lejeune (role) e9096a3844 [FIX] web_editor: allow translations of hidden blocks
Steps to reproduce:
- Drop a block, hide it on desktop and save
- Add a second language and click on translate
=> This raises an error.

The bug happened after the forward-port of [1] to 16.3, because
`_updateInvisibleDOM` was called prior to `_loadSnippetsTemplates`: it
then tried to `_createSnippetEditor`, requiring `templateOptions` while
they were still undefined.

opw-3383659

[1]: https://github.com/odoo/odoo/commit/959ea3d361f

closes odoo/odoo#127139

X-original-commit: c92ea9f10cdd38b275157e1ba7e79b84e3e45cbb
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-07-07 17:57:42 +02:00
shsa-odoo bbc0b10778 [FIX] web_editor: emojipicker must be grouped together with widgets
Before this commit:

EmojiPicker was in separate group as widget.

After this commit:

EmojiPicker should be grouped together.

task-3414175

closes odoo/odoo#127561

Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
2023-07-06 17:52:39 +02:00
Sanjay-Sharma 4f6a92e684 [IMP] web_editor: add emoji picker in web editor
Purpose:

This commit adds Emoji_picker functionality to the web_editor,
allowing users to conveniently add emojis to their text and
improving the overall user experience.

Specifications:

Now we can insert emoji in web_editor using `/emoji`.

Task id: 3253958

closes odoo/odoo#125137

Related: odoo/enterprise#42772
Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
2023-07-05 11:37:06 +02:00
Soukéina Bojabza b2bf8c62a1 [FIX] web_editor: re-allow hiding column count widget if specified class
When the `s_nb_column_fixed` class is present on the row, it should not
be possible to change the number of columns in the "Columns" option (the
option is supposed to be hidden).

However, since commit [1], this behavior is broken. It happened because
the "Columns" option needs to always be displayed in order to display
correctly the "Grid" option and this class was therefore ignored.

This commit restores this class behavior by hiding only the widget
changing the number of columns and not the complete "Columns" option, in
order to still be able to toggle between the grid and the normal modes.

[1]: https://github.com/odoo/odoo/commit/84d684d8bdf43d3db11defd8174dee44775085c2

task-3369847

closes odoo/odoo#127144

X-original-commit: 8148521f052268877f36947e0533843a25d17b83
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2023-07-04 14:02:25 +02:00
Benoit Socias 943944dd24 [IMP] web_editor, website_slides: keep data when adding URL attachments
When a URL is entered to add an attachment through the media dialog
a URL attachment is created. If the source material is removed the
attachment will not be reachable anymore.

This commit fetches the data and adds it as an uploaded file when
adding a URL image in website.
If the image binary cannot be fetched by the client (e.g. CORS), the
old approach is used instead.

This commit also adapts test tours which relied on the image's `src` to
verify if the entered URL had been taken into account by making them
rely on the image's `data-original-src` instead.

task-3129360

closes odoo/odoo#118877

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-07-04 14:02:20 +02:00
Benjamin Vray 7ee6d9ff2f [FIX] web, website, web_editor: fix popup scrollbar
Steps to reproduce the bug:

- Drag and drop several snippets onto a web page in edit mode to make
the vertical scrollbar appear.
- Drag and drop a popup onto the page.
- Drag and drop snippets into the popup so that the height of the popup
exceeds the height of the viewport.
- Try to scroll the popup downwards by clicking and dragging on the
scrollbar (not using the mouse wheel).
- Bug: the page is scrolled instead of the popup.

Note: This bug occurs in Chrome (not in Firefox).

This issue occurs because two scrollbars are present at the same
location (one for the page and one for the popup) and they overlap each
other. Normally, Bootstrap removes the scrollbar from the body when a
modal is opened, and this behavior was adapted for the #wrapwrap element
with this commit [1]. However, when transitioning to Bootstrap 5, the
code that overrides Bootstrap was removed instead of being adapted (this
was done in this commit [2]).

In later commits [3] and [4], we continued to remove code that updated
the scrollbar based on the opening of a modal because this code was
causing errors due to the fact that it was incomplete without the part
removed by commit [2].

This commit restores the original behavior (before the deletions made by
the aforementioned commits) by restoring the missing code and properly
adapting it to Bootstrap 5.

[1]: https://github.com/odoo/odoo/commit/9cf8b97fe40444b44ebb6e6fb992bc658a087d32
[2]: https://github.com/odoo/odoo/commit/0b94da214b7017e8580e671cbaa68ade6de2fbc7
[3]: https://github.com/odoo/odoo/commit/cb7cf77ed080e86f800af61c9a3dc4ad36ad6cfb
[4]: https://github.com/odoo/odoo/commit/51939d09f84579f61f1ff77aacd754beba036dc2

task-3102275

closes odoo/odoo#126709

X-original-commit: 0e75f1c01ca4fcc3eb483a7256bcf72b2bca39c3
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
2023-06-30 00:20:47 +02:00
Rodolpho Lima fd63a53fcd [FIX] web_editor: toolbar glitch when selecting media
The code snippet removed by this commit had no useful effect, as
`selection.addRange(range)` a few line above triggers
`OdooEditor._onSelectionChange`, which repositions the toolbar
elsewhere.

The result was a "glitch": the toolbar would briefly be displayed over
the top left corner of the media before finally being displayed above
(or below) it.

This commit removes such undesirable effect.

task-3347942

closes odoo/odoo#126445

X-original-commit: f0272411f6cab059cc8bc2ceed37d9ce59ffe80c
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Signed-off-by: Nicolas Bayet (nby) <nby@odoo.com>
Signed-off-by: Rodolpho Cammarosano de Lima (rcdl) <rcdl@odoo.com>
2023-06-26 22:15:47 +02:00