From 9100e675dfe7ae60ea3c8f1a5ef1e9a78a4ab4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sun, 2 Apr 2017 21:04:31 +0200 Subject: [FIX] web: add support for discarding lines in o2m This is not a complete work, but it introduces the basic infrastructure to properly edit various more sophisticated editing behaviours. The main focus of this commit is to handle discarding invalid lines in one2many, potentially asking the user for confirmation. So, the relevant methods have to be modified to return some deferred, because the operation is now asynchronous. --- .../web/static/src/js/fields/relational_fields.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index c29f958cc06..4ae30264ff0 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -560,6 +560,28 @@ var FieldX2Many = AbstractField.extend({ isSet: function () { return true; }, + /** + * This is a tricky override. For relational fields, we don't just need to + * know if the field is valid. We also need to discard some invalid lines, + * if the user is ok with it (or automatically if the invalid line is not + * dirty). This is the reason why we need to change the signature of the + * AbstractField isValid method to optionally return a deferred. + * + * @override + * @returns {boolean|Deferred} if there is a renderer (sub list or kanban + * view), we may need to ask the user => it will return a deferred. + * Otherwise, it returns a boolean + */ + isValid: function () { + if (!this.renderer) { + return this._super.apply(this, arguments); + } + var def = $.Deferred(); + this.renderer.canBeSaved() + .then(def.resolve.bind(def, true)) + .fail(def.resolve.bind(def, false)); + return def; + }, //-------------------------------------------------------------------------- // Private -- cgit v1.2.3