author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 08 Jul 2009 17:22:24 +0200 | |
branch | stable |
changeset 2327 | 2aa28ac13d64 |
parent 2312 | af4d8f75c5db |
child 2328 | 206735882b8e |
permissions | -rw-r--r-- |
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 | 10 |
_ = unicode |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
|
1147 | 12 |
from copy import copy |
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 | 17 |
|
18 |
from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity, |
|
19 |
specified_etype_implements, yes) |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
from cubicweb.utils import make_uid |
1132 | 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 |
1685
3c59ae0e6548
fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1629
diff
changeset
|
23 |
from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, eid_param |
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
|
24 |
from cubicweb.web.form import FormViewMixIn |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
25 |
from cubicweb.web.formfields import RelationField |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
26 |
from cubicweb.web.formwidgets import Button, SubmitButton, ResetButton, Select |
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
|
27 |
from cubicweb.web.views import forms |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1459
diff
changeset
|
28 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
|
1147 | 30 |
def relation_id(eid, rtype, role, reid): |
31 |
"""return an identifier for a relation between two entities""" |
|
32 |
if role == 'subject': |
|
33 |
return u'%s:%s:%s' % (eid, rtype, reid) |
|
34 |
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
|
35 |
|
1528
864ae7c15ef5
other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1498
diff
changeset
|
36 |
def toggleable_relation_link(eid, nodeid, label='x'): |
1147 | 37 |
"""return javascript snippet to delete/undelete a relation between two |
38 |
entities |
|
39 |
""" |
|
1320 | 40 |
js = u"javascript: togglePendingDelete('%s', %s);" % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2247
diff
changeset
|
41 |
nodeid, xml_escape(dumps(eid))) |
1320 | 42 |
return u'[<a class="handle" href="%s" id="handle%s">%s</a>]' % ( |
43 |
js, nodeid, label) |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
44 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
|
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1313
diff
changeset
|
46 |
class DeleteConfForm(FormViewMixIn, EntityView): |
1147 | 47 |
"""form used to confirm deletion of some entities""" |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
id = 'deleteconf' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
title = _('delete') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
# 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
|
51 |
# else we will only delete the displayed page |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
need_navigation = False |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
53 |
|
1852
f04da596da6c
give back onsubmit customizability (oops)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1847
diff
changeset
|
54 |
def call(self, onsubmit=None): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
"""ask for confirmation before real deletion""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
req, w = self.req, self.w |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
_ = req._ |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
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
|
59 |
% _('this action is not reversible!')) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
# XXX above message should have style of a warning |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?')) |
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
|
62 |
form = self.vreg.select_object('forms', 'composite', req, domid='deleteconf', |
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
|
63 |
copy_nav_params=True, |
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
|
64 |
action=self.build_url('edit'), onsubmit=onsubmit, |
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
|
65 |
form_buttons=[Button(stdmsgs.YES, cwaction='delete'), |
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
|
66 |
Button(stdmsgs.NO, cwaction='cancel')]) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
done = set() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
68 |
w(u'<ul>\n') |
1147 | 69 |
for entity in self.rset.entities(): |
70 |
if entity.eid in done: |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
continue |
1147 | 72 |
done.add(entity.eid) |
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
|
73 |
subform = self.vreg.select_object('forms', 'base', req, entity=entity, |
2048
5e4d1433b90b
replace set_error_url/set_dom_id by a single mainform argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2046
diff
changeset
|
74 |
mainform=False) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
form.form_add_subform(subform) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
# 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
|
77 |
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
|
78 |
href=entity.absolute_url())) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
w(u'</ul>\n') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
w(form.form_render()) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
|
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1313
diff
changeset
|
83 |
class ClickAndEditFormView(FormViewMixIn, EntityView): |
1147 | 84 |
"""form used to permit ajax edition of an attribute of an entity in a view |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
85 |
|
1147 | 86 |
(double-click on the field to see an appropriate edition widget) |
87 |
""" |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
id = 'reledit' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
__select__ = non_final_entity() & match_kwargs('rtype') |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
90 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
# 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
|
92 |
|
1147 | 93 |
ondblclick = "showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')" |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
94 |
|
1579 | 95 |
def cell_call(self, row, col, rtype=None, role='subject', reload=False, |
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
96 |
vid='textoutofcontext', default=None): |
1147 | 97 |
"""display field to edit entity's `rtype` relation on double-click""" |
1579 | 98 |
rschema = self.schema.rschema(rtype) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
entity = self.entity(row, col) |
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
100 |
if not default: |
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
101 |
default = self.req._('not specified') |
1579 | 102 |
if rschema.is_final(): |
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
|
103 |
value = entity.printable_value(rtype) |
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
|
104 |
if not entity.has_perm('update'): |
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
|
105 |
self.w(value) |
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
|
106 |
return |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
107 |
else: |
1579 | 108 |
rset = entity.related(rtype, role) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2247
diff
changeset
|
109 |
# XXX xml_escape but that depends of the actual vid |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2247
diff
changeset
|
110 |
value = xml_escape(self.view(vid, rset, 'null') or default) |
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
|
111 |
# XXX consider local roles ? |
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
|
112 |
if role == 'subject'and not rschema.has_perm(self.req, 'add', |
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
|
113 |
fromeid=entity.eid): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
self.w(value) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
return |
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
|
116 |
elif role == 'object'and not rschema.has_perm(self.req, 'add', |
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
|
117 |
toeid=entity.eid): |
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
|
118 |
self.w(value) |
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
|
119 |
return |
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
|
120 |
if not value.strip(): |
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
|
121 |
value = default |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
122 |
if rschema.is_final(): |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
123 |
form = self._build_attribute_form(entity, value, rtype, role, |
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
124 |
reload, row, col, default) |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
125 |
else: |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
126 |
form = self._build_relation_form(entity, value, rtype, role, |
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
127 |
row, col, vid, default) |
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
|
128 |
renderer = self.vreg.select_object('formrenderers', 'base', self.req, |
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
|
129 |
entity=entity, |
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
|
130 |
display_label=False, display_help=False, |
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
|
131 |
display_fields=[(rtype, role)], |
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
|
132 |
table_class='', button_bar_class='buttonbar', |
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
|
133 |
display_progress_div=False) |
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
134 |
self.w(form.form_render(renderer=renderer)) |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
135 |
|
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
136 |
def _build_relation_form(self, entity, value, rtype, role, row, col, vid, default): |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
137 |
divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid)) |
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
138 |
event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : vid, |
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
139 |
'default' : default, 'role' : role} |
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
|
140 |
onsubmit = ("return inlineValidateRelationForm('%(divid)s-form', '%(rtype)s', " |
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
|
141 |
"'%(role)s', '%(eid)s', '%(divid)s', '%(vid)s', '%(default)s');" |
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
|
142 |
% event_data) |
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
|
143 |
cancelclick = "cancelInlineEdit(%s,\'%s\',\'%s\')" % ( |
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
|
144 |
entity.eid, rtype, divid) |
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
|
145 |
form = self.vreg.select_object('forms', 'base', self.req, entity=entity, |
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
|
146 |
domid='%s-form' % divid, cssstyle='display: none', |
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
|
147 |
onsubmit=onsubmit, action='#', |
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
|
148 |
form_buttons=[SubmitButton(), |
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
|
149 |
Button(stdmsgs.BUTTON_CANCEL, |
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
|
150 |
onclick=cancelclick)]) |
1767 | 151 |
form.append_field(RelationField(name=rtype, role=role, sort=True, |
1763
65ec5ccc8927
that should be automatic
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1762
diff
changeset
|
152 |
widget=Select(), |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
153 |
label=u' ')) |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
154 |
self.w(tags.div(value, klass='editableField', id=divid, |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
155 |
ondblclick=self.ondblclick % event_data)) |
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
156 |
return form |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1750
diff
changeset
|
157 |
|
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
158 |
def _build_attribute_form(self, entity, value, rtype, role, reload, row, col, default): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
159 |
eid = entity.eid |
1559
c4d4851bd18b
[editforms] fix missing __maineid, avoid double submit through submit button, say no to locals()
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1528
diff
changeset
|
160 |
divid = 'd%s' % make_uid('%s-%s' % (rtype, eid)) |
1576
3bfcf1e4eb26
display_fields should search for name+role
sylvain.thenault@logilab.fr
parents:
1559
diff
changeset
|
161 |
event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype, |
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1781
diff
changeset
|
162 |
'reload' : dumps(reload), 'default' : default} |
2327
2aa28ac13d64
[reledit] onsubmit event is not common to both cases, move from class
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2312
diff
changeset
|
163 |
onsubmit = ("return inlineValidateAttributeForm('%(divid)s-form', '%(rtype)s', " |
2aa28ac13d64
[reledit] onsubmit event is not common to both cases, move from class
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2312
diff
changeset
|
164 |
"'%(eid)s', '%(divid)s', %(reload)s, '%(default)s');") |
1559
c4d4851bd18b
[editforms] fix missing __maineid, avoid double submit through submit button, say no to locals()
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1528
diff
changeset
|
165 |
buttons = [SubmitButton(stdmsgs.BUTTON_OK), |
1304 | 166 |
Button(stdmsgs.BUTTON_CANCEL, |
1576
3bfcf1e4eb26
display_fields should search for name+role
sylvain.thenault@logilab.fr
parents:
1559
diff
changeset
|
167 |
onclick="cancelInlineEdit(%s,\'%s\',\'%s\')" % ( |
3bfcf1e4eb26
display_fields should search for name+role
sylvain.thenault@logilab.fr
parents:
1559
diff
changeset
|
168 |
eid, rtype, divid))] |
1147 | 169 |
form = self.vreg.select_object('forms', 'edition', self.req, self.rset, |
1304 | 170 |
row=row, col=col, form_buttons=buttons, |
1147 | 171 |
domid='%s-form' % divid, action='#', |
172 |
cssstyle='display: none', |
|
2327
2aa28ac13d64
[reledit] onsubmit event is not common to both cases, move from class
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2312
diff
changeset
|
173 |
onsubmit=onsubmit % event_data) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
self.w(tags.div(value, klass='editableField', id=divid, |
1559
c4d4851bd18b
[editforms] fix missing __maineid, avoid double submit through submit button, say no to locals()
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1528
diff
changeset
|
175 |
ondblclick=self.ondblclick % event_data)) |
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
176 |
return form |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
177 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
178 |
|
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1313
diff
changeset
|
179 |
class EditionFormView(FormViewMixIn, EntityView): |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
180 |
"""display primary entity edition form""" |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
181 |
id = 'edition' |
1147 | 182 |
# add yes() so it takes precedence over deprecated views in baseforms, |
183 |
# though not baseforms based customized view |
|
184 |
__select__ = one_line_rset() & non_final_entity() & yes() |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
185 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
186 |
title = _('edition') |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
187 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
188 |
def cell_call(self, row, col, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
189 |
entity = self.complete_entity(row, col) |
1147 | 190 |
self.render_form(entity) |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
191 |
|
1147 | 192 |
def render_form(self, entity): |
193 |
"""fetch and render the form""" |
|
194 |
self.form_title(entity) |
|
1286
cb68c8af3858
use entity's rset and row/col info
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
195 |
form = self.vreg.select_object('forms', 'edition', self.req, entity.rset, |
cb68c8af3858
use entity's rset and row/col info
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
196 |
row=entity.row, col=entity.col, entity=entity, |
1305
395ef7f2b95b
cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
197 |
submitmsg=self.submited_message()) |
1147 | 198 |
self.init_form(form, entity) |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
199 |
self.w(form.form_render(formvid=u'edition')) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
200 |
|
1147 | 201 |
def init_form(self, form, entity): |
202 |
"""customize your form before rendering here""" |
|
2049
b9baedffeb8b
set __maineid in EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2048
diff
changeset
|
203 |
pass |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
204 |
|
1147 | 205 |
def form_title(self, entity): |
206 |
"""the form view title""" |
|
207 |
ptitle = self.req._(self.title) |
|
208 |
self.w(u'<div class="formTitle"><span>%s %s</span></div>' % ( |
|
209 |
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
|
210 |
|
1147 | 211 |
def submited_message(self): |
212 |
"""return the message that will be displayed on successful edition""" |
|
213 |
return self.req._('entity edited') |
|
214 |
||
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
215 |
|
1147 | 216 |
class CreationFormView(EditionFormView): |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
217 |
"""display primary entity creation form""" |
1147 | 218 |
id = 'creation' |
219 |
__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
|
220 |
|
1147 | 221 |
title = _('creation') |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
222 |
|
1147 | 223 |
def call(self, **kwargs): |
224 |
"""creation view for an entity""" |
|
225 |
etype = kwargs.pop('etype', self.req.form.get('etype')) |
|
226 |
try: |
|
1435
6cd6172718bb
allow to instantiate an entity without rset
sylvain.thenault@logilab.fr
parents:
1423
diff
changeset
|
227 |
entity = self.vreg.etype_class(etype)(self.req) |
1147 | 228 |
except: |
229 |
self.w(self.req._('no such entity type %s') % etype) |
|
230 |
else: |
|
231 |
self.initialize_varmaker() |
|
232 |
entity.eid = self.varmaker.next() |
|
233 |
self.render_form(entity) |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
234 |
|
1147 | 235 |
def form_title(self, entity): |
236 |
"""the form view title""" |
|
237 |
if '__linkto' in self.req.form: |
|
238 |
if isinstance(self.req.form['__linkto'], list): |
|
239 |
# XXX which one should be considered (case: add a ticket to a |
|
240 |
# version in jpl) |
|
241 |
rtype, linkto_eid, role = self.req.form['__linkto'][0].split(':') |
|
242 |
else: |
|
243 |
rtype, linkto_eid, role = self.req.form['__linkto'].split(':') |
|
244 |
linkto_rset = self.req.eid_rset(linkto_eid) |
|
245 |
linkto_type = linkto_rset.description[0][0] |
|
246 |
if role == 'subject': |
|
247 |
title = self.req.__('creating %s (%s %s %s %%(linkto)s)' % ( |
|
248 |
entity.e_schema, entity.e_schema, rtype, linkto_type)) |
|
249 |
else: |
|
250 |
title = self.req.__('creating %s (%s %%(linkto)s %s %s)' % ( |
|
251 |
entity.e_schema, linkto_type, rtype, entity.e_schema)) |
|
252 |
msg = title % {'linkto' : self.view('incontext', linkto_rset)} |
|
253 |
self.w(u'<div class="formTitle notransform"><span>%s</span></div>' % msg) |
|
254 |
else: |
|
255 |
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
|
256 |
|
1147 | 257 |
def url(self): |
258 |
"""return the url associated with this view""" |
|
259 |
return self.create_url(self.req.form.get('etype')) |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
260 |
|
1147 | 261 |
def submited_message(self): |
262 |
"""return the message that will be displayed on successful edition""" |
|
263 |
return self.req._('entity created') |
|
264 |
||
265 |
||
266 |
class CopyFormView(EditionFormView): |
|
267 |
"""display primary entity creation form initialized with values from another |
|
268 |
entity |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
269 |
""" |
1147 | 270 |
id = 'copy' |
271 |
def render_form(self, entity): |
|
272 |
"""fetch and render the form""" |
|
273 |
# 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
|
274 |
# request's cache. |
1685
3c59ae0e6548
fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1629
diff
changeset
|
275 |
entity.complete() |
1147 | 276 |
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
|
277 |
self.copying = entity |
1685
3c59ae0e6548
fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1629
diff
changeset
|
278 |
self.initialize_varmaker() |
3c59ae0e6548
fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1629
diff
changeset
|
279 |
self.newentity.eid = self.varmaker.next() |
1147 | 280 |
self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n' |
281 |
% self.req._('Please note that this is only a shallow copy')) |
|
1685
3c59ae0e6548
fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1629
diff
changeset
|
282 |
super(CopyFormView, self).render_form(self.newentity) |
1147 | 283 |
del self.newentity |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
284 |
|
1147 | 285 |
def init_form(self, form, entity): |
286 |
"""customize your form before rendering here""" |
|
287 |
super(CopyFormView, self).init_form(form, entity) |
|
288 |
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
|
289 |
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
|
290 |
self.copying.eid) |
a2b5dfdb4b62
should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents:
1692
diff
changeset
|
291 |
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
|
292 |
'add'): |
a2b5dfdb4b62
should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents:
1692
diff
changeset
|
293 |
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
|
294 |
# 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
|
295 |
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
|
296 |
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
|
297 |
|
1147 | 298 |
def submited_message(self): |
299 |
"""return the message that will be displayed on successful edition""" |
|
300 |
return self.req._('entity copied') |
|
301 |
||
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
302 |
|
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
|
303 |
class TableEditForm(forms.CompositeForm): |
1147 | 304 |
id = 'muledit' |
1692 | 305 |
domid = 'entityForm' |
306 |
onsubmit = "return validateForm('%s', null);" % domid |
|
1304 | 307 |
form_buttons = [SubmitButton(_('validate modifications on selected items')), |
308 |
ResetButton(_('revert changes'))] |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
309 |
|
1692 | 310 |
def __init__(self, req, rset, **kwargs): |
311 |
kwargs.setdefault('__redirectrql', rset.printable_rql()) |
|
312 |
super(TableEditForm, self).__init__(req, rset, **kwargs) |
|
1147 | 313 |
for row in xrange(len(self.rset)): |
314 |
form = self.vreg.select_object('forms', 'edition', self.req, self.rset, |
|
1305
395ef7f2b95b
cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
315 |
row=row, attrcategories=('primary',), |
2048
5e4d1433b90b
replace set_error_url/set_dom_id by a single mainform argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2046
diff
changeset
|
316 |
mainform=False) |
1324 | 317 |
# XXX rely on the EntityCompositeFormRenderer to put the eid input |
1147 | 318 |
form.remove_field(form.field_by_name('eid')) |
319 |
self.form_add_subform(form) |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
320 |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
321 |
|
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1313
diff
changeset
|
322 |
class TableEditFormView(FormViewMixIn, EntityView): |
1147 | 323 |
id = 'muledit' |
324 |
__select__ = EntityView.__select__ & yes() |
|
325 |
title = _('multiple edit') |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
326 |
|
1147 | 327 |
def call(self, **kwargs): |
328 |
"""a view to edit multiple entities of the same type the first column |
|
329 |
should be the eid |
|
330 |
""" |
|
331 |
#self.form_title(entity) |
|
1305
395ef7f2b95b
cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
332 |
form = self.vreg.select_object('forms', self.id, self.req, self.rset) |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
333 |
self.w(form.form_render()) |
1147 | 334 |
|
335 |
||
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1313
diff
changeset
|
336 |
class InlineEntityEditionFormView(FormViewMixIn, EntityView): |
1147 | 337 |
id = 'inline-edition' |
338 |
__select__ = non_final_entity() & match_kwargs('peid', 'rtype') |
|
339 |
removejs = "removeInlinedEntity('%s', '%s', '%s')" |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
340 |
|
1147 | 341 |
def call(self, **kwargs): |
342 |
"""redefine default call() method to avoid automatic |
|
343 |
insertions of <div class="section"> between each row of |
|
344 |
the resultset |
|
345 |
""" |
|
346 |
rset = self.rset |
|
347 |
for i in xrange(len(rset)): |
|
348 |
self.wview(self.id, rset, row=i, **kwargs) |
|
349 |
||
350 |
def cell_call(self, row, col, peid, rtype, role='subject', **kwargs): |
|
351 |
""" |
|
352 |
:param peid: the parent entity's eid hosting the inline form |
|
353 |
:param rtype: the relation bridging `etype` and `peid` |
|
354 |
:param role: the role played by the `peid` in the relation |
|
355 |
""" |
|
356 |
entity = self.entity(row, col) |
|
357 |
divonclick = "restoreInlinedEntity('%s', '%s', '%s')" % (peid, rtype, |
|
358 |
entity.eid) |
|
359 |
self.render_form(entity, peid, rtype, role, divonclick=divonclick) |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
360 |
|
1147 | 361 |
def render_form(self, entity, peid, rtype, role, **kwargs): |
362 |
"""fetch and render the form""" |
|
1297 | 363 |
form = self.vreg.select_object('forms', 'edition', self.req, None, |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
364 |
entity=entity, form_renderer_id='inline', |
2049
b9baedffeb8b
set __maineid in EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2048
diff
changeset
|
365 |
mainform=False, copy_nav_params=False) |
1396 | 366 |
self.add_hiddens(form, entity, peid, rtype, role) |
367 |
divid = '%s-%s-%s' % (peid, rtype, entity.eid) |
|
368 |
title = self.schema.rschema(rtype).display_name(self.req, role) |
|
1147 | 369 |
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
|
370 |
countkey = '%s_count' % rtype |
9dbbe6a4c9b0
use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2224
diff
changeset
|
371 |
try: |
9dbbe6a4c9b0
use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2224
diff
changeset
|
372 |
self.req.data[countkey] += 1 |
9dbbe6a4c9b0
use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2224
diff
changeset
|
373 |
except: |
9dbbe6a4c9b0
use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2224
diff
changeset
|
374 |
self.req.data[countkey] = 1 |
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
375 |
self.w(form.form_render(divid=divid, title=title, removejs=removejs, |
2247
9dbbe6a4c9b0
use a counter of displayed inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2224
diff
changeset
|
376 |
counter=self.req.data[countkey], **kwargs)) |
1396 | 377 |
|
378 |
def add_hiddens(self, form, entity, peid, rtype, role): |
|
379 |
# to ease overriding (see cubes.vcsfile.views.forms for instance) |
|
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
|
380 |
if self.keep_entity(form, entity, peid, rtype): |
1147 | 381 |
if entity.has_eid(): |
382 |
rval = entity.eid |
|
383 |
else: |
|
384 |
rval = INTERNAL_FIELD_VALUE |
|
385 |
form.form_add_hidden('edit%s-%s:%s' % (role[0], rtype, peid), rval) |
|
386 |
form.form_add_hidden(name='%s:%s' % (rtype, peid), value=entity.eid, |
|
387 |
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
|
388 |
|
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
|
389 |
def keep_entity(self, form, entity, peid, rtype): |
1147 | 390 |
if not entity.has_eid(): |
391 |
return True |
|
392 |
# are we regenerating form because of a validation error ? |
|
1750 | 393 |
if form.form_previous_values: |
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
|
394 |
cdvalues = self.req.list_form_param(eid_param(rtype, peid), |
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
|
395 |
form.form_previous_values) |
1147 | 396 |
if unicode(entity.eid) not in cdvalues: |
397 |
return False |
|
398 |
return True |
|
399 |
||
400 |
||
401 |
class InlineEntityCreationFormView(InlineEntityEditionFormView): |
|
402 |
id = 'inline-creation' |
|
403 |
__select__ = (match_kwargs('peid', 'rtype') |
|
404 |
& specified_etype_implements('Any')) |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
405 |
removejs = "removeInlineForm('%s', '%s', '%s')" |
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
406 |
|
1147 | 407 |
def call(self, etype, peid, rtype, role='subject', **kwargs): |
408 |
""" |
|
409 |
:param etype: the entity type being created in the inline form |
|
410 |
:param peid: the parent entity's eid hosting the inline form |
|
411 |
:param rtype: the relation bridging `etype` and `peid` |
|
412 |
:param role: the role played by the `peid` in the relation |
|
413 |
""" |
|
414 |
try: |
|
415 |
entity = self.vreg.etype_class(etype)(self.req, None, None) |
|
416 |
except: |
|
417 |
self.w(self.req._('no such entity type %s') % etype) |
|
418 |
return |
|
419 |
self.initialize_varmaker() |
|
420 |
entity.eid = self.varmaker.next() |
|
421 |
self.render_form(entity, peid, rtype, role) |