web/views/boxes.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 23 Jul 2012 18:01:09 +0200
branchstable
changeset 8490 fa1bd95ded71
parent 8455 b5b263f1ad67
child 8567 1ac70b1bf00e
permissions -rw-r--r--
Added tag cubicweb-debian-version-3.15.2-1 for changeset 9aa5553b2652
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7990
a673d1d9a738 [diet] drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7679
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5839
53cbdc5e0426 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5517
diff changeset
    18
"""Generic boxes for CubicWeb web client:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
* actions box
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    21
* search box
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    23
Additional boxes (disabled by default):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
* schema box
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    25
* possible views box
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
* startup views box
5839
53cbdc5e0426 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5517
diff changeset
    27
"""
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    28
from __future__ import with_statement
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
__docformat__ = "restructuredtext en"
1876
b06a797448aa cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1848
diff changeset
    31
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    33
from warnings import warn
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    34
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2265
diff changeset
    35
from logilab.mtconverter import xml_escape
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    36
from logilab.common.deprecation import class_deprecated
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    38
from cubicweb import Unauthorized
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8183
diff changeset
    39
from cubicweb.predicates import (match_user_groups, match_kwargs,
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    40
                                non_final_entity, nonempty_rset,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    41
                                match_context, contextual)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    42
from cubicweb.utils import wrap_on_write
2265
4c028cb136a4 add import to remove deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    43
from cubicweb.view import EntityView
4c028cb136a4 add import to remove deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    44
from cubicweb.schema import display_name
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    45
from cubicweb.web import component, box, htmlwidgets
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    47
# XXX bw compat, some cubes import this class from here
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    48
BoxTemplate = box.BoxTemplate
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    49
BoxHtml = htmlwidgets.BoxHtml
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
    50
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    51
class EditBox(component.CtxComponent): # XXX rename to ActionsBox
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
    box with all actions impacting the entity displayed: edit, copy, delete
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6785
diff changeset
    54
    change state, add related entities...
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
    56
    __regid__ = 'edit_box'
1150
2d1b721fded9 remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    57
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
    title = _('actions')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    order = 2
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    60
    contextual = True
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
    61
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    62
    def init_rendering(self):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    63
        super(EditBox, self).init_rendering()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    64
        _ = self._cw._
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    65
        self._menus_in_order = []
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    66
        self._menus_by_id = {}
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        # build list of actions
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    68
        actions = self._cw.vreg['actions'].possible_actions(self._cw, self.cw_rset,
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    69
                                                            **self.cw_extra_kwargs)
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    70
        other_menu = self._get_menu('moreactions', _('more actions'))
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    71
        for category, defaultmenu in (('mainactions', self),
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    72
                                      ('moreactions', other_menu),
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    73
                                      ('addrelated', None)):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
            for action in actions.get(category, ()):
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    75
                if action.submenu:
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    76
                    menu = self._get_menu(action.submenu)
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    77
                else:
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    78
                    menu = defaultmenu
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    79
                action.fill_menu(self, menu)
3916
6e7af0e8e524 more conditions have to be verified before unfolding the 'more actions' menu content directly into the box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3511
diff changeset
    80
        # if we've nothing but actions in the other_menu, add them directly into the box
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    81
        if not self.items and len(self._menus_by_id) == 1 and not other_menu.is_empty():
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    82
            self.items = other_menu.items
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    83
        else: # ensure 'more actions' menu appears last
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    84
            self._menus_in_order.remove(other_menu)
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
    85
            self._menus_in_order.append(other_menu)
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    86
            for submenu in self._menus_in_order:
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    87
                self.add_submenu(self, submenu)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    88
        if not self.items:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    89
            raise component.EmptyComponent()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    90
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    91
    def render_title(self, w):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    92
        title = self._cw._(self.title)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    93
        if self.cw_rset:
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    94
            etypes = self.cw_rset.column_types(0)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    95
            if len(etypes) == 1:
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    96
                plural = self.cw_rset.rowcount > 1 and 'plural' or ''
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    97
                etypelabel = display_name(self._cw, iter(etypes).next(), plural)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    98
                title = u'%s - %s' % (title, etypelabel.lower())
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
    99
        w(title)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   100
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   101
    def render_body(self, w):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   102
        self.render_items(w)
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
   103
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   104
    def _get_menu(self, id, title=None, label_prefix=None):
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   105
        try:
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   106
            return self._menus_by_id[id]
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   107
        except KeyError:
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   108
            if title is None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   109
                title = self._cw._(id)
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   110
            self._menus_by_id[id] = menu = htmlwidgets.BoxMenu(title)
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   111
            menu.label_prefix = label_prefix
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   112
            self._menus_in_order.append(menu)
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   113
            return menu
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   114
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
    def add_submenu(self, box, submenu, label_prefix=None):
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   116
        appendanyway = getattr(submenu, 'append_anyway', False)
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   117
        if len(submenu.items) == 1 and not appendanyway:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
            boxlink = submenu.items[0]
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   119
            if submenu.label_prefix:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   120
                # XXX iirk
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   121
                if hasattr(boxlink, 'label'):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   122
                    boxlink.label = u'%s %s' % (submenu.label_prefix, boxlink.label)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   123
                else:
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6785
diff changeset
   124
                    boxlink = u'%s %s' % (submenu.label_prefix, boxlink)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
            box.append(boxlink)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        elif submenu.items:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
            box.append(submenu)
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3084
diff changeset
   128
        elif appendanyway:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   129
            box.append(xml_escape(submenu.label))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   132
