1
2
3
4
5
6
7
8
9
10
11
12
13 from AccessControl import ClassSecurityInfo, Permissions
14 from ZenMenu import ZenMenu
15 from Globals import InitializeClass
16 from Acquisition import aq_base, aq_chain
17 from Products.ZenRelations.RelSchema import *
18 from Products.ZenUtils.Utils import cmpClassNames
19 from Products.ZenWidgets import messaging
20
22 """ ZenMenuable is a mixin providing menuing.
23 """
24
25 security = ClassSecurityInfo()
26
27 security.declareProtected('Change Device', 'manage_addZenMenu')
48
49
50 security.declareProtected('Change Device', 'manage_addZenMenuItem')
55 """ Add ZenMenuItem
56 """
57 menu = getattr(self.zenMenus, menuid, None)
58 if not menu: menu = self.manage_addZenMenu(menuid)
59 menu.manage_addZenMenuItem(id, description, action,
60 permissions, isdialog, isglobal,
61 banned_classes, allowed_classes, banned_ids, ordering)
62 if REQUEST:
63 return self.callZenScreen(REQUEST)
64
65
66 security.declareProtected('Change Device', 'manage_deleteZenMenuItem')
74
75
76 security.declareProtected('Change Device', 'manage_saveMenuItemOrdering')
86
87
88 security.declareProtected('Change Device', 'manage_addItemsToZenMenu')
90 """ Add ZenMenuItems to a ZenMenu.
91 Accepts a list of dictionaries.
92 Available keyword args:
93 id
94 description
95 action
96 permissions
97 isglobal
98 isdialog
99 banned_classes
100 allowed_classes
101 banned_ids
102 """
103 if not items:
104 items = [{}]
105 menu = getattr(self.zenMenus, menuid, None)
106 if not menu: menu = self.manage_addZenMenu(menuid)
107 if isinstance(items, dict): items = [items]
108 for item in items:
109 menu.manage_addZenMenuItem(**item)
110 return menu
111
112 security.declareProtected('Change Device', 'buildMenus')
117
118 security.declareProtected('Change Device', 'manage_deleteZenMenu')
132
133
135 """ Build menus for this context, acquiring ZenMenus
136 which in turn acquire ZenMenuItems.
137
138 Pass it a menuid for a list of menuitems,
139 a sequence of menuids for a dict of lists of items,
140 or nothing for a dict of all available menus.
141 """
142 if not context: context=self
143 menus = {}
144 if not isinstance(self, ZenMenuable): return None
145 if isinstance(menuids, (str,unicode)): menuids=[menuids]
146 mychain = aq_chain(context.primaryAq())
147 mychain.reverse()
148 for obj in mychain:
149 if getattr(aq_base(obj), 'zenMenus', None):
150 mens = obj.zenMenus()
151 while mens:
152 c = mens.pop()
153 if menuids and c.id not in menuids: continue
154 menu = menus[c.id] = menus.get(c.id, {})
155 its = c.zenMenuItems()
156 while its:
157 i = its.pop()
158 def permfilter(p):
159 return self.checkRemotePerm(p,context)
160 permok = filter(permfilter,
161 getattr(i,'permissions',('',)))
162 if not permok \
163 or (not getattr(i, 'isglobal', True) and \
164 context!=i.getMenuItemOwner())\
165 or (context.id in i.banned_ids) \
166 or (i.allowed_classes and not \
167 cmpClassNames(context, i.allowed_classes))\
168 or cmpClassNames(context, i.banned_classes):
169 continue
170 menu[i.id] = i
171 keys = menus.keys()
172 for key in keys:
173 menus[key] = menus[key].values()
174 if not menus[key]: del menus[key]
175 if not menus:
176 return None
177 elif len(menus.keys())==1:
178 return menus.values()[0]
179 else:
180 return menus
181
182 InitializeClass(ZenMenuable)
183