|
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.interfaces import MANAGE_SITE_ROOT_PERMISSION |
|
20 from pyams_content.reference.interfaces import IReferenceTable |
|
21 from pyams_i18n.interfaces import II18n |
|
22 from pyams_skin.interfaces import IInnerPage, IPageHeader |
|
23 from pyams_skin.interfaces.viewlet import IBreadcrumbItem |
|
24 from pyams_skin.layer import IPyAMSLayer |
|
25 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
|
26 from pyams_zmi.interfaces.menu import ISiteManagementMenu, IPropertiesMenu |
|
27 from pyams_zmi.layer import IAdminLayer |
|
28 from z3c.table.interfaces import IValues, IColumn |
|
29 |
|
30 # import packages |
|
31 from pyams_form.form import AJAXEditForm |
|
32 from pyams_pagelet.pagelet import pagelet_config |
|
33 from pyams_skin.container import ContainerView |
|
34 from pyams_skin.page import DefaultPageHeaderAdapter |
|
35 from pyams_skin.table import BaseTable, TrashColumn |
|
36 from pyams_skin.viewlet.breadcrumb import BreadcrumbItem |
|
37 from pyams_skin.viewlet.menu import MenuItem |
|
38 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
|
39 from pyams_utils.url import absolute_url |
|
40 from pyams_viewlet.manager import viewletmanager_config |
|
41 from pyams_viewlet.viewlet import viewlet_config |
|
42 from pyams_zmi.form import AdminDialogEditForm |
|
43 from pyams_zmi.view import AdminView |
|
44 from pyramid.view import view_config |
|
45 from z3c.form import field |
|
46 from zope.interface import implementer |
|
47 |
|
48 from pyams_content import _ |
|
49 |
|
50 |
|
51 # |
|
52 # Table properties |
|
53 # |
|
54 |
|
55 @adapter_config(context=(IReferenceTable, IPyAMSLayer), provides=IBreadcrumbItem) |
|
56 class ReferenceTableBreadcrumbAdapter(BreadcrumbItem): |
|
57 """References table breadcrumb adapter""" |
|
58 |
|
59 @property |
|
60 def label(self): |
|
61 return II18n(self.context).query_attribute('short_name', request=self.request) |
|
62 |
|
63 css_class = 'strong' |
|
64 |
|
65 |
|
66 @viewlet_config(name='contents.menu', context=IReferenceTable, layer=IAdminLayer, |
|
67 manager=ISiteManagementMenu, permission=VIEW_SYSTEM_PERMISSION, weight=1) |
|
68 @viewletmanager_config(name='contents.menu', layer=IAdminLayer, provides=IPropertiesMenu) |
|
69 @implementer(IPropertiesMenu) |
|
70 class ReferenceTableContentsMenu(MenuItem): |
|
71 """References table contents menu""" |
|
72 |
|
73 label = _("Contents") |
|
74 icon_class = 'fa-table' |
|
75 url = '#contents.html' |
|
76 |
|
77 |
|
78 class ReferenceTableContentsTable(BaseTable): |
|
79 """References table contents table""" |
|
80 |
|
81 title = _("Table contents") |
|
82 |
|
83 @property |
|
84 def data_attributes(self): |
|
85 attributes = super(ReferenceTableContentsTable, self).data_attributes |
|
86 table_attrs = {'data-ams-location': absolute_url(self.context, self.request)} |
|
87 if 'table' in attributes: |
|
88 attributes['table'].update(table_attrs) |
|
89 else: |
|
90 attributes['table'] = table_attrs |
|
91 return attributes |
|
92 |
|
93 |
|
94 @adapter_config(context=(IReferenceTable, IPyAMSLayer, ReferenceTableContentsTable), provides=IValues) |
|
95 class ReferenceTableContentsValues(ContextRequestViewAdapter): |
|
96 """Reference table contents values""" |
|
97 |
|
98 @property |
|
99 def values(self): |
|
100 return self.context.values() |
|
101 |
|
102 |
|
103 @adapter_config(context=(IReferenceTable, IPyAMSLayer, ReferenceTableContentsTable), provides=IColumn) |
|
104 class ReferenceTableTrashColumn(TrashColumn): |
|
105 """Reference table trash column""" |
|
106 |
|
107 permission = MANAGE_SITE_ROOT_PERMISSION |
|
108 |
|
109 |
|
110 @pagelet_config(name='contents.html', context=IReferenceTable, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
|
111 @implementer(IInnerPage) |
|
112 class ReferenceTableContentsView(AdminView, ContainerView): |
|
113 """Reference table contents view""" |
|
114 |
|
115 table_class = ReferenceTableContentsTable |
|
116 |
|
117 |
|
118 @adapter_config(context=(IReferenceTable, IAdminLayer, ReferenceTableContentsView), provides=IPageHeader) |
|
119 class ReferenceTableHeaderAdapter(DefaultPageHeaderAdapter): |
|
120 """References table header adapter""" |
|
121 |
|
122 title = _("References tables") |
|
123 |
|
124 @property |
|
125 def subtitle(self): |
|
126 return II18n(self.context).query_attribute('title', request=self.request) |
|
127 |
|
128 icon_class = 'fa fa-fw fa-table' |
|
129 |
|
130 |
|
131 @viewlet_config(name='properties.menu', context=IReferenceTable, layer=IAdminLayer, |
|
132 manager=IPropertiesMenu, permission=VIEW_SYSTEM_PERMISSION, weight=20) |
|
133 class ReferenceTablePropertiesMenu(MenuItem): |
|
134 """Reference table properties menu""" |
|
135 |
|
136 label = _("Properties...") |
|
137 icon_class = 'fa-edit' |
|
138 |
|
139 url = 'properties.html' |
|
140 modal_target = True |
|
141 |
|
142 |
|
143 @pagelet_config(name='properties.html', context=IReferenceTable, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
|
144 class ReferenceTablePropertiesEditForm(AdminDialogEditForm): |
|
145 """Reference table properties edit form""" |
|
146 |
|
147 legend = _("Edit table properties") |
|
148 |
|
149 fields = field.Fields(IReferenceTable).omit('__parent__', '__name__') |
|
150 ajax_handler = 'properties.json' |
|
151 edit_permission = MANAGE_SITE_ROOT_PERMISSION |
|
152 |
|
153 |
|
154 @view_config(name='properties.json', context=IReferenceTable, request_type=IPyAMSLayer, |
|
155 permission=MANAGE_SITE_ROOT_PERMISSION, renderer='json', xhr=True) |
|
156 class ReferenceTablePropertiesAJAXEditForm(AJAXEditForm, ReferenceTablePropertiesEditForm): |
|
157 """Reference table properties edit form, JSON renderer""" |