src/pyams_portal/zmi/portlet.py
changeset 0 6f99128c6d48
child 5 670b7956c689
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_portal/zmi/portlet.py	Wed Jun 17 09:58:33 2015 +0200
@@ -0,0 +1,63 @@
+#
+# 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_portal.interfaces import IPortlet
+from z3c.form.interfaces import HIDDEN_MODE
+
+# import packages
+from pyams_zmi.form import AdminDialogEditForm
+from pyramid.url import resource_url
+from z3c.form import field
+
+from pyams_portal import _
+
+
+class PortletConfigurationEditor(AdminDialogEditForm):
+    """Base portlet configuration editor"""
+
+    @property
+    def title(self):
+        translate = self.request.localizer.translate
+        registry = self.request.registry
+        portlet = registry.queryUtility(IPortlet, name=self.context.portlet_name)
+        return translate(_("« {0} »  portal template - {1}")).format(self.context.__parent__.name,
+                                                                     translate(portlet.label))
+
+    legend = _("Edit portlet configuration")
+    dialog_class = 'modal-large'
+
+    interface = None
+    edit_permission = 'portal.templates.manage'
+
+    def get_form_action(self):
+        return resource_url(self.context.__parent__, self.request, self.request.view_name)
+
+    def get_ajax_handler(self):
+        return resource_url(self.context.__parent__, self.request, self.ajax_handler)
+
+    @property
+    def fields(self):
+        fields = field.Fields(self.interface)
+        if not self.getContent().can_inherit:
+            fields = fields.omit('inherit_parent')
+        return fields
+
+    def updateWidgets(self, prefix=None):
+        super(PortletConfigurationEditor, self).updateWidgets(prefix)
+        self.widgets['slot_name'].mode = HIDDEN_MODE
+        self.widgets['position'].mode = HIDDEN_MODE