Module: check_mk
Branch: master
Commit: 6e2f8cc17085d55bca0fd2234c14e9495e4f157d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6e2f8cc17085d5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Oct 8 09:28:04 2014 +0200
Dashlets can now register custom validation functions; Fixed problem with url dashlet
validation
---
web/htdocs/dashboard.py | 1 +
web/plugins/dashboard/dashlets.py | 11 +++++++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index c75304b..82e6739 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -881,6 +881,7 @@ def page_edit_dashlet():
title = _('Properties'),
render = 'form',
optional_keys = dashlet_type.get('opt_params'),
+ validate = dashlet_type.get('validate_params'),
elements = params,
)
elif type(params) == type(lambda x: x):
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index ea44fad..18f9ec1 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -573,6 +573,12 @@ def dashlet_url(params):
if params.get('show_in_iframe', True):
return params['url']
+def dashlet_url_validate(value, varprefix):
+ if 'url' not in value and 'urlfunc' not in value:
+ raise MKUserError(varprefix, _('You need to provide either an URL or '
+ 'the name of a python function to be used
'
+ 'for rendering the dashlet.'))
+
dashlet_types["url"] = {
"title" : _("Custom URL"),
"sort_index" : 80,
@@ -580,7 +586,7 @@ dashlet_types["url"] = {
"iframe_urlfunc" : dashlet_url,
"allowed" : config.builtin_role_ids,
"size" : (30, 10),
- "parameters" : [
+ "parameters" : [
("url", TextAscii(
title = _('URL'),
size = 50,
@@ -595,5 +601,6 @@ dashlet_types["url"] = {
default_value = True,
)),
],
- "opt_params": ['url', 'urlfunc'],
+ "opt_params" : ['url', 'urlfunc'],
+ "validate_params" : dashlet_url_validate,
}