diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-05-04 16:56:57 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2017-05-08 14:02:40 +0200 |
| commit | 0764bc41aa0d28e2a6dcbf6d169d3f8ea092a627 (patch) | |
| tree | 4d2343bc2f7c856f8badf9d0dc16ff1cdbd04ae8 /addons/web/static/src/js/views/basic/basic_controller.js | |
| parent | c8d77f93e5a857acd22025f4a8d4d42d674479d1 (diff) | |
[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).
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.js | 23 |
1 files changed, 12 insertions, 11 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 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 |
