[FIX] web_editor, *: allow editor dialogs in simple HTML areas
* website_forum Summernote is instantiated as a simple text editor for 'simple' HTML backend fields and in website_forum. In those cases, the user was not able to open editor dialogs anymore as their opening was now handled by the RTE widget in web_editor since the recent website refactoring. The goal was to use `this._rpc` in these dialogs (and this required the dialogs to be attached to the widget parenting system). As a fix, a new component was implemented to handle these dialog openings and this component is thus created by the RTE widget and the other places that need the feature. The right fix would be a better integration of the summernote editor in the parenting system but this requires a lot more work than this commit, this will be the goal of the future editor refactoring.
This commit is contained in:
@@ -7,6 +7,7 @@ var config = require('web.config');
|
||||
var core = require('web.core');
|
||||
var session = require('web.session');
|
||||
var field_registry = require('web.field_registry');
|
||||
var SummernoteManager = require('web_editor.rte.summernote');
|
||||
var transcoder = require('web_editor.transcoder');
|
||||
|
||||
var TranslatableFieldMixin = basic_fields.TranslatableFieldMixin;
|
||||
@@ -25,6 +26,14 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMi
|
||||
className: 'oe_form_field oe_form_field_html_text',
|
||||
supportedFieldTypes: ['html'],
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
start: function () {
|
||||
new SummernoteManager(this);
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -269,10 +269,6 @@ var RTEWidget = Widget.extend({
|
||||
|
||||
$.fn.carousel = this.edit_bootstrap_carousel;
|
||||
|
||||
core.bus.on('alt_dialog_demand', this, this._onAltDialogDemand);
|
||||
core.bus.on('link_dialog_demand', this, this._onLinkDialogDemand);
|
||||
core.bus.on('media_dialog_demand', this, this._onMediaDialogDemand);
|
||||
|
||||
$(document).on('mousedown.rte activate.rte', this, this._onMousedown.bind(this));
|
||||
$(document).on('mouseup.rte', this, this._onMouseup.bind(this));
|
||||
|
||||
@@ -342,10 +338,6 @@ var RTEWidget = Widget.extend({
|
||||
|
||||
$.fn.carousel = this.init_bootstrap_carousel;
|
||||
|
||||
core.bus.off('alt_dialog_demand', this, this._onAltDialogDemand);
|
||||
core.bus.off('link_dialog_demand', this, this._onLinkDialogDemand);
|
||||
core.bus.off('media_dialog_demand', this, this._onMediaDialogDemand);
|
||||
|
||||
$(document).off('.rte');
|
||||
$('#wrapwrap, .o_editable').off('.rte');
|
||||
|
||||
@@ -566,66 +558,6 @@ var RTEWidget = Widget.extend({
|
||||
_onClick: function (e) {
|
||||
e.preventDefault();
|
||||
},
|
||||
/**
|
||||
* Called when a demand to open a alt dialog is received on the bus.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} data
|
||||
*/
|
||||
_onAltDialogDemand: function (data) {
|
||||
var altDialog = new weWidgets.alt(this,
|
||||
data.options || {},
|
||||
data.$editable,
|
||||
data.media
|
||||
);
|
||||
if (data.onSave) {
|
||||
altDialog.on('save', this, data.onSave);
|
||||
}
|
||||
if (data.onCancel) {
|
||||
altDialog.on('cancel', this, data.onCancel);
|
||||
}
|
||||
altDialog.open();
|
||||
},
|
||||
/**
|
||||
* Called when a demand to open a link dialog is received on the bus.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} data
|
||||
*/
|
||||
_onLinkDialogDemand: function (data) {
|
||||
var linkDialog = new weWidgets.LinkDialog(this,
|
||||
data.options || {},
|
||||
data.$editable,
|
||||
data.linkInfo
|
||||
);
|
||||
if (data.onSave) {
|
||||
linkDialog.on('save', this, data.onSave);
|
||||
}
|
||||
if (data.onCancel) {
|
||||
linkDialog.on('cancel', this, data.onCancel);
|
||||
}
|
||||
linkDialog.open();
|
||||
},
|
||||
/**
|
||||
* Called when a demand to open a media dialog is received on the bus.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} data
|
||||
*/
|
||||
_onMediaDialogDemand: function (data) {
|
||||
var mediaDialog = new weWidgets.MediaDialog(this,
|
||||
data.options || {},
|
||||
data.$editable,
|
||||
data.media
|
||||
);
|
||||
if (data.onSave) {
|
||||
mediaDialog.on('save', this, data.onSave);
|
||||
}
|
||||
if (data.onCancel) {
|
||||
mediaDialog.on('cancel', this, data.onCancel);
|
||||
}
|
||||
mediaDialog.open();
|
||||
},
|
||||
/**
|
||||
* Called when the mouse is pressed on the document -> activate element
|
||||
* edition.
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
odoo.define('web_editor.rte.summernote', function (require) {
|
||||
'use strict';
|
||||
|
||||
var core = require('web.core');
|
||||
var ajax = require('web.ajax');
|
||||
var Class = require('web.Class');
|
||||
var core = require('web.core');
|
||||
var mixins = require('web.mixins');
|
||||
var weContext = require('web_editor.context');
|
||||
var widgets = require('web_editor.widget');
|
||||
var rte = require('web_editor.rte');
|
||||
var weWidgets = require('web_editor.widget');
|
||||
|
||||
var QWeb = core.qweb;
|
||||
var _t = core._t;
|
||||
@@ -422,8 +424,8 @@ dom.isImgFont = function (node) {
|
||||
var className = (node && node.className || "");
|
||||
if (node && (nodeName === "SPAN" || nodeName === "I") && className.length) {
|
||||
var classNames = className.split(/\s+/);
|
||||
for (var k=0; k<widgets.fontIcons.length; k++) {
|
||||
if (_.intersection(widgets.fontIcons[k].alias, classNames).length) {
|
||||
for (var k=0; k<weWidgets.fontIcons.length; k++) {
|
||||
if (_.intersection(weWidgets.fontIcons[k].alias, classNames).length) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -969,4 +971,133 @@ $.summernote.lang.odoo = {
|
||||
redo: _t('Redo')
|
||||
}
|
||||
};
|
||||
|
||||
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
/**
|
||||
* @todo get rid of this. This has been implemented as a fix to be able to
|
||||
* instantiate media, link and alt dialogs outside the main editor: in the
|
||||
* simple HTML fields and forum textarea.
|
||||
*/
|
||||
var SummernoteManager = Class.extend(mixins.EventDispatcherMixin, {
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
init: function (parent) {
|
||||
mixins.EventDispatcherMixin.init.call(this);
|
||||
this.setParent(parent);
|
||||
|
||||
core.bus.on('alt_dialog_demand', this, this._onAltDialogDemand);
|
||||
core.bus.on('link_dialog_demand', this, this._onLinkDialogDemand);
|
||||
core.bus.on('media_dialog_demand', this, this._onMediaDialogDemand);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
destroy: function () {
|
||||
mixins.EventDispatcherMixin.destroy.call(this);
|
||||
|
||||
core.bus.off('alt_dialog_demand', this, this._onAltDialogDemand);
|
||||
core.bus.off('link_dialog_demand', this, this._onLinkDialogDemand);
|
||||
core.bus.off('media_dialog_demand', this, this._onMediaDialogDemand);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Called when a demand to open a alt dialog is received on the bus.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} data
|
||||
*/
|
||||
_onAltDialogDemand: function (data) {
|
||||
if (data.__alreadyDone) {
|
||||
return;
|
||||
}
|
||||
data.__alreadyDone = true;
|
||||
var altDialog = new weWidgets.alt(this,
|
||||
data.options || {},
|
||||
data.$editable,
|
||||
data.media
|
||||
);
|
||||
if (data.onSave) {
|
||||
altDialog.on('save', this, data.onSave);
|
||||
}
|
||||
if (data.onCancel) {
|
||||
altDialog.on('cancel', this, data.onCancel);
|
||||
}
|
||||
altDialog.open();
|
||||
},
|
||||
/**
|
||||
* Called when a demand to open a link dialog is received on the bus.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} data
|
||||
*/
|
||||
_onLinkDialogDemand: function (data) {
|
||||
if (data.__alreadyDone) {
|
||||
return;
|
||||
}
|
||||
data.__alreadyDone = true;
|
||||
var linkDialog = new weWidgets.LinkDialog(this,
|
||||
data.options || {},
|
||||
data.$editable,
|
||||
data.linkInfo
|
||||
);
|
||||
if (data.onSave) {
|
||||
linkDialog.on('save', this, data.onSave);
|
||||
}
|
||||
if (data.onCancel) {
|
||||
linkDialog.on('cancel', this, data.onCancel);
|
||||
}
|
||||
linkDialog.open();
|
||||
},
|
||||
/**
|
||||
* Called when a demand to open a media dialog is received on the bus.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} data
|
||||
*/
|
||||
_onMediaDialogDemand: function (data) {
|
||||
if (data.__alreadyDone) {
|
||||
return;
|
||||
}
|
||||
data.__alreadyDone = true;
|
||||
var mediaDialog = new weWidgets.MediaDialog(this,
|
||||
data.options || {},
|
||||
data.$editable,
|
||||
data.media
|
||||
);
|
||||
if (data.onSave) {
|
||||
mediaDialog.on('save', this, data.onSave);
|
||||
}
|
||||
if (data.onCancel) {
|
||||
mediaDialog.on('cancel', this, data.onCancel);
|
||||
}
|
||||
mediaDialog.open();
|
||||
},
|
||||
});
|
||||
/**
|
||||
* @todo cannot do this without include because it would make a loop in the
|
||||
* JS module dependencies otherwise.
|
||||
*/
|
||||
rte.Class.include({
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
start: function () {
|
||||
this._summernoteManager = new SummernoteManager(this);
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
cancel: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this._summernoteManager.destroy();
|
||||
},
|
||||
});
|
||||
return SummernoteManager;
|
||||
});
|
||||
|
||||
@@ -2,8 +2,11 @@ odoo.define('website_forum.editor', function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var wUtils = require('website.utils');
|
||||
var Widget = require('web.Widget');
|
||||
var SummernoteManager = require('web_editor.rte.summernote');
|
||||
var WebsiteNewMenu = require("website.newMenu");
|
||||
var wUtils = require('website.utils');
|
||||
var websiteRootData = require('website.WebsiteRoot');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
@@ -54,4 +57,15 @@ WebsiteNewMenu.include({
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
var WebsiteForumManager = Widget.extend({
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
new SummernoteManager(this);
|
||||
},
|
||||
});
|
||||
websiteRootData.websiteRootRegistry.add(WebsiteForumManager, '#wrapwrap');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user