19 # import interfaces |
19 # import interfaces |
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.interfaces import IInnerPage |
|
25 from pyams_skin.layer import IPyAMSLayer |
24 from pyams_skin.layer import IPyAMSLayer |
26 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
25 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
27 from pyams_zmi.interfaces.menu import IPropertiesMenu |
26 from pyams_zmi.interfaces.menu import IPropertiesMenu |
28 from z3c.table.interfaces import IValues, IColumn |
27 from z3c.table.interfaces import IValues, IColumn |
29 |
28 |
37 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
36 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
38 from pyams_utils.traversing import get_parent |
37 from pyams_utils.traversing import get_parent |
39 from pyams_utils.url import absolute_url |
38 from pyams_utils.url import absolute_url |
40 from pyams_viewlet.viewlet import viewlet_config |
39 from pyams_viewlet.viewlet import viewlet_config |
41 from pyams_zmi.form import InnerAdminDisplayForm |
40 from pyams_zmi.form import InnerAdminDisplayForm |
42 from pyams_zmi.view import AdminView |
41 from pyams_zmi.view import ContainerAdminView |
43 from pyramid.decorator import reify |
42 from pyramid.decorator import reify |
44 from pyramid.exceptions import NotFound |
43 from pyramid.exceptions import NotFound |
45 from pyramid.view import view_config |
44 from pyramid.view import view_config |
46 from z3c.form import field |
45 from z3c.form import field |
47 from z3c.table.column import GetAttrColumn |
46 from z3c.table.column import GetAttrColumn |
56 |
55 |
57 class AssociationItemAJAXAddForm(AJAXAddForm): |
56 class AssociationItemAJAXAddForm(AJAXAddForm): |
58 """Association item add form, JSON renderer""" |
57 """Association item add form, JSON renderer""" |
59 |
58 |
60 def get_ajax_output(self, changes): |
59 def get_ajax_output(self, changes): |
61 associations_table = AssociationsTable(self.context, self.request, None) |
60 associations_table = AssociationsTable(self.context, self.request) |
62 associations_table.update() |
61 associations_table.update() |
63 return {'status': 'success', |
62 return {'status': 'success', |
64 'message': self.request.localizer.translate(_("Association was correctly added.")), |
63 'message': self.request.localizer.translate(_("Association was correctly added.")), |
65 'callback': 'PyAMS_content.associations.afterUpdateCallback', |
64 'callback': 'PyAMS_content.associations.afterUpdateCallback', |
66 'options': {'parent': associations_table.id, |
65 'options': {'parent': associations_table.id, |
70 class AssociationItemAJAXEditForm(AJAXEditForm): |
69 class AssociationItemAJAXEditForm(AJAXEditForm): |
71 """Association item properties edit form, JSON renderer""" |
70 """Association item properties edit form, JSON renderer""" |
72 |
71 |
73 def get_associations_table(self): |
72 def get_associations_table(self): |
74 target = get_parent(self.context, IAssociationTarget) |
73 target = get_parent(self.context, IAssociationTarget) |
75 associations_table = AssociationsTable(target, self.request, None) |
74 associations_table = AssociationsTable(target, self.request) |
76 associations_table.update() |
75 associations_table.update() |
77 return {'status': 'success', |
76 return {'status': 'success', |
78 'message': self.request.localizer.translate(self.successMessage), |
77 'message': self.request.localizer.translate(self.successMessage), |
79 'callback': 'PyAMS_content.associations.afterUpdateCallback', |
78 'callback': 'PyAMS_content.associations.afterUpdateCallback', |
80 'options': {'parent': associations_table.id, |
79 'options': {'parent': associations_table.id, |
93 label = _("Associations...") |
92 label = _("Associations...") |
94 icon_class = 'fa-link' |
93 icon_class = 'fa-link' |
95 url = '#associations.html' |
94 url = '#associations.html' |
96 |
95 |
97 |
96 |
98 @pagelet_config(name='associations.html', context=IAssociationTarget, layer=IPyAMSLayer, |
|
99 permission=VIEW_SYSTEM_PERMISSION) |
|
100 @template_config(template='templates/associations-view.pt', layer=IPyAMSLayer) |
|
101 @implementer(IInnerPage, IAssociationsView) |
|
102 class AssociationsContainerView(AdminView, Pagelet): |
|
103 """Associations container view""" |
|
104 |
|
105 title = _("Associations list") |
|
106 |
|
107 def __init__(self, context, request): |
|
108 super(AssociationsContainerView, self).__init__(context, request) |
|
109 self.table = AssociationsTable(context, request, self) |
|
110 |
|
111 def update(self): |
|
112 super(AssociationsContainerView, self).update() |
|
113 self.table.update() |
|
114 |
|
115 |
|
116 @adapter_config(name='associations', context=(IAssociationTarget, IPyAMSLayer, IAssociationsParentForm), |
|
117 provides=IInnerSubForm) |
|
118 @template_config(template='templates/associations.pt', layer=IPyAMSLayer) |
|
119 @implementer(IAssociationsView) |
|
120 class AssociationsView(InnerAdminDisplayForm): |
|
121 """Associations view""" |
|
122 |
|
123 fields = field.Fields(Interface) |
|
124 weight = 90 |
|
125 |
|
126 def __init__(self, context, request, view): |
|
127 super(AssociationsView, self).__init__(context, request, view) |
|
128 self.table = AssociationsTable(context, request, self) |
|
129 |
|
130 def update(self): |
|
131 super(AssociationsView, self).update() |
|
132 self.table.update() |
|
133 |
|
134 |
|
135 class AssociationsTable(ProtectedFormObjectMixin, BaseTable): |
97 class AssociationsTable(ProtectedFormObjectMixin, BaseTable): |
136 """Associations view inner table""" |
98 """Associations view inner table""" |
137 |
99 |
138 @property |
100 @property |
139 def id(self): |
101 def id(self): |
140 return 'associations_{0}_list'.format(self.context.__name__) |
102 return 'associations_{0}_list'.format(self.context.__name__) |
141 |
103 |
142 hide_header = True |
104 hide_header = True |
143 sortOn = None |
105 sortOn = None |
144 |
|
145 def __init__(self, context, request, view): |
|
146 super(AssociationsTable, self).__init__(context, request) |
|
147 self.view = view |
|
148 |
106 |
149 @property |
107 @property |
150 def cssClasses(self): |
108 def cssClasses(self): |
151 classes = ['table', 'table-bordered', 'table-striped', 'table-hover', 'table-tight'] |
109 classes = ['table', 'table-bordered', 'table-striped', 'table-hover', 'table-tight'] |
152 permission = self.permission |
110 permission = self.permission |
295 |
253 |
296 |
254 |
297 @adapter_config(name='trash', context=(IAssociationTarget, IPyAMSLayer, AssociationsTable), provides=IColumn) |
255 @adapter_config(name='trash', context=(IAssociationTarget, IPyAMSLayer, AssociationsTable), provides=IColumn) |
298 class AssociationsTableTrashColumn(ProtectedFormObjectMixin, TrashColumn): |
256 class AssociationsTableTrashColumn(ProtectedFormObjectMixin, TrashColumn): |
299 """Associations table trash column""" |
257 """Associations table trash column""" |
|
258 |
|
259 |
|
260 @pagelet_config(name='associations.html', context=IAssociationTarget, layer=IPyAMSLayer, |
|
261 permission=VIEW_SYSTEM_PERMISSION) |
|
262 @implementer(IAssociationsView) |
|
263 class AssociationsContainerView(ContainerAdminView, Pagelet): |
|
264 """Associations container view""" |
|
265 |
|
266 title = _("Associations list") |
|
267 table_class = AssociationsTable |
|
268 |
|
269 |
|
270 @adapter_config(name='associations', context=(IAssociationTarget, IPyAMSLayer, IAssociationsParentForm), |
|
271 provides=IInnerSubForm) |
|
272 @template_config(template='templates/associations.pt', layer=IPyAMSLayer) |
|
273 @implementer(IAssociationsView) |
|
274 class AssociationsView(InnerAdminDisplayForm): |
|
275 """Associations view""" |
|
276 |
|
277 fields = field.Fields(Interface) |
|
278 weight = 90 |
|
279 |
|
280 def __init__(self, context, request, view): |
|
281 super(AssociationsView, self).__init__(context, request, view) |
|
282 self.table = AssociationsTable(context, request) |
|
283 self.table.view = self |
|
284 |
|
285 def update(self): |
|
286 super(AssociationsView, self).update() |
|
287 self.table.update() |