From 1c5ea99b7b82c2b6f28ad1a3dbffc1300fda6466 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 4 May 2017 13:27:31 +0200 Subject: [FIX] web: display a translation alert when saving the form view In the form view, when the user saves a record (with a multilang instance), an alert is displayed to display all modified translatable fields. --- .../static/src/js/views/basic/basic_controller.js | 42 +++++++++++++++++----- 1 file changed, 33 insertions(+), 9 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 f1e71bcfd5a..4b38ac69403 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -19,7 +19,8 @@ var _t = core._t; var BasicController = AbstractController.extend(FieldManagerMixin, { custom_events: _.extend({}, AbstractController.prototype.custom_events, FieldManagerMixin.custom_events, { reload: '_onReload', - sidebar_data_asked: '_onSidebarDataAsked' + sidebar_data_asked: '_onSidebarDataAsked', + translate: '_onTranslate', }), /** * @override @@ -169,6 +170,8 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * @param {string} [recordID] - default to main recordID * @param {Object} [options] * @returns {Deferred} + * Resolved with the list of field names (whose value has been modified) + * Rejected if the record can't be saved */ saveRecord: function (recordID, options) { // Some field widgets can't detect (all) their changes immediately or @@ -367,6 +370,8 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * if true, the record will only be 'locally' saved: its changes * will move from the _changes key to the data key * @returns {Deferred} + * Resolved with the list of field names (whose value has been modified) + * Rejected if the record can't be saved */ _saveRecord: function (recordID, options) { recordID = recordID || this.handle; @@ -376,22 +381,24 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { savePoint: false, }); - var def = $.Deferred(); // Check if the view is in a valid state for saving // Note: it is the model's job to do nothing if there is nothing to save if (this.canBeSaved(recordID)) { - def = this.model.save(recordID, { // Save then leave edit mode + var self = this; + var def = this.model.save(recordID, { // Save then leave edit mode reload: options.reload, savePoint: options.savePoint, }); - } else { - def.reject(); // Cannot be saved, do nothing at all - } - - if (options.stayInEdit) { + if (!options.stayInEdit) { + def = def.then(function (fieldNames) { + return self._confirmSave(recordID).then(function () { + return fieldNames; + }); + }); + } return def; } else { - return def.then(this._confirmSave.bind(this, recordID)); + return $.Deferred().reject(); // Cannot be saved } }, /** @@ -498,6 +505,23 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var sidebarEnv = this._getSidebarEnv(); event.data.callback(sidebarEnv); }, + /** + * open the translation view for the current field + * + * @private + * @param {OdooEvent} event + */ + _onTranslate: function (event) { + var record = this.model.get(event.data.id, {raw: true}); + this._rpc({ + route: '/web/dataset/call_button', + params: { + model: 'ir.translation', + method: 'translate_fields', + args: [record.model, record.res_id, event.data.fieldName, record.getContext()], + } + }).then(this.do_action.bind(this)); + }, }); return BasicController; -- cgit v1.2.3