mirror of https://github.com/OCA/web.git
[INIT][web_search_with_and]
parent
dae7460ce8
commit
1f3ef8cc7a
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of OpenERP. The COPYRIGHT file at the top level of
|
||||
# this module contains the full copyright notices and license terms.
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2014 by UAB Versada (Ltd.) <http://www.versada.lt>
|
||||
# and contributors. See AUTHORS for more details.
|
||||
#
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
{
|
||||
'name': "Force AND on Search Input",
|
||||
'version': '0.1',
|
||||
'author': 'Versada UAB, Odoo Community Association (OCA)',
|
||||
'category': 'web',
|
||||
'website': 'http://www.versada.lt',
|
||||
'description': """
|
||||
When searching on same field multiple times Odoo joins queries with OR.
|
||||
Press Shift key to join them with AND.
|
||||
|
||||
This gives the same affect as using Advanced Search on same field several times.
|
||||
""",
|
||||
'depends': [
|
||||
'web',
|
||||
],
|
||||
'data': [
|
||||
'data.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<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>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,43 @@
|
|||
openerp.web_search_with_and = function (instance) {
|
||||
|
||||
instance.web.SearchView = instance.web.SearchView.extend({
|
||||
select_completion: function (e, ui) {
|
||||
var self = this;
|
||||
if (e.shiftKey) {
|
||||
e.preventDefault();
|
||||
|
||||
var input_index = _(this.input_subviews).indexOf(
|
||||
this.subviewForRoot(
|
||||
this.$('div.oe_searchview_input:focus')[0]));
|
||||
this.query.add(ui.item.facet, {at: input_index / 2, shiftKey: true});
|
||||
} else {
|
||||
this._super(e, ui);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
instance.web.search.SearchQuery = instance.web.search.SearchQuery.extend({
|
||||
add: function (values, options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (!values) {
|
||||
values = [];
|
||||
} else if (!(values instanceof Array)) {
|
||||
values = [values];
|
||||
}
|
||||
|
||||
if (options.shiftKey) {
|
||||
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.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue