Module: check_mk
Branch: master
Commit: 1f68a922c18d4cc32b19b63d6f441372cc7232a5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1f68a922c18d4c…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Dec 29 13:33:03 2011 +0100
Create new helper lib forms.py
---
web/htdocs/forms.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
web/htdocs/htmllib.py | 8 +++---
web/htdocs/pages.css | 5 +++
web/htdocs/wato.css | 5 ---
4 files changed, 79 insertions(+), 9 deletions(-)
diff --git a/web/htdocs/forms.py b/web/htdocs/forms.py
new file mode 100644
index 0000000..7ad903e
--- /dev/null
+++ b/web/htdocs/forms.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2012 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+from lib import *
+
+
+def edit_dictionary(entries, value):
+ new_value = {}
+ if html.check_transaction():
+ messages = []
+ for name, vs in entries:
+ try:
+ v = vs.from_html_vars(name)
+ vs.validate_value(v, name)
+ new_value[name] = v
+ except MKUserError, e:
+ messages.append(vs.title() + ": " + e.message)
+ html.add_user_error(e.varname, e.message)
+ if messages:
+ html.show_error("".join(["%s<br>\n" % m for m in
messages]))
+ else:
+ return new_value
+
+ html.begin_form("form")
+ html.write("<table class=form>\n")
+ first = True
+ for name, vs in entries:
+ html.write("<tr><td class=legend>%s" % vs.title())
+ if vs.help():
+ html.write("<br><i>%s</i>" % vs.help())
+ html.write("</td><td class=content>")
+ if name in value:
+ v = value[name]
+ else:
+ v = vs.default_value()
+ vs.render_input(name, v)
+ if first:
+ vs.set_focus(name)
+ first = False
+ html.write("<tr><td class=buttons colspan=2>")
+ html.button("save", _("Save"))
+ html.write("</td></tr>\n")
+ html.write("</table>\n")
+ html.hidden_fields()
+ html.end_form()
+
+
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 0cbbc74..80d47d8 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -322,15 +322,15 @@ class html:
(obj_id, style, title, disabled, text, href))
# self.write("<a href=\"%s\"
class=button%s%s>%s</a>" % (href, obj_id, style, text))
- def icon_button(url, help, icon):
- html.write('<a href="%s">'
+ def icon_button(self, url, help, icon):
+ self.write('<a href="%s">'
'<img class=iconbutton title="%s"
src="images/button_%s_lo.png" '
'onmouseover=\"hilite_icon(this, 1)\" '
'onmouseout=\"hilite_icon(this, 0)\">'
'</a>\n' % (url, help, icon))
- def empty_icon_button():
- html.write('<img class=trans src="images/trans.png">')
+ def empty_icon_button(self):
+ self.write('<img class=trans src="images/trans.png">')
def jsbutton(self, varname, text, onclick, style=''):
if style:
diff --git a/web/htdocs/pages.css b/web/htdocs/pages.css
index 124d389..f0cb41f 100644
--- a/web/htdocs/pages.css
+++ b/web/htdocs/pages.css
@@ -321,6 +321,11 @@ tr.groupheader a:hover {
border: 1px solid #fff;
}
+img.iconbutton {
+ width: 20px;
+ height: 20px;
+}
+
/*-------------------------------------------------------------------------.
| _____ |
| | ___|__ _ __ _ __ ___ ___ |
diff --git a/web/htdocs/wato.css b/web/htdocs/wato.css
index d249448..4021bac 100644
--- a/web/htdocs/wato.css
+++ b/web/htdocs/wato.css
@@ -290,11 +290,6 @@ Boston, MA 02110-1301 USA.
top: 3px;
}
-.wato img.iconbutton {
- width: 20px;
- height: 20px;
-}
-
.wato img.trans {
width: 24px;
}