web/views/editforms.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 11 Jan 2010 14:13:26 +0100
branchstable
changeset 4219 87203a0a3a81
parent 4212 ab6573088b4a
child 4238 b8ea99f5e8ea
permissions -rw-r--r--
do not attempt to daemonize under windows
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
"""Set of HTML automatic forms to create, delete, copy or edit a single entity
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
or a list of entities of the same type
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
:organization: Logilab
4212
ab6573088b4a update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3953
diff changeset
     5
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
: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: 1965
diff changeset
     7
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
"""
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
__docformat__ = "restructuredtext en"
1965
34f57246330d cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1852
diff changeset
    10
_ = unicode
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    12
from copy import copy
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    13
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
from simplejson import dumps
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2247
diff changeset
    16
from logilab.mtconverter import xml_escape
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
    17
from logilab.common.decorators import cached
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    18
3532
df045bc51d00 [inlined forms] nicer add_hiddens implementation relying on standard entity forms handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3518
diff changeset
    19
from cubicweb import neg_role
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    20
from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    21
                                specified_etype_implements, yes)
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    22
from cubicweb.view import EntityView
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
from cubicweb.common import tags
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
    24
from cubicweb.web import stdmsgs, eid_param
3078
186ccbe0ba3f missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3077
diff changeset
    25
from cubicweb.web import uicfg
2672
c66f52d44394 [reledit] don't try to use rel-edit on attributes without assicated fields (e.g _format field)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2576
diff changeset
    26
from cubicweb.web.form import FormViewMixIn, FieldNotFound
2328
206735882b8e [reledit] use guess_field, thus fixing select widget lacking a multiple attr. in case of * cardinality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2327
diff changeset
    27
from cubicweb.web.formfields import guess_field
206735882b8e [reledit] use guess_field, thus fixing select widget lacking a multiple attr. in case of * cardinality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2327
diff changeset
    28
from cubicweb.web.formwidgets import Button, SubmitButton, ResetButton
2005
e8032965f37a turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1995
diff changeset
    29
from cubicweb.web.views import forms
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents: 1459
diff changeset
    30
3927
b2a6c25b8429 consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3880
diff changeset
    31
_pvdc = uicfg.primaryview_display_ctrl
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    33
def relation_id(eid, rtype, role, reid):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    34
    """return an identifier for a relation between two entities"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    35
    if role == 'subject':
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    36
        return u'%s:%s:%s' % (eid, rtype, reid)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    37
    return u'%s:%s:%s' % (reid, rtype, eid)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
    38
1528
864ae7c15ef5 other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1498
diff changeset
    39
def toggleable_relation_link(eid, nodeid, label='x'):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    40
    """return javascript snippet to delete/undelete a relation between two
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    41
    entities
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    42
    """
1320
c85f4d8eff8b cleanup
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
    43
    js = u"javascript: togglePendingDelete('%s', %s);" % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2247
diff changeset
    44
        nodeid, xml_escape(dumps(eid)))
1320
c85f4d8eff8b cleanup
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
    45
    return u'[<a class="handle" href="%s" id="handle%s">%s</a>]' % (
c85f4d8eff8b cleanup
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
    46
        js, nodeid, label)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    49
class DeleteConfForm(forms.CompositeForm):
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    50
    id = 'deleteconf'
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    51
    __select__ = non_final_entity()
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    52
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    53
    domid = 'deleteconf'
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    54
    copy_nav_params = True
3803
414bb8439002 [web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3800
diff changeset
    55
    form_buttons = [Button(stdmsgs.BUTTON_DELETE, cwaction='delete'),
414bb8439002 [web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3800
diff changeset
    56
                    Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')]
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    57
    @property
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    58
    def action(self):
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    59
        return self.build_url('edit')
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    60
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    61
    def __init__(self, *args, **kwargs):
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    62
        super(DeleteConfForm, self).__init__(*args, **kwargs)
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    63
        done = set()
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    64
        for entity in self.rset.entities():
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    65
            if entity.eid in done:
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    66
                continue
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    67
            done.add(entity.eid)
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: 2576
diff changeset
    68
            subform = self.vreg['forms'].select('base', self.req, entity=entity,
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: 2576
diff changeset
    69
                                                mainform=False)
3513
c002f6488631 [form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3355
diff changeset
    70
            self.add_subform(subform)
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    71
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    72
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    73
class DeleteConfFormView(FormViewMixIn, EntityView):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    74
    """form used to confirm deletion of some entities"""
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
    id = 'deleteconf'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
    title = _('delete')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
    # don't use navigation, all entities asked to be deleted should be displayed
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
    # else we will only delete the displayed page
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
    need_navigation = False
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
    80
1852
f04da596da6c give back onsubmit customizability (oops)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1847
diff changeset
    81
    def call(self, onsubmit=None):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
        """ask for confirmation before real deletion"""
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
        req, w = self.req, self.w
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
        _ = req._
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
        w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
          % _('this action is not reversible!'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
        # XXX above message should have style of a warning
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
        w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?'))
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: 2576
diff changeset
    89
        form = self.vreg['forms'].select(self.id, req, rset=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: 2576
diff changeset
    90
                                         onsubmit=onsubmit)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
        w(u'<ul>\n')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    92
        for entity in self.rset.entities():
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    93
            # don't use outofcontext view or any other that may contain inline edition form
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
            w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    95
                                      href=entity.absolute_url()))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
        w(u'</ul>\n')
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
    97
        w(form.render())
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    99
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   100
class ClickAndEditFormView(FormViewMixIn, EntityView):
2686
c700ace6ebfd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2679
diff changeset
   101
    """form used to permit ajax edition of a relation or attribute of an entity
