web/views/editforms.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 23 Sep 2009 19:40:19 +0200
changeset 3451 6b46d73823f5
parent 3396 fb261afd49cd
child 3457 0924d0d08d60
permissions -rw-r--r--
[api] work in progress, use __regid__, cw_*, etc.
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
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1965
diff changeset
     5
:copyright: 2001-2009 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
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    17
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    18
from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    19
                                specified_etype_implements, yes)
2678
0308dc159b96 use yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2675
diff changeset
    20
from cubicweb.utils import make_uid
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    21
from cubicweb.view import EntityView
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
from cubicweb.common import tags
3078
186ccbe0ba3f missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3077
diff changeset
    23
from cubicweb.web import INTERNAL_FIELD_VALUE, RequestError, stdmsgs, eid_param
186ccbe0ba3f missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3077
diff changeset
    24
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
    25
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
    26
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
    27
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
    28
from cubicweb.web.views import forms
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents: 1459
diff changeset
    29
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    31
def relation_id(eid, rtype, role, reid):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    32
    """return an identifier for a relation between two entities"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    33
    if role == 'subject':
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    34
        return u'%s:%s:%s' % (eid, rtype, reid)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    35
    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
    36
1528
864ae7c15ef5 other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1498
diff changeset
    37
def toggleable_relation_link(eid, nodeid, label='x'):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    38
    """return javascript snippet to delete/undelete a relation between two
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    39
    entities
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    40
    """
1320
c85f4d8eff8b cleanup
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
    41
    js = u"javascript: togglePendingDelete('%s', %s);" % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2247
diff changeset
    42
        nodeid, xml_escape(dumps(eid)))
1320
c85f4d8eff8b cleanup
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
    43
    return u'[<a class="handle" href="%s" id="handle%s">%s</a>]' % (
c85f4d8eff8b cleanup
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
    44
        js, nodeid, label)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    47
class DeleteConfForm(forms.CompositeForm):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
    48
    __regid__ = 'deleteconf'
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    49
    __select__ = non_final_entity()
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    50
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    51
    domid = 'deleteconf'
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    52
    copy_nav_params = True
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    53
    form_buttons = [Button(stdmsgs.YES, cwaction='delete'),
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    54
                    Button(stdmsgs.NO, cwaction='cancel')]
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    55
    @property
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    56
    def action(self):
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    57
        return self.build_url('edit')
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    58
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    59
    def __init__(self, *args, **kwargs):
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    60
        super(DeleteConfForm, self).__init__(*args, **kwargs)
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    61
        done = set()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
    62
        for entity in self.cw_rset.entities():
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    63
            if entity.eid in done:
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    64
                continue
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    65
            done.add(entity.eid)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
    66
            subform = self._cw.vreg['forms'].select('base', self._cw, entity=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
    67
                                                mainform=False)
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    68
            self.form_add_subform(subform)
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    69
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    70
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    71
class DeleteConfFormView(FormViewMixIn, EntityView):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    72
    """form used to confirm deletion of some entities"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
    73
    __regid__ = 'deleteconf'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
    title = _('delete')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
    # 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
    76
    # else we will only delete the displayed page
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
    need_navigation = False
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
    78
1852
f04da596da6c give back onsubmit customizability (oops)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1847
diff changeset
    79
    def call(self, onsubmit=None):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
        """ask for confirmation before real deletion"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
    81
        req, w = self._cw, self.w
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
        _ = req._
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
        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
    84
          % _('this action is not reversible!'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
        # XXX above message should have style of a warning
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
        w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?'))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
    87
        form = self._cw.vreg['forms'].select(self.__regid__, req, rset=self.cw_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
    88
                                         onsubmit=onsubmit)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
        w(u'<ul>\n')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
    90
        for entity in self.cw_rset.entities():
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
            # 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
    92
            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
    93
                                      href=entity.absolute_url()))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
        w(u'</ul>\n')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    95
        w(form.form_render())
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    97
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
    98
class ClickAndEditFormView(FormViewMixIn, EntityView):
2686
c700ace6ebfd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2679
diff changeset
    99
    """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
   100
    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
   101
