diff -r 26d51b558325 -r 4541a452fd4c src/pyams_content/component/illustration/zmi/__init__.py --- a/src/pyams_content/component/illustration/zmi/__init__.py Fri Jun 15 15:29:30 2018 +0200 +++ b/src/pyams_content/component/illustration/zmi/__init__.py Fri Jun 15 18:18:16 2018 +0200 @@ -17,16 +17,15 @@ # import interfaces from pyams_content.component.illustration.interfaces import IBasicIllustration, IBasicIllustrationTarget, \ - IIllustration, IIllustrationTarget + IIllustration, IIllustrationTarget, ILinkIllustrationTarget from pyams_content.component.paragraph import IBaseParagraph -from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager from pyams_skin.layer import IPyAMSLayer -from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION from pyams_zmi.interfaces import IPropertiesEditForm from transaction.interfaces import ITransactionManager # import packages +from pyams_content.component.illustration.zmi.paragraph import ParagraphContainerIllustrationMarker from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event from pyams_content.features.renderer.zmi.widget import RendererFieldWidget from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event @@ -43,41 +42,19 @@ # Illustration properties inner edit form # -@viewlet_config(name='illustration', context=IIllustrationTarget, layer=IPyAMSLayer, view=IParagraphContainerTable, - manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=5) -@template_config(template='templates/paragraph-illustration-icon.pt', layer=IPyAMSLayer) -class ParagraphContainerIllustrationMarker(Viewlet): - """Paragraph container illustration marker column""" - - weight = 5 - action_class = 'action illustration nowrap width-40' - icon_class = 'fa fa-fw fa-picture-o' - icon_hint = _("Illustration") - - marker_type = 'illustration' - - def render(self): - illustration = IIllustration(self.context, None) - if illustration and illustration.data: - for value in illustration.data.values(): - if value: - return super(ParagraphContainerIllustrationMarker, self).render() - return '' - - @adapter_config(name='illustration', context=(IBasicIllustrationTarget, IPyAMSLayer, IPropertiesEditForm), provides=IInnerSubForm) class BasicIllustrationPropertiesInnerEditForm(InnerAdminEditForm): """Basic illustration properties inner edit form""" - prefix = 'illustration_form.' + prefix = 'basic_illustration_form.' css_class = 'form-group' padding_class = '' - fieldset_class = 'margin-top-10 padding-y-5' + fieldset_class = 'bordered margin-top-10 padding-y-5' legend = _("Illustration") - legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto' + legend_class = 'illustration switcher no-y-padding padding-right-10' fields = field.Fields(IBasicIllustration).omit('__parent__', '__name__') @@ -93,18 +70,17 @@ @property def switcher_state(self): content = self.getContent() - for value in (content.data or {}).values(): - if value: - return 'open' + if content.has_data(): + return 'open' def get_ajax_output(self, changes): output = super(BasicIllustrationPropertiesInnerEditForm, self).get_ajax_output(changes) - updated = changes.get(IIllustration, ()) - events = output.setdefault('events', []) + updated = changes.get(IBasicIllustration, ()) if 'data' in updated: # we have to commit transaction to be able to handle blobs... ITransactionManager(self.context).get().commit() - events.append(get_json_form_refresh_event(self.context, self.request, self.__class__)) + output.setdefault('events', []).append( + get_json_form_refresh_event(self.context, self.request, self.__class__)) return output @@ -113,6 +89,11 @@ class IllustrationPropertiesInnerEditForm(BasicIllustrationPropertiesInnerEditForm): """Illustration properties inner edit form""" + prefix = 'illustration_form.' + + fields = field.Fields(IIllustration).omit('__parent__', '__name__') + fields['renderer'].widgetFactory = RendererFieldWidget + @property def legend(self): if IBaseParagraph.providedBy(self.context): @@ -125,13 +106,22 @@ if IBaseParagraph.providedBy(self.context): return 'illustration switcher no-y-padding padding-right-10 pull-left width-auto' else: - return 'illustration no-y-padding' + return 'illustration switcher no-y-padding' - fields = field.Fields(IIllustration).omit('__parent__', '__name__') - fields['renderer'].widgetFactory = RendererFieldWidget + @property + def fieldset_class(self): + result = 'margin-top-10 padding-y-5' + if not IBaseParagraph.providedBy(self.context): + result += ' bordered' + return result hide_widgets_prefix_div = True + @property + def switcher_state(self): + if not IBaseParagraph.providedBy(self.context): + return 'open' + def updateWidgets(self, prefix=None): super(IllustrationPropertiesInnerEditForm, self).updateWidgets(prefix) if 'description' in self.widgets: @@ -139,9 +129,8 @@ def get_ajax_output(self, changes): output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes) - updated = changes.get(IIllustration, ()) events = output.setdefault('events', []) - if 'data' in updated: + if 'data' in changes.get(IBasicIllustration, ()): if IBaseParagraph.providedBy(self.context): if self.getContent().data: events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self, @@ -150,12 +139,29 @@ events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self, EmptyViewlet, ParagraphContainerIllustrationMarker.marker_type)) - elif 'renderer' in updated: + elif 'renderer' in changes.get(IIllustration, ()): events.append(get_json_widget_refresh_event(self.context, self.request, IllustrationPropertiesInnerEditForm, 'renderer')) return output +@adapter_config(name='link-illustration', context=(ILinkIllustrationTarget, IPyAMSLayer, IPropertiesEditForm), + provides=IInnerSubForm) +class LinkIllustrationPropertiesInnerEditForm(BasicIllustrationPropertiesInnerEditForm): + """Link illustration properties inner edit form""" + + prefix = 'link_illustration_form.' + + legend = _("Navigation link illustration") + legend_class = 'illustration switcher no-y-padding' + + weight = 11 + + def getContent(self): + registry = self.request.registry + return registry.getAdapter(self.context, IIllustration, name='link') + + @viewlet_config(name='illustration-thumbnail', context=IBasicIllustrationTarget, layer=IPyAMSLayer, view=BasicIllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) @template_config(template='templates/illustration-thumbnail.pt', layer=IPyAMSLayer)