[FIX] mass_mailing: multiple toolbar instances
Before this commit, multiple toolbar instances would be created when switching between records via the form view pager. This commit fixes the issue by using and properly setting up the existing Toolbar child component, without the need to instantiate a new one. It also removes this module's dependency on the legacy ComponentWrapper. task-3495685 closes odoo/odoo#144802 Signed-off-by: Nicolas Bayet (nby) <nby@odoo.com>
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { loadBundle } from "@web/core/assets";
|
||||
import { attachComponent } from "@web/legacy/utils";
|
||||
import { Wysiwyg } from "@web_editor/js/wysiwyg/wysiwyg";
|
||||
import { closestElement } from "@web_editor/js/editor/odoo-editor/src/OdooEditor";
|
||||
import { Toolbar } from "@web_editor/js/editor/toolbar";
|
||||
import "@web_editor/js/wysiwyg/wysiwyg_iframe";
|
||||
|
||||
export class MassMailingWysiwyg extends Wysiwyg {
|
||||
@@ -13,6 +11,11 @@ export class MassMailingWysiwyg extends Wysiwyg {
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
async startEdition() {
|
||||
// The initial toolbar of the Wysiwyg component will be used as the
|
||||
// mainToolbar (sticky on mobile and floating on desktop).
|
||||
this.mainToolbarEl = this.toolbarRef.el.firstChild;
|
||||
this.mainToolbarEl.classList.add('d-none');
|
||||
|
||||
const res = await super.startEdition(...arguments);
|
||||
// Prevent selection change outside of snippets.
|
||||
this.$editable.on('mousedown', e => {
|
||||
@@ -38,48 +41,33 @@ export class MassMailingWysiwyg extends Wysiwyg {
|
||||
|
||||
/**
|
||||
* Sets SnippetsMenu fold state and switches toolbar.
|
||||
* Instantiates a new floating Toolbar if needed.
|
||||
* Configures the main toolbar if needed.
|
||||
*
|
||||
* @param {Boolean} fold
|
||||
*/
|
||||
async setSnippetsMenuFolded(fold = true) {
|
||||
if (fold) {
|
||||
this.snippetsMenu.setFolded(true);
|
||||
if (!this.floatingToolbar) {
|
||||
// The wysiwyg can be instanciated inside an iframe. The dialog
|
||||
// component is mounted on the global document.
|
||||
const toolbarWrapperElement = document.createElement('div');
|
||||
toolbarWrapperElement.style.display = 'contents';
|
||||
document.body.append(toolbarWrapperElement);
|
||||
// Instantiate and configure new toolbar.
|
||||
await attachComponent({}, toolbarWrapperElement, Toolbar, this.state.toolbarProps);
|
||||
this.toolbarEl = toolbarWrapperElement.firstChild;
|
||||
this.floatingToolbarEl = this.toolbarEl;
|
||||
|
||||
this._configureToolbar({ snippets: false });
|
||||
this._updateEditorUI();
|
||||
this.setCSSVariables(this.toolbarEl);
|
||||
this.odooEditor.setupToolbar(this.toolbarEl);
|
||||
if (this.odooEditor.isMobile) {
|
||||
document.body.querySelector('.o_mail_body').prepend(this.toolbarEl);
|
||||
} else {
|
||||
document.body.append(this.toolbarEl);
|
||||
}
|
||||
setSnippetsMenuFolded(fold = true) {
|
||||
this.snippetsMenu.setFolded(fold);
|
||||
this.toolbarEl = fold ? this.mainToolbarEl : this.snippetsMenuToolbarEl;
|
||||
// At startup, the `SnippetMenu` set its toolbar before the
|
||||
// `mainToolbarEl` had the chance to be configured. So we configure it
|
||||
// now if we need it.
|
||||
if (fold && !this._isMainToolbarReady) {
|
||||
// Setup toolbar.
|
||||
this._configureToolbar({ snippets: false });
|
||||
this._updateEditorUI();
|
||||
this.setCSSVariables(this.toolbarEl);
|
||||
// Position the toolbar element.
|
||||
if (this.odooEditor.isMobile) {
|
||||
document.body.querySelector('.o_mail_body').prepend(this.toolbarEl);
|
||||
} else {
|
||||
this.toolbarEl = this.floatingToolbarEl;
|
||||
}
|
||||
this.toolbarEl.classList.remove('d-none');
|
||||
this.odooEditor.autohideToolbar = true;
|
||||
this.odooEditor.toolbarHide();
|
||||
} else {
|
||||
this.snippetsMenu.setFolded(false);
|
||||
this.toolbarEl = this.snippetsMenuToolbarEl;
|
||||
|
||||
this.odooEditor.autohideToolbar = false;
|
||||
if (this.floatingToolbarEl) {
|
||||
this.floatingToolbarEl.classList.add('d-none');
|
||||
document.body.append(this.toolbarEl);
|
||||
}
|
||||
this._isMainToolbarReady = true;
|
||||
}
|
||||
this.odooEditor.toolbar = this.toolbarEl;
|
||||
this.odooEditor.autohideToolbar = !!fold;
|
||||
this.odooEditor.toolbarHide();
|
||||
this.mainToolbarEl.classList.toggle('d-none', !fold);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1895,7 +1895,7 @@ var SnippetsMenu = Widget.extend({
|
||||
|
||||
const toolbarEl = this._toolbarWrapperEl.firstChild;
|
||||
toolbarEl.classList.remove('oe-floating');
|
||||
this.options.wysiwyg.toolbarEl.style.display = 'none';
|
||||
this.options.wysiwyg.toolbarEl.classList.add('d-none');
|
||||
this.options.wysiwyg.setupToolbar(toolbarEl);
|
||||
this._addToolbar();
|
||||
this._checkEditorToolbarVisibilityCallback = this._checkEditorToolbarVisibility.bind(this);
|
||||
|
||||
Reference in New Issue
Block a user