From 8bdc650f79e0e35de152d456cc9cc565db46a027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Fri, 13 Apr 2018 09:44:16 +0200 Subject: [PATCH] [FIX] web: always update breadcrumb on change title Revision on https://github.com/odoo/odoo/commit/32b8cec5361174c92c45a4975d4e02f1fb448aa2 Before this commit, when we switch channels in the Discuss app, the breadcrumb was visually not updated: it keeps the name of the first opened channel. With this commit, the breadcrumb is updated on each change of channel, so that it displays the name of the currently opened channel. Technical details: This is due to a change of logic of updating the GUI of the breadcrumb: before the refactoring above, discuss had to pass the content of the breadcrumb to the control panel, in order to update the breadcrumb visually. After the refactoring, the action manager should warn the control panel to update the breadcrumb on any change of the title. This is already the case for `ir.actions.act_window`, but not for all types of client actions. --- .../static/src/js/chrome/action_manager.js | 15 ++++++++++ .../js/chrome/action_manager_act_window.js | 8 ----- .../tests/chrome/action_manager_tests.js | 30 +++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index e1c0ddd3e8e..36c94a95c0e 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -835,12 +835,27 @@ var ActionManager = Widget.extend({ * is ready when it will be appended to the DOM. This allows to prevent * flickering for widgets doing async stuff in willStart() or start(). * + * Also updates the control panel on any change of the title on controller's + * widget. + * * @private * @param {Object} controller * @returns {Deferred} resolved with the controller when it is ready */ _startController: function (controller) { + var self = this; var fragment = document.createDocumentFragment(); + // AAB: change this logic to stop using the properties mixin + controller.widget.on("change:title", this, function () { + if (self.getCurrentController() !== controller) { + return; + } + var action = self.actions[controller.actionID]; + if (!action.flags || !action.flags.headless) { + var breadcrumbs = self._getBreadcrumbs(); + self.controlPanel.update({breadcrumbs: breadcrumbs}, {clear: false}); + } + }); return controller.widget.appendTo(fragment).then(function () { return controller; }); 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 4e636de6355..2621071731c 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 @@ -202,15 +202,7 @@ ActionManager.include({ // the action has been removed, so simply destroy the widget widget.destroy(); } else { - // AAB: change this logic to stop using the properties mixin - widget.on("change:title", this, function () { - if (!action.flags.headless) { - var breadcrumbs = self._getBreadcrumbs(); - self.controlPanel.update({breadcrumbs: breadcrumbs}, {clear: false}); - } - }); controller.widget = widget; - def.resolve(controller); } }).fail(def.reject.bind(def)); diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 45cd39920a1..e6f97c20bdd 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -1532,6 +1532,36 @@ QUnit.module('ActionManager', { delete core.action_registry.map.HelloWorldTest; }); + QUnit.test('breadcrumb is updated on title change', function (assert) { + assert.expect(2); + + var ClientAction = Widget.extend(ControlPanelMixin, { + className: 'o_client_action_test', + events: { + click: function () { + this.set("title", 'new title'); + }, + }, + start: function () { + this.set("title", 'initial title'); + this.$el.text('Hello World'); + }, + }); + var actionManager = createActionManager(); + core.action_registry.add('HelloWorldTest', ClientAction); + actionManager.doAction('HelloWorldTest'); + + assert.strictEqual($('ol.breadcrumb').text(), "initial title", + "should have initial title as breadcrumb content"); + + actionManager.$('.o_client_action_test').click(); + assert.strictEqual($('ol.breadcrumb').text(), "new title", + "should have updated title as breadcrumb content"); + + actionManager.destroy(); + delete core.action_registry.map.HelloWorldTest; + }); + QUnit.module('Server actions'); QUnit.test('can execute server actions from db ID', function (assert) {