src/pyams_content/component/illustration/zmi/__init__.py
changeset 682 d093aba47072
parent 535 d01efcb4d332
child 694 4541a452fd4c
equal deleted inserted replaced
681:bb371b8a67e4 682:d093aba47072
    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, IIllustrationTarget
    19 from pyams_content.component.illustration.interfaces import IBasicIllustration, IBasicIllustrationTarget, \
       
    20     IIllustration, IIllustrationTarget
    20 from pyams_content.component.paragraph import IBaseParagraph
    21 from pyams_content.component.paragraph import IBaseParagraph
    21 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
    22 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
    22 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
    23 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
    23 from pyams_skin.layer import IPyAMSLayer
    24 from pyams_skin.layer import IPyAMSLayer
    24 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
    25 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
    62                 if value:
    63                 if value:
    63                     return super(ParagraphContainerIllustrationMarker, self).render()
    64                     return super(ParagraphContainerIllustrationMarker, self).render()
    64         return ''
    65         return ''
    65 
    66 
    66 
    67 
    67 @adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
    68 @adapter_config(name='illustration', context=(IBasicIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
    68                 provides=IInnerSubForm)
    69                 provides=IInnerSubForm)
    69 class IllustrationPropertiesInnerEditForm(InnerAdminEditForm):
    70 class BasicIllustrationPropertiesInnerEditForm(InnerAdminEditForm):
    70     """Illustration properties inner edit form"""
    71     """Basic illustration properties inner edit form"""
    71 
    72 
    72     prefix = 'illustration_form.'
    73     prefix = 'illustration_form.'
    73 
    74 
    74     css_class = 'form-group'
    75     css_class = 'form-group'
    75     padding_class = ''
    76     padding_class = ''
    76     fieldset_class = 'margin-top-10 padding-y-5'
    77     fieldset_class = 'margin-top-10 padding-y-5'
       
    78 
       
    79     legend = _("Illustration")
       
    80     legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto'
       
    81 
       
    82     fields = field.Fields(IBasicIllustration).omit('__parent__', '__name__')
       
    83 
       
    84     weight = 10
       
    85 
       
    86     def getContent(self):
       
    87         return IIllustration(self.context)
       
    88 
       
    89     def check_mode(self):
       
    90         if self.parent_form is not None:
       
    91             self.mode = self.parent_form.mode
       
    92 
       
    93     @property
       
    94     def switcher_state(self):
       
    95         content = self.getContent()
       
    96         for value in (content.data or {}).values():
       
    97             if value:
       
    98                 return 'open'
       
    99 
       
   100     def get_ajax_output(self, changes):
       
   101         output = super(BasicIllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
       
   102         updated = changes.get(IIllustration, ())
       
   103         events = output.setdefault('events', [])
       
   104         if 'data' in updated:
       
   105             # we have to commit transaction to be able to handle blobs...
       
   106             ITransactionManager(self.context).get().commit()
       
   107             events.append(get_json_form_refresh_event(self.context, self.request, self.__class__))
       
   108         return output
       
   109 
       
   110 
       
   111 @adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
       
   112                 provides=IInnerSubForm)
       
   113 class IllustrationPropertiesInnerEditForm(BasicIllustrationPropertiesInnerEditForm):
       
   114     """Illustration properties inner edit form"""
    77 
   115 
    78     @property
   116     @property
    79     def legend(self):
   117     def legend(self):
    80         if IBaseParagraph.providedBy(self.context):
   118         if IBaseParagraph.providedBy(self.context):
    81             return _("Illustration")
   119             return _("Illustration")
    91 
   129 
    92     fields = field.Fields(IIllustration).omit('__parent__', '__name__')
   130     fields = field.Fields(IIllustration).omit('__parent__', '__name__')
    93     fields['renderer'].widgetFactory = RendererFieldWidget
   131     fields['renderer'].widgetFactory = RendererFieldWidget
    94 
   132 
    95     hide_widgets_prefix_div = True
   133     hide_widgets_prefix_div = True
    96     weight = 10
       
    97 
       
    98     def getContent(self):
       
    99         return IIllustration(self.context)
       
   100 
       
   101     def check_mode(self):
       
   102         if self.parent_form is not None:
       
   103             self.mode = self.parent_form.mode
       
   104 
   134 
   105     def updateWidgets(self, prefix=None):
   135     def updateWidgets(self, prefix=None):
   106         super(IllustrationPropertiesInnerEditForm, self).updateWidgets(prefix)
   136         super(IllustrationPropertiesInnerEditForm, self).updateWidgets(prefix)
   107         if 'description' in self.widgets:
   137         if 'description' in self.widgets:
   108             self.widgets['description'].widget_css_class = 'textarea'
   138             self.widgets['description'].widget_css_class = 'textarea'
   110     def get_ajax_output(self, changes):
   140     def get_ajax_output(self, changes):
   111         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
   141         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
   112         updated = changes.get(IIllustration, ())
   142         updated = changes.get(IIllustration, ())
   113         events = output.setdefault('events', [])
   143         events = output.setdefault('events', [])
   114         if 'data' in updated:
   144         if 'data' in updated:
   115             # we have to commit transaction to be able to handle blobs...
       
   116             ITransactionManager(self.context).get().commit()
       
   117             events.append(get_json_form_refresh_event(self.context, self.request,
       
   118                                                       IllustrationPropertiesInnerEditForm))
       
   119             if IBaseParagraph.providedBy(self.context):
   145             if IBaseParagraph.providedBy(self.context):
   120                 if self.getContent().data:
   146                 if self.getContent().data:
   121                     events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
   147                     events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
   122                                                                            ParagraphContainerIllustrationMarker))
   148                                                                            ParagraphContainerIllustrationMarker))
   123                 else:
   149                 else:
   128             events.append(get_json_widget_refresh_event(self.context, self.request,
   154             events.append(get_json_widget_refresh_event(self.context, self.request,
   129                                                         IllustrationPropertiesInnerEditForm, 'renderer'))
   155                                                         IllustrationPropertiesInnerEditForm, 'renderer'))
   130         return output
   156         return output
   131 
   157 
   132 
   158 
   133 @viewlet_config(name='illustration-thumbnail', context=IIllustrationTarget, layer=IPyAMSLayer,
   159 @viewlet_config(name='illustration-thumbnail', context=IBasicIllustrationTarget, layer=IPyAMSLayer,
   134                 view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager)
   160                 view=BasicIllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager)
   135 @template_config(template='templates/illustration-thumbnail.pt', layer=IPyAMSLayer)
   161 @template_config(template='templates/illustration-thumbnail.pt', layer=IPyAMSLayer)
   136 class IllustrationThumbnail(Viewlet):
   162 class IllustrationThumbnail(Viewlet):
   137     """Paragraph illustration thumbnail"""
   163     """Paragraph illustration thumbnail"""
   138 
   164 
   139     def __new__(cls, context, request, view, manager):
   165     def __new__(cls, context, request, view, manager):