Module: check_mk
Branch: master
Commit: 3032eb1c193c4ac2a726d9688841102e389c48fe
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3032eb1c193c4a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 20 11:17:34 2015 +0100
visual types can now register a function to check whether or not a visual can be deleted
---
web/htdocs/visuals.py | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 6c8ea63..685a711 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -247,7 +247,8 @@ def available(what, all_visuals):
def page_list(what, title, visuals, custom_columns = [],
render_custom_buttons = None,
render_custom_columns = None,
- render_custom_context_buttons = None):
+ render_custom_context_buttons = None,
+ check_deletable_handler = None):
what_s = what[:-1]
if not config.may("general.edit_" + what):
@@ -268,14 +269,22 @@ def page_list(what, title, visuals, custom_columns = [],
delname = html.var("_delete")
if delname and html.transaction_valid():
deltitle = visuals[(config.user_id, delname)]['title']
- c = html.confirm(_("Please confirm the deletion of \"%s\".")
% deltitle)
- if c:
- del visuals[(config.user_id, delname)]
- save(what, visuals)
- html.reload_sidebar()
- elif c == False:
- html.footer()
- return
+
+ try:
+ if check_deletable_handler:
+ check_deletable_handler(visuals, delname)
+
+ c = html.confirm(_("Please confirm the deletion of
\"%s\".") % deltitle)
+ if c:
+ del visuals[(config.user_id, delname)]
+ save(what, visuals)
+ html.reload_sidebar()
+ elif c == False:
+ html.footer()
+ return
+ except MKUserError, e:
+ html.write("<div class=error>%s</div>\n" % e.message)
+ html.add_user_error(e.varname, e.message)
keys_sorted = visuals.keys()
keys_sorted.sort(cmp = lambda a,b: -cmp(a[0],b[0]) or cmp(a[1], b[1]))