[FIX] web_editor: catch errors during save and allow to fix it

Prior to this commit, when an exception occured during the save of an
ir.ui.view, the traceback was shown to the user and an alert directly
asks the user to reload or cancel the page.

While reloading, the changes that produced the traceback were not saved
and the other modifications were saved.
If the user choose to cancel the reload, the web editor UI was freezed
and there couldn't be any edition anymore.

This commit adds correctly the popover to target the invalid element and
shows the error rather than reloading the page.
The element which caused the error can still be edited. The other are no
more editable.

task-2700198

closes odoo/odoo#87350

X-original-commit: 10b97f37ab5d78b3a2b0f63fa019ee95bb78ea7d
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Thibault Libioulle (tle) <tle@odoo.com>
This commit is contained in:
Thibault Libioulle
2022-03-29 18:21:51 +02:00
parent 6a41d1ee2d
commit 55a6f2e996
2 changed files with 15 additions and 9 deletions
+12 -5
View File
@@ -28,7 +28,8 @@ from werkzeug import urls
import odoo.modules
from odoo import api, models, fields
from odoo import _, api, models, fields
from odoo.exceptions import ValidationError
from odoo.tools import ustr, posix_to_ldml, pycompat
from odoo.tools import html_escape as escape
from odoo.tools.misc import get_lang, babel_locale_parse
@@ -181,8 +182,11 @@ class Float(models.AbstractModel):
def from_html(self, model, field, element):
lang = self.user_lang()
value = element.text_content().strip()
return float(value.replace(lang.thousands_sep, '')
.replace(lang.decimal_point, '.'))
try:
return float(value.replace(lang.thousands_sep, '')
.replace(lang.decimal_point, '.'))
except:
raise ValidationError(_('You entered an invalid value, please try again.'))
class ManyToOne(models.AbstractModel):
@@ -478,8 +482,11 @@ class Monetary(models.AbstractModel):
value = element.find('span').text.strip()
return float(value.replace(lang.thousands_sep, '')
.replace(lang.decimal_point, '.'))
try:
return float(value.replace(lang.thousands_sep, '')
.replace(lang.decimal_point, '.'))
except:
raise ValidationError(_('You entered an invalid value, please try again.'))
class Duration(models.AbstractModel):
@@ -1844,13 +1844,13 @@ const Wysiwyg = Widget.extend({
// the DOM regeneration. Add markings instead, and returns a
// new rejection with all relevant info
var id = _.uniqueId('carlos_danger_');
$el.addClass('o_dirty oe_carlos_danger ' + id);
$el.addClass('o_dirty o_editable oe_carlos_danger ' + id);
$('.o_editable.' + id)
.removeClass(id)
.popover({
trigger: 'hover',
content: response.message.data.message || '',
placement: 'auto top',
placement: 'auto',
})
.popover('show');
});
@@ -1860,8 +1860,7 @@ const Wysiwyg = Widget.extend({
window.onbeforeunload = null;
}).guardedCatch((failed) => {
// If there were errors, re-enable edition
this.cancel();
this.start();
this.cancel(false);
});
},
// TODO unused => remove or reuse as it should be