Changeset 2772 in products for quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py
- Timestamp:
- Sep 1, 2010 2:32:08 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py
r2769 r2772 41 41 '/'.join(self.context.absolute_url().split('/')[:-1]) or \ 42 42 self.context.absolute_url() 43 43 44 self.cat_sufix = self.conf.nested_category_sufix or '' 45 self.cat_prefix = self.conf.nested_category_prefix or '' 44 46 # fetch actions-based tabs? 45 47 if conf.show_actions_tabs: … … 66 68 if conf.actions_category not in tool.objectIds(): 67 69 return [] 68 69 self.chain = [] #save not traversable chain here 70 self.tchain = [] #save the best traversable chain here 71 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(res) 76 return res 70 self.tabs =[] 71 self.normalize_actions(tool._getOb(conf.actions_category), context, 0) 72 current_item = 0 73 delta = 1000 74 for info in self.tabs: 75 if self.context_url.startswith(info['url']) and \ 76 len(self.context_url) - len(info['url']) < delta: 77 current_item = self.tabs.index(info) 78 self.id_chain = [id for id in self.mark_active(self.tabs[current_item]['id'])] 79 80 return self._subactions(tool._getOb(conf.actions_category), context, 0) 77 81 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 82 def mark_active(self, current_id): 83 for info in self.tabs: 84 if info['id'] == current_id: 85 info['currentItem'] = True 86 self.mark_active(info['parent']) 87 yield(info['id']) 88 89 def normalize_actions(self, category, object, level): 90 for info in self._actionInfos(category, object): 91 children = [] 92 bottomLevel = self.conf.actions_tabs_level 93 if bottomLevel < 1 or level < bottomLevel: 94 # try to find out appropriate subcategory 95 subcat_id = self.cat_prefix + info['id'] + self.cat_sufix 96 if subcat_id != info['id'] and \ 97 subcat_id in category.objectIds(): 98 subcat = category._getOb(subcat_id) 99 if IActionCategory.providedBy(subcat): 100 children = self.normalize_actions(subcat, object, level+1) 101 tab = {'id' : info['id'], 102 'title': info['title'], 103 'url': info['url'], 104 'currentItem' : False, 105 'parent': category['id']} 106 self.tabs.append(tab) 86 107 87 108 def _subactions(self, category, object, level=0, lchain=[]): 88 109 """Build tabs dictionary out of portal actions""" 89 110 tabs = [] 90 currentParentId = -1 91 index = -1 92 local = False 111 93 112 for info in self._actionInfos(category, object): 94 # prepare data for action95 # TODO: implement current element functionality, maybe should be96 # done on a template level because of separate content and97 # actions tabs are rendered separately98 99 index += 1100 113 icon = info['icon'] and '<img src="%s" />' % info['icon'] or '' 101 114 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 = index106 else:107 currentParentId = index108 if self.context_url == info['url']:109 lchain.append(index)110 local = True111 112 115 # look up children for a given action 113 116 children = [] … … 124 127 subcat = category._getOb(subcat_id) 125 128 if IActionCategory.providedBy(subcat): 126 children, local = self._subactions(subcat, object, level+1, lchain) 127 if local: 128 lchain.append(index) 129 129 children = self._subactions(subcat, object, level+1) 130 131 active = False 132 if info['id'] in self.id_chain: 133 active = True 130 134 # make up final tab dictionary 131 135 tab = {'Title': info['title'], … … 134 138 'show_children': len(children) > 0, 135 139 'children': children, 136 'currentItem': False,137 'currentParent': False,140 'currentItem': active, 141 'currentParent': active, 138 142 'item_icon': {'html_tag': icon}, 139 143 'normalized_review_state': 'visible'} 140 144 tabs.append(tab) 141 142 if currentParentId > -1: 143 self.tchain.append(currentParentId) 144 return tabs, local 145 return tabs 145 146 146 147 def _actionInfos(self, category, object, check_visibility=1,
Note: See TracChangeset
for help on using the changeset viewer.