309 |
309 |
310 |
310 |
311 # basic html widgets ########################################################### |
311 # basic html widgets ########################################################### |
312 |
312 |
313 class TextInput(Input): |
313 class TextInput(Input): |
314 """Simple <input type='text'>, will return an unicode string.""" |
314 """Simple <input type='text'>, will return a unicode string.""" |
315 type = 'text' |
315 type = 'text' |
316 |
316 |
317 |
317 |
318 class EmailInput(Input): |
318 class EmailInput(Input): |
319 """Simple <input type='email'>, will return a unicode string.""" |
319 """Simple <input type='email'>, will return a unicode string.""" |
320 type = 'email' |
320 type = 'email' |
321 |
321 |
322 |
322 |
323 class PasswordSingleInput(Input): |
323 class PasswordSingleInput(Input): |
324 """Simple <input type='password'>, will return an utf-8 encoded string. |
324 """Simple <input type='password'>, will return a utf-8 encoded string. |
325 |
325 |
326 You may prefer using the :class:`~cubicweb.web.formwidgets.PasswordInput` |
326 You may prefer using the :class:`~cubicweb.web.formwidgets.PasswordInput` |
327 widget which handles password confirmation. |
327 widget which handles password confirmation. |
328 """ |
328 """ |
329 type = 'password' |
329 type = 'password' |
336 |
336 |
337 |
337 |
338 class PasswordInput(Input): |
338 class PasswordInput(Input): |
339 """<input type='password'> and a confirmation input. Form processing will |
339 """<input type='password'> and a confirmation input. Form processing will |
340 fail if password and confirmation differs, else it will return the password |
340 fail if password and confirmation differs, else it will return the password |
341 as an utf-8 encoded string. |
341 as a utf-8 encoded string. |
342 """ |
342 """ |
343 type = 'password' |
343 type = 'password' |
344 |
344 |
345 def _render(self, form, field, renderer): |
345 def _render(self, form, field, renderer): |
346 assert self.suffix is None, 'suffix not supported' |
346 assert self.suffix is None, 'suffix not supported' |
377 # ignore value which makes no sense here (XXX even on form validation error?) |
377 # ignore value which makes no sense here (XXX even on form validation error?) |
378 return ('',) |
378 return ('',) |
379 |
379 |
380 |
380 |
381 class HiddenInput(Input): |
381 class HiddenInput(Input): |
382 """Simple <input type='hidden'> for hidden value, will return an unicode |
382 """Simple <input type='hidden'> for hidden value, will return a unicode |
383 string. |
383 string. |
384 """ |
384 """ |
385 type = 'hidden' |
385 type = 'hidden' |
386 setdomid = False # by default, don't set id attribute on hidden input |
386 setdomid = False # by default, don't set id attribute on hidden input |
387 settabindex = False |
387 settabindex = False |
388 |
388 |
389 |
389 |
390 class ButtonInput(Input): |
390 class ButtonInput(Input): |
391 """Simple <input type='button'>, will return an unicode string. |
391 """Simple <input type='button'>, will return a unicode string. |
392 |
392 |
393 If you want a global form button, look at the :class:`Button`, |
393 If you want a global form button, look at the :class:`Button`, |
394 :class:`SubmitButton`, :class:`ResetButton` and :class:`ImgButton` below. |
394 :class:`SubmitButton`, :class:`ResetButton` and :class:`ImgButton` below. |
395 """ |
395 """ |
396 type = 'button' |
396 type = 'button' |
397 |
397 |
398 |
398 |
399 class TextArea(FieldWidget): |
399 class TextArea(FieldWidget): |
400 """Simple <textarea>, will return an unicode string.""" |
400 """Simple <textarea>, will return a unicode string.""" |
401 |
401 |
402 def _render(self, form, field, renderer): |
402 def _render(self, form, field, renderer): |
403 values, attrs = self.values_and_attributes(form, field) |
403 values, attrs = self.values_and_attributes(form, field) |
404 attrs.setdefault('onkeyup', 'autogrow(this)') |
404 attrs.setdefault('onkeyup', 'autogrow(this)') |
405 if not values: |
405 if not values: |
417 return tags.textarea(value, name=field.input_name(form, self.suffix), |
417 return tags.textarea(value, name=field.input_name(form, self.suffix), |
418 **attrs) |
418 **attrs) |
419 |
419 |
420 |
420 |
421 class FCKEditor(TextArea): |
421 class FCKEditor(TextArea): |
422 """FCKEditor enabled <textarea>, will return an unicode string containing |
422 """FCKEditor enabled <textarea>, will return a unicode string containing |
423 HTML formated text. |
423 HTML formated text. |
424 """ |
424 """ |
425 def __init__(self, *args, **kwargs): |
425 def __init__(self, *args, **kwargs): |
426 super(FCKEditor, self).__init__(*args, **kwargs) |
426 super(FCKEditor, self).__init__(*args, **kwargs) |
427 self.attrs['cubicweb:type'] = 'wysiwyg' |
427 self.attrs['cubicweb:type'] = 'wysiwyg' |
431 return super(FCKEditor, self)._render(form, field, renderer) |
431 return super(FCKEditor, self)._render(form, field, renderer) |
432 |
432 |
433 |
433 |
434 class Select(FieldWidget): |
434 class Select(FieldWidget): |
435 """Simple <select>, for field having a specific vocabulary. Will return |
435 """Simple <select>, for field having a specific vocabulary. Will return |
436 an unicode string, or a list of unicode strings. |
436 a unicode string, or a list of unicode strings. |
437 """ |
437 """ |
438 vocabulary_widget = True |
438 vocabulary_widget = True |
439 default_size = 10 |
439 default_size = 10 |
440 |
440 |
441 def __init__(self, attrs=None, multiple=False, **kwargs): |
441 def __init__(self, attrs=None, multiple=False, **kwargs): |
627 |
627 |
628 # javascript widgets ########################################################### |
628 # javascript widgets ########################################################### |
629 |
629 |
630 class DateTimePicker(TextInput): |
630 class DateTimePicker(TextInput): |
631 """<input type='text'> + javascript date/time picker for date or datetime |
631 """<input type='text'> + javascript date/time picker for date or datetime |
632 fields. Will return the date or datetime as an unicode string. |
632 fields. Will return the date or datetime as a unicode string. |
633 """ |
633 """ |
634 monthnames = ('january', 'february', 'march', 'april', |
634 monthnames = ('january', 'february', 'march', 'april', |
635 'may', 'june', 'july', 'august', |
635 'may', 'june', 'july', 'august', |
636 'september', 'october', 'november', 'december') |
636 'september', 'october', 'november', 'december') |
637 daynames = ('monday', 'tuesday', 'wednesday', 'thursday', |
637 daynames = ('monday', 'tuesday', 'wednesday', 'thursday', |
669 form._cw._('calendar'), helperid) ) |
669 form._cw._('calendar'), helperid) ) |
670 |
670 |
671 |
671 |
672 class JQueryDatePicker(FieldWidget): |
672 class JQueryDatePicker(FieldWidget): |
673 """Use jquery.ui.datepicker to define a date picker. Will return the date as |
673 """Use jquery.ui.datepicker to define a date picker. Will return the date as |
674 an unicode string. |
674 a unicode string. |
675 """ |
675 """ |
676 needs_js = ('jquery.ui.js', ) |
676 needs_js = ('jquery.ui.js', ) |
677 needs_css = ('jquery.ui.css',) |
677 needs_css = ('jquery.ui.css',) |
678 default_size = 10 |
678 default_size = 10 |
679 |
679 |
929 fields = [f.render(form, renderer) for f in field.subfields(form)] |
929 fields = [f.render(form, renderer) for f in field.subfields(form)] |
930 return u'<div>%s</div>' % ' '.join(fields) |
930 return u'<div>%s</div>' % ' '.join(fields) |
931 |
931 |
932 |
932 |
933 class EditableURLWidget(FieldWidget): |
933 class EditableURLWidget(FieldWidget): |
934 """Custom widget to edit separatly an url path / query string (used by |
934 """Custom widget to edit separatly a URL path / query string (used by |
935 default for the `path` attribute of `Bookmark` entities). |
935 default for the `path` attribute of `Bookmark` entities). |
936 |
936 |
937 It deals with url quoting nicely so that the user edit the unquoted value. |
937 It deals with url quoting nicely so that the user edit the unquoted value. |
938 """ |
938 """ |
939 |
939 |