diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index 014aa918e54..3d2dc7a4076 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -12,7 +12,6 @@ odoo.define('web.ActionManager', function (require) { var AbstractAction = require('web.AbstractAction'); var concurrency = require('web.concurrency'); var Context = require('web.Context'); -var config = require('web.config'); var core = require('web.core'); var Dialog = require('web.Dialog'); var dom = require('web.dom'); @@ -717,6 +716,9 @@ var ActionManager = Widget.extend({ controller: controller, }); + // close all dialogs when the current controller changes + core.bus.trigger('close_dialogs'); + // toggle the fullscreen mode for actions in target='fullscreen' this._toggleFullscreen(); }, diff --git a/addons/web/static/src/js/core/dialog.js b/addons/web/static/src/js/core/dialog.js index 8f128b657d9..e3101e52bde 100644 --- a/addons/web/static/src/js/core/dialog.js +++ b/addons/web/static/src/js/core/dialog.js @@ -22,8 +22,8 @@ var Dialog = Widget.extend({ custom_events: _.extend({}, Widget.prototype.custom_events, { focus_control_button: '_onFocusControlButton', }), - events: _.extend({} , Widget.prototype.events, { - 'keydown .modal-footer button':'_onFooterButtonKeyDown', + events: _.extend({}, Widget.prototype.events, { + 'keydown .modal-footer button': '_onFooterButtonKeyDown', }), /** * @param {Widget} parent @@ -92,6 +92,8 @@ var Dialog = Widget.extend({ this.backdrop = options.backdrop; this.renderHeader = options.renderHeader; this.renderFooter = options.renderFooter; + + core.bus.on('close_dialogs', this, this.destroy.bind(this)); }, /** * Wait for XML dependencies and instantiate the modal structure (except 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 827afbb99ed..89477f9c974 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -14,7 +14,6 @@ var FormController = BasicController.extend({ custom_events: _.extend({}, BasicController.prototype.custom_events, { bounce_edit: '_onBounceEdit', button_clicked: '_onButtonClicked', - do_action: '_onDoAction', edited_list: '_onEditedList', open_one2many_record: '_onOpenOne2ManyRecord', open_record: '_onOpenRecord', @@ -543,26 +542,6 @@ var FormController = BasicController.extend({ _onDiscard: function () { this._discardChanges(); }, - /** - * Destroy subdialog widgets after an action is finished. - * - * @param {OdooEvent} ev - * @private - */ - _onDoAction: function (ev) { - var self = this; - // A priori, different widgets could write on the "on_success" key. - // Below we ensure that all the actions required by those widgets - // are executed in a suitable order before every cycle of destruction. - var callback = ev.data.on_success || function () {}; - ev.data.on_success = function () { - callback(); - function isDialog (widget) { - return (widget instanceof Dialog); - } - _.invoke(self.getChildren().filter(isDialog), 'destroy'); - }; - }, /** * Called when the user clicks on 'Duplicate Record' in the sidebar * diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 578fcfbd660..8a6675ecc58 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -23,13 +23,14 @@ QUnit.module('ActionManager', { fields: { foo: {string: "Foo", type: "char"}, bar: {string: "Bar", type: "many2one", relation: 'partner'}, + o2m: {string: "One2Many", type: "one2many", relation: 'partner', relation_field: 'bar'}, }, records: [ - {id: 1, display_name: "First record", foo: "yop", bar: 2}, - {id: 2, display_name: "Second record", foo: "blip", bar: 1}, - {id: 3, display_name: "Third record", foo: "gnap", bar: 1}, - {id: 4, display_name: "Fourth record", foo: "plop", bar: 2}, - {id: 5, display_name: "Fifth record", foo: "zoup", bar: 2}, + {id: 1, display_name: "First record", foo: "yop", bar: 2, o2m: [2, 3]}, + {id: 2, display_name: "Second record", foo: "blip", bar: 1, o2m: [1, 4, 5]}, + {id: 3, display_name: "Third record", foo: "gnap", bar: 1, o2m: []}, + {id: 4, display_name: "Fourth record", foo: "plop", bar: 2, o2m: []}, + {id: 5, display_name: "Fifth record", foo: "zoup", bar: 2, o2m: []}, ], }, pony: { @@ -512,6 +513,68 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test('executing an action with target != "new" closes all dialogs', async function (assert) { + assert.expect(4); + + this.archs['partner,false,form'] = '
'; + + var actionManager = await createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + }); + + await actionManager.doAction(3); + assert.containsOnce(actionManager, '.o_list_view'); + + await testUtils.dom.click(actionManager.$('.o_list_view .o_data_row:first')); + assert.containsOnce(actionManager, '.o_form_view'); + + await testUtils.dom.click(actionManager.$('.o_form_view .o_data_row:first')); + assert.containsOnce(document.body, '.modal .o_form_view'); + + await actionManager.doAction(1); // target != 'new' + assert.containsNone(document.body, '.modal'); + + actionManager.destroy(); + }); + + QUnit.test('executing an action with target "new" does not close dialogs', async function (assert) { + assert.expect(4); + + this.archs['partner,false,form'] = '