From 84d867dbacda744c3543da9d5f8483369e3276ff Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Fri, 29 Apr 2022 10:44:03 +0200 Subject: [PATCH] [IMP] website, web_editor: add customize_show views to editor panel After this commit, the customize_show views are automatically added in the editor panel as page options in the "customize" tab. Most of the customize_show views have been replaced by snippets options but for some it was better to keep an auto population system so as not to have to create too many bridge modules when it's not worth it (e.g. My Portal page). See merge commit for more information. task-2710582 --- .../static/src/js/editor/snippets.editor.js | 3 ++ .../static/src/js/editor/snippets.editor.js | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 36321199aa5..98fd7ba4e8a 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -405,6 +405,9 @@ var SnippetEditor = Widget.extend({ if (this.$target.parent('.row').length) { return _t("Column"); } + if (this.$target.is('#wrapwrap > main')) { + return _t("Page Options"); + } return _t("Block"); }, /** diff --git a/addons/website/static/src/js/editor/snippets.editor.js b/addons/website/static/src/js/editor/snippets.editor.js index ab0e3b83791..f8bd3da2ae7 100644 --- a/addons/website/static/src/js/editor/snippets.editor.js +++ b/addons/website/static/src/js/editor/snippets.editor.js @@ -53,6 +53,43 @@ weSnippetEditor.SnippetsMenu.include({ document.body.classList.remove('o_animated_text_highlighted'); }, + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Adds the "customize_show" templates to the options page of the editor + * panel. + * + * @override + */ + async loadSnippets() { + const viewName = $(this.options.wysiwyg.odooEditor.document.documentElement).data('view-xmlid'); + const snippets = await this._super(...arguments); + if (!viewName) { + return snippets; + } + const $snippets = $(snippets); + return this._rpc({ + route: '/website/get_switchable_related_views', + params: { + key: viewName, + }, + }).then(function (result) { + _.each(result, view => { + $snippets.siblings('#snippet_options').append($(` +
+ +
+ `)); + }); + return $('
').append($snippets).html(); + }); + }, + //-------------------------------------------------------------------------- // Private //--------------------------------------------------------------------------