# HG changeset patch # User tflorac@xsup98-004.onf.fr # Date 1507839919 -7200 # Node ID d82d8670735e6400a3b4b03a61f8abf127bc8689 # Parent 4d90e2502e5d4f6ca06f3a66bf82a76e9ecf9bcd Added custom view for association deletion diff -r 4d90e2502e5d -r d82d8670735e src/pyams_content/component/association/zmi/__init__.py --- a/src/pyams_content/component/association/zmi/__init__.py Thu Oct 12 22:24:23 2017 +0200 +++ b/src/pyams_content/component/association/zmi/__init__.py Thu Oct 12 22:25:19 2017 +0200 @@ -22,7 +22,7 @@ from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION from pyams_form.interfaces.form import IInnerSubForm from pyams_skin.layer import IPyAMSLayer -from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION +from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_PERMISSION from pyams_zmi.interfaces.menu import IPropertiesMenu from z3c.table.interfaces import IValues, IColumn @@ -63,7 +63,7 @@ 'message': self.request.localizer.translate(_("Association was correctly added.")), 'events': [{ 'event': 'PyAMS_content.changed_item', - 'options': {'object_type': 'associations', + 'options': {'handler': 'PyAMS_content.associations.refreshAssociations', 'object_name': associations_table.id, 'table': associations_table.render()} }]} @@ -80,7 +80,7 @@ 'message': self.request.localizer.translate(self.successMessage), 'events': [{ 'event': 'PyAMS_content.changed_item', - 'options': {'object_type': 'associations', + 'options': {'handler': 'PyAMS_content.associations.refreshAssociations', 'object_name': associations_table.id, 'table': associations_table.render()} }]} @@ -128,6 +128,7 @@ 'data-ams-location': absolute_url(IAssociationContainer(self.context), self.request), 'data-ams-tablednd-drag-handle': 'td.sorter', 'data-ams-tablednd-drop-target': 'set-associations-order.json'} + attributes.setdefault('tr', {}).setdefault('data-ams-delete-target', 'delete-association.json'); return attributes @reify @@ -263,6 +264,39 @@ """Associations table trash column""" +@view_config(name='delete-association.json', context=IAssociationContainer, request_type=IPyAMSLayer, + permission=MANAGE_PERMISSION, renderer='json', xhr=True) +def delete_association(request): + """Delete association""" + + from pyams_content.component.paragraph.zmi.container \ + import ParagraphContainerTable, ParagraphTitleToolbarViewletManager + + translate = request.localizer.translate + name = request.params.get('object_name') + if not name: + return {'status': 'message', + 'messagebox': {'status': 'error', + 'content': translate(_("No provided object_name argument!"))}} + if name not in request.context: + return {'status': 'message', + 'messagebox': {'status': 'error', + 'content': translate(_("Given association name doesn't exist!"))}} + del request.context[name] + parent = get_parent(request.context, IAssociationTarget) + table = ParagraphContainerTable(parent, request) + viewlet = ParagraphTitleToolbarViewletManager(parent, request, table) + viewlet.update() + return {'status': 'success', + 'handle_json': True, + 'events': [{ + 'event': 'PyAMS_content.changed_item', + 'options': {'handler': 'PyAMS_content.paragraphs.updateToolbar', + 'object_name': parent.__name__, + 'toolbar_tag': viewlet.render()} + }]} + + @pagelet_config(name='associations.html', context=IAssociationTarget, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) @implementer(IAssociationsView)