[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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user