c700ace6ebfd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2679
diff changeset
   102
    in a view, if logged user have the permission to edit it.
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   103
2686
c700ace6ebfd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2679
diff changeset
   104
    (double-click on the field to see an appropriate edition widget).
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   105
    """
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   106
    id = 'doreledit'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   107
    __select__ = non_final_entity() & match_kwargs('rtype')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   108
    # FIXME editableField class could be toggleable from userprefs
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   109
2504
f28b1ffc3c91 some reledit fixes: actually needs metadata in form's attrcategories, check autoform_section for attributes (XXX need check for relation), no <not specified> visible when attribute isn't editable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2484
diff changeset
   110
    # add metadata to allow edition of metadata attributes (not considered by
f28b1ffc3c91 some reledit fixes: actually needs metadata in form's attrcategories, check autoform_section for attributes (XXX need check for relation), no <not specified> visible when attribute isn't editable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2484
diff changeset
   111
    # edition form by default)
f28b1ffc3c91 some reledit fixes: actually needs metadata in form's attrcategories, check autoform_section for attributes (XXX need check for relation), no <not specified> visible when attribute isn't editable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2484
diff changeset
   112
    attrcategories = ('primary', 'secondary', 'metadata')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   113
2365
9f5e911eab07 [reledit] allow composite edition if the composite is object
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2361
diff changeset
   114
    _onclick = u"showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')"
3742
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   115
    _onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   116
                 "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');")
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   117
    _cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')"
3800
2d951200f898 [web ui] fix the editable fields: better look and behaviour.
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3793
diff changeset
   118
    _defaultlandingzone = (u'<img title="%(msg)s" src="data/pen_icon.png" '
2484
7e9283731db8 [reledit] a nicer icon
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2483
diff changeset
   119
                           'alt="%(msg)s"/>')
2335
b78249be8a4b [reledit] fix reload type (was a string), use simple clicks instead of doubles
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2334
diff changeset
   120
    _landingzonemsg = _('click to edit this field')
2332
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   121
    # default relation vids according to cardinality
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   122
    _one_rvid = 'incontext'
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   123
    _many_rvid = 'csv'
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   124
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   125
2329
8b5a1af6dc35 [reledit] small cleanup and add escape param to control xml_escapability of the value, also rename vid arg which clashes with entity.view(...) args
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2328
diff changeset
   126
    def cell_call(self, row, col, rtype=None, role='subject',
2336
a15d3f54f0f2 [reledit] left in by accident
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2335
diff changeset
   127
                  reload=False,      # controls reloading the whole page after change
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   128
                  rvid=None,         # vid to be applied to other side of rtype (non final relations only)
2332
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   129
                  default=None,      # default value
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   130
                  landing_zone=None  # prepend value with a separate html element to click onto
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   131
                                     # (esp. needed when values are links)
2329
8b5a1af6dc35 [reledit] small cleanup and add escape param to control xml_escapability of the value, also rename vid arg which clashes with entity.view(...) args
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2328
diff changeset
   132
                  ):
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   133
        """display field to edit entity's `rtype` relation on click"""
2329
8b5a1af6dc35 [reledit] small cleanup and add escape param to control xml_escapability of the value, also rename vid arg which clashes with entity.view(...) args
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2328
diff changeset
   134
        assert rtype
3742
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   135
        assert role in ('subject', 'object'), '%s is not an acceptable role value' % role
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   136
        self.req.add_js('cubicweb.edition.js')
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   137
        self.req.add_css('cubicweb.form.css')
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   138
        if default is None:
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   139
            default = xml_escape(self.req._('<no value>'))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   140
        entity = self.entity(row, col)
2332
b04d80f19075 [reledit] try to be smart at getting a good default vid for relations, factor computing cardinality from reledit and formfields
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2331
diff changeset
   141
        rschema = entity.schema.rschema(rtype)
2482
dead2d56f711 [reledit] attributes : have a laning zone after all (less intrusive), fix likely bug of relation edition
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2392
diff changeset
   142
        lzone = self._build_landing_zone(landing_zone)
2333
1de22d3e985b [reledit] landing zone useful only for relations; cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2332
diff changeset
   143
        # compute value, checking perms, build form
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3643
diff changeset
   144
        if rschema.final:
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   145
            form = self._build_form(entity, rtype, role, 'edition', default, reload, lzone,
3742
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   146
                                    attrcategories=self.attrcategories)
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   147
            if not self.should_edit_attribute(entity, rschema, role, form):
