author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 17 Feb 2010 11:25:12 +0100 | |
branch | stable |
changeset 4604 | 96cc3d296d75 |
parent 4387 | 4aacd6492ef4 |
child 4641 | 9d8903b04031 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3953
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1965
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
9 |
__docformat__ = "restructuredtext en" |
1965 | 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 |
3518
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
17 |
from logilab.common.decorators import cached |
1147 | 18 |
|
19 |
from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity, |
|
20 |
specified_etype_implements, yes) |
|
1132 | 21 |
from cubicweb.view import EntityView |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4007
diff
changeset
|
22 |
from cubicweb import tags |
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
23 |
from cubicweb.web import uicfg, stdmsgs, eid_param, \ |
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
24 |
formfields as ff, formwidgets as fw |
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 |
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
|
26 |
from cubicweb.web.views import forms |
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1459
diff
changeset
|
27 |
|
3927
b2a6c25b8429
consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3880
diff
changeset
|
28 |
_pvdc = uicfg.primaryview_display_ctrl |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
|
2572
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
31 |
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
|
32 |
__regid__ = 'deleteconf' |
2572
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
33 |
__select__ = non_final_entity() |
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
34 |
|
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
35 |
domid = 'deleteconf' |
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
36 |
copy_nav_params = True |
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
37 |
form_buttons = [fw.Button(stdmsgs.BUTTON_DELETE, cwaction='delete'), |
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
38 |
fw.Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')] |
2572
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
39 |
@property |
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
40 |
def action(self): |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
41 |
return self._cw.build_url('edit') |
2572
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
42 |
|
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
43 |
def __init__(self, *args, **kwargs): |
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
44 |
super(DeleteConfForm, self).__init__(*args, **kwargs) |
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
45 |
done = set() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
46 |
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
|
47 |
if entity.eid in done: |
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
48 |
continue |
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
49 |
done.add(entity.eid) |
3485 | 50 |
subform = self._cw.vreg['forms'].select('base', self._cw, |
51 |
entity=entity, |
|
52 |
mainform=False) |
|
3513
c002f6488631
[form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3355
diff
changeset
|
53 |
self.add_subform(subform) |
2572
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
54 |
|
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
55 |
|
58556f9317c9
[notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2538
diff
changeset
|
56 |
class DeleteConfFormView(FormViewMixIn, EntityView): |
1147 | 57 |
"""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
|
58 |
__regid__ = 'deleteconf' |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
title = _('delete') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
# 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
|
61 |
# else we will only delete the displayed page |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4242
diff
changeset
|
62 |
paginable = False |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
63 |
|
1852
f04da596da6c
give back onsubmit customizability (oops)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1847
diff
changeset
|
64 |
def call(self, onsubmit=None): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
65 |
"""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
|
66 |
req, w = self._cw, self.w |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
_ = req._ |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
68 |
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
|
69 |
% _('this action is not reversible!')) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
# XXX above message should have style of a warning |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?')) |
3485 | 72 |
form = self._cw.vreg['forms'].select(self.__regid__, req, |
73 |
rset=self.cw_rset, |
|
74 |
onsubmit=onsubmit) |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
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
|
76 |
for entity in self.cw_rset.entities(): |
3485 | 77 |
# don't use outofcontext view or any other that may contain inline |
78 |
# edition form |
|
4242
b4b39745d26e
Backed out changeset b8ea99f5e8ea, tags.a escape its content.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4238
diff
changeset
|
79 |
w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'), |
b4b39745d26e
Backed out changeset b8ea99f5e8ea, tags.a escape its content.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4238
diff
changeset
|
80 |
href=entity.absolute_url())) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
w(u'</ul>\n') |
3953
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3947
diff
changeset
|
82 |
w(form.render()) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
|
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1313
diff
changeset
|
85 |
class EditionFormView(FormViewMixIn, EntityView): |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
86 |
"""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
|
87 |
__regid__ = 'edition' |
1147 | 88 |
# add yes() so it takes precedence over deprecated views in baseforms, |
89 |
# though not baseforms based customized view |
|
90 |
__select__ = one_line_rset() & non_final_entity() & yes() |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
title = _('edition') |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
93 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
def cell_call(self, row, col, **kwargs): |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
95 |
entity = self.cw_rset.complete_entity(row, col) |
1147 | 96 |
self.render_form(entity) |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
97 |
|
1147 | 98 |
def render_form(self, entity): |
99 |
"""fetch and render the form""" |
|
100 |
self.form_title(entity) |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
101 |
form = self._cw.vreg['forms'].select('edition', self._cw, rset=entity.cw_rset, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
102 |
row=entity.cw_row, col=entity.cw_col, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
103 |
entity=entity, |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
104 |
submitmsg=self.submited_message()) |
1147 | 105 |
self.init_form(form, entity) |
4167
73e649a7797d
fix render (formerly form_render) prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
106 |
self.w(form.render(formvid=u'edition')) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
107 |
|
1147 | 108 |
def init_form(self, form, entity): |
109 |
"""customize your form before rendering here""" |
|
2049
b9baedffeb8b
set __maineid in EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2048
diff
changeset
|
110 |
pass |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
111 |
|
1147 | 112 |
def form_title(self, entity): |
113 |
"""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
|
114 |
ptitle = self._cw._(self.title) |
1147 | 115 |
self.w(u'<div class="formTitle"><span>%s %s</span></div>' % ( |
116 |
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
|
117 |
|
1147 | 118 |
def submited_message(self): |
119 |
"""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
|
120 |
return self._cw._('entity edited') |
1147 | 121 |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
122 |
|
1147 | 123 |
class CreationFormView(EditionFormView): |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
124 |
"""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
|
125 |
__regid__ = 'creation' |
1147 | 126 |
__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
|
127 |
|
1147 | 128 |
title = _('creation') |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
129 |
|
1147 | 130 |
def call(self, **kwargs): |
131 |
"""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
|
132 |
# 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
|
133 |
# selector |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
entity.eid = self._cw.varmaker.next() |
3077
6c92323667a6
case insensitive add/XXX url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3062
diff
changeset
|
137 |
self.render_form(entity) |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
138 |
|
1147 | 139 |
def form_title(self, entity): |
140 |
"""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
|
141 |
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
|
142 |
if isinstance(self._cw.form['__linkto'], list): |
1147 | 143 |
# XXX which one should be considered (case: add a ticket to a |
144 |
# version in jpl) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
145 |
rtype, linkto_eid, role = self._cw.form['__linkto'][0].split(':') |
1147 | 146 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
147 |
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
|
148 |
linkto_rset = self._cw.eid_rset(linkto_eid) |
1147 | 149 |
linkto_type = linkto_rset.description[0][0] |
150 |
if role == 'subject': |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
151 |
title = self._cw.__('creating %s (%s %s %s %%(linkto)s)' % ( |
1147 | 152 |
entity.e_schema, entity.e_schema, rtype, linkto_type)) |
153 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
154 |
title = self._cw.__('creating %s (%s %%(linkto)s %s %s)' % ( |
1147 | 155 |
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
|
156 |
msg = title % {'linkto' : self._cw.view('incontext', linkto_rset)} |
1147 | 157 |
self.w(u'<div class="formTitle notransform"><span>%s</span></div>' % msg) |
158 |
else: |
|
159 |
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
|
160 |
|
1147 | 161 |
def url(self): |
162 |
"""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
|
163 |
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
|
164 |
|
1147 | 165 |
def submited_message(self): |
166 |
"""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
|
167 |
return self._cw._('entity created') |
1147 | 168 |
|
169 |
||
170 |
class CopyFormView(EditionFormView): |
|
171 |
"""display primary entity creation form initialized with values from another |
|
172 |
entity |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
173 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
174 |
__regid__ = 'copy' |
3629 | 175 |
|
3627
70dbba754c11
fix title of CopyFormView
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3586
diff
changeset
|
176 |
title = _('copy') |
3062
a8e901fc4457
ease overriding of copy warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2686
diff
changeset
|
177 |
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
|
178 |
|
1147 | 179 |
def render_form(self, entity): |
180 |
"""fetch and render the form""" |
|
181 |
# 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
|
182 |
# request's cache. |
1685
3c59ae0e6548
fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1629
diff
changeset
|
183 |
entity.complete() |
1147 | 184 |
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
|
185 |
self.copying = entity |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
186 |
self.newentity.eid = self._cw.varmaker.next() |
1147 | 187 |
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
|
188 |
% self._cw._(self.warning_message)) |
1685
3c59ae0e6548
fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1629
diff
changeset
|
189 |
super(CopyFormView, self).render_form(self.newentity) |
1147 | 190 |
del self.newentity |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
191 |
|
1147 | 192 |
def init_form(self, form, entity): |
193 |
"""customize your form before rendering here""" |
|
194 |
super(CopyFormView, self).init_form(form, entity) |
|
195 |
if entity.eid == self.newentity.eid: |
|
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4160
diff
changeset
|
196 |
form.add_hidden(eid_param('__cloned_eid', entity.eid), |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4160
diff
changeset
|
197 |
self.copying.eid) |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
198 |
for rschema, role in form.editable_attributes(): |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3643
diff
changeset
|
199 |
if not rschema.final: |
1703
a2b5dfdb4b62
should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents:
1692
diff
changeset
|
200 |
# 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
|
201 |
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
|
202 |
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
|
203 |
|
1147 | 204 |
def submited_message(self): |
205 |
"""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
|
206 |
return self._cw._('entity copied') |
1147 | 207 |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
208 |
|
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
|
209 |
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
|
210 |
__regid__ = 'muledit' |
1692 | 211 |
domid = 'entityForm' |
212 |
onsubmit = "return validateForm('%s', null);" % domid |
|
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
213 |
form_buttons = [fw.SubmitButton(_('validate modifications on selected items')), |
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
214 |
fw.ResetButton(_('revert changes'))] |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
215 |
|
1692 | 216 |
def __init__(self, req, rset, **kwargs): |
217 |
kwargs.setdefault('__redirectrql', rset.printable_rql()) |
|
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
form = self._cw.vreg['forms'].select('edition', self._cw, |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
221 |
rset=self.cw_rset, row=row, |
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
222 |
formtype='muledit', |
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
223 |
copy_nav_params=False, |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
224 |
mainform=False) |
1324 | 225 |
# XXX rely on the EntityCompositeFormRenderer to put the eid input |
1147 | 226 |
form.remove_field(form.field_by_name('eid')) |
3513
c002f6488631
[form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3355
diff
changeset
|
227 |
self.add_subform(form) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
228 |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
229 |
|
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1313
diff
changeset
|
230 |
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
|
231 |
__regid__ = 'muledit' |
1147 | 232 |
__select__ = EntityView.__select__ & yes() |
233 |
title = _('multiple edit') |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
234 |
|
1147 | 235 |
def call(self, **kwargs): |
236 |
"""a view to edit multiple entities of the same type the first column |
|
237 |
should be the eid |
|
238 |
""" |
|
239 |
#self.form_title(entity) |
|
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
240 |
form = self._cw.vreg['forms'].select(self.__regid__, self._cw, |
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
241 |
rset=self.cw_rset, |
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
242 |
copy_nav_params=True) |
4310
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
243 |
# XXX overriding formvid (eg __form_id) necessary to make work edition: |
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
244 |
# the edit controller try to select the form with no rset but |
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
245 |
# entity=entity, and use this form to edit the entity. So we want |
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
246 |
# edition form there but specifying formvid may have other undesired |
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
247 |
# side effect. Maybe we should provide another variable optinally |
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
248 |
# telling which form the edit controller should select (eg difffers |
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
249 |
# between html generation / post handling form) |
a139b98b6af5
specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4278
diff
changeset
|
250 |
self.w(form.render(formvid='edition')) |
1147 | 251 |
|
252 |
||
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
253 |
# click and edit handling ('reledit') ########################################## |
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
254 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
255 |
class DummyForm(object): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
256 |
__slots__ = ('event_args',) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
257 |
def form_render(self, **_args): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
258 |
return u'' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
259 |
def render(self, **_args): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
260 |
return u'' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
261 |
def append_field(self, *args): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
262 |
pass |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
263 |
def field_by_name(self, rtype, role, eschema=None): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
264 |
return None |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
265 |
|
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
266 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
267 |
class ClickAndEditFormView(FormViewMixIn, EntityView): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
268 |
"""form used to permit ajax edition of a relation or attribute of an entity |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
269 |
in a view, if logged user have the permission to edit it. |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
270 |
|
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
271 |
(double-click on the field to see an appropriate edition widget). |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
272 |
""" |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
273 |
__regid__ = 'doreledit' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
274 |
__select__ = non_final_entity() & match_kwargs('rtype') |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
275 |
# FIXME editableField class could be toggleable from userprefs |
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
276 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
277 |
_onclick = u"showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')" |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
278 |
_onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', " |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
279 |
"'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');") |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
280 |
_cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
281 |
_defaultlandingzone = (u'<img title="%(msg)s" src="data/pen_icon.png" ' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
282 |
'alt="%(msg)s"/>') |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
283 |
_landingzonemsg = _('click to edit this field') |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
284 |
# default relation vids according to cardinality |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
285 |
_one_rvid = 'incontext' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
286 |
_many_rvid = 'csv' |
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
287 |
|
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4366
diff
changeset
|
288 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
289 |
def cell_call(self, row, col, rtype=None, role='subject', |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
290 |
reload=False, # controls reloading the whole page after change |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
291 |
rvid=None, # vid to be applied to other side of rtype (non final relations only) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
292 |
default=None, # default value |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
293 |
landing_zone=None # prepend value with a separate html element to click onto |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
294 |
# (esp. needed when values are links) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
295 |
): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
296 |
"""display field to edit entity's `rtype` relation on click""" |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
297 |
assert rtype |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
298 |
assert role in ('subject', 'object'), '%s is not an acceptable role value' % role |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
299 |
self._cw.add_js('cubicweb.edition.js') |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
300 |
self._cw.add_css('cubicweb.form.css') |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
301 |
if default is None: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
302 |
default = xml_escape(self._cw._('<no value>')) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
303 |
schema = self._cw.vreg.schema |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
304 |
entity = self.cw_rset.get_entity(row, col) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
305 |
rschema = schema.rschema(rtype) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
306 |
lzone = self._build_landing_zone(landing_zone) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
307 |
# compute value, checking perms, build form |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
308 |
if rschema.final: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
309 |
form = self._build_form(entity, rtype, role, 'base', default, reload, lzone) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
310 |
if not self.should_edit_attribute(entity, rschema, role, form): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
311 |
self.w(entity.printable_value(rtype)) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
312 |
return |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
313 |
value = entity.printable_value(rtype) or default |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
314 |
else: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
315 |
rvid = self._compute_best_vid(entity.e_schema, rschema, role) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
316 |
rset = entity.related(rtype, role) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
317 |
if rset: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
318 |
value = self._cw.view(rvid, rset) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
319 |
else: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
320 |
value = default |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
321 |
if not self.should_edit_relation(entity, rschema, role, rvid): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
322 |
if rset: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
323 |
self.w(value) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
324 |
return |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
325 |
# XXX do we really have to give lzone twice? |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
326 |
form = self._build_form(entity, rtype, role, 'base', default, reload, lzone, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
327 |
dict(vid=rvid, lzone=lzone)) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
328 |
field = form.field_by_name(rtype, role, entity.e_schema) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
329 |
form.append_field(field) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
330 |
self.relation_form(lzone, value, form, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
331 |
self._build_renderer(entity, rtype, role)) |
3518
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
332 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
333 |
def should_edit_attribute(self, entity, rschema, role, form): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
334 |
rtype = str(rschema) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
335 |
ttype = rschema.targets(entity.__regid__, role)[0] |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
336 |
afs = uicfg.autoform_section.etype_get(entity.__regid__, rtype, role, ttype) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
337 |
if 'main_hidden' in afs or not entity.has_perm('update'): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
338 |
return False |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
339 |
try: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
340 |
form.field_by_name(rtype, role, entity.e_schema) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
341 |
except FieldNotFound: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
342 |
return False |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
343 |
return True |
3518
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
344 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
345 |
def should_edit_relation(self, entity, rschema, role, rvid): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
346 |
if ((role == 'subject' and not rschema.has_perm(self._cw, 'add', |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
347 |
fromeid=entity.eid)) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
348 |
or |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
349 |
(role == 'object' and not rschema.has_perm(self._cw, 'add', |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
350 |
toeid=entity.eid))): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
351 |
return False |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
352 |
return True |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
353 |
|
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
354 |
def relation_form(self, lzone, value, form, renderer): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
355 |
"""xxx-reledit div (class=field) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
356 |
+-xxx div (class="editableField") |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
357 |
| +-landing zone |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
358 |
+-xxx-value div |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
359 |
+-xxx-form div |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
360 |
""" |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
361 |
w = self.w |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
362 |
divid = form.event_args['divid'] |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
363 |
w(u'<div id="%s-reledit" class="field" ' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
364 |
u'onmouseout="addElementClass(jQuery(\'#%s\'), \'hidden\')" ' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
365 |
u'onmouseover="removeElementClass(jQuery(\'#%s\'), \'hidden\')">' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
366 |
% (divid, divid, divid)) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
367 |
w(u'<div id="%s-value" class="editableFieldValue">%s</div>' % (divid, value)) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
368 |
w(form.render(renderer=renderer)) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
369 |
w(u'<div id="%s" class="editableField hidden" onclick="%s" title="%s">' % ( |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
370 |
divid, xml_escape(self._onclick % form.event_args), |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
371 |
self._cw._(self._landingzonemsg))) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
372 |
w(lzone) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
373 |
w(u'</div>') |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
374 |
w(u'</div>') |
1147 | 375 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
376 |
def _compute_best_vid(self, eschema, rschema, role): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
377 |
dispctrl = _pvdc.etype_get(eschema, rschema, role) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
378 |
if dispctrl.get('rvid'): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
379 |
return dispctrl['rvid'] |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
380 |
if eschema.rdef(rschema, role).role_cardinality(role) in '+*': |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
381 |
return self._many_rvid |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
382 |
return self._one_rvid |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
383 |
|
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
384 |
def _build_landing_zone(self, lzone): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
385 |
return lzone or self._defaultlandingzone % { |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
386 |
'msg': xml_escape(self._cw._(self._landingzonemsg))} |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
387 |
|
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
388 |
def _build_renderer(self, entity, rtype, role): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
389 |
return self._cw.vreg['formrenderers'].select( |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
390 |
'base', self._cw, entity=entity, display_label=False, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
391 |
display_help=False, table_class='', |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
392 |
button_bar_class='buttonbar', display_progress_div=False) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
393 |
|
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
394 |
def _build_args(self, entity, rtype, role, formid, default, reload, lzone, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
395 |
extradata=None): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
396 |
divid = '%s-%s-%s' % (rtype, role, entity.eid) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
397 |
event_args = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
398 |
'reload' : dumps(reload), 'default' : default, 'role' : role, 'vid' : u'', |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
399 |
'lzone' : lzone} |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
400 |
if extradata: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
401 |
event_args.update(extradata) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
402 |
return divid, event_args |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
403 |
|
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
404 |
def _build_form(self, entity, rtype, role, formid, default, reload, lzone, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
405 |
extradata=None, **formargs): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
406 |
divid, event_args = self._build_args(entity, rtype, role, formid, default, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
407 |
reload, lzone, extradata) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
408 |
onsubmit = self._onsubmit % event_args |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
409 |
cancelclick = self._cancelclick % (entity.eid, rtype, divid) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
410 |
form = self._cw.vreg['forms'].select( |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
411 |
formid, self._cw, entity=entity, domid='%s-form' % divid, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
412 |
cssstyle='display: none', onsubmit=onsubmit, action='#', |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
413 |
form_buttons=[fw.SubmitButton(), |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
414 |
fw.Button(stdmsgs.BUTTON_CANCEL, onclick=cancelclick)], |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
415 |
**formargs) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
416 |
form.event_args = event_args |
3518
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
417 |
return form |
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
418 |
|
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
419 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
420 |
class AutoClickAndEditFormView(ClickAndEditFormView): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
421 |
"""same as ClickAndEditFormView but checking if the view *should* be applied |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
422 |
by checking uicfg configuration and composite relation property. |
3518
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
423 |
""" |
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
424 |
__regid__ = 'reledit' |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
425 |
_onclick = (u"loadInlineEditionForm(%(eid)s, '%(rtype)s', '%(role)s', " |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
426 |
"'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');") |
1423
39320a58faac
missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents:
1396
diff
changeset
|
427 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
428 |
def should_edit_relation(self, entity, rschema, role, rvid): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
429 |
eschema = entity.e_schema |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
430 |
rtype = str(rschema) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
431 |
# XXX check autoform_section. what if 'generic'? |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
432 |
dispctrl = _pvdc.etype_get(eschema, rtype, role) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
433 |
vid = dispctrl.get('vid', 'reledit') |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
434 |
if vid != 'reledit': # reledit explicitly disabled |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
435 |
return False |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
436 |
if eschema.rdef(rschema, role).composite == role: |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
437 |
return False |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
438 |
return super(AutoClickAndEditFormView, self).should_edit_relation( |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
439 |
entity, rschema, role, rvid) |
3518
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
440 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
441 |
def _build_form(self, entity, rtype, role, formid, default, reload, lzone, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
442 |
extradata=None, **formargs): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
443 |
_divid, event_args = self._build_args(entity, rtype, role, formid, default, |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
444 |
reload, lzone, extradata) |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
445 |
form = DummyForm() |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
446 |
form.event_args = event_args |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
447 |
return form |
3518
11ce4682187d
[form] important refactoring of inlined forms to get proper separation of form object creation / rendering
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3513
diff
changeset
|
448 |
|
4387
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
449 |
def _build_renderer(self, entity, rtype, role): |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
450 |
pass |
4aacd6492ef4
reorganize code:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
451 |