Package Products :: Package Zuul :: Package routers :: Module nav
[hide private]
[frames] | no frames]

Source Code for Module Products.Zuul.routers.nav

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2010, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  #  
  8  ############################################################################## 
  9   
 10   
 11  """ 
 12  Operations for Navigation 
 13   
 14  Available at:  /zport/dmd/detailnav_router 
 15  """ 
 16   
 17  from Products.ZenUtils.Ext import DirectRouter 
 18  from Products.ZenUtils.extdirect.router import DirectResponse 
 19  from Products.Zuul.decorators import require 
 20  from Products.ZenUI3.security.security import permissionsForContext 
 21   
 22   
23 -class DetailNavRouter(DirectRouter):
24 """ 25 Router to Details navigation for given uid 26 """ 27
28 - def _getLinkMenuItems(self, menuIds, ob):
29 def filterFn(menu): 30 return not menu.isdialog
31 items = filter(filterFn, self._getMenuItems(menuIds, ob)) 32 return items
33
34 - def _getDialogMenuItems(self, menuIds, ob):
35 def filterFn(menu): 36 return menu.isdialog
37 items = filter(filterFn, self._getMenuItems(menuIds, ob)) 38 return items 39
40 - def _getMenuItems(self, menuIds, ob):
41 linkMenus = [] 42 menus = ob.getMenus(menuIds) 43 if menus: 44 if isinstance(menus, list): 45 menus = [menus]; 46 else: 47 menus = menus.values() 48 for menuItems in menus: 49 for menuItem in menuItems: 50 linkMenus.append(menuItem) 51 return linkMenus
52
53 - def getDetailNavConfigs(self, uid=None, menuIds=None):
54 """ 55 return a list of Detail navigation configurations. Can be used to create 56 navigation links. Format is: 57 { 58 id: <id of the configuration>, 59 'viewName': <view to display>, 60 'xtype': <Ext type for the panel>, 61 'text': <display name of the config info> 62 } 63 """ 64 detailItems = [] 65 def convertToDetailNav(tab): 66 return { 67 'id': '%s' % tab['name'].lower(), 68 'xtype': 'backcompat', 69 'viewName': tab['action'], 70 'text': tab['name'] 71 }
72 def menuToNav(menu): 73 return { 74 'id': '%s' % menu.id.lower(), 75 'xtype': 'backcompat', 76 'viewName': menu.action, 77 'text': menu.description 78 } 79 80 if uid: 81 ob = self.context.dmd.unrestrictedTraverse(uid) 82 tabs = ob.zentinelTabs('') 83 detailItems = [ convertToDetailNav(tab) for tab in tabs ] 84 #get menu items that are not dialogs 85 if menuIds: 86 menus = self._getLinkMenuItems(menuIds, ob) 87 if menus: 88 detailItems.extend(menuToNav(menu) for menu in menus) 89 return DirectResponse(detailConfigs=detailItems) 90
91 - def getContextMenus(self, uid=None, menuIds=None):
92 if uid: 93 ob = self.context.dmd.unrestrictedTraverse(uid) 94 menuItems = [] 95 if menuIds: 96 menus = self._getDialogMenuItems(menuIds, ob) 97 def menuToConfig(menu): 98 return { 99 'id': '%s' % menu.id.lower(), 100 'viewName': menu.action, 101 'text': menu.description 102 }
103 if menus: 104 menuItems.extend(menuToConfig(menu) for menu in menus) 105 return DirectResponse(menuItems=menuItems) 106
107 - def getSecurityPermissions(self, uid):
108 """ 109 returns a dictionary of all the permissions a 110 user has on the context 111 """ 112 obj = self.context.dmd.unrestrictedTraverse(uid) 113 permissions = permissionsForContext(obj) 114 return DirectResponse.succeed(data=permissions)
115