|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm |
|
20 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ |
|
21 IParagraphPreview |
|
22 from pyams_content.component.paragraph.interfaces.verbatim import IVerbatimParagraph, VERBATIM_PARAGRAPH_TYPE |
|
23 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView |
|
24 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION |
|
25 from pyams_form.interfaces.form import IInnerForm, IEditFormButtons |
|
26 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu |
|
27 from pyams_skin.layer import IPyAMSLayer |
|
28 from pyams_zmi.interfaces import IPropertiesEditForm |
|
29 from z3c.form.interfaces import INPUT_MODE |
|
30 |
|
31 # import packages |
|
32 from pyams_content.component.paragraph.verbatim import VerbatimParagraph |
|
33 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \ |
|
34 BaseParagraphAddMenu, BaseParagraphPropertiesEditForm |
|
35 from pyams_content.features.renderer.zmi import BaseRenderedContentPreview |
|
36 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget |
|
37 from pyams_pagelet.pagelet import pagelet_config |
|
38 from pyams_utils.adapter import adapter_config |
|
39 from pyams_viewlet.viewlet import viewlet_config |
|
40 from pyams_zmi.form import AdminDialogAddForm |
|
41 from pyramid.view import view_config |
|
42 from z3c.form import field, button |
|
43 from zope.interface import implementer |
|
44 |
|
45 from pyams_content import _ |
|
46 |
|
47 |
|
48 # |
|
49 # Verbatim paragraph |
|
50 # |
|
51 |
|
52 @viewlet_config(name='add-verbatim-paragraph.menu', context=IParagraphContainerTarget, view=IParagraphContainerView, |
|
53 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=600) |
|
54 class VerbatimParagraphAddMenu(BaseParagraphAddMenu): |
|
55 """Verbatim paragraph add menu""" |
|
56 |
|
57 label = _("Verbatim...") |
|
58 label_css_class = 'fa fa-fw fa-quote-right' |
|
59 url = 'add-verbatim-paragraph.html' |
|
60 paragraph_type = VERBATIM_PARAGRAPH_TYPE |
|
61 |
|
62 |
|
63 @pagelet_config(name='add-verbatim-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer, |
|
64 permission=MANAGE_CONTENT_PERMISSION) |
|
65 class VerbatimParagraphAddForm(AdminDialogAddForm): |
|
66 """Verbatim paragraph add form""" |
|
67 |
|
68 legend = _("Add new verbatim paragraph") |
|
69 icon_css_class = 'fa fa-fw fa-quote-right' |
|
70 |
|
71 fields = field.Fields(IVerbatimParagraph).omit('__parent__', '__name__', 'visible') |
|
72 ajax_handler = 'add-verbatim-paragraph.json' |
|
73 edit_permission = MANAGE_CONTENT_PERMISSION |
|
74 |
|
75 def updateWidgets(self, prefix=None): |
|
76 super(VerbatimParagraphAddForm, self).updateWidgets(prefix) |
|
77 if 'quote' in self.widgets: |
|
78 self.widgets['quote'].widget_css_class = 'textarea' |
|
79 |
|
80 def create(self, data): |
|
81 return VerbatimParagraph() |
|
82 |
|
83 def add(self, object): |
|
84 IParagraphContainer(self.context).append(object) |
|
85 |
|
86 |
|
87 @view_config(name='add-verbatim-paragraph.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer, |
|
88 permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True) |
|
89 class VerbatimParagraphAJAXAddForm(BaseParagraphAJAXAddForm, VerbatimParagraphAddForm): |
|
90 """Verbatim paragraph add form, JSON renderer""" |
|
91 |
|
92 |
|
93 @pagelet_config(name='properties.html', context=IVerbatimParagraph, layer=IPyAMSLayer, |
|
94 permission=MANAGE_CONTENT_PERMISSION) |
|
95 class VerbatimParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm): |
|
96 """Verbatim paragraph properties edit form""" |
|
97 |
|
98 legend = _("Edit verbatim paragraph properties") |
|
99 icon_css_class = 'fa fa-fw fa-quote-right' |
|
100 |
|
101 fields = field.Fields(IVerbatimParagraph).omit('__parent__', '__name__', 'visible') |
|
102 fields['renderer'].widgetFactory = RendererFieldWidget |
|
103 |
|
104 ajax_handler = 'properties.json' |
|
105 edit_permission = MANAGE_CONTENT_PERMISSION |
|
106 |
|
107 def updateWidgets(self, prefix=None): |
|
108 super(VerbatimParagraphPropertiesEditForm, self).updateWidgets(prefix) |
|
109 if 'quote' in self.widgets: |
|
110 self.widgets['quote'].widget_css_class = 'textarea' |
|
111 |
|
112 |
|
113 @view_config(name='properties.json', context=IVerbatimParagraph, request_type=IPyAMSLayer, |
|
114 permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True) |
|
115 class VerbatimParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, VerbatimParagraphPropertiesEditForm): |
|
116 """Verbatim paragraph properties edit form, JSON renderer""" |
|
117 |
|
118 |
|
119 @adapter_config(context=(IVerbatimParagraph, IPyAMSLayer), provides=IParagraphInnerEditor) |
|
120 @implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm) |
|
121 class VerbatimParagraphInnerEditForm(VerbatimParagraphPropertiesEditForm): |
|
122 """Verbatim paragraph inner edit form""" |
|
123 |
|
124 legend = None |
|
125 ajax_handler = 'inner-properties.json' |
|
126 |
|
127 @property |
|
128 def buttons(self): |
|
129 if self.mode == INPUT_MODE: |
|
130 return button.Buttons(IEditFormButtons) |
|
131 else: |
|
132 return button.Buttons() |
|
133 |
|
134 |
|
135 @view_config(name='inner-properties.json', context=IVerbatimParagraph, request_type=IPyAMSLayer, |
|
136 permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True) |
|
137 class VerbatimParagraphInnerAJAXEditForm(BaseParagraphAJAXEditForm, VerbatimParagraphInnerEditForm): |
|
138 """Verbatim paragraph inner edit form, JSON renderer""" |
|
139 |
|
140 def get_ajax_output(self, changes): |
|
141 output = super(VerbatimParagraphInnerAJAXEditForm, self).get_ajax_output(changes) |
|
142 if 'renderer' in changes.get(IVerbatimParagraph, ()): |
|
143 form = VerbatimParagraphInnerEditForm(self.context, self.request) |
|
144 form.update() |
|
145 output.setdefault('events', []).append({ |
|
146 'event': 'myams.refresh', |
|
147 'options': { |
|
148 'object_id': '{0}_{1}_{2}'.format( |
|
149 self.context.__class__.__name__, |
|
150 getattr(form.getContent(), '__name__', 'noname').replace('++', ''), |
|
151 form.id), |
|
152 'content': form.render() |
|
153 } |
|
154 }) |
|
155 return output |
|
156 |
|
157 |
|
158 # |
|
159 # Verbatim paragraph preview |
|
160 # |
|
161 |
|
162 @adapter_config(context=(IVerbatimParagraph, IPyAMSLayer), provides=IParagraphPreview) |
|
163 class VerbatimParagraphPreview(BaseRenderedContentPreview): |
|
164 """Verbatim paragraph preview""" |