update to work with latest plone.formwidget.autocomplete
This commit is contained in:
parent
04fd35f1da
commit
83770551bb
|
@ -29,13 +29,14 @@
|
|||
</div>
|
||||
|
||||
<script type="text/javascript" tal:condition="python: 'ajax_load' not in request.form.keys()">
|
||||
function autocomplete_ready(event, data, formatted) {
|
||||
window.location=window.location+'/'+data[1];
|
||||
function autocomplete_ready(event, ui) {
|
||||
window.location=window.location+'/'+ui.item.value;
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.keyword-search').autocomplete('listKeywords', {
|
||||
'cacheLength': 0, 'matchContains': true, 'scroll': true, 'max': 30}).result(autocomplete_ready);
|
||||
$('.keyword-search').autocomplete({'source': 'listKeywords',
|
||||
'cacheLength': 0, 'matchContains': true, 'scroll': true, 'max': 30,
|
||||
'select': autocomplete_ready});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -73,16 +74,17 @@ function prep_thesaurus_overlay() {
|
|||
|
||||
prep_thesaurus_overlay();
|
||||
|
||||
function autocomplete_ready(event, data, formatted) {
|
||||
var keyword_id = data[1];
|
||||
function autocomplete_ready(event, ui) {
|
||||
var keyword_id = ui.item.value;
|
||||
$(this).parents('.overlay-ajax').data('keyword-id', keyword_id);
|
||||
thesaurus_url = $('#dmskeywords-navigation').data('thesaurus-url');
|
||||
$('.pb-ajax > div').load(thesaurus_url+'/'+data[1] + '?ajax_load=123 #content>*', prep_thesaurus_overlay);
|
||||
$('.pb-ajax > div').load(thesaurus_url+'/' + keyword_id + '?ajax_load=123 #content>*', prep_thesaurus_overlay);
|
||||
}
|
||||
|
||||
thesaurus_url = $('#dmskeywords-navigation').data('thesaurus-url');
|
||||
$('.keyword-search').autocomplete(thesaurus_url + '/listKeywords', {
|
||||
'cacheLength': 0, 'matchContains': true, 'scroll': true, 'max': 30}).result(autocomplete_ready);
|
||||
$('.keyword-search').autocomplete({'source': thesaurus_url + '/listKeywords',
|
||||
'cacheLength': 0, 'matchContains': true, 'scroll': true, 'max': 30,
|
||||
'select': autocomplete_ready});
|
||||
|
||||
|
||||
</script>
|
||||
|
|
|
@ -53,3 +53,7 @@
|
|||
display: block;
|
||||
padding-top: 1ex;
|
||||
}
|
||||
|
||||
ul.ui-autocomplete.ui-front {
|
||||
z-index: 12000;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
|
||||
from zope.interface import implementer
|
||||
from zope.interface import implements
|
||||
from zope.interface import Interface
|
||||
|
@ -115,9 +117,10 @@ class ListKeywordsView(BrowserView):
|
|||
return self._items
|
||||
|
||||
def __call__(self):
|
||||
self.request.response.setHeader('Content-type', 'text/plain')
|
||||
self.request.response.setHeader('Content-type', 'application/json')
|
||||
|
||||
query_string = unicode(self.request.form.get('term'), 'utf-8')
|
||||
|
||||
query_string = unicode(self.request.form.get('q'), 'utf-8')
|
||||
query_terms = [normalizer.normalize(x) for x in query_string.split()]
|
||||
|
||||
startswith = []
|
||||
|
@ -129,7 +132,7 @@ class ListKeywordsView(BrowserView):
|
|||
if not term in title.lower():
|
||||
break
|
||||
else:
|
||||
item = '%s|%s' % (title, id)
|
||||
item = {'label': title, 'value': id}
|
||||
if title.lower().startswith(q):
|
||||
startswith.append((normalized, item))
|
||||
continue
|
||||
|
@ -148,5 +151,8 @@ class ListKeywordsView(BrowserView):
|
|||
for item in _list:
|
||||
result.append(item[1])
|
||||
if len(result) > 29:
|
||||
return '\n'.join(result)
|
||||
return '\n'.join(result)
|
||||
break
|
||||
else:
|
||||
continue
|
||||
break
|
||||
return json.dumps(result)
|
||||
|
|
Reference in New Issue