From 5f98040430ab0ce750382cc0faf57146f8759752 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 27 Sep 2016 15:30:08 +0200 Subject: [FIX] website, *: properly process saving from editor dialogs * web_editor, website_blog Since recent refactoring, web editor dialogs automatically trigger an event when closed (saved or cancel). The problem is that there still was manual trigger of those events or variants ("save" instead of "saved"). To prevent multi-saving and be consistent, all save events are now automatically triggered on save/close (no more manual) and the event name is "save". --- .../web_editor/static/src/js/snippets.options.js | 2 +- addons/web_editor/static/src/js/widgets.js | 23 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'addons/web_editor/static/src/js') diff --git a/addons/web_editor/static/src/js/snippets.options.js b/addons/web_editor/static/src/js/snippets.options.js index f1cf4a47381..7a6bb5fef4c 100644 --- a/addons/web_editor/static/src/js/snippets.options.js +++ b/addons/web_editor/static/src/js/snippets.options.js @@ -349,7 +349,7 @@ odoo.define('web_editor.snippets.options', function (require) { var _editor = new widget.MediaDialog(null, {}, null, $image[0]).open(); _editor.$('[href="#editor-media-video"], [href="#editor-media-icon"]').addClass('hidden'); - _editor.on('saved', this, function () { + _editor.on('save', this, function () { var value = $image.attr("src"); this.background(type, value, $li); this.$target.addClass("oe_custom_bg"); diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js index e4e838567c2..c19fc826f87 100644 --- a/addons/web_editor/static/src/js/widgets.js +++ b/addons/web_editor/static/src/js/widgets.js @@ -34,11 +34,11 @@ Dialog = Dialog.extend({ self.$('input:first').focus(); }); this.on("closed", this, function () { - this.trigger(this.destroyAction); + this.trigger(this.destroyAction, this.final_data || null); }); }, save: function () { - this.destroyAction = "saved"; + this.destroyAction = "save"; this.close(); }, }); @@ -164,8 +164,8 @@ var MediaDialog = Dialog.extend({ }, save: function () { if (this.options.select_images) { - this.trigger("saved", this.active.save()); - this.close(); + this.final_data = this.active.save(); + this._super.apply(this, arguments); return; } if(this.rte) { @@ -198,8 +198,9 @@ var MediaDialog = Dialog.extend({ } var media = this.active.media; - $(document.body).trigger("media-saved", [media, self.old_media]); - self.trigger("saved", [media, self.old_media]); + this.final_data = [media, self.old_media]; + $(document.body).trigger("media-saved", this.final_data); + setTimeout(function () { if (!media.parentNode) { return; @@ -316,10 +317,8 @@ var ImageDialog = Widget.extend({ }, save: function () { if (this.options.select_images) { - this.parent.trigger("save", this.images); return this.images; } - this.parent.trigger("save", this.media); var img = this.images[0]; if (!img) { @@ -669,7 +668,6 @@ var fontIconsDialog = Widget.extend({ */ save: function () { var self = this; - this.parent.trigger("save", this.media); var style = this.media.attributes.style ? this.media.attributes.style.value : ''; var classes = (this.media.className||"").split(/\s+/); var custom_classes = /^fa(-[1-5]x|spin|rotate-(9|18|27)0|flip-(horizont|vertic)al|fw|border)?$/; @@ -685,6 +683,8 @@ var fontIconsDialog = Widget.extend({ style = style.replace(/\s*width:[^;]+/, ''); } $(this.media).attr("class", _.compact(final_classes).join(' ')).attr("style", style); + + return this.media; }, /** * return the data font object (with base, parser and icons) or null @@ -908,7 +908,6 @@ var VideoDialog = Widget.extend({ return false; }, save: function () { - this.parent.trigger("save", this.media); var video_id = this.$("#video_id").val(); if (!video_id) { this.$("button.btn-primary").click(); @@ -922,6 +921,8 @@ var VideoDialog = Widget.extend({ ''); $(this.media).replaceWith($iframe); this.media = $iframe[0]; + + return this.media; }, clear: function () { if (this.media.dataset.src) { @@ -1096,7 +1097,7 @@ var LinkDialog = Dialog.extend({ if (classes.replace(/(^|[ ])(btn-default|btn-success|btn-primary|btn-info|btn-warning|btn-danger)([ ]|$)/gi, ' ')) { self.data.style = {'background-color': '', 'color': ''}; } - self.trigger("save", self.data); + self.final_data = self.data; }).then(_super); }, bind_data: function () { -- cgit v1.2.3