From 0764bc41aa0d28e2a6dcbf6d169d3f8ea092a627 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 4 May 2017 16:56:57 +0200 Subject: [FIX] web: list rendering was not properly updated after discard Before this commit, when hitting the "Discard" button in an editable list view, the line switched to readonly mode but with the undiscarded data (even though the data was properly discarded and not saved). Fortunately, the fix is in fact making the save/discard/update system more consistent. Here are some reasons why: - the `_confirmSave` method is now used after a save or a discard (while it was before only called on readonly views where a change was made by a special field widget). - Abandonning a record (discarding a new unsaved one), is now the responsability of `discardChanges` (and not `_setMode`). - The renderer `updateState` method is used when its state is updated. - ... Note that setting the renderer mode is now taking care of deferreds properly (the widgets deferred are now considered when switching a row to readonly/edit mode). --- .../static/src/js/views/basic/basic_controller.js | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 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 b7cd40d9e7c..f1e71bcfd5a 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -118,13 +118,18 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var self = this; recordID = recordID || this.handle; return this.canBeDiscarded(recordID).then(function (needDiscard) { + if (options && options.readonlyIfRealDiscard && !needDiscard) { + return; + } + if (needDiscard) { // Just some optimization self.model.discardChanges(recordID); } - if (options && options.readonlyIfRealDiscard && !needDiscard) { + if (self.model.isNew(recordID)) { + self._abandonRecord(recordID); return; } - self._setMode('readonly', recordID); + return self._confirmSave(recordID); }); }, /** @@ -386,7 +391,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { if (options.stayInEdit) { return def; } else { - return def.then(this._setMode.bind(this, 'readonly', recordID)); + return def.then(this._confirmSave.bind(this, recordID)); } }, /** @@ -397,17 +402,13 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * @private * @param {string} mode - 'readonly' or 'edit' * @param {string} [recordID] + * @returns {Deferred} */ _setMode: function (mode, recordID) { - recordID = recordID || this.handle; - // If trying to make a temporary record readonly, discard the record - if (mode === 'readonly' && this.model.isNew(recordID)) { - this._abandonRecord(recordID); - return; - } - if (recordID === this.handle) { - this.update({mode: mode}, {reload: false}); + if ((recordID || this.handle) === this.handle) { + return this.update({mode: mode}, {reload: false}); } + return $.when(); }, /** * Helper method, to get the current environment variables from the model -- cgit v1.2.3 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 From a0217f4475b02660fc687d154f1287029ed0e23d Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Fri, 12 May 2017 13:22:01 +0200 Subject: [FIX] web: BasicModel: update parent data after record deletion After the record deletion, the parent should be updated to take the deletion into account. This was causing an issue in the Kanban view: after a column deletion, it appeared again if you created a new one. --- addons/web/static/src/js/views/basic/basic_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 4b38ac69403..1e0187b348e 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -294,7 +294,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var self = this; function doIt() { return self.model - .deleteRecords(ids, self.modelName, self.handle) + .deleteRecords(ids, self.modelName) .then(self._onDeletedRecords.bind(self, ids)); } if (this.confirmOnDelete) { -- cgit v1.2.3