web/views/boxes.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 25 Aug 2009 18:47:25 +0200
branch3.5
changeset 2993 2d06451013ac
parent 2920 64322aa83a1d
child 3084 096d680c9da2
permissions -rw-r--r--
[actions box] implements #344415, will have to take care to application relying on the old behaviour
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
generic boxes for CubicWeb web client:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
* actions box
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
* possible views box
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
additional (disabled by default) boxes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
* schema box
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
* startup views box
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
:organization: Logilab
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1876
diff changeset
    12
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1876
diff changeset
    14
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
__docformat__ = "restructuredtext en"
1876
b06a797448aa cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1848
diff changeset
    17
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2265
diff changeset
    19
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    21
from cubicweb.selectors import match_user_groups, non_final_entity
2265
4c028cb136a4 add import to remove deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    22
from cubicweb.view import EntityView
4c028cb136a4 add import to remove deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    23
from cubicweb.schema import display_name
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem
1285
d5ce82d65c2b for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    25
from cubicweb.web import uicfg
663
482d39578366 kill ExtResourcesBoxTemplate
sylvain.thenault@logilab.fr
parents: 635
diff changeset
    26
from cubicweb.web.box import BoxTemplate
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
    28
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
class EditBox(BoxTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
    box with all actions impacting the entity displayed: edit, copy, delete
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
    change state, add related entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    id = 'edit_box'
809
31962f99770b fix box selectors
sylvain.thenault@logilab.fr
parents: 742
diff changeset
    35
    __select__ = BoxTemplate.__select__ & non_final_entity()
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
    36
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
    title = _('actions')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    order = 2
1285
d5ce82d65c2b for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    39
    # class attributes below are actually stored in the uicfg module since we
d5ce82d65c2b for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    40
    # don't want them to be reloaded
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
    41
    appearsin_addmenu = uicfg.actionbox_appearsin_addmenu
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
    42
1247
3332c92d950c give view when selecting actions
sylvain.thenault@logilab.fr
parents: 1242
diff changeset
    43
    def call(self, view=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
        _ = self.req._
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        title = _(self.title)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        if self.rset:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
            etypes = self.rset.column_types(0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
            if len(etypes) == 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
                plural = self.rset.rowcount > 1 and 'plural' or ''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
                etypelabel = display_name(self.req, iter(etypes).next(), plural)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
                title = u'%s - %s' % (title, etypelabel.lower())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        box = BoxWidget(title, self.id, _class="greyBoxFrame")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        # build list of actions
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2443
diff changeset
    54
        actions = self.vreg['actions'].possible_actions(self.req, self.rset,
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2443
diff changeset
    55
                                                        view=view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        add_menu = BoxMenu(_('add')) # 'addrelated' category
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
        other_menu = BoxMenu(_('more actions')) # 'moreactions' category
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        searchstate = self.req.search_state[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
        for category, menu in (('mainactions', box),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
                               ('addrelated', add_menu),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
                               ('moreactions', other_menu)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
            for action in actions.get(category, ()):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
                menu.append(self.box_action(action))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
        if self.rset and self.rset.rowcount == 1 and \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
               not self.schema[self.rset.description[0][0]].is_final() and \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
               searchstate == 'normal':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
            entity = self.rset.get_entity(0, 0)
2993
2d06451013ac [actions box] implements #344415, will have to take care to application relying on the old behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    68
            for action in self.schema_actions(entity):
2d06451013ac [actions box] implements #344415, will have to take care to application relying on the old behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    69
                add_menu.append(action)
185
9fc69c46e5e7 EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 143
diff changeset
    70
            self.workflow_actions(entity, box)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        if box.is_empty() and not other_menu.is_empty():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
            box.items = other_menu.items
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
            other_menu.items = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
        self.add_submenu(box, add_menu, _('add'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        self.add_submenu(box, other_menu)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        if not box.is_empty():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
            box.render(self.w)
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
    78
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    def add_submenu(self, box, submenu, label_prefix=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
        if len(submenu.items) == 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
            boxlink = submenu.items[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
            if label_prefix:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
                boxlink.label = u'%s %s' % (label_prefix, boxlink.label)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
            box.append(boxlink)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        elif submenu.items:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
            box.append(submenu)
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
    87
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
    def schema_actions(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        user = self.req.user
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        actions = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        _ = self.req._
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        eschema = entity.e_schema
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
    93
        for rschema, teschema, x in self.add_related_schemas(entity):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
            if x == 'subject':
1848
981b8dc9e4d0 fix i18n msgstr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1752
diff changeset
    95
                label = 'add %s %s %s %s' % (eschema, rschema, teschema, x)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
                url = self.linkto_url(entity, rschema, teschema, 'object')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
            else:
1848
981b8dc9e4d0 fix i18n msgstr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1752
diff changeset
    98
                label = 'add %s %s %s %s' % (teschema, rschema, eschema, x)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
                url = self.linkto_url(entity, rschema, teschema, 'subject')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
            actions.append(self.mk_action(_(label), url))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
        return actions
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
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
   103
    def add_related_schemas(self, entity):
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
   104
        """this is actually used ui method to generate 'addrelated' actions from
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
   105
        the schema.
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
   106
2993
2d06451013ac [actions box] implements #344415, will have to take care to application relying on the old behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   107
        If you don't want any auto-generated actions, you should overrides this
2d06451013ac [actions box] implements #344415, will have to take care to application relying on the old behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   108
        method to return an empty list. If you only want some, you can configure
2d06451013ac [actions box] implements #344415, will have to take care to application relying on the old behaviour
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   109
        them by using uicfg.actionbox_appearsin_addmenu
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
   110
        """
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
   111
        req = self.req
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
   112
        eschema = entity.e_schema
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
   113
        for role, rschemas in (('subject', eschema.subject_relations()),
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
   114
                               ('object', eschema.object_relations())):
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
   115
            for rschema in rschemas:
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
   116
                if rschema.is_final():
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
   117
                    continue
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
   118
                # check the relation can be added as well
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
   119
                # XXX consider autoform_permissions_overrides?
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
   120
                if role == 'subject'and not rschema.has_perm(req, 'add',
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
   121
                                                             fromeid=entity.eid):
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
   122
                    continue
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
   123
                if role == 'object'and not rschema.has_perm(req, 'add',
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
   124
                                                            toeid=entity.eid):
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
   125
                    continue
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
   126
                # check the target types can be added as well
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
   127
                for teschema in rschema.targets(eschema, role):
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
   128
                    if not self.appearsin_addmenu.etype_get(eschema, rschema,
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1732
diff changeset
   129
                                                            role, teschema):
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
   130
                        continue
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
   131
                    if teschema.has_local_role('add') or teschema.has_perm(req, 'add'):
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
   132
                        yield rschema, teschema, role
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
   133
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
185
9fc69c46e5e7 EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 143
diff changeset
   135
    def workflow_actions(self, entity, box):
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   136
        if entity.e_schema.has_subject_relation('in_state') and entity.in_state:
399
8df3b190275b don't use global _
sylvain.thenault@logilab.fr
parents: 185
diff changeset
   137
            _ = self.req._
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   138
            menu_title = u'%s: %s' % (_('state'), entity.printable_state)
2443
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   139
            menu_items = []
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   140
            for tr in entity.possible_transitions():
2443
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   141
                url = entity.absolute_url(vid='statuschange', treid=tr.eid)
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   142
                menu_items.append(self.mk_action(_(tr.name), url))
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   143
            wfurl = self.build_url('cwetype/%s'%entity.e_schema, vid='workflow')
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   144
            menu_items.append(self.mk_action(_('view workflow'), wfurl))
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   145
            wfurl = entity.absolute_url(vid='wfhistory')
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   146
            menu_items.append(self.mk_action(_('view history'), wfurl))
b36f759bd2cc #343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   147
            box.append(BoxMenu(menu_title, menu_items))
185
9fc69c46e5e7 EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 143
diff changeset
   148
        return None
9fc69c46e5e7 EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 143
diff changeset
   149
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
    def linkto_url(self, entity, rtype, etype, target):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
        return self.build_url(vid='creation', etype=etype,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
                              __linkto='%s:%s:%s' % (rtype, entity.eid, target),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
                              __redirectpath=entity.rest_path(), # should not be url quoted!
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
                              __redirectvid=self.req.form.get('vid', ''))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
class SearchBox(BoxTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
    """display a box with a simple search form"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
    id = 'search_box'
809
31962f99770b fix box selectors
sylvain.thenault@logilab.fr
parents: 742
diff changeset
   160
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
    visible = True # enabled by default
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
    title = _('search')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
    order = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
    formdef = u"""<form action="%s">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
<table id="tsearch"><tr><td>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
<input id="norql" type="text" accesskey="q" tabindex="%s" title="search text" value="%s" name="rql" />
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
<input type="hidden" name="__fromsearchbox" value="1" />
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
<input type="hidden" name="subvid" value="tsearch" />
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
</td><td>
852
105893288777 simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 536
diff changeset
   170
<input tabindex="%s" type="submit" id="rqlboxsubmit" class="rqlsubmit" value="" />
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
</td></tr></table>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
</form>"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    def call(self, view=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
        req = self.req
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
        if req.form.pop('__fromsearchbox', None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
            rql = req.form.get('rql', '')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
            rql = ''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
        form = self.formdef % (req.build_url('view'), req.next_tabindex(),
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2265
diff changeset
   181
                               xml_escape(rql), req.next_tabindex())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
        box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
        box.append(BoxHtml(form))
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
   185
        box.render(self.w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
# boxes disabled by default ###################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
class PossibleViewsBox(BoxTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
    """display a box containing links to all possible views"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
    id = 'possible_views_box'
809
31962f99770b fix box selectors
sylvain.thenault@logilab.fr
parents: 742
diff changeset
   193
    __select__ = BoxTemplate.__select__ & match_user_groups('users', 'managers')
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
   194
809
31962f99770b fix box selectors
sylvain.thenault@logilab.fr
parents: 742
diff changeset
   195
    visible = False
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
    title = _('possible views')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    order = 10
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        box = BoxWidget(self.req._(self.title), self.id)
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2443
diff changeset
   201
        views = [v for v in self.vreg['views'].possible_views(self.req,
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2443
diff changeset
   202
                                                              rset=self.rset)
613
e059279de6cf more cleanup
sylvain.thenault@logilab.fr
parents: 612
diff changeset
   203
                 if v.category != 'startupview']
e059279de6cf more cleanup
sylvain.thenault@logilab.fr
parents: 612
diff changeset
   204
        for category, views in self.sort_actions(views):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
            menu = BoxMenu(category)
613
e059279de6cf more cleanup
sylvain.thenault@logilab.fr
parents: 612
diff changeset
   206
            for view in views:
e059279de6cf more cleanup
sylvain.thenault@logilab.fr
parents: 612
diff changeset
   207
                menu.append(self.box_action(view))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
            box.append(menu)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
        if not box.is_empty():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
            box.render(self.w)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
125
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 107
diff changeset
   212
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
class StartupViewsBox(BoxTemplate):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
    """display a box containing links to all startup views"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
    id = 'startup_views_box'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
    visible = False # disabled by default
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
    title = _('startup views')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
    order = 70
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
        box = BoxWidget(self.req._(self.title), self.id)
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2443
diff changeset
   222
        for view in self.vreg['views'].possible_views(self.req, None):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
            if view.category == 'startupview':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
                box.append(self.box_action(view))
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
   225
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
        if not box.is_empty():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
            box.render(self.w)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
1263
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 1181 1247
diff changeset
   229
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   230
# helper classes ##############################################################
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   231
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   232
class SideBoxView(EntityView):
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   233
    """helper view class to display some entities in a sidebox"""
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   234
    id = 'sidebox'
1450
8edb0806dde4 fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents: 1285
diff changeset
   235
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   236
    def call(self, boxclass='sideBox', title=u''):
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   237
        """display a list of entities by calling their <item_vid> view"""
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   238
        if title:
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   239
            self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % title)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   240
        self.w(u'<div class="%s"><div class="sideBoxBody">' % boxclass)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   241
        # if not too much entities, show them all in a list
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   242
        maxrelated = self.req.property_value('navigation.related-limit')
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   243
        if self.rset.rowcount <= maxrelated:
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   244
            if len(self.rset) == 1:
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   245
                self.wview('incontext', self.rset, row=0)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   246
            elif 1 < len(self.rset) < 5:
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   247
                self.wview('csv', self.rset)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   248
            else:
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   249
                self.wview('simplelist', self.rset)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   250
        # else show links to display related entities
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   251
        else:
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   252
            self.rset.limit(maxrelated)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   253
            rql = self.rset.printable_rql(encoded=False)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   254
            self.wview('simplelist', self.rset)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   255
            self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql),
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   256
                                               self.req._('see them all')))
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 811
diff changeset
   257
        self.w(u'</div>\n</div>\n')