From 4a1d776243b059d423152bd026bb8bc758477224 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 2 Apr 2021 09:18:52 +0000 Subject: [PATCH] [REF] web_editor: prevent duplicate code in LinkDialog and LinkTools LinkTools were recently introduced to provide a new UI from link editing within a sidebar where there is one. It was implemented separately from the existing LinkDialog despite them having a lot of code in common. In order to prevent future discrepancies between them, this commit introduces the Link widget which contains the common logic for link editing, to be extended by LinkTools and LinkDialog (via an intermediary widget). closes odoo/odoo#69137 X-original-commit: 5415ea46f8d3ee4732111a21b0cd9fa8bdb9526e Signed-off-by: David Monjoie (dmo) --- .../static/src/js/wysiwyg/widgets/link.js | 421 ++++++++++++++++++ .../src/js/wysiwyg/widgets/link_dialog.js | 300 ++++--------- .../src/js/wysiwyg/widgets/link_tools.js | 288 +++--------- .../static/src/js/wysiwyg/wysiwyg.js | 46 +- .../static/src/js/wysiwyg/wysiwyg_utils.js | 38 -- 5 files changed, 582 insertions(+), 511 deletions(-) create mode 100644 addons/web_editor/static/src/js/wysiwyg/widgets/link.js diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js new file mode 100644 index 00000000000..70804bbcd50 --- /dev/null +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -0,0 +1,421 @@ +odoo.define('wysiwyg.widgets.Link', function (require) { +'use strict'; + +const core = require('web.core'); +const OdooEditorLib = require('web_editor.odoo-editor'); +const wysiwygUtils = require('@web_editor/js/wysiwyg/wysiwyg_utils'); +const Widget = require('web.Widget'); + +const getDeepRange = OdooEditorLib.getDeepRange; +const getInSelection = OdooEditorLib.getInSelection; +const _t = core._t; + +/** + * Allows to customize link content and style. + */ +const Link = Widget.extend({ + xmlDependencies: ['/web_editor/static/src/xml/wysiwyg.xml'], + events: { + 'input': '_onAnyChange', + 'change': '_onAnyChange', + 'input input[name="url"]': '_onURLInput', + }, + + /** + * @constructor + * @param {Boolean} data.isButton - whether if the target is a button element. + */ + init: function (parent, options, editable, data, $button, link) { + this.options = options || {}; + this._super(parent, _.extend({ + title: _t("Link to"), + }, this.options)); + + this.data = data || {}; + this.isButton = this.data.isButton; + this.$button = $button; + + this.data.className = this.data.className || ""; + this.data.iniClassName = this.data.iniClassName || ""; + + // Using explicit type 'link' to preserve style when the target is