Module: check_mk
Branch: master
Commit: 705ad91f5f74861dd55acee58e0e5aa1162ab751
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=705ad91f5f7486…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Nov 15 17:30:32 2011 +0100
Multsite: cleanup context buttons
---
web/htdocs/htmllib.py | 9 +++++++-
web/htdocs/views.py | 43 +++++++++++++++++++----------------------
web/plugins/views/builtin.py | 3 ++
3 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 0c1c0e6..9e49e1c 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -169,6 +169,7 @@ class html:
self.link_target = None
self.form_name = None
self.form_vars = []
+ self.context_buttons_open = False
def plugin_stylesheets(self):
global plugin_stylesheets
@@ -320,11 +321,17 @@ class html:
def begin_context_buttons(self):
self.write("<table class=contextlinks><tr><td>\n")
+ self.context_buttons_open = True
def end_context_buttons(self):
- self.write("</td></tr></table>\n")
+ if self.context_buttons_open:
+ self.write("</td></tr></table>\n")
+ self.context_buttons_open = False
def context_button(self, title, url, icon=None, hot=False, id=None):
+ if not self.context_buttons_open:
+ self.begin_context_buttons()
+
if icon:
title = '<img src="images/icon_%s.png">%s' % (icon,
title)
if id:
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index f663e03..6aae97f 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1583,21 +1583,6 @@ def view_linktitle(view):
def show_context_links(thisview, active_filters):
- # Show button to WATO, if permissions allow this
- if config.wato_enabled and config.may("wato.use"):
- html.begin_context_buttons()
- execute_hooks('buttons-begin')
- first = False
- host = html.var("host")
- if host:
- url = wato.api.link_to_host(host)
- else:
- url = wato.api.link_to_path(html.var("wato_folder", ""))
- html.context_button(_("WATO"), url, "wato")
-
- else:
- first = True
-
# compute list of html variables used actively by hidden or shown
# filters.
active_filter_vars = set([])
@@ -1606,6 +1591,23 @@ def show_context_links(thisview, active_filters):
if html.has_var(var):
active_filter_vars.add(var)
+ # html.begin_context_buttons() called automatically by html.context_button()
+ # That way if no button is painted we avoid the empty container
+ execute_hooks('buttons-begin')
+
+ # WATO: If we have a host context, then show button to WATO, if permissions allow
this
+ if "host" in active_filter_vars \
+ and config.wato_enabled \
+ and config.may("wato.use") \
+ and (config.may("wato.hosts") or config.may("wato.seeall")):
+ host = html.var("host")
+ if host:
+ url = wato.api.link_to_host(host)
+ else:
+ url = wato.api.link_to_path(html.var("wato_folder", ""))
+ html.context_button(_("WATO"), url, "wato")
+
+
# sort views after text of possible button (sort buttons after their text)
sorted_views = []
for view in html.available_views.values():
@@ -1638,17 +1640,12 @@ def show_context_links(thisview, active_filters):
# add context link to this view
if len(used_contextvars):
- if first:
- first = False
- html.begin_context_buttons()
- execute_hooks('buttons-begin')
vars_values = [ (var, html.var(var)) for var in set(used_contextvars) ]
- html.context_button(linktitle, html.makeuri_contextless(vars_values +
[("view_name", name)]), view.get("icon"))
+ html.context_button(linktitle,
+ html.makeuri_contextless(vars_values + [("view_name", name)]),
view.get("icon"))
execute_hooks('buttons-end')
-
- if not first:
- html.end_context_buttons()
+ html.end_context_buttons()
# Retrieve data via livestatus, convert into list of dicts,
diff --git a/web/plugins/views/builtin.py b/web/plugins/views/builtin.py
index 661a083..375965f 100644
--- a/web/plugins/views/builtin.py
+++ b/web/plugins/views/builtin.py
@@ -551,6 +551,7 @@ multisite_builtin_views.update({
('st3', 'on'),
('stp', '')],
'hidden': True,
+ 'hidebutton' : True,
'hide_filters': ['site', 'host'],
'layout': 'boxed',
'mustsearch': False,
@@ -1165,6 +1166,7 @@ multisite_builtin_views.update({
'hard_filtervars': [
('is_summary_host', '0'),],
'hidden': True,
+ 'hidebutton': True,
'hide_filters': ['site'],
'layout': 'boxed',
'mustsearch': False,
@@ -1759,6 +1761,7 @@ multisite_builtin_views.update({
('host_check_command', ''),
('service_output', '')],
'hidden': True,
+ 'hidebutton': True,
'hide_filters': ['site'],
'layout': 'boxed',
'linktitle': _('Services of Site'),