From 029dd1a214f727e25b479610df96b7ee94dd8127 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Tue, 20 Aug 2019 07:46:52 +0000 Subject: [IMP] web: edit translations in new dialog Before this commit, translations were edited in a list view with a filter on the field that needed to be translated. After this commit, the translations for each fields are translated in a dedicated dialog. The changes done to the current language are taken into account immediately, both ways, from the dialog to the form and from the form to the dialog. Translating terms is also available in create mode, the user will be prompted to save before editing a translation Task ID: 2028152 closes odoo/odoo#36185 Signed-off-by: VincentSchippefilt --- .../static/src/js/views/basic/basic_controller.js | 53 ++++++++++++++++------ 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_controller.js') diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 2163f074cb0..be0b9a00bf3 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -12,6 +12,7 @@ var core = require('web.core'); var Dialog = require('web.Dialog'); var FieldManagerMixin = require('web.FieldManagerMixin'); var Pager = require('web.Pager'); +var TranslationDialog = require('web.TranslationDialog'); var _t = core._t; @@ -331,6 +332,23 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var state = this.model.get(this.handle); return this.renderer.confirmChange(state, id, fields, e); }, + /** + * Ask the user to confirm he wants to save the record + * @private + */ + _confirmSaveNewRecord: function () { + var self = this; + var def = new Promise(function (resolve, reject) { + var message = _t("You need to save this new record before editing the translation. Do you want to proceed?"); + var dialog = Dialog.confirm(self, message, { + title: _t("Warning"), + confirm_callback: resolve.bind(self, true), + cancel_callback: reject, + }); + dialog.on('closed', self, reject); + }); + return def; + }, /** * Delete records (and ask for confirmation if necessary) * @@ -789,28 +807,35 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * @private * @param {OdooEvent} ev */ - _onTranslate: function (ev) { + _onTranslate: async function (ev) { ev.stopPropagation(); - var self = this; - var record = this.model.get(ev.data.id, {raw: true}); - this._rpc({ + + if (this.model.isNew(ev.data.id)) { + await this._confirmSaveNewRecord(); + var updatedFields = await this.saveRecord(ev.data.id, { stayInEdit: true }); + await this._confirmChange(ev.data.id, updatedFields, ev); + } + var record = this.model.get(ev.data.id, { raw: true }); + var result = await this._rpc({ route: '/web/dataset/call_button', params: { model: 'ir.translation', method: 'translate_fields', args: [record.model, record.res_id, ev.data.fieldName], - kwargs: {context: record.getContext()}, + kwargs: { context: record.getContext() }, } - }).then(function (result) { - self.do_action(result, { - on_reverse_breadcrumb: function () { - if (!_.isEmpty(self.renderer.alertFields)) { - self.renderer.displayTranslationAlert(); - } - return false; - }, - }); }); + + this.translationDialog = new TranslationDialog(this, { + domain: result.domain, + searchName: result.context.search_default_name, + fieldName: record.fieldsInfo[record.viewType][ev.data.fieldName].name, + userLanguageValue: ev.target.value || '', + dataPointID: record.id, + isComingFromTranslationAlert: ev.data.isComingFromTranslationAlert, + isText: record.fields[ev.data.fieldName].type === 'text', + }); + return this.translationDialog.open(); }, }); -- cgit v1.2.3