[FIX] web_editor: allow images command in html fields

The images command was disabled in html fields if the field's view
didn't define the `allowCommandImages` option. This allows that option
to be undefined so it can be overridden by its default value when such
is the case. Before this commit however, the option was always set to
`false` when undefined (the opposite of the expected default value).

opw-3134660

X-original-commit: bf0f17d2c9f19b88d4db2f4e15423ec0c831167f
Part-of: odoo/odoo#111777
This commit is contained in:
Antoine Guenet
2023-02-03 10:35:47 +01:00
parent 68057e7161
commit 39a2002bf1
2 changed files with 47 additions and 24 deletions
@@ -229,7 +229,7 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
* @returns {Object}
*/
_getWysiwygOptions: function () {
return Object.assign({}, this.nodeOptions, {
const wysiwygOptions = {
recordInfo: {
context: this.record.getContext(this.recordParams),
res_model: this.model,
@@ -246,7 +246,6 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
iframeCssAssets: this.nodeOptions.cssEdit,
snippets: this.nodeOptions.snippets,
value: this.value,
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,
@@ -260,7 +259,20 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
maxHeight: this.nodeOptions.maxHeight,
resizable: 'resizable' in this.nodeOptions ? this.nodeOptions.resizable : false,
editorPlugins: [QWebPlugin],
});
};
if ('allowCommandImage' in this.nodeOptions) {
// Set the option only if it is explicitly set in the view so a
// default can be set elsewhere otherwise.
wysiwygOptions.allowCommandImage = Boolean(this.nodeOptions.allowCommandImage);
}
if (this.field.sanitize && this.field.sanitize_tags) {
wysiwygOptions.allowCommandVideo = false; // Sanitized fields remove videos.
} else if ('allowCommandVideo' in this.nodeOptions) {
// Set the option only if it is explicitly set in the view so a
// default can be set elsewhere otherwise.
wysiwygOptions.allowCommandVideo = Boolean(this.nodeOptions.allowCommandVideo);
}
return Object.assign({}, this.nodeOptions, wysiwygOptions);
},
/**
* Toggle the code view and update the UI.
@@ -616,6 +616,37 @@ HtmlField.displayName = _lt("Html");
HtmlField.supportedTypes = ["html"];
HtmlField.extractProps = ({ attrs, field }) => {
const wysiwygOptions = {
placeholder: attrs.placeholder,
noAttachment: attrs.options['no-attachment'],
inIframe: Boolean(attrs.options.cssEdit),
iframeCssAssets: attrs.options.cssEdit,
iframeHtmlClass: attrs.iframeHtmlClass,
snippets: attrs.options.snippets,
mediaModalParams: {
noVideos: 'noVideos' in attrs.options ? attrs.options.noVideos : true,
useMediaLibrary: true,
},
linkForceNewWindow: true,
tabsize: 0,
height: attrs.options.height,
minHeight: attrs.options.minHeight,
maxHeight: attrs.options.maxHeight,
resizable: 'resizable' in attrs.options ? attrs.options.resizable : false,
editorPlugins: [QWebPlugin],
};
if ('allowCommandImage' in attrs.options) {
// Set the option only if it is explicitly set in the view so a default
// can be set elsewhere otherwise.
wysiwygOptions.allowCommandImage = Boolean(attrs.options.allowCommandImage);
}
if (field.sanitize && field.sanitize_tags) {
wysiwygOptions.allowCommandVideo = false; // Sanitized fields remove videos.
} else if ('allowCommandVideo' in attrs.options) {
// Set the option only if it is explicitly set in the view so a default
// can be set elsewhere otherwise.
wysiwygOptions.allowCommandVideo = Boolean(attrs.options.allowCommandVideo);
}
return {
isTranslatable: field.translate,
fieldName: field.name,
@@ -629,27 +660,7 @@ HtmlField.extractProps = ({ attrs, field }) => {
isInlineStyle: attrs.options['style-inline'],
wrapper: attrs.options.wrapper,
wysiwygOptions: {
placeholder: attrs.placeholder,
noAttachment: attrs.options['no-attachment'],
inIframe: Boolean(attrs.options.cssEdit),
iframeCssAssets: attrs.options.cssEdit,
iframeHtmlClass: attrs.iframeHtmlClass,
snippets: attrs.options.snippets,
allowCommandImage: Boolean(attrs.options.allowCommandImage),
allowCommandVideo: Boolean(attrs.options.allowCommandVideo) && (!field.sanitize || !field.sanitize_tags),
mediaModalParams: {
noVideos: 'noVideos' in attrs.options ? attrs.options.noVideos : true,
useMediaLibrary: true,
},
linkForceNewWindow: true,
tabsize: 0,
height: attrs.options.height,
minHeight: attrs.options.minHeight,
maxHeight: attrs.options.maxHeight,
resizable: 'resizable' in attrs.options ? attrs.options.resizable : false,
editorPlugins: [QWebPlugin],
},
wysiwygOptions,
};
};