[FIX] web_editor: properly set media dialog onlyImages and find video

Media dialog was trying to reach the current media's parent node, which
was not possible as it was cloned on instantiation.
To fix this, the `showImageDialog` now passes the `onlyImages` option
upon instantiation, checking the parent's data. It also passes the
media's parent if said parent is a video. This way, neither of these two
things need to be done in media dialog.

closes odoo/odoo#31634

Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com>
This commit is contained in:
Antoine Guenet
2019-03-06 12:51:41 +00:00
parent f1c0530515
commit 0374ecaeb8
2 changed files with 9 additions and 6 deletions
@@ -54,7 +54,14 @@ var MediaPlugin = AbstractPlugin.extend({
this.context.invoke('editor.saveRange');
var media = this.context.invoke('editor.restoreTarget');
var mediaDialog = new weWidgets.MediaDialog(this.options.parent, {},
var $mediaParent = $(media).parent();
if ($mediaParent.hasClass('media_iframe_video')) {
media = $mediaParent[0];
$mediaParent = $mediaParent.parent();
}
var mediaDialog = new weWidgets.MediaDialog(this.options.parent, {
onlyImages: $mediaParent.data('oeField') === 'image' || $mediaParent.data('oeType') === 'image',
},
$(media).clone()[0]
);
@@ -48,7 +48,7 @@ var MediaDialog = Dialog.extend({
this.$media = $(media);
this.multiImages = options.multiImages;
var onlyImages = options.onlyImages || this.multiImages || (this.media && (this.$media.parent().data('oeField') === 'image' || this.$media.parent().data('oeType') === 'image'));
var onlyImages = options.onlyImages || this.multiImages;
this.noImages = options.noImages;
this.noDocuments = onlyImages || options.noDocuments;
this.noIcons = onlyImages || options.noIcons;
@@ -80,10 +80,6 @@ var MediaDialog = Dialog.extend({
this.active = this.documentDialog;
} else if (this.videoDialog && this.$media.hasClass('media_iframe_video')) {
this.active = this.videoDialog;
} else if (this.videoDialog && this.$media.parent().hasClass('media_iframe_video')) {
this.$media = this.$media.parent();
this.media = this.$media[0];
this.active = this.videoDialog;
} else if (this.iconDialog && this.$media.is('span, i')) {
this.active = this.iconDialog;
}