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.

55 lines
1.9 KiB

  1. odoo.define('web_search_with_and', function (require) {
  2. "use strict";
  3. var SearchView = require('web.SearchView');
  4. var Backbone = window.Backbone;
  5. SearchView.include({
  6. // Override the base method to detect a 'shift' event
  7. select_completion: function (e, ui) {
  8. if (e.shiftKey
  9. && ui.item.facet.values
  10. && ui.item.facet.values.length
  11. && String(ui.item.facet.values[0].value).trim() !== "") {
  12. // In case of an 'AND' search a new facet is added regarding of the previous facets
  13. e.preventDefault();
  14. this.query.add(ui.item.facet, {shiftKey: true});
  15. } else {
  16. return this._super.apply(this, arguments);
  17. }
  18. }
  19. });
  20. SearchView.SearchQuery.prototype = SearchView.SearchQuery.extend({
  21. // Override the odoo method to (conditionally) add a search facet even if a existing
  22. // facet for the same field/category already exists.
  23. // The prototype is used to override the 'add' function in order to execute the
  24. // following code before the Odoo native override (trick)
  25. add: function (values, options) {
  26. options = options || {};
  27. if (options.shiftKey) {
  28. if (!values) {
  29. values = [];
  30. }
  31. else if (!(values instanceof Array)) {
  32. values = [values];
  33. }
  34. delete options.shiftKey;
  35. _(values).each(function (value) {
  36. var model = this._prepareModel(value, options);
  37. Backbone.Collection.prototype.add.call(this, model, options);
  38. }, this);
  39. return this;
  40. }
  41. else {
  42. return this.constructor.__super__.add.call(this, values, options);
  43. }
  44. }
  45. }).prototype;
  46. });