From d95150c69be95141920007dc51cf10ef64809f64 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Mon, 19 Dec 2022 08:27:31 +0000 Subject: [PATCH] [FIX] web_editor: hide "Open in New Window" option for emails When `link_tools` was introduced at [1], the selectors to the `is_new_window` input were copied from `link_dialog`'s `_onURLInput` without being adapted. Later the code was refactored into `link` at [2] because they were an exact match. This commit updates the selectors to also match the field inside the link tools. Steps to reproduce: - Edit Home page - Drop a "Banner" block - Select the "Contact Us" button - Change the URL to an e-mail address => The "Open In New Window" field was still available [1]: https://github.com/odoo/odoo/commit/740168ce8d27da3d6a7156d2d79655a898394923#diff-6345b8d133e9b338a77c50a8e5ae824fe405cb9319e98a2ac349b072be07a3a2R321 [2]: https://github.com/odoo/odoo/commit/4a1d776243b059d423152bd026bb8bc758477224 opw-3086198 task-3096806 closes odoo/odoo#108812 X-original-commit: 292dcb99e55178358a64c9879ba4b1721e67d02c Signed-off-by: Quentin Smetz (qsm) --- .../web_editor/static/src/js/wysiwyg/widgets/link.js | 11 ++++++++++- .../static/src/js/wysiwyg/widgets/link_dialog.js | 6 ++++++ .../static/src/js/wysiwyg/widgets/link_tools.js | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js index 8e99f888bbe..8d291dedff5 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -334,6 +334,15 @@ const Link = Widget.extend({ } return nodes; }, + /** + * Abstract method: return a JQuery object containing the UI elements + * holding the "Open in new window" option's row of the link. + * + * @abstract + * @private + * @returns {JQuery} + */ + _getIsNewWindowFormRow() {}, /** * Abstract method: return a JQuery object containing the UI elements * holding the styling options of the link (eg: color, size, shape). @@ -510,7 +519,7 @@ const Link = Widget.extend({ var $linkUrlInput = this.$('#o_link_dialog_url_input'); let value = $linkUrlInput.val(); let isLink = value.indexOf('@') < 0; - this.$('input[name="is_new_window"]').closest('.row').toggleClass('d-none', !isLink); + this._getIsNewWindowFormRow().toggleClass('d-none', !isLink); this.$('.o_strip_domain').toggleClass('d-none', value.indexOf(window.location.origin) !== 0); }, /** diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js index e09e4fa3c42..b8ae37ae380 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js @@ -85,6 +85,12 @@ const _DialogLinkWidget = Link.extend({ _doStripDomain: function () { return this.$('#o_link_dialog_url_strip_domain').prop('checked'); }, + /** + * @override + */ + _getIsNewWindowFormRow() { + return this.$('input[name="is_new_window"]').closest('.row'); + }, /** * @override */ diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js index f126d3a6b10..b6cee090e9a 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js @@ -104,6 +104,12 @@ const LinkTools = Link.extend({ _doStripDomain: function () { return this.$('we-checkbox[name="do_strip_domain"]').closest('we-button.o_we_checkbox_wrapper').hasClass('active'); }, + /** + * @override + */ + _getIsNewWindowFormRow() { + return this.$('we-checkbox[name="is_new_window"]').closest('we-row'); + }, /** * @override */