From a4a54ab8387b68b4477ba3b22bc974ebd349b0d3 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 18 Jan 2018 11:15:01 +0100 Subject: [PATCH] [FIX] web: change a param of a client action in the url Before this rev., an error occurred when the user changed a param of the url when being in a client action. For instance, open Discuss, go to 'Starred', then click on the 'Back' arrow of the browser. The error occurred because the code made the assumption that the current action was an ir.actions.act_window. --- .../js/chrome/action_manager_act_window.js | 8 ++- .../tests/chrome/action_manager_tests.js | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/chrome/action_manager_act_window.js b/addons/web/static/src/js/chrome/action_manager_act_window.js index a37b37fca73..04322237d7a 100644 --- a/addons/web/static/src/js/chrome/action_manager_act_window.js +++ b/addons/web/static/src/js/chrome/action_manager_act_window.js @@ -45,11 +45,15 @@ ActionManager.include({ */ loadState: function (state) { var action; - var options = {pushState: false}; + var options = { + clear_breadcrumbs: true, + pushState: false, + }; if (state.action) { var currentController = this.getCurrentController(); var currentAction = currentController && this.actions[currentController.actionID]; - if (currentAction && currentAction.id === state.action) { + if (currentAction && currentAction.id === state.action && + currentAction.type === 'ir.actions.act_window') { // the action to load is already the current one, so update it this._closeDialog(true); // there may be a currently opened dialog, close it currentAction.env.currentId = state.id; diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 445cd19c128..28fed6fb2d5 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -87,6 +87,11 @@ QUnit.module('ActionManager', { res_model: 'pony', type: 'ir.actions.act_window', views: [[false, 'list'], [false, 'form']], + }, { + id: 9, + name: 'A Client Action', + tag: 'ClientAction', + type: 'ir.actions.client', }]; this.archs = { @@ -774,6 +779,59 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test('change a param of an ir.actions.client in the url', function (assert) { + assert.expect(7); + + var ClientAction = Widget.extend(ControlPanelMixin, { + className: 'o_client_action', + init: function (parent, action) { + this._super.apply(this, arguments); + var context = action.context; + this.a = context.params && context.params.a || 'default value'; + }, + start: function () { + assert.step('start'); + this.$el.text(this.a); + this.trigger_up('push_state', { + controllerID: this.controllerID, + state: {a: this.a}, + }); + }, + }); + core.action_registry.add('ClientAction', ClientAction); + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + }); + + // execute the client action + actionManager.doAction(9); + + assert.strictEqual(actionManager.$('.o_client_action').text(), 'default value', + "should have rendered the client action"); + assert.strictEqual($('.o_control_panel .breadcrumb li').length, 1, + "there should be one controller in the breadcrumbs"); + + // update param 'a' in the url + actionManager.loadState({ + action: 9, + a: 'new value', + }); + + assert.strictEqual(actionManager.$('.o_client_action').text(), 'new value', + "should have rerendered the client action with the correct param"); + assert.strictEqual($('.o_control_panel .breadcrumb li').length, 1, + "there should still be one controller in the breadcrumbs"); + + // should have executed the client action twice + assert.verifySteps(['start', 'start']); + + actionManager.destroy(); + delete core.action_registry.map.ClientAction; + }); + QUnit.module('Concurrency management'); QUnit.test('drop previous actions if possible', function (assert) {