--- a/src/pyams_content/shared/form/interfaces/__init__.py Tue Sep 19 11:11:12 2017 +0200
+++ b/src/pyams_content/shared/form/interfaces/__init__.py Tue Sep 19 11:11:30 2017 +0200
@@ -17,8 +17,15 @@
# import interfaces
from pyams_content.shared.common.interfaces import ISharedTool, IWfSharedContent, ISharedContent
+from zope.annotation.interfaces import IAttributeAnnotatable
+from zope.container.interfaces import IContainer, IContained
# import packages
+from pyams_i18n.schema import I18nTextLineField, I18nTextField
+from pyams_utils.schema import MailAddressField, TextLineListField
+from zope.container.constraints import containers, contains
+from zope.interface import Interface, Attribute
+from zope.schema import TextLine, Choice, Bool
from pyams_content import _
@@ -26,14 +33,157 @@
FORM_CONTENT_TYPE = 'form'
FORM_CONTENT_NAME = _('Form')
+FORM_FIELD_CONTAINER_KEY = 'pyams_content.shared.form_fields'
+
class IFormsManager(ISharedTool):
"""Formq manager interface"""
+class IFormField(IContained):
+ """Form field interface"""
+
+ containers('.IFormFieldContainer')
+
+ name = TextLine(title=_("Field name"),
+ description=_("Field internal name; must be unique for a given form"),
+ required=True)
+
+ field_type = Choice(title=_("Field type"),
+ description=_("Selected field type"),
+ vocabulary='PyAMS form field types',
+ required=True)
+
+ label = I18nTextLineField(title=_("Label"),
+ description=_("User field label"),
+ required=True)
+
+ description = I18nTextField(title=_("Description"),
+ description=_("Field description can be displayed as hint"),
+ required=False)
+
+ placeholder = TextLine(title=_("Placeholder"),
+ description=_("Some field types like textline can display a placeholder"),
+ required=False)
+
+ values = TextLineListField(title=_("Optional values"),
+ description=_("List of available values (for 'choice' and 'list' field types)"),
+ required=False)
+
+ default = I18nTextLineField(title=_("Default value"),
+ description=_("Give default value if field type can use it"),
+ required=False)
+
+ required = Bool(title=_("Required?"),
+ description=_("Select 'yes' to set field as mandatory"),
+ required=True,
+ default=False)
+
+ visible = Bool(title=_("Visible?"),
+ description=_("Select 'no' to hide given field..."),
+ required=True,
+ default=True)
+
+
+class IFormFieldFactory(Interface):
+ """Form field factory interface"""
+
+ label = Attribute("Factory label")
+ weight = Attribute("Factory weight")
+
+ def get_schema_field(self, field):
+ """Get schema field matching given form field"""
+
+
+class IFormFieldContainer(IContainer):
+ """Form fields container interface"""
+
+ contains(IFormField)
+
+ def append(self, field):
+ """Append given field to container"""
+
+ def get_fields(self):
+ """Get schema fields matching current fields"""
+
+
+class IFormFieldContainerTarget(Interface):
+ """Form fields container target marker interface"""
+
+
class IWfForm(IWfSharedContent):
"""Form interface"""
+ user_title = I18nTextLineField(title=_("Form title"),
+ required=True)
+
+ header = I18nTextField(title=_("Form header"),
+ required=False)
+
+ handler = Choice(title=_("Form handler"),
+ description=_("Select how form data is transmitted"),
+ vocabulary='PyAMS form handlers')
+
+ auth_only = Bool(title=_("Authenticated only?"),
+ description=_("If 'yes', only authenticated users will be able to see and submit form"),
+ required=True,
+ default=False)
+
+ use_captcha = Bool(title=_("Use captcha?"),
+ description=_("If 'yes', a captcha will be added automatically to the form"),
+ required=True,
+ default=True)
+
+ submit_label = I18nTextLineField(title=_("Submit label"),
+ description=_("Label of form submit button"),
+ required=True)
+
+ def query_handler(self, handler=None):
+ """Get form handler utility"""
+
class IForm(ISharedContent):
"""Workflow managed form interface"""
+
+
+#
+# Form handler
+#
+
+class IFormHandler(Interface):
+ """Form handler interface"""
+
+ label = Attribute("Handler label")
+ target_interface = Attribute("Handler target marker interface")
+ handler_info = Attribute("Handler info interface")
+
+ def handle(self, data):
+ """Handle entered data"""
+
+
+class IFormHandlerInfo(Interface):
+ """Base handler info interface"""
+
+
+class IMailtoHandlerInfo(IFormHandlerInfo):
+ """Mailto form handler info interface"""
+
+ source_address = MailAddressField(title=_("Source address"),
+ description=_("Mail address from which form data is sent"),
+ required=True)
+
+ source_name = TextLine(title=_("Source name"),
+ description=_("Name of mail data sender"),
+ required=False)
+
+ target_address = MailAddressField(title=_("Recipient address"),
+ description=_("Mail address to which form data is sent"),
+ required=True)
+
+ target_name = TextLine(title=_("Recipient name"),
+ description=_("Name of data recipient"),
+ required=False)
+
+
+class IMailtoHandlerTarget(IAttributeAnnotatable):
+ """Mailto handler target marker interface"""