Permalink
Browse files

- Add a configuration panel to define a mode for each area (above and…

… below)

  of each page.
  • Loading branch information...
1 parent 41446b0 commit 119713a91a03997955dc301fd034a85532a975c2 @toutpt toutpt committed Oct 18, 2012
@@ -22,7 +22,18 @@
directory="resources"
/>
<include package ="plone.app.portlets" />
-
+ <utility
+ component=".viewlets.ModeVocabulary"
+ name="collective.masonry.vocabulary.mode"
+ />
+ <browser:page
+ name="manage-collective.masonry"
+ for="*"
+ class=".viewlets.ViewletConfigurationFormView"
+ permission="plone.app.portlets.ManagePortlets"
+ layer="collective.masonry.interfaces.IMasonryLayer"
+ />
+ <adapter factory=".viewlets.ViewletConfigurationAdapter"/>
<!-- PORTLETS ABOVE AND BELOW CONTENT -->
<browser:viewlet
name="masonry.portletsabovecontent"
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
- <version>1200</version>
+ <version>1201</version>
<dependencies>
<dependency>profile-collective.js.imageloaded:default</dependency>
<dependency>profile-collective.js.masonry:default</dependency>
@@ -0,0 +1,12 @@
+<registry>
+ <record name="collective.masonry.vocabulary.mode">
+ <field type="plone.registry.field.Tuple">
+ <title>Masonry mode</title>
+ <value_type type="plone.registry.field.TextLine" />
+ </field>
+ <value>
+ <element>Fixed width</element>
+ <element>Fixed width and height</element>
+ </value>
+ </record>
+</registry>
@@ -30,13 +30,24 @@
</h1>
<div id="content-core">
<p i18n:domain="plone">
- <a href=""
- class="link-parent"
- tal:attributes="href string:${context/absolute_url}"
- i18n:translate="return_to_view">
- Return
+ <a href=""
+ class="link-parent"
+ tal:attributes="href string:${context/absolute_url}"
+ i18n:translate="return_to_view">
+ Return
+ </a>
+
+ <tal:block tal:define="is_portal_root context/@@plone_context_state/is_portal_root;"
+ tal:condition="not:is_portal_root">
+ -
+ <a class="link-parent" tal:condition="plone_view/getParentObject|nothing"
+ tal:attributes="href python:plone_view.getParentObject().absolute_url()+'/@@manage-portlets'"
+ i18n:translate="">
+ Go to parent folder
</a>
+ </tal:block>
</p>
+ <p><a tal:attributes="href string:${context/absolute_url}/@@manage-collective.masonry">Manage masrony configuration for this page</a></p>
<h2>Manage portlets above the content</h2>
<div class="portlet-manager">
@@ -1,7 +1,7 @@
<div id="portlets-above"
i18n:domain="collective.masonry" tal:define="inmanage python:request.get('URL').endswith('@@manage-portlets') or 'portlets++' in request.get('URL')">
- <tal:block tal:condition="not:inmanage">
+ <div tal:attributes="class view/get_mode" tal:condition="not:inmanage">
<div id="portletsAboveContent" tal:content="structure provider:masonry.above" />
<div class="visualClear"/>
- </tal:block>
+ </div>
</div>
@@ -1,7 +1,7 @@
-<div id="portlets-below"
+<div id="portlets-below" tal:attributes="class view/get_mode"
i18n:domain="collective.masonry" tal:define="inmanage python:request.get('URL').endswith('@@manage-portlets') or 'portlets++' in request.get('URL')">
- <tal:block tal:condition="not:inmanage">
+ <div tal:attributes="class view/get_mode" tal:condition="not:inmanage">
<div id="portletsBelowContent" tal:content="structure provider:masonry.below" />
<div class="visualClear"/>
- </tal:block>
+ </div>
</div>
@@ -7,7 +7,7 @@
title="Common upgrade"
description="apply profile"
source="*"
- destination="1200"
+ destination="1201"
handler=".upgrades.common"
profile="collective.masonry:default"/>
@@ -1,34 +1,101 @@
+from zope import component
+from zope import schema
+from zope import interface
from zope.component import getMultiAdapter
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.layout.viewlets.common import ViewletBase
from Products.CMFCore.utils import getToolByName
+from plone.i18n.normalizer.base import baseNormalize
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from plone.autoform.form import AutoExtensibleForm
+from z3c.form import form, button
+from plone.z3cform import layout
+from zope.schema.interfaces import IVocabularyFactory
+from plone.registry.interfaces import IRegistry
+
+
+class RegistryVocabulary(object):
+ """vocabulary to use with plone.app.registry"""
+ interface.implements(IVocabularyFactory)
+
+ def __init__(self, key):
+ self.key = key
+ def __call__(self, context):
+
+ registry = component.queryUtility(IRegistry)
+ if registry is None:
+ return []
+ categories = registry[self.key]
+ terms = [SimpleTerm(baseNormalize(category),
+ baseNormalize(category),
+ category) for category in categories]
+ return SimpleVocabulary(terms)
+
+
+ModeVocabulary = RegistryVocabulary('collective.masonry.vocabulary.mode')
+
+
+class IViewletConfiguration(interface.Interface):
+ abovemode = schema.Choice(title=u"Above mode",
+ vocabulary="collective.masonry.vocabulary.mode")
+ belowmode = schema.Choice(title=u"Below mode",
+ vocabulary="collective.masonry.vocabulary.mode")
+
+
+class ViewletConfigurationForm(AutoExtensibleForm, form.EditForm):
+ """Form to configure default view"""
+ schema = IViewletConfiguration
+
+
+class ViewletConfigurationFormView(layout.FormWrapper):
+ form = ViewletConfigurationForm
+
+class ViewletConfigurationAdapter(object):
+ component.adapts(interface.Interface)
+ interface.implements(IViewletConfiguration)
+
+ def __init__(self, context):
+ self.context = context
+
+ def get_abovemode(self):
+ return getattr(self.context, 'masonryabovemode',
+ self.default_above_mode)
+ def set_abovemode(self, value):
+ setattr(self.context, 'masonryabovemode', value)
+ abovemode = property(get_abovemode, set_abovemode)
+
+ def get_belowmode(self):
+ return getattr(self.context, 'masonrybelowmode',
+ self.default_above_mode)
+ def set_belowmode(self, value):
+ setattr(self.context, 'masonrybelowmode', value)
+ belowmode = property(get_belowmode, set_belowmode)
+
+ @property
+ def default_above_mode(self):
+ return 'Fixed width'
+
class PortletsAboveViewlet(ViewletBase):
render = ViewPageTemplateFile('templates/portletsabovecontent.pt')
-
+
def update(self):
"""
Define everything we want to call in the template
"""
context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state')
self.manageUrl = '%s/@@manage-masonryportlets' % context_state.view_url()
-
+
## This is the way it's done in plone.app.portlets.manager, so we'll do the same
mt = getToolByName(self.context, 'portal_membership')
self.canManagePortlets = mt.checkPermission('Portlets: Manage portlets', self.context)
+ self.config = IViewletConfiguration(self.context)
+ def get_mode(self):
+ return baseNormalize(self.config.abovemode).lower().replace(' ','-')
-class PortletsBelowViewlet(ViewletBase):
+class PortletsBelowViewlet(PortletsAboveViewlet):
render = ViewPageTemplateFile('templates/portletsbelowcontent.pt')
-
- def update(self):
- """
- Define everything we want to call in the template
- """
- context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state')
- self.manageUrl = '%s/@@manage-masonryportlets' % context_state.view_url()
-
- ## This is the way it's done in plone.app.portlets.manager, so we'll do the same
- mt = getToolByName(self.context, 'portal_membership')
- self.canManagePortlets = mt.checkPermission('Portlets: Manage portlets', self.context)
+ def get_mode(self):
+ return baseNormalize(self.config.belowmode).lower().replace(' ','-')
View
@@ -4,7 +4,8 @@ Changelog
1.2.2 (unreleased)
------------------
-- Nothing changed yet.
+- Add a configuration panel to define a mode for each area (above and below)
+ of each page.
1.2.1 (2012-08-13)
View
@@ -30,6 +30,7 @@
'setuptools',
'collective.js.masonry',
'collective.js.imageloaded',
+ 'collective.registry',
# -*- Extra requirements: -*-
],
extras_require = {'test':['plone.app.testing']},

0 comments on commit 119713a

Please sign in to comment.