author | Julien Cristau <julien.cristau@logilab.fr> |
Fri, 24 Jul 2015 09:57:08 +0200 | |
changeset 10644 | c43e5dc41f8b |
parent 10372 | 9222e056584e |
child 10662 | 10942ed172de |
permissions | -rw-r--r-- |
9871
3d3aa4dd6a32
[reledit] Fix reledit icons jumpiness (closes #4106867)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8748
diff
changeset
|
1 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
3 |
# |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
4 |
# This file is part of CubicWeb. |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
5 |
# |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
9 |
# any later version. |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
10 |
# |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
14 |
# details. |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
15 |
# |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
18 |
"""edit entity attributes/relations from any view, without going to the entity |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
19 |
form |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
20 |
""" |
6582
8eb7883b4223
[pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6329
diff
changeset
|
21 |
|
8eb7883b4223
[pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6329
diff
changeset
|
22 |
__docformat__ = "restructuredtext en" |
8eb7883b4223
[pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6329
diff
changeset
|
23 |
_ = unicode |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5878
diff
changeset
|
24 |
|
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
25 |
import copy |
6283
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
26 |
from warnings import warn |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
27 |
|
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
28 |
from logilab.mtconverter import xml_escape |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
29 |
from logilab.common.deprecation import deprecated, class_renamed |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
30 |
from logilab.common.decorators import cached |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
31 |
|
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
32 |
from cubicweb import neg_role |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
33 |
from cubicweb.schema import display_name |
8253
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
34 |
from cubicweb.utils import json, json_dumps |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8100
diff
changeset
|
35 |
from cubicweb.predicates import non_final_entity, match_kwargs |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
36 |
from cubicweb.view import EntityView |
8665
e65af61bde7d
[uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8253
diff
changeset
|
37 |
from cubicweb.web import stdmsgs |
e65af61bde7d
[uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8253
diff
changeset
|
38 |
from cubicweb.web.views import uicfg |
6111
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
39 |
from cubicweb.web.form import FieldNotFound |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
40 |
from cubicweb.web.formwidgets import Button, SubmitButton |
8253
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
41 |
from cubicweb.web.views.ajaxcontroller import ajaxfunc |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
42 |
|
6111
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
43 |
class _DummyForm(object): |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
44 |
__slots__ = ('event_args',) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
45 |
def form_render(self, **_args): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
46 |
return u'' |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
47 |
def render(self, *_args, **_kwargs): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
48 |
return u'' |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
49 |
def append_field(self, *args): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
50 |
pass |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
51 |
def add_hidden(self, *args): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
52 |
pass |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
53 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
54 |
class AutoClickAndEditFormView(EntityView): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
55 |
__regid__ = 'reledit' |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
56 |
__select__ = non_final_entity() & match_kwargs('rtype') |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
57 |
|
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
58 |
# ui side continuations |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
59 |
_onclick = (u"cw.reledit.loadInlineEditionForm('%(formid)s', %(eid)s, '%(rtype)s', '%(role)s', " |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
60 |
"'%(divid)s', %(reload)s, '%(vid)s', '%(action)s');") |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
61 |
_cancelclick = "cw.reledit.cleanupAfterCancel('%s')" |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
62 |
|
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
63 |
# ui side actions/buttons |
7070
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
64 |
_addzone = u'<img title="%(msg)s" src="%(logo)s" alt="%(msg)s"/>' |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
65 |
_addmsg = _('click to add a value') |
7070
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
66 |
_addlogo = 'plus.png' |
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
67 |
_deletezone = u'<img title="%(msg)s" src="%(logo)s" alt="%(msg)s"/>' |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
68 |
_deletemsg = _('click to delete this value') |
7070
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
69 |
_deletelogo = 'cancel.png' |
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
70 |
_editzone = u'<img title="%(msg)s" src="%(logo)s" alt="%(msg)s"/>' |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
71 |
_editzonemsg = _('click to edit this field') |
7070
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
72 |
_editlogo = 'pen_icon.png' |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
73 |
|
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
74 |
# renderer |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
75 |
_form_renderer_id = 'base' |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
76 |
|
8100
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
77 |
def entity_call(self, entity, rtype=None, role='subject', |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
78 |
reload=False, # controls reloading the whole page after change |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
79 |
# boolean, eid (to redirect), or |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
80 |
# function taking the subject entity & returning a boolean or an eid |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
81 |
rvid=None, # vid to be applied to other side of rtype (non final relations only) |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
82 |
default_value=None, |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
83 |
formid='base', |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
84 |
action=None |
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
85 |
): |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
86 |
"""display field to edit entity's `rtype` relation on click""" |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
87 |
assert rtype |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
88 |
self._cw.add_css('cubicweb.form.css') |
6755
799ae44925c4
[views/reledit] funky API made this fatal (it was previously only eating the second argument)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6754
diff
changeset
|
89 |
self._cw.add_js(('cubicweb.reledit.js', 'cubicweb.edition.js', 'cubicweb.ajax.js')) |
8100
21918a60a5c5
[reledit] implements entity_call instead of cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8086
diff
changeset
|
90 |
self.entity = entity |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
91 |
rschema = self._cw.vreg.schema[rtype] |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8665
diff
changeset
|
92 |
rctrl = self._cw.vreg['uicfg'].select('reledit', self._cw, entity=entity) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
93 |
self._rules = rctrl.etype_get(self.entity.e_schema.type, rschema.type, role, '*') |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
94 |
reload = self._compute_reload(rschema, role, reload) |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
95 |
divid = self._build_divid(rtype, role, self.entity.eid) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
96 |
if rschema.final: |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
97 |
self._handle_attribute(rschema, role, divid, reload, action) |
6111
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
98 |
else: |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
99 |
if self._is_composite(): |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
100 |
self._handle_composite(rschema, role, divid, reload, formid, action) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
101 |
else: |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
102 |
self._handle_relation(rschema, role, divid, reload, formid, action) |
6111
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
103 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
104 |
def _handle_attribute(self, rschema, role, divid, reload, action): |
7834
258fc0b4a1e0
[reledit] honore 'rvid' for attribute relations (closes #1947471)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7156
diff
changeset
|
105 |
rvid = self._rules.get('rvid', None) |
258fc0b4a1e0
[reledit] honore 'rvid' for attribute relations (closes #1947471)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7156
diff
changeset
|
106 |
if rvid is not None: |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7834
diff
changeset
|
107 |
value = self._cw.view(rvid, entity=self.entity, |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7834
diff
changeset
|
108 |
rtype=rschema.type, role=role) |
7834
258fc0b4a1e0
[reledit] honore 'rvid' for attribute relations (closes #1947471)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7156
diff
changeset
|
109 |
else: |
258fc0b4a1e0
[reledit] honore 'rvid' for attribute relations (closes #1947471)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7156
diff
changeset
|
110 |
value = self.entity.printable_value(rschema.type) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
111 |
if not self._should_edit_attribute(rschema): |
6111
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
112 |
self.w(value) |
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
113 |
return |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7834
diff
changeset
|
114 |
form, renderer = self._build_form(self.entity, rschema, role, divid, |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7834
diff
changeset
|
115 |
'base', reload, action) |
6283
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
116 |
value = value or self._compute_default_value(rschema, role) |
6111
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
117 |
self.view_form(divid, value, form, renderer) |
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
118 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
119 |
def _compute_formid_value(self, rschema, role, rvid, formid): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
120 |
related_rset = self.entity.related(rschema.type, role) |
6111
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
121 |
if related_rset: |
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
122 |
value = self._cw.view(rvid, related_rset) |
06c96a79c3c0
[views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6110
diff
changeset
|
123 |
else: |
6283
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
124 |
value = self._compute_default_value(rschema, role) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
125 |
if not self._should_edit_relation(rschema, role): |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
126 |
return None, value |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
127 |
return formid, value |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
128 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
129 |
def _handle_relation(self, rschema, role, divid, reload, formid, action): |
6329
918dd7448630
[reledit] drop compute_best_vid method now useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6289
diff
changeset
|
130 |
rvid = self._rules.get('rvid', 'autolimited') |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
131 |
formid, value = self._compute_formid_value(rschema, role, rvid, formid) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
132 |
if formid is None: |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
133 |
return self.w(value) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
134 |
form, renderer = self._build_form(self.entity, rschema, role, divid, formid, |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
135 |
reload, action, dict(vid=rvid)) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
136 |
self.view_form(divid, value, form, renderer) |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
137 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
138 |
def _handle_composite(self, rschema, role, divid, reload, formid, action): |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
139 |
# this is for attribute-like composites (1 target type, 1 related entity at most, for now) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
140 |
entity = self.entity |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
141 |
related_rset = entity.related(rschema.type, role) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
142 |
add_related = self._may_add_related(related_rset, rschema, role) |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
143 |
edit_related = self._may_edit_related_entity(related_rset, rschema, role) |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
144 |
delete_related = edit_related and self._may_delete_related(related_rset, rschema, role) |
6329
918dd7448630
[reledit] drop compute_best_vid method now useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6289
diff
changeset
|
145 |
rvid = self._rules.get('rvid', 'autolimited') |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
146 |
formid, value = self._compute_formid_value(rschema, role, rvid, formid) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
147 |
if formid is None or not (edit_related or add_related): |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
148 |
# till we learn to handle cases where not (edit_related or add_related) |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
149 |
self.w(value) |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
150 |
return |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
151 |
form, renderer = self._build_form(entity, rschema, role, divid, formid, |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
152 |
reload, action, dict(vid=rvid)) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
153 |
self.view_form(divid, value, form, renderer, |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
154 |
edit_related, add_related, delete_related) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
155 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
156 |
@cached |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
157 |
def _compute_ttypes(self, rschema, role): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
158 |
dual_role = neg_role(role) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
159 |
return getattr(rschema, '%ss' % dual_role)() |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
160 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
161 |
def _compute_reload(self, rschema, role, reload): |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
162 |
ctrl_reload = self._rules.get('reload', reload) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
163 |
if callable(ctrl_reload): |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
164 |
ctrl_reload = ctrl_reload(self.entity) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
165 |
if isinstance(ctrl_reload, int) and ctrl_reload > 1: # not True/False |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
166 |
ctrl_reload = self._cw.build_url(ctrl_reload) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
167 |
return ctrl_reload |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
168 |
|
6283
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
169 |
def _compute_default_value(self, rschema, role): |
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
170 |
default = self._rules.get('novalue_label') |
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
171 |
if default is None: |
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
172 |
if self._rules.get('novalue_include_rtype'): |
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
173 |
default = self._cw._('<%s not specified>') % display_name( |
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
174 |
self._cw, rschema.type, role) |
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
175 |
else: |
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
176 |
default = self._cw._('<not specified>') |
8086
a057a0a4371b
[reledit] default label should be translated, I don't thing we've an opportunity to do it another way as uicfg objects are static
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
177 |
else: |
a057a0a4371b
[reledit] default label should be translated, I don't thing we've an opportunity to do it another way as uicfg objects are static
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
178 |
default = self._cw._(default) |
6283
c827fa795a6b
[reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6282
diff
changeset
|
179 |
return xml_escape(default) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
180 |
|
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
181 |
def _is_composite(self): |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
182 |
return self._rules.get('edit_target') == 'related' |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
183 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
184 |
def _may_add_related(self, related_rset, rschema, role): |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
185 |
""" ok for attribute-like composite entities """ |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
186 |
ttypes = self._compute_ttypes(rschema, role) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
187 |
if len(ttypes) > 1: # many etypes: learn how to do it |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
188 |
return False |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
189 |
rdef = rschema.role_rdef(self.entity.e_schema, ttypes[0], role) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
190 |
card = rdef.role_cardinality(role) |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
191 |
if related_rset or card not in '?1': |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
192 |
return False |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
193 |
if role == 'subject': |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
194 |
kwargs = {'fromeid': self.entity.eid} |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
195 |
else: |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
196 |
kwargs = {'toeid': self.entity.eid} |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
197 |
return rdef.has_perm(self._cw, 'add', **kwargs) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
198 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
199 |
def _may_edit_related_entity(self, related_rset, rschema, role): |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
200 |
""" controls the edition of the related entity """ |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
201 |
ttypes = self._compute_ttypes(rschema, role) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
202 |
if len(ttypes) > 1 or len(related_rset.rows) != 1: |
5878
8d1ca4150397
[reledit] fix relation cardinality handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5874
diff
changeset
|
203 |
return False |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
204 |
if self.entity.e_schema.rdef(rschema, role).role_cardinality(role) not in '?1': |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
205 |
return False |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
206 |
return related_rset.get_entity(0, 0).cw_has_perm('update') |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
207 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
208 |
def _may_delete_related(self, related_rset, rschema, role): |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
209 |
# we assume may_edit_related, only 1 related entity |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
210 |
if not related_rset: |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
211 |
return False |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
212 |
rentity = related_rset.get_entity(0, 0) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
213 |
entity = self.entity |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
214 |
if role == 'subject': |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
215 |
kwargs = {'fromeid': entity.eid, 'toeid': rentity.eid} |
10372
9222e056584e
[reledit] also check for cardinality before displaying the delete relation action. Closes #5334750
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9893
diff
changeset
|
216 |
cardinality = rschema.rdefs[(entity.cw_etype, rentity.cw_etype)].cardinality[0] |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
217 |
else: |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
218 |
kwargs = {'fromeid': rentity.eid, 'toeid': entity.eid} |
10372
9222e056584e
[reledit] also check for cardinality before displaying the delete relation action. Closes #5334750
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9893
diff
changeset
|
219 |
cardinality = rschema.rdefs[(rentity.cw_etype, entity.cw_etype)].cardinality[1] |
9222e056584e
[reledit] also check for cardinality before displaying the delete relation action. Closes #5334750
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9893
diff
changeset
|
220 |
if cardinality in '1+': |
9222e056584e
[reledit] also check for cardinality before displaying the delete relation action. Closes #5334750
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9893
diff
changeset
|
221 |
return False |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
222 |
# NOTE: should be sufficient given a well built schema/security |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
223 |
return rschema.has_perm(self._cw, 'delete', **kwargs) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
224 |
|
7070
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
225 |
def _build_zone(self, zonedef, msg, logo): |
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
226 |
return zonedef % {'msg': xml_escape(self._cw._(msg)), |
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
227 |
'logo': xml_escape(self._cw.data_url(logo))} |
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
228 |
|
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
229 |
def _build_edit_zone(self): |
7070
5f8e52d722c5
[web] provide a data_url() method on req and get_rid of explicit datadir_url usage (#1438736)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6932
diff
changeset
|
230 |
return self._build_zone(self._editzone, self._editzonemsg, self._editlogo) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
231 |
|
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
232 |
def _build_delete_zone(self): |
7151
04d0624a1832
[reledit] fix crash due to wrong attributes usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7070
diff
changeset
|
233 |
return self._build_zone(self._deletezone, self._deletemsg, self._deletelogo) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
234 |
|
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
235 |
def _build_add_zone(self): |
7151
04d0624a1832
[reledit] fix crash due to wrong attributes usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7070
diff
changeset
|
236 |
return self._build_zone(self._addzone, self._addmsg, self._addlogo) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
237 |
|
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
238 |
def _build_divid(self, rtype, role, entity_eid): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
239 |
""" builds an id for the root div of a reledit widget """ |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
240 |
return '%s-%s-%s' % (rtype, role, entity_eid) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
241 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
242 |
def _build_args(self, entity, rtype, role, formid, reload, action, |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
243 |
extradata=None): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
244 |
divid = self._build_divid(rtype, role, entity.eid) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
245 |
event_args = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'formid': formid, |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
246 |
'reload' : json_dumps(reload), 'action': action, |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
247 |
'role' : role, 'vid' : u''} |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
248 |
if extradata: |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
249 |
event_args.update(extradata) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
250 |
return event_args |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
251 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
252 |
def _prepare_form(self, entity, rschema, role, action): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
253 |
assert action in ('edit_rtype', 'edit_related', 'add', 'delete'), action |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
254 |
if action == 'edit_rtype': |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
255 |
return False, entity |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
256 |
label = True |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
257 |
if action in ('edit_related', 'delete'): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
258 |
edit_entity = entity.related(rschema, role).get_entity(0, 0) |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
259 |
elif action == 'add': |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
260 |
add_etype = self._compute_ttypes(rschema, role)[0] |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
261 |
_new_entity = self._cw.vreg['etypes'].etype_class(add_etype)(self._cw) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
262 |
_new_entity.eid = self._cw.varmaker.next() |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
263 |
edit_entity = _new_entity |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
264 |
# XXX see forms.py ~ 276 and entities.linked_to method |
9492
c7fc56eecd1a
English typography
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents:
9257
diff
changeset
|
265 |
# is there another way? |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
266 |
self._cw.form['__linkto'] = '%s:%s:%s' % (rschema, entity.eid, neg_role(role)) |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
267 |
assert edit_entity |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
268 |
return label, edit_entity |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
269 |
|
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
270 |
def _build_renderer(self, related_entity, display_label): |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
271 |
return self._cw.vreg['formrenderers'].select( |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
272 |
self._form_renderer_id, self._cw, entity=related_entity, |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
273 |
display_label=display_label, |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
274 |
table_class='attributeForm' if display_label else '', |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
275 |
display_help=False, button_bar_class='buttonbar', |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
276 |
display_progress_div=False) |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
277 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
278 |
def _build_form(self, entity, rschema, role, divid, formid, reload, action, |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
279 |
extradata=None, **formargs): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
280 |
rtype = rschema.type |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
281 |
event_args = self._build_args(entity, rtype, role, formid, reload, action, extradata) |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
282 |
if not action: |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
283 |
form = _DummyForm() |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
284 |
form.event_args = event_args |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
285 |
return form, None |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
286 |
label, edit_entity = self._prepare_form(entity, rschema, role, action) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
287 |
cancelclick = self._cancelclick % divid |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
288 |
form = self._cw.vreg['forms'].select( |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
289 |
formid, self._cw, rset=edit_entity.as_rset(), entity=edit_entity, |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
290 |
domid='%s-form' % divid, formtype='inlined', |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
291 |
action=self._cw.build_url('validateform', __onsuccess='window.parent.cw.reledit.onSuccess'), |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
292 |
cwtarget='eformframe', cssclass='releditForm', |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
293 |
**formargs) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
294 |
# pass reledit arguments |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
295 |
for pname, pvalue in event_args.iteritems(): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
296 |
form.add_hidden('__reledit|' + pname, pvalue) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
297 |
# handle buttons |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
298 |
if form.form_buttons: # edition, delete |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
299 |
form_buttons = [] |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
300 |
for button in form.form_buttons: |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
301 |
if not button.label.endswith('apply'): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
302 |
if button.label.endswith('cancel'): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
303 |
button = copy.deepcopy(button) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
304 |
button.cwaction = None |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
305 |
button.onclick = cancelclick |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
306 |
form_buttons.append(button) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
307 |
form.form_buttons = form_buttons |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
308 |
else: # base |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
309 |
form.form_buttons = [SubmitButton(), |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
310 |
Button(stdmsgs.BUTTON_CANCEL, onclick=cancelclick)] |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
311 |
form.event_args = event_args |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
312 |
if formid == 'base': |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
313 |
field = form.field_by_name(rtype, role, entity.e_schema) |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
314 |
form.append_field(field) |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
315 |
return form, self._build_renderer(edit_entity, label) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
316 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
317 |
def _should_edit_attribute(self, rschema): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
318 |
entity = self.entity |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
319 |
rdef = entity.e_schema.rdef(rschema) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
320 |
# check permissions |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
321 |
if not entity.cw_has_perm('update'): |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
322 |
return False |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
323 |
rdef = entity.e_schema.rdef(rschema) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
324 |
return rdef.has_perm(self._cw, 'update', eid=entity.eid) |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
325 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
326 |
def _should_edit_relation(self, rschema, role): |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
327 |
eeid = self.entity.eid |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
328 |
perm_args = {'fromeid': eeid} if role == 'subject' else {'toeid': eeid} |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
329 |
return rschema.has_perm(self._cw, 'add', **perm_args) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
330 |
|
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
331 |
def _open_form_wrapper(self, divid, value, form, renderer, |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
332 |
_edit_related, _add_related, _delete_related): |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
333 |
w = self.w |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
334 |
w(u'<div id="%(id)s-reledit" onmouseout="%(out)s" onmouseover="%(over)s" class="%(css)s">' % |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
335 |
{'id': divid, 'css': 'releditField', |
9871
3d3aa4dd6a32
[reledit] Fix reledit icons jumpiness (closes #4106867)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8748
diff
changeset
|
336 |
'out': "jQuery('#%s').addClass('invisible')" % divid, |
3d3aa4dd6a32
[reledit] Fix reledit icons jumpiness (closes #4106867)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8748
diff
changeset
|
337 |
'over': "jQuery('#%s').removeClass('invisible')" % divid}) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
338 |
w(u'<div id="%s-value" class="editableFieldValue">' % divid) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
339 |
w(value) |
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
340 |
w(u'</div>') |
6596
9717122d5e06
[3.10] drop deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
341 |
form.render(w=w, renderer=renderer) |
9871
3d3aa4dd6a32
[reledit] Fix reledit icons jumpiness (closes #4106867)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8748
diff
changeset
|
342 |
w(u'<div id="%s" class="editableField invisible">' % divid) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
343 |
|
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
344 |
def _edit_action(self, divid, args, edit_related, add_related, _delete_related): |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
345 |
# XXX disambiguate wrt edit_related |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
346 |
if not add_related: # currently, excludes edition |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
347 |
w = self.w |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
348 |
args['formid'] = 'edition' if edit_related else 'base' |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
349 |
args['action'] = 'edit_related' if edit_related else 'edit_rtype' |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
350 |
w(u'<div id="%s-update" class="editableField" onclick="%s" title="%s">' % |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
351 |
(divid, xml_escape(self._onclick % args), self._cw._(self._editzonemsg))) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
352 |
w(self._build_edit_zone()) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
353 |
w(u'</div>') |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
354 |
|
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
355 |
def _add_action(self, divid, args, _edit_related, add_related, _delete_related): |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
356 |
if add_related: |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
357 |
w = self.w |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
358 |
args['formid'] = 'edition' |
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
359 |
args['action'] = 'add' |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
360 |
w(u'<div id="%s-add" class="editableField" onclick="%s" title="%s">' % |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
361 |
(divid, xml_escape(self._onclick % args), self._cw._(self._addmsg))) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
362 |
w(self._build_add_zone()) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
363 |
w(u'</div>') |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
364 |
|
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
365 |
def _del_action(self, divid, args, _edit_related, _add_related, delete_related): |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
366 |
if delete_related: |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
367 |
w = self.w |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
368 |
args['formid'] = 'deleteconf' |
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
369 |
args['action'] = 'delete' |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
370 |
w(u'<div id="%s-delete" class="editableField" onclick="%s" title="%s">' % |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
371 |
(divid, xml_escape(self._onclick % args), self._cw._(self._deletemsg))) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
372 |
w(self._build_delete_zone()) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
373 |
w(u'</div>') |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
374 |
|
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
375 |
def _close_form_wrapper(self): |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
376 |
self.w(u'</div>') |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
377 |
self.w(u'</div>') |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
378 |
|
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
379 |
def view_form(self, divid, value, form=None, renderer=None, |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
380 |
edit_related=False, add_related=False, delete_related=False): |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
381 |
self._open_form_wrapper(divid, value, form, renderer, |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
382 |
edit_related, add_related, delete_related) |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
383 |
args = form.event_args.copy() |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
384 |
self._edit_action(divid, args, edit_related, add_related, delete_related) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
385 |
self._add_action(divid, args, edit_related, add_related, delete_related) |
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6246
diff
changeset
|
386 |
self._del_action(divid, args, edit_related, add_related, delete_related) |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
387 |
self._close_form_wrapper() |
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6111
diff
changeset
|
388 |
|
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
389 |
|
7076
0eed6045d785
[reledit] kill the reledit/doreledit duality
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7070
diff
changeset
|
390 |
ClickAndEditFormView = class_renamed('ClickAndEditFormView', AutoClickAndEditFormView) |
8253
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
391 |
|
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
392 |
|
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
393 |
@ajaxfunc(output_type='xhtml') |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
394 |
def reledit_form(self): |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
395 |
req = self._cw |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
396 |
args = dict((x, req.form[x]) |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
397 |
for x in ('formid', 'rtype', 'role', 'reload', 'action')) |
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
398 |
rset = req.eid_rset(int(self._cw.form['eid'])) |
8253
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
399 |
try: |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
400 |
args['reload'] = json.loads(args['reload']) |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
401 |
except ValueError: # not true/false, an absolute url |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
402 |
assert args['reload'].startswith('http') |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
403 |
view = req.vreg['views'].select('reledit', req, rset=rset, rtype=args['rtype']) |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
404 |
return self._call_view(view, **args) |
df7d6c57a6c8
[reledit, autoform] move reledit_form definition in reledit.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8190
diff
changeset
|
405 |