2686
c700ace6ebfd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2679
diff changeset
   102
    (double-click on the field to see an appropriate edition widget).
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   103
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   104
    __regid__ = 'doreledit'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   105
    __select__ = non_final_entity() & match_kwargs('rtype')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   106
    # 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
   107
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
   108
    # 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
   109
    # 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
   110
    attrcategories = ('primary', 'secondary', 'metadata')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   111
2365
9f5e911eab07 [reledit] allow composite edition if the composite is object
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2361
diff changeset
   112
    _onclick = u"showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')"
2484
7e9283731db8 [reledit] a nicer icon
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2483
diff changeset
   113
    _defaultlandingzone = (u'<img title="%(msg)s" '
7e9283731db8 [reledit] a nicer icon
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2483
diff changeset
   114
                           'src="data/accessories-text-editor.png" '
7e9283731db8 [reledit] a nicer icon
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2483
diff changeset
   115
                           '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
   116
    _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
   117
    # 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
   118
    _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
   119
    _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
   120
2678
0308dc159b96 use yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2675
diff changeset
   121
    def _compute_best_vid(self, eschema, rschema, role):
0308dc159b96 use yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2675
diff changeset
   122
        if eschema.cardinality(rschema, role) in '+*':
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
   123
            return self._many_rvid
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
        return self._one_rvid
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   125
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   126
    def _build_landing_zone(self, lzone):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   127
        return lzone or self._defaultlandingzone % {'msg' : xml_escape(self._cw._(self._landingzonemsg))}
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   128
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   129
    def _build_renderer(self, entity, rtype, role):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   130
        return self._cw.vreg['formrenderers'].select(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   131
            'base', self._cw, entity=entity, display_label=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
   132
            display_help=False, display_fields=[(rtype, role)], table_class='',
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
   133
            button_bar_class='buttonbar', display_progress_div=False)
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   134
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
   135
    def _build_form(self, entity, rtype, role, formid, default, onsubmit, reload,
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
   136
                  extradata=None, **formargs):
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
   137
        divid = 'd%s' % make_uid('%s-%s' % (rtype, 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
   138
        event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype,
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
   139
                      'reload' : dumps(reload), 'default' : default}
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
   140
        if extradata:
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
   141
            event_data.update(extradata)
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
   142
        onsubmit %= event_data
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
   143
        cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (entity.eid, rtype,
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
   144
                                                            divid)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   145
        form = self._cw.vreg['forms'].select(
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   146
            formid, self._cw, entity=entity, domid='%s-form' % divid,
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
            cssstyle='display: none', onsubmit=onsubmit, action='#',
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
   148
            form_buttons=[SubmitButton(), Button(stdmsgs.BUTTON_CANCEL,
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
   149
                                                 onclick=cancelclick)],
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
            **formargs)
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
   151
        form.event_data = event_data
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
   152
        return 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
   153
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
   154
    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
   155
                  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
   156
                  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
   157
                  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
   158
                  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
   159
                                     # (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
   160
                  ):
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   161
        """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
   162
        assert rtype
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   163
        assert role in ('subject', 'object')
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2365
diff changeset
   164
        if default is None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   165
            default = xml_escape(self._cw._('<no value>'))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   166
        schema = self._cw.vreg.schema
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   167
        entity = self.cw_rset.get_entity(row, col)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   168
        rschema = 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
   169
        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
   170
        # compute value, checking perms, build form
1579
4eea314694e2 apply on non final relation
sylvain.thenault@logilab.fr
parents: 1576
diff changeset
   171
        if rschema.is_final():
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
   172
            onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', "
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
                        "%(reload)s, '%(default)s');")
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
            form = self._build_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
   175
                entity, rtype, role, 'edition', default, onsubmit, reload,
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
                attrcategories=self.attrcategories)
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
            if not self.should_edit_attribute(entity, rschema, role, form):
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
   178
                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
   179
            value = entity.printable_value(rtype) or default
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
            self.attribute_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
   181
                                 self._build_renderer(entity, rtype, role))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   182
        else:
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
            if rvid is None:
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
                rvid = self._compute_best_vid(entity.e_schema, rschema, 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
   185
            if not self.should_edit_relation(entity, rschema, role, rvid):
2380
5d980ba57632 [reledit] restore primaryview_display_ctrl usage by default in reledit (including bugfix over last implementation)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2376
diff changeset
   186
                return
1579
4eea314694e2 apply on non final relation
sylvain.thenault@logilab.fr
parents: 1576
diff changeset
   187
            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
   188
            if rset:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   189
                value = self._cw.view(rvid, rset)
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
   190
            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
   191
                value = default
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
   192
            onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
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
                        "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');")
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
            form = self._build_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
   195
                entity, rtype, role, 'base', default, onsubmit, reload,
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
   196
                dict(vid=rvid, role=role, lzone=lzone))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   197
            field = guess_field(entity.e_schema, schema.rschema(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
   198
            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
   199
            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
   200
                               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
   201
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
   202
    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
   203
        rtype = str(rschema)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   204
        ttype = rschema.targets(entity.__regid__, role)[0]
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   205
        afs = uicfg.autoform_section.etype_get(entity.__regid__, rtype, role, ttype)
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
   206
        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
   207
            self.w(entity.printable_value(rtype))
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
   208
            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
   209
        try:
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
   210
            field = form.field_by_name(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
   211
        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
   212
            self.w(entity.printable_value(rtype))
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
   213
            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
   214
        return True
1759
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1750
diff changeset
   215
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
   216
    def should_edit_relation(self, entity, rschema, role, rvid):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   217
        if ((role == 'subject' and not rschema.has_perm(self._cw, 'add',
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
   218
                                                        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
   219
            or
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   220
            (role == 'object' and not rschema.has_perm(self._cw, 'add',
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
   221
                                                       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
   222
            self.wview(rvid, entity.related(str(rschema), role), 'null')
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
   223
            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
   224
        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
   225
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
   226
    def attribute_form(self, lzone, value, form, renderer):
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
   227
        """div (class=field)
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
   228
              +-xxx div
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
   229
              |  +-xxx div (class=editableField)
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
   230
              |  |  +-landing zone
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
   231
              |  +-value-xxx div
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
   232
              |     +-value
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
   233
              +-form-xxx div
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
   234
        """
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
   235
        w = self.w
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
   236
        w(u'<div class="field">')
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
   237
        w(u'<div id="%s" style="display: inline">' % form.event_data['divid'])
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
   238
        w(tags.div(lzone, klass='editableField',
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
   239
                   onclick=self._onclick % form.event_data))
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
   240
        w(u'<div id="value-%s" style="display: inline">%s</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
   241
               (form.event_data['divid'], value))
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
   242
        w(u'</div>')
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
   243
        w(form.form_render(renderer=renderer))
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
   244
        w(u'</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
   245
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
   246
    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
   247
        """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
   248
              +-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
   249
              |   +-landing zone
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
   250
              +-value
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
   251
              +-form-xxx div
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
   252
        """
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
   253
        w = self.w
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
   254
        w(u'<div id="%s-reledit" class="field">' % form.event_data['divid'])
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
   255
        w(tags.div(lzone, klass='editableField', id=form.event_data['divid'],
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
   256
                   onclick=self._onclick % form.event_data))
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
   257
        w(value)
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
   258
        w(form.form_render(renderer=renderer))
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
   259
        w(u'</div>')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   260
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   261
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
   262
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
   263
    """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
   264
    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
   265
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   266
    __regid__ = 'reledit'
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
   267
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
    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
   269
        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
   270
        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
   271
        # XXX check autoform_section. what if 'generic'?
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
   272
        dispctrl = uicfg.primaryview_display_ctrl.etype_get(eschema, 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
   273
        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
   274
        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
   275
            self.wview(vid, entity.related(rtype, role), 'null')
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
   276
            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
   277
        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
   278
            self.wview(rvid, entity.related(rtype, role), 'null')
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
   279
            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
   280
        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
   281
            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
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
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   284
class EditionFormView(FormViewMixIn, EntityView):
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   285
    """display primary entity edition form"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   286
    __regid__ = 'edition'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   287
    # add yes() so it takes precedence over deprecated views in baseforms,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   288
    # though not baseforms based customized view
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   289
    __select__ = one_line_rset() & non_final_entity() & yes()
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   290
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   291
    title = _('edition')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   292
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   293
    def cell_call(self, row, col, **kwargs):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   294
        entity = self.complete_entity(row, col)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   295
        self.render_form(entity)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   296
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   297
    def render_form(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   298
        """fetch and render the form"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   299
        self.form_title(entity)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   300
        form = self._cw.vreg['forms'].select('edition', self._cw, rset=entity.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
   301
                                         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
   302
                                         submitmsg=self.submited_message())
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   303
        self.init_form(form, entity)
1995
ec95eaa2b711 turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   304
        self.w(form.form_render(formvid=u'edition'))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   305
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   306
    def init_form(self, form, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   307
        """customize your form before rendering here"""
2049
b9baedffeb8b set __maineid in EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2048
diff changeset
   308
        pass
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   309
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   310
    def form_title(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   311
        """the form view title"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   312
        ptitle = self._cw._(self.title)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   313
        self.w(u'<div class="formTitle"><span>%s %s</span></div>' % (
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   314
            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
   315
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   316
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   317
        """return the message that will be displayed on successful edition"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   318
        return self._cw._('entity edited')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   319
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   320
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   321
class CreationFormView(EditionFormView):
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   322
    """display primary entity creation form"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   323
    __regid__ = 'creation'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   324
    __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
   325
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   326
    title = _('creation')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   327
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   328
    def call(self, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   329
        """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
   330
        # 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
   331
        # selector
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   332
        etype = kwargs.pop('etype', self._cw.form.get('etype'))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   333
        entity = self._cw.vreg['etypes'].etype_class(etype)(self._cw)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   334
        entity.eid = self._cw.varmaker.next()
3077
6c92323667a6 case insensitive add/XXX url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3062
diff changeset
   335
        self.render_form(entity)
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 form_title(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   338
        """the form view title"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   339
        if '__linkto' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   340
            if isinstance(self._cw.form['__linkto'], list):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   341
                # XXX which one should be considered (case: add a ticket to a
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   342
                # version in jpl)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   343
                rtype, linkto_eid, role = self._cw.form['__linkto'][0].split(':')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   344
            else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   345
                rtype, linkto_eid, role = self._cw.form['__linkto'].split(':')
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   346
            linkto_rset = self._cw.eid_rset(linkto_eid)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   347
            linkto_type = linkto_rset.description[0][0]
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   348
            if role == 'subject':
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   349
                title = self._cw.__('creating %s (%s %s %s %%(linkto)s)' % (
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   350
                    entity.e_schema, entity.e_schema, rtype, linkto_type))
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   351
            else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   352
                title = self._cw.__('creating %s (%s %%(linkto)s %s %s)' % (
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   353
                    entity.e_schema, linkto_type, rtype, entity.e_schema))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   354
            msg = title % {'linkto' : self._cw.view('incontext', linkto_rset)}
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   355
            self.w(u'<div class="formTitle notransform"><span>%s</span></div>' % msg)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   356
        else:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   357
            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
   358
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   359
    def url(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   360
        """return the url associated with this view"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   361
        return self.create_url(self._cw.form.get('etype'))
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   362
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   363
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   364
        """return the message that will be displayed on successful edition"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   365
        return self._cw._('entity created')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   366
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   367
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   368
class CopyFormView(EditionFormView):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   369
    """display primary entity creation form initialized with values from another
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   370
    entity
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   371
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   372
    __regid__ = 'copy'
3062
a8e901fc4457 ease overriding of copy warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2686
diff changeset
   373
    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
   374
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   375
    def render_form(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   376
        """fetch and render the form"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   377
        # 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
   378
        # request's cache.
1685
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   379
        entity.complete()
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   380
        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
   381
        self.copying = entity
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   382
        self.newentity.eid = self._cw.varmaker.next()
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   383
        self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   384
               % self._cw._(self.warning_message))
1685
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   385
        super(CopyFormView, self).render_form(self.newentity)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   386
        del self.newentity
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   387
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   388
    def init_form(self, form, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   389
        """customize your form before rendering here"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   390
        super(CopyFormView, self).init_form(form, entity)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   391
        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
   392
            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
   393
                                 self.copying.eid)
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   394
        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
   395
                                                           'add'):
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   396
            if not rschema.is_final():
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   397
                # 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
   398
                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
   399
                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
   400
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   401
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   402
        """return the message that will be displayed on successful edition"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   403
        return self._cw._('entity copied')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   404
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   405
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
   406
class TableEditForm(forms.CompositeForm):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   407
    __regid__ = 'muledit'
1692
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   408
    domid = 'entityForm'
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   409
    onsubmit = "return validateForm('%s', null);" % domid
1304
8975c8e520a9 refactor button handling
sylvain.thenault@logilab.fr
parents: 1297
diff changeset
   410
    form_buttons = [SubmitButton(_('validate modifications on selected items')),
8975c8e520a9 refactor button handling
sylvain.thenault@logilab.fr
parents: 1297
diff changeset
   411
                    ResetButton(_('revert changes'))]
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   412
1692
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   413
    def __init__(self, req, rset, **kwargs):
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   414
        kwargs.setdefault('__redirectrql', rset.printable_rql())
2890
fdcb8a2bb6eb fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   415
        super(TableEditForm, self).__init__(req, rset=rset, **kwargs)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   416
        for row in xrange(len(self.cw_rset)):
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   417
            form = self._cw.vreg['forms'].select('edition', self._cw,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   418
                                             rset=self.cw_rset, row=row,
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
   419
                                             attrcategories=('primary',),
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
   420
                                             mainform=False)
1324
a82f83188695 ease renderer overriding
sylvain.thenault@logilab.fr
parents: 1322
diff changeset
   421
            # XXX rely on the EntityCompositeFormRenderer to put the eid input
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   422
            form.remove_field(form.field_by_name('eid'))
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   423
            self.form_add_subform(form)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   424
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   425
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   426
class TableEditFormView(FormViewMixIn, EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   427
    __regid__ = 'muledit'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   428
    __select__ = EntityView.__select__ & yes()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   429
    title = _('multiple edit')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   430
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   431
    def call(self, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   432
        """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
   433
        should be the eid
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   434
        """
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   435
        #self.form_title(entity)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   436
        form = self._cw.vreg['forms'].select(self.__regid__, self._cw, rset=self.cw_rset)
1995
ec95eaa2b711 turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   437
        self.w(form.form_render())
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   438
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   439
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   440
class InlineEntityEditionFormView(FormViewMixIn, EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   441
    __regid__ = 'inline-edition'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   442
    __select__ = non_final_entity() & match_kwargs('peid', 'rtype')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   443
    removejs = "removeInlinedEntity('%s', '%s', '%s')"
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   444
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   445
    def call(self, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   446
        """redefine default call() method to avoid automatic
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   447
        insertions of <div class="section"> between each row of
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   448
        the resultset
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   449
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   450
        rset = self.cw_rset
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   451
        for i in xrange(len(rset)):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   452
            self.wview(self.__regid__, rset, row=i, **kwargs)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   453
3327
44efba78afac fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3078
diff changeset
   454
    def cell_call(self, row, col, peid, rtype, role, i18nctx, **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   455
        """
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   456
        :param peid: the parent entity's eid hosting the inline form
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   457
        :param rtype: the relation bridging `etype` and `peid`
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   458
        :param role: the role played by the `peid` in the relation
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   459
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   460
        entity = self.cw_rset.get_entity(row, col)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   461
        divonclick = "restoreInlinedEntity('%s', '%s', '%s')" % (peid, rtype,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   462
                                                                 entity.eid)
3327
44efba78afac fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3078
diff changeset
   463
        self.render_form(entity, peid, rtype, role, i18nctx,
44efba78afac fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3078
diff changeset
   464
                         divonclick=divonclick)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   465
3327
44efba78afac fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3078
diff changeset
   466
    def render_form(self, entity, peid, rtype, role, i18nctx, **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   467
        """fetch and render the form"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   468
        form = self._cw.vreg['forms'].select('edition', self._cw, entity=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
   469
                                         form_renderer_id='inline',
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
   470
                                         mainform=False, copy_nav_params=False)
1396
daaebf6b9922 refactor to ease overriding
sylvain.thenault@logilab.fr
parents: 1366
diff changeset
   471
        self.add_hiddens(form, entity, peid, rtype, role)
daaebf6b9922 refactor to ease overriding
sylvain.thenault@logilab.fr
parents: 1366
diff changeset
   472
        divid = '%s-%s-%s' % (peid, rtype, entity.eid)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   473
        title = self._cw.pgettext(i18nctx, 'This %s' % entity.e_schema)
3327
44efba78afac fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3078
diff changeset
   474
        removejs = self.removejs % (peid, rtype, entity.eid)
2247
9dbbe6a4c9b0 use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2224
diff changeset
   475
        countkey = '%s_count' % rtype
9dbbe6a4c9b0 use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2224
diff changeset
   476
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   477
            self._cw.data[countkey] += 1
2247
9dbbe6a4c9b0 use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2224
diff changeset
   478
        except:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   479
            self._cw.data[countkey] = 1
1995
ec95eaa2b711 turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   480
        self.w(form.form_render(divid=divid, title=title, removejs=removejs,
3327
44efba78afac fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3078
diff changeset
   481
                                i18nctx=i18nctx,
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   482
                                counter=self._cw.data[countkey], **kwargs))
1396
daaebf6b9922 refactor to ease overriding
sylvain.thenault@logilab.fr
parents: 1366
diff changeset
   483
daaebf6b9922 refactor to ease overriding
sylvain.thenault@logilab.fr
parents: 1366
diff changeset
   484
    def add_hiddens(self, form, entity, peid, rtype, role):
daaebf6b9922 refactor to ease overriding
sylvain.thenault@logilab.fr
parents: 1366
diff changeset
   485
        # to ease overriding (see cubes.vcsfile.views.forms for instance)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   486
        form.form_add_hidden(name='%s:%s' % (rtype, peid), value=entity.eid,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   487
                             id='rel-%s-%s-%s'  % (peid, rtype, entity.eid))
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   488
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
   489
    def keep_entity(self, form, entity, peid, rtype):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   490
        if not entity.has_eid():
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   491
            return True
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   492
        # are we regenerating form because of a validation error ?
1750
9df5e65c5f79 fix name error
sylvain.thenault@logilab.fr
parents: 1710
diff changeset
   493
        if form.form_previous_values:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   494
            cdvalues = self._cw.list_form_param(eid_param(rtype, 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
   495
                                                form.form_previous_values)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   496
            if unicode(entity.eid) not in cdvalues:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   497
                return False
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   498
        return True
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   499
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   500
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   501
class InlineEntityCreationFormView(InlineEntityEditionFormView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   502
    __regid__ = 'inline-creation'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   503
    __select__ = (match_kwargs('peid', 'rtype')
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   504
                  & specified_etype_implements('Any'))
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   505
    removejs = "removeInlineForm('%s', '%s', '%s')"
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   506
3327
44efba78afac fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3078
diff changeset
   507
    def call(self, etype, peid, rtype, role, i18nctx, **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   508
        """
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   509
        :param etype: the entity type being created in the inline form
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   510
        :param peid: the parent entity's eid hosting the inline form
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   511
        :param rtype: the relation bridging `etype` and `peid`
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   512
        :param role: the role played by the `peid` in the relation
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   513
        """
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   514
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   515
            cls = self._cw.vreg['etypes'].etype_class(etype)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   516
        except:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   517
            self.w(self._cw._('no such entity type %s') % etype)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   518
            return
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   519
        entity = cls(self._cw)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   520
        entity.eid = self._cw.varmaker.next()
3355
39ea15e4589a [inline forms] propagate kwargs to render_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3346
diff changeset
   521
        self.render_form(entity, peid, rtype, role, i18nctx, **kwargs)