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 IIllustration, IIllustrationTarget |
|
20 from pyams_content.component.paragraph import IBaseParagraph |
20 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar |
21 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar |
21 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager |
22 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager |
22 from pyams_skin.layer import IPyAMSLayer |
23 from pyams_skin.layer import IPyAMSLayer |
23 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
24 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
24 from pyams_utils.interfaces.data import IObjectData |
25 from pyams_utils.interfaces.data import IObjectData |
25 from pyams_zmi.interfaces import IPropertiesEditForm |
26 from pyams_zmi.interfaces import IPropertiesEditForm |
26 from transaction.interfaces import ITransactionManager |
27 from transaction.interfaces import ITransactionManager |
27 |
28 |
28 # import packages |
29 # import packages |
|
30 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event |
29 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget |
31 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget |
30 from pyams_content.skin import pyams_content |
32 from pyams_content.skin import pyams_content |
31 from pyams_form.security import ProtectedFormObjectMixin |
33 from pyams_form.security import ProtectedFormObjectMixin |
|
34 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event |
32 from pyams_skin.viewlet.toolbar import JsToolbarAction |
35 from pyams_skin.viewlet.toolbar import JsToolbarAction |
33 from pyams_template.template import template_config |
36 from pyams_template.template import template_config |
34 from pyams_utils.adapter import adapter_config |
37 from pyams_utils.adapter import adapter_config |
35 from pyams_utils.fanstatic import get_resource_path |
38 from pyams_utils.fanstatic import get_resource_path |
36 from pyams_viewlet.viewlet import viewlet_config, Viewlet |
39 from pyams_viewlet.viewlet import viewlet_config, Viewlet, EmptyViewlet |
37 from pyams_zmi.form import InnerAdminEditForm |
40 from pyams_zmi.form import InnerAdminEditForm |
38 from z3c.form import field |
41 from z3c.form import field |
39 from zope.interface import implementer |
42 from zope.interface import implementer |
40 |
43 |
41 from pyams_content import _ |
44 from pyams_content import _ |
54 weight = 5 |
57 weight = 5 |
55 action_class = 'action illustration nowrap width-40' |
58 action_class = 'action illustration nowrap width-40' |
56 icon_class = 'fa fa-fw fa-file-image-o' |
59 icon_class = 'fa fa-fw fa-file-image-o' |
57 icon_hint = _("Illustration") |
60 icon_hint = _("Illustration") |
58 |
61 |
59 def __new__(cls, context, request, view, manager): |
62 marker_type = 'illustration' |
60 illustration = IIllustration(context, None) |
63 |
61 if (not illustration) or not illustration.data: |
64 def render(self): |
62 return None |
65 illustration = IIllustration(self.context, None) |
63 for value in illustration.data.values(): |
66 if illustration and illustration.data: |
64 if value: |
67 for value in illustration.data.values(): |
65 return Viewlet.__new__(cls) |
68 if value: |
66 return None |
69 return super(ParagraphContainerIllustrationMarker, self).render() |
|
70 return '' |
67 |
71 |
68 |
72 |
69 @adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm), |
73 @adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm), |
70 provides=IInnerSubForm) |
74 provides=IInnerSubForm) |
71 class IllustrationPropertiesInnerEditForm(InnerAdminEditForm): |
75 class IllustrationPropertiesInnerEditForm(InnerAdminEditForm): |
99 self.widgets['description'].widget_css_class = 'textarea' |
103 self.widgets['description'].widget_css_class = 'textarea' |
100 |
104 |
101 def get_ajax_output(self, changes): |
105 def get_ajax_output(self, changes): |
102 output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes) |
106 output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes) |
103 updated = changes.get(IIllustration, ()) |
107 updated = changes.get(IIllustration, ()) |
104 if ('data' in updated) or ('renderer' in updated): |
108 events = output.setdefault('events', []) |
105 if 'data' in updated: |
109 if 'data' in updated: |
106 # we have to commit transaction to be able to handle blobs... |
110 # we have to commit transaction to be able to handle blobs... |
107 ITransactionManager(self.context).get().commit() |
111 ITransactionManager(self.context).get().commit() |
108 form = IllustrationPropertiesInnerEditForm(self.context, self.request) |
112 events.append(get_json_form_refresh_event(self.context, self.request, |
109 form.update() |
113 IllustrationPropertiesInnerEditForm)) |
110 illustration = form.getContent() |
114 if IBaseParagraph.providedBy(self.context): |
111 output.setdefault('events', []).append({ |
115 if self.getContent().data: |
112 'event': 'myams.refresh', |
116 events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self, |
113 'options': { |
117 ParagraphContainerIllustrationMarker)) |
114 'object_id': '{0}_{1}_{2}'.format( |
118 else: |
115 self.context.__class__.__name__, |
119 events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self, |
116 getattr(illustration, '__name__', 'noname').replace('++', ''), |
120 EmptyViewlet, |
117 form.id), |
121 ParagraphContainerIllustrationMarker.marker_type)) |
118 'content': form.render() |
122 elif 'renderer' in updated: |
119 } |
123 events.append(get_json_widget_refresh_event(self.context, self.request, |
120 }) |
124 IllustrationPropertiesInnerEditForm, 'renderer')) |
121 viewlet = ParagraphContainerIllustrationMarker(self.context, self.request, self, None) |
|
122 if viewlet is not None: |
|
123 viewlet.update() |
|
124 output.setdefault('events', []).append({ |
|
125 'event': 'myams.refresh', |
|
126 'options': { |
|
127 'handler': 'PyAMS_content.paragraphs.updateMarkers', |
|
128 'object_name': self.context.__name__, |
|
129 'marker_type': 'illustration', |
|
130 'marker_tag': viewlet.render() if viewlet is not None else '' |
|
131 } |
|
132 }) |
|
133 return output |
125 return output |
134 |
126 |
135 |
127 |
136 @viewlet_config(name='add-illustration.action', context=IIllustrationTarget, layer=IPyAMSLayer, |
128 @viewlet_config(name='add-illustration.action', context=IIllustrationTarget, layer=IPyAMSLayer, |
137 view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) |
129 view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager) |