[FIX] web: update breadcrumbs when switching view

To reproduce:
 1. go on list view
 2. open record in form view
 3. come back on list view
 4. switch to kanban
 5. open record in form view
 6. click on breadcrumb

Before this rev. we were back on the list view, and not the kanban view.

This is due to the fact that the breadcrumb was not updated when switching view,
(if a controller was already existing) so the form view control panel breadcrumb
was still referencing the wrong (list) controller.

This bug appeared with the control panel refactoring, which is now managed by
the view itself (and not the action manager as previously).

Task 1932646

closes odoo/odoo#31598

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Martin Geubelle
2019-03-06 10:28:01 +00:00
parent 5805c032a4
commit 1793d6d138
3 changed files with 25 additions and 3 deletions
@@ -535,6 +535,9 @@ ActionManager.include({
return newController(controller.jsID);
} else {
return $.when(controller.widget.willRestore()).then(function () {
viewOptions = _.extend({}, viewOptions, {
breadcrumbs: self._getBreadcrumbs(self.controllerStack.slice(0, index)),
});
return controller.widget.reload(viewOptions).then(function () {
return controller;
});
@@ -243,7 +243,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
return;
}
self.renderer.setLocalState(localState);
return self._update(state);
return self._update(state, params);
});
});
},
@@ -399,12 +399,15 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
*
* @private
* @param {Object} state the state given by the model
* @param {Object} [params]
* @param {Object[]} [params.breadcrumbs]
* @returns {Deferred}
*/
_update: function () {
_update: function (state, params) {
// AAB: update the control panel -> this will be moved elsewhere at some point
var cpContent = _.extend({}, this.controlPanelElements);
this.updateControlPanel({
breadcrumbs: params && params.breadcrumbs,
cp_content: cpContent,
title: this.getTitle(),
});
@@ -2276,7 +2276,7 @@ QUnit.module('ActionManager', {
});
QUnit.test('breadcrumbs are updated when switching between views', function (assert) {
assert.expect(10);
assert.expect(15);
var actionManager = createActionManager({
actions: this.actions,
@@ -2297,6 +2297,20 @@ QUnit.module('ActionManager', {
assert.strictEqual($('.o_control_panel .breadcrumb-item').text(), 'Partners',
"breadcrumbs should still display the display_name of the action");
// open a record in form view
testUtils.dom.click(actionManager.$('.o_kanban_view .o_kanban_record:first'));
assert.strictEqual($('.o_control_panel .breadcrumb-item').length, 2,
"there should be two controllers in the breadcrumbs");
assert.strictEqual($('.o_control_panel .breadcrumb-item:last').text(), 'First record',
"breadcrumbs should contain the display_name of the opened record");
// go back to kanban view using the breadcrumbs
testUtils.dom.click($('.o_control_panel .breadcrumb a'));
assert.strictEqual($('.o_control_panel .breadcrumb-item').length, 1,
"there should be one controller in the breadcrumbs");
assert.strictEqual($('.o_control_panel .breadcrumb-item').text(), 'Partners',
"breadcrumbs should display the display_name of the action");
// switch back to list view
testUtils.dom.click($('.o_control_panel .o_cp_switch_list'));
assert.strictEqual($('.o_control_panel .breadcrumb-item').length, 1,
@@ -2313,6 +2327,8 @@ QUnit.module('ActionManager', {
// go back to list view using the breadcrumbs
testUtils.dom.click($('.o_control_panel .breadcrumb a'));
assert.containsOnce(actionManager, '.o_list_view',
"should be back on list view");
assert.strictEqual($('.o_control_panel .breadcrumb-item').length, 1,
"there should be one controller in the breadcrumbs");
assert.strictEqual($('.o_control_panel .breadcrumb-item').text(), 'Partners',