diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index bbe193c813e..3afe536d009 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -6692,6 +6692,31 @@ registry.SelectTemplate = SnippetOptionWidget.extend({ } }, + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Retrieves a template either from cache or through RPC. + * + * @private + * @param {string} xmlid + * @returns {string} + */ + async _getTemplate(xmlid) { + if (!this._templates[xmlid]) { + this._templates[xmlid] = await this._rpc({ + model: 'ir.ui.view', + method: 'render_public_asset', + args: [`${xmlid}`, {}], + kwargs: { + context: this.options.context, + }, + }); + } + return this._templates[xmlid]; + }, + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- @@ -6712,14 +6737,7 @@ registry.SelectTemplate = SnippetOptionWidget.extend({ // TODO should be better and retrieve all rendering in one RPC (but // those ~10 RPC are only done once per edit mode if the option is // opened, so I guess this is acceptable). - this._templates[xmlid] = await this._rpc({ - model: 'ir.ui.view', - method: 'render_public_asset', - args: [`${xmlid}`, {}], - kwargs: { - context: this.options.context, - }, - }); + await this._getTemplate(xmlid); }); this._templatesLoading = Promise.all(proms); }, diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 42a5e2c8d56..2e027666c6b 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -3269,6 +3269,25 @@ options.registry.MegaMenuLayout = options.registry.SelectTemplate.extend({ this.selectTemplateWidgetName = 'mega_menu_template_opt'; }, + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * @override + */ + notify(name, data) { + if (name === 'reset_template') { + const xmlid = this._getCurrentTemplateXMLID(); + this._getTemplate(xmlid).then(template => { + this.containerEl.insertAdjacentHTML('beforeend', template); + data.onSuccess(); + }); + } else { + this._super(...arguments); + } + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -3278,12 +3297,41 @@ options.registry.MegaMenuLayout = options.registry.SelectTemplate.extend({ */ _computeWidgetState: function (methodName, params) { if (methodName === 'selectTemplate') { - const templateDefiningClass = this.containerEl.querySelector('section') - .classList.value.split(' ').filter(cl => cl.startsWith('s_mega_menu'))[0]; - return `website.${templateDefiningClass}`; + return this._getCurrentTemplateXMLID(); } return this._super(...arguments); }, + /** + * @private + * @returns {string} xmlid of the current template. + */ + _getCurrentTemplateXMLID: function () { + const templateDefiningClass = this.containerEl.querySelector('section') + .classList.value.split(' ').filter(cl => cl.startsWith('s_mega_menu'))[0]; + return `website.${templateDefiningClass}`; + }, +}); + +/** + * Hides delete button for Mega Menu block. + */ +options.registry.MegaMenuNoDelete = options.Class.extend({ + forceNoDeleteButton: true, + + /** + * @override + */ + async onRemove() { + await new Promise(resolve => { + this.trigger_up('option_update', { + optionName: 'MegaMenuLayout', + name: 'reset_template', + data: { + onSuccess: () => resolve(), + } + }); + }); + }, }); return { diff --git a/addons/website/views/snippets/snippets.xml b/addons/website/views/snippets/snippets.xml index 600419a2624..9c6fe2bc6a2 100644 --- a/addons/website/views/snippets/snippets.xml +++ b/addons/website/views/snippets/snippets.xml @@ -1030,6 +1030,8 @@ +
+