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.

130 lines
5.0 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_searchpanel.KanbanView', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var config = require('web.config');
  23. var pyUtils = require('web.py_utils');
  24. var utils = require('web.utils');
  25. var KanbanView = require('web.KanbanView');
  26. var SearchPanel = require('web.SearchPanel');
  27. var _t = core._t;
  28. var QWeb = core.qweb;
  29. KanbanView.include({
  30. config: _.extend({}, KanbanView.prototype.config, {
  31. SearchPanel: SearchPanel,
  32. }),
  33. init: function (viewInfo, params) {
  34. this.searchPanelSections = Object.create(null);
  35. this._super.apply(this, arguments);
  36. this.hasSearchPanel = !_.isEmpty(this.searchPanelSections);
  37. },
  38. getController: function (parent) {
  39. var self = this;
  40. var def = undefined;
  41. if (this.hasSearchPanel) {
  42. def = this._createSearchPanel(parent);
  43. }
  44. var _super = this._super.bind(this);
  45. return $.when(def).then(function (searchPanel) {
  46. return _super(parent).done(function (controller) {
  47. if (self.hasSearchPanel) {
  48. self.controllerParams.searchPanel.setParent(controller);
  49. }
  50. return controller
  51. });
  52. });
  53. },
  54. _createSearchPanel: function (parent) {
  55. var self = this;
  56. var defaultCategoryValues = {};
  57. Object.keys(this.loadParams.context).forEach(function (key) {
  58. var match = /^searchpanel_default_(.*)$/.exec(key);
  59. if (match) {
  60. defaultCategoryValues[match[1]] = self.loadParams.context[key];
  61. }
  62. });
  63. var controlPanelDomain = this.loadParams.domain;
  64. var searchPanel = new this.config.SearchPanel(parent, {
  65. defaultCategoryValues: defaultCategoryValues,
  66. fields: this.fields,
  67. model: this.loadParams.modelName,
  68. searchDomain: controlPanelDomain,
  69. sections: this.searchPanelSections,
  70. });
  71. this.controllerParams.searchPanel = searchPanel;
  72. this.controllerParams.controlPanelDomain = controlPanelDomain;
  73. return searchPanel.appendTo(document.createDocumentFragment()).then(function () {
  74. var searchPanelDomain = searchPanel.getDomain();
  75. self.loadParams.domain = controlPanelDomain.concat(searchPanelDomain);
  76. });
  77. },
  78. _processNode: function (node, fv) {
  79. if (node.tag === 'searchpanel') {
  80. // if (!config.device.isMobile) {
  81. // this._processSearchPanelNode(node, fv);
  82. // }
  83. this._processSearchPanelNode(node, fv);
  84. return false;
  85. }
  86. return this._super.apply(this, arguments);
  87. },
  88. _processSearchPanelNode: function (node, fv) {
  89. var self = this;
  90. node.children.forEach(function (childNode, index) {
  91. if (childNode.tag !== 'field') {
  92. return;
  93. }
  94. if (childNode.attrs.invisible === "1") {
  95. return;
  96. }
  97. var fieldName = childNode.attrs.name;
  98. var type = childNode.attrs.select === 'multi' ? 'filter' : 'category';
  99. var sectionId = _.uniqueId('section_');
  100. var section = {
  101. color: childNode.attrs.color,
  102. description: childNode.attrs.string || fv.fields[fieldName].string,
  103. fieldName: fieldName,
  104. icon: childNode.attrs.icon,
  105. id: sectionId,
  106. index: index,
  107. type: type,
  108. };
  109. if (section.type === 'category') {
  110. section.icon = section.icon || 'fa-folder';
  111. } else if (section.type === 'filter') {
  112. section.disableCounters = !!pyUtils.py_eval(childNode.attrs.disable_counters || '0');
  113. section.domain = childNode.attrs.domain || '[]';
  114. section.groupBy = childNode.attrs.groupby;
  115. section.icon = section.icon || 'fa-filter';
  116. }
  117. self.searchPanelSections[sectionId] = section;
  118. });
  119. },
  120. });
  121. });