diff --git a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js index fde6edec486..8c2a67a66f6 100644 --- a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js +++ b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js @@ -619,6 +619,37 @@ export class WysiwygAdapterComponent extends ComponentAdapter { return this.props.quitCallback(); } } + /** + * Called when a snippet is about to be cloned in the page. Notifies the + * WebsiteRoot that it should stop the public widgets inside that snippet. + * + * @private + * @param {OdooEvent} ev + */ + _onSnippetWillBeCloned(ev) { + this._websiteRootEvent('widgets_stop_request', { + $target: ev.data.$target, + }); + } + /** + * Called when a snippet is cloned in the page. Notifies the WebsiteRoot + * that it should start the public widgets for this snippet and the snippet it + * was cloned from. + * + * @private + * @param {OdooEvent} ev + */ + _onSnippetCloned(ev) { + this._websiteRootEvent('widgets_start_request', { + editableMode: true, + $target: ev.data.$target, + }); + + this._websiteRootEvent('widgets_start_request', { + editableMode: true, + $target: ev.data.$origin, + }); + } /*** * Starts the widgets inside the dropped snippet. * @@ -732,6 +763,8 @@ WysiwygAdapterComponent.prototype.events = { 'context_get': '_onContextGet', 'action_demand': '_handleAction', 'request_cancel': '_onCancelRequest', + 'snippet_will_be_cloned': '_onSnippetWillBeCloned', + 'snippet_cloned': '_onSnippetCloned', 'snippet_dropped': '_onSnippetDropped', 'snippet_removed': '_onSnippetRemoved', 'reload_bundles': '_reloadBundles', diff --git a/addons/website/static/tests/tours/start_cloned_snippet.js b/addons/website/static/tests/tours/start_cloned_snippet.js new file mode 100644 index 00000000000..d077f7a277c --- /dev/null +++ b/addons/website/static/tests/tours/start_cloned_snippet.js @@ -0,0 +1,33 @@ +/** @odoo-module **/ + +import wTourUtils from 'website.tour_utils'; + +const countdownSnippet = { + name: 'Countdown', + id: 's_countdown', +}; +const dragNDropOutOfFooter = wTourUtils.dragNDrop(countdownSnippet); +dragNDropOutOfFooter.run = 'drag_and_drop iframe #wrapwrap #wrap'; + +wTourUtils.registerEditionTour('website_start_cloned_snippet', { + edition: true, + test: true, + url: '/', +}, [ + dragNDropOutOfFooter, + wTourUtils.clickOnSnippet(countdownSnippet), + { + content: 'Click on clone snippet', + trigger: '.oe_snippet_clone', + }, + { + content: 'Check that the cloned snippet has a canvas and that something has been drawn inside of it', + trigger: 'iframe .s_countdown:eq(1) canvas', + run: function () { + // Check that at least one bit has been drawn in the canvas + if (!this.$anchor[0].getContext('2d').getImageData(0, 0, 1000, 1000).data.includes(1)) { + console.error('The cloned snippet should have been started'); + } + }, + }, +]); diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index 79f98356abc..e1a142046e8 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -308,3 +308,6 @@ class TestUi(odoo.tests.HttpCase): def test_20_snippet_editor_panel_options(self): self.start_tour("/@/?enable_editor=1", "snippet_editor_panel_options", login="admin") + + def test_21_website_start_cloned_snippet(self): + self.start_tour('/web', 'website_start_cloned_snippet', login='admin')