From 3aad756d32ece364ccbe0953d6acebdbe7581f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sun, 21 May 2017 09:23:27 +0200 Subject: [FIX] web: properly handles ESC in editable lists It is not really easy to handle discard operations. We need to handle the discard in editable lists, and in x2manys. This is not exactly the same code, but most of this was done by moving the discard method from the formcontroller to the basic controller. With this commit, the user can now discard the changes for the current record by pressing ESC. If the record is new, it will remove it, if not, it will ask for confirmation before. --- .../static/src/js/views/basic/basic_controller.js | 26 ++++++++++++++++++++++ 1 file changed, 26 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 4c8363a81b1..3b24df19e3e 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -18,6 +18,7 @@ var _t = core._t; var BasicController = AbstractController.extend(FieldManagerMixin, { custom_events: _.extend({}, AbstractController.prototype.custom_events, FieldManagerMixin.custom_events, { + discard_changes: '_onDiscardChanges', reload: '_onReload', sidebar_data_asked: '_onSidebarDataAsked', translate: '_onTranslate', @@ -456,6 +457,31 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { // Handlers //-------------------------------------------------------------------------- + /** + * Called when a list element asks to discard the changes made to one of + * its rows. It can happen with a x2many (if we are in a form view) or with + * a list view. + * + * @private + * @param {OdooEvent} ev + */ + _onDiscardChanges: function (ev) { + var self = this; + ev.stopPropagation(); + var recordID = ev.data.recordID; + this.discardChanges(recordID) + .done(function () { + if (self.model.isNew(recordID)) { + self._abandonRecord(recordID); + } + // TODO this will tell the renderer to rerender the widget that + // asked for the discard but will unfortunately lose the click + // made on another row if any + self._confirmChange(self.handle, [ev.data.fieldName], ev) + .always(ev.data.onSuccess); + }) + .fail(ev.data.onFailure); + }, /** * Forces to save directly the changes if the controller is in readonly, * because in that case the changes come from widgets that are editable even -- cgit v1.2.3