226 |
227 |
227 def render(self, form, field): |
228 def render(self, form, field): |
228 self.add_media(form) |
229 self.add_media(form) |
229 attrs = self._render_attrs(form, field)[-1] |
230 attrs = self._render_attrs(form, field)[-1] |
230 return tags.div(**attrs) |
231 return tags.div(**attrs) |
|
232 |
|
233 |
|
234 class Button(Input): |
|
235 type = 'button' |
|
236 def __init__(self, label=stdmsgs.BUTTON_OK, attrs=None, |
|
237 setdomid=None, settabindex=None, |
|
238 name='', value='', onclick=None, cwaction=None): |
|
239 super(Button, self).__init__(attrs, setdomid, settabindex) |
|
240 self.label = label |
|
241 self.name = name |
|
242 self.value = '' |
|
243 self.onclick = onclick |
|
244 self.cwaction = cwaction |
|
245 self.attrs.setdefault('klass', 'validateButton') |
|
246 |
|
247 def render(self, form, field=None): |
|
248 label = form.req._(self.label) |
|
249 attrs = self.attrs.copy() |
|
250 if self.cwaction: |
|
251 assert self.onclick is None |
|
252 attrs['onclick'] = "postForm('__action_%s', \'%s\', \'%s\')" % ( |
|
253 self.cwaction, self.label, form.domid) |
|
254 elif self.onclick: |
|
255 attrs['onclick'] = self.onclick |
|
256 if self.name: |
|
257 attrs['name'] = name |
|
258 if self.setdomid: |
|
259 attrs['id'] = self.name |
|
260 if self.settabindex and not 'tabindex' in attrs: |
|
261 attrs['tabindex'] = form.req.next_tabindex() |
|
262 return tags.input(value=label, type=self.type, **attrs) |
|
263 |
|
264 |
|
265 class SubmitButton(Button): |
|
266 type = 'submit' |
|
267 |
|
268 class ResetButton(Button): |
|
269 type = 'reset' |
|
270 |
|
271 class ImgButton(object): |
|
272 def __init__(self, domid, href, label, imgressource): |
|
273 self.domid = domid |
|
274 self.href = href |
|
275 self.imgressource = imgressource |
|
276 self.label = label |
|
277 |
|
278 def render(self, form, field=None): |
|
279 self.imgsrc = form.req.external_resource(self.imgressource) |
|
280 return '<a id="%(domid)s" href="%(href)s"><img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % self.__dict__ |
|
281 |
|
282 |
|
283 # XXX EntityLinkComboBoxWidget, AddComboBoxWidget, AutoCompletionWidget, |
|
284 # StaticFileAutoCompletionWidget, RestrictedAutoCompletionWidget... |