summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-08-22 15:44:39 +0200
committerqsm-odoo <qsm@odoo.com>2017-08-23 11:27:55 +0200
commit0fb82ab34e0e68f226397c872a6760ecf0472734 (patch)
treece13d19e0c12a6f2a48e3d17de7ee65baf47315d /addons/web_editor/static/src
parentc5c53c8b6d1e900cd141091a90b39abcc29179d5 (diff)
[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.
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/backend/fields.js9
-rw-r--r--addons/web_editor/static/src/js/editor/rte.js68
-rw-r--r--addons/web_editor/static/src/js/editor/rte.summernote.js139
3 files changed, 144 insertions, 72 deletions
diff --git a/addons/web_editor/static/src/js/backend/fields.js b/addons/web_editor/static/src/js/backend/fields.js
index ab4828fe89d..2486fea9b81 100644
--- a/addons/web_editor/static/src/js/backend/fields.js
+++ b/addons/web_editor/static/src/js/backend/fields.js
@@ -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
//--------------------------------------------------------------------------
diff --git a/addons/web_editor/static/src/js/editor/rte.js b/addons/web_editor/static/src/js/editor/rte.js
index fffe8786f91..fb86f92b25a 100644
--- a/addons/web_editor/static/src/js/editor/rte.js
+++ b/addons/web_editor/static/src/js/editor/rte.js
@@ -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');
@@ -567,66 +559,6 @@ var RTEWidget = Widget.extend({
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.
*
diff --git a/addons/web_editor/static/src/js/editor/rte.summernote.js b/addons/web_editor/static/src/js/editor/rte.summernote.js
index 7067ab28af6..01b83530e48 100644
--- a/addons/web_editor/static/src/js/editor/rte.summernote.js
+++ b/addons/web_editor/static/src/js/editor/rte.summernote.js
@@ -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;
});