diff --git a/tabellio/searchform/docsearchpfb.pt b/tabellio/searchform/docsearchpfb.pt index f257bf2..eff4478 100644 --- a/tabellio/searchform/docsearchpfb.pt +++ b/tabellio/searchform/docsearchpfb.pt @@ -119,10 +119,42 @@ function author_autocomplete_ready(event, data, formatted) { }(jQuery)); } +function sync_from_checkboxes(elem, dummyinput) +{ + t = ''; + $(elem).find('span.option').each(function(idx, el) { + if ($(el).find('input').attr('checked')) { + if (t.length > 0) { + t = t + ', '; + } + t = t + $(el).find('label span').text(); + } + }); + $(dummyinput).attr('value', t); +} + +function setup_appearance(index, elem) +{ + var dummyinput = $(''); + console.log('dummy input:', dummyinput); + sync_from_checkboxes(elem, dummyinput); + dummyinput.click(function() { + $(elem).find('span.option').toggle(); + }); + $(elem).find('.fieldErrorBox').after(dummyinput); + $(elem).find('span.option').click(function() { + sync_from_checkboxes(elem, dummyinput); + }); + $(elem).find('span.option').hide(); +} + (function($) { $().ready(function() { $('.author-autocomplete').autocomplete('./listAuthors', { }).result(author_autocomplete_ready); + $('#formfield-document-widgets-l_doctypes').each(setup_appearance); + $('#formfield-document-widgets-l_topics').each(setup_appearance); + $('#formfield-document-widgets-l_polgroups').each(setup_appearance); }); })(jQuery); diff --git a/tabellio/searchform/form.py b/tabellio/searchform/form.py index 0a33ec6..0566943 100644 --- a/tabellio/searchform/form.py +++ b/tabellio/searchform/form.py @@ -16,6 +16,7 @@ import z3c.form.interfaces from z3c.form.browser import text from z3c.form import widget from z3c.form.interfaces import ITextWidget +from z3c.form.browser.checkbox import CheckBoxWidget from z3c.relationfield.schema import RelationChoice, RelationList from plone.formwidget.contenttree import ObjPathSourceBinder @@ -172,6 +173,9 @@ class TopicsWidget(text.TextWidget): def FieldTopicsWidget(field, request): return widget.FieldWidget(field, TopicsWidget(request)) +def FieldDroppedCheckboxWidget(field, request): + return widget.FieldWidget(field, CheckBoxWidget(request)) + class IFolderWithDocuments(interface.Interface): pass @@ -225,6 +229,36 @@ def possible_sessions(context): terms.append(SimpleVocabulary.createTerm(term_id, term_id, term)) return SimpleVocabulary(terms) +@grok.provider(IContextSourceBinder) +def possible_polgroups(context): + terms = [] + + current = getToolByName(context, 'portal_url').getPortalObject() + settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False) + for part in settings.polgroupsPath.split('/'): + if not part: + continue + current = getattr(current, part) + + for object in current.objectValues(): + if object.portal_type != 'themis.datatypes.polgroup': + continue + polgroup_id = object.id + polgroup_str = object.Title() + terms.append(SimpleVocabulary.createTerm(polgroup_id, polgroup_id, polgroup_str)) + return SimpleVocabulary(terms) + + +@grok.provider(IContextSourceBinder) +def possible_topics(context): + catalog = getToolByName(context, 'portal_catalog') + topics = tabellio.config.utils.get_topics_dict() + terms = [] + for key, value in topics.items(): + topic_id = key + topic_str = value[0] + terms.append(SimpleVocabulary.createTerm(topic_id, topic_id, topic_str)) + return SimpleVocabulary(terms) class IDocumentSearch(interface.Interface): search_type_is_document = schema.TextLine(title=u'Search Type', default=u'1', required=False) @@ -353,13 +387,18 @@ class IDocumentPfbSearch(interface.Interface): search_type_is_document = schema.TextLine(title=u'Search Type', default=u'1') nodoc = schema.TextLine(title=_(u'Document Number'), required=False) - doctype = schema.Choice(title=_(u'Type'), required=False, - source=possible_document_types) + l_doctypes = schema.List(title=_(u'Types'), required=False, + value_type=schema.Choice(title=_(u'Type'), required=False, + source=possible_document_types)) ttitle = schema.TextLine(title=_(u'Title'), required=False) text = schema.TextLine(title=_(u'Text'), required=False) authors = schema.TextLine(title=_(u'Authors'), required=False) - polgroups = schema.TextLine(title=_(u'Political Groups'), required=False) - topics = schema.TextLine(title=_(u'Topics'), required=False) + l_polgroups = schema.List(title=_(u'Political Groups'), required=False, + value_type=schema.Choice(title=_(u'Political Group'), + required=False, source=possible_polgroups)) + l_topics = schema.List(title=_(u'Topics'), required=False, + value_type=schema.Choice(required=False, + source=possible_topics)); session = schema.Choice(title=_(u'Legislature / Session'), required=False, source=possible_sessions) start = schema.Date(title=_(u'Start'), required=False) @@ -374,8 +413,9 @@ class DocumentPfbSearchForm(form.Form): prefix = 'document' fields = field.Fields(IDocumentPfbSearch) fields['authors'].widgetFactory = FieldAuthorsWidget - fields['polgroups'].widgetFactory = FieldPolgroupsWidget - fields['topics'].widgetFactory = FieldTopicsWidget + fields['l_doctypes'].widgetFactory = FieldDroppedCheckboxWidget + fields['l_polgroups'].widgetFactory = FieldDroppedCheckboxWidget + fields['l_topics'].widgetFactory = FieldDroppedCheckboxWidget ignoreContext = True template = ViewPageTemplateFile('form_templates/view_pfbdocsearch.pt') @@ -423,6 +463,16 @@ class IGlobalSearchForm(interface.Interface): adopted = schema.Bool(title=_(u'Limit to adopted'), required=False, default=False) decreted = schema.Bool(title=_(u'Limit to decreted'), required=False, default=False) + l_doctypes = schema.List(title=_(u'Types'), required=False, + value_type=schema.Choice(title=_(u'Type'), required=False, + source=possible_document_types)) + l_polgroups = schema.List(title=_(u'Political Groups'), required=False, + value_type=schema.Choice(title=_(u'Political Group'), + required=False, source=possible_polgroups)) + l_topics = schema.List(title=_(u'Topics'), required=False, + value_type=schema.Choice(required=False, + source=possible_topics)); + class GlobalSearchForm(form.Form): fields = field.Fields(IGlobalSearchForm) @@ -502,6 +552,8 @@ class SearchView(BrowserView): kw['doctype'] = possible_document_types(self.context).getTermByToken(data.get('doctype')).title if data.get('dostype'): kw['dostype'] = possible_dossier_types(self.context).getTermByToken(data.get('dostype')).title + if data.get('l_doctypes'): + kw['doctype'] = [possible_document_types(self.context).getTermByToken(x).title for x in data.get('l_doctypes')] if data.get('start') and data.get('end'): kw['dateDoc'] = {'query': [data.get('start'), data.get('end')], 'range': 'minmax'} @@ -525,10 +577,16 @@ class SearchView(BrowserView): if data.get('polgroups'): kw['polgroupsDoc'] = {'query': data.get('polgroups').strip().split(), 'operator': 'and'} + if data.get('l_polgroups'): + kw['polgroupsDoc'] = {'query': [possible_polgroups(self.context).getTermByToken(x).title for x in data.get('l_polgroups')], + 'operator': 'and'} if data.get('topics'): kw['topics'] = {'query': data.get('topics').strip().split(), 'operator': 'and'} + if data.get('l_topics'): + kw['topics'] = {'query': [possible_topics(self.context).getTermByToken(x).title for x in data.get('l_topics')], + 'operator': 'and'} if data.get('adopted'): kw['adopted'] = data.get('adopted')