src/pyams_content/component/illustration/zmi/__init__.py
changeset 1005 107406cb705c
parent 1004 ca57b160d863
child 1070 ea0c7ac589c4
equal deleted inserted replaced
1004:ca57b160d863 1005:107406cb705c
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     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
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 from zope.interface import implementer
       
    13 
       
    14 from pyams_content.skin import pyams_content
       
    15 from pyams_form.security import ProtectedFormObjectMixin
       
    16 from pyams_skin.viewlet.toolbar import JsToolbarAction
       
    17 from pyams_utils.fanstatic import get_resource_path
       
    18 from pyams_utils.interfaces.data import IObjectData
       
    19 
       
    20 
    12 
    21 __docformat__ = 'restructuredtext'
    13 __docformat__ = 'restructuredtext'
    22 
    14 
    23 from transaction.interfaces import ITransactionManager
    15 from transaction.interfaces import ITransactionManager
    24 from z3c.form import field
    16 from z3c.form import field
    25 
    17 from zope.interface import implementer
    26 from pyams_content import _
    18 
    27 from pyams_content.component.illustration.interfaces import IBasicIllustration, IBasicIllustrationTarget, \
    19 from pyams_content.component.illustration.interfaces import IBasicIllustration, IBasicIllustrationTarget, \
    28     IIllustration, IIllustrationTarget, ILinkIllustrationTarget
    20     IIllustration, IIllustrationTarget, ILinkIllustrationTarget
    29 # import packages
       
    30 from pyams_content.component.illustration.zmi.paragraph import ParagraphContainerIllustrationMarker
    21 from pyams_content.component.illustration.zmi.paragraph import ParagraphContainerIllustrationMarker
    31 from pyams_content.component.paragraph import IBaseParagraph
    22 from pyams_content.component.paragraph import IBaseParagraph
    32 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event
    23 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event
    33 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    24 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
       
    25 from pyams_content.skin import pyams_content
    34 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
    26 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
       
    27 from pyams_form.security import ProtectedFormObjectMixin
    35 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
    28 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
    36 from pyams_skin.layer import IPyAMSLayer
    29 from pyams_skin.layer import IPyAMSLayer
       
    30 from pyams_skin.viewlet.toolbar import JsToolbarAction
    37 from pyams_template.template import template_config
    31 from pyams_template.template import template_config
    38 from pyams_utils.adapter import adapter_config
    32 from pyams_utils.adapter import adapter_config
    39 from pyams_viewlet.viewlet import viewlet_config, Viewlet, EmptyViewlet
    33 from pyams_utils.fanstatic import get_resource_path
       
    34 from pyams_utils.interfaces.data import IObjectData
       
    35 from pyams_viewlet.viewlet import EmptyViewlet, Viewlet, viewlet_config
    40 from pyams_zmi.form import InnerAdminEditForm
    36 from pyams_zmi.form import InnerAdminEditForm
    41 from pyams_zmi.interfaces import IPropertiesEditForm
    37 from pyams_zmi.interfaces import IPropertiesEditForm
       
    38 
       
    39 from pyams_content import _
    42 
    40 
    43 
    41 
    44 #
    42 #
    45 # Illustration properties inner edit form
    43 # Illustration properties inner edit form
    46 #
    44 #
    52 
    50 
    53     prefix = 'basic_illustration_form.'
    51     prefix = 'basic_illustration_form.'
    54 
    52 
    55     css_class = 'form-group'
    53     css_class = 'form-group'
    56     padding_class = ''
    54     padding_class = ''
    57     # fieldset_class = 'bordered margin-top-10 padding-y-5'
       
    58 
    55 
    59     legend = _("Illustration")
    56     legend = _("Illustration")
    60     # legend_class = 'illustration switcher no-y-padding padding-right-10'
       
    61 
    57 
    62     fields = field.Fields(IBasicIllustration).omit('__parent__', '__name__')
    58     fields = field.Fields(IBasicIllustration).omit('__parent__', '__name__')
    63 
    59 
    64     weight = 10
    60     weight = 10
    65 
    61 
    93             if content.has_data():
    89             if content.has_data():
    94                 return 'open'
    90                 return 'open'
    95 
    91 
    96     def get_ajax_output(self, changes):
    92     def get_ajax_output(self, changes):
    97         output = super(BasicIllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
    93         output = super(BasicIllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
       
    94         events = output.setdefault('events', [])
    98         updated = changes.get(IBasicIllustration, ())
    95         updated = changes.get(IBasicIllustration, ())
    99         if 'data' in updated:
    96         if 'data' in updated:
   100             # we have to commit transaction to be able to handle blobs...
    97             # we have to commit transaction to be able to handle blobs...
   101             ITransactionManager(self.context).get().commit()
    98             ITransactionManager(self.context).get().commit()
   102             output.setdefault('events', []).append(
    99             if IBaseParagraph.providedBy(self.context):
   103                 get_json_form_refresh_event(self.context, self.request, self.__class__))
   100                 if self.getContent().data:
       
   101                     events.append(
       
   102                         get_json_paragraph_markers_refresh_event(self.context, self.request, self,
       
   103                                                                  ParagraphContainerIllustrationMarker))
       
   104                 else:
       
   105                     events.append(
       
   106                         get_json_paragraph_markers_refresh_event(self.context, self.request, self,
       
   107                                                                  EmptyViewlet,
       
   108                                                                  ParagraphContainerIllustrationMarker.marker_type))
       
   109             events.append(get_json_form_refresh_event(self.context, self.request, self.__class__))
   104         return output
   110         return output
   105 
   111 
   106 
   112 
   107 @adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
   113 @adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
   108                 provides=IInnerSubForm)
   114                 provides=IInnerSubForm)
   126         if not IBaseParagraph.providedBy(self.context):
   132         if not IBaseParagraph.providedBy(self.context):
   127             return 'open'
   133             return 'open'
   128 
   134 
   129     def get_ajax_output(self, changes):
   135     def get_ajax_output(self, changes):
   130         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
   136         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
   131         events = output.setdefault('events', [])
   137         if 'renderer' in changes.get(IIllustration, ()):
   132         if 'data' in changes.get(IBasicIllustration, ()):
   138             output.setdefault('events', []).append(
   133             if IBaseParagraph.providedBy(self.context):
   139                 get_json_widget_refresh_event(self.context, self.request,
   134                 if self.getContent().data:
   140                                               IllustrationPropertiesInnerEditForm, 'renderer'))
   135                     events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
       
   136                                                                            ParagraphContainerIllustrationMarker))
       
   137                 else:
       
   138                     events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
       
   139                                                                            EmptyViewlet,
       
   140                                                                            ParagraphContainerIllustrationMarker.marker_type))
       
   141         elif 'renderer' in changes.get(IIllustration, ()):
       
   142             events.append(get_json_widget_refresh_event(self.context, self.request,
       
   143                                                         IllustrationPropertiesInnerEditForm, 'renderer'))
       
   144         return output
   141         return output
   145 
   142 
   146 
   143 
   147 @adapter_config(name='link-illustration', context=(ILinkIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
   144 @adapter_config(name='link-illustration', context=(ILinkIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
   148                 provides=IInnerSubForm)
   145                 provides=IInnerSubForm)
   160         registry = self.request.registry
   157         registry = self.request.registry
   161         return registry.getAdapter(self.context, IIllustration, name='link')
   158         return registry.getAdapter(self.context, IIllustration, name='link')
   162 
   159 
   163 
   160 
   164 @viewlet_config(name='add-illustration.action', context=IBasicIllustrationTarget, layer=IPyAMSLayer,
   161 @viewlet_config(name='add-illustration.action', context=IBasicIllustrationTarget, layer=IPyAMSLayer,
   165                 view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager)
   162                 view=BasicIllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager)
   166 @implementer(IObjectData)
   163 @implementer(IObjectData)
   167 class AddIllustrationAction(ProtectedFormObjectMixin, JsToolbarAction):
   164 class AddIllustrationAction(ProtectedFormObjectMixin, JsToolbarAction):
   168     """Add illustration action"""
   165     """Add illustration action"""
   169 
   166 
   170     group_css_class = 'btn-group clearfix persistent'
   167     group_css_class = 'btn-group clearfix persistent'