mirror of https://github.com/OCA/web.git
- migration web_search_with_and
parent
e7104679f2
commit
082c8e3ba4
|
@ -1,17 +1,14 @@
|
|||
# Copyright 2015 Andrius Preimantas <andrius@versada.lt>
|
||||
# Copyright 2020 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
'name': "Use AND conditions on omnibar search",
|
||||
'version': '12.0.1.0.0',
|
||||
'author': 'Versada UAB, Odoo Community Association (OCA)',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'web',
|
||||
'website': 'https://github.com/OCA/web',
|
||||
'depends': [
|
||||
'web',
|
||||
],
|
||||
'data': [
|
||||
'data/data.xml',
|
||||
],
|
||||
"name": "Use AND conditions on omnibar search",
|
||||
"version": "13.0.1.0.0",
|
||||
"author": "Versada UAB, ACSONE SA/NV, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"category": "web",
|
||||
"website": "https://github.com/OCA/web",
|
||||
"depends": ["web"],
|
||||
"data": ["data/data.xml"],
|
||||
}
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<template id="assets_backend" name="web_view_editor assets" inherit_id="web.assets_backend">
|
||||
<template
|
||||
id="assets_backend"
|
||||
name="web_view_editor assets"
|
||||
inherit_id="web.assets_backend"
|
||||
>
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/web_search_with_and/static/src/js/search.js"/>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/web_search_with_and/static/src/js/search.js"
|
||||
/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
* Adrien Didenot <adrien.didenot@horanet.com>
|
||||
* Francesco Apruzzese <f.apruzzese@apuliasoftware.it>
|
||||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
|
||||
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>
|
||||
|
|
|
@ -1,55 +1,39 @@
|
|||
odoo.define('web_search_with_and', function (require) {
|
||||
odoo.define("web_search_with_and", function(require) {
|
||||
"use strict";
|
||||
|
||||
var SearchView = require('web.SearchView');
|
||||
var Backbone = window.Backbone;
|
||||
var searchBarAutocompleteRegistry = require("web.search_bar_autocomplete_sources_registry");
|
||||
var SearchBar = require("web.SearchBar");
|
||||
|
||||
SearchView.include({
|
||||
// Override the base method to detect a 'shift' event
|
||||
select_completion: function (e, ui) {
|
||||
if (e.shiftKey
|
||||
&& ui.item.facet.values
|
||||
&& ui.item.facet.values.length
|
||||
&& String(ui.item.facet.values[0].value).trim() !== "") {
|
||||
// In case of an 'AND' search a new facet is added regarding of the previous facets
|
||||
SearchBar.include({
|
||||
// Override the base method to detect a "shift" event
|
||||
_onAutoCompleteSelected: function(e, ui) {
|
||||
var values = ui.item.facet.values;
|
||||
if (
|
||||
e.shiftKey &&
|
||||
values &&
|
||||
values.length &&
|
||||
String(values[0].value).trim() !== ""
|
||||
) {
|
||||
// In case of an "AND" search a new facet is added regarding of
|
||||
// the previous facets
|
||||
e.preventDefault();
|
||||
|
||||
this.query.add(ui.item.facet, {shiftKey: true});
|
||||
var filter = ui.item.facet.filter;
|
||||
var field = this.fields[filter.attrs.name];
|
||||
var Obj = searchBarAutocompleteRegistry.getAny([
|
||||
filter.attrs.widget,
|
||||
field.type,
|
||||
]);
|
||||
var obj = new Obj(this, filter, field, this.actionContext);
|
||||
var new_filter = Object.assign({}, ui.item.facet.filter, {
|
||||
domain: obj.getDomain(values),
|
||||
autoCompleteValues: values,
|
||||
});
|
||||
this.trigger_up("new_filters", {
|
||||
filters: [new_filter],
|
||||
});
|
||||
} else {
|
||||
|
||||
return this._super.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
SearchView.SearchQuery.prototype = SearchView.SearchQuery.extend({
|
||||
// Override the odoo method to (conditionally) add a search facet even if a existing
|
||||
// facet for the same field/category already exists.
|
||||
// The prototype is used to override the 'add' function in order to execute the
|
||||
// following code before the Odoo native override (trick)
|
||||
add: function (values, options) {
|
||||
options = options || {};
|
||||
if (options.shiftKey) {
|
||||
|
||||
if (!values) {
|
||||
values = [];
|
||||
}
|
||||
else if (!(values instanceof Array)) {
|
||||
values = [values];
|
||||
}
|
||||
|
||||
delete options.shiftKey;
|
||||
_(values).each(function (value) {
|
||||
var model = this._prepareModel(value, options);
|
||||
Backbone.Collection.prototype.add.call(this, model, options);
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.constructor.__super__.add.call(this, values, options);
|
||||
}
|
||||
}
|
||||
}).prototype;
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue