+ ))
+
+
+class AjaxMenuItem(ObjectBase):
+ def __init__(self, label, url, a_attrs=None, span_label='', span_attrs=None, visibility=None, weight=500, name=''):
+ super(AjaxMenuItem, self).__init__(visibility, weight, name)
+ self.label = self.Argument(label)
+ self.url = self.Argument(url)
+ self.a_attrs = self.Argument(a_attrs or {})
+ self.span_label = self.Argument(span_label)
+ self.span_attrs = self.Argument(span_attrs or {})
+
+ def render(self, context):
+ return html.buildtag('li',
+ html.buildtag('span', self.span_label(context), **self.span_attrs(context)) + \
+ html.hyperlink(self.url(context), self.label(context), **self.a_attrs(context)),
+ **{'class': 'item'})
+
+class AjaxMenuGroup(ObjectBase, Registry):
+ def __init__(self, label, items, visibility=None, weight=500, name=''):
+ super(AjaxMenuGroup, self).__init__(visibility, weight, name)
+ self.label = label
+
+ for item in items:
+ self.add(item)
+
+ def can_render(self, context):
+ if super(AjaxMenuGroup, self).can_render(context):
+ for item in self:
+ if item.can_render(context): return True
+
+ return False
+
+ def render(self, context):
+ return html.buildtag('li', self.label, **{'class': 'separator'}) + "".join([
+ item.render(context) for item in self if item.can_render(context)
+ ])
+
+class UserMenuItem(AjaxMenuItem):
+ def __init__(self, render_to=None, *args, **kwargs):
+ super(UserMenuItem, self).__init__(*args, **kwargs)
+ self.render_to = render_to
+
+ def can_render(self, context):
+ return (not self.render_to or (self.render_to(context['user']))) and super(UserMenuItem, self)._visible_to(context['viewer'])