[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 `<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
This commit is contained in:
Alexandre Kühn
2018-10-10 15:29:31 +00:00
parent a943d8a712
commit 1f7e98dd9b
2 changed files with 51 additions and 2 deletions
@@ -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',
@@ -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 `<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();
});
});
});