--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_file/zmi/file.py Thu Feb 19 10:56:21 2015 +0100
@@ -0,0 +1,79 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_file.interfaces import IFile, IFileInfo
+from pyams_skin.interfaces.viewlet import IContextActions
+from pyams_skin.layer import IPyAMSLayer
+
+# import packages
+from pyams_form.form import AJAXEditForm
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.viewlet.toolbar import ToolbarMenuItem
+from pyams_viewlet.viewlet import viewlet_config
+from pyams_zmi.form import AdminDialogEditForm
+from pyramid.view import view_config
+from z3c.form import field
+from zope.interface import Interface
+
+from pyams_file import _
+
+
+@viewlet_config(name='file.properties.action', context=IFile, layer=IPyAMSLayer, view=Interface,
+ manager=IContextActions, permission='view', weight=1)
+class FileRenameAction(ToolbarMenuItem):
+ """File rename action"""
+
+ label = _("Properties...")
+ label_css_class = 'fa fa-fw fa-edit'
+
+ url = 'properties.html'
+ modal_target = True
+
+
+@pagelet_config(name='properties.html', context=IFile, layer=IPyAMSLayer, permission='view')
+class FilePropertiesEditForm(AdminDialogEditForm):
+ """File properties edit form"""
+
+ legend = _("Update file properties")
+ icon_css_class = 'fa fa-fw fa-edit'
+
+ fields = field.Fields(IFileInfo)
+ ajax_handler = 'properties.json'
+
+ @property
+ def title(self):
+ return self.context.title or self.context.filename
+
+ def updateWidgets(self, prefix=None):
+ super(FilePropertiesEditForm, self).updateWidgets()
+ self.widgets['description'].label_css_class = 'textarea'
+
+
+@view_config(name='properties.json', context=IFile, request_type=IPyAMSLayer,
+ permission='manage', renderer='json', xhr=True)
+class FilePropertiesAJAXEditForm(AJAXEditForm, FilePropertiesEditForm):
+ """File properties edit form, AJAX renderer"""
+
+ def get_ajax_output(self, changes):
+ info_changes = changes.get(IFileInfo, ())
+ if ('title' in info_changes) or ('filename' in info_changes):
+ return {'status': 'reload',
+ 'smallbox': self.request.localizer.translate(self.successMessage),
+ 'smallbox_status': 'success'}
+ else:
+ return super(FilePropertiesAJAXEditForm, self).get_ajax_output(changes)