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.

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