web/views/boxes.py
branchtls-sprint
changeset 1450 8edb0806dde4
parent 1285 d5ce82d65c2b
child 1533 bcd4bfff658b
equal deleted inserted replaced
1449:7751785c0815 1450:8edb0806dde4
    22 from cubicweb.view import EntityView
    22 from cubicweb.view import EntityView
    23 from cubicweb.web import uicfg
    23 from cubicweb.web import uicfg
    24 from cubicweb.web.box import BoxTemplate
    24 from cubicweb.web.box import BoxTemplate
    25 
    25 
    26 _ = unicode
    26 _ = unicode
    27     
    27 
    28 class EditBox(BoxTemplate):
    28 class EditBox(BoxTemplate):
    29     """
    29     """
    30     box with all actions impacting the entity displayed: edit, copy, delete
    30     box with all actions impacting the entity displayed: edit, copy, delete
    31     change state, add related entities
    31     change state, add related entities
    32     """
    32     """
    36     title = _('actions')
    36     title = _('actions')
    37     order = 2
    37     order = 2
    38     # class attributes below are actually stored in the uicfg module since we
    38     # class attributes below are actually stored in the uicfg module since we
    39     # don't want them to be reloaded
    39     # don't want them to be reloaded
    40     rmode = uicfg.rmode
    40     rmode = uicfg.rmode
    41         
    41 
    42     @classmethod
    42     @classmethod
    43     def vreg_initialization_completed(cls):
    43     def vreg_initialization_completed(cls):
    44         """set default category tags for relations where it's not yet defined in
    44         """set default category tags for relations where it's not yet defined in
    45         the category relation tags
    45         the category relation tags
    46         """
    46         """
    69     @classmethod
    69     @classmethod
    70     def relation_mode(cls, rtype, etype, targettype, role='subject'):
    70     def relation_mode(cls, rtype, etype, targettype, role='subject'):
    71         """return a string telling if the given relation is usually created
    71         """return a string telling if the given relation is usually created
    72         to a new entity ('create' mode) or to an existant entity ('link' mode)
    72         to a new entity ('create' mode) or to an existant entity ('link' mode)
    73         """
    73         """
    74         return cls.rmode.rtag(rtype, role, etype, targettype)
    74         if role == 'subject':
       
    75             return cls.rmode.rtag(rtype, role, etype, targettype)
       
    76         return cls.rmode.rtag(rtype, role, targettype, etype)
    75 
    77 
    76 
    78 
    77     def call(self, view=None, **kwargs):
    79     def call(self, view=None, **kwargs):
    78         _ = self.req._
    80         _ = self.req._
    79         title = _(self.title)
    81         title = _(self.title)
   115             other_menu.items = []
   117             other_menu.items = []
   116         self.add_submenu(box, add_menu, _('add'))
   118         self.add_submenu(box, add_menu, _('add'))
   117         self.add_submenu(box, other_menu)
   119         self.add_submenu(box, other_menu)
   118         if not box.is_empty():
   120         if not box.is_empty():
   119             box.render(self.w)
   121             box.render(self.w)
   120             
   122 
   121     def add_submenu(self, box, submenu, label_prefix=None):
   123     def add_submenu(self, box, submenu, label_prefix=None):
   122         if len(submenu.items) == 1:
   124         if len(submenu.items) == 1:
   123             boxlink = submenu.items[0]
   125             boxlink = submenu.items[0]
   124             if label_prefix:
   126             if label_prefix:
   125                 boxlink.label = u'%s %s' % (label_prefix, boxlink.label)
   127                 boxlink.label = u'%s %s' % (label_prefix, boxlink.label)
   126             box.append(boxlink)
   128             box.append(boxlink)
   127         elif submenu.items:
   129         elif submenu.items:
   128             box.append(submenu)
   130             box.append(submenu)
   129         
   131 
   130     def schema_actions(self, entity):
   132     def schema_actions(self, entity):
   131         user = self.req.user
   133         user = self.req.user
   132         actions = []
   134         actions = []
   133         _ = self.req._
   135         _ = self.req._
   134         eschema = entity.e_schema
   136         eschema = entity.e_schema
   223         form = self.formdef % (req.build_url('view'), req.next_tabindex(),
   225         form = self.formdef % (req.build_url('view'), req.next_tabindex(),
   224                                html_escape(rql), req.next_tabindex())
   226                                html_escape(rql), req.next_tabindex())
   225         title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title)
   227         title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title)
   226         box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False)
   228         box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False)
   227         box.append(BoxHtml(form))
   229         box.append(BoxHtml(form))
   228         box.render(self.w)            
   230         box.render(self.w)
   229 
   231 
   230 
   232 
   231 # boxes disabled by default ###################################################
   233 # boxes disabled by default ###################################################
   232 
   234 
   233 class PossibleViewsBox(BoxTemplate):
   235 class PossibleViewsBox(BoxTemplate):
   234     """display a box containing links to all possible views"""
   236     """display a box containing links to all possible views"""
   235     id = 'possible_views_box'
   237     id = 'possible_views_box'
   236     __select__ = BoxTemplate.__select__ & match_user_groups('users', 'managers')
   238     __select__ = BoxTemplate.__select__ & match_user_groups('users', 'managers')
   237     
   239 
   238     visible = False
   240     visible = False
   239     title = _('possible views')
   241     title = _('possible views')
   240     order = 10
   242     order = 10
   241 
   243 
   242     def call(self, **kwargs):
   244     def call(self, **kwargs):
   262     def call(self, **kwargs):
   264     def call(self, **kwargs):
   263         box = BoxWidget(self.req._(self.title), self.id)
   265         box = BoxWidget(self.req._(self.title), self.id)
   264         for view in self.vreg.possible_views(self.req, None):
   266         for view in self.vreg.possible_views(self.req, None):
   265             if view.category == 'startupview':
   267             if view.category == 'startupview':
   266                 box.append(self.box_action(view))
   268                 box.append(self.box_action(view))
   267         
   269 
   268         if not box.is_empty():
   270         if not box.is_empty():
   269             box.render(self.w)
   271             box.render(self.w)
   270 
   272 
   271 
   273 
   272 # helper classes ##############################################################
   274 # helper classes ##############################################################
   273 
   275 
   274 class SideBoxView(EntityView):
   276 class SideBoxView(EntityView):
   275     """helper view class to display some entities in a sidebox"""
   277     """helper view class to display some entities in a sidebox"""
   276     id = 'sidebox'
   278     id = 'sidebox'
   277     
   279 
   278     def call(self, boxclass='sideBox', title=u''):
   280     def call(self, boxclass='sideBox', title=u''):
   279         """display a list of entities by calling their <item_vid> view"""
   281         """display a list of entities by calling their <item_vid> view"""
   280         if title:
   282         if title:
   281             self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % title)
   283             self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % title)
   282         self.w(u'<div class="%s"><div class="sideBoxBody">' % boxclass)
   284         self.w(u'<div class="%s"><div class="sideBoxBody">' % boxclass)