author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 27 Jul 2009 18:40:29 +0200 | |
changeset 2519 | ac1a869e1e93 |
parent 2518 | 38c28ee40138 |
child 2522 | 562f5dcf2345 |
permissions | -rw-r--r-- |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
"""widget classes for form construction |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
3 |
:organization: Logilab |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1970
diff
changeset
|
4 |
:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
5 |
: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:
1970
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
""" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
9 |
|
1096 | 10 |
from datetime import date |
1966
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
11 |
from warnings import warn |
1096 | 12 |
|
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
13 |
from cubicweb.common import tags, uilib |
1735
07afba765926
no value, but something needs to be shown // needs review //
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1650
diff
changeset
|
14 |
from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
16 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
class FieldWidget(object): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
18 |
"""abstract widget class""" |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
19 |
# javascript / css files required by the widget |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
needs_js = () |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
21 |
needs_css = () |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
22 |
# automatically set id and tabindex attributes ? |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
setdomid = True |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
settabindex = True |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
25 |
# does this widget expect a vocabulary |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
26 |
vocabulary_widget = False |
1474 | 27 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
def __init__(self, attrs=None, setdomid=None, settabindex=None): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
29 |
if attrs is None: |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
30 |
attrs = {} |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
31 |
self.attrs = attrs |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
if setdomid is not None: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
# override class's default value |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
self.setdomid = setdomid |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
if settabindex is not None: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
# override class's default value |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
self.settabindex = settabindex |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
def add_media(self, form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
"""adds media (CSS & JS) required by this widget""" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
if self.needs_js: |
1096 | 42 |
form.req.add_js(self.needs_js) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
if self.needs_css: |
1096 | 44 |
form.req.add_css(self.needs_css) |
1474 | 45 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
def render(self, form, field): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
47 |
"""render the widget for the given `field` of `form`. |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
48 |
To override in concrete class |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
49 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
raise NotImplementedError |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
51 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
def _render_attrs(self, form, field): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
53 |
"""return html tag name, attributes and a list of values for the field |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
54 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
name = form.context[field]['name'] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
values = form.context[field]['value'] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
if not isinstance(values, (tuple, list)): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
values = (values,) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
attrs = dict(self.attrs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
if self.setdomid: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
attrs['id'] = form.context[field]['id'] |
1273
64e1db70161b
don't set tabindex if already in attrs
sylvain.thenault@logilab.fr
parents:
1152
diff
changeset
|
62 |
if self.settabindex and not 'tabindex' in attrs: |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
attrs['tabindex'] = form.req.next_tabindex() |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
return name, values, attrs |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
65 |
|
1096 | 66 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
class Input(FieldWidget): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
68 |
"""abstract widget class for <input> tag based widgets""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
type = None |
1474 | 70 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
def render(self, form, field): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
72 |
"""render the widget for the given `field` of `form`. |
1474 | 73 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
74 |
Generate one <input> tag for each field's value |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
75 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
self.add_media(form) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
name, values, attrs = self._render_attrs(form, field) |
1768
b59b7c422a8a
ensure input widgets are displayed anyway if they get an empty list as values
sylvain.thenault@logilab.fr
parents:
1749
diff
changeset
|
78 |
# ensure something is rendered |
b59b7c422a8a
ensure input widgets are displayed anyway if they get an empty list as values
sylvain.thenault@logilab.fr
parents:
1749
diff
changeset
|
79 |
if not values: |
b59b7c422a8a
ensure input widgets are displayed anyway if they get an empty list as values
sylvain.thenault@logilab.fr
parents:
1749
diff
changeset
|
80 |
values = (INTERNAL_FIELD_VALUE,) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
inputs = [tags.input(name=name, value=value, type=self.type, **attrs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
for value in values] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
return u'\n'.join(inputs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
|
1096 | 85 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
86 |
# basic html widgets ########################################################### |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
87 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
class TextInput(Input): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
89 |
"""<input type='text'>""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
type = 'text' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
|
1096 | 92 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
class PasswordInput(Input): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
94 |
"""<input type='password'> and its confirmation field (using |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
95 |
<field's name>-confirm as name) |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
96 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
type = 'password' |
1474 | 98 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
def render(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
self.add_media(form) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
101 |
name, values, attrs = self._render_attrs(form, field) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
102 |
assert len(values) == 1 |
1110
c71997f514ba
fix password widget: do not duplicate dom id, fix confirm field name
sylvain.thenault@logilab.fr
parents:
1096
diff
changeset
|
103 |
id = attrs.pop('id') |
1328
c050f9f8672e
password input may be used with non eidparam fields...
sylvain.thenault@logilab.fr
parents:
1311
diff
changeset
|
104 |
try: |
c050f9f8672e
password input may be used with non eidparam fields...
sylvain.thenault@logilab.fr
parents:
1311
diff
changeset
|
105 |
confirmname = '%s-confirm:%s' % tuple(name.rsplit(':', 1)) |
1329 | 106 |
except TypeError: |
1328
c050f9f8672e
password input may be used with non eidparam fields...
sylvain.thenault@logilab.fr
parents:
1311
diff
changeset
|
107 |
confirmname = '%s-confirm' % name |
1110
c71997f514ba
fix password widget: do not duplicate dom id, fix confirm field name
sylvain.thenault@logilab.fr
parents:
1096
diff
changeset
|
108 |
inputs = [tags.input(name=name, value=values[0], type=self.type, id=id, **attrs), |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
109 |
'<br/>', |
1294
870bc725cc9a
password widget should use the same value as main field for the confirm, else if we don't notice that we got a validation error while no password modification has been done
sylvain.thenault@logilab.fr
parents:
1273
diff
changeset
|
110 |
tags.input(name=confirmname, value=values[0], type=self.type, **attrs), |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
111 |
' ', tags.span(form.req._('confirm password'), |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
112 |
**{'class': 'emphasis'})] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
return u'\n'.join(inputs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
|
1096 | 115 |
|
1934
be86bb31c4c2
add single input password widget
Florent <florent@secondweb.fr>
parents:
1875
diff
changeset
|
116 |
class PasswordSingleInput(Input): |
be86bb31c4c2
add single input password widget
Florent <florent@secondweb.fr>
parents:
1875
diff
changeset
|
117 |
"""<input type='password'> without a confirmation field""" |
be86bb31c4c2
add single input password widget
Florent <florent@secondweb.fr>
parents:
1875
diff
changeset
|
118 |
type = 'password' |
be86bb31c4c2
add single input password widget
Florent <florent@secondweb.fr>
parents:
1875
diff
changeset
|
119 |
|
be86bb31c4c2
add single input password widget
Florent <florent@secondweb.fr>
parents:
1875
diff
changeset
|
120 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
121 |
class FileInput(Input): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
122 |
"""<input type='file'>""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
123 |
type = 'file' |
1474 | 124 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
125 |
def _render_attrs(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
126 |
# ignore value which makes no sense here (XXX even on form validation error?) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
127 |
name, values, attrs = super(FileInput, self)._render_attrs(form, field) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
128 |
return name, ('',), attrs |
1096 | 129 |
|
1474 | 130 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
131 |
class HiddenInput(Input): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
132 |
"""<input type='hidden'>""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
133 |
type = 'hidden' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
134 |
setdomid = False # by default, don't set id attribute on hidden input |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
135 |
settabindex = False |
1096 | 136 |
|
1474 | 137 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
138 |
class ButtonInput(Input): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
139 |
"""<input type='button'> |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
140 |
|
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
141 |
if you want a global form button, look at the Button, SubmitButton, |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
142 |
ResetButton and ImgButton classes below. |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
143 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
144 |
type = 'button' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
145 |
|
1096 | 146 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
147 |
class TextArea(FieldWidget): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
148 |
"""<textarea>""" |
2366
e4229723b824
[formwidgets] let the textarea height be dependant on the actual content (up to a limit)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2360
diff
changeset
|
149 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
150 |
def render(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
151 |
name, values, attrs = self._render_attrs(form, field) |
2131
00e6d1cb18ea
[views] call autogrow only once per key event
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2091
diff
changeset
|
152 |
attrs.setdefault('onkeyup', 'autogrow(this)') |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
153 |
if not values: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
value = u'' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
elif len(values) == 1: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
value = values[0] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
157 |
else: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
158 |
raise ValueError('a textarea is not supposed to be multivalued') |
2366
e4229723b824
[formwidgets] let the textarea height be dependant on the actual content (up to a limit)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2360
diff
changeset
|
159 |
lines = value.splitlines() |
e4229723b824
[formwidgets] let the textarea height be dependant on the actual content (up to a limit)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2360
diff
changeset
|
160 |
linecount = len(lines) |
e4229723b824
[formwidgets] let the textarea height be dependant on the actual content (up to a limit)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2360
diff
changeset
|
161 |
for line in lines: |
e4229723b824
[formwidgets] let the textarea height be dependant on the actual content (up to a limit)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2360
diff
changeset
|
162 |
linecount += len(line) / 80 |
e4229723b824
[formwidgets] let the textarea height be dependant on the actual content (up to a limit)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2360
diff
changeset
|
163 |
attrs.setdefault('cols', 80) |
e4229723b824
[formwidgets] let the textarea height be dependant on the actual content (up to a limit)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2360
diff
changeset
|
164 |
attrs.setdefault('rows', min(15, linecount + 2)) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
return tags.textarea(value, name=name, **attrs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
166 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
167 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
168 |
class FCKEditor(TextArea): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
169 |
"""FCKEditor enabled <textarea>""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
170 |
def __init__(self, *args, **kwargs): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
171 |
super(FCKEditor, self).__init__(*args, **kwargs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
172 |
self.attrs['cubicweb:type'] = 'wysiwyg' |
1474 | 173 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
def render(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
175 |
form.req.fckeditor_config() |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
176 |
return super(FCKEditor, self).render(form, field) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
177 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
178 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
179 |
class Select(FieldWidget): |
1474 | 180 |
"""<select>, for field having a specific vocabulary""" |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
181 |
vocabulary_widget = True |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
182 |
|
1562
e6d2c07c0c58
[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1541
diff
changeset
|
183 |
def __init__(self, attrs=None, multiple=False): |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
184 |
super(Select, self).__init__(attrs) |
1541
ddddbb748355
[widgets] an option for Select to show sorted content
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1538
diff
changeset
|
185 |
self._multiple = multiple |
1474 | 186 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
187 |
def render(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
188 |
name, curvalues, attrs = self._render_attrs(form, field) |
1989
8c8dead642f7
set default select size to 1 into the widget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
189 |
if not 'size' in attrs: |
8c8dead642f7
set default select size to 1 into the widget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
190 |
attrs['size'] = self._multiple and '5' or '1' |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
191 |
options = [] |
1771
bb9538d91465
fix <optgroup> tag cannot be empty according to DTD
Florent <florent@secondweb.fr>
parents:
1768
diff
changeset
|
192 |
optgroup_opened = False |
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
193 |
for option in field.vocabulary(form): |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
194 |
try: |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
195 |
label, value, oattrs = option |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
196 |
except ValueError: |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
197 |
label, value = option |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
198 |
oattrs = {} |
1336
2e552353c42a
insert an optgroup as separator on None values
sylvain.thenault@logilab.fr
parents:
1330
diff
changeset
|
199 |
if value is None: |
2e552353c42a
insert an optgroup as separator on None values
sylvain.thenault@logilab.fr
parents:
1330
diff
changeset
|
200 |
# handle separator |
1771
bb9538d91465
fix <optgroup> tag cannot be empty according to DTD
Florent <florent@secondweb.fr>
parents:
1768
diff
changeset
|
201 |
if optgroup_opened: |
bb9538d91465
fix <optgroup> tag cannot be empty according to DTD
Florent <florent@secondweb.fr>
parents:
1768
diff
changeset
|
202 |
options.append(u'</optgroup>') |
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
203 |
oattrs.setdefault('label', label or '') |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
204 |
options.append(u'<optgroup %s>' % uilib.sgml_attributes(oattrs)) |
1771
bb9538d91465
fix <optgroup> tag cannot be empty according to DTD
Florent <florent@secondweb.fr>
parents:
1768
diff
changeset
|
205 |
optgroup_opened = True |
1336
2e552353c42a
insert an optgroup as separator on None values
sylvain.thenault@logilab.fr
parents:
1330
diff
changeset
|
206 |
elif value in curvalues: |
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
207 |
options.append(tags.option(label, value=value, |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
208 |
selected='selected', **oattrs)) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
209 |
else: |
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
210 |
options.append(tags.option(label, value=value, **oattrs)) |
1771
bb9538d91465
fix <optgroup> tag cannot be empty according to DTD
Florent <florent@secondweb.fr>
parents:
1768
diff
changeset
|
211 |
if optgroup_opened: |
bb9538d91465
fix <optgroup> tag cannot be empty according to DTD
Florent <florent@secondweb.fr>
parents:
1768
diff
changeset
|
212 |
options.append(u'</optgroup>') |
1541
ddddbb748355
[widgets] an option for Select to show sorted content
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1538
diff
changeset
|
213 |
return tags.select(name=name, multiple=self._multiple, |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
214 |
options=options, **attrs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
215 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
216 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
217 |
class CheckBox(Input): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
218 |
"""<input type='checkbox'>, for field having a specific vocabulary. One |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
219 |
input will be generated for each possible value. |
1474 | 220 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
221 |
type = 'checkbox' |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
222 |
vocabulary_widget = True |
1474 | 223 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
224 |
def render(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
225 |
name, curvalues, attrs = self._render_attrs(form, field) |
1367
01bb5b727fe3
set dom id on the first input of radio choices
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
226 |
domid = attrs.pop('id', None) |
2519
ac1a869e1e93
nicer checkbox widget implementation, avoid extra <br/> at the end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2518
diff
changeset
|
227 |
sep = attrs.pop('separator', u'<br/>\n') |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
228 |
options = [] |
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
229 |
for i, option in enumerate(field.vocabulary(form)): |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
230 |
try: |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
231 |
label, value, oattrs = option |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
232 |
except ValueError: |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
233 |
label, value = option |
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
234 |
oattrs = {} |
1367
01bb5b727fe3
set dom id on the first input of radio choices
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
235 |
iattrs = attrs.copy() |
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
236 |
iattrs.update(oattrs) |
1367
01bb5b727fe3
set dom id on the first input of radio choices
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
237 |
if i == 0 and domid is not None: |
2518
38c28ee40138
allow vocabulary functions to return either label/value or label/value/dict (to use as attributes of the tag for this input)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2366
diff
changeset
|
238 |
iattrs.setdefault('id', domid) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
239 |
if value in curvalues: |
1367
01bb5b727fe3
set dom id on the first input of radio choices
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
240 |
iattrs['checked'] = u'checked' |
01bb5b727fe3
set dom id on the first input of radio choices
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
241 |
tag = tags.input(name=name, type=self.type, value=value, **iattrs) |
2519
ac1a869e1e93
nicer checkbox widget implementation, avoid extra <br/> at the end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2518
diff
changeset
|
242 |
options.append(tag + label) |
ac1a869e1e93
nicer checkbox widget implementation, avoid extra <br/> at the end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2518
diff
changeset
|
243 |
return sep.join(options) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
244 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
245 |
|
1832
3384264d25cc
fix CheckBox multiple dom id and refactor with Radio
Florent <florent@secondweb.fr>
parents:
1771
diff
changeset
|
246 |
class Radio(CheckBox): |
3384264d25cc
fix CheckBox multiple dom id and refactor with Radio
Florent <florent@secondweb.fr>
parents:
1771
diff
changeset
|
247 |
"""<input type='radio'>, for field having a specific vocabulary. One |
3384264d25cc
fix CheckBox multiple dom id and refactor with Radio
Florent <florent@secondweb.fr>
parents:
1771
diff
changeset
|
248 |
input will be generated for each possible value. |
3384264d25cc
fix CheckBox multiple dom id and refactor with Radio
Florent <florent@secondweb.fr>
parents:
1771
diff
changeset
|
249 |
""" |
3384264d25cc
fix CheckBox multiple dom id and refactor with Radio
Florent <florent@secondweb.fr>
parents:
1771
diff
changeset
|
250 |
type = 'radio' |
3384264d25cc
fix CheckBox multiple dom id and refactor with Radio
Florent <florent@secondweb.fr>
parents:
1771
diff
changeset
|
251 |
|
2225 | 252 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
253 |
# javascript widgets ########################################################### |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
254 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
255 |
class DateTimePicker(TextInput): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
256 |
"""<input type='text' + javascript date/time picker for date or datetime |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
257 |
fields |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
258 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
259 |
monthnames = ('january', 'february', 'march', 'april', |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
260 |
'may', 'june', 'july', 'august', |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
261 |
'september', 'october', 'november', 'december') |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
262 |
daynames = ('monday', 'tuesday', 'wednesday', 'thursday', |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
263 |
'friday', 'saturday', 'sunday') |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
264 |
|
1311
4cc6e2723dc7
move ajax.js to base form class
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
265 |
needs_js = ('cubicweb.calendar.js',) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
266 |
needs_css = ('cubicweb.calendar_popup.css',) |
1474 | 267 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
268 |
@classmethod |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
269 |
def add_localized_infos(cls, req): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
270 |
"""inserts JS variables defining localized months and days""" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
271 |
# import here to avoid dependancy from cubicweb-common to simplejson |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
272 |
_ = req._ |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
273 |
monthnames = [_(mname) for mname in cls.monthnames] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
274 |
daynames = [_(dname) for dname in cls.daynames] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
275 |
req.html_headers.define_var('MONTHNAMES', monthnames) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
276 |
req.html_headers.define_var('DAYNAMES', daynames) |
1474 | 277 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
278 |
def render(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
279 |
txtwidget = super(DateTimePicker, self).render(form, field) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
280 |
self.add_localized_infos(form.req) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
281 |
cal_button = self._render_calendar_popup(form, field) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
282 |
return txtwidget + cal_button |
1474 | 283 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
284 |
def _render_calendar_popup(self, form, field): |
1392
d6279efff7b3
refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents:
1389
diff
changeset
|
285 |
value = form.form_field_value(field) |
d6279efff7b3
refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents:
1389
diff
changeset
|
286 |
if not value: |
d6279efff7b3
refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents:
1389
diff
changeset
|
287 |
value = date.today() |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
288 |
inputid = form.context[field]['id'] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
289 |
helperid = '%shelper' % inputid |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
290 |
year, month = value.year, value.month |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
291 |
return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper"> |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
292 |
<img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>""" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
293 |
% (helperid, inputid, year, month, |
1392
d6279efff7b3
refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents:
1389
diff
changeset
|
294 |
form.req.external_resource('CALENDAR_ICON'), |
d6279efff7b3
refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents:
1389
diff
changeset
|
295 |
form.req._('calendar'), helperid) ) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
296 |
|
1474 | 297 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
298 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
299 |
# ajax widgets ################################################################ |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
300 |
|
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
301 |
def init_ajax_attributes(attrs, wdgtype, loadtype=u'auto'): |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
302 |
try: |
1344
930020cb134b
shouldn't use unicode keys in attrs
sylvain.thenault@logilab.fr
parents:
1337
diff
changeset
|
303 |
attrs['klass'] += u' widget' |
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
304 |
except KeyError: |
1344
930020cb134b
shouldn't use unicode keys in attrs
sylvain.thenault@logilab.fr
parents:
1337
diff
changeset
|
305 |
attrs['klass'] = u'widget' |
930020cb134b
shouldn't use unicode keys in attrs
sylvain.thenault@logilab.fr
parents:
1337
diff
changeset
|
306 |
attrs.setdefault('cubicweb:wdgtype', wdgtype) |
930020cb134b
shouldn't use unicode keys in attrs
sylvain.thenault@logilab.fr
parents:
1337
diff
changeset
|
307 |
attrs.setdefault('cubicweb:loadtype', loadtype) |
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
308 |
|
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
309 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
310 |
class AjaxWidget(FieldWidget): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
311 |
"""simple <div> based ajax widget""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
312 |
def __init__(self, wdgtype, inputid=None, **kwargs): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
313 |
super(AjaxWidget, self).__init__(**kwargs) |
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
314 |
init_ajax_attributes(self.attrs, wdgtype) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
315 |
if inputid is not None: |
1344
930020cb134b
shouldn't use unicode keys in attrs
sylvain.thenault@logilab.fr
parents:
1337
diff
changeset
|
316 |
self.attrs['cubicweb:inputid'] = inputid |
1474 | 317 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
318 |
def render(self, form, field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
319 |
self.add_media(form) |
1147 | 320 |
attrs = self._render_attrs(form, field)[-1] |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
321 |
return tags.div(**attrs) |
1304 | 322 |
|
1474 | 323 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
324 |
class AutoCompletionWidget(TextInput): |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
325 |
"""ajax widget for StringField, proposing matching existing values as you |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
326 |
type. |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
327 |
""" |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
328 |
needs_js = ('cubicweb.widgets.js', 'jquery.autocomplete.js') |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
329 |
needs_css = ('jquery.autocomplete.css',) |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
330 |
wdgtype = 'SuggestField' |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
331 |
loadtype = 'auto' |
1474 | 332 |
|
1966
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
333 |
def __init__(self, *args, **kwargs): |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
334 |
try: |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
335 |
self.autocomplete_initfunc = kwargs.pop('autocomplete_initfunc') |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
336 |
except KeyError: |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
337 |
warn('use autocomplete_initfunc argument of %s constructor ' |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
338 |
'instead of relying on autocomplete_initfuncs dictionary on ' |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
339 |
'the entity class' % self.__class__.__name__, |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
340 |
DeprecationWarning) |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
341 |
self.autocomplete_initfunc = None |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
342 |
super(AutoCompletionWidget, self).__init__(*args, **kwargs) |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
343 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
344 |
def _render_attrs(self, form, field): |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
345 |
name, values, attrs = super(AutoCompletionWidget, self)._render_attrs(form, field) |
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
346 |
init_ajax_attributes(attrs, self.wdgtype, self.loadtype) |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
347 |
# XXX entity form specific |
1875
7bcb02377516
no rschema attribute on widgets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1874
diff
changeset
|
348 |
attrs['cubicweb:dataurl'] = self._get_url(form.edited_entity, field) |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
349 |
return name, values, attrs |
1474 | 350 |
|
1875
7bcb02377516
no rschema attribute on widgets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1874
diff
changeset
|
351 |
def _get_url(self, entity, field): |
1966
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
352 |
if self.autocomplete_initfunc is None: |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
353 |
# XXX for bw compat |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
354 |
fname = entity.autocomplete_initfuncs[field.name] |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
355 |
else: |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
356 |
fname = self.autocomplete_initfunc |
1875
7bcb02377516
no rschema attribute on widgets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1874
diff
changeset
|
357 |
return entity.req.build_url('json', fname=fname, mode='remote', |
7bcb02377516
no rschema attribute on widgets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1874
diff
changeset
|
358 |
pageid=entity.req.pageid) |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
359 |
|
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
360 |
|
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
361 |
class StaticFileAutoCompletionWidget(AutoCompletionWidget): |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
362 |
"""XXX describe me""" |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
363 |
wdgtype = 'StaticFileSuggestField' |
1474 | 364 |
|
1875
7bcb02377516
no rschema attribute on widgets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1874
diff
changeset
|
365 |
def _get_url(self, entity, field): |
1966
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
366 |
if self.autocomplete_initfunc is None: |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
367 |
# XXX for bw compat |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
368 |
fname = entity.autocomplete_initfuncs[field.name] |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
369 |
else: |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
370 |
fname = self.autocomplete_initfunc |
87ce7d336393
stop using autocomplete_initfuncs dict on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1934
diff
changeset
|
371 |
return entity.req.datadir_url + fname |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
372 |
|
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
373 |
|
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
374 |
class RestrictedAutoCompletionWidget(AutoCompletionWidget): |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
375 |
"""XXX describe me""" |
1474 | 376 |
wdgtype = 'RestrictedSuggestField' |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
377 |
|
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
378 |
|
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
379 |
class AddComboBoxWidget(Select): |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
380 |
def _render_attrs(self, form, field): |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
381 |
name, values, attrs = super(AddComboBoxWidget, self)._render_attrs(form, field) |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
382 |
init_ajax_attributes(self.attrs, 'AddComboBox') |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
383 |
# XXX entity form specific |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
384 |
entity = form.edited_entity |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
385 |
attrs['cubicweb:etype_to'] = entity.e_schema |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
386 |
etype_from = entity.e_schema.subject_relation(self.name).objects(entity.e_schema)[0] |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
387 |
attrs['cubicweb:etype_from'] = etype_from |
1474 | 388 |
|
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
389 |
def render(self, form, field): |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
390 |
return super(AddComboBoxWidget, self).render(form, field) + u''' |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
391 |
<div id="newvalue"> |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
392 |
<input type="text" id="newopt" /> |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
393 |
<a href="javascript:noop()" id="add_newopt"> </a></div> |
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
394 |
''' |
1359 | 395 |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
396 |
# buttons ###################################################################### |
1304 | 397 |
|
398 |
class Button(Input): |
|
1389 | 399 |
"""<input type='button'>, base class for global form buttons |
400 |
||
401 |
note label is a msgid which will be translated at form generation time, you |
|
402 |
should not give an already translated string. |
|
403 |
""" |
|
1304 | 404 |
type = 'button' |
405 |
def __init__(self, label=stdmsgs.BUTTON_OK, attrs=None, |
|
406 |
setdomid=None, settabindex=None, |
|
407 |
name='', value='', onclick=None, cwaction=None): |
|
408 |
super(Button, self).__init__(attrs, setdomid, settabindex) |
|
409 |
self.label = label |
|
410 |
self.name = name |
|
411 |
self.value = '' |
|
412 |
self.onclick = onclick |
|
413 |
self.cwaction = cwaction |
|
414 |
self.attrs.setdefault('klass', 'validateButton') |
|
1474 | 415 |
|
1304 | 416 |
def render(self, form, field=None): |
417 |
label = form.req._(self.label) |
|
418 |
attrs = self.attrs.copy() |
|
419 |
if self.cwaction: |
|
420 |
assert self.onclick is None |
|
421 |
attrs['onclick'] = "postForm('__action_%s', \'%s\', \'%s\')" % ( |
|
422 |
self.cwaction, self.label, form.domid) |
|
423 |
elif self.onclick: |
|
424 |
attrs['onclick'] = self.onclick |
|
425 |
if self.name: |
|
426 |
attrs['name'] = name |
|
427 |
if self.setdomid: |
|
428 |
attrs['id'] = self.name |
|
429 |
if self.settabindex and not 'tabindex' in attrs: |
|
430 |
attrs['tabindex'] = form.req.next_tabindex() |
|
431 |
return tags.input(value=label, type=self.type, **attrs) |
|
432 |
||
1474 | 433 |
|
1304 | 434 |
class SubmitButton(Button): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
435 |
"""<input type='submit'>, main button to submit a form""" |
1304 | 436 |
type = 'submit' |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
437 |
|
1474 | 438 |
|
1304 | 439 |
class ResetButton(Button): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
440 |
"""<input type='reset'>, main button to reset a form. |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
441 |
You usually don't want this. |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
442 |
""" |
1304 | 443 |
type = 'reset' |
444 |
||
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
445 |
|
1304 | 446 |
class ImgButton(object): |
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
447 |
"""<img> wrapped into a <a> tag with href triggering something (usually a |
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
448 |
javascript call) |
1389 | 449 |
|
450 |
note label is a msgid which will be translated at form generation time, you |
|
451 |
should not give an already translated string. |
|
1330
92343a468e2a
add some documentation, backport *CompletionWidget
sylvain.thenault@logilab.fr
parents:
1329
diff
changeset
|
452 |
""" |
1304 | 453 |
def __init__(self, domid, href, label, imgressource): |
454 |
self.domid = domid |
|
455 |
self.href = href |
|
456 |
self.imgressource = imgressource |
|
457 |
self.label = label |
|
1474 | 458 |
|
1304 | 459 |
def render(self, form, field=None): |
1389 | 460 |
label = form.req._(self.label) |
461 |
imgsrc = form.req.external_resource(self.imgressource) |
|
462 |
return '<a id="%(domid)s" href="%(href)s">'\ |
|
463 |
'<img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % { |
|
464 |
'label': label, 'imgsrc': imgsrc, |
|
465 |
'domid': self.domid, 'href': self.href} |
|
1474 | 466 |
|
1304 | 467 |
|
1474 | 468 |
|
1337
828bbf500bcc
backport AddComboBoxWidget, ajax widgets refactoring
sylvain.thenault@logilab.fr
parents:
1336
diff
changeset
|
469 |
# XXX EntityLinkComboBoxWidget, [Raw]DynamicComboBoxWidget |