forked from Techsystech/web
[13.0][MIG] - migration web_search_with_and
parent
5089fa896b
commit
ccb5f1158d
|
@ -0,0 +1 @@
|
||||||
|
../../../../web_search_with_and
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
|
@ -1,17 +1,14 @@
|
||||||
# Copyright 2015 Andrius Preimantas <andrius@versada.lt>
|
# 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).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': "Use AND conditions on omnibar search",
|
"name": "Use AND conditions on omnibar search",
|
||||||
'version': '12.0.1.0.0',
|
"version": "13.0.1.0.0",
|
||||||
'author': 'Versada UAB, Odoo Community Association (OCA)',
|
"author": "Versada UAB, ACSONE SA/NV, Odoo Community Association (OCA)",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'category': 'web',
|
"category": "web",
|
||||||
'website': 'https://github.com/OCA/web',
|
"website": "https://github.com/OCA/web",
|
||||||
'depends': [
|
"depends": ["web"],
|
||||||
'web',
|
"data": ["data/data.xml"],
|
||||||
],
|
|
||||||
'data': [
|
|
||||||
'data/data.xml',
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<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">
|
<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>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
* Adrien Didenot <adrien.didenot@horanet.com>
|
* Adrien Didenot <adrien.didenot@horanet.com>
|
||||||
* Francesco Apruzzese <f.apruzzese@apuliasoftware.it>
|
* Francesco Apruzzese <f.apruzzese@apuliasoftware.it>
|
||||||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
|
* 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";
|
"use strict";
|
||||||
|
|
||||||
var SearchView = require('web.SearchView');
|
var searchBarAutocompleteRegistry = require("web.search_bar_autocomplete_sources_registry");
|
||||||
var Backbone = window.Backbone;
|
var SearchBar = require("web.SearchBar");
|
||||||
|
|
||||||
SearchView.include({
|
SearchBar.include({
|
||||||
// Override the base method to detect a 'shift' event
|
// Override the base method to detect a "shift" event
|
||||||
select_completion: function (e, ui) {
|
_onAutoCompleteSelected: function(e, ui) {
|
||||||
if (e.shiftKey
|
var values = ui.item.facet.values;
|
||||||
&& ui.item.facet.values
|
if (
|
||||||
&& ui.item.facet.values.length
|
e.shiftKey &&
|
||||||
&& String(ui.item.facet.values[0].value).trim() !== "") {
|
values &&
|
||||||
// In case of an 'AND' search a new facet is added regarding of the previous facets
|
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();
|
e.preventDefault();
|
||||||
|
var filter = ui.item.facet.filter;
|
||||||
this.query.add(ui.item.facet, {shiftKey: true});
|
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 {
|
} else {
|
||||||
|
|
||||||
return this._super.apply(this, arguments);
|
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