20 from pyams_content.component.paragraph import IBaseParagraph |
20 from pyams_content.component.paragraph import IBaseParagraph |
21 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar |
21 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar |
22 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager |
22 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager |
23 from pyams_skin.layer import IPyAMSLayer |
23 from pyams_skin.layer import IPyAMSLayer |
24 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
24 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
25 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 |
30 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event |
29 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event |
31 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget |
30 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget |
32 from pyams_content.skin import pyams_content |
|
33 from pyams_form.security import ProtectedFormObjectMixin |
|
34 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event |
31 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event |
35 from pyams_skin.viewlet.toolbar import JsToolbarAction |
|
36 from pyams_template.template import template_config |
32 from pyams_template.template import template_config |
37 from pyams_utils.adapter import adapter_config |
33 from pyams_utils.adapter import adapter_config |
38 from pyams_utils.fanstatic import get_resource_path |
|
39 from pyams_viewlet.viewlet import viewlet_config, Viewlet, EmptyViewlet |
34 from pyams_viewlet.viewlet import viewlet_config, Viewlet, EmptyViewlet |
40 from pyams_zmi.form import InnerAdminEditForm |
35 from pyams_zmi.form import InnerAdminEditForm |
41 from z3c.form import field |
36 from z3c.form import field |
42 from zope.interface import implementer |
|
43 |
37 |
44 from pyams_content import _ |
38 from pyams_content import _ |
45 |
39 |
46 |
40 |
47 # |
41 # |
54 class ParagraphContainerIllustrationMarker(Viewlet): |
48 class ParagraphContainerIllustrationMarker(Viewlet): |
55 """Paragraph container illustration marker column""" |
49 """Paragraph container illustration marker column""" |
56 |
50 |
57 weight = 5 |
51 weight = 5 |
58 action_class = 'action illustration nowrap width-40' |
52 action_class = 'action illustration nowrap width-40' |
59 icon_class = 'fa fa-fw fa-file-image-o' |
53 icon_class = 'fa fa-fw fa-picture-o' |
60 icon_hint = _("Illustration") |
54 icon_hint = _("Illustration") |
61 |
55 |
62 marker_type = 'illustration' |
56 marker_type = 'illustration' |
63 |
57 |
64 def render(self): |
58 def render(self): |
79 |
73 |
80 css_class = 'form-group' |
74 css_class = 'form-group' |
81 padding_class = '' |
75 padding_class = '' |
82 fieldset_class = 'margin-top-10 padding-y-5' |
76 fieldset_class = 'margin-top-10 padding-y-5' |
83 |
77 |
84 legend = _("Illustration") |
78 @property |
85 legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto' |
79 def legend(self): |
|
80 if IBaseParagraph.providedBy(self.context): |
|
81 return _("Illustration") |
|
82 else: |
|
83 return _("Header illustration") |
|
84 |
|
85 @property |
|
86 def legend_class(self): |
|
87 if IBaseParagraph.providedBy(self.context): |
|
88 return 'illustration switcher no-y-padding padding-right-10 pull-left width-auto' |
|
89 else: |
|
90 return 'illustration no-y-padding' |
86 |
91 |
87 fields = field.Fields(IIllustration).omit('__parent__', '__name__') |
92 fields = field.Fields(IIllustration).omit('__parent__', '__name__') |
88 fields['renderer'].widgetFactory = RendererFieldWidget |
93 fields['renderer'].widgetFactory = RendererFieldWidget |
89 |
94 |
90 hide_widgets_prefix_div = True |
95 hide_widgets_prefix_div = True |
123 events.append(get_json_widget_refresh_event(self.context, self.request, |
128 events.append(get_json_widget_refresh_event(self.context, self.request, |
124 IllustrationPropertiesInnerEditForm, 'renderer')) |
129 IllustrationPropertiesInnerEditForm, 'renderer')) |
125 return output |
130 return output |
126 |
131 |
127 |
132 |
128 @viewlet_config(name='add-illustration.action', context=IIllustrationTarget, layer=IPyAMSLayer, |
|
129 view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) |
|
130 @implementer(IObjectData) |
|
131 class AddIllustrationAction(ProtectedFormObjectMixin, JsToolbarAction): |
|
132 """Add illustration action""" |
|
133 |
|
134 group_css_class = 'btn-group clearfix persistent' |
|
135 label = _("Add illustration") |
|
136 url = 'PyAMS_content.illustration.addIllustration' |
|
137 |
|
138 def __new__(cls, context, request, view, manager): |
|
139 illustration = IIllustration(context, None) |
|
140 if illustration and illustration.data: |
|
141 for value in illustration.data.values(): |
|
142 if value: |
|
143 return None |
|
144 return JsToolbarAction.__new__(cls) |
|
145 |
|
146 @property |
|
147 def object_data(self): |
|
148 return { |
|
149 'ams-plugins': 'pyams_content', |
|
150 'ams-plugin-pyams_content-src': get_resource_path(pyams_content) |
|
151 } |
|
152 |
|
153 |
|
154 @viewlet_config(name='illustration-thumbnail', context=IIllustrationTarget, layer=IPyAMSLayer, |
133 @viewlet_config(name='illustration-thumbnail', context=IIllustrationTarget, layer=IPyAMSLayer, |
155 view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) |
134 view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) |
156 @template_config(template='templates/illustration-thumbnail.pt', layer=IPyAMSLayer) |
135 @template_config(template='templates/illustration-thumbnail.pt', layer=IPyAMSLayer) |
157 class IllustrationThumbnail(Viewlet): |
136 class IllustrationThumbnail(Viewlet): |
158 """Illustration thumbnail""" |
137 """Paragraph illustration thumbnail""" |
159 |
138 |
160 def __new__(cls, context, request, view, manager): |
139 def __new__(cls, context, request, view, manager): |
|
140 if not IBaseParagraph.providedBy(context): |
|
141 return None |
161 illustration = IIllustration(context, None) |
142 illustration = IIllustration(context, None) |
162 if (not illustration) or not illustration.data: |
143 if (not illustration) or not illustration.data: |
163 return None |
144 return None |
164 for value in illustration.data.values(): |
145 for value in illustration.data.values(): |
165 if value: |
146 if value: |