diff --git a/web_search_autocomplete_prefetch/README.rst b/web_search_autocomplete_prefetch/README.rst index 88b25800..0df604e0 100644 --- a/web_search_autocomplete_prefetch/README.rst +++ b/web_search_autocomplete_prefetch/README.rst @@ -1,27 +1,41 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License: AGPL-3 - ============================ Prefetch autocomplete offers ============================ +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/10.0/web_search_autocomplete_prefetch + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-10-0/web-10-0-web_search_autocomplete_prefetch + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + When searching, the autocomplete options can be a bit frustrating because you will be offered choices that won't yield a result. This addon searches for the term in the background and only offers an option if this search has a result. -Usage -===== - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/8.0 - -For further information, please visit: +**Table of contents** -* https://www.odoo.com/forum/help-1 +.. contents:: + :local: -Known issues / Roadmap -====================== +Configuration +============= * some searches (especially via function fields) can be very heavy on the server. @@ -32,38 +46,46 @@ Known issues / Roadmap on your field in the search view. * by default, the addon triggers a search 350 milliseconds after the last key - pess. If you want a different timeout, set the parameter + press. If you want a different timeout, set the parameter ``web_search_autocomplete_prefetch.keypress_timeout`` to the amount of milliseconds you need as timeout. - Bug Tracker =========== Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* Therp BV + Contributors ------------- +~~~~~~~~~~~~ * Holger Brunn -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit https://odoo-community.org. +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_search_autocomplete_prefetch/__init__.py b/web_search_autocomplete_prefetch/__init__.py index 6d9656f1..94673b34 100644 --- a/web_search_autocomplete_prefetch/__init__.py +++ b/web_search_autocomplete_prefetch/__init__.py @@ -1,3 +1,2 @@ # -*- coding: utf-8 -*- -# © 2015 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_search_autocomplete_prefetch/__openerp__.py b/web_search_autocomplete_prefetch/__manifest__.py similarity index 81% rename from web_search_autocomplete_prefetch/__openerp__.py rename to web_search_autocomplete_prefetch/__manifest__.py index 03db260a..492421d2 100644 --- a/web_search_autocomplete_prefetch/__openerp__.py +++ b/web_search_autocomplete_prefetch/__manifest__.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -# © 2015 Therp BV +# Copyright 2015-2018 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Prefetch autocomplete offers", - "version": "8.0.1.0.0", + "version": "10.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", "license": "AGPL-3", "category": "Usability", "summary": "Offer only items on autocompletion that will yield results", diff --git a/web_search_autocomplete_prefetch/readme/CONFIGURE.rst b/web_search_autocomplete_prefetch/readme/CONFIGURE.rst new file mode 100644 index 00000000..c56e2e8d --- /dev/null +++ b/web_search_autocomplete_prefetch/readme/CONFIGURE.rst @@ -0,0 +1,12 @@ +* some searches (especially via function fields) can be very heavy on the + server. + To disable prefetching on a per field basis, set the option + `web_search_autocomplete_prefetch.disable`:: + + options="{'web_search_autocomplete_prefetch.disable': true}" + + on your field in the search view. +* by default, the addon triggers a search 350 milliseconds after the last key + press. If you want a different timeout, set the parameter + ``web_search_autocomplete_prefetch.keypress_timeout`` to the amount of + milliseconds you need as timeout. diff --git a/web_search_autocomplete_prefetch/readme/CONTRIBUTORS.rst b/web_search_autocomplete_prefetch/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b120a956 --- /dev/null +++ b/web_search_autocomplete_prefetch/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Holger Brunn diff --git a/web_search_autocomplete_prefetch/readme/DESCRIPTION.rst b/web_search_autocomplete_prefetch/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c6509e38 --- /dev/null +++ b/web_search_autocomplete_prefetch/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +When searching, the autocomplete options can be a bit frustrating because you +will be offered choices that won't yield a result. This addon searches for the +term in the background and only offers an option if this search has a result. diff --git a/web_search_autocomplete_prefetch/static/description/index.html b/web_search_autocomplete_prefetch/static/description/index.html new file mode 100644 index 00000000..0d1a5320 --- /dev/null +++ b/web_search_autocomplete_prefetch/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Prefetch autocomplete offers + + + +
+

