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.

98 lines
3.7 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_web_theme.AppsMenu', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var config = require("web.config");
  23. var session = require("web.session");
  24. var AppsMenu = require("web.AppsMenu");
  25. var MenuSearchMixin = require("muk_web_theme.MenuSearchMixin");
  26. var _t = core._t;
  27. var QWeb = core.qweb;
  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: function (parent, menuData) {
  37. this._super.apply(this, arguments);
  38. for (var 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: function () {
  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.apply(this, arguments);
  52. },
  53. _onSearchResultChosen: function (event) {
  54. event.preventDefault();
  55. var $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. var app = _.find(this._apps, function (_app) {
  65. return text.indexOf(_app.name + suffix) === 0;
  66. });
  67. core.bus.trigger("change_menu_section", app.menuID);
  68. },
  69. _onAppsMenuItemClicked: function (event) {
  70. this._super.apply(this, arguments);
  71. event.preventDefault();
  72. },
  73. _setBackgroundImage: function () {
  74. var url = session.url('/web/image', {
  75. model: 'res.company',
  76. id: session.company_id,
  77. field: 'background_image',
  78. });
  79. this.$('.dropdown-menu').css({
  80. "background-size": "cover",
  81. "background-image": "url(" + url + ")"
  82. });
  83. if (session.muk_web_theme_background_blend_mode) {
  84. this.$('.o-app-name').css({
  85. "mix-blend-mode": session.muk_web_theme_background_blend_mode,
  86. });
  87. }
  88. },
  89. _onMenuHide: function(event) {
  90. return $('.oe_wait').length === 0 && !this.$('input').is(':focus');
  91. },
  92. }));
  93. });