[1572] | 1 | from zope.interface import Interface |
---|
| 2 | from zope.component import adapts |
---|
| 3 | from zope.interface import implements |
---|
| 4 | from zope import schema |
---|
| 5 | from zope.app.form import CustomWidgetFactory |
---|
| 6 | from zope.app.form.browser import ObjectWidget |
---|
| 7 | from zope.app.form.browser import ListSequenceWidget |
---|
| 8 | from zope.formlib import form |
---|
| 9 | |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | from Products.CMFDefault.formlib.schema import SchemaAdapterBase |
---|
| 12 | |
---|
| 13 | from Products.CMFPlone.interfaces import IPloneSiteRoot |
---|
| 14 | |
---|
| 15 | from plone.app.controlpanel.form import ControlPanelForm |
---|
| 16 | |
---|
| 17 | from quintagroup.portlet.collection import MessageFactory as _ |
---|
| 18 | from quintagroup.portlet.collection.utils import getStylesVocabulary |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | class IValueTitlePair(Interface): |
---|
| 22 | value = schema.TextLine(title=u"value", required=True) |
---|
| 23 | title = schema.TextLine(title=u"title", required=False) |
---|
| 24 | |
---|
[3556] | 25 | |
---|
[1572] | 26 | class ValueTitlePair(object): |
---|
| 27 | implements(IValueTitlePair) |
---|
[3556] | 28 | |
---|
[1572] | 29 | def __init__(self, value='', title=''): |
---|
| 30 | self.value = value |
---|
| 31 | self.title = title |
---|
| 32 | |
---|
[3556] | 33 | |
---|
[1572] | 34 | class IQCollectionPortletPanelSchema(Interface): |
---|
| 35 | |
---|
| 36 | portlet_dropdown = schema.List( |
---|
| 37 | title=_(u'Dropdown select'), |
---|
| 38 | description=_(u"These entries are used for generating dropdown select " |
---|
| 39 | "for quintagroup collection portlet. Note: pipe (|) " |
---|
| 40 | "symbol is not allowed in the value field."), |
---|
| 41 | value_type=schema.Object(IValueTitlePair, title=u"entry"), |
---|
| 42 | required=True |
---|
| 43 | ) |
---|
| 44 | |
---|
[3556] | 45 | |
---|
[1572] | 46 | class QCollectionPortletControlPanelAdapter(SchemaAdapterBase): |
---|
| 47 | adapts(IPloneSiteRoot) |
---|
| 48 | implements(IQCollectionPortletPanelSchema) |
---|
| 49 | |
---|
| 50 | def __init__(self, context): |
---|
| 51 | super(QCollectionPortletControlPanelAdapter, self).__init__(context) |
---|
| 52 | self.context = context |
---|
| 53 | self.pp = getToolByName(context, 'portal_properties', None) |
---|
| 54 | |
---|
| 55 | def get_portlet_dropdown(self): |
---|
[3556] | 56 | return [ValueTitlePair(v, t) for (v, t) in getStylesVocabulary( |
---|
| 57 | self.context)] |
---|
[1572] | 58 | |
---|
| 59 | def set_portlet_dropdown(self, value): |
---|
| 60 | dropdown_list = [] |
---|
| 61 | for vt in value: |
---|
| 62 | value = vt.value |
---|
| 63 | title = vt.title or value |
---|
| 64 | dropdown_list.append('%s|%s' % (value, title)) |
---|
| 65 | self.setValue(dropdown_list) |
---|
| 66 | |
---|
| 67 | portlet_dropdown = property(get_portlet_dropdown, set_portlet_dropdown) |
---|
| 68 | |
---|
| 69 | def setValue(self, value): |
---|
| 70 | if self.pp is not None: |
---|
| 71 | if getattr(self.pp, 'qcollectionportlet_properties', None) is None: |
---|
| 72 | self.pp.addPropertySheet( |
---|
| 73 | 'qcollectionportlet_properties', |
---|
| 74 | 'QCollection portlet properties' |
---|
| 75 | ) |
---|
| 76 | sheet = getattr(self.pp, 'qcollectionportlet_properties', None) |
---|
| 77 | if not sheet.hasProperty('portlet_dropdown'): |
---|
| 78 | sheet.manage_addProperty('portlet_dropdown', value, 'lines') |
---|
| 79 | else: |
---|
| 80 | sheet.manage_changeProperties(portlet_dropdown=value) |
---|
| 81 | |
---|
| 82 | valuetitle_widget = CustomWidgetFactory(ObjectWidget, ValueTitlePair) |
---|
| 83 | combination_widget = CustomWidgetFactory(ListSequenceWidget, |
---|
| 84 | subwidget=valuetitle_widget) |
---|
| 85 | |
---|
[3556] | 86 | |
---|
[1572] | 87 | class QCollectionPortletControlPanel(ControlPanelForm): |
---|
| 88 | |
---|
| 89 | form_fields = form.FormFields(IQCollectionPortletPanelSchema) |
---|
| 90 | form_fields['portlet_dropdown'].custom_widget = combination_widget |
---|
| 91 | |
---|
| 92 | label = _("QCollection portlet settings") |
---|
| 93 | description = _("This form is for managing QCollection portlet " |
---|
[3556] | 94 | "classes available on portlet add/edit form.") |
---|
[1572] | 95 | form_name = _("QCollection portlet settings") |
---|