src/pyams_content/shared/form/zmi/properties.py
changeset 1343 530cbb970243
parent 1335 e090134614d2
child 1346 88b5ce31afdc
equal deleted inserted replaced
1342:999fa08d99c2 1343:530cbb970243
    12 
    12 
    13 from z3c.form import field
    13 from z3c.form import field
    14 from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
    14 from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
    15 from zope.interface import Interface
    15 from zope.interface import Interface
    16 
    16 
       
    17 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
    17 from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
    18 from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
    18 from pyams_content.shared.form.interfaces import IWfForm
    19 from pyams_content.shared.form.interfaces import IWfForm
       
    20 from pyams_form.form import ajax_config
    19 from pyams_form.group import NamedWidgetsGroup
    21 from pyams_form.group import NamedWidgetsGroup
    20 from pyams_form.interfaces.form import IInnerSubForm
    22 from pyams_form.interfaces.form import IInnerSubForm
       
    23 from pyams_pagelet.pagelet import pagelet_config
    21 from pyams_skin.layer import IPyAMSLayer
    24 from pyams_skin.layer import IPyAMSLayer
    22 from pyams_utils.adapter import adapter_config
    25 from pyams_utils.adapter import adapter_config
       
    26 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
    23 from pyams_zmi.form import InnerAdminEditForm
    27 from pyams_zmi.form import InnerAdminEditForm
    24 
    28 
    25 
    29 
    26 __docformat__ = 'restructuredtext'
    30 __docformat__ = 'restructuredtext'
    27 
    31 
    28 from pyams_content import _
    32 from pyams_content import _
    29 
    33 
    30 
    34 
       
    35 @pagelet_config(name='properties.html', context=IWfForm, layer=IPyAMSLayer,
       
    36                 permission=VIEW_SYSTEM_PERMISSION)
       
    37 @ajax_config(name='properties.json', context=IWfForm, layer=IPyAMSLayer,
       
    38              permission=MANAGE_CONTENT_PERMISSION)
       
    39 class FormPropertiesEditForm(SharedContentPropertiesEditForm):
       
    40     """Form properties edit form"""
       
    41 
       
    42     interface = IWfForm
       
    43     fieldnames = ('title', 'short_name', 'content_url', 'alt_title',
       
    44                   'header', 'description', 'notepad')
       
    45 
       
    46 
    31 @adapter_config(name='form-settings',
    47 @adapter_config(name='form-settings',
    32                 context=(IWfForm, IPyAMSLayer, SharedContentPropertiesEditForm),
    48                 context=(IWfForm, IPyAMSLayer, FormPropertiesEditForm),
    33                 provides=IInnerSubForm)
    49                 provides=IInnerSubForm)
    34 class FormPropertiesEditForm(InnerAdminEditForm):
    50 class FormPropertiesInnerEditForm(InnerAdminEditForm):
    35     """Form properties edit form extension"""
    51     """Form properties edit form extension"""
    36 
    52 
    37     prefix = 'form_properties.'
    53     prefix = 'form_properties.'
    38 
    54 
    39     legend = _("Main form settings")
    55     legend = _("Main form settings")
    40     fieldset_class = 'bordered no-x-margin margin-y-10'
    56     fieldset_class = 'bordered no-x-margin margin-y-10'
    41 
    57 
    42     fields = field.Fields(IWfForm).select('user_title', 'form_header', 'auth_only', 'submit_label',
    58     fields = field.Fields(IWfForm).select('form_header', 'user_title', 'auth_only',
    43                                           'submit_message', 'handler', 'use_captcha', 'client_captcha_key',
    59                                           'submit_label', 'submit_message', 'handler',
       
    60                                           'use_captcha', 'client_captcha_key',
    44                                           'server_captcha_key', 'captcha_proxy')
    61                                           'server_captcha_key', 'captcha_proxy')
    45     fields['use_captcha'].widgetFactory = SingleCheckBoxFieldWidget
    62     fields['use_captcha'].widgetFactory = SingleCheckBoxFieldWidget
    46 
    63 
    47     weight = 1
    64     weight = 1
    48 
    65 
    49     def updateGroups(self):
    66     def updateGroups(self):
    50         self.add_group(NamedWidgetsGroup(self, 'head', self.widgets,
    67         self.add_group(NamedWidgetsGroup(self, 'head', self.widgets,
    51                                          ('user_title', 'form_header', 'auth_only',
    68                                          ('form_header', 'user_title', 'auth_only',
    52                                           'submit_label', 'submit_message', 'handler')))
    69                                           'submit_label', 'submit_message', 'handler')))
    53         self.add_group(NamedWidgetsGroup(self, 'captcha', self.widgets,
    70         self.add_group(NamedWidgetsGroup(self, 'captcha', self.widgets,
    54                                          ('use_captcha', 'client_captcha_key', 'server_captcha_key', 'captcha_proxy'),
    71                                          ('use_captcha', 'client_captcha_key',
       
    72                                           'server_captcha_key', 'captcha_proxy'),
    55                                          fieldset_class='inner bordered',
    73                                          fieldset_class='inner bordered',
    56                                          legend=_("Add captcha"),
    74                                          legend=_("Add captcha"),
    57                                          css_class='inner',
    75                                          css_class='inner',
    58                                          switch=True,
    76                                          switch=True,
    59                                          checkbox_switch=True,
    77                                          checkbox_switch=True,
    60                                          checkbox_field=IWfForm['use_captcha']))
    78                                          checkbox_field=IWfForm['use_captcha']))
    61         super(FormPropertiesEditForm, self).updateGroups()
    79         super(FormPropertiesInnerEditForm, self).updateGroups()
    62 
    80 
    63     def get_ajax_output(self, changes):
    81     def get_ajax_output(self, changes):
    64         if 'handler' in changes.get(IWfForm, ()):
    82         if 'handler' in changes.get(IWfForm, ()):
    65             return {
    83             return {
    66                 'status': 'reload',
    84                 'status': 'reload',
    67                 'message': self.request.localizer.translate(self.successMessage)
    85                 'message': self.request.localizer.translate(self.successMessage)
    68             }
    86             }
    69         else:
    87         else:
    70             return super(FormPropertiesEditForm, self).get_ajax_output(changes)
    88             return super(FormPropertiesInnerEditForm, self).get_ajax_output(changes)
    71 
    89 
    72 
    90 
    73 @adapter_config(name='handler-settings',
    91 @adapter_config(name='handler-settings',
    74                 context=(IWfForm, IPyAMSLayer, SharedContentPropertiesEditForm),
    92                 context=(IWfForm, IPyAMSLayer, SharedContentPropertiesEditForm),
    75                 provides=IInnerSubForm)
    93                 provides=IInnerSubForm)
    89     @property
   107     @property
    90     def legend(self):
   108     def legend(self):
    91         handler = self.context.query_handler()
   109         handler = self.context.query_handler()
    92         if handler is not None:
   110         if handler is not None:
    93             translate = self.request.localizer.translate
   111             translate = self.request.localizer.translate
    94             return translate(_("« {handler} » form handler settings")).format(handler=translate(handler.label))
   112             return translate(_("« {handler} » form handler settings")).format(
       
   113                 handler=translate(handler.label))
    95         else:
   114         else:
    96             return _("Form handler settings")
   115             return _("Form handler settings")
    97 
   116 
    98     @property
   117     @property
    99     def fields(self):
   118     def fields(self):