summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_controller.js
diff options
context:
space:
mode:
authorVincent Schippefilt <vsc@odoo.com>2019-08-20 07:46:52 +0000
committerVincent Schippefilt <vsc@odoo.com>2019-09-09 13:09:53 +0000
commit029dd1a214f727e25b479610df96b7ee94dd8127 (patch)
tree5b33cb401962523f20c768043def21a7b0349cfc /addons/web/static/src/js/views/basic/basic_controller.js
parent263849c3365af3d62fa5b9ceaff65b2f7b84c092 (diff)
[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 <VincentSchippefilt@users.noreply.github.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_controller.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js53
1 files changed, 39 insertions, 14 deletions
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;
@@ -332,6 +333,23 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
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)
*
* @param {string[]} ids list of local record ids
@@ -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();
},
});