Permalink
Browse files

[FIX]web: translation field warning method issue has been fixed

Before this commit:
After transating any field, transalation warning could not be opened for transalation.

Afte this commit:
Transalation can be done of any field from transalation warning form view. History of multiple translation pages have also been maintained until page roload.

Issue-ID: 1877480

Co-authored-by: Mohammed Shekha <msh@openerp.com>
  • Loading branch information...
tsh-odoo and msh-odoo committed Aug 20, 2018
1 parent b87879c commit aa1794a752115a3ad79e19fbc525fdea814f2b86
@@ -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;
@@ -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,17 +105,24 @@ 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,
fields: this.alertFields[this.state.res_id],
lang: _t.database.parameters.name
}));
if (this.$('.o_form_statusbar').length) {
@@ -865,6 +874,9 @@ var FormRenderer = BasicRenderer.extend({

return $.when.apply($, defs).then(function () {
self._updateView($form.contents());
if (!_.isEmpty(self.alertFields) && self.state.res_id in self.alertFields) {
self.displayTranslationAlert();
}
}, function () {
$form.remove();
}).then(function(){
@@ -970,6 +982,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;
@@ -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 &lt; _.size(fields)-1">, </t></a></strong>
</t>
</div>
</t>
@@ -5472,9 +5472,10 @@ QUnit.module('Views', {
});

QUnit.test('display translation alert', function (assert) {
assert.expect(1);
assert.expect(2);

this.data.partner.fields.foo.translate = true;
this.data.partner.fields.display_name.translate = true;

var multi_lang = _t.database.multi_lang;
_t.database.multi_lang = true;
@@ -5487,6 +5488,7 @@ QUnit.module('Views', {
'<sheet>' +
'<group>' +
'<field name="foo"/>' +
'<field name="display_name"/>' +
'</group>' +
'</sheet>' +
'</form>',
@@ -5496,14 +5498,66 @@ QUnit.module('Views', {
form.$buttons.find('.o_form_button_edit').click();
form.$('input[name="foo"]').val("test").trigger("input");
form.$buttons.find('.o_form_button_save').click();
assert.strictEqual(form.$('.o_form_view > .alert > div .oe_field_translate').length, 1,"should have single translation alert");

assert.strictEqual(form.$('.o_form_view > .alert > div').length, 1,"should have a translation alert");
form.$buttons.find('.o_form_button_edit').click();
form.$('input[name="display_name"]').val("test2").trigger("input");
form.$buttons.find('.o_form_button_save').click();
assert.strictEqual(form.$('.o_form_view > .alert > div .oe_field_translate').length, 2,"should have two translate fields in translation alert");

form.destroy();

_t.database.multi_lang = multi_lang;
});

QUnit.test('translation alert are preserved on pager change', function (assert) {
assert.expect(5);

this.data.partner.fields.foo.translate = true;

var multi_lang = _t.database.multi_lang;
_t.database.multi_lang = true;

var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="foo"/>' +
'</sheet>' +
'</form>',
viewOptions: {
ids: [1, 2],
index: 0,
},
res_id: 1,
});

form.$buttons.find('.o_form_button_edit').click();
form.$('input[name="foo"]').val("test").trigger("input");
form.$buttons.find('.o_form_button_save').click();

assert.strictEqual(form.$('.o_form_view > .alert > div').length, 1, "should have a translation alert");

// click on the pager to switch to the next record
form.pager.$('.o_pager_next').click();
assert.strictEqual(form.$('.o_form_view > .alert > div').length, 0, "should not have a translation alert");

// click on the pager to switch back to the previous record
form.pager.$('.o_pager_previous').click();
assert.strictEqual(form.$('.o_form_view > .alert > div').length, 1, "should have a translation alert");

// remove translation alert by click X and check alert even after form reload
form.$('.o_form_view > .alert > .close').click();
assert.strictEqual(form.$('.o_form_view > .alert > div').length, 0, "should not have a translation alert");
form.reload();
assert.strictEqual(form.$('.o_form_view > .alert > div').length, 0, "should not have a translation alert after reload");

form.destroy();
_t.database.multi_lang = multi_lang;
});

QUnit.test('translate event correctly handled with multiple controllers', function (assert) {
assert.expect(3);

0 comments on commit aa1794a

Please sign in to comment.