From 1011453e55aca23ece466c2bab9a97e85b259f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 2 Oct 2015 11:49:23 +0200 Subject: [PATCH] Replace typeahead by custom completion based on bootstrap dropdown review20421002 --- bower.json | 1 - index.html | 2 - src/common.js | 230 ++++++++++++++++++++++++++++++++------------- src/sao.js | 72 +++++--------- src/sao.less | 5 + src/screen.js | 41 ++++---- src/typeahead.less | 82 ---------------- src/view.js | 124 ++++++++++++------------ 8 files changed, 275 insertions(+), 282 deletions(-) delete mode 100644 src/typeahead.less diff --git a/bower.json b/bower.json index 3fb468d943..0b38156350 100644 --- a/bower.json +++ b/bower.json @@ -19,7 +19,6 @@ "bootstrap": "~3.3.4", "moment": "~2.10.2", "eonasdan-bootstrap-datetimepicker": "~4.7.14", - "typeahead.js": "~0.11.1", "gettext.js": "~0.5.0", "d3": "~3.5.0", "c3": "~0.4.10" diff --git a/index.html b/index.html index 958f7ab8c3..baad555f6a 100644 --- a/index.html +++ b/index.html @@ -13,14 +13,12 @@ this repository contains the full copyright notices and license terms. --> - - diff --git a/src/common.js b/src/common.js index 8e9af9600c..c949a93980 100644 --- a/src/common.js +++ b/src/common.js @@ -2935,74 +2935,174 @@ }); Sao.common.processing = new Sao.common.Processing(); - Sao.common.get_completion = function(entry, source, match_selected) { - entry.attr('autocomplete', 'off'); - entry.typeahead({ - 'minLength': 1, - 'highlight': true - }, { - 'limit': Sao.config.limit, - 'name': 'suggestions', - 'source': source, - 'displayKey': 'rec_name', - }, { - 'name': 'actions', - 'source': function(query, process) { - var results = []; - if (entry.data('search')) { - results.push({ - 'id': 'search', - 'action': Sao.i18n.gettext('Search...'), - 'query': query - }); - } - if (entry.data('create')) { - results.push({ - 'id': 'create', - 'action': Sao.i18n.gettext('Create...'), - 'query': query - }); - } - process(results); - }, - 'displayKey': 'query', - 'templates': { - 'suggestion': function(context) { - return '

' + context.action + '

'; - } - } - }); - entry.on('typeahead:select', match_selected); - }; - Sao.common.update_completion = function(entry, record, field, model, - domain) { - var prm = jQuery.Deferred(); - var update = function(search_text, domain) { - if (entry.typeahead('val') != search_text) { - return prm.reject(); - } - if (!search_text || !model) { - return prm.reject(); - } - if (domain === undefined) { - domain = field.get_domain(record); - } - var context = field.get_context(record); - domain = [['rec_name', 'ilike', '%' + search_text + '%'], domain]; + Sao.common.InputCompletion = Sao.class_(Object, { + init: function(el, source, match_selected, format) { + el.wrap('