From 1f7e98dd9bb138ae94d294696f853c5b6ae3b4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 4 Oct 2018 19:58:07 +0000 Subject: [PATCH] [FIX] web_settings_dashboard: set up your company Before this commit, it was not possible to set up a company. This is caused by the clickable DOM element being a `` with `href='#'`. This redirects to the 1st app in community (usually the 'Discuss' app), which prevents opening the form view to set up information about your company. This commit fixes the issue by preventing the browser to change the URL in the address bar when clicking on 'Set up'. Closes #27434 Closes #27442 --- .../static/src/js/dashboard.js | 13 +++++- .../static/tests/dashboard_tests.js | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/addons/web_settings_dashboard/static/src/js/dashboard.js b/addons/web_settings_dashboard/static/src/js/dashboard.js index 2065769bdc0..85a2be3e8c5 100644 --- a/addons/web_settings_dashboard/static/src/js/dashboard.js +++ b/addons/web_settings_dashboard/static/src/js/dashboard.js @@ -371,7 +371,7 @@ var DashboardCompany = Widget.extend({ template: 'DashboardCompany', events: { - 'click .o_setup_company': 'on_setup_company' + 'click .o_setup_company': '_onSetupCompany' }, init: function (parent, data) { @@ -380,7 +380,16 @@ var DashboardCompany = Widget.extend({ this._super.apply(this, arguments); }, - on_setup_company: function () { + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @param {MouseEvent} ev + */ + _onSetupCompany: function (ev) { + ev.preventDefault(); var self = this; var action = { type: 'ir.actions.act_window', diff --git a/addons/web_settings_dashboard/static/tests/dashboard_tests.js b/addons/web_settings_dashboard/static/tests/dashboard_tests.js index 0fab2f8d97f..d0a8ced5d38 100644 --- a/addons/web_settings_dashboard/static/tests/dashboard_tests.js +++ b/addons/web_settings_dashboard/static/tests/dashboard_tests.js @@ -231,6 +231,46 @@ QUnit.module('settings_dashboard', function () { dashboard.destroy(); }); + + QUnit.test('Prevent default behaviour when clicking on set up company', function (assert) { + assert.expect(3); + + var dashboard = createDashboard({ + dashboards: ['company'], + mockRPC: function (route, args) { + if (route === '/web_settings_dashboard/data') { + return $.when({ + company: { + company_name: 'MyCompany' + } + }); + } + return this._super.apply(this, arguments); + }, + }); + + var $setupCompany = dashboard.$('.o_setup_company'); + + assert.strictEqual($setupCompany.length, 1, + "should have button to set up company"); + + // Prevent the browser default behaviour when clicking on anything. + // This includes clicking on a `` with `href`, so that it does not + // change the URL in the address bar. + $(document.body).on('click.o_test', function (ev) { + assert.ok(ev.isDefaultPrevented(), + "should have prevented browser default behaviour"); + assert.strictEqual(ev.target, $setupCompany[0], + "should have clicked on 'setup company' button"); + ev.preventDefault(); + }); + + $setupCompany.click(); + + $(document.body).off('click.o_test'); + + dashboard.destroy(); + }); }); });