From 8a5d22826c8ec3c23a5c7e2f2347ae20fe9e2269 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 16 Mar 2021 12:25:06 +0000 Subject: [PATCH] [FIX] website_forum: show normal image modal in forum In #67893 the image icon was removed, but it contradicts the interface and made a feature that was working for employee less available. Since saas-12.3, we always use the full media dialog when showing the editor on the forum so we could not add an image with the image icon if were not an employee. Before saas-12.3, the original summernote image dialog was shown for everyone but website editor that saw the full media dialog (beecause we are using the same editor to do both things). With this change, we always have the original dialog in the forum message editor thanks to a new option "disableFullMediaDialog". opw-2470720 closes odoo/odoo#68166 X-original-commit: c026c360fb77ce43f47f7645f48e37bced988b85 Signed-off-by: Nicolas Lempereur (nle) --- addons/web_editor/static/src/js/editor/rte.summernote.js | 9 ++++++++- addons/website_forum/static/src/js/website_forum.js | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) 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 1c24bb4f7e4..e01c9d452a4 100644 --- a/addons/web_editor/static/src/js/editor/rte.summernote.js +++ b/addons/web_editor/static/src/js/editor/rte.summernote.js @@ -464,7 +464,12 @@ eventHandler.modules.linkDialog.showLinkDialog = function ($editable, $dialog, l }); return def; }; +var originalShowImageDialog = eventHandler.modules.imageDialog.showImageDialog; eventHandler.modules.imageDialog.showImageDialog = function ($editable) { + var options = $editable.closest('.o_editable, .note-editor').data('options'); + if (options.disableFullMediaDialog) { + return originalShowImageDialog.apply(this, arguments); + } var r = $editable.data('range'); if (r.sc.tagName && r.sc.childNodes.length) { r.sc = r.sc.childNodes[r.so]; @@ -472,7 +477,6 @@ eventHandler.modules.imageDialog.showImageDialog = function ($editable) { var media = $(r.sc).parents().addBack().filter(function (i, el) { return dom.isImg(el); })[0]; - var options = $editable.closest('.o_editable, .note-editor').data('options'); topBus.trigger('media_dialog_demand', { $editable: $editable, media: media, @@ -866,6 +870,9 @@ eventHandler.attach = function (oLayoutInfo, options) { oLayoutInfo.editor().on('dragstart', 'img', function (e) { e.preventDefault(); }); $(document).on('mousedown', summernote_mousedown).on('mouseup', summernote_mouseup); oLayoutInfo.editor().off('click').on('click', function (e) {e.preventDefault();}); // if the content editable is a link + oLayoutInfo.editor().find('.note-image-dialog').on('click', '.note-image-input', function (e) { + e.stopPropagation(); // let browser default happen for image file input + }); /** * Open Media Dialog on double click on an image/video/icon. diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index c20b65d4b1a..85db9236a9e 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -141,6 +141,7 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({ res_model: 'forum.post', res_id: +window.location.pathname.split('-').pop(), }, + disableFullMediaDialog: true, }; if (!hasFullEdit) { options.plugins = {