Changeset 2768 in products for quintagroup.dropdownmenu


Ignore:
Timestamp:
Aug 30, 2010 1:04:25 PM (14 years ago)
Author:
chervol
Message:

added non-traversable highlights support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py

    r2701 r2768  
    2525    recurse = ViewPageTemplateFile('templates/sections_recurse.pt') 
    2626 
     27 
    2728    def update(self): 
    2829        # we may need some previously defined variables 
     
    3738        self.context_state = getMultiAdapter((self.context, self.request),  
    3839                                              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() 
    3943 
    4044        # fetch actions-based tabs? 
     
    6367            return [] 
    6468 
    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""" 
    7489        tabs = [] 
    7590        currentParentId = -1 
    7691        index = -1 
    77         currentParent = False 
     92        local = False       
    7893        for info in self._actionInfos(category, object): 
    7994            # prepare data for action 
     
    8196            #       done on a template level because of separate content and 
    8297            #       actions tabs are rendered separately 
    83             currentItem = False 
    8498 
    8599            index += 1 
    86100            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                 
    88112            # look up children for a given action 
    89113            children = [] 
     
    100124                    subcat = category._getOb(subcat_id) 
    101125                    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             
    115130            # make up final tab dictionary 
    116131            tab = {'Title': info['title'], 
     
    119134                   'show_children': len(children) > 0, 
    120135                   'children': children, 
    121                    'currentItem': currentItem, 
    122                    'currentParent': currentParent, 
     136                   'currentItem': False,  
     137                   'currentParent': False, 
    123138                   'item_icon': {'html_tag': icon}, 
    124139                   'normalized_review_state': 'visible'} 
    125140            tabs.append(tab) 
     141 
    126142        if currentParentId > -1: 
    127             tabs[currentParentId]['currentParent'] = True 
    128         return tabs 
     143            self.tchain.append(currentParentId) 
     144        return tabs, local 
    129145 
    130146    def _actionInfos(self, category, object, check_visibility=1, 
Note: See TracChangeset for help on using the changeset viewer.