Skip to content
Browse files

Add actual actions to the toolbar.

  • Loading branch information...
1 parent b7b20f2 commit 57f58d7d07c63adbf98c0012020c6915ccd451bd Rob Gietema committed Nov 7, 2011
Showing with 91 additions and 2 deletions.
  1. +2 −2 plone/app/toolbar/bbb/toolbarlink.pt
  2. +89 −0 plone/app/toolbar/toolbar.py
View
4 plone/app/toolbar/bbb/toolbarlink.pt
@@ -21,14 +21,14 @@
left: 0;
top: 0;
width: 100%;
- height: 44px;
+ height: 43px;
z-index: 9999;
-webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
body {
- margin-top: 44px;
+ margin-top: 43px;
}
</style>
<script type="text/javascript">
View
89 plone/app/toolbar/toolbar.py
@@ -3,6 +3,8 @@
from zope.publisher.browser import BrowserView
from plone.registry.interfaces import IRegistry
from plone.memoize.instance import memoize
+from Acquisition import aq_inner
+from urllib import unquote
from Acquisition import aq_base
from AccessControl import getSecurityManager
@@ -145,3 +147,90 @@ def settingsActions(self):
@memoize
def baseURL(self):
return self.context.absolute_url()
+
+ @memoize
+ def prepareObjectTabs(self, default_tab='view',
+ sort_first=['folderContents']):
+ """Prepare the object tabs by determining their order and working
+ out which tab is selected. Used in global_contentviews.pt
+ """
+ context = aq_inner(self.context)
+ context_url = context.absolute_url()
+ context_fti = context.getTypeInfo()
+
+ context_state = getMultiAdapter(
+ (context, self.request), name=u'plone_context_state')
+ actions = context_state.actions
+
+ action_list = []
+ if context_state.is_structural_folder():
+ action_list = actions('folder')
+ action_list.extend(actions('object'))
+
+ tabs = []
+ found_selected = False
+ fallback_action = None
+
+ # we use the context-acquired request object here, which is
+ # different from the request fetching the tile HTML
+ request_url = self.context.REQUEST['ACTUAL_URL']
+ request_url_path = request_url[len(context_url):]
+
+ if request_url_path.startswith('/'):
+ request_url_path = request_url_path[1:]
+
+ for action in action_list:
+ item = {'title': action['title'],
+ 'id': action['id'],
+ 'url': '',
+ 'selected': False}
+
+ action_url = action['url'].strip()
+ starts = action_url.startswith
+ if starts('http') or starts('javascript'):
+ item['url'] = action_url
+ else:
+ item['url'] = '%s/%s' % (context_url, action_url)
+
+ action_method = item['url'].split('/')[-1]
+
+ # Action method may be a method alias:
+ # Attempt to resolve to a template.
+ action_method = context_fti.queryMethodID(
+ action_method, default=action_method)
+ if action_method:
+ request_action = unquote(request_url_path)
+ request_action = context_fti.queryMethodID(
+ request_action, default=request_action)
+ if action_method == request_action:
+ item['selected'] = True
+ found_selected = True
+
+ current_id = item['id']
+ if current_id == default_tab:
+ fallback_action = item
+
+ tabs.append(item)
+
+ if not found_selected and fallback_action is not None:
+ fallback_action['selected'] = True
+
+ def sortOrder(tab):
+ try:
+ return sort_first.index(tab['id'])
+ except ValueError:
+ return 255
+
+ tabs.sort(key=sortOrder)
+ return tabs
+
+ def object_actions(self):
+ context = aq_inner(self.context)
+ context_state = getMultiAdapter((context, self.request),
+ name=u'plone_context_state')
+
+ return context_state.actions('object_actions')
+
+ def icon(self, action):
+ return action.get('icon', None)
+

0 comments on commit 57f58d7

Please sign in to comment.
Something went wrong with that request. Please try again.