From b5d0cde0fcb77625e9a04f452f67edfa9bd55d19 Mon Sep 17 00:00:00 2001 From: NetItUp-CarloToso Date: Thu, 21 Dec 2023 11:17:02 +0000 Subject: [PATCH 1/2] fix formatting --- .../static/src/views/form/form_controller.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/edit_save_button/static/src/views/form/form_controller.js b/edit_save_button/static/src/views/form/form_controller.js index 6c9156329..a94948397 100644 --- a/edit_save_button/static/src/views/form/form_controller.js +++ b/edit_save_button/static/src/views/form/form_controller.js @@ -18,14 +18,14 @@ const viewRegistry = registry.category("views"); odoo.__DEBUG__ && console.log("Console log inside the patch function", FormController.prototype, "form_controller"); var data = false; -patch(FormController.prototype, "save",{ +patch(FormController.prototype, "save", { setup() { data = false; this.props.preventEdit = !data this._super(); }, - async edit(){ + async edit() { this._super(); data = true; await this.model.root.switchMode("edit"); @@ -35,20 +35,20 @@ patch(FormController.prototype, "save",{ data = false; await this.model.root.switchMode("readonly"); }, - async discard(){ + async discard() { this._super(); data = false; await this.model.root.switchMode("readonly"); }, - async beforeLeave() { + async beforeLeave() { if (this.model.root.isDirty) { if (confirm("The changes you have made will save Automatically!")) { - return this.model.root.save({noReload: true, stayInEdition: true}); + return this.model.root.save({ noReload: true, stayInEdition: true }); } else { this.model.root.discard(); return true; } } - } + } }) From e61ad9edce254bfa57c7eabf98026daaed01b060 Mon Sep 17 00:00:00 2001 From: NetItUp-CarloToso Date: Thu, 21 Dec 2023 11:18:41 +0000 Subject: [PATCH 2/2] only switch to readonly if save is successful --- edit_save_button/static/src/views/form/form_controller.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/edit_save_button/static/src/views/form/form_controller.js b/edit_save_button/static/src/views/form/form_controller.js index a94948397..019460aa1 100644 --- a/edit_save_button/static/src/views/form/form_controller.js +++ b/edit_save_button/static/src/views/form/form_controller.js @@ -30,10 +30,12 @@ patch(FormController.prototype, "save", { data = true; await this.model.root.switchMode("edit"); }, - async saveButtonClicked(params = {}){ - this._super(); + async saveButtonClicked(params = {}) { + let saved = await this._super(); data = false; - await this.model.root.switchMode("readonly"); + if (saved) { + await this.model.root.switchMode("readonly"); + } }, async discard() { this._super();