21 IParagraphPreview |
21 IParagraphPreview |
22 from pyams_content.component.paragraph.interfaces.video import IVideoParagraph, VIDEO_PARAGRAPH_TYPE |
22 from pyams_content.component.paragraph.interfaces.video import IVideoParagraph, VIDEO_PARAGRAPH_TYPE |
23 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView |
23 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView |
24 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION |
24 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION |
25 from pyams_form.interfaces.form import IInnerForm, IEditFormButtons |
25 from pyams_form.interfaces.form import IInnerForm, IEditFormButtons |
26 from pyams_i18n.interfaces import II18n |
|
27 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu |
26 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu |
28 from pyams_skin.layer import IPyAMSLayer |
27 from pyams_skin.layer import IPyAMSLayer |
29 from pyams_zmi.interfaces import IPropertiesEditForm |
28 from pyams_zmi.interfaces import IPropertiesEditForm |
30 from transaction.interfaces import ITransactionManager |
29 from transaction.interfaces import ITransactionManager |
31 from z3c.form.interfaces import INPUT_MODE |
30 from z3c.form.interfaces import INPUT_MODE |
33 # import packages |
32 # import packages |
34 from pyams_content.component.association.zmi import AssociationsTable |
33 from pyams_content.component.association.zmi import AssociationsTable |
35 from pyams_content.component.paragraph.video import VideoParagraph |
34 from pyams_content.component.paragraph.video import VideoParagraph |
36 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ |
35 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ |
37 BaseParagraphAddMenu, BaseParagraphPropertiesEditForm |
36 BaseParagraphAddMenu, BaseParagraphPropertiesEditForm |
|
37 from pyams_content.features.renderer.zmi import BaseRenderedContentPreview |
|
38 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget |
38 from pyams_form.group import NamedWidgetsGroup |
39 from pyams_form.group import NamedWidgetsGroup |
39 from pyams_pagelet.pagelet import pagelet_config |
40 from pyams_pagelet.pagelet import pagelet_config |
40 from pyams_template.template import template_config |
|
41 from pyams_utils.adapter import adapter_config |
41 from pyams_utils.adapter import adapter_config |
42 from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider |
42 from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider |
43 from pyams_zmi.form import AdminDialogAddForm |
43 from pyams_zmi.form import AdminDialogAddForm |
44 from pyramid.view import view_config |
44 from pyramid.view import view_config |
45 from z3c.form import field, button |
45 from z3c.form import field, button |
83 legend=_("HTML content"), |
83 legend=_("HTML content"), |
84 css_class='inner switcher padding-right-10 no-y-padding pull-left', |
84 css_class='inner switcher padding-right-10 no-y-padding pull-left', |
85 switch=True, |
85 switch=True, |
86 hide_if_empty=True)) |
86 hide_if_empty=True)) |
87 self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets, |
87 self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets, |
88 ('description', 'author', 'data'), |
88 ('description', 'author', 'data', 'renderer'), |
89 bordered=False)) |
89 bordered=False)) |
90 |
90 |
91 def create(self, data): |
91 def create(self, data): |
92 return VideoParagraph() |
92 return VideoParagraph() |
93 |
93 |
109 legend = _("Edit video properties") |
109 legend = _("Edit video properties") |
110 dialog_class = 'modal-large' |
110 dialog_class = 'modal-large' |
111 icon_css_class = 'fa fa-fw fa-film' |
111 icon_css_class = 'fa fa-fw fa-film' |
112 |
112 |
113 fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible') |
113 fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible') |
|
114 fields['renderer'].widgetFactory = RendererFieldWidget |
|
115 |
114 ajax_handler = 'properties.json' |
116 ajax_handler = 'properties.json' |
115 edit_permission = MANAGE_CONTENT_PERMISSION |
117 edit_permission = MANAGE_CONTENT_PERMISSION |
116 |
118 |
117 def updateWidgets(self, prefix=None): |
119 def updateWidgets(self, prefix=None): |
118 super(VideoParagraphPropertiesEditForm, self).updateWidgets(prefix) |
120 super(VideoParagraphPropertiesEditForm, self).updateWidgets(prefix) |
126 legend=_("HTML content"), |
128 legend=_("HTML content"), |
127 css_class='inner switcher padding-right-10 no-y-padding pull-left', |
129 css_class='inner switcher padding-right-10 no-y-padding pull-left', |
128 switch=True, |
130 switch=True, |
129 hide_if_empty=True)) |
131 hide_if_empty=True)) |
130 self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets, |
132 self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets, |
131 ('description', 'author', 'data'), |
133 ('description', 'author', 'data', 'renderer'), |
132 bordered=False)) |
134 bordered=False)) |
133 |
135 |
134 |
136 |
135 @view_config(name='properties.json', context=IVideoParagraph, request_type=IPyAMSLayer, |
137 @view_config(name='properties.json', context=IVideoParagraph, request_type=IPyAMSLayer, |
136 permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True) |
138 permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True) |
181 'event': 'PyAMS_content.changed_item', |
183 'event': 'PyAMS_content.changed_item', |
182 'options': {'handler': 'PyAMS_content.associations.refreshAssociations', |
184 'options': {'handler': 'PyAMS_content.associations.refreshAssociations', |
183 'object_name': associations_table.id, |
185 'object_name': associations_table.id, |
184 'table': associations_table.render()} |
186 'table': associations_table.render()} |
185 }) |
187 }) |
186 if 'data' in updated: |
188 if ('data' in updated) or ('renderer' in updated): |
187 # we have to commit transaction to be able to handle blobs... |
189 if 'data' in updated: |
188 ITransactionManager(self.context).get().commit() |
190 # we have to commit transaction to be able to handle blobs... |
|
191 ITransactionManager(self.context).get().commit() |
189 form = VideoParagraphPropertiesInnerEditForm(self.context, self.request) |
192 form = VideoParagraphPropertiesInnerEditForm(self.context, self.request) |
190 form.update() |
193 form.update() |
191 output.setdefault('events', []).append({ |
194 output.setdefault('events', []).append({ |
192 'event': 'myams.refresh', |
195 'event': 'myams.refresh', |
193 'options': {'object_id': '{0}_{1}_{2}'.format( |
196 'options': { |
194 self.context.__class__.__name__, |
197 'object_id': '{0}_{1}_{2}'.format( |
195 getattr(form.getContent(), '__name__', 'noname').replace('++', ''), |
198 self.context.__class__.__name__, |
196 form.id), |
199 getattr(form.getContent(), '__name__', 'noname').replace('++', ''), |
197 'content': form.render()} |
200 form.id), |
|
201 'content': form.render() |
|
202 } |
198 }) |
203 }) |
199 return output |
204 return output |
200 |
205 |
201 |
206 |
202 # |
207 # |
203 # Video paragraph preview |
208 # Video paragraph preview |
204 # |
209 # |
205 |
210 |
206 @adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphPreview) |
211 @adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphPreview) |
207 @template_config(template='templates/video-preview.pt', layer=IPyAMSLayer) |
212 class VideoParagraphPreview(BaseRenderedContentPreview): |
208 class VideoParagraphPreview(BaseContentProvider): |
|
209 """Video paragraph preview""" |
213 """Video paragraph preview""" |
210 |
|
211 language = None |
|
212 |
|
213 def update(self): |
|
214 i18n = II18n(self.context) |
|
215 if self.language: |
|
216 for attr in ('title', 'body', 'description'): |
|
217 setattr(self, attr, i18n.get_attribute(attr, self.language, request=self.request)) |
|
218 else: |
|
219 for attr in ('title', 'body', 'description'): |
|
220 setattr(self, attr, i18n.query_attribute(attr, request=self.request)) |
|