Changeset 2768 in products for quintagroup.dropdownmenu
- Timestamp:
- Aug 30, 2010 1:04:25 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py
r2701 r2768 25 25 recurse = ViewPageTemplateFile('templates/sections_recurse.pt') 26 26 27 27 28 def update(self): 28 29 # we may need some previously defined variables … … 37 38 self.context_state = getMultiAdapter((self.context, self.request), 38 39 name="plone_context_state") 40 self.context_url = self.context_state.is_default_page() and \ 41 '/'.join(self.context.absolute_url().split('/')[:-1]) or \ 42 self.context.absolute_url() 39 43 40 44 # fetch actions-based tabs? … … 63 67 return [] 64 68 65 #category_ids = category.objectIds() 66 #selectedTabs = self.context.restrictedTraverse('selectedTabs') 67 ## try to find out selected subtab 68 #if tab['id'] == self.selected_portal_tab: 69 #selection = selectedTabs(None, None, tab['subtabs']) 70 #self.selected_sub_tab = selection['portal'] 71 return self._subactions(tool._getOb(conf.actions_category), context) 72 73 def _subactions(self, category, object, level=0): 69 self.chain = [] #save not traversable chain here 70 self.tchain = [] #save the best traversable chain here 71 self.res, c = self._subactions(tool._getOb(conf.actions_category), context, 0, self.chain) 72 self.tchain.reverse() 73 self.chain.reverse() 74 self.chain = self.chain and self.chain or self.tchain 75 self._activate(self.res) 76 return self.res 77 78 def _activate(self, res, level=0): 79 """Mark selected chain in the tabs dictionary""" 80 if self.chain and len(self.chain) > level: 81 res[self.chain[level]]['currentItem'] = True 82 res[self.chain[level]]['currentParent'] = True 83 if level + 1 < len(self.chain): 84 self._activate(res[self.chain[level]]['children'], level+1) 85 86 87 def _subactions(self, category, object, level=0, lchain=[]): 88 """Build tabs dictionary out of portal actions""" 74 89 tabs = [] 75 90 currentParentId = -1 76 91 index = -1 77 currentParent = False92 local = False 78 93 for info in self._actionInfos(category, object): 79 94 # prepare data for action … … 81 96 # done on a template level because of separate content and 82 97 # actions tabs are rendered separately 83 currentItem = False84 98 85 99 index += 1 86 100 icon = info['icon'] and '<img src="%s" />' % info['icon'] or '' 87 101 102 if self.context_url.startswith(info['url']) and info['url'] != self.site_url: 103 if currentParentId > -1: 104 if len(tabs[currentParentId]['getURL']) < len(info['url']): 105 currentParentId = index 106 else: 107 currentParentId = index 108 if self.context_url == info['url']: 109 lchain.append(index) 110 local = True 111 88 112 # look up children for a given action 89 113 children = [] … … 100 124 subcat = category._getOb(subcat_id) 101 125 if IActionCategory.providedBy(subcat): 102 children = self._subactions(subcat, object, level+1) 103 104 url = self.context_state.is_default_page() and \ 105 '/'.join(self.context.absolute_url().split('/')[:-1]) or \ 106 self.context.absolute_url() 107 if url.startswith(info['url']) and info['url'] != self.site_url: 108 if currentParentId > -1: 109 if len(tabs[currentParentId]['getURL']) < len(info['url']): 110 currentParentId = index 111 else: 112 currentParentId = index 113 if url == info['url']: 114 currentItem = True 126 children, local = self._subactions(subcat, object, level+1, lchain) 127 if local: 128 lchain.append(index) 129 115 130 # make up final tab dictionary 116 131 tab = {'Title': info['title'], … … 119 134 'show_children': len(children) > 0, 120 135 'children': children, 121 'currentItem': currentItem,122 'currentParent': currentParent,136 'currentItem': False, 137 'currentParent': False, 123 138 'item_icon': {'html_tag': icon}, 124 139 'normalized_review_state': 'visible'} 125 140 tabs.append(tab) 141 126 142 if currentParentId > -1: 127 tabs[currentParentId]['currentParent'] = True128 return tabs 143 self.tchain.append(currentParentId) 144 return tabs, local 129 145 130 146 def _actionInfos(self, category, object, check_visibility=1,
Note: See TracChangeset
for help on using the changeset viewer.