From 1a0702f1e20a8347a1135ade60858f5905bbca2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 27 Feb 2017 16:15:54 +0100 Subject: [FIX] web: properly handles dirty data in form views Before this commit, we only consider the BasicModel point of view to determine if a record is dirty. It is good when we want to determine if it is actually necessary to save the data, but not correct when we want to know if some changes can be discarded. With this commit, the form controller keeps track of its 'dirty' state, coming from user interactions. It uses this flag to determine if changes can be discarded. --- addons/web/static/src/js/views/basic/basic_controller.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (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 24b5c7fa3d0..2847003f5df 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -33,6 +33,7 @@ return AbstractController.extend(FieldManagerMixin, { this.hasButtons = params.hasButtons; FieldManagerMixin.init.call(this, this.model); this.handle = params.initialState.id; + this.isDirty = false; }, /** * @override @@ -148,6 +149,18 @@ return AbstractController.extend(FieldManagerMixin, { // Handlers //-------------------------------------------------------------------------- + /** + * We need to keep manually track of the isDirty property. Note that it is + * not the same as the one from the basic model. A new record from the + * basic model is considered dirty, but from the controller point of view, + * there was no user interaction and should not be dirty. + * + * @private + */ + _onFieldChanged: function () { + this.isDirty = true; + FieldManagerMixin._onFieldChanged.apply(this, arguments); + }, /** * When a reload event triggers up, we need to reload the full view. * For example, after a form view dialog saved some data. -- cgit v1.2.3