class SearchBox(component.CtxComponent):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    """display a box with a simple search form"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
   134
    __regid__ = 'search_box'
809
31962f99770b fix box selectors
sylvain.thenault@logilab.fr
parents: 742
diff changeset
   135
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
    title = _('search')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    order = 0
8183
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   138
    formdef = u"""<form action="%(action)s">
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   139
<table id="%(id)s"><tr><td>
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   140
<input class="norql" type="text" accesskey="q" tabindex="%(tabindex1)s" title="search text" value="%(value)s" name="rql" />
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
<input type="hidden" name="__fromsearchbox" value="1" />
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
<input type="hidden" name="subvid" value="tsearch" />
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
</td><td>
8183
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   144
<input tabindex="%(tabindex2)s" type="submit" class="rqlsubmit" value="" />
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   145
 </td></tr></table>
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   146
 </form>"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   148
    def render_title(self, w):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   149
        w(u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>"""
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   150
          % self._cw._(self.title))
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   151
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   152
    def render_body(self, w):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   153
        if self._cw.form.pop('__fromsearchbox', None):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   154
            rql = self._cw.form.get('rql', '')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
            rql = ''
8183
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   157
        tabidx1 = self._cw.next_tabindex()
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   158
        tabidx2 = self._cw.next_tabindex()
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   159
        w(self.formdef % {'action': self._cw.build_url('view'),
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   160
                          'value': xml_escape(rql),
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   161
                          'id': self.cw_extra_kwargs.get('domid', 'tsearch'),
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   162
                          'tabindex1': tabidx1,
7d658ea27ec5 [search box] allow to specify domid in select arguments. Closes #2162166
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   163
                          'tabindex2': tabidx2})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
# boxes disabled by default ###################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   168
class PossibleViewsBox(component.CtxComponent):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
    """display a box containing links to all possible views"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
   170
    __regid__ = 'possible_views_box'
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
   171
6668
d651bf5a66a9 [boxes] PossibleViewsBox is contextual, StartupViewsBox isn't
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6612
diff changeset
   172
    contextual = True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    title = _('possible views')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    order = 10
6668
d651bf5a66a9 [boxes] PossibleViewsBox is contextual, StartupViewsBox isn't
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6612
diff changeset
   175
    visible = False # disabled by default
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   177
    def init_rendering(self):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   178
        self.views = [v for v in self._cw.vreg['views'].possible_views(self._cw,
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   179
                                                                       rset=self.cw_rset)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   180
                      if v.category != 'startupview']
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   181
        if not self.views:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   182
            raise component.EmptyComponent()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   183
        self.items = []
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   184
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   185
    def render_body(self, w):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   186
        for category, views in box.sort_by_category(self.views):
7679
c4803e94b8a4 [boxes] 3.13.2 regression: should specify dom id else we may generate bad xhtml
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7670
diff changeset
   187
            menu = htmlwidgets.BoxMenu(self._cw._(category), ident=category)
613
e059279de6cf more cleanup
sylvain.thenault@logilab.fr
parents: 612
diff changeset
   188
            for view in views:
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6785
diff changeset
   189
                menu.append(self.action_link(view))
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   190
            self.append(menu)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   191
        self.render_items(w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
125
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 107
diff changeset
   193
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   194
class StartupViewsBox(PossibleViewsBox):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
    """display a box containing links to all startup views"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
   196
    __regid__ = 'startup_views_box'
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   197
6668
d651bf5a66a9 [boxes] PossibleViewsBox is contextual, StartupViewsBox isn't
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6612
diff changeset
   198
    contextual = False
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
    title = _('startup views')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
    order = 70
6668
d651bf5a66a9 [boxes] PossibleViewsBox is contextual, StartupViewsBox isn't
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6612
diff changeset
   201
    visible = False # disabled by default
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   203
    def init_rendering(self):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   204
        self.views = [v for v in self._cw.vreg['views'].possible_views(self._cw)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   205
                      if v.category == 'startupview']
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   206
        if not self.views:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   207
            raise component.EmptyComponent()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   208
        self.items = []
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
7670
6397a9051f65 [boxes] closes #1832844: translate views category in possible views boxes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6854
diff changeset
   210
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   211
class RsetBox(component.CtxComponent):
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   212
    """helper view class to display an rset in a sidebox"""
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   213
    __select__ = nonempty_rset() & match_kwargs('title', 'vid')
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   214
    __regid__ = 'rsetbox'
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   215
    cw_property_defs = {}
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   216
    context = 'incontext'
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   217
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   218
    @property
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   219
    def domid(self):
6785
c462147c9315 [boxes] add id of the rset to generated dom id of RsetBox to lower chance of id conflict (object id may be reused later)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6668
diff changeset
   220
        return super(RsetBox, self).domid + unicode(abs(id(self))) + unicode(abs(id(self.cw_rset)))
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   221
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   222
    def render_title(self, w):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   223
        w(self.cw_extra_kwargs['title'])
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   224
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   225
    def render_body(self, w):
6479
16a402e91a54 [primary] RsetBox view should give dispctrl & all to its subview. Also, don't use csv when in boxes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6409
diff changeset
   226
        if 'dispctrl' in self.cw_extra_kwargs:
16a402e91a54 [primary] RsetBox view should give dispctrl & all to its subview. Also, don't use csv when in boxes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6409
diff changeset
   227
            # XXX do not modify dispctrl!
16a402e91a54 [primary] RsetBox view should give dispctrl & all to its subview. Also, don't use csv when in boxes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6409
diff changeset
   228
            self.cw_extra_kwargs['dispctrl'].setdefault('subvid', 'outofcontext')
16a402e91a54 [primary] RsetBox view should give dispctrl & all to its subview. Also, don't use csv when in boxes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6409
diff changeset
   229
            self.cw_extra_kwargs['dispctrl'].setdefault('use_list_limit', 1)
16a402e91a54 [primary] RsetBox view should give dispctrl & all to its subview. Also, don't use csv when in boxes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6409
diff changeset
   230
        self._cw.view(self.cw_extra_kwargs['vid'], self.cw_rset, w=w,
16a402e91a54 [primary] RsetBox view should give dispctrl & all to its subview. Also, don't use csv when in boxes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6409
diff changeset
   231
                      initargs=self.cw_extra_kwargs)
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   232
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   233
 # helper classes ##############################################################
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   234
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   235
class SideBoxView(EntityView):
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   236
    """helper view class to display some entities in a sidebox"""
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   237
    __metaclass__ = class_deprecated
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   238
    __deprecation_warning__ = '[3.10] SideBoxView is deprecated, use RsetBox instead (%(cls)s)'
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   239
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
   240
    __regid__ = 'sidebox'
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
   241
6536
fd059ab1a502 [old boxes] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6526
diff changeset
   242
    def call(self, title=u'', **kwargs):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   243
        """display a list of entities by calling their <item_vid> view"""
6407
595e6807dda5 [primary view] default to outofcontext view for entities displayed in boxes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   244
        if 'dispctrl' in self.cw_extra_kwargs:
595e6807dda5 [primary view] default to outofcontext view for entities displayed in boxes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   245
            # XXX do not modify dispctrl!
595e6807dda5 [primary view] default to outofcontext view for entities displayed in boxes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   246
            self.cw_extra_kwargs['dispctrl'].setdefault('subvid', 'outofcontext')
6479
16a402e91a54 [primary] RsetBox view should give dispctrl & all to its subview. Also, don't use csv when in boxes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6409
diff changeset
   247
            self.cw_extra_kwargs['dispctrl'].setdefault('use_list_limit', 1)
6573
58f166d41420 [boxes] take care to duplicated 'title' argument if already specified in cw_extra_kwargs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6536
diff changeset
   248
        if title:
58f166d41420 [boxes] take care to duplicated 'title' argument if already specified in cw_extra_kwargs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6536
diff changeset
   249
            self.cw_extra_kwargs['title'] = title
6612
2f2871fbfb51 [3.10 bw compat] ensure context is specified, else crash on RsetBox
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6573
diff changeset
   250
        self.cw_extra_kwargs.setdefault('context', 'incontext')
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   251
        box = self._cw.vreg['ctxcomponents'].select(
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   252
            'rsetbox', self._cw, rset=self.cw_rset, vid='autolimited',
6573
58f166d41420 [boxes] take care to duplicated 'title' argument if already specified in cw_extra_kwargs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6536
diff changeset
   253
            **self.cw_extra_kwargs)
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   254
        box.render(self.w)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   255
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   256
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   257
class ContextualBoxLayout(component.Layout):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   258
    __select__ = match_context('incontext', 'left', 'right') & contextual()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   259
    # predefined class in cubicweb.css: contextualBox | contextFreeBox
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   260
    cssclass = 'contextualBox'
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   261
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   262
    def render(self, w):
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   263
        if self.init_rendering():
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   264
            view = self.cw_extra_kwargs['view']
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   265
            w(u'<div class="%s %s" id="%s">' % (self.cssclass, view.cssclass,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   266
                                                view.domid))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   267
            with wrap_on_write(w, u'<div class="boxTitle"><span>',
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   268
                               u'</span></div>') as wow:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   269
                view.render_title(wow)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   270
            w(u'<div class="boxBody">')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   271
            view.render_body(w)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   272
            # boxFooter div is a CSS place holder (for shadow for example)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   273
            w(u'</div><div class="boxFooter"></div></div>\n')
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   274
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   275
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   276
class ContextFreeBoxLayout(ContextualBoxLayout):
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   277
    __select__ = match_context('incontext', 'left', 'right') & ~contextual()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5839
diff changeset
   278
    cssclass = 'contextFreeBox'