Prefetch autocomplete offers

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

When searching, the autocomplete options can be a bit frustrating because you +will be offered choices that won’t yield a result. This addon searches for the +term in the background and only offers an option if this search has a result.

+

Table of contents

+ +
+

Configuration

+
    +
  • some searches (especially via function fields) can be very heavy on the +server. +To disable prefetching on a per field basis, set the option +web_search_autocomplete_prefetch.disable:

    +
    +options="{'web_search_autocomplete_prefetch.disable': true}"
    +
    +

    on your field in the search view.

    +
  • +
  • by default, the addon triggers a search 350 milliseconds after the last key +press. If you want a different timeout, set the parameter +web_search_autocomplete_prefetch.keypress_timeout to the amount of +milliseconds you need as timeout.

    +
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_search_autocomplete_prefetch/static/src/js/web_search_autocomplete_prefetch.js b/web_search_autocomplete_prefetch/static/src/js/web_search_autocomplete_prefetch.js index 1d34dde5..a4131e38 100644 --- a/web_search_autocomplete_prefetch/static/src/js/web_search_autocomplete_prefetch.js +++ b/web_search_autocomplete_prefetch/static/src/js/web_search_autocomplete_prefetch.js @@ -1,127 +1,144 @@ //-*- coding: utf-8 -*- -//© 2015 Therp BV +//Copyright 2015-2018 Therp BV //License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +odoo.define('web_search_autocomplete_prefetch', function(require) { + var CompoundDomain = require('web.data').CompoundDomain, + Mutex = require('web.utils').Mutex; -openerp.web_search_autocomplete_prefetch = function(instance) -{ - // overwrite this or use it to recycle the functionality for your own field - openerp.web_search_autocomplete_prefetch.complete = function(self, value, data) - { - if(self.options['web_search_autocomplete_prefetch.disable']) - { + var complete = function(self, value, data) { + if(self.options['web_search_autocomplete_prefetch.disable']) { return data; } - if(!self.autocomplete_mutex) - { - self.autocomplete_mutex = new instance.Mutex() + if(!self.autocomplete_mutex) { + self.autocomplete_mutex = new Mutex(); } var facet = { - get: function(name) - { - switch(name) - { + get: function(name) { + switch(name) { case 'label': return value; case 'value': return value; case 'operator': return 'ilike'; } }, + attributes: { + value: value, + }, }, - domain = new instance.web.CompoundDomain( + domain = new CompoundDomain( self.get_domain({values: [facet]}), - self.view.dataset.domain); - domain.set_eval_context(self.view.dataset.get_context()); - return self.autocomplete_mutex.exec(function() - { - return self.view.dataset._model.call( + self.searchview.dataset.domain + ); + domain.set_eval_context(self.searchview.dataset.get_context()); + return self.autocomplete_mutex.exec(function() { + return self.searchview.dataset._model.call( 'search_count', [domain.eval()], - {context: self.view.dataset.get_context()}) - .then(function(count) - { - if(count) - { - _.each(data, function(obj) - { - obj.label += _.str.sprintf(' (%s)', count); - }); - return data; - } - else - { - return null; - } - }); + {context: self.searchview.dataset.get_context()} + ) + .then(function(count) { + if(count) { + _.each(data, function(obj) { + obj.label += _.str.sprintf(' (%s)', count); + }); + return data; + } + return null; + }); }); - } + }; - instance.web.search.CharField.include({ - init: function() - { + return { + // overwrite this or use it to recycle the functionality + // for your own field + complete: complete, + }; +}); + +odoo.define('web_search_autocomplete_prefetch.inputs', function(require) { + var AutoComplete = require('web.AutoComplete'), + Field = require('web.search_inputs').Field, + Model = require('web.Model'), + pyeval = require('web.pyeval'), + search_widgets_registry = require('web.core').search_widgets_registry, + web_search_autocomplete_prefetch = require( + 'web_search_autocomplete_prefetch' + ); + + Field.include({ + init: function() { var result = this._super.apply(this, arguments); - this.options = instance.web.py_eval(this.attrs.options || '{}'); + this.options = pyeval.py_eval(this.attrs.options || '{}'); return result; }, - complete: function(value) - { + }); + + search_widgets_registry.get('char').include({ + complete: function(value) { var self = this; - return this._super.apply(this, arguments).then(function(data) - { - return openerp.web_search_autocomplete_prefetch.complete( - self, value, data); + return this._super.apply(this, arguments).then(function(data) { + return web_search_autocomplete_prefetch.complete( + self, value, data + ); }); } }); - instance.web.search.ManyToOneField.include({ - complete: function(value) - { + search_widgets_registry.get('many2one').include({ + complete: function(value) { var self = this; - return this._super.apply(this, arguments).then(function(data) - { - return openerp.web_search_autocomplete_prefetch.complete( - self, value, data); + return this._super.apply(this, arguments).then(function(data) { + return web_search_autocomplete_prefetch.complete( + self, value, data + ); }); } }); - instance.web.search.AutoComplete.include({ + search_widgets_registry.get('selection').include({ + complete: function(value) { + var self = this; + return this._super.apply(this, arguments).then(function(data) { + return web_search_autocomplete_prefetch.complete( + self, value, data + ); + }); + } + }); + + AutoComplete.include({ keypress_timeout: 350, - start: function() - { + start: function() { var self = this; return jQuery.when( this._super.apply(this, arguments), - new instance.web.Model('ir.config_parameter').call( + new Model('ir.config_parameter').call( 'get_param', [ 'web_search_autocomplete_prefetch.keypress_timeout', this.keypress_timeout ] - ).then(function(keypress_timeout) - { - self.keypress_timeout = parseInt(keypress_timeout); + ).then(function(keypress_timeout) { + self.keypress_timeout = parseInt(keypress_timeout, 10); }) ); }, - select_item: function() - { - if(!this.current_result) - { + select_item: function() { + if(!this.current_result) { return; } return this._super.apply(this, arguments); }, - initiate_search: function(query) - { + initiate_search: function(query) { var self = this, _super = this._super, last_timeout = null; - this.last_timeout = last_timeout = window.setTimeout(function() - { - if(self.last_timeout == last_timeout) - { - _super.apply(self, [query]); - } - }, this.keypress_timeout) + this.last_timeout = last_timeout = window.setTimeout( + function() { + if(self.last_timeout === last_timeout) { + _super.apply(self, [query]); + } + }, + this.keypress_timeout + ); }, }); -} +}); diff --git a/web_search_autocomplete_prefetch/views/base_view.xml b/web_search_autocomplete_prefetch/views/base_view.xml index 2c6a9723..f5fd09bc 100644 --- a/web_search_autocomplete_prefetch/views/base_view.xml +++ b/web_search_autocomplete_prefetch/views/base_view.xml @@ -1,16 +1,12 @@ - - - - ir.ui.view - - - + + + ir.ui.view + + - {'web_search_autocomplete_prefetch.disable': true} + {'web_search_autocomplete_prefetch.disable': true} - - - - - + + + diff --git a/web_search_autocomplete_prefetch/views/templates.xml b/web_search_autocomplete_prefetch/views/templates.xml index 624c099d..8d4e89e5 100644 --- a/web_search_autocomplete_prefetch/views/templates.xml +++ b/web_search_autocomplete_prefetch/views/templates.xml @@ -1,10 +1,8 @@ - - - - - + + +