diff options
| author | Sébastien Theys <seb@odoo.com> | 2019-05-23 14:47:36 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2019-05-27 16:32:52 +0000 |
| commit | e378aebc247942ee5152127b9d8328f66d3b7a1e (patch) | |
| tree | 28cfd201d75ab7917e0f572ae5acd73488173de1 /addons/web_editor/static/src | |
| parent | dece93d5bec5a9d331c8f4d6b1af6423a4009ca4 (diff) | |
[IMP] web_editor, website_blog: clean up save/saved events
The web_editor had two different events `save` and `saved` doing more or less
the same thing but with a different signature.
In this commit we keep only the `save` event and adapt the code accordingly.
PR: #33509
Diffstat (limited to 'addons/web_editor/static/src')
6 files changed, 20 insertions, 33 deletions
diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/media.js b/addons/web_editor/static/src/js/wysiwyg/plugin/media.js index e6a598a2813..9ba83486e25 100644 --- a/addons/web_editor/static/src/js/wysiwyg/plugin/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/plugin/media.js @@ -67,8 +67,8 @@ var MediaPlugin = AbstractPlugin.extend({ $(media).clone()[0] ); - mediaDialog.on('saved', this, function (data) { - this.insertMedia(media, data); + mediaDialog.on('save', this, function (element) { + this.insertMedia(media, element); }); mediaDialog.on('closed', this, function () { this.context.invoke('editor.restoreRange'); @@ -157,13 +157,12 @@ var MediaPlugin = AbstractPlugin.extend({ * Insert or replace a media. * * @param {Node} previous the media to replace, if any - * @param {Object} data contains the media to insert + * @param {Node} newMedia contains the media to insert */ - insertMedia: function (previous, data) { - if (!data.media) { + insertMedia: function (previous, newMedia) { + if (!newMedia) { return; } - var newMedia = data.media; this._wrapCommand(function () { this.$editable.focus(); var rng = this.context.invoke('editor.createRange'); @@ -689,17 +688,17 @@ var ImagePlugin = AbstractMediaPlugin.extend({ //-------------------------------------------------------------------------- /** - * Open the crop image dialog and listen to its saved/closed events. + * Open the crop image dialog and listen to its save/closed events. */ cropImageDialog: function () { this.context.invoke('editor.saveRange'); var media = this.context.invoke('editor.restoreTarget'); var cropImageDialog = new weWidgets.CropImageDialog(this.options.parent, {}, - $(media).clone() + $(media).clone()[0] ); - cropImageDialog.on('saved', this, function (data) { - this.context.invoke('MediaPlugin.insertMedia', media, data); + cropImageDialog.on('save', this, function (img) { + this.context.invoke('MediaPlugin.insertMedia', media, img); }); cropImageDialog.on('closed', this, function () { this.context.invoke('editor.restoreRange'); @@ -708,18 +707,18 @@ var ImagePlugin = AbstractMediaPlugin.extend({ cropImageDialog.open(); }, /** - * Open the alt dialog (change image title and alt) and listen to its saved/closed events. + * Open the alt dialog (change image title and alt) and listen to its save/closed events. */ altDialg: function () { this.context.invoke('editor.saveRange'); var media = this.context.invoke('editor.restoreTarget'); var altDialog = new weWidgets.AltDialog(this.options.parent, {}, - $(media).clone() + $(media).clone()[0] ); - altDialog.on('saved', this, this._wrapCommand(function (data) { - $(media).attr('alt', $(data.media).attr('alt')) - .attr('title', $(data.media).attr('title')) + altDialog.on('save', this, this._wrapCommand(function (img) { + $(media).attr('alt', img.alt) + .attr('title', img.title) .trigger('content_changed'); })); altDialog.on('closed', this, function () { diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/alt_dialog.js b/addons/web_editor/static/src/js/wysiwyg/widgets/alt_dialog.js index dd6baff130f..98abc75f6c1 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/alt_dialog.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/alt_dialog.js @@ -52,9 +52,7 @@ var AltDialog = Dialog.extend({ $(this.media).attr('alt', alt ? alt.replace(allNonEscQuots, """) : null) .attr('title', title ? title.replace(allNonEscQuots, """) : null); - this.trigger('saved', { - media: this.media, - }); + this.final_data = this.media; return this._super.apply(this, arguments); }, }); diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/crop_dialog.js b/addons/web_editor/static/src/js/wysiwyg/widgets/crop_dialog.js index cb1feaf3f4d..19623d05f5e 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/crop_dialog.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/crop_dialog.js @@ -172,9 +172,7 @@ var CropImageDialog = Dialog.extend({ }); this.$media.attr('src', canvas.toDataURL(this.imageData.mimetype)); - this.trigger('saved', { - media: this.$media[0], - }); + this.final_data = this.media; return this._super.apply(this, arguments); }, diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js index ddd987f4ed2..a30b4a223b4 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -47,6 +47,8 @@ var MediaWidget = Widget.extend({ */ search: function (needle) {}, /** + * Saves the currently configured media on the target media. + * * @abstract * @returns {*} */ diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media_dialog.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media_dialog.js index cdfde911597..4297d5f4dd3 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media_dialog.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media_dialog.js @@ -141,16 +141,6 @@ var MediaDialog = Dialog.extend({ var args = arguments; return Promise.resolve(this.active.save()).then(function (data) { self.final_data = data; - // In the case of multi images selection we suppose this was not to - // replace an old media, so we only retrieve the images and save. - if (!self.multiImages) { - // TODO this dialog triggers 'save' and 'saved' with different - // data on close... should refactor to avoid confusion... - self.trigger('saved', { - attachments: self.active.images, - media: data, - }); - } return _super.apply(self, args); }); }, diff --git a/addons/web_editor/static/src/js/wysiwyg_snippets/snippets.options.js b/addons/web_editor/static/src/js/wysiwyg_snippets/snippets.options.js index 5c7a41ae8f3..020a91b0a2b 100644 --- a/addons/web_editor/static/src/js/wysiwyg_snippets/snippets.options.js +++ b/addons/web_editor/static/src/js/wysiwyg_snippets/snippets.options.js @@ -858,8 +858,8 @@ registry.background = SnippetOption.extend({ res_id: $editable.data('oe-id'), }, $image[0]).open(); - _editor.on('save', this, function () { - this._setCustomBackground($image.attr('src')); + _editor.on('save', this, function (image) { + this._setCustomBackground(image.src); this.$target.trigger('content_changed'); }); _editor.on('closed', this, function () { |
