diff options
| author | Tejas Shahu <tsh@odoo.com> | 2018-08-20 13:27:54 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2019-01-24 11:14:55 +0000 |
| commit | a63a953a2dd216d313a7adaeb21345f5258247fa (patch) | |
| tree | 0c89ef8a94d403ded3ff099c7f7a6d3cdf2b73ea /addons/web/static/src | |
| parent | fab415acabf409538943aee9dec00c677caa43d6 (diff) | |
[FIX] web: translation issue fixed
Before this commit:
Editing a translatable field -> clicking on a translation
warning ->
come back through breadcrumb do not preserve translation
warning.
After this commit:
Editing a translatable field -> clicking on a translation
warning ->
come back through breadcrumb preserves translation warning.
Technical note: alertFields is now an object and an attribute
of the form renderer
that stores translation alerts per record. The translation
alerts
created for a given record are maintained unless
they are closed manually or the renderer is destroyed.
Issue-ID: 1877480
Co-authored-by: Mohammed Shekha <msh@openerp.com>
closes odoo/odoo#29377
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/views/form/form_controller.js | 9 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/form/form_renderer.js | 45 | ||||
| -rw-r--r-- | addons/web/static/src/xml/base.xml | 2 |
3 files changed, 39 insertions, 17 deletions
diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js index 625bca3cc5e..6b6baa1ec74 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -216,17 +216,16 @@ var FormController = BasicController.extend({ // are displayed with an alert var fields = self.renderer.state.fields; var data = self.renderer.state.data; - var alertFields = []; + var alertFields = {}; for (var k = 0; k < changedFields.length; k++) { var field = fields[changedFields[k]]; var fieldData = data[changedFields[k]]; if (field.translate && fieldData) { - alertFields.push(field); + alertFields[changedFields[k]] = field; } } - if (alertFields.length) { - self.renderer.alertFields = alertFields; - self.renderer.displayTranslationAlert(); + if (!_.isEmpty(alertFields)) { + self.renderer.updateAlertFields(alertFields); } } return changedFields; diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js index 232da4d25c1..6ceafa5d43b 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -13,6 +13,7 @@ var FormRenderer = BasicRenderer.extend({ className: "o_form_view", events: _.extend({}, BasicRenderer.prototype.events, { 'click .o_notification_box .oe_field_translate': '_onTranslate', + 'click .o_notification_box .close': '_onTranslateNotificationClose', 'click .oe_title, .o_inner_group': '_onClick', }), custom_events: _.extend({}, BasicRenderer.prototype.custom_events, { @@ -30,6 +31,7 @@ var FormRenderer = BasicRenderer.extend({ this._super.apply(this, arguments); this.idsForLabels = {}; this.lastActivatedFieldIndex = -1; + this.alertFields = {}; }, /** * @override @@ -103,23 +105,32 @@ var FormRenderer = BasicRenderer.extend({ }); return fieldNames; }, + /* + * Updates translation alert fields for the current state and display updated fields + * + * @param {Object} alertFields + */ + updateAlertFields: function (alertFields) { + this.alertFields[this.state.res_id] = _.extend(this.alertFields[this.state.res_id] || {}, alertFields); + this.displayTranslationAlert(); + }, /** * 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. - * - * @param {Object[]} alertFields field list */ displayTranslationAlert: function () { this.$('.o_notification_box').remove(); - var $notification = $(qweb.render('notification-box', {type: 'info'})) - .append(qweb.render('translation-alert', { - fields: this.alertFields, - lang: _t.database.parameters.name - })); - if (this.$('.o_form_statusbar').length) { - this.$('.o_form_statusbar').after($notification); - } else { - this.$el.prepend($notification); + if (this.alertFields[this.state.res_id]) { + var $notification = $(qweb.render('notification-box', {type: 'info'})) + .append(qweb.render('translation-alert', { + fields: this.alertFields[this.state.res_id], + lang: _t.database.parameters.name + })); + if (this.$('.o_form_statusbar').length) { + this.$('.o_form_statusbar').after($notification); + } else { + this.$el.prepend($notification); + } } }, /** @@ -865,6 +876,9 @@ var FormRenderer = BasicRenderer.extend({ return $.when.apply($, defs).then(function () { self._updateView($form.contents()); + if (self.state.res_id in self.alertFields) { + self.displayTranslationAlert(); + } }, function () { $form.remove(); }).then(function(){ @@ -970,6 +984,15 @@ var FormRenderer = BasicRenderer.extend({ event.preventDefault(); this.trigger_up('translate', {fieldName: event.target.name, id: this.state.id}); }, + /** + * remove alert fields of record from alertFields object + * + * @private + * @param {MouseEvent} ev + */ + _onTranslateNotificationClose: function(ev) { + delete this.alertFields[this.state.res_id]; + }, }); return FormRenderer; diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 49c3aa73b6e..26fad2dfd40 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1326,7 +1326,7 @@ <div> Please update translations of : <t t-foreach="fields" t-as="field"> - <strong><a class="oe_field_translate" t-att-name="field.name" href="#"><t t-esc="field.string"/><t t-if="!field_last">, </t></a></strong> + <strong><a class="oe_field_translate" t-att-name="field" href="#"><t t-esc="field_value.string"/><t t-if="field_index < _.size(fields)-1">, </t></a></strong> </t> </div> </t> |