3643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3636
diff changeset
   148
                self.w(entity.printable_value(rtype))
2224
52041b014949 fix #344046 and #344322: check relation permission, set to default when edition allowed and no value (for final *and* non final relations)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2049
diff changeset
   149
                return
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   150
            value = entity.printable_value(rtype) or default
3742
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   151
            self.relation_form(lzone, value, form,
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   152
                               self._build_renderer(entity, rtype, role))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
        else:
3927
b2a6c25b8429 consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3880
diff changeset
   154
            rvid = self._compute_best_vid(entity.e_schema, rschema, role)
1579
4eea314694e2 apply on non final relation
sylvain.thenault@logilab.fr
parents: 1576
diff changeset
   155
            rset = entity.related(rtype, role)
2504
f28b1ffc3c91 some reledit fixes: actually needs metadata in form's attrcategories, check autoform_section for attributes (XXX need check for relation), no <not specified> visible when attribute isn't editable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2484
diff changeset
   156
            if rset:
f28b1ffc3c91 some reledit fixes: actually needs metadata in form's attrcategories, check autoform_section for attributes (XXX need check for relation), no <not specified> visible when attribute isn't editable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2484
diff changeset
   157
                value = self.view(rvid, rset)
f28b1ffc3c91 some reledit fixes: actually needs metadata in form's attrcategories, check autoform_section for attributes (XXX need check for relation), no <not specified> visible when attribute isn't editable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2484
diff changeset
   158
            else:
f28b1ffc3c91 some reledit fixes: actually needs metadata in form's attrcategories, check autoform_section for attributes (XXX need check for relation), no <not specified> visible when attribute isn't editable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2484
diff changeset
   159
                value = default
3636
9b16e7b6ba35 [reledit] display value anyway when should not edit attribute/relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3627
diff changeset
   160
            if not self.should_edit_relation(entity, rschema, role, rvid):
9b16e7b6ba35 [reledit] display value anyway when should not edit attribute/relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3627
diff changeset
   161
                if rset:
9b16e7b6ba35 [reledit] display value anyway when should not edit attribute/relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3627
diff changeset
   162
                    self.w(value)
9b16e7b6ba35 [reledit] display value anyway when should not edit attribute/relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3627
diff changeset
   163
                return
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   164
            form = self._build_form(entity, rtype, role, 'base', default, reload, lzone,
3742
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3689
diff changeset
   165
                                    dict(vid=rvid, lzone=lzone))
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   166
            field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   167
            form.append_field(field)
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   168
            self.relation_form(lzone, value, form,
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   169
                               self._build_renderer(entity, rtype, role))
2365
9f5e911eab07 [reledit] allow composite edition if the composite is object
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2361
diff changeset
   170
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   171
    def should_edit_attribute(self, entity, rschema, role, form):
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   172
        rtype = str(rschema)
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   173
        ttype = rschema.targets(entity.id, role)[0]
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   174
        afs = uicfg.autoform_section.etype_get(entity.id, rtype, role, ttype)
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   175
        if not (afs in self.attrcategories and entity.has_perm('update')):
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   176
            return False
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   177
        try:
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   178
            form.field_by_name(rtype, role)
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   179
        except FieldNotFound:
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   180
            return False
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   181
        return True
1759
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1750
diff changeset
   182
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   183
    def should_edit_relation(self, entity, rschema, role, rvid):
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   184
        if ((role == 'subject' and not rschema.has_perm(self.req, 'add',
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   185
                                                        fromeid=entity.eid))
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   186
            or
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   187
            (role == 'object' and not rschema.has_perm(self.req, 'add',
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   188
                                                       toeid=entity.eid))):
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   189
            return False
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   190
        return True
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   191
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   192
    def relation_form(self, lzone, value, form, renderer):
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   193
        """xxx-reledit div (class=field)
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   194
              +-xxx div (class="editableField")
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   195
              |   +-landing zone
3767
03924de0014d reledit: stuff the value into its own div and properly hide it when necessary (but dont lump it with the landingzone div for it switches the form on when one clicks on a value to traverse it)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3761
diff changeset
   196
              +-xxx-value div
03924de0014d reledit: stuff the value into its own div and properly hide it when necessary (but dont lump it with the landingzone div for it switches the form on when one clicks on a value to traverse it)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3761
diff changeset
   197
              +-xxx-form div
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   198
        """
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   199
        w = self.w
3767
03924de0014d reledit: stuff the value into its own div and properly hide it when necessary (but dont lump it with the landingzone div for it switches the form on when one clicks on a value to traverse it)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3761
diff changeset
   200
        divid = form.event_args['divid']
