[IMP] web: display message to edit translations when translated fields have been modified
This commit is contained in:
committed by
Raphael Collet
parent
4b768b3ba0
commit
cb835f8a3b
@@ -648,8 +648,8 @@ class WebClient(http.Controller):
|
||||
ids = res_lang.search(request.cr, uid, [("code", "=", lang)])
|
||||
lang_params = None
|
||||
if ids:
|
||||
lang_params = res_lang.read(request.cr, uid, ids[0], ["direction", "date_format", "time_format",
|
||||
"grouping", "decimal_point", "thousands_sep"])
|
||||
lang_params = res_lang.read(request.cr, uid, ids[0],
|
||||
["name", "direction", "date_format", "time_format", "grouping", "decimal_point", "thousands_sep"])
|
||||
|
||||
# Regional languages (ll_CC) must inherit/override their parent lang (ll), but this is
|
||||
# done server-side when the language is loaded, so we only need to load the user's lang.
|
||||
|
||||
@@ -905,6 +905,7 @@ var FormView = View.extend(common.FieldManagerMixin, {
|
||||
if (!self.datarecord.id) {
|
||||
// Creation save
|
||||
save_deferral = self.dataset.create(values, {readonly_fields: readonly_values}).then(function(r) {
|
||||
self.display_translation_alert(values);
|
||||
return self.record_created(r, prepend_on_create);
|
||||
}, null);
|
||||
} else if (_.isEmpty(values)) {
|
||||
@@ -913,6 +914,7 @@ var FormView = View.extend(common.FieldManagerMixin, {
|
||||
} else {
|
||||
// Write save
|
||||
save_deferral = self.dataset.write(self.datarecord.id, values, {readonly_fields: readonly_values}).then(function(r) {
|
||||
self.display_translation_alert(values);
|
||||
return self.record_saved(r);
|
||||
}, null);
|
||||
}
|
||||
@@ -1072,6 +1074,32 @@ var FormView = View.extend(common.FieldManagerMixin, {
|
||||
sidebar_eval_context: function () {
|
||||
return $.when(this.build_eval_context());
|
||||
},
|
||||
/*
|
||||
* Show a warning message if the user modified a translated field. For each
|
||||
* field, the notification provides a link to edit the field's translations.
|
||||
*/
|
||||
display_translation_alert: function(values) {
|
||||
if (_t.database.multi_lang) {
|
||||
var alert_fields = _.filter(this.translatable_fields, function(field) {
|
||||
return _.has(values, field.name)
|
||||
});
|
||||
if (alert_fields.length) {
|
||||
var $content = $(QWeb.render('translation-alert', {
|
||||
fields: alert_fields,
|
||||
lang: _t.database.parameters.name
|
||||
}));
|
||||
// bind click event on "Update translations" links
|
||||
$content.find('.oe_field_translate').click(function(ev) {
|
||||
ev.preventDefault();
|
||||
_.find(alert_fields, {'name': ev.target.name}).on_translate();
|
||||
});
|
||||
// show notification
|
||||
this.once('to_view_mode', this, function () {
|
||||
this.notify_in_form($content);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Add a notification box inside the form. The notification automatically
|
||||
* goes away (by default when switching to edit mode or changing the form
|
||||
|
||||
@@ -1464,4 +1464,13 @@
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="translation-alert">
|
||||
<t t-foreach="fields" t-as="field">
|
||||
<div>
|
||||
You have updated <strong><t t-esc="field.string"/></strong> (<t t-esc="lang"/>).
|
||||
<a class="oe_field_translate" t-att-name="field.name" href="#">Update translations</a>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
||||
Reference in New Issue
Block a user