summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/wysiwyg/plugin/abstract.js
diff options
context:
space:
mode:
authorGorash <chm@odoo.com>2019-08-20 06:23:06 +0000
committerDavid Monjoie <dmo@odoo.com>2019-08-21 18:52:36 +0000
commit35b61822a8b12ebbdb455495479df6f2e13db03e (patch)
tree999c382ea06b53b8da8d7db2d82e671d831dd856 /addons/web_editor/static/src/js/wysiwyg/plugin/abstract.js
parentf14cecfc0a7f401533213aaa968ee233e19d1325 (diff)
[REV] wev_editor, website: revert saas-12.2 editor
This commit reverts the saas-12.2 editor by putting back the editor of Odoo 12. The saas-12.2 editor was an intermediate work between the previous editor of Odoo 12 and the new one slated for Odoo 13. It was unstable but it was supposed to be replaced by the new editor of version 13. However, since the new editor has been postponed to Odoo 14, the saas-12.2 one would have been staying in Odoo 13, which would have been a nightmare to maintain. To avoid this outcome, we chose to put back the 12.0 editor in its place. This has the particular advantage that Odoo 13 will share the same bugfixes as Odoo 12 and 11 as they all run under the same core editor, while the saas-12.2 one would have been an entirely different beast to maintain. This is a partial revert of f2969923. Part of PR 35677. Co-authored-by: Nicolas Bayet <nby@odoo.com> Co-authored-by: Antoine Guenet <age@odoo.com> Co-authored-by: Christophe Matthieu <chm@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js/wysiwyg/plugin/abstract.js')
-rw-r--r--addons/web_editor/static/src/js/wysiwyg/plugin/abstract.js222
1 files changed, 0 insertions, 222 deletions
diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/abstract.js b/addons/web_editor/static/src/js/wysiwyg/plugin/abstract.js
deleted file mode 100644
index de776020a42..00000000000
--- a/addons/web_editor/static/src/js/wysiwyg/plugin/abstract.js
+++ /dev/null
@@ -1,222 +0,0 @@
-odoo.define('web_editor.wysiwyg.plugin.abstract', function (require) {
-'use strict';
-
-var Class = require('web.Class');
-var mixins = require('web.mixins');
-var ServicesMixin = require('web.ServicesMixin');
-var wysiwygTranslation = require('web_editor.wysiwyg.translation');
-var wysiwygOptions = require('web_editor.wysiwyg.options');
-
-//--------------------------------------------------------------------------
-// AbstractPlugin for summernote module API
-//--------------------------------------------------------------------------
-
-var AbstractPlugin = Class.extend(mixins.EventDispatcherMixin, ServicesMixin).extend({
- /**
- * Use this prop if you want to extend a summernote plugin.
- */
- init: function (context) {
- var self = this;
- this._super.apply(this, arguments);
- this.setParent(context.options.parent);
- this.context = context;
-
- if (!this.context.invoke) {
- // for use outside of wysiwyg/summernote
- this.context.invoke = function () {};
- }
-
- this.$editable = context.layoutInfo.editable;
- this.editable = this.$editable[0];
- this.document = this.editable.ownerDocument;
- this.window = this.document.defaultView;
- this.summernote = this.window._summernoteSlave || $.summernote; // if the target is in iframe
- this.ui = this.summernote.ui;
- this.$editingArea = context.layoutInfo.editingArea;
- this.options = _.defaults(context.options || {}, wysiwygOptions);
- this.lang = wysiwygTranslation;
- this._addButtons();
- if (this.events) {
- this.events = _.clone(this.events);
- _.each(_.keys(this.events), function (key) {
- var value = self.events[key];
- if (typeof value === 'string') {
- value = self[value].bind(self);
- }
- if (key.indexOf('summernote.') === 0) {
- self.events[key] = value;
- } else {
- delete self.events[key];
- key = key.split(' ');
- if (key.length > 1) {
- self.context.layoutInfo.editor.on(key[0], key.slice(1).join(' '), value);
- } else {
- self.context.layoutInfo.editor.on(key, value);
- }
- }
- });
- }
- },
-
- //--------------------------------------------------------------------------
- // Public summernote module API
- //--------------------------------------------------------------------------
-
- shouldInitialize: function () {
- return true;
- },
- initialize: function () {},
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- /**
- * Override to add buttons.
- */
- _addButtons: function () {},
- /**
- * Creates a dropdown button with its contents and behavior.
- *
- * @param {str} optionName
- * @param {str} buttonIcon (ex.: 'note-icon-align')
- * @param {str} buttonTooltip (ex.: 'Align Paragraph')
- * @param {Object[]} values (ex.: [{value: 'padding-small', string: 'S'}])
- * @param {function} onclick
- */
- _createDropdownButton: function (optionName, buttonIcon, buttonTooltip, values, onclick) {
- var self = this;
-
- if (!onclick) {
- onclick = function (e) {
- var classNames = _.map(values, function (item) {
- return item.value;
- }).join(' ');
- var $target = $(self.context.invoke('editor.restoreTarget'));
- $target.removeClass(classNames);
- if ($(e.target).data('value')) {
- $target.addClass($(e.target).data('value'));
- }
- };
- }
- if (optionName) {
- this.context.memo('button.' + optionName, function () {
- return self._renderDropdownButton(buttonIcon, buttonTooltip, values, onclick);
- });
- } else {
- return this._renderDropdownButton(buttonIcon, buttonTooltip, values, onclick);
- }
- },
- /**
- * Creates a button to toggle a class.
- *
- * @param {str} optionName
- * @param {str} buttonIcon (ex.: 'note-icon-align')
- * @param {str} buttonTooltip (ex.: 'Align Paragraph')
- * @param {str} className
- */
- _createToggleButton: function (optionName, buttonIcon, buttonTooltip, className) {
- var self = this;
- return this._createButton(optionName, buttonIcon, buttonTooltip, function () {
- var $target = $(self.context.invoke('editor.restoreTarget'));
- $target.toggleClass(className);
- });
- },
- /**
- * Creates a button.
- *
- * @param {str} optionName
- * @param {str} buttonIcon (ex.: 'note-icon-align')
- * @param {str} buttonTooltip (ex.: 'Align Paragraph')
- * @param {function} onclick
- */
- _createButton: function (optionName, buttonIcon, buttonTooltip, onclick) {
- var self = this;
- if (optionName) {
- this.context.memo('button.' + optionName, function () {
- return self._renderButton(buttonIcon, buttonTooltip, onclick);
- });
- } else {
- return this._renderButton(buttonIcon, buttonTooltip, onclick);
- }
- },
- /**
- * Helper function to _createButton: renders the button.
- *
- * @param {str} buttonIcon (ex.: 'note-icon-align')
- * @param {str} buttonTooltip (ex.: 'Align Paragraph')
- * @param {function} onclick
- * @returns {JQuery}
- */
- _renderButton: function (buttonIcon, buttonTooltip, onclick) {
- var self = this;
- return this.context.invoke('buttons.button', {
- contents: buttonIcon.indexOf('<') === -1 ? this.ui.icon(buttonIcon) : buttonIcon,
- tooltip: buttonTooltip,
- click: function (e) {
- e.preventDefault();
- self.context.invoke('editor.beforeCommand');
- onclick(e);
- self.editable.normalize();
- self.context.invoke('editor.saveRange');
- self.context.invoke('editor.afterCommand');
- },
- }).render();
- },
- /**
- * Helper function to _createDropdownButton: renders the dropdown button.
- *
- * @param {str} buttonIcon (ex.: 'note-icon-align')
- * @param {str} buttonTooltip (ex.: 'Align Paragraph')
- * @param {Object[]} values (ex.: [{value: 'padding-small', string: 'S'}])
- * @param {function} onclick
- * @param {JQuery}
- */
- _renderDropdownButton: function (buttonIcon, buttonTooltip, values, onclick) {
- return this.ui.buttonGroup([
- this.context.invoke('buttons.button', {
- className: 'dropdown-toggle',
- contents: buttonIcon.indexOf('<') === -1 ?
- this.ui.dropdownButtonContents(this.ui.icon(buttonIcon), this.options) : buttonIcon,
- tooltip: buttonTooltip,
- data: {
- toggle: 'dropdown'
- }
- }),
- this.ui.dropdown({
- items: values,
- template: function (item) {
- return item.string;
- },
- click: this._wrapCommand(function (e) {
- e.preventDefault();
- onclick(e);
- }),
- })
- ]).render();
- },
- /**
- * Wraps a given function between common actions required
- * for history (undo/redo) and the maintenance of the DOM/range.
- *
- * @param {function} fn
- * @returns {any} the return of fn
- */
- _wrapCommand: function (fn) {
- var self = this;
- return function () {
- self.context.invoke('editor.restoreRange');
- self.context.invoke('editor.beforeCommand');
- var res = fn.apply(self, arguments);
- self.editable.normalize();
- self.context.invoke('editor.saveRange');
- self.context.invoke('editor.afterCommand');
- return res;
- };
- },
-
-});
-
-return AbstractPlugin;
-
-});