3800
2d951200f898 [web ui] fix the editable fields: better look and behaviour.
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3793
diff changeset
   201
        w(u'<div id="%s-reledit" class="field" '
2d951200f898 [web ui] fix the editable fields: better look and behaviour.
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3793
diff changeset
   202
          u'onmouseout="addElementClass(jQuery(\'#%s\'), \'hidden\')" '
2d951200f898 [web ui] fix the editable fields: better look and behaviour.
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3793
diff changeset
   203
          u'onmouseover="removeElementClass(jQuery(\'#%s\'), \'hidden\')">'
2d951200f898 [web ui] fix the editable fields: better look and behaviour.
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3793
diff changeset
   204
          % (divid, divid, divid))
2d951200f898 [web ui] fix the editable fields: better look and behaviour.
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3793
diff changeset
   205
        w(u'<div id="%s-value" class="editableFieldValue">%s</div>' % (divid, value))
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   206
        w(form.render(renderer=renderer))
3800
2d951200f898 [web ui] fix the editable fields: better look and behaviour.
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3793
diff changeset
   207
        w(u'<div id="%s" class="editableField hidden" onclick="%s" title="%s">' % (
3767
03924de0014d reledit: stuff the value into its own div and properly hide it when necessary (but dont lump it with the landingzone div for it switches the form on when one clicks on a value to traverse it)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3761
diff changeset
   208
                divid, xml_escape(self._onclick % form.event_args),
3761
2c3b72faf05d small cleanup & revert to less intrusive icon
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3760
diff changeset
   209
                self.req._(self._landingzonemsg)))
2c3b72faf05d small cleanup & revert to less intrusive icon
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3760
diff changeset
   210
        w(lzone)
3760
9d93faa0e6dc actually hide the value when editing, cleanup spurious arg
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3756
diff changeset
   211
        w(u'</div>')
2482
dead2d56f711 [reledit] attributes : have a laning zone after all (less intrusive), fix likely bug of relation edition
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2392
diff changeset
   212
        w(u'</div>')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   213
3745
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   214
    def _compute_best_vid(self, eschema, rschema, role):
3927
b2a6c25b8429 consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3880
diff changeset
   215
        dispctrl = _pvdc.etype_get(eschema, rschema, role)
b2a6c25b8429 consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3880
diff changeset
   216
        if dispctrl.get('rvid'):
b2a6c25b8429 consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3880
diff changeset
   217
            return dispctrl['rvid']
3745
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   218
        if eschema.cardinality(rschema, role) in '+*':
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   219
            return self._many_rvid
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   220
        return self._one_rvid
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   221
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   222
    def _build_landing_zone(self, lzone):
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   223
        return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))}
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   224
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   225
    def _build_renderer(self, entity, rtype, role):
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   226
        return self.vreg['formrenderers'].select(
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   227
            'base', self.req, entity=entity, display_label=False,
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   228
            display_help=False, display_fields=[(rtype, role)], table_class='',
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   229
            button_bar_class='buttonbar', display_progress_div=False)
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   230
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   231
    def _build_args(self, entity, rtype, role, formid, default, reload, lzone,
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   232
                    extradata=None):
3748
7143198dd8a4 node ids shall not begin with a number
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3745
diff changeset
   233
        divid = '%s-%s-%s' % (rtype, role, entity.eid)
3745
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   234
        event_args = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype,
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   235
                      'reload' : dumps(reload), 'default' : default, 'role' : role, 'vid' : u'',
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   236
                      'lzone' : lzone}
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   237
        if extradata:
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   238
            event_args.update(extradata)
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   239
        return divid, event_args
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   240
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   241
    def _build_form(self, entity, rtype, role, formid, default, reload, lzone,
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   242
                  extradata=None, **formargs):
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   243
        divid, event_args = self._build_args(entity, rtype, role, formid, default,
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   244
                                      reload, lzone, extradata)
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   245
        onsubmit = self._onsubmit % event_args
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   246
        cancelclick = self._cancelclick % (entity.eid, rtype, divid)
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   247
        form = self.vreg['forms'].select(
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   248
            formid, self.req, entity=entity, domid='%s-form' % divid,
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   249
            cssstyle='display: none', onsubmit=onsubmit, action='#',
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   250
            form_buttons=[SubmitButton(), Button(stdmsgs.BUTTON_CANCEL,
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   251
                                                 onclick=cancelclick)],
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   252
            **formargs)
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   253
        form.event_args = event_args
006c81b94ec5 move these definitions below cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3744
diff changeset
   254
        return form
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   255
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   256
class DummyForm(object):
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   257
    __slots__ = ('event_args',)
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   258
    def form_render(self, **_args):
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   259
        return u''
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   260
    def render(self, **_args):
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   261
        return u''
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   262
    def append_field(self, *args):
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   263
        pass
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   264
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   265
class AutoClickAndEditFormView(ClickAndEditFormView):
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   266
    """same as ClickAndEditFormView but checking if the view *should* be applied
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   267
    by checking uicfg configuration and composite relation property.
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   268
    """
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   269
    id = 'reledit'
