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.

95 lines
3.5 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (c) 2017-today MuK IT GmbH.
  4. *
  5. * This file is part of MuK Grid Snippets
  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.AppsMenu', function (require) {
  23. "use strict";
  24. const core = require('web.core');
  25. const session = require("web.session");
  26. const AppsMenu = require("web.AppsMenu");
  27. const MenuSearchMixin = require("muk_web_theme.MenuSearchMixin");
  28. AppsMenu.include(_.extend({}, MenuSearchMixin, {
  29. events: _.extend({}, AppsMenu.prototype.events, {
  30. "keydown .mk_search_input input": "_onSearchResultsNavigate",
  31. "click .mk_menu_search_result": "_onSearchResultChosen",
  32. "shown.bs.dropdown": "_onMenuShown",
  33. "hidden.bs.dropdown": "_onMenuHidden",
  34. "hide.bs.dropdown": "_onMenuHide",
  35. }),
  36. init(parent, menuData) {
  37. this._super(...arguments);
  38. for (let n in this._apps) {
  39. this._apps[n].web_icon_data = menuData.children[n].web_icon_data;
  40. }
  41. this._searchableMenus = _.reduce(
  42. menuData.children, this._findNames.bind(this), {}
  43. );
  44. this._search_def = $.Deferred();
  45. },
  46. start() {
  47. this._setBackgroundImage();
  48. this.$search_container = this.$(".mk_search_container");
  49. this.$search_input = this.$(".mk_search_input input");
  50. this.$search_results = this.$(".mk_search_results");
  51. return this._super(...arguments);
  52. },
  53. _onSearchResultChosen(event) {
  54. event.preventDefault();
  55. const $result = $(event.currentTarget),
  56. text = $result.text().trim(),
  57. data = $result.data(),
  58. suffix = ~text.indexOf("/") ? "/" : "";
  59. this.trigger_up("menu_clicked", {
  60. action_id: data.actionId,
  61. id: data.menuId,
  62. previous_menu_id: data.parentId,
  63. });
  64. const app = _.find(this._apps, (_app) => text.indexOf(_app.name + suffix) === 0);
  65. core.bus.trigger("change_menu_section", app.menuID);
  66. },
  67. _onAppsMenuItemClicked(event) {
  68. this._super(...arguments);
  69. event.preventDefault();
  70. },
  71. _setBackgroundImage() {
  72. const url = session.url('/web/image', {
  73. model: 'res.company',
  74. id: session.company_id,
  75. field: 'background_image',
  76. });
  77. this.$('.dropdown-menu').css({
  78. "background-size": "cover",
  79. "background-image": "url(" + url + ")"
  80. });
  81. if (session.muk_web_theme_background_blend_mode) {
  82. this.$('.o-app-name').css({
  83. "mix-blend-mode": session.muk_web_theme_background_blend_mode,
  84. });
  85. }
  86. },
  87. _onMenuHide(event) {
  88. return $('.oe_wait').length === 0 && !this.$('input').is(':focus');
  89. },
  90. }));
  91. });