[FIX] web_settings_dashboard: load a translation

Before this commit, there was an issue when trying to load
a translation from the 'Settings' application.

	- Go to 'Settings'
	- Click on 'Load a translation'
	> It redirects to 1st app (community) or home menu (enterprise)

This is not a big issue in enterprise, because the modal is
that let the user load a translation is still prompted.
This is however not the case in the community version.

This issue is caused by 'Load a translation' being a `<a>` with
`href='#'`. The purpose of the `href='#'` is to have the pointer
cursor on mouse hover. However, when clicking a `<a>` with `href`,
the browser changes the URL in the address bar with the content of
the `href`, which for the value `'#'` is linked to the top of the
main page. In community, this redirects to the 1st installed app
(usually 'Apps' or 'Discuss'), whereas in enterprise it redirects
to the home menu.

This commit fixes this issue by preventing the default browser
behaviour when clicking on "Load a translation", so that it does
not change the URL in the address bar.

Closes #27434
Closes #27442
This commit is contained in:
Alexandre Kühn
2018-10-10 15:29:31 +00:00
parent 5822d3cbdb
commit a943d8a712
2 changed files with 55 additions and 3 deletions
@@ -346,10 +346,22 @@ var DashboardTranslations = Widget.extend({
template: 'DashboardTranslations',
events: {
'click .o_load_translations': 'on_load_translations'
'click .o_load_translations': '_onLoadTranslations'
},
on_load_translations: function () {
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* Called when clicking on "Load a translation" button. It prompts a dialog
* to load a translation.
*
* @private
* @param {MouseEvent} ev
*/
_onLoadTranslations: function (ev) {
ev.preventDefault();
this.do_action('base.action_view_base_language_install');
}
@@ -21,7 +21,11 @@ function createDashboard(params) {
widget.destroy();
};
dashboard.appendTo($('#qunit-fixture'));
if (params.debug) {
dashboard.appendTo($('body'));
} else {
dashboard.appendTo($('#qunit-fixture'));
}
return dashboard;
}
@@ -191,6 +195,42 @@ QUnit.module('settings_dashboard', function () {
dashboard.destroy();
});
QUnit.test('Prevent default behaviour when clicking on load translation', function (assert) {
assert.expect(3);
var dashboard = createDashboard({
dashboards: ['translations'],
mockRPC: function (route, args) {
if (route === '/web_settings_dashboard/data') {
return $.when();
}
return this._super.apply(this, arguments);
},
});
var $loadTranslation = dashboard.$('.o_load_translations');
assert.strictEqual($loadTranslation.length, 1,
"should have button to load translations");
// 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, $loadTranslation[0],
"should have clicked on 'load a translation' button");
ev.preventDefault();
});
$loadTranslation.click();
$(document.body).off('click.o_test');
dashboard.destroy();
});
});
});