20 from pyams_content.component.association.interfaces import IAssociationTarget, IAssociationContainer, IAssociationInfo |
20 from pyams_content.component.association.interfaces import IAssociationTarget, IAssociationContainer, IAssociationInfo |
21 from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm, IAssociationsView |
21 from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm, IAssociationsView |
22 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION |
22 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION |
23 from pyams_form.interfaces.form import IInnerSubForm |
23 from pyams_form.interfaces.form import IInnerSubForm |
24 from pyams_skin.layer import IPyAMSLayer |
24 from pyams_skin.layer import IPyAMSLayer |
25 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_PERMISSION |
25 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
26 from pyams_zmi.interfaces.menu import IPropertiesMenu |
26 from pyams_zmi.interfaces.menu import IPropertiesMenu |
27 from z3c.table.interfaces import IValues, IColumn |
27 from z3c.table.interfaces import IValues, IColumn |
28 |
28 |
29 # import packages |
29 # import packages |
30 from pyams_form.form import AJAXAddForm, AJAXEditForm |
30 from pyams_form.form import AJAXAddForm, AJAXEditForm |
31 from pyams_form.security import ProtectedFormObjectMixin |
31 from pyams_form.security import ProtectedFormObjectMixin |
32 from pyams_pagelet.pagelet import pagelet_config, Pagelet |
32 from pyams_pagelet.pagelet import pagelet_config, Pagelet |
33 from pyams_skin.table import BaseTable, SorterColumn, NameColumn, ImageColumn, I18nColumn, TrashColumn, \ |
33 from pyams_skin.table import BaseTable, SorterColumn, NameColumn, ImageColumn, I18nColumn, TrashColumn, \ |
34 VisibilitySwitcherColumn |
34 VisibilitySwitcherColumn |
35 from pyams_skin.container import switch_element_visibility |
35 from pyams_skin.container import switch_element_visibility, delete_container_element |
|
36 from pyams_skin.event import get_json_switched_table_refresh_event, get_json_table_row_refresh_event |
36 from pyams_skin.viewlet.menu import MenuItem |
37 from pyams_skin.viewlet.menu import MenuItem |
37 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
38 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
38 from pyams_utils.traversing import get_parent |
39 from pyams_utils.traversing import get_parent |
39 from pyams_utils.url import absolute_url |
40 from pyams_utils.url import absolute_url |
40 from pyams_viewlet.viewlet import viewlet_config |
41 from pyams_viewlet.viewlet import viewlet_config |
56 |
57 |
57 class AssociationItemAJAXAddForm(AJAXAddForm): |
58 class AssociationItemAJAXAddForm(AJAXAddForm): |
58 """Association item add form, JSON renderer""" |
59 """Association item add form, JSON renderer""" |
59 |
60 |
60 def get_ajax_output(self, changes): |
61 def get_ajax_output(self, changes): |
61 table = AssociationsTable(self.context, self.request) |
|
62 table.update() |
|
63 return { |
62 return { |
64 'status': 'success', |
63 'status': 'success', |
65 'message': self.request.localizer.translate(_("Association was correctly added.")), |
64 'message': self.request.localizer.translate(_("Association was correctly added.")), |
66 'events': [{ |
65 'events': [ |
67 'event': 'myams.refresh', |
66 get_json_switched_table_refresh_event(self.context, self.request, AssociationsTable) |
68 'options': { |
67 ] |
69 'handler': 'MyAMS.skin.refreshSwitchedTable', |
|
70 'object_id': table.id, |
|
71 'table': table.render() |
|
72 } |
|
73 }] |
|
74 } |
68 } |
75 |
69 |
76 |
70 |
77 class AssociationItemAJAXEditForm(AJAXEditForm): |
71 class AssociationItemAJAXEditForm(AJAXEditForm): |
78 """Association item properties edit form, JSON renderer""" |
72 """Association item properties edit form, JSON renderer""" |
79 |
73 |
80 def get_associations_table(self): |
74 def get_associations_table(self): |
81 target = get_parent(self.context, IAssociationTarget) |
75 target = get_parent(self.context, IAssociationTarget) |
82 table = AssociationsTable(target, self.request) |
|
83 table.update() |
|
84 return { |
76 return { |
85 'status': 'success', |
77 'status': 'success', |
86 'message': self.request.localizer.translate(self.successMessage), |
78 'message': self.request.localizer.translate(self.successMessage), |
87 'events': [{ |
79 'events': [ |
88 'event': 'myams.refresh', |
80 get_json_table_row_refresh_event(target, self.request, AssociationsTable, self.context) |
89 'options': { |
81 ] |
90 'handler': 'MyAMS.skin.refreshSwitchedTable', |
|
91 'object_id': table.id, |
|
92 'table': table.render() |
|
93 } |
|
94 }] |
|
95 } |
82 } |
96 |
83 |
97 |
84 |
98 # |
85 # |
99 # Content associations view |
86 # Content associations view |
133 attributes['table'] = { |
118 attributes['table'] = { |
134 'id': self.id, |
119 'id': self.id, |
135 'data-ams-location': absolute_url(IAssociationContainer(self.context), self.request), |
120 'data-ams-location': absolute_url(IAssociationContainer(self.context), self.request), |
136 'data-ams-tablednd-drag-handle': 'td.sorter', |
121 'data-ams-tablednd-drag-handle': 'td.sorter', |
137 'data-ams-tablednd-drop-target': 'set-associations-order.json', |
122 'data-ams-tablednd-drop-target': 'set-associations-order.json', |
138 'data-ams-visibility-target': 'switch-association-visibility.json' |
123 'data-ams-visibility-switcher': 'switch-association-visibility.json' |
139 } |
124 } |
140 attributes.setdefault('tr', {}).update({ |
|
141 'data-ams-delete-target': 'delete-association.json' |
|
142 }) |
|
143 return attributes |
125 return attributes |
144 |
126 |
145 @reify |
127 @reify |
146 def values(self): |
128 def values(self): |
147 return list(super(AssociationsTable, self).values) |
129 return list(super(AssociationsTable, self).values) |
248 @adapter_config(name='trash', context=(IAssociationTarget, IPyAMSLayer, AssociationsTable), provides=IColumn) |
230 @adapter_config(name='trash', context=(IAssociationTarget, IPyAMSLayer, AssociationsTable), provides=IColumn) |
249 class AssociationsTableTrashColumn(ProtectedFormObjectMixin, TrashColumn): |
231 class AssociationsTableTrashColumn(ProtectedFormObjectMixin, TrashColumn): |
250 """Associations table trash column""" |
232 """Associations table trash column""" |
251 |
233 |
252 |
234 |
253 @view_config(name='delete-association.json', context=IAssociationContainer, request_type=IPyAMSLayer, |
235 @view_config(name='delete-element.json', context=IAssociationContainer, request_type=IPyAMSLayer, |
254 permission=MANAGE_PERMISSION, renderer='json', xhr=True) |
236 renderer='json', xhr=True) |
255 def delete_association(request): |
237 def delete_association(request): |
256 """Delete association""" |
238 """Delete association""" |
257 |
239 output = delete_container_element(request) |
258 from pyams_content.component.paragraph.zmi.container \ |
240 if output.get('status') == 'success': |
259 import ParagraphContainerTable, ParagraphTitleToolbarViewletManager |
241 from pyams_content.component.paragraph.zmi import get_json_paragraph_toolbar_refresh_event |
260 |
242 parent = get_parent(request.context, IAssociationTarget) |
261 translate = request.localizer.translate |
243 output.update({ |
262 name = request.params.get('object_name') |
244 'handle_json': True, |
263 if not name: |
245 'events': [ |
264 return { |
246 get_json_paragraph_toolbar_refresh_event(parent, request), |
265 'status': 'message', |
247 get_json_switched_table_refresh_event(parent, request, AssociationsTable) |
266 'messagebox': { |
248 ] |
267 'status': 'error', |
249 }) |
268 'content': translate(_("No provided object_name argument!")) |
250 return output |
269 } |
|
270 } |
|
271 if name not in request.context: |
|
272 return { |
|
273 'status': 'message', |
|
274 'messagebox': { |
|
275 'status': 'error', |
|
276 'content': translate(_("Given association name doesn't exist!")) |
|
277 } |
|
278 } |
|
279 del request.context[name] |
|
280 parent = get_parent(request.context, IAssociationTarget) |
|
281 table = ParagraphContainerTable(parent, request) |
|
282 viewlet = ParagraphTitleToolbarViewletManager(parent, request, table) |
|
283 viewlet.update() |
|
284 return { |
|
285 'status': 'success', |
|
286 'handle_json': True, |
|
287 'events': [{ |
|
288 'event': 'myams.refresh', |
|
289 'options': { |
|
290 'handler': 'PyAMS_content.paragraphs.updateToolbar', |
|
291 'object_name': parent.__name__, |
|
292 'toolbar_tag': viewlet.render() |
|
293 } |
|
294 }] |
|
295 } |
|
296 |
251 |
297 |
252 |
298 @pagelet_config(name='associations.html', context=IAssociationTarget, layer=IPyAMSLayer, |
253 @pagelet_config(name='associations.html', context=IAssociationTarget, layer=IPyAMSLayer, |
299 permission=VIEW_SYSTEM_PERMISSION) |
254 permission=VIEW_SYSTEM_PERMISSION) |
300 @implementer(IAssociationsView) |
255 @implementer(IAssociationsView) |