# HG changeset patch # User Sylvain Thénault # Date 1294744776 -3600 # Node ID 3f3d576b87d9348247a2a9ac6c7631a9c2bd0fc6 # Parent 30faf6021278e100c66a4a7e40e33456b8d426c5 [web action] refactor box menu handling, fixing #1401943 on the way diff -r 30faf6021278 -r 3f3d576b87d9 devtools/testlib.py --- a/devtools/testlib.py Tue Jan 11 12:05:12 2011 +0100 +++ b/devtools/testlib.py Tue Jan 11 12:19:36 2011 +0100 @@ -480,9 +480,7 @@ def items(self): return self class fake_box(object): - def mk_action(self, label, url, **kwargs): - return (label, url) - def box_action(self, action, **kwargs): + def action_link(self, action, **kwargs): return (action.title, action.url()) submenu = fake_menu() action.fill_menu(fake_box(), submenu) diff -r 30faf6021278 -r 3f3d576b87d9 web/action.py --- a/web/action.py Tue Jan 11 12:05:12 2011 +0100 +++ b/web/action.py Tue Jan 11 12:19:36 2011 +0100 @@ -43,7 +43,7 @@ def fill_menu(self, box, menu): """add action(s) to the given submenu of the given box""" for action in self.actual_actions(): - menu.append(box.box_action(action)) + menu.append(box.action_link(action)) def html_class(self): if self._cw.selected(self.url()): diff -r 30faf6021278 -r 3f3d576b87d9 web/component.py --- a/web/component.py Tue Jan 11 12:05:12 2011 +0100 +++ b/web/component.py Tue Jan 11 12:19:36 2011 +0100 @@ -24,7 +24,7 @@ from warnings import warn -from logilab.common.deprecation import class_deprecated, class_renamed +from logilab.common.deprecation import class_deprecated, class_renamed, deprecated from logilab.mtconverter import xml_escape from cubicweb import Unauthorized, role, target, tags @@ -36,7 +36,7 @@ non_final_entity, partial_relation_possible, partial_has_related_entities) from cubicweb.appobject import AppObject -from cubicweb.web import INTERNAL_FIELD_VALUE, htmlwidgets, stdmsgs +from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs # abstract base class for navigation components ################################ @@ -163,6 +163,57 @@ rendered """ + +class Link(object): + """a link to a view or action in the ui. + + Use this rather than `cw.web.htmlwidgets.BoxLink`. + + Note this class could probably be avoided with a proper DOM on the server + side. + """ + newstyle = True + + def __init__(self, href, label, **attrs): + self.href = href + self.label = label + self.attrs = attrs + + def __unicode__(self): + return tags.a(self.label, href=self.href, **self.attrs) + + def render(self, w): + w(tags.a(self.label, href=self.href, **self.attrs)) + + +class Separator(object): + """a menu separator. + + Use this rather than `cw.web.htmlwidgets.BoxSeparator`. + """ + newstyle = True + + def render(self, w): + w(u'
') + + +def _bwcompatible_render_item(w, item): + if hasattr(item, 'render'): + if getattr(item, 'newstyle', False): + if isinstance(item, Separator): + w(u'') + item.render(w) + w(u'