33 from pyams_content.component.paragraph.zmi.container import ParagraphContainerTable, ParagraphContainerBaseTable |
33 from pyams_content.component.paragraph.zmi.container import ParagraphContainerTable, ParagraphContainerBaseTable |
34 from pyams_form.form import AJAXEditForm, AJAXAddForm |
34 from pyams_form.form import AJAXEditForm, AJAXAddForm |
35 from pyams_form.help import FormHelp |
35 from pyams_form.help import FormHelp |
36 from pyams_form.security import ProtectedFormObjectMixin |
36 from pyams_form.security import ProtectedFormObjectMixin |
37 from pyams_pagelet.pagelet import pagelet_config |
37 from pyams_pagelet.pagelet import pagelet_config |
|
38 from pyams_skin.event import get_json_switched_table_refresh_event |
|
39 from pyams_skin.table import get_element_id |
38 from pyams_skin.viewlet.menu import MenuItem, MenuDivider |
40 from pyams_skin.viewlet.menu import MenuItem, MenuDivider |
39 from pyams_skin.viewlet.toolbar import ToolbarMenuItem |
41 from pyams_skin.viewlet.toolbar import ToolbarMenuItem |
40 from pyams_utils.adapter import adapter_config |
42 from pyams_utils.adapter import adapter_config |
41 from pyams_utils.registry import query_utility |
43 from pyams_utils.registry import query_utility |
42 from pyams_utils.traversing import get_parent |
44 from pyams_utils.traversing import get_parent |
67 @pagelet_config(name='default-paragraphs.html', context=IParagraphFactorySettings, layer=IPyAMSLayer, |
69 @pagelet_config(name='default-paragraphs.html', context=IParagraphFactorySettings, layer=IPyAMSLayer, |
68 permission=MANAGE_TOOL_PERMISSION) |
70 permission=MANAGE_TOOL_PERMISSION) |
69 class DefaultParagraphsEditForm(AdminDialogEditForm): |
71 class DefaultParagraphsEditForm(AdminDialogEditForm): |
70 """Default paragraphs edit form""" |
72 """Default paragraphs edit form""" |
71 |
73 |
|
74 prefix = 'default_paragraphs.' |
|
75 |
72 legend = _("Paragraphs types") |
76 legend = _("Paragraphs types") |
73 |
77 |
74 fields = field.Fields(IParagraphFactorySettings) |
78 fields = field.Fields(IParagraphFactorySettings) |
75 ajax_handler = 'default-paragraphs.json' |
79 ajax_handler = 'default-paragraphs.json' |
76 edit_permission = MANAGE_TOOL_PERMISSION |
80 edit_permission = MANAGE_TOOL_PERMISSION |
93 |
97 |
94 |
98 |
95 # |
99 # |
96 # Base paragraph forms |
100 # Base paragraph forms |
97 # |
101 # |
|
102 |
|
103 def get_json_paragraph_refresh_event(context, request): |
|
104 """Get JSON response value for paragraph refresh event""" |
|
105 parent = get_parent(context, IParagraphContainerTarget) |
|
106 return { |
|
107 'event': 'myams.refresh', |
|
108 'options': { |
|
109 'handler': 'PyAMS_content.paragraphs.refreshParagraph', |
|
110 'object_id': get_element_id(ParagraphContainerBaseTable, context, parent), |
|
111 'title': II18n(context).query_attribute('title', request=request), |
|
112 'visible': context.visible |
|
113 } |
|
114 } |
|
115 |
|
116 |
|
117 def get_json_paragraph_toolbar_refresh_event(context, request, table_factory=None, viewlet_factory=None): |
|
118 """Get JSON response value for paragraph toolbar refresh event""" |
|
119 if table_factory is None: |
|
120 from pyams_content.component.paragraph.zmi.container import ParagraphContainerTable as table_factory |
|
121 if viewlet_factory is None: |
|
122 from pyams_content.component.paragraph.zmi.container import ParagraphTitleToolbarViewletManager as viewlet_factory |
|
123 |
|
124 parent = get_parent(context, IParagraphContainerTarget) |
|
125 table = table_factory(context, request) |
|
126 viewlet = viewlet_factory(context, request, table) |
|
127 viewlet.update() |
|
128 return { |
|
129 'event': 'myams.refresh', |
|
130 'options': { |
|
131 'handler': 'PyAMS_content.paragraphs.updateToolbar', |
|
132 'object_id': get_element_id(ParagraphContainerBaseTable, context, parent), |
|
133 'toolbar_tag': viewlet.render() |
|
134 } |
|
135 } |
|
136 |
|
137 |
|
138 def get_json_paragraph_markers_refresh_event(context, request, form, viewlet_factory, marker_type=None): |
|
139 """Get JSON response value for paragraph markers refresh event""" |
|
140 parent = get_parent(context, IParagraphContainerTarget) |
|
141 marker = viewlet_factory(context, request, form, None) |
|
142 if marker is not None: |
|
143 marker.update() |
|
144 return { |
|
145 'event': 'myams.refresh', |
|
146 'options': { |
|
147 'handler': 'PyAMS_content.paragraphs.updateMarkers', |
|
148 'object_id': get_element_id(ParagraphContainerBaseTable, context, parent), |
|
149 'marker_type': marker_type or marker.marker_type, |
|
150 'marker_tag': marker.render() |
|
151 } |
|
152 } |
|
153 |
98 |
154 |
99 class BaseParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem): |
155 class BaseParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem): |
100 """Base paragraph add menu""" |
156 """Base paragraph add menu""" |
101 |
157 |
102 paragraph_type = None |
158 paragraph_type = None |
131 def get_ajax_output(self, changes): |
187 def get_ajax_output(self, changes): |
132 if IWfSharedContent.providedBy(self.context): |
188 if IWfSharedContent.providedBy(self.context): |
133 table_factory = ParagraphContainerTable |
189 table_factory = ParagraphContainerTable |
134 else: |
190 else: |
135 table_factory = ParagraphContainerBaseTable |
191 table_factory = ParagraphContainerBaseTable |
136 table = table_factory(self.context, self.request) |
192 return { |
137 table.update() |
193 'status': 'success', |
138 return {'status': 'success', |
194 'message': self.request.localizer.translate(_("Paragraph was correctly added.")), |
139 'message': self.request.localizer.translate(_("Paragraph was correctly added.")), |
195 'events': [get_json_switched_table_refresh_event(self.context, self.request, table_factory)] |
140 'events': [{ |
196 } |
141 'event': 'myams.refresh', |
|
142 'options': { |
|
143 'handler': 'MyAMS.skin.refreshSwitchedTable', |
|
144 'object_id': table.id, |
|
145 'table': table.render() |
|
146 } |
|
147 }]} |
|
148 |
197 |
149 |
198 |
150 class BaseParagraphPropertiesEditForm(AdminDialogEditForm): |
199 class BaseParagraphPropertiesEditForm(AdminDialogEditForm): |
151 """Base paragraph edit form""" |
200 """Base paragraph edit form""" |
152 |
201 |
153 @property |
202 prefix = 'paragraph.' |
154 def prefix(self): |
|
155 return 'paragraph_{0}_form.'.format(self.context.__name__) |
|
156 |
203 |
157 @property |
204 @property |
158 def title(self): |
205 def title(self): |
159 registry = self.request.registry |
206 registry = self.request.registry |
160 for parent in lineage(self.context): |
207 for parent in lineage(self.context): |
171 """Base paragraph AJAX edit form""" |
218 """Base paragraph AJAX edit form""" |
172 |
219 |
173 def get_ajax_output(self, changes): |
220 def get_ajax_output(self, changes): |
174 output = super(BaseParagraphAJAXEditForm, self).get_ajax_output(changes) |
221 output = super(BaseParagraphAJAXEditForm, self).get_ajax_output(changes) |
175 if 'title' in changes.get(IBaseParagraph, ()): |
222 if 'title' in changes.get(IBaseParagraph, ()): |
176 output.setdefault('events', []).append({ |
223 output.setdefault('events', []).append( |
177 'event': 'myams.refresh', |
224 get_json_paragraph_refresh_event(self.context, self.request)) |
178 'options': { |
|
179 'handler': 'PyAMS_content.paragraphs.refreshParagraph', |
|
180 'object_name': self.context.__name__, |
|
181 'title': II18n(self.context).query_attribute('title', request=self.request), |
|
182 'visible': self.context.visible |
|
183 } |
|
184 }) |
|
185 return output |
225 return output |