summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Fretin <vincent.fretin@gmail.com>2013-02-20 15:51:40 (GMT)
committerVincent Fretin <vincent.fretin@gmail.com>2013-02-20 15:51:40 (GMT)
commit212370ce1f8e94b1d757afbbb554e2b05d72d275 (patch)
treece2cb21b8c76856ae58fd170d1723cf162bc71fa
parentd7a215003e7f6869c9caee453fd938c51567ad51 (diff)
downloadcollective.contact.widget-212370ce1f8e94b1d757afbbb554e2b05d72d275.zip
collective.contact.widget-212370ce1f8e94b1d757afbbb554e2b05d72d275.tar.gz
collective.contact.widget-212370ce1f8e94b1d757afbbb554e2b05d72d275.tar.bz2
Term has now a portal_type, url and extra, so we can customise autocomplete search result
-rw-r--r--src/collective/contact/widget/source.py24
-rw-r--r--src/collective/contact/widget/widgets.py24
2 files changed, 37 insertions, 11 deletions
diff --git a/src/collective/contact/widget/source.py b/src/collective/contact/widget/source.py
index 1b76d13..767ba3a 100644
--- a/src/collective/contact/widget/source.py
+++ b/src/collective/contact/widget/source.py
@@ -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'
diff --git a/src/collective/contact/widget/widgets.py b/src/collective/contact/widget/widgets.py
index 5e0ef8d..38add4e 100644
--- a/src/collective/contact/widget/widgets.py
+++ b/src/collective/contact/widget/widgets.py
@@ -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)])