From 1f3ef8cc7a98445356f0da14d98a82f4941505f6 Mon Sep 17 00:00:00 2001 From: Andrius Preimantas Date: Mon, 27 Apr 2015 17:56:12 +0300 Subject: [PATCH] [INIT][web_search_with_and] --- web_search_with_and/__init__.py | 4 ++ web_search_with_and/__openerp__.py | 44 +++++++++++++++++++++ web_search_with_and/data.xml | 10 +++++ web_search_with_and/static/src/js/search.js | 43 ++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 web_search_with_and/__init__.py create mode 100644 web_search_with_and/__openerp__.py create mode 100644 web_search_with_and/data.xml create mode 100644 web_search_with_and/static/src/js/search.js diff --git a/web_search_with_and/__init__.py b/web_search_with_and/__init__.py new file mode 100644 index 00000000..2fc5376b --- /dev/null +++ b/web_search_with_and/__init__.py @@ -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. + diff --git a/web_search_with_and/__openerp__.py b/web_search_with_and/__openerp__.py new file mode 100644 index 00000000..5b873ea5 --- /dev/null +++ b/web_search_with_and/__openerp__.py @@ -0,0 +1,44 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014 by UAB Versada (Ltd.) +# 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 . +# +############################################################################## + +{ + '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, +} diff --git a/web_search_with_and/data.xml b/web_search_with_and/data.xml new file mode 100644 index 00000000..a7842349 --- /dev/null +++ b/web_search_with_and/data.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/web_search_with_and/static/src/js/search.js b/web_search_with_and/static/src/js/search.js new file mode 100644 index 00000000..8c052e40 --- /dev/null +++ b/web_search_with_and/static/src/js/search.js @@ -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); + } + }, + }); +};