Module: check_mk
Branch: master
Commit: e736f0f54a6b08fc5b951650ede6e99188bac85f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e736f0f54a6b08…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Nov 28 18:41:56 2011 +0100
Mobile: first version of filter form
---
web/htdocs/htmllib.py | 27 +++++++++++++++++++++------
web/htdocs/mobile.css | 11 +++++++++++
web/htdocs/mobile.py | 21 ++++++++++++++++++++-
web/plugins/views/filters.py | 7 +++----
4 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index a8c9164..0ac7690 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -439,15 +439,24 @@ class html:
if varname:
self.form_vars.append(varname)
- def radiobutton(self, varname, value, checked, text):
+ def radiobutton(self, varname, value, checked, label):
if self.has_var(varname):
checked = self.var(varname) == value
checked_text = checked and " checked" or ""
- self.write("<input type=radio name=%s value=\"%s\"%s>
%s\n" %
- (varname, value, checked_text, text))
+ if label:
+ id = "rb_%s_%s" % (varname, value)
+ idtxt = ' id="%s"' % id
+ else:
+ idtxt = ""
+ self.write("<input type=radio name=%s
value=\"%s\"%s%s>\n" %
+ (varname, value, checked_text, idtxt))
+ if label:
+ self.write('<label for="%s">%s</label>\n' %
(id, label))
self.form_vars.append(varname)
- def checkbox(self, varname, deflt=False, cssclass = '', onclick = None,
add_attr = []):
+ def checkbox(self, varname, deflt=False, cssclass = '', onclick = None,
label=None, id=None, add_attr = None):
+ if add_attr == None:
+ add_attr = [] # do not use [] as default element, it will be a global
variable!
error = self.user_errors.get(varname)
if error:
html = "<x class=inputerror>"
@@ -460,13 +469,19 @@ class html:
if value == None: # form not yet filled in
value = deflt
- checked = value and " CHECKED" or ""
+ checked = value and " CHECKED " or ""
if cssclass:
cssclass = ' class="%s"' % cssclass
onclick_code = onclick and " onclick=\"%s\"" % (onclick) or
""
- self.write("<input type=checkbox name=\"%s\"%s%s%s%s>"
%
+ if label and not id:
+ id = "cb_" + varname
+ if id:
+ add_attr.append('id="%s"' % id)
+ self.write("<input type=checkbox
name=\"%s\"%s%s%s%s>\n" %
(varname, checked, cssclass, onclick_code, "
".join(add_attr)))
self.form_vars.append(varname)
+ if label:
+ self.write('<label for="%s">%s</label>\n' %
(id, label))
if error:
html += "</x>"
diff --git a/web/htdocs/mobile.css b/web/htdocs/mobile.css
index 46e5524..b966216 100644
--- a/web/htdocs/mobile.css
+++ b/web/htdocs/mobile.css
@@ -36,6 +36,17 @@ body.mobile table.dataset tr.data td {
font-size: 10pt;
}
+/* Forms for filters and commands */
+body.mobile table.form {
+ width: 100%;
+}
+body.mobile table.form > tbody > tr > * {
+ width: 100%;
+}
+body.mobile table.form th {
+ border-style: none;
+}
+
/* Perfometers */
diff --git a/web/htdocs/mobile.py b/web/htdocs/mobile.py
index b77cbb1..cfa629f 100644
--- a/web/htdocs/mobile.py
+++ b/web/htdocs/mobile.py
@@ -168,7 +168,7 @@ def render_view(view, rows, datasource, group_painters, painters,
# Page: Filters
jqm_page_header(_("Filter / Search"), home="mobile.py",
id="filter")
- jqm_page_content("Hier kommen die Filter")
+ show_filter_form(show_filters)
jqm_page_navfooter(navbar, '#filter', page_id)
# Page: Context buttons
@@ -178,6 +178,25 @@ def render_view(view, rows, datasource, group_painters, painters,
jqm_page_navfooter(navbar, '#filter', page_id)
+def show_filter_form(show_filters):
+ # Sort filters
+ s = [(f.sort_index, f.title, f) for f in show_filters if f.available()]
+ s.sort()
+
+ html.begin_form("filter")
+ html.write('<table class="form">\n')
+
+ for sort_index, title, f in s:
+ html.write('<tr><th>%s</th></tr>\n' % title)
+ html.write('<tr><td>\n')
+ f.display()
+ html.write('</td></tr>\n')
+ html.write("</table>\n")
+
+ html.hidden_fields()
+ html.end_form()
+
+
def show_context_links(context_links):
items = []
for view, title, uri, icon, buttonid in context_links:
diff --git a/web/plugins/views/filters.py b/web/plugins/views/filters.py
index 3325604..e4fbb15 100644
--- a/web/plugins/views/filters.py
+++ b/web/plugins/views/filters.py
@@ -191,8 +191,8 @@ class FilterServiceState(Filter):
for var, text in [(self.prefix + "st0", "OK"), (self.prefix +
"st1", "WARN"), \
(self.prefix + "st2", "CRIT"), (self.prefix
+ "st3", "UNKNOWN"),
(self.prefix + "stp", "PENDING")]:
- html.checkbox(var, True)
- html.write(" %s " % text)
+ html.checkbox(var, True, label=text)
+ # html.write(" %s " % text)
def filter(self, infoname):
headers = []
@@ -223,8 +223,7 @@ class FilterHostState(Filter):
def display(self):
for var, text in [("hst0", _("UP")), ("hst1",
_("DOWN")),
("hst2", _("UNREACH")), ("hstp",
_("PENDING"))]:
- html.checkbox(var, True)
- html.write(" %s " % text)
+ html.checkbox(var, True, label=text)
def filter(self, infoname):
headers = []