You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.9 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (c) 2017-2019 MuK IT GmbH.
  4. *
  5. * This file is part of MuK Backend Theme
  6. * (see https://mukit.at).
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. **********************************************************************************/
  22. odoo.define('muk_web_theme.Menu', function (require) {
  23. "use strict";
  24. var core = require('web.core');
  25. var config = require("web.config");
  26. var Menu = require("web.Menu");
  27. var AppsBar = require("muk_web_theme.AppsBar");
  28. var _t = core._t;
  29. var QWeb = core.qweb;
  30. Menu.include({
  31. events: _.extend({}, Menu.prototype.events, {
  32. "click .o_menu_apps a[data-toggle=dropdown]": "_onAppsMenuClick",
  33. "click .mk_menu_mobile_section": "_onMobileSectionClick",
  34. "click .o_menu_sections [role=menuitem]": "_hideMobileSubmenus",
  35. "show.bs.dropdown .o_menu_systray, .o_menu_apps": "_hideMobileSubmenus",
  36. }),
  37. menusTemplate: config.device.isMobile ?
  38. 'muk_web_theme.MobileMenu.sections' : Menu.prototype.menusTemplate,
  39. start: function () {
  40. var res = this._super.apply(this, arguments);
  41. this.$menu_toggle = this.$(".mk_menu_sections_toggle");
  42. this.$menu_apps_sidebar = this.$('.mk_apps_sidebar_panel');
  43. this._appsBar = new AppsBar(this, this.menu_data);
  44. this._appsBar.appendTo(this.$menu_apps_sidebar);
  45. this.$menu_apps_sidebar.renderScrollBar();
  46. if (config.device.isMobile) {
  47. var menu_ids = _.keys(this.$menu_sections);
  48. for (var i = 0; i < menu_ids.length; i++) {
  49. var $section = this.$menu_sections[menu_ids[i]];
  50. $section.on('click', 'a[data-menu]', this, function(ev) {
  51. ev.stopPropagation();
  52. });
  53. }
  54. }
  55. return res;
  56. },
  57. _hideMobileSubmenus: function () {
  58. if (this.$menu_toggle.is(":visible") && $('.oe_wait').length === 0 &&
  59. this.$section_placeholder.is(":visible")) {
  60. this.$section_placeholder.collapse("hide");
  61. }
  62. },
  63. _updateMenuBrand: function () {
  64. if (!config.device.isMobile) {
  65. return this._super.apply(this, arguments);
  66. }
  67. },
  68. _onAppsMenuClick: function(event, checkedCanBeRemoved) {
  69. var action_manager = this.getParent().action_manager;
  70. var controller = action_manager.getCurrentController();
  71. if (controller && !checkedCanBeRemoved) {
  72. controller.widget.canBeRemoved().done(function () {
  73. $(event.currentTarget).trigger('click', [true]);
  74. $(event.currentTarget).off('.bs.dropdown');
  75. });
  76. event.stopPropagation();
  77. event.preventDefault();
  78. }
  79. },
  80. _onMobileSectionClick: function (event) {
  81. event.preventDefault();
  82. event.stopPropagation();
  83. var $section = $(event.currentTarget);
  84. if ($section.hasClass('show')) {
  85. $section.removeClass('show');
  86. $section.find('.show').removeClass('show');
  87. $section.find('.fa-chevron-down').hide();
  88. $section.find('.fa-chevron-right').show();
  89. } else {
  90. $section.addClass('show');
  91. $section.find('ul:first').addClass('show');
  92. $section.find('.fa-chevron-down:first').show();
  93. $section.find('.fa-chevron-right:first').hide();
  94. }
  95. },
  96. });
  97. });