From a943d8a71214cdf289375f0318cd3d34e7dec3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 4 Oct 2018 19:43:42 +0000 Subject: [PATCH 1/4] [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 `` with `href='#'`. The purpose of the `href='#'` is to have the pointer cursor on mouse hover. However, when clicking 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 --- .../static/src/js/dashboard.js | 16 ++++++- .../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 `` 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(); + }); }); }); 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 2/4] [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(); + }); }); }); From 4f3e051891634388ed3ffe5757706380fcc9ba00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Fri, 5 Oct 2018 15:21:56 +0000 Subject: [PATCH 3/4] [FIX] web_settings_dashboard: browse apps Before this commit, it was not possible to access apps from 'Browse apps' in the Settings menu when at least one app was installed. This is caused by the clickable DOM element being a `` with `href='#'`. This redirects to the 1st app, usually the 'Discuss' app, which prevents opening the kanban view with apps. This commit fixes the issue by preventing the browser to change the URL in the address bar when clicking on 'Browse apps' from the 'Settings' application. Closes #27434 Closes #27442 --- addons/iap/static/src/js/dashboard.js | 7 +--- .../static/src/js/dashboard.js | 15 ++++++- .../static/tests/dashboard_tests.js | 40 +++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/addons/iap/static/src/js/dashboard.js b/addons/iap/static/src/js/dashboard.js index b3490da2eda..995cc444e24 100644 --- a/addons/iap/static/src/js/dashboard.js +++ b/addons/iap/static/src/js/dashboard.js @@ -1,20 +1,15 @@ odoo.define('iap.Dashboard', function (require) { "use strict"; -var ajax = require('web.ajax'); -var core = require('web.core'); var Dashboard = require('web_settings_dashboard'); -var _t = core._t; -var QWeb = core.qweb; - Dashboard.Dashboard.include({ /** * @override */ load_apps: function (data) { var _super = this._super.bind(this); - return ajax.jsonRpc('/web/dataset/call_kw', 'call', { + return this._rpc({ model: 'iap.account', method: 'get_account_url', args: [], diff --git a/addons/web_settings_dashboard/static/src/js/dashboard.js b/addons/web_settings_dashboard/static/src/js/dashboard.js index 85a2be3e8c5..01af7071c09 100644 --- a/addons/web_settings_dashboard/static/src/js/dashboard.js +++ b/addons/web_settings_dashboard/static/src/js/dashboard.js @@ -248,7 +248,7 @@ var DashboardApps = Widget.extend({ template: 'DashboardApps', events: { - 'click .o_browse_apps': 'on_new_apps', + 'click .o_browse_apps': '_onClickBrowseApps', 'click .o_confirm_upgrade': 'confirm_upgrade', }, @@ -265,7 +265,18 @@ var DashboardApps = Widget.extend({ } }, - on_new_apps: function(){ + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Called when clicking on 'Browse Apps' button. + * + * @private + * @param {MouseEvent} ev + */ + _onClickBrowseApps: function (ev) { + ev.preventDefault(); this.do_action('base.open_module_tree'); }, diff --git a/addons/web_settings_dashboard/static/tests/dashboard_tests.js b/addons/web_settings_dashboard/static/tests/dashboard_tests.js index d0a8ced5d38..f638d20e748 100644 --- a/addons/web_settings_dashboard/static/tests/dashboard_tests.js +++ b/addons/web_settings_dashboard/static/tests/dashboard_tests.js @@ -271,6 +271,46 @@ QUnit.module('settings_dashboard', function () { dashboard.destroy(); }); + + QUnit.test('Prevent default behaviour when clicking on browse apps', function (assert) { + assert.expect(3); + + var dashboard = createDashboard({ + dashboards: ['apps'], + mockRPC: function (route, args) { + if (route === '/web_settings_dashboard/data') { + return $.when({ + apps: {}, + }); + } + if (args.method === 'get_account_url') { + return $.when('fakeURL'); + } + return this._super.apply(this, arguments); + }, + }); + + var $browseAppsButton = dashboard.$('.btn.o_browse_apps'); + + // 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, $browseAppsButton[0], + "should have clicked on 'browse apps' button"); + ev.preventDefault(); + }); + + assert.strictEqual($browseAppsButton.length, 1, + "should have button to browse apps"); + + $browseAppsButton.click(); + + $(document.body).off('click.o_test'); + dashboard.destroy(); + }); }); }); From b7cf456560dc4fd7c1217ba90f0b5609466ede50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Tue, 9 Oct 2018 09:38:50 +0000 Subject: [PATCH 4/4] [FIX] web: `self.menu.change_menu_section` is not a function Revision on https://github.com/odoo/odoo/commit/19eacf7d23c9413de4430a3422b5ed74b37ef242 The commit above changed the menu in community, so that it looks like enterprise. To do so, it copies the menu management from the enterprise repository to the community repository. Some code about the home menu has been removed, since it is replaced with the app menu in community. However, some functions have been removed by accident, such as `change_menu_section`. Closes #27436 --- addons/web/static/src/js/chrome/menu.js | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/addons/web/static/src/js/chrome/menu.js b/addons/web/static/src/js/chrome/menu.js index 7f60e2ea44f..589b9cb2c06 100644 --- a/addons/web/static/src/js/chrome/menu.js +++ b/addons/web/static/src/js/chrome/menu.js @@ -79,6 +79,32 @@ var Menu = Widget.extend({ return this._super.apply(this, arguments); }, + change_menu_section: function (primary_menu_id) { + if (!this.$menu_sections[primary_menu_id]) { + return; // unknown menu_id + } + + if (this.current_primary_menu === primary_menu_id) { + return; // already in that menu + } + + if (this.current_primary_menu) { + this.$menu_sections[this.current_primary_menu].detach(); + } + + // Get back the application name + for (var i = 0; i < this.menu_data.children.length; i++) { + if (this.menu_data.children[i].id === primary_menu_id) { + this.$menu_brand_placeholder.text(this.menu_data.children[i].name); + break; + } + } + + this.$menu_sections[primary_menu_id].appendTo(this.$section_placeholder); + this.current_primary_menu = primary_menu_id; + + core.bus.trigger('resize'); + }, _trigger_menu_clicked: function (menu_id, action_id) { this.trigger_up('menu_clicked', { id: menu_id,