# HG changeset patch # User Thierry Florac # Date 1507875279 -7200 # Node ID 9345af0a1b4c560a0f76b41d2bbd14d80c09b747 # Parent e585a41adea132412676f1299f9bb6ef35ff5fab Added marker for illustrations in paragraphs diff -r e585a41adea1 -r 9345af0a1b4c src/pyams_content/component/illustration/zmi/__init__.py --- a/src/pyams_content/component/illustration/zmi/__init__.py Fri Oct 13 08:13:59 2017 +0200 +++ b/src/pyams_content/component/illustration/zmi/__init__.py Fri Oct 13 08:14:39 2017 +0200 @@ -17,15 +17,20 @@ # import interfaces from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationRenderer, IIllustrationTarget -from pyams_form.interfaces.form import IInnerSubForm +from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar +from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager from pyams_i18n.interfaces import II18n 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_form.security import ProtectedFormObjectMixin +from pyams_skin.viewlet.toolbar import JsToolbarAction from pyams_template.template import get_view_template, template_config from pyams_utils.adapter import ContextRequestAdapter, adapter_config +from pyams_viewlet.viewlet import viewlet_config, Viewlet from pyams_zmi.form import InnerAdminEditForm from z3c.form import field @@ -82,6 +87,27 @@ # 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-file-image-o' + icon_hint = _("Illustration") + + def __new__(cls, context, request, view, manager): + illustration = IIllustration(context, None) + if (not illustration) or not illustration.data: + return None + for value in illustration.data.values(): + if value: + return Viewlet.__new__(cls) + return None + + @adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm), provides=IInnerSubForm) class IllustrationPropertiesInnerEditForm(InnerAdminEditForm): @@ -94,9 +120,10 @@ fieldset_class = 'margin-top-10 padding-y-5' legend = _("Illustration") - legend_class = 'inner switcher no-y-padding padding-right-10 pull-left' + legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto' fields = field.Fields(IIllustration).omit('__parent__', '__name__') + hide_widgets_prefix_div = True weight = 10 def getContent(self): @@ -111,12 +138,6 @@ if 'description' in self.widgets: self.widgets['description'].widget_css_class = 'textarea' - @property - def switcher_state(self): - for lang, data in self.getContent().data: - if data: - return 'open' - def get_ajax_output(self, changes): output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes) if 'data' in changes.get(IIllustration, ()): @@ -124,13 +145,62 @@ ITransactionManager(self.context).get().commit() form = IllustrationPropertiesInnerEditForm(self.context, self.request) form.update() + illustration = form.getContent() output.setdefault('events', []).append({ 'event': 'PyAMS_content.changed_item', - 'options': {'object_type': 'form', + 'options': {'handler': 'PyAMS_content.refreshForm', 'object_name': '{0}_{1}_{2}'.format( self.context.__class__.__name__, - getattr(form.getContent(), '__name__', 'noname').replace('++', ''), + getattr(illustration, '__name__', 'noname').replace('++', ''), form.id), 'form': form.render()} }) + viewlet = ParagraphContainerIllustrationMarker(self.context, self.request, self, None) + if viewlet is not None: + viewlet.update() + output.setdefault('events', []).append({ + 'event': 'PyAMS_content.changed_item', + 'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers', + 'object_name': self.context.__name__, + 'marker_type': 'illustration', + 'marker_tag': viewlet.render() if viewlet is not None else ''} + }) return output + + +@viewlet_config(name='add-illustration.action', context=IIllustrationTarget, layer=IPyAMSLayer, + view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) +class AddIllustrationAction(ProtectedFormObjectMixin, JsToolbarAction): + """Add illustration action""" + + group_css_class = 'btn-group clearfix persistent' + label = _("Add illustration") + url = 'PyAMS_content.illustration.addIllustration' + + def __new__(cls, context, request, view, manager): + illustration = IIllustration(context, None) + if illustration and illustration.data: + for value in illustration.data.values(): + if value: + return None + return JsToolbarAction.__new__(cls) + + +@viewlet_config(name='illustration-thumbnail', context=IIllustrationTarget, layer=IPyAMSLayer, + view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) +@template_config(template='templates/illustration-thumbnail.pt', layer=IPyAMSLayer) +class IllustrationThumbnail(Viewlet): + """Illustration thumbnail""" + + def __new__(cls, context, request, view, manager): + illustration = IIllustration(context, None) + if (not illustration) or not illustration.data: + return None + for value in illustration.data.values(): + if value: + return Viewlet.__new__(cls) + return None + + def __init__(self, context, request, view, manager): + super(IllustrationThumbnail, self).__init__(context, request, view, manager) + self.illustration = IIllustration(context) diff -r e585a41adea1 -r 9345af0a1b4c src/pyams_content/component/illustration/zmi/templates/illustration-thumbnail.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/component/illustration/zmi/templates/illustration-thumbnail.pt Fri Oct 13 08:14:39 2017 +0200 @@ -0,0 +1,4 @@ + + + diff -r e585a41adea1 -r 9345af0a1b4c src/pyams_content/component/illustration/zmi/templates/paragraph-illustration-icon.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/component/illustration/zmi/templates/paragraph-illustration-icon.pt Fri Oct 13 08:14:39 2017 +0200 @@ -0,0 +1,8 @@ +
+ +