3760
9d93faa0e6dc actually hide the value when editing, cleanup spurious arg
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3756
diff changeset
   270
    _onclick = (u"loadInlineEditionForm(%(eid)s, '%(rtype)s', '%(role)s', "
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   271
                "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');")
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   272
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   273
    def should_edit_attribute(self, entity, rschema, role, _form):
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   274
        rtype = str(rschema)
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   275
        ttype = rschema.targets(entity.id, role)[0]
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   276
        afs = uicfg.autoform_section.etype_get(entity.id, rtype, role, ttype)
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   277
        if not (afs in self.attrcategories and entity.has_perm('update')):
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   278
            return False
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   279
        return True
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   280
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   281
    def should_edit_relation(self, entity, rschema, role, rvid):
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   282
        eschema = entity.e_schema
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   283
        rtype = str(rschema)
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   284
        # XXX check autoform_section. what if 'generic'?
3927
b2a6c25b8429 consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3880
diff changeset
   285
        dispctrl = _pvdc.etype_get(eschema, rtype, role)
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   286
        vid = dispctrl.get('vid', 'reledit')
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   287
        if vid != 'reledit': # reledit explicitly disabled
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   288
            return False
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   289
        if eschema.role_rproperty(role, rschema, 'composite') == role:
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   290
            return False
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   291
        return super(AutoClickAndEditFormView, self).should_edit_relation(
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   292
            entity, rschema, role, rvid)
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   293
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   294
    def _build_form(self, entity, rtype, role, formid, default, reload, lzone,
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   295
                  extradata=None, **formargs):
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   296
        _divid, event_args = self._build_args(entity, rtype, role, formid, default,
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   297
                                              reload, lzone, extradata)
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   298
        form = DummyForm()
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   299
        form.event_args = event_args
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   300
        return form
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   301
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   302
    def _build_renderer(self, entity, rtype, role):
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   303
        pass
