3
0
Fork 0

[FIX] web_responsive: Change AppDrawer close method

Previous of this commit, AppDrawer closes when the action have an id
that is defined in a menu item and no rpc calls are running.
Now AppDrawer closes in a more generic way, is enough that a
controller is attached to consider that the AppDrawer needs to be
closed.
14.0
Alexandre Díaz 2020-02-23 04:15:30 +01:00 committed by Splash
parent 3a223fa490
commit c42a1abfdb
2 changed files with 36 additions and 66 deletions

View File

@ -6,7 +6,7 @@
{ {
"name": "Web Responsive", "name": "Web Responsive",
"summary": "Responsive web client, community-supported", "summary": "Responsive web client, community-supported",
"version": "13.0.2.0.0", "version": "13.0.2.0.1",
"category": "Website", "category": "Website",
"website": "https://github.com/OCA/web", "website": "https://github.com/OCA/web",
"author": "LasLabs, Tecnativa, " "Odoo Community Association (OCA)", "author": "LasLabs, Tecnativa, " "Odoo Community Association (OCA)",

View File

@ -17,12 +17,28 @@ odoo.define("web_responsive", function(require) {
const ListRenderer = require("web.ListRenderer"); const ListRenderer = require("web.ListRenderer");
const DocumentViewer = require("mail.DocumentViewer"); const DocumentViewer = require("mail.DocumentViewer");
/* /* Hide AppDrawer in desktop and mobile modes.
* Helper function to know if are waiting * To avoid delays in pages with a lot of DOM nodes we make
* * sub-groups' with 'querySelector' to improve the performance.
*/ */
function isWaiting() { function closeAppDrawer() {
return $(".oe_wait").length !== 0; _.defer(function() {
// Need close AppDrawer?
var menu_apps_dropdown = document.querySelector(".o_menu_apps .dropdown");
$(menu_apps_dropdown)
.has(".dropdown-menu.show")
.find("> a")
.dropdown("toggle");
// Need close Sections Menu?
// TODO: Change to 'hide' in modern Bootstrap >4.1
var menu_sections = document.querySelector(
".o_menu_sections li.show .dropdown-toggle"
);
$(menu_sections).dropdown("toggle");
// Need close Mobile?
var menu_sections_mobile = document.querySelector(".o_menu_sections.show");
$(menu_sections_mobile).collapse("hide");
});
} }
/** /**
@ -129,6 +145,7 @@ odoo.define("web_responsive", function(require) {
_onAppsMenuItemClicked: function(ev) { _onAppsMenuItemClicked: function(ev) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation();
}, },
/** /**
@ -284,7 +301,7 @@ odoo.define("web_responsive", function(require) {
* Control if AppDrawer can be closed * Control if AppDrawer can be closed
*/ */
_hideAppsMenu: function() { _hideAppsMenu: function() {
return !isWaiting() && !this.$("input").is(":focus"); return !this.$("input").is(":focus");
}, },
}); });
@ -297,10 +314,7 @@ odoo.define("web_responsive", function(require) {
*/ */
canBeDiscarded: function(recordID) { canBeDiscarded: function(recordID) {
if (this.model.isDirty(recordID || this.handle)) { if (this.model.isDirty(recordID || this.handle)) {
$(".o_menu_apps .dropdown:has(.dropdown-menu.show) > a").dropdown( closeAppDrawer();
"toggle"
);
$(".o_menu_sections li.show .dropdown-toggle").dropdown("toggle");
} }
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
@ -310,11 +324,9 @@ odoo.define("web_responsive", function(require) {
events: _.extend( events: _.extend(
{ {
// Clicking a hamburger menu item should close the hamburger // Clicking a hamburger menu item should close the hamburger
"click .o_menu_sections [role=menuitem]": "_hideMobileSubmenus", "click .o_menu_sections [role=menuitem]": "_onClickMenuItem",
// Opening any dropdown in the navbar should hide the hamburger // Opening any dropdown in the navbar should hide the hamburger
"show.bs.dropdown .o_menu_systray, .o_menu_apps": "_hideMobileSubmenus", "show.bs.dropdown .o_menu_systray, .o_menu_apps": "_hideMobileSubmenus",
// Prevent close section menu
"hide.bs.dropdown .o_menu_sections": "_hideMenuSection",
}, },
Menu.prototype.events Menu.prototype.events
), ),
@ -329,21 +341,21 @@ odoo.define("web_responsive", function(require) {
*/ */
_hideMobileSubmenus: function() { _hideMobileSubmenus: function() {
if ( if (
config.device.isMobile &&
this.$menu_toggle.is(":visible") && this.$menu_toggle.is(":visible") &&
this.$section_placeholder.is(":visible") && this.$section_placeholder.is(":visible")
!isWaiting()
) { ) {
this.$section_placeholder.collapse("hide"); this.$section_placeholder.collapse("hide");
} }
}, },
/** /**
* Hide Menu Section * Prevent hide the menu (should be closed when action is loaded)
* *
* @returns {Boolean} * @param {ClickEvent} ev
*/ */
_hideMenuSection: function() { _onClickMenuItem: function(ev) {
return !isWaiting(); ev.stopPropagation();
}, },
/** /**
@ -356,17 +368,6 @@ odoo.define("web_responsive", function(require) {
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
} }
}, },
/**
* Don't display the menu if are waiting for an action to end
*
* @override
*/
_onMouseOverMenu: function() {
if (!isWaiting()) {
this._super.apply(this, arguments);
}
},
}); });
RelationalFields.FieldStatus.include({ RelationalFields.FieldStatus.include({
@ -455,42 +456,11 @@ odoo.define("web_responsive", function(require) {
// Hide AppDrawer or Menu when the action has been completed // Hide AppDrawer or Menu when the action has been completed
ActionManager.include({ ActionManager.include({
/** /**
* Because the menu aren't closed when click, this method * @override
* searchs for the menu with the action executed to close it.
* To avoid delays in pages with a lot of DOM nodes we make
* 'sub-groups' with 'querySelector' to improve the performance.
*
* @param {action} action
* The executed action
*/ */
_hideMenusByAction: function(action) { _appendController: function() {
const uniq_sel = "[data-action-id=" + action.id + "]"; this._super.apply(this, arguments);
// Need close AppDrawer? closeAppDrawer();
const menu_apps_dropdown = document.querySelector(".o_menu_apps .dropdown");
$(menu_apps_dropdown)
.has(".dropdown-menu.show")
.has(uniq_sel)
.find("> a")
.dropdown("toggle");
// Need close Sections Menu?
const menu_sections = document.querySelector(".o_menu_sections li.show");
$(menu_sections)
.has(uniq_sel)
.find(".dropdown-toggle")
.dropdown("toggle");
// Need close Mobile?
const menu_sections_mobile = document.querySelector(
".o_menu_sections.show"
);
$(menu_sections_mobile)
.has(uniq_sel)
.hide();
},
_handleAction: function(action) {
return this._super
.apply(this, arguments)
.finally($.proxy(this, "_hideMenusByAction", action));
}, },
}); });