src/pyams_content/component/illustration/zmi/__init__.py
changeset 395 2a39b333a585
parent 360 e47b68b41f06
child 489 dcdb0ce828f8
equal deleted inserted replaced
394:1ebcb03e9bff 395:2a39b333a585
    14 
    14 
    15 
    15 
    16 # import standard library
    16 # import standard library
    17 
    17 
    18 # import interfaces
    18 # import interfaces
    19 from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationRenderer, IIllustrationTarget
    19 from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationTarget
    20 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
    20 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
    21 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
    21 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
    22 from pyams_i18n.interfaces import II18n
       
    23 from pyams_skin.layer import IPyAMSLayer
    22 from pyams_skin.layer import IPyAMSLayer
    24 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
    23 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
    25 from pyams_utils.interfaces.data import IObjectData
    24 from pyams_utils.interfaces.data import IObjectData
    26 from pyams_zmi.interfaces import IPropertiesEditForm
    25 from pyams_zmi.interfaces import IPropertiesEditForm
    27 from transaction.interfaces import ITransactionManager
    26 from transaction.interfaces import ITransactionManager
    28 
    27 
    29 # import packages
    28 # import packages
       
    29 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    30 from pyams_content.skin import pyams_content
    30 from pyams_content.skin import pyams_content
    31 from pyams_form.security import ProtectedFormObjectMixin
    31 from pyams_form.security import ProtectedFormObjectMixin
    32 from pyams_skin.viewlet.toolbar import JsToolbarAction
    32 from pyams_skin.viewlet.toolbar import JsToolbarAction
    33 from pyams_template.template import get_view_template, template_config
    33 from pyams_template.template import template_config
    34 from pyams_utils.adapter import ContextRequestAdapter, adapter_config
    34 from pyams_utils.adapter import adapter_config
    35 from pyams_utils.fanstatic import get_resource_path
    35 from pyams_utils.fanstatic import get_resource_path
    36 from pyams_viewlet.viewlet import viewlet_config, Viewlet
    36 from pyams_viewlet.viewlet import viewlet_config, Viewlet
    37 from pyams_zmi.form import InnerAdminEditForm
    37 from pyams_zmi.form import InnerAdminEditForm
    38 from z3c.form import field
    38 from z3c.form import field
    39 from zope.interface import implementer
    39 from zope.interface import implementer
    40 
    40 
    41 from pyams_content import _
    41 from pyams_content import _
    42 
       
    43 
       
    44 #
       
    45 # Illustration renderers
       
    46 #
       
    47 
       
    48 class BaseIllustrationRenderer(ContextRequestAdapter):
       
    49     """Base illustration renderer"""
       
    50 
       
    51     language = None
       
    52 
       
    53     def update(self):
       
    54         i18n = II18n(self.context)
       
    55         if self.language:
       
    56             self.legend = i18n.get_attribute('alt_title', self.language, request=self.request)
       
    57         else:
       
    58             self.legend = i18n.query_attribute('alt_title', request=self.request)
       
    59 
       
    60     render = get_view_template()
       
    61 
       
    62 
       
    63 @adapter_config(name='hidden', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
       
    64 class HiddenIllustrationRenderer(BaseIllustrationRenderer):
       
    65     """Hidden illustration renderer"""
       
    66 
       
    67     label = _("Hidden illustration")
       
    68     weight = -999
       
    69 
       
    70     def render(self):
       
    71         return ''
       
    72 
       
    73 
       
    74 @adapter_config(name='default', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
       
    75 @template_config(template='templates/renderer-default.pt', layer=IPyAMSLayer)
       
    76 class DefaultIllustrationRenderer(BaseIllustrationRenderer):
       
    77     """Default illustration renderer"""
       
    78 
       
    79     label = _("Centered illustration")
       
    80     weight = 1
       
    81 
       
    82 
       
    83 @adapter_config(name='left+zoom', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
       
    84 @template_config(template='templates/renderer-left.pt', layer=IPyAMSLayer)
       
    85 class LeftIllustrationWithZoomRenderer(BaseIllustrationRenderer):
       
    86     """Illustrtaion renderer with small image and zoom"""
       
    87 
       
    88     label = _("Small illustration on the left with zoom")
       
    89     weight = 2
       
    90 
       
    91 
       
    92 @adapter_config(name='right+zoom', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
       
    93 @template_config(template='templates/renderer-right.pt', layer=IPyAMSLayer)
       
    94 class RightIllustrationWithZoomRenderer(BaseIllustrationRenderer):
       
    95     """Illustrtaion renderer with small image and zoom"""
       
    96 
       
    97     label = _("Small illustration on the right with zoom")
       
    98     weight = 3
       
    99 
    42 
   100 
    43 
   101 #
    44 #
   102 # Illustration properties inner edit form
    45 # Illustration properties inner edit form
   103 #
    46 #
   136 
    79 
   137     legend = _("Illustration")
    80     legend = _("Illustration")
   138     legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto'
    81     legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto'
   139 
    82 
   140     fields = field.Fields(IIllustration).omit('__parent__', '__name__')
    83     fields = field.Fields(IIllustration).omit('__parent__', '__name__')
       
    84     fields['renderer'].widgetFactory = RendererFieldWidget
       
    85 
   141     hide_widgets_prefix_div = True
    86     hide_widgets_prefix_div = True
   142     weight = 10
    87     weight = 10
   143 
    88 
   144     def getContent(self):
    89     def getContent(self):
   145         return IIllustration(self.context)
    90         return IIllustration(self.context)
   153         if 'description' in self.widgets:
    98         if 'description' in self.widgets:
   154             self.widgets['description'].widget_css_class = 'textarea'
    99             self.widgets['description'].widget_css_class = 'textarea'
   155 
   100 
   156     def get_ajax_output(self, changes):
   101     def get_ajax_output(self, changes):
   157         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
   102         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
   158         if 'data' in changes.get(IIllustration, ()):
   103         illustration_changes = changes.get(IIllustration, ())
       
   104         if ('data' in illustration_changes) or ('renderer' in illustration_changes):
   159             # we have to commit transaction to be able to handle blobs...
   105             # we have to commit transaction to be able to handle blobs...
   160             ITransactionManager(self.context).get().commit()
   106             ITransactionManager(self.context).get().commit()
   161             form = IllustrationPropertiesInnerEditForm(self.context, self.request)
   107             form = IllustrationPropertiesInnerEditForm(self.context, self.request)
   162             form.update()
   108             form.update()
   163             illustration = form.getContent()
   109             illustration = form.getContent()