Module: check_mk
Branch: master
Commit: 7fbaa0c2412a2c42aa6ef5b68ca6a237c551ba8c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7fbaa0c2412a2c…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun May 27 11:04:28 2012 +0200
ValueSpec Dictionary: new rendering function, fix focus code
---
web/htdocs/valuespec.py | 36 +++++++++++++++++++++++++++++++++---
web/htdocs/wato.py | 12 +++++++++---
web/plugins/sidebar/wato.py | 4 +++-
3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 62ee869..5e3e858 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1,4 +1,4 @@
-
+#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
@@ -24,7 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import math, os, time, re, sre_constants, urlparse
+import math, os, time, re, sre_constants, urlparse, forms
from lib import *
# Abstract base class of all value declaration classes.
@@ -1613,8 +1613,15 @@ class Dictionary(ValueSpec):
self._optional_keys = kwargs.get("optional_keys", True)
self._required_keys = kwargs.get("required_keys", [])
self._columns = kwargs.get("columns", 1) # possible: 1 or 2
+ self._render = kwargs.get("render", "normal") # also:
"form" -> use forms.section()
def render_input(self, varprefix, value):
+ if self._render == "form":
+ self.render_input_form(varprefix, value)
+ else:
+ self.render_input_normal(varprefix, value)
+
+ def render_input_normal(self, varprefix, value):
html.write("<table class=dictionary>")
for param, vs in self._elements:
html.write("<tr><td class=dictleft>")
@@ -1646,8 +1653,31 @@ class Dictionary(ValueSpec):
html.write("</div></td></tr>")
html.write("</table>")
+ def render_input_form(self, varprefix, value):
+ forms.header(self.title())
+ for param, vs in self._elements:
+ div_id = varprefix + "_d_" + param
+ vp = varprefix + "_p_" + param
+ if self._optional_keys and param not in self._required_keys:
+ visible = html.get_checkbox(vp + "_USE")
+ if visible == None:
+ visible = param in value
+ onclick = "valuespec_toggle_option(this, %r)" % div_id
+ checkbox_code = '<input type=checkbox name="%s" %s
onclick="%s">' % (
+ vp + "_USE", visible and "CHECKED" or
"", onclick)
+ forms.section(vs.title(), checkbox=checkbox_code)
+ else:
+ visible = True
+ forms.section(vs.title())
+
+ html.write('<div id="%s" style="display:
%s">' % (
+ div_id, not visible and "none" or ""))
+ html.help(vs.help())
+ vs.render_input(vp, value.get(param, vs.default_value()))
+ html.write("</div>")
+
def set_focus(self, varprefix):
- self._elements[0][1].set_focus(varprefix + self._elements[0][0])
+ self._elements[0][1].set_focus(varprefix + "_p_" +
self._elements[0][0])
def canonical_value(self):
return dict([
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 7bd373f..e4aa2ce 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -256,7 +256,9 @@ def page_handler():
# he needs an explicit access permission for doing changes:
if config.may("wato.seeall"):
for pname in modeperms:
- config.need_permission("wato." + pname)
+ if '.' not in pname:
+ pname = "wato." + pname
+ config.need_permission(pname)
result = modefunc("action")
if type(result) == tuple:
@@ -287,7 +289,9 @@ def page_handler():
# Check general permissions for the new mode
if not config.may("wato.seeall"):
for pname in modeperms:
- config.need_permission("wato." + pname)
+ if '.' not in pname:
+ pname = "wato." + pname
+ config.need_permission(pname)
except MKUserError, e:
action_message = e.message
@@ -5136,7 +5140,9 @@ def mode_main(phase):
def render_main_menu(some_modules, columns = 2):
html.write('<div class="mainmenu">')
for nr, (mode_or_url, title, icon, permission, help) in enumerate(some_modules):
- if not config.may("wato." + permission) and not
config.may("wato.seeall"):
+ if "." not in permission:
+ permission = "wato." + permission
+ if not config.may(permission) and not config.may("wato.seeall"):
continue
if '?' in mode_or_url or '/' in mode_or_url:
diff --git a/web/plugins/sidebar/wato.py b/web/plugins/sidebar/wato.py
index 47c69ed..be085a2 100644
--- a/web/plugins/sidebar/wato.py
+++ b/web/plugins/sidebar/wato.py
@@ -43,7 +43,9 @@ def render_wato():
iconlink(_("Main Menu"), "wato.py", "home")
for mode, title, icon, permission, help in wato.modules:
- if config.may("wato." + permission) or
config.may("wato.seeall"):
+ if "." not in permission:
+ permission = "wato." + permission
+ if config.may(permission) or config.may("wato.seeall"):
iconlink(title, "wato.py?mode=%s" % mode, icon)
num_pending = wato.api.num_pending_changes()