Module: check_mk
Branch: master
Commit: 4ae5278c217c8c17e5852b8739a15c6d624d045f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4ae5278c217c8c…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Thu Dec 1 12:08:54 2016 +0100
htmllib: Refactored radiobuttons.
---
web/htdocs/htmllib.py | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index aba534d..1f9bd44 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1920,33 +1920,30 @@ class html(DeprecationWrapper):
def begin_radio_group(self, horizontal=False):
if self.mobile:
- if horizontal:
- add = 'data-type="horizontal" '
- else:
- add = ''
- self.write('<fieldset %s data-role="controlgroup">' %
add)
+ attrs = {'data-type' : "horizontal" if horizontal else
None,
+ 'data-role' : "controlgroup"}
+ self.write(self._render_opening_tag("fieldset", **attrs))
def end_radio_group(self):
if self.mobile:
- self.write('</fieldset>')
+ self.write(self._render_closing_tag("fieldset"))
def radiobutton(self, varname, value, checked, label):
+ # Model
+ self.form_vars.append(varname)
+
+ # Controller
if self.has_var(varname):
checked = self.var(varname) == value
- checked_text = checked and " checked" or ""
- if label:
- id = "rb_%s_%s" % (varname, self.attrencode(value))
- idtxt = ' id="%s"' % id
- else:
- idtxt = ""
- self.write("<input type=radio name=%s
value=\"%s\"%s%s>\n" %
- (varname, self.attrencode(value), checked_text, idtxt))
- if label:
- self.write('<label for="%s">%s</label>\n' %
(id, label))
- self.form_vars.append(varname)
+ # View
+ id_="rb_%s_%s" % (varname, value) if label else None
+ self.input(name=varname, type_="radio", value = value,
+ checked="" if checked else None, id_=id_)
+ if label:
+ self.label(label, for_=id_)
def begin_checkbox_group(self, horizonal=False):
self.begin_radio_group(horizonal)