2679
3fa8c0cec760 [reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2678
diff changeset
   304
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   305
class EditionFormView(FormViewMixIn, EntityView):
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   306
    """display primary entity edition form"""
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   307
    id = 'edition'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   308
    # add yes() so it takes precedence over deprecated views in baseforms,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   309
    # though not baseforms based customized view
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   310
    __select__ = one_line_rset() & non_final_entity() & yes()
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   311
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   312
    title = _('edition')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   313
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   314
    def cell_call(self, row, col, **kwargs):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   315
        entity = self.complete_entity(row, col)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   316
        self.render_form(entity)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   317
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   318
    def render_form(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   319
        """fetch and render the form"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   320
        self.form_title(entity)
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: 2576
diff changeset
   321
        form = self.vreg['forms'].select('edition', self.req, rset=entity.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: 2576
diff changeset
   322
                                         row=entity.row, col=entity.col, entity=entity,
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: 2576
diff changeset
   323
                                         submitmsg=self.submited_message())
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   324
        self.init_form(form, entity)
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   325
        self.w(form.render(rendervalues=dict(formvid=u'edition')))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   326
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   327
    def init_form(self, form, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   328
        """customize your form before rendering here"""
2049
b9baedffeb8b set __maineid in EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2048
diff changeset
   329
        pass
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   330
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   331
    def form_title(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   332
        """the form view title"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   333
        ptitle = self.req._(self.title)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   334
        self.w(u'<div class="formTitle"><span>%s %s</span></div>' % (
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   335
            entity.dc_type(), ptitle and '(%s)' % ptitle))
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   336
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   337
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   338
        """return the message that will be displayed on successful edition"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   339
        return self.req._('entity edited')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   340
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   341
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   342
class CreationFormView(EditionFormView):
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   343
    """display primary entity creation form"""
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   344
    id = 'creation'
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   345
    __select__ = specified_etype_implements('Any') & yes()
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   346
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   347
    title = _('creation')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   348
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   349
    def call(self, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   350
        """creation view for an entity"""
3346
b1fd9d4ef579 fix case insensitive selector for entity creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3331
diff changeset
   351
        # at this point we know etype is a valid entity type, thanks to our
b1fd9d4ef579 fix case insensitive selector for entity creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3331
diff changeset
   352
        # selector
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   353
        etype = kwargs.pop('etype', self.req.form.get('etype'))
3077
6c92323667a6 case insensitive add/XXX url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3062
diff changeset
   354
        entity = self.vreg['etypes'].etype_class(etype)(self.req)
6c92323667a6 case insensitive add/XXX url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3062
diff changeset
   355
        self.initialize_varmaker()
6c92323667a6 case insensitive add/XXX url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3062
diff changeset
   356
        entity.eid = self.varmaker.next()
6c92323667a6 case insensitive add/XXX url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3062
diff changeset
   357
        self.render_form(entity)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   358
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   359
    def form_title(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   360
        """the form view title"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   361
        if '__linkto' in self.req.form:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   362
            if isinstance(self.req.form['__linkto'], list):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   363
                # XXX which one should be considered (case: add a ticket to a
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   364
                # version in jpl)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   365
                rtype, linkto_eid, role = self.req.form['__linkto'][0].split(':')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   366
            else:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   367
                rtype, linkto_eid, role = self.req.form['__linkto'].split(':')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   368
            linkto_rset = self.req.eid_rset(linkto_eid)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   369
            linkto_type = linkto_rset.description[0][0]
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   370
            if role == 'subject':
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   371
                title = self.req.__('creating %s (%s %s %s %%(linkto)s)' % (
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   372
                    entity.e_schema, entity.e_schema, rtype, linkto_type))
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   373
            else:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   374
                title = self.req.__('creating %s (%s %%(linkto)s %s %s)' % (
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   375
                    entity.e_schema, linkto_type, rtype, entity.e_schema))
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   376
            msg = title % {'linkto' : self.view('incontext', linkto_rset)}
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   377
            self.w(u'<div class="formTitle notransform"><span>%s</span></div>' % msg)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   378
        else:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   379
            super(CreationFormView, self).form_title(entity)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   380
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   381
    def url(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   382
        """return the url associated with this view"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   383
        return self.create_url(self.req.form.get('etype'))
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   384
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   385
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   386
        """return the message that will be displayed on successful edition"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   387
        return self.req._('entity created')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   388
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   389
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   390
class CopyFormView(EditionFormView):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   391
    """display primary entity creation form initialized with values from another
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   392
    entity
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   393
    """
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   394
    id = 'copy'
3627
70dbba754c11 fix title of CopyFormView
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 3586
diff changeset
   395
    title = _('copy')
3062
a8e901fc4457 ease overriding of copy warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2686
diff changeset
   396
    warning_message = _('Please note that this is only a shallow copy')
a8e901fc4457 ease overriding of copy warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2686
diff changeset
   397
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   398
    def render_form(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   399
        """fetch and render the form"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   400
        # make a copy of entity to avoid altering the entity in the
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   401
        # request's cache.
1685
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   402
        entity.complete()
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   403
        self.newentity = copy(entity)
1703
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   404
        self.copying = entity
1685
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   405
        self.initialize_varmaker()
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   406
        self.newentity.eid = self.varmaker.next()
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   407
        self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n'
3062
a8e901fc4457 ease overriding of copy warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2686
diff changeset
   408
               % self.req._(self.warning_message))
1685
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   409
        super(CopyFormView, self).render_form(self.newentity)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   410
        del self.newentity
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   411
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   412
    def init_form(self, form, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   413
        """customize your form before rendering here"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   414
        super(CopyFormView, self).init_form(form, entity)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   415
        if entity.eid == self.newentity.eid:
1703
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   416
            form.form_add_hidden(eid_param('__cloned_eid', entity.eid),
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   417
                                 self.copying.eid)
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   418
        for rschema, _, role in form.relations_by_category(form.attrcategories,
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   419
                                                           'add'):
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3643
diff changeset
   420
            if not rschema.final:
1703
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   421
                # ensure relation cache is filed
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   422
                rset = self.copying.related(rschema, role)
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   423
                self.newentity.set_related_cache(rschema, role, rset)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   424
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   425
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   426
        """return the message that will be displayed on successful edition"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   427
        return self.req._('entity copied')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   428
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   429
2005
e8032965f37a turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1995
diff changeset
   430
class TableEditForm(forms.CompositeForm):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   431
    id = 'muledit'
1692
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   432
    domid = 'entityForm'
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   433
    onsubmit = "return validateForm('%s', null);" % domid
1304
8975c8e520a9 refactor button handling
sylvain.thenault@logilab.fr
parents: 1297
diff changeset
   434
    form_buttons = [SubmitButton(_('validate modifications on selected items')),
8975c8e520a9 refactor button handling
sylvain.thenault@logilab.fr
parents: 1297
diff changeset
   435
                    ResetButton(_('revert changes'))]
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   436
1692
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   437
    def __init__(self, req, rset, **kwargs):
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   438
        kwargs.setdefault('__redirectrql', rset.printable_rql())
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   439
        super(TableEditForm, self).__init__(req, rset, **kwargs)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   440
        for row in xrange(len(self.rset)):
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: 2576
diff changeset
   441
            form = self.vreg['forms'].select('edition', 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: 2576
diff changeset
   442
                                             rset=self.rset, row=row,
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: 2576
diff changeset
   443
                                             attrcategories=('primary',),
3880
88fc53eb5b5f [forms] muledit mainform should copy nav params, its subforms shouldn't
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3806
diff changeset
   444
                                             copy_nav_params=False,
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: 2576
diff changeset
   445
                                             mainform=False)
1324
a82f83188695 ease renderer overriding
sylvain.thenault@logilab.fr
parents: 1322
diff changeset
   446
            # XXX rely on the EntityCompositeFormRenderer to put the eid input
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   447
            form.remove_field(form.field_by_name('eid'))
3513
c002f6488631 [form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3355
diff changeset
   448
            self.add_subform(form)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   449
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   450
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   451
class TableEditFormView(FormViewMixIn, EntityView):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   452
    id = 'muledit'
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   453
    __select__ = EntityView.__select__ & yes()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   454
    title = _('multiple edit')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   455
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   456
    def call(self, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   457
        """a view to edit multiple entities of the same type the first column
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   458
        should be the eid
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   459
        """
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   460
        #self.form_title(entity)
3880
88fc53eb5b5f [forms] muledit mainform should copy nav params, its subforms shouldn't
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3806
diff changeset
   461
        form = self.vreg['forms'].select(self.id, self.req, rset=self.rset,
88fc53eb5b5f [forms] muledit mainform should copy nav params, its subforms shouldn't
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3806
diff changeset
   462
                                         copy_nav_params=True)
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   463
        self.w(form.render())
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   464
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   465
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   466
class InlineEntityEditionFormView(FormViewMixIn, EntityView):
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   467
    """
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   468
    :attr peid: the parent entity's eid hosting the inline form
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   469
    :attr rtype: the relation bridging `etype` and `peid`
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   470
    :attr role: the role played by the `peid` in the relation
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   471
    :attr pform: the parent form where this inlined form is being displayed
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   472
    """
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   473
    id = 'inline-edition'
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   474
    __select__ = non_final_entity() & match_kwargs('peid', 'rtype')
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   475
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   476
    _select_attrs = ('peid', 'rtype', 'role', 'pform')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   477
    removejs = "removeInlinedEntity('%s', '%s', '%s')"
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   478
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   479
    def __init__(self, *args, **kwargs):
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   480
        for attr in self._select_attrs:
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   481
            setattr(self, attr, kwargs.pop(attr, None))
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   482
        super(InlineEntityEditionFormView, self).__init__(*args, **kwargs)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   483
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   484
    def _entity(self):
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   485
        assert self.row is not None, self
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   486
        return self.rset.get_entity(self.row, self.col)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   487
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   488
    @property
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   489
    @cached
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   490
    def form(self):
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   491
        entity = self._entity()
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   492
        form = self.vreg['forms'].select('edition', self.req,
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   493
                                         entity=entity,
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   494
                                         form_renderer_id='inline',
3939
c1050081ac4b fix inline-creation form when called through ajax
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3933
diff changeset
   495
                                         copy_nav_params=False,
3941
dc6a04997b77 fix ze fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3939
diff changeset
   496
                                         mainform=False,
3930
c0ae3148b893 fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3927
diff changeset
   497
                                         parent_form=self.pform,
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   498
                                         **self.extra_kwargs)
3941
dc6a04997b77 fix ze fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3939
diff changeset
   499
        if self.pform is None:
3943
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3941
diff changeset
   500
            form.restore_previous_post(form.session_key())
3930
c0ae3148b893 fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3927
diff changeset
   501
        #assert form.parent_form
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   502
        self.add_hiddens(form, entity)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   503
        return form
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   504
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   505
    def cell_call(self, row, col, i18nctx, **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   506
        """
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   507
        :param peid: the parent entity's eid hosting the inline form
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   508
        :param rtype: the relation bridging `etype` and `peid`
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   509
        :param role: the role played by the `peid` in the relation
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   510
        """
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   511
        entity = self._entity()
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   512
        divonclick = "restoreInlinedEntity('%s', '%s', '%s')" % (
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   513
            self.peid, self.rtype, entity.eid)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   514
        self.render_form(i18nctx, divonclick=divonclick, **kwargs)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   515
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   516
    def render_form(self, i18nctx, **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   517
        """fetch and render the form"""
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   518
        entity = self._entity()
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   519
        divid = '%s-%s-%s' % (self.peid, self.rtype, entity.eid)
3933
865b6be915ec ease customization of title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3931
diff changeset
   520
        title = self.form_title(entity, i18nctx)
865b6be915ec ease customization of title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3931
diff changeset
   521
        removejs = self.removejs and self.removejs % (
865b6be915ec ease customization of title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3931
diff changeset
   522
            self.peid, self.rtype, entity.eid)
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   523
        countkey = '%s_count' % self.rtype
2247
9dbbe6a4c9b0 use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2224
diff changeset
   524
        try:
9dbbe6a4c9b0 use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2224
diff changeset
   525
            self.req.data[countkey] += 1
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   526
        except KeyError:
2247
9dbbe6a4c9b0 use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2224
diff changeset
   527
            self.req.data[countkey] = 1
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   528
        # XXX split kwargs into additional rendervalues / formvalues
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   529
        self.w(self.form.render(
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   530
            rendervalues=dict(divid=divid, title=title, removejs=removejs,
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   531
                              i18nctx=i18nctx, counter=self.req.data[countkey]),
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3947
diff changeset
   532
            formvalues=kwargs))
1396
daaebf6b9922 refactor to ease overriding
sylvain.thenault@logilab.fr
parents: 1366
diff changeset
   533
3933
865b6be915ec ease customization of title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3931
diff changeset
   534
    def form_title(self, entity, i18nctx):
3931
882de7c1c247 make title overriddable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3930
diff changeset
   535
        return self.req.pgettext(i18nctx, 'This %s' % entity.e_schema)
882de7c1c247 make title overriddable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3930
diff changeset
   536
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   537
    def add_hiddens(self, form, entity):
3532
df045bc51d00 [inlined forms] nicer add_hiddens implementation relying on standard entity forms handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3518
diff changeset
   538
        """to ease overriding (see cubes.vcsfile.views.forms for instance)"""
df045bc51d00 [inlined forms] nicer add_hiddens implementation relying on standard entity forms handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3518
diff changeset
   539
        iid = 'rel-%s-%s-%s' % (self.peid, self.rtype, entity.eid)
3586
52b00c5e441a cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3534
diff changeset
   540
        #  * str(self.rtype) in case it's a schema object
3534
81cfec545e1b ensure str is given as field's name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3532
diff changeset
   541
        #  * neged_role() since role is the for parent entity, we want the role
81cfec545e1b ensure str is given as field's name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3532
diff changeset
   542
        #    of the inlined entity
81cfec545e1b ensure str is given as field's name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3532
diff changeset
   543
        form.form_add_hidden(name=str(self.rtype), value=self.peid,
3532
df045bc51d00 [inlined forms] nicer add_hiddens implementation relying on standard entity forms handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3518
diff changeset
   544
                             role=neg_role(self.role), eidparam=True, id=iid)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   545
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   546
    def keep_entity(self, form, entity):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   547
        if not entity.has_eid():
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   548
            return True
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   549
        # are we regenerating form because of a validation error ?
1750
9df5e65c5f79 fix name error
sylvain.thenault@logilab.fr
parents: 1710
diff changeset
   550
        if form.form_previous_values:
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   551
            cdvalues = self.req.list_form_param(eid_param(self.rtype, self.peid),
1710
8c717cc0b353 refactor error handling: get validation error information from a form attribute instead of req.data to avoid pb when multiple forms are displayed
sylvain.thenault@logilab.fr
parents: 1703
diff changeset
   552
                                                form.form_previous_values)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   553
            if unicode(entity.eid) not in cdvalues:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   554
                return False
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   555
        return True
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   556
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   557
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   558
class InlineEntityCreationFormView(InlineEntityEditionFormView):
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   559
    """
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   560
    :attr etype: the entity type being created in the inline form
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   561
    """
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   562
    id = 'inline-creation'
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   563
    __select__ = (match_kwargs('peid', 'rtype')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   564
                  & specified_etype_implements('Any'))
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   565
    _select_attrs = InlineEntityEditionFormView._select_attrs + ('etype',)
3947
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   566
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   567
    @property
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   568
    def removejs(self):
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   569
        entity = self._entity()
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   570
        card = entity.e_schema.role_rproperty(neg_role(self.role), self.rtype, 'cardinality')
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   571
        card = card[self.role == 'object']
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   572
        # when one is adding an inline entity for a relation of a single card,
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   573
        # the 'add a new xxx' link disappears. If the user then cancel the addition,
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   574
        # we have to make this link appears back. This is done by giving add new link
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   575
        # id to removeInlineForm.
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   576
        if card not in '?1':
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   577
            return "removeInlineForm('%s', '%s', '%s')"
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   578
        divid = "addNew%s%s%s:%s" % (self.etype, self.rtype, self.role, self.peid)
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3943
diff changeset
   579
        return "removeInlineForm('%%s', '%%s', '%%s', '%s')" % divid
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   580
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   581
    @cached
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   582
    def _entity(self):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   583
        try:
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   584
            cls = self.vreg['etypes'].etype_class(self.etype)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   585
        except:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   586
            self.w(self.req._('no such entity type %s') % etype)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   587
            return
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   588
        self.initialize_varmaker()
3331
8e63b72287b1 cleaner code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3327
diff changeset
   589
        entity = cls(self.req)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   590
        entity.eid = self.varmaker.next()
3518
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   591
        return entity
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   592
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   593
    def call(self, i18nctx, **kwargs):
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   594
        self.render_form(i18nctx, **kwargs)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   595
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   596
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   597
class InlineAddNewLinkView(InlineEntityCreationFormView):
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   598
    """
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   599
    :attr card: the cardinality of the relation according to role of `peid`
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   600
    """
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   601
    id = 'inline-addnew-link'
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   602
    __select__ = (match_kwargs('peid', 'rtype')
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   603
                  & specified_etype_implements('Any'))
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   604
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   605
    _select_attrs = InlineEntityCreationFormView._select_attrs + ('card',)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   606
    form = None # no actual form wrapped
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   607
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   608
    def call(self, i18nctx, **kwargs):
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   609
        divid = "addNew%s%s%s:%s" % (self.etype, self.rtype, self.role, self.peid)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   610
        self.w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   611
          % divid)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   612
        js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % (
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   613
            self.peid, self.etype, self.rtype, self.role, i18nctx)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   614
        if self.pform.should_hide_add_new_relation_link(self.rtype, self.card):
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   615
            js = "toggleVisibility('%s'); %s" % (divid, js)
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   616
        __ = self.req.pgettext
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   617
        self.w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   618
          % (self.rtype, self.peid, js, __(i18nctx, 'add a %s' % self.etype)))
11ce4682187d [form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3513
diff changeset
   619
        self.w(u'</div>')