Term has now a portal_type, url and extra, so we can customise autocomplete search result
parent
d7a215003e
commit
212370ce1f
|
@ -7,6 +7,24 @@ from plone.formwidget.contenttree.source import PathSourceBinder, ObjPathSource
|
|||
from Products.CMFPlone.utils import base_hasattr, getToolByName
|
||||
|
||||
|
||||
class Term(SimpleTerm):
|
||||
def __init__(self, value, token=None, title=None, brain=None):
|
||||
super(Term, self).__init__(value, token, title)
|
||||
self.brain = brain
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self.brain.getURL()
|
||||
|
||||
@property
|
||||
def portal_type(self):
|
||||
return self.brain.portal_type
|
||||
|
||||
@property
|
||||
def extra(self):
|
||||
return u""
|
||||
|
||||
|
||||
def parse_query(query, path_prefix=""):
|
||||
"""Copied from plone.app.vocabularies.catalog.parse_query
|
||||
but depth=1 removed.
|
||||
|
@ -47,10 +65,10 @@ class ContactSource(ObjPathSource):
|
|||
# TODO avoid to wake up object, create a get_full_title brain metadada
|
||||
if base_hasattr(brain.getObject(), "get_full_title"):
|
||||
full_title = brain.getObject().get_full_title()
|
||||
return SimpleTerm(value, token=brain.getPath(), title=full_title)
|
||||
return Term(value, token=brain.getPath(), title=full_title, brain=brain)
|
||||
else:
|
||||
return SimpleTerm(value, token=brain.getPath(), title=brain.Title or
|
||||
brain.id)
|
||||
return Term(value, token=brain.getPath(), title=brain.Title or
|
||||
brain.id, brain=brain)
|
||||
|
||||
def tokenToPath(self, token):
|
||||
"""For token='/Plone/a/b', return '/a/b'
|
||||
|
|
|
@ -49,17 +49,16 @@ $(document).ready(function() {
|
|||
input_box.flushCache();
|
||||
// trigger change event on newly added input element
|
||||
var input = input_box.parents('.querySelectSearch').parent('div').siblings('.autocompleteInputWidget').find('input').last();
|
||||
ccw.add_contact_preview(input);
|
||||
var url = data[3];
|
||||
ccw.add_contact_preview(input, url);
|
||||
input.trigger('change');
|
||||
}
|
||||
return noform;
|
||||
};
|
||||
|
||||
var pendingCall = {timeStamp: null, procID: null};
|
||||
ccw.add_contact_preview = function (input) {
|
||||
var path = input.val().split('/').slice(2).join('/');
|
||||
if (path) {
|
||||
var url = portal_url+'/'+path;
|
||||
ccw.add_contact_preview = function (input, url) {
|
||||
if (url) {
|
||||
input.siblings('.label')
|
||||
.wrapInner('<a href="'+url+'" class="link-tooltip">');
|
||||
}
|
||||
|
@ -125,9 +124,17 @@ class TermViewlet(grok.Viewlet):
|
|||
title = title.decode('utf-8')
|
||||
return title
|
||||
|
||||
@property
|
||||
def portal_type(self):
|
||||
return self.context.portal_type
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self.context.absolute_url()
|
||||
|
||||
def render(self):
|
||||
return u"""<input type="hidden" name="objpath" value="%s" />""" % (
|
||||
'|'.join([self.token, self.title]))
|
||||
'|'.join([self.token, self.title, self.portal_type, self.url]))
|
||||
|
||||
OVERLAY_TEMPLATE = """
|
||||
$('#%(id)s-autocomplete').find('.%(klass)s'
|
||||
|
@ -158,7 +165,8 @@ function (event, data, formatted) {
|
|||
formwidget_autocomplete_new_value(input_box,data[0],data[1]);
|
||||
// trigger change event on newly added input element
|
||||
var input = input_box.parents('.querySelectSearch').parent('div').siblings('.autocompleteInputWidget').find('input').last();
|
||||
ccw.add_contact_preview(input);
|
||||
var url = data[3];
|
||||
ccw.add_contact_preview(input, url);
|
||||
input.trigger('change');
|
||||
}(jQuery));
|
||||
}
|
||||
|
@ -251,5 +259,5 @@ class AutocompleteSearch(BaseAutocompleteSearch):
|
|||
else:
|
||||
terms = set()
|
||||
|
||||
return '\n'.join(["%s|%s" % (t.token, t.title or t.token)
|
||||
return '\n'.join(["|".join((t.token, t.title or t.token, t.portal_type, t.url, t.extra))
|
||||
for t in sorted(terms, key=lambda t: t.title)])
|
||||
|
|
Reference in New Issue