diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-10-04 19:43:42 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-10-10 15:29:31 +0000 |
| commit | a943d8a71214cdf289375f0318cd3d34e7dec3a0 (patch) | |
| tree | 1d5c4fcce9f9caec759db19ee9656c26a7ab9829 /addons/web_settings_dashboard/static | |
| parent | 5822d3cbdb19288271a2b36613c44a678fa14cc1 (diff) | |
[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
Diffstat (limited to 'addons/web_settings_dashboard/static')
| -rw-r--r-- | addons/web_settings_dashboard/static/src/js/dashboard.js | 16 | ||||
| -rw-r--r-- | addons/web_settings_dashboard/static/tests/dashboard_tests.js | 42 |
2 files changed, 55 insertions, 3 deletions
diff --git a/addons/web_settings_dashboard/static/src/js/dashboard.js b/addons/web_settings_dashboard/static/src/js/dashboard.js index 4eaf10aab53..2065769bdc0 100644 --- a/addons/web_settings_dashboard/static/src/js/dashboard.js +++ b/addons/web_settings_dashboard/static/src/js/dashboard.js @@ -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'); } diff --git a/addons/web_settings_dashboard/static/tests/dashboard_tests.js b/addons/web_settings_dashboard/static/tests/dashboard_tests.js index 7b593969967..0fab2f8d97f 100644 --- a/addons/web_settings_dashboard/static/tests/dashboard_tests.js +++ b/addons/web_settings_dashboard/static/tests/dashboard_tests.js @@ -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(); + }); }); }); |
