equal
deleted
inserted
replaced
11 from warnings import warn |
11 from warnings import warn |
12 |
12 |
13 from cubicweb.common import tags, uilib |
13 from cubicweb.common import tags, uilib |
14 from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE, ProcessFormError |
14 from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE, ProcessFormError |
15 |
15 |
|
16 from logilab.mtconverter import xml_escape |
16 |
17 |
17 class FieldWidget(object): |
18 class FieldWidget(object): |
18 """abstract widget class""" |
19 """abstract widget class""" |
19 # javascript / css files required by the widget |
20 # javascript / css files required by the widget |
20 needs_js = () |
21 needs_js = () |
470 type = 'button' |
471 type = 'button' |
471 def __init__(self, label=stdmsgs.BUTTON_OK, attrs=None, |
472 def __init__(self, label=stdmsgs.BUTTON_OK, attrs=None, |
472 setdomid=None, settabindex=None, |
473 setdomid=None, settabindex=None, |
473 name='', value='', onclick=None, cwaction=None): |
474 name='', value='', onclick=None, cwaction=None): |
474 super(Button, self).__init__(attrs, setdomid, settabindex) |
475 super(Button, self).__init__(attrs, setdomid, settabindex) |
475 self.label = label |
476 if isinstance(label, tuple): |
|
477 self.label = label[0] |
|
478 self.icon = label[1] |
|
479 else: |
|
480 self.label = label |
|
481 self.icon = None |
476 self.name = name |
482 self.name = name |
477 self.value = '' |
483 self.value = '' |
478 self.onclick = onclick |
484 self.onclick = onclick |
479 self.cwaction = cwaction |
485 self.cwaction = cwaction |
480 self.attrs.setdefault('klass', 'validateButton') |
486 self.attrs.setdefault('klass', 'validateButton') |
492 attrs['name'] = name |
498 attrs['name'] = name |
493 if self.setdomid: |
499 if self.setdomid: |
494 attrs['id'] = self.name |
500 attrs['id'] = self.name |
495 if self.settabindex and not 'tabindex' in attrs: |
501 if self.settabindex and not 'tabindex' in attrs: |
496 attrs['tabindex'] = form._cw.next_tabindex() |
502 attrs['tabindex'] = form._cw.next_tabindex() |
497 return tags.input(value=label, type=self.type, **attrs) |
503 if self.icon: |
|
504 img = tags.img(src=form._cw.external_resource(self.icon), alt=self.icon) |
|
505 else: |
|
506 img = u'' |
|
507 return tags.button(img + xml_escape(label), escapecontent=False, |
|
508 value=label, type=self.type, **attrs) |
498 |
509 |
499 |
510 |
500 class SubmitButton(Button): |
511 class SubmitButton(Button): |
501 """<input type='submit'>, main button to submit a form""" |
512 """<input type='submit'>, main button to submit a form""" |
502 type = 'submit' |
513 type = 'submit' |