8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
12 |
12 |
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 from uuid import uuid4 |
13 from uuid import uuid4 |
18 |
14 |
19 # import interfaces |
|
20 from pyams_content.interfaces import MANAGE_SITE_ROOT_PERMISSION, IBaseContent |
|
21 from pyams_content.reference.pictograms.interfaces import IPictogramTable, IPictogram |
|
22 from pyams_content.reference.zmi.table import ReferenceTableContentsTable, ReferenceTableContentsView |
|
23 from pyams_i18n.interfaces import II18n |
|
24 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager |
|
25 from pyams_skin.layer import IPyAMSLayer |
|
26 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
|
27 from pyams_zmi.layer import IAdminLayer |
|
28 from z3c.table.interfaces import IColumn |
|
29 |
|
30 # import packages |
|
31 from pyams_content.reference.pictograms import Pictogram |
|
32 from pyams_file.zmi.image import render_image |
|
33 from pyams_form.form import AJAXAddForm, ajax_config |
|
34 from pyams_i18n.column import I18nAttrColumn |
|
35 from pyams_pagelet.pagelet import pagelet_config |
|
36 from pyams_skin.event import get_json_table_row_refresh_event |
|
37 from pyams_skin.table import I18nColumn |
|
38 from pyams_skin.viewlet.toolbar import ToolbarAction |
|
39 from pyams_utils.adapter import adapter_config |
|
40 from pyams_utils.traversing import get_parent |
|
41 from pyams_viewlet.viewlet import viewlet_config |
|
42 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm |
|
43 from pyramid.httpexceptions import HTTPNotFound |
15 from pyramid.httpexceptions import HTTPNotFound |
44 from pyramid.renderers import render, render_to_response |
16 from pyramid.renderers import render, render_to_response |
45 from pyramid.response import Response |
17 from pyramid.response import Response |
46 from pyramid.view import view_config |
18 from pyramid.view import view_config |
47 from z3c.form import field |
19 from z3c.form import field |
48 from z3c.table.column import GetAttrColumn |
20 from z3c.table.column import GetAttrColumn |
|
21 from z3c.table.interfaces import IColumn |
|
22 |
|
23 from pyams_content.interfaces import IBaseContent, MANAGE_SITE_ROOT_PERMISSION |
|
24 from pyams_content.reference.pictograms import Pictogram |
|
25 from pyams_content.reference.pictograms.interfaces import IPictogram, IPictogramTable |
|
26 from pyams_content.reference.zmi.table import ReferenceTableContentsTable, \ |
|
27 ReferenceTableContentsView |
|
28 from pyams_file.image import render_image |
|
29 from pyams_form.form import AJAXAddForm, ajax_config |
|
30 from pyams_i18n.column import I18nAttrColumn |
|
31 from pyams_i18n.interfaces import II18n |
|
32 from pyams_pagelet.pagelet import pagelet_config |
|
33 from pyams_skin.event import get_json_table_row_refresh_event |
|
34 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager |
|
35 from pyams_skin.layer import IPyAMSLayer |
|
36 from pyams_skin.table import I18nColumn |
|
37 from pyams_skin.viewlet.toolbar import ToolbarAction |
|
38 from pyams_utils.adapter import adapter_config |
|
39 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
|
40 from pyams_utils.traversing import get_parent |
|
41 from pyams_viewlet.viewlet import viewlet_config |
|
42 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm |
|
43 from pyams_zmi.layer import IAdminLayer |
|
44 |
|
45 |
|
46 __docformat__ = 'restructuredtext' |
|
47 |
49 |
48 |
50 from pyams_content import _ |
49 from pyams_content import _ |
51 |
50 |
52 |
51 |
53 @viewlet_config(name='add-pictogram.action', context=IPictogramTable, layer=IPyAMSLayer, |
52 @viewlet_config(name='add-pictogram.action', context=IPictogramTable, layer=IPyAMSLayer, |
62 modal_target = True |
61 modal_target = True |
63 |
62 |
64 |
63 |
65 @pagelet_config(name='add-pictogram.html', context=IPictogramTable, layer=IPyAMSLayer, |
64 @pagelet_config(name='add-pictogram.html', context=IPictogramTable, layer=IPyAMSLayer, |
66 permission=MANAGE_SITE_ROOT_PERMISSION) |
65 permission=MANAGE_SITE_ROOT_PERMISSION) |
67 @ajax_config(name='add-pictogram.json', context=IPictogramTable, layer=IPyAMSLayer, base=AJAXAddForm) |
66 @ajax_config(name='add-pictogram.json', context=IPictogramTable, layer=IPyAMSLayer, |
|
67 base=AJAXAddForm) |
68 class PictogramAddForm(AdminDialogAddForm): |
68 class PictogramAddForm(AdminDialogAddForm): |
69 """Pictogram add form""" |
69 """Pictogram add form""" |
70 |
70 |
71 legend = _("Add new pictogram") |
71 legend = _("Add new pictogram") |
72 dialog_class = 'modal-large' |
72 dialog_class = 'modal-large' |
83 |
83 |
84 def nextURL(self): |
84 def nextURL(self): |
85 return 'contents.html' |
85 return 'contents.html' |
86 |
86 |
87 |
87 |
88 @pagelet_config(name='properties.html', context=IPictogram, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
88 @pagelet_config(name='properties.html', context=IPictogram, layer=IPyAMSLayer, |
|
89 permission=VIEW_SYSTEM_PERMISSION) |
89 @ajax_config(name='properties.json', context=IPictogram, layer=IPyAMSLayer) |
90 @ajax_config(name='properties.json', context=IPictogram, layer=IPyAMSLayer) |
90 class PictogramEditForm(AdminDialogEditForm): |
91 class PictogramEditForm(AdminDialogEditForm): |
91 """Pictogram properties edit form""" |
92 """Pictogram properties edit form""" |
92 |
93 |
93 prefix = 'pictogram_properties.' |
94 prefix = 'pictogram_properties.' |
102 output = super(self.__class__, self).get_ajax_output(changes) |
103 output = super(self.__class__, self).get_ajax_output(changes) |
103 if ('image' in changes.get(IPictogram, ())) or \ |
104 if ('image' in changes.get(IPictogram, ())) or \ |
104 ('title' in changes.get(IBaseContent, ())): |
105 ('title' in changes.get(IBaseContent, ())): |
105 parent = get_parent(self.context, IPictogramTable) |
106 parent = get_parent(self.context, IPictogramTable) |
106 output.setdefault('events', []).append( |
107 output.setdefault('events', []).append( |
107 get_json_table_row_refresh_event(parent, self.request, PictogramTableContentsTable, self.context)) |
108 get_json_table_row_refresh_event(parent, self.request, |
|
109 PictogramTableContentsTable, self.context)) |
108 return output |
110 return output |
109 |
111 |
110 |
112 |
111 # |
113 # |
112 # Pictogram table |
114 # Pictogram table |
141 if image: |
145 if image: |
142 return render_image(image, 32, 32, self.request, timestamp=True) |
146 return render_image(image, 32, 32, self.request, timestamp=True) |
143 return '--' |
147 return '--' |
144 |
148 |
145 |
149 |
146 @adapter_config(name='name', context=(IPictogramTable, IAdminLayer, PictogramTableContentsTable), provides=IColumn) |
150 @adapter_config(name='name', |
|
151 context=(IPictogramTable, IAdminLayer, PictogramTableContentsTable), |
|
152 provides=IColumn) |
147 class PictogramTableNameColumn(I18nColumn, I18nAttrColumn): |
153 class PictogramTableNameColumn(I18nColumn, I18nAttrColumn): |
148 """Pictogram table name column""" |
154 """Pictogram table name column""" |
149 |
155 |
150 _header = _("Title") |
156 _header = _("Title") |
151 weight = 10 |
157 weight = 10 |
152 attrName = 'title' |
158 attrName = 'title' |
153 |
159 |
154 |
160 |
155 @pagelet_config(name='contents.html', context=IPictogramTable, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) |
161 @pagelet_config(name='contents.html', context=IPictogramTable, layer=IPyAMSLayer, |
|
162 permission=VIEW_SYSTEM_PERMISSION) |
156 class PictogramTableContentsView(ReferenceTableContentsView): |
163 class PictogramTableContentsView(ReferenceTableContentsView): |
157 """Pictograms table contents view""" |
164 """Pictograms table contents view""" |
158 |
165 |
159 table_class = PictogramTableContentsTable |
166 table_class = PictogramTableContentsTable |
160 |
167 |