7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
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 |
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 from pyams_content.shared.common import IWfSharedContent |
|
13 from pyams_form.interfaces.form import IFormContextPermissionChecker |
12 |
14 |
13 __docformat__ = 'restructuredtext' |
15 __docformat__ = 'restructuredtext' |
14 |
16 |
15 |
17 |
16 # import standard library |
18 # import standard library |
17 |
19 |
18 # import interfaces |
20 # import interfaces |
19 from pyams_content.component.gallery.interfaces import IGallery, IGalleryFile, IGalleryTarget |
21 from pyams_content.component.gallery.interfaces import IGallery, IGalleryFile |
20 from pyams_content.component.gallery.zmi.interfaces import IGalleryImageAddFields, IGalleryImagesView |
22 from pyams_content.component.gallery.zmi.interfaces import IGalleryImageAddFields, IGalleryImagesView |
21 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION |
23 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION |
22 from pyams_file.interfaces.archive import IArchiveExtractor |
24 from pyams_file.interfaces.archive import IArchiveExtractor |
23 from pyams_i18n.interfaces import II18n |
25 from pyams_i18n.interfaces import II18n |
24 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager, IContextActions |
26 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager, IContextActions |
25 from pyams_skin.layer import IPyAMSLayer |
27 from pyams_skin.layer import IPyAMSLayer |
26 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, VIEW_PERMISSION |
28 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, FORBIDDEN_PERMISSION |
27 from z3c.form.interfaces import NOT_CHANGED |
29 from z3c.form.interfaces import NOT_CHANGED |
28 from zope.schema.interfaces import WrongType |
30 from zope.schema.interfaces import WrongType |
29 |
31 |
30 # import packages |
32 # import packages |
31 from pyams_content.component.gallery.file import GalleryFile |
33 from pyams_content.component.gallery.file import GalleryFile |
128 'target': '#gallery_images_{0}'.format(self.context.__name__)} |
130 'target': '#gallery_images_{0}'.format(self.context.__name__)} |
129 |
131 |
130 |
132 |
131 @viewlet_config(name='file.showhide.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView, |
133 @viewlet_config(name='file.showhide.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView, |
132 manager=IContextActions, permission=VIEW_SYSTEM_PERMISSION, weight=1) |
134 manager=IContextActions, permission=VIEW_SYSTEM_PERMISSION, weight=1) |
133 class GalleryFileShowAddAction(JsToolbarActionItem): |
135 class GalleryFileShowHideAction(WfSharedContentPermissionMixin, JsToolbarActionItem): |
134 """Gallery file show/hide action""" |
136 """Gallery file show/hide action""" |
135 |
137 |
136 label = _("Show/hide image") |
138 edit_permission = FORBIDDEN_PERMISSION |
|
139 |
|
140 def __init__(self, context, request, view, manager): |
|
141 super(GalleryFileShowHideAction, self).__init__(context, request, view, manager) |
|
142 content = get_parent(context, IWfSharedContent) |
|
143 if content is not None: |
|
144 self.edit_permission = IFormContextPermissionChecker(content).edit_permission |
|
145 |
|
146 @property |
|
147 def label(self): |
|
148 if self.request.has_permission(self.edit_permission, context=self.context): |
|
149 return _("Show/hide image") |
|
150 else: |
|
151 return '' |
137 |
152 |
138 @property |
153 @property |
139 def label_css_class(self): |
154 def label_css_class(self): |
140 if self.context.visible: |
155 if self.context.visible: |
141 return 'fa fa-fw fa-eye' |
156 return 'fa fa-fw fa-eye' |
143 return 'fa fa-fw fa-eye-slash text-danger' |
158 return 'fa fa-fw fa-eye-slash text-danger' |
144 |
159 |
145 hint_gravity = 'nw' |
160 hint_gravity = 'nw' |
146 |
161 |
147 url = 'PyAMS_content.galleries.switchImageVisibility' |
162 url = 'PyAMS_content.galleries.switchImageVisibility' |
|
163 |
|
164 def get_url(self): |
|
165 if self.request.has_permission(self.edit_permission, context=self.context): |
|
166 return self.url |
148 |
167 |
149 |
168 |
150 @viewlet_config(name='file.properties.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView, |
169 @viewlet_config(name='file.properties.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView, |
151 manager=IContextActions, permission=VIEW_SYSTEM_PERMISSION, weight=5) |
170 manager=IContextActions, permission=VIEW_SYSTEM_PERMISSION, weight=5) |
152 class GalleryFilePropertiesAction(FilePropertiesAction): |
171 class GalleryFilePropertiesAction(FilePropertiesAction): |
210 } |
229 } |
211 }) |
230 }) |
212 return output |
231 return output |
213 |
232 |
214 |
233 |
215 @viewlet_config(name='gallery-file-download.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView, |
|
216 manager=IContextActions, permission=VIEW_PERMISSION, weight=89) |
|
217 class GalleryFileDownloaderAction(JsToolbarActionItem): |
|
218 """Gallery file downloader action""" |
|
219 |
|
220 label = _("Download image...") |
|
221 label_css_class = 'fa fa-fw fa-download' |
|
222 hint_gravity = 'nw' |
|
223 |
|
224 @property |
|
225 def url(self): |
|
226 return absolute_url(self.context.data, self.request, query={'download': '1'}) |
|
227 |
|
228 |
|
229 @viewlet_config(name='gallery-file-remover.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView, |
234 @viewlet_config(name='gallery-file-remover.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView, |
230 manager=IContextActions, weight=90) |
235 manager=IContextActions, weight=90) |
231 class GalleryFileRemoverAction(WfSharedContentPermissionMixin, JsToolbarActionItem): |
236 class GalleryFileRemoverAction(WfSharedContentPermissionMixin, JsToolbarActionItem): |
232 """Gallery file remover action""" |
237 """Gallery file remover action""" |
233 |
238 |