14 |
14 |
15 |
15 |
16 # import standard library |
16 # import standard library |
17 |
17 |
18 # import interfaces |
18 # import interfaces |
19 from pyams_portal.interfaces import IPortlet |
19 from pyams_form.interfaces.form import IInnerTabForm |
20 from z3c.form.interfaces import HIDDEN_MODE |
20 from pyams_portal.interfaces import IPortlet, IPortalTemplate, IPortalPage, IPortalContext, MANAGE_TEMPLATE_PERMISSION |
|
21 from pyams_skin.layer import IPyAMSLayer |
21 |
22 |
22 # import packages |
23 # import packages |
23 from pyams_zmi.form import AdminDialogEditForm |
24 from pyams_template.template import template_config |
24 from pyramid.url import resource_url |
25 from pyams_utils.adapter import adapter_config |
|
26 from pyams_utils.url import absolute_url |
|
27 from pyams_zmi.form import AdminDialogEditForm, InnerAdminEditForm |
|
28 from pyramid.decorator import reify |
25 from z3c.form import field |
29 from z3c.form import field |
|
30 from zope.interface import Interface |
26 |
31 |
27 from pyams_portal import _ |
32 from pyams_portal import _ |
28 |
33 |
29 |
34 |
30 class PortletConfigurationEditor(AdminDialogEditForm): |
35 @template_config(template='templates/portlet.pt', layer=IPyAMSLayer) |
31 """Base portlet configuration editor""" |
36 class PortletSettingsEditor(AdminDialogEditForm): |
|
37 """Portlet settings edit form""" |
32 |
38 |
33 @property |
39 @property |
34 def title(self): |
40 def title(self): |
35 translate = self.request.localizer.translate |
41 translate = self.request.localizer.translate |
36 registry = self.request.registry |
42 parent = self.configuration.__parent__ |
37 portlet = registry.queryUtility(IPortlet, name=self.context.portlet_name) |
43 if not IPortalTemplate.providedBy(parent): |
38 return translate(_("« {0} » portal template - {1}")).format(self.context.__parent__.name, |
44 parent = IPortalPage(parent).template |
39 translate(portlet.label)) |
45 return translate(_("« {0} » portal template - {1}")).format(parent.name, |
|
46 translate(self.portlet.label)) |
40 |
47 |
41 legend = _("Edit portlet configuration") |
48 legend = _("Edit portlet settings") |
42 dialog_class = 'modal-large' |
49 dialog_class = 'modal-large' |
43 |
50 |
44 interface = None |
51 settings = None |
45 edit_permission = 'portal.templates.manage' |
52 fields = field.Fields(Interface) |
|
53 edit_permission = MANAGE_TEMPLATE_PERMISSION |
|
54 |
|
55 @reify |
|
56 def configuration(self): |
|
57 return self.context.configuration |
|
58 |
|
59 @property |
|
60 def override_label(self): |
|
61 translate = self.request.localizer.translate |
|
62 if IPortalContext.providedBy(self.configuration.__parent__.__parent__): |
|
63 return translate(_("Override parent settings")) |
|
64 else: |
|
65 return translate(_("Override template settings")) |
46 |
66 |
47 def get_form_action(self): |
67 def get_form_action(self): |
48 return resource_url(self.context.__parent__, self.request, self.request.view_name) |
68 return absolute_url(self.configuration.__parent__, self.request, self.request.view_name) |
49 |
69 |
50 def get_ajax_handler(self): |
70 def get_ajax_handler(self): |
51 return resource_url(self.context.__parent__, self.request, self.ajax_handler) |
71 return absolute_url(self.configuration.__parent__, self.request, self.ajax_handler) |
|
72 |
|
73 @reify |
|
74 def portlet(self): |
|
75 registry = self.request.registry |
|
76 return registry.queryUtility(IPortlet, name=self.configuration.portlet_name) |
|
77 |
|
78 |
|
79 @adapter_config(name='properties', context=(Interface, IPyAMSLayer, PortletSettingsEditor), provides=IInnerTabForm) |
|
80 class PortletSettingsPropertiesEditor(InnerAdminEditForm): |
|
81 """Portlet settings properties editor""" |
|
82 |
|
83 id = 'properties_form' |
|
84 tab_label = _("Main properties") |
|
85 legend = None |
52 |
86 |
53 @property |
87 @property |
54 def fields(self): |
88 def fields(self): |
55 fields = field.Fields(self.interface) |
89 return field.Fields(self.parent_form.settings).omit('__name__') |
56 if not self.getContent().can_inherit: |
|
57 fields = fields.omit('inherit_parent') |
|
58 return fields |
|
59 |
90 |
60 def updateWidgets(self, prefix=None): |
91 weight = 10 |
61 super(PortletConfigurationEditor, self).updateWidgets(prefix) |
|
62 self.widgets['slot_name'].mode = HIDDEN_MODE |
|
63 self.widgets['position'].mode = HIDDEN_MODE |
|