From ac68afda065fb53f3ff10ccab72da0551bff639e Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 16 May 2016 11:24:48 +0200 Subject: [PATCH 1/4] [FIX] pass dataset's context to search_count --- .../static/src/js/web_search_autocomplete_prefetch.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 b9f825880..1ff401efe 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 @@ -33,7 +33,8 @@ openerp.web_search_autocomplete_prefetch = function(instance) return self.autocomplete_mutex.exec(function() { return self.view.dataset._model.call( - 'search_count', [domain.eval()]) + 'search_count', [domain.eval()], + {context: self.view.dataset.get_context()}) .then(function(count) { if(count) From f851728d0f73620208ca540fa8ab50b8155c9e72 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 1 May 2017 18:53:56 +0200 Subject: [PATCH 2/4] [ADD] search only a few milliseconds after a keypress --- .../src/js/web_search_autocomplete_prefetch.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 1ff401efe..4ae89e9ff 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 @@ -84,6 +84,7 @@ openerp.web_search_autocomplete_prefetch = function(instance) }); instance.web.search.AutoComplete.include({ + keypress_timeout: 200, select_item: function() { if(!this.current_result) @@ -92,5 +93,18 @@ openerp.web_search_autocomplete_prefetch = function(instance) } return this._super.apply(this, arguments); }, + 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) + }, }); } From 66c70fffbe5d5a8ffc1a1a75493b36794b01658c Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 1 May 2017 19:11:22 +0200 Subject: [PATCH 3/4] [IMP] slightly higher timeout --- .../static/src/js/web_search_autocomplete_prefetch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4ae89e9ff..99556afa9 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 @@ -84,7 +84,7 @@ openerp.web_search_autocomplete_prefetch = function(instance) }); instance.web.search.AutoComplete.include({ - keypress_timeout: 200, + keypress_timeout: 350, select_item: function() { if(!this.current_result) From 08b3b724f042f3269b0ba60ce6ca343fd3e26a58 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 5 May 2017 12:05:02 +0200 Subject: [PATCH 4/4] [ADD] make prefetch timeout configurable --- web_search_autocomplete_prefetch/README.rst | 9 +++++++-- .../src/js/web_search_autocomplete_prefetch.js | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/web_search_autocomplete_prefetch/README.rst b/web_search_autocomplete_prefetch/README.rst index e8f8af570..88b25800c 100644 --- a/web_search_autocomplete_prefetch/README.rst +++ b/web_search_autocomplete_prefetch/README.rst @@ -12,7 +12,6 @@ term in the background and only offers an option if this search has a result. Usage ===== -* go to ... .. 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 @@ -26,11 +25,17 @@ Known issues / Roadmap * 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 + pess. 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 =========== 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 99556afa9..1d34dde55 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 @@ -85,6 +85,23 @@ openerp.web_search_autocomplete_prefetch = function(instance) instance.web.search.AutoComplete.include({ keypress_timeout: 350, + start: function() + { + var self = this; + return jQuery.when( + this._super.apply(this, arguments), + new instance.web.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); + }) + ); + }, select_item: function() { if(!this.current_result)