3
0
Fork 0

Merge PR #1529 into 12.0

Signed-off-by pedrobaeza
12.0
OCA-git-bot 2020-02-24 12:23:56 +00:00
commit 0018d1e1f2
1 changed files with 37 additions and 60 deletions

View File

@ -16,12 +16,28 @@ odoo.define('web_responsive', function (require) {
var Chatter = require('mail.Chatter'); var Chatter = require('mail.Chatter');
var DocumentViewer = require('mail.DocumentViewer'); var DocumentViewer = require('mail.DocumentViewer');
/*
* Helper function to know if are waiting /* Hide AppDrawer in desktop and mobile modes.
* * 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');
});
} }
/** /**
@ -130,6 +146,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();
}, },
/** /**
@ -292,21 +309,21 @@ 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');
}, },
}); });
BasicController.include({ BasicController.include({
/** /**
* Close the AppDrawer if the data set is dirty and a discard dialog is opened * Close the AppDrawer if the data set is dirty and a discard dialog
* is opened
* *
* @override * @override
*/ */
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('toggle'); closeAppDrawer();
$('.o_menu_sections li.show .dropdown-toggle').dropdown('toggle');
} }
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
@ -315,12 +332,10 @@ odoo.define('web_responsive', function (require) {
Menu.include({ Menu.include({
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": "show.bs.dropdown .o_menu_systray, .o_menu_apps":
"_hideMobileSubmenus", "_hideMobileSubmenus",
// Prevent close section menu
"hide.bs.dropdown .o_menu_sections": "_hideMenuSection",
}, Menu.prototype.events), }, Menu.prototype.events),
start: function () { start: function () {
@ -333,21 +348,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();
}, },
/** /**
@ -360,17 +375,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({
@ -434,38 +438,11 @@ odoo.define('web_responsive', function (require) {
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 () {
_.defer(function () { this._super.apply(this, arguments);
var uniq_sel = '[data-action-id='+action.id+']'; closeAppDrawer();
// Need close AppDrawer?
var 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?
// TODO: Change to 'hide' in modern Bootstrap >4.1
var menu_sections = document.querySelector(
'.o_menu_sections li.show');
$(menu_sections).has(uniq_sel).find('.dropdown-toggle')
.dropdown('toggle');
// Need close Mobile?
var menu_sections_mobile = document.querySelector(
'.o_menu_sections.show');
$(menu_sections_mobile).has(uniq_sel).collapse('hide');
});
},
_handleAction: function (action) {
return this._super.apply(this, arguments).always(
$.proxy(this, '_hideMenusByAction', action));
}, },
}); });