# HG changeset patch
# User Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
# Date 1287670925 -7200
#      Thu Oct 21 16:22:05 2010 +0200
# Node ID 57a92eae8941b1b6a8d09e87002714928d4ea286
# Parent  ab6783fd3a15ec39e21b670ce905b7f545aaf968
[widgets] use LazyRestrictedAutoCompletionWidget instead of RestirectedAUtoCompletionWidget

diff --git a/views/__init__.py b/views/__init__.py
--- a/views/__init__.py
+++ b/views/__init__.py
@@ -9,10 +9,19 @@
 _afs.tag_subject_of(('Expense', 'spent_for', '*'), 'main', 'attributes')
 _afs.tag_subject_of(('Expense', 'spent_for', '*'), 'muledit', 'attributes')
 _affk.tag_subject_of(('Expense', 'spent_for', '*'),
-                     {'widget': fw.RestrictedAutoCompletionWidget(autocomplete_initfunc='get_concerned_by')})
+                     {'widget': fw.LazyRestrictedAutoCompletionWidget(
+            autocomplete_initfunc='get_concerned_by',
+            autocomplete_settings={'limit': 100,
+                                   'delay': 300}),
+                      })
 
 
 @monkeypatch(basecontrollers.JSonController)
 @basecontrollers.jsonize
 def js_get_concerned_by(self):
-    return self._cw.execute('DISTINCT Any W,R ORDERBY R WHERE W ref R').rows
+    term = self._cw.form['q']
+    limit = self._cw.form.get('limit', 50)
+    return [{'value': eid, 'label': ref}
+            for eid, ref in self._cw.execute('DISTINCT Any W,R ORDERBY R LIMIT %s WHERE W ref R,'
+                                             'W ref ILIKE %%(term)s' % limit,
+                                             {'term': u'%%%s%%' % term})]