From ef6b330d8fe298f30cfac6244d8795ff9ab5f19b Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Wed, 5 Apr 2017 16:13:42 +0200 Subject: [PATCH] [FIX] web: Form: avoid to change mode on button click When clicking on a button in a form view, the current data should be saved but the form view shouldn't be re-rendered in readonly. Before this commit, the view was re-rendered, causing a weird glitch in dialogs as buttons that were supposed to be moved to the dialog's footer appeared inside the view when the button was clicked. Also forces the default mode in form view to readonly, so that it is correctly redrawn in readonly when coming back using the breadcrumbs. --- addons/web/static/src/js/chrome/view_manager.js | 4 +++- addons/web/static/src/js/views/form/form_controller.js | 3 ++- addons/web/static/test/views/form_tests.js | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/js/chrome/view_manager.js b/addons/web/static/src/js/chrome/view_manager.js index d8f0e3776d9..c3835686e11 100644 --- a/addons/web/static/src/js/chrome/view_manager.js +++ b/addons/web/static/src/js/chrome/view_manager.js @@ -286,7 +286,9 @@ var ViewManager = Widget.extend(ControlPanelMixin, { }).fail(view.loaded.reject.bind(view.loaded)); } else { view.loaded = view.loaded.then(function() { - view_options = _.extend({}, view_options, self.env); + // By default, the view will be loaded in readonly mode + // Returns to this default mode if you load action from breadcrumb + view_options = _.extend({mode: 'readonly'}, view_options, self.env); return view.controller.reload(view_options); }); } diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js index 9bb1aaaaacf..d73c5cb0ef1 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -452,7 +452,8 @@ var FormController = BasicController.extend({ } else if (attrs.special) { def = this._callButtonAction(attrs, event.data.record); } else { - def = this.saveRecord().then(function () { + // save the record but don't switch to readonly mode + def = this.saveRecord({stayInEdit: true}).then(function () { return self._callButtonAction(attrs, event.data.record); }); } diff --git a/addons/web/static/test/views/form_tests.js b/addons/web/static/test/views/form_tests.js index 4bc4e73a5a6..83f337e7799 100644 --- a/addons/web/static/test/views/form_tests.js +++ b/addons/web/static/test/views/form_tests.js @@ -1113,14 +1113,13 @@ QUnit.module('Views', { }); form.$('.oe_stat_button').first().click(); assert.strictEqual(count, 1, "should have triggered a execute action"); - assert.strictEqual(form.mode, "readonly", "form view should be in readonly mode"); + assert.strictEqual(form.mode, "edit", "form view should be in edit mode"); - form.$buttons.find('.o_form_button_edit').click(); form.$('input').val("tralala").trigger('input'); form.$('.oe_stat_button').first().click(); - assert.strictEqual(form.mode, "readonly", "form view should be in readonly mode"); + assert.strictEqual(form.mode, "edit", "form view should be in edit mode"); assert.strictEqual(count, 2, "should have triggered a execute action"); form.destroy(); });