Skip to content

Commit

Permalink
[FIX] website, *: do not observe changes of drag and drop initialization
Browse files Browse the repository at this point in the history
*: web_editor

Commit [1] made the multiple drag and drop feature of the editor stop
using jQuery and used our own implementation. Unfortunately, the
initialization of that implementation in the case of the "drag column
on image move" feature marked the page as dirty by mistake.

Steps to reproduce:
- Enter edit mode
- Add a "Text - Image" snippet
- Save
- Enter edit mode again
- Click on the image of the snippet (and do not do anything else)
- Click on discard
=> A popup appears to say you will lose your changes... while you did
   not make any.

[1]: odoo@7594d71

Related to runbot-18747

Part-of: odoo#148728
  • Loading branch information
qsm-odoo committed Jan 10, 2024
1 parent 6941af6 commit 32a6729
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions addons/web_editor/static/src/js/editor/drag_and_drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export function useNativeDraggable(hookParams, initialParams) {
};
// Compatibility for tests
const el = initialParams.ref.el;
// TODO this is probably to be removed in master: the received params
// contain the selector that should be checked and it will be transferred
// to the makeDraggableHook function. There should not be any need to add
// the default selector class here.
el.classList.add("o_draggable");
cleanupFunctions.push(() => el.classList.remove("o_draggable"));

Expand Down
6 changes: 6 additions & 0 deletions addons/web_editor/static/src/js/editor/snippets.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ var SnippetEditor = Widget.extend({
this.draggableComponent = this._initDragAndDrop(".o_move_handle", ".oe_overlay", this.el);
if (!this.$target[0].matches("section")) {
// Allow the user to drag the image itself to move the target.
// Note that the o_draggable class will be added by the
// _initDragAndDrop function. So adding it here is probably
// useless. To check. The fact that that class is added in any
// case should probably reviewed in master anyway (TODO).
this.options.wysiwyg.odooEditor.observerUnactive('image_drag_and_drop');
this.$target[0].classList.add("o_draggable");
this.draggableComponentImgs = this._initDragAndDrop("img", ".o_draggable", this.$target[0]);
this.options.wysiwyg.odooEditor.observerActive('image_drag_and_drop');
}
} else {
this.$('.o_overlay_move_options').addClass('d-none');
Expand Down
31 changes: 24 additions & 7 deletions addons/website/static/tests/tours/website_no_dirty_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import wTourUtils from '@website/js/tours/tour_utils';

wTourUtils.registerWebsitePreviewTour('website_no_dirty_page', {
test: true,
url: '/',
edition: true,
}, () => [
const makeSteps = (steps = []) => [
wTourUtils.dragNDrop({
id: "s_text_image",
name: "Text - Image",
Expand All @@ -25,7 +21,9 @@ wTourUtils.registerWebsitePreviewTour('website_no_dirty_page', {
content: "Confirm we are in edit mode",
trigger: 'body.editor_has_snippets',
run: () => null,
}, {
},
...steps,
{
// Makes sure the dirty flag does not happen after a setTimeout or
// something like that.
content: "Click elsewhere and wait for a few ms",
Expand All @@ -43,4 +41,23 @@ wTourUtils.registerWebsitePreviewTour('website_no_dirty_page', {
trigger: 'body:not(.editor_has_snippets)',
run: () => null,
},
]);
];

wTourUtils.registerWebsitePreviewTour('website_no_action_no_dirty_page', {
test: true,
url: '/',
edition: true,
}, () => makeSteps());

wTourUtils.registerWebsitePreviewTour('website_no_dirty_page', {
test: true,
url: '/',
edition: true,
}, () => makeSteps([
{
// This has been known to mark the page as dirty because of the "drag
// the column on image move" feature.
content: "Click on default image",
trigger: 'iframe .s_text_image img',
},
]));
2 changes: 1 addition & 1 deletion addons/website/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def test_website_extra_items_no_dirty_page(self):
'parent_id': website.menu_id.id,
})

self.start_tour('/', 'website_no_dirty_page', login='admin')
self.start_tour('/', 'website_no_action_no_dirty_page', login='admin')

def test_website_no_dirty_page(self):
# Previous tests are testing the dirty behavior when the extra items
Expand Down

0 comments on commit 32a6729

Please sign in to comment.