3
0
Fork 0

[MIG] Migrate web_search_with_and from 8.0 to 10.0

12.0
adrien.didenot 2017-02-02 16:57:27 +01:00 committed by David Dufresne
parent e47ca7ed6f
commit 13eb97b196
5 changed files with 55 additions and 36 deletions

View File

@ -26,7 +26,15 @@ Usage
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/8.0 :target: https://runbot.odoo-community.org/runbot/162/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits Credits
======= =======
@ -35,6 +43,7 @@ Contributors
------------ ------------
* Andrius Preimantas <andrius@versada.lt> * Andrius Preimantas <andrius@versada.lt>
* Adrien Didenot <adrien.didenot@horanet.com>
Maintainer Maintainer
---------- ----------
@ -49,4 +58,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
To contribute to this module, please visit http://odoo-community.org. To contribute to this module, please visit http://odoo-community.org.

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2015 Andrius Preimantas <andrius@versada.lt> # Copyright 2015 Andrius Preimantas <andrius@versada.lt>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': "Use AND conditions on omnibar search", 'name': "Use AND conditions on omnibar search",
'version': '8.0.1.0.0', 'version': '10.0.1.0.0',
'author': 'Versada UAB, Odoo Community Association (OCA)', 'author': 'Versada UAB, Odoo Community Association (OCA)',
'license': 'AGPL-3', 'license': 'AGPL-3',
'category': 'web', 'category': 'web',

View File

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp> <odoo>
<data> <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>
</data>
</openerp>

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -1,43 +1,55 @@
openerp.web_search_with_and = function (instance) { odoo.define('web_search_with_and', function (require) {
"use strict";
instance.web.SearchView = instance.web.SearchView.extend({ var SearchView = require('web.SearchView');
var Backbone = window.Backbone;
SearchView.include({
// Override the base method to detect a 'shift' event
select_completion: function (e, ui) { select_completion: function (e, ui) {
var self = this; if (e.shiftKey
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
e.preventDefault(); e.preventDefault();
var input_index = _(this.input_subviews).indexOf( this.query.add(ui.item.facet, {shiftKey: true});
this.subviewForRoot(
this.$('div.oe_searchview_input:focus')[0]));
this.query.add(ui.item.facet, {at: input_index / 2, shiftKey: true});
} else { } else {
this._super(e, ui);
return this._super.apply(this, arguments);
} }
}, }
}); });
instance.web.search.SearchQuery = instance.web.search.SearchQuery.extend({ 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) { add: function (values, options) {
options = options || {}; options = options || {};
if (!values) {
values = [];
} else if (!(values instanceof Array)) {
values = [values];
}
if (options.shiftKey) { if (options.shiftKey) {
if (!values) {
values = [];
}
else if (!(values instanceof Array)) {
values = [values];
}
delete options.shiftKey; delete options.shiftKey;
_(values).each(function (value) { _(values).each(function (value) {
var model = this._prepareModel(value, options); var model = this._prepareModel(value, options);
Backbone.Collection.prototype.add.call(this, model, options); Backbone.Collection.prototype.add.call(this, model, options);
}, this); }, this);
return this; return this;
} }
else { else {
return this.constructor.__super__.add.apply(this, arguments); return this.constructor.__super__.add.call(this, values, options);
} }
}, }
}); }).prototype;
};
});