From cae188514fa8b0a7c785a630ac4aff677b2071fa Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 27 Nov 2017 10:07:28 +0100 Subject: [PATCH] [FIX] web_editor: Fieldtexthtml wait until iframe loaded to save In the case where: - you are too fast editing a mass mailing, trigger an onchange (e.g. mailing_model) and then save You can use the edit/save shortcuts to make yourself believe you are Flash Gordon - your internet is too slow (Down: 4Mb/s, Up: 500kb/s, Latency: 20ms) Before ths commit, the onchange will return *before* the field (the iframe actually) is loaded. This onchange contains a signal *in* the body_html of the field to allow communication with the iframe. If you save before the iframe is loaded, this body_html keyword will be saved. After this commit we deactivate the save button until the iframe is loaded. We could have gone for a python user error on the value of the body_html too. But it would have added a supplementary click and potential reloading OPW 783616 --- addons/web_editor/static/src/js/backend.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 94c6e8057c0..2b3c0e0790c 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -293,6 +293,8 @@ var FieldTextHtml = widget.extend({ var self = this; this.$el.closest('.modal-body').css('max-height', 'none'); this.$iframe = this.$el.find('iframe'); + // deactivate any button to avoid saving a not ready iframe + $('.o_cp_buttons, .o_statusbar_buttons').find('button').addClass('o_disabled').attr('disabled', true); this.document = null; this.$body = $(); this.$content = $(); @@ -318,6 +320,8 @@ var FieldTextHtml = widget.extend({ this.lang = this.lang ? this.lang[1] : this.view.dataset.context.lang; this._dirty_flag = false; this.render_value(); + // reactivate all the buttons when the field's content (the iframe) is loaded + $('.o_cp_buttons, .o_statusbar_buttons').find('button').removeClass('o_disabled').attr('disabled', false); setTimeout(function () { self.add_button(); setTimeout(self.resize,0);