Source code for pyams_form.schema

#
# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#

"""PyAMS_form.schema module

This module provides an interface and a schema field for form buttons.
"""

from z3c.form.button import Button
from z3c.form.interfaces import IButton
from zope.interface import implementer
from zope.schema import Bool, TextLine
from zope.schema.fieldproperty import FieldProperty


__docformat__ = 'restructuredtext'


[docs]class IResetButton(IButton): """Reset button interface"""
[docs]@implementer(IResetButton) class ResetButton(Button): """Reset button"""
[docs]class ICloseButton(IButton): """Close button interface"""
[docs]@implementer(ICloseButton) class CloseButton(Button): """Close button"""
[docs]class IActionButton(IButton): """Action button interface An action button is a form button which can be used to redirect the user to a "target" URL, eventually opened in a modal window, or which can call a "click" handler which is the name of a javascript function. """ label = TextLine(title="Button label", description="Button label displayed as hint", required=False) label_css_class = TextLine(title="Label icon CSS class", description="CSS class associated with label", required=True, default='fa fa-fw fa-edit') click_handler = TextLine(title="Button click handler", description="Javascript function called by button click", required=False) url = TextLine(title="Button target URL", description="Target URL accessed by button click", required=False) modal_target = Bool(title="Modal target?", description="If True, target URL is opened in a modal frame", required=False, default=False)
[docs]@implementer(IActionButton) class ActionButton(Button): """Action button""" label_css_class = FieldProperty(IActionButton['label_css_class']) click_handler = FieldProperty(IActionButton['click_handler']) url = FieldProperty(IActionButton['url']) modal_target = FieldProperty(IActionButton['modal_target']) def __init__(self, *args, **kwargs): if 'label_css_class' in kwargs: self.label_css_class = kwargs.pop('label_css_class') self.click_handler = kwargs.pop('click_handler', None) self.url = kwargs.pop('url', None) self.modal_target = kwargs.pop('modal_target', None) super(ActionButton, self).__init__(*args, **kwargs)