Module: check_mk
Branch: master
Commit: 6931228f9c26ebfca042f9e7661a21539d70b2fa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6931228f9c26eb…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 4 10:44:20 2011 +0100
Disabling page refresh when at least one command box is open
- View pages are not refreshed when at least one form (Filter, Commands, Display Options)
is open
- Switched page refresh code from HTTP header to javascript timeouts to be more
controllable
---
ChangeLog | 2 +
web/htdocs/htmllib.py | 17 ++++++--
web/htdocs/js/check_mk.js | 92 ++++++++++++++++++++++++++++++++++++++-------
web/htdocs/views.py | 3 +-
4 files changed, 95 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c479e2a..3ffaf27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -40,6 +40,8 @@
which broke the snapin titles and also the tactical overview table
* Sidebar: Fixed bulletlist positioning
* Fixed header displaying on views when the edit button is not shown to the user
+ * View pages are not refreshed when at least one form (Filter, Commands,
+ Display Options) is open
Checks & Agents:
* Fixed problem with OnlyFrom: in Linux agent (df didn't work properly)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index c28709e..aeba1c8 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -127,6 +127,7 @@ class html:
self.focus_object = None
self.global_vars = []
self.browser_reload = 0
+ self.browser_redirect = ''
self.events = set([]) # currently used only for sounds
self.header_sent = False
@@ -358,20 +359,28 @@ class html:
jQuery('a.tips').cluetip({ajaxCache: false, dropShadow:
false, showTitle: false });
});
</script>
-
- </head>
''')
+
+ if self.browser_reload != 0:
+ if self.browser_redirect != '':
+ self.req.write("<script
type=\"text/javascript\">setReload(%s, '%s')</script>\n"
%
+ (self.browser_reload,
self.browser_redirect))
+ else:
+ self.req.write("<script
type=\"text/javascript\">setReload(%s)</script>\n" %
self.browser_reload)
+
+
+ self.req.write("</head>\n")
self.req.header_sent = True
def html_foot(self):
self.write("</html>\n")
def set_browser_reload(self, secs):
- self.req.headers_out.add("refresh", str(secs))
self.browser_reload = secs
def set_browser_redirect(self, secs, url):
- self.req.headers_out.add("refresh", "%d; URL=%s" % (secs,
url))
+ self.browser_reload = secs
+ self.browser_redirect = url
def header(self, title=''):
if not self.header_sent:
diff --git a/web/htdocs/js/check_mk.js b/web/htdocs/js/check_mk.js
index 256a447..7e7665e 100644
--- a/web/htdocs/js/check_mk.js
+++ b/web/htdocs/js/check_mk.js
@@ -98,10 +98,10 @@ function filter_activation(oid)
var disabled = usage != "hard" && usage != "show";
for (var i in oTd.childNodes) {
- oNode = oTd.childNodes[i];
- if (oNode.nodeName == "INPUT" || oNode.nodeName == "SELECT") {
- oNode.disabled = disabled;
- }
+ oNode = oTd.childNodes[i];
+ if (oNode.nodeName == "INPUT" || oNode.nodeName == "SELECT")
{
+ oNode.disabled = disabled;
+ }
}
p = null;
@@ -109,18 +109,29 @@ function filter_activation(oid)
selectobject = null;
}
+var gNumOpenTabs = 0;
+
function toggle_tab(linkobject, oid)
{
var table = document.getElementById(oid);
if (table.style.display == "none") {
- table.style.display = "";
+ table.style.display = "";
linkobject.setAttribute("className", "left open");
linkobject.setAttribute("class", "left open");
+
+ // Stop the refresh while at least one tab is open
+ gNumOpenTabs += 1;
+ setReload(0);
}
else {
- table.style.display = "none";
+ table.style.display = "none";
linkobject.setAttribute("className", "left closed");
linkobject.setAttribute("class", "left closed");
+
+ // Re-Enable the reload
+ gNumOpenTabs -= 1;
+ if(gNumOpenTabs == 0)
+ setReload(gReloadTime);
}
table = null;
}
@@ -228,33 +239,33 @@ function actionResponseHandler(oImg, code) {
window.location.reload();
} else if(validResponse && response[0] === 'TIMEOUT') {
oImg.src = 'images/icon_reload_failed.gif';
- oImg.title = 'Timeout while performing action: ' + response[1];
+ oImg.title = 'Timeout while performing action: ' + response[1];
} else if(validResponse) {
oImg.src = 'images/icon_reload_failed.gif';
- oImg.title = 'Problem while processing - Response: ' + response.join('
');
+ oImg.title = 'Problem while processing - Response: ' +
response.join(' ');
} else {
oImg.src = 'images/icon_reload_failed.gif';
oImg.title = 'Invalid response: ' + response;
}
- response = null;
- validResponse = null;
- oImg = null;
+ response = null;
+ validResponse = null;
+ oImg = null;
}
function performAction(oLink, action, type, site, name1, name2) {
var oImg = oLink.childNodes[0];
oImg.src = 'images/icon_reloading.gif';
- // Chrome and IE are not animating the gif during sync ajax request
- // So better use the async request here
+ // Chrome and IE are not animating the gif during sync ajax request
+ // So better use the async request here
get_url('nagios_action.py?action='+action+'&site='+site+'&host='+name1+'&service='+name2,
actionResponseHandler, oImg);
oImg = null;
}
/* -----------------------------------------------------
- View editor
+ view editor
-------------------------------------------------- */
function delete_view_column(oImg) {
var oDiv = oImg;
@@ -264,3 +275,56 @@ function delete_view_column(oImg) {
oDiv = null;
}
+
+// ----------------------------------------------------------------------------
+// page reload stuff
+// ----------------------------------------------------------------------------
+
+//Stores the reload timer object
+var gReloadTimer = null;
+// This stores the last refresh time of the page (But never 0)
+var gReloadTime = 0;
+
+// Highlights/Unhighlights a refresh button
+function toggleRefreshButton(s, enable) {
+ var o = document.getElementById('button-refresh-' + s);
+ if(o) {
+ if(enable) {
+ o.setAttribute("className", "left w40 selected");
+ o.setAttribute("class", "left w40 selected");
+ } else {
+ o.setAttribute("className", "left w40");
+ o.setAttribute("class", "left w40");
+ }
+ }
+ o = null;
+}
+
+
+// When called with one or more parameters parameters it reschedules the
+// timer to the given interval. If the parameter is 0 the reload is stopped.
+// When called with two parmeters the 2nd one is used as new url.
+function setReload(secs, url) {
+ if(typeof url === 'undefined')
+ url = '';
+
+ if (gReloadTimer) {
+ toggleRefreshButton(0, false);
+ toggleRefreshButton(gReloadTime, false);
+ clearTimeout(gReloadTimer);
+ }
+
+ toggleRefreshButton(secs, true);
+
+ if (secs !== 0) {
+ gReloadTime = secs;
+ gReloadTimer = setTimeout("handleReload('" + url +
"')", Math.ceil(parseFloat(secs) * 1000));
+ }
+}
+
+function handleReload(url) {
+ if (url === '')
+ window.location.reload(false);
+ else
+ window.location.href = url;
+}
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index e6cbf26..d8a0026 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1053,7 +1053,8 @@ def show_view(view, show_heading = False, show_buttons = True,
show_footer = Tru
reftext = "%d s" % ref
else:
reftext = "∞"
- html.write('<td class="left w40%s"><a
href="%s">%s</a></td>\n' % (addclass, uri, reftext))
+ html.write('<td class="left w40%s"
id="button-refresh-%s"><a
href="%s">%s</a></td>\n' %
+ (addclass,
ref, uri, reftext))
html.write("<td class=minigap></td>\n")
html.write("<td class=gap> </td>\n")