[FIX] web_editor, website, *: editor notify method must be synchronous

* website_form

Some technical explanations:

The method became async because the `setTarget` call which was in there
became `async` since it performed an UI update. As this method being
async is a problem with some snippets, it is best to keep it synchronous
for now. For this, the UI update in `setTarget` is removed and becomes
the responsibility of the caller. Nothing relied on it except one code,
which is solved by calling `onFocus` before the UI update which occurs
on focus, as it is already the case in master.

closes odoo/odoo#44850

X-original-commit: 53bba0660237abbcadc9675fd89ec94a2a31e130
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2020-02-07 12:43:25 +00:00
parent 91fb0d3020
commit ef03b02af6
3 changed files with 13 additions and 12 deletions
@@ -1676,9 +1676,9 @@ const SnippetOptionWidget = Widget.extend({
* @param {*} data
* @returns {Promise}
*/
notify: async function (name, data) {
notify: function (name, data) {
if (name === 'target') {
await this.setTarget(data);
this.setTarget(data);
}
},
/**
@@ -1687,12 +1687,13 @@ const SnippetOptionWidget = Widget.extend({
* per-slide options to be in the main menu of the whole snippet. This
* function allows to set the option's target.
*
* Note: the UI is not updated accordindly automatically.
*
* @param {jQuery} $target - the new target element
* @returns {Promise}
*/
setTarget: async function ($target) {
setTarget: function ($target) {
this.$target = $target;
await this.updateUI();
},
/**
* Updates the UI. For widget update, @see _computeWidgetState.
@@ -2290,8 +2291,8 @@ registry.sizing = SnippetOptionWidget.extend({
/**
* @override
*/
setTarget: async function () {
await this._super(...arguments);
setTarget: function () {
this._super(...arguments);
this._onResize();
},
/**
@@ -2471,8 +2472,8 @@ registry.background = SnippetOptionWidget.extend({
/**
* @override
*/
setTarget: async function () {
await this._super(...arguments);
setTarget: function () {
this._super(...arguments);
// TODO should be automatic for all options as equal to the start method
this.bindBackgroundEvents();
this.__customImageSrc = this._getSrcFromCssValue();
@@ -294,8 +294,8 @@ options.registry.gallery = options.Class.extend({
*
* @override
*/
notify: async function (name, data) {
await this._super(...arguments);
notify: function (name, data) {
this._super(...arguments);
if (name === 'image_removed') {
data.$image.remove(); // Force the removal of the image before reset
this.mode('reset', this.getMode());
@@ -403,8 +403,8 @@ options.registry.WebsiteFormEditor = FormEditor.extend({
/**
* @override
*/
notify: async function (name, data) {
await this._super(...arguments);
notify: function (name, data) {
this._super(...arguments);
if (name === 'field_mark') {
this._setLabelsMark();
} else if (name === 'add_field') {