src/pyams_content/shared/form/zmi/properties.py
changeset 170 26aefef3d0aa
child 527 5dd1aa8bedd9
equal deleted inserted replaced
169:483b0f16e9a6 170:26aefef3d0aa
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyams_content.shared.form.interfaces import IWfForm
       
    20 from pyams_form.interfaces.form import IInnerSubForm
       
    21 from pyams_skin.layer import IPyAMSLayer
       
    22 
       
    23 # import packages
       
    24 from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
       
    25 from pyams_utils.adapter import adapter_config
       
    26 from pyams_zmi.form import InnerAdminEditForm
       
    27 from z3c.form import field
       
    28 from zope.interface import Interface
       
    29 
       
    30 from pyams_content import _
       
    31 
       
    32 
       
    33 @adapter_config(name='form-settings',
       
    34                 context=(IWfForm, IPyAMSLayer, SharedContentPropertiesEditForm),
       
    35                 provides=IInnerSubForm)
       
    36 class FormPropertiesEditForm(InnerAdminEditForm):
       
    37     """Form properties edit form extension"""
       
    38 
       
    39     legend = _("Main form settings")
       
    40     fieldset_class = 'bordered no-x-margin margin-y-10'
       
    41 
       
    42     fields = field.Fields(IWfForm).select('user_title', 'header', 'handler', 'auth_only', 'use_captcha', 'submit_label')
       
    43     weight = 1
       
    44 
       
    45     def updateWidgets(self, prefix=None):
       
    46         super(FormPropertiesEditForm, self).updateWidgets(prefix)
       
    47         if 'header' in self.widgets:
       
    48             self.widgets['header'].widget_css_class = 'textarea'
       
    49 
       
    50     def get_ajax_output(self, changes):
       
    51         if 'handler' in changes.get(IWfForm, ()):
       
    52             return {'status': 'reload',
       
    53                     'message': self.request.localizer.translate(self.successMessage)}
       
    54         else:
       
    55             return super(FormPropertiesEditForm, self).get_ajax_output(changes)
       
    56 
       
    57 
       
    58 @adapter_config(name='handler-settings',
       
    59                 context=(IWfForm, IPyAMSLayer, SharedContentPropertiesEditForm),
       
    60                 provides=IInnerSubForm)
       
    61 class FormHandlerPropertiesEditForm(InnerAdminEditForm):
       
    62     """Form handler properties edit form extension"""
       
    63 
       
    64     legend = _("Form handler settings")
       
    65     fieldset_class = 'bordered no-x-margin margin-y-10'
       
    66 
       
    67     def __new__(cls, context, request, view):
       
    68         handler = context.query_handler()
       
    69         if handler is None:
       
    70             return None
       
    71         return InnerAdminEditForm.__new__(cls)
       
    72 
       
    73     @property
       
    74     def fields(self):
       
    75         handler = self.context.query_handler()
       
    76         if handler is None:
       
    77             interface = Interface
       
    78         else:
       
    79             interface = handler.handler_info
       
    80         return field.Fields(interface)
       
    81 
       
    82     weight = 2