[FIX] web_editor: missing record info for converted images
When the Wysiwyg is used by website, multiple editable elements are possible, and each of them carry the related record's model and id in the element's dataset. On the other hand, when the Wysiwyg is used by the html field, there's only one root editable element, and such information is not present in the editable's dataset, but in the widget's options object. Before this commit, when saving the content of an html field, modified images were converted to attachments without the correct reference to the record's model and id. This commit makes sure that such information is passed to the route that handles attachment creation. task-3495668 closes odoo/odoo#135806 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com> Signed-off-by: Antoine Guenet (age) <age@odoo.com>
This commit is contained in:
@@ -1159,7 +1159,10 @@ export class Wysiwyg extends Component {
|
||||
*/
|
||||
savePendingImages($editable = this.$editable) {
|
||||
const defs = Array.from($editable).map(async (editableEl) => {
|
||||
const {res_model: resModel, res_id: resId} = this.options.recordInfo;
|
||||
let { oeModel: resModel, oeId: resId } = editableEl.dataset;
|
||||
if (!resModel) {
|
||||
({ res_model: resModel, res_id: resId } = this.options.recordInfo);
|
||||
}
|
||||
// When saving a webp, o_b64_image_to_save is turned into
|
||||
// o_modified_image_to_save by _saveB64Image to request the saving
|
||||
// of the pre-converted webp resizes and all the equivalent jpgs.
|
||||
|
||||
@@ -293,7 +293,7 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => {
|
||||
QUnit.module('Save scenarios');
|
||||
|
||||
QUnit.test("Ensure that urgentSave works even with modified image to save", async (assert) => {
|
||||
assert.expect(3);
|
||||
assert.expect(5);
|
||||
let formController;
|
||||
// Patch to get the controller instance.
|
||||
patchWithCleanup(FormController.prototype, {
|
||||
@@ -377,6 +377,8 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => {
|
||||
route === `/web_editor/modify_image/${imageRecord.id}`
|
||||
) {
|
||||
if (modifyImageCount === 0) {
|
||||
assert.equal(args.res_model, 'partner');
|
||||
assert.equal(args.res_id, 1);
|
||||
await modifyImagePromise;
|
||||
return newImageSrc;
|
||||
} else {
|
||||
@@ -437,7 +439,7 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => {
|
||||
});
|
||||
|
||||
QUnit.test("Pasted/dropped images are converted to attachments on save", async (assert) => {
|
||||
assert.expect(4);
|
||||
assert.expect(6);
|
||||
|
||||
// Patch to get a promise to get the htmlField component instance when
|
||||
// the wysiwyg is instancied.
|
||||
@@ -457,6 +459,9 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => {
|
||||
|
||||
const mockRPC = async function (route, args) {
|
||||
if (route === '/web_editor/attachment/add_data') {
|
||||
// Check that the correct record model and id were sent.
|
||||
assert.equal(args.res_model, 'partner');
|
||||
assert.equal(args.res_id, 1);
|
||||
return {
|
||||
image_src: '/test_image_url.png',
|
||||
access_token: '1234',
|
||||
|
||||
Reference in New Issue
Block a user