diff --git a/addons/web_editor/static/src/js/backend/field_html.js b/addons/web_editor/static/src/js/backend/field_html.js index 9a492f29627..e16baa6838a 100644 --- a/addons/web_editor/static/src/js/backend/field_html.js +++ b/addons/web_editor/static/src/js/backend/field_html.js @@ -204,6 +204,9 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { allowCommandVideo: Boolean(this.nodeOptions.allowCommandVideo) && (!this.field.sanitize || !this.field.sanitize_tags), mediaModalParams: { noVideos: 'noVideos' in this.nodeOptions ? this.nodeOptions.noVideos : true, + res_model: this.model, + res_id: this.res_id, + useMediaLibrary: true, }, linkForceNewWindow: true, tabsize: 0, diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 73e8bd033fc..e5878c674bd 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1175,6 +1175,7 @@ const Wysiwyg = Widget.extend({ if (!sel.rangeCount) { return; } + const range = sel.getRangeAt(0); // We lose the current selection inside the content editable when we // click the media dialog button so we need to be able to restore the // selection when the modal is closed. @@ -1183,7 +1184,7 @@ const Wysiwyg = Widget.extend({ const $node = $(params.node); // We need to keep track of FA icon because media.js will _clear those classes const wasFontAwesome = $node.hasClass('fa'); - const $editable = $(this.odooEditor.editable); + const $editable = $(OdooEditorLib.closestElement(range.startContainer, '.o_editable')); const model = $editable.data('oe-model'); const field = $editable.data('oe-field'); const type = $editable.data('oe-type'); diff --git a/addons/website/static/tests/tours/media_dialog.js b/addons/website/static/tests/tours/media_dialog.js new file mode 100644 index 00000000000..93cca3d81da --- /dev/null +++ b/addons/website/static/tests/tours/media_dialog.js @@ -0,0 +1,24 @@ +/** @odoo-module */ + +import tour from 'web_tour.tour'; +import wTourUtils from 'website.tour_utils'; + +tour.register('website_media_dialog_undraw', { + test: true, + url: '/', +}, [ +{ + trigger: 'a[data-action=edit]', +}, +wTourUtils.dragNDrop({ + id: 's_text_image', + name: 'Text - Image', +}), +{ + trigger: '.s_text_image img', + run: "dblclick", +}, +{ + trigger: '.o_select_media_dialog:has(.o_we_search_select option[value="media-library"])', +}, +]); diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index 69431500b13..cda6ebbdc2e 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -106,6 +106,8 @@ class TestUiHtmlEditor(odoo.tests.HttpCase): }) self.start_tour("/", 'test_html_editor_scss', login='admin', timeout=120) + def media_dialog_undraw(self): + self.start_tour("/", 'website_media_dialog_undraw', login='admin') @odoo.tests.tagged('-at_install', 'post_install') class TestUiTranslate(odoo.tests.HttpCase):