[icinga-checkins] icinga.org: icinga-core/test/cgis: classic-ui: change javascript page refresh method again.

git at icinga.org git at icinga.org
Tue Apr 3 09:26:31 CEST 2012


Module: icinga-core
Branch: test/cgis
Commit: 64b5e9cfe7706d1ff7040c5ee28076c13ab7b7bb
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=64b5e9cfe7706d1ff7040c5ee28076c13ab7b7bb

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Mon Mar 19 23:02:06 2012 +0100

classic-ui: change javascript page refresh method again.

hope this works persintent in all browser implementations now.
damn IE

---

 cgi/cgiutils.c                |   45 +---------------------------------------
 html/js/checkbox_functions.js |    4 +-
 html/js/page_refresh.js       |   40 ++++++++++++++++++++++++++++++++++++
 include/cgiutils.h            |    1 +
 4 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/cgi/cgiutils.c b/cgi/cgiutils.c
index f77233a..e19df66 100644
--- a/cgi/cgiutils.c
+++ b/cgi/cgiutils.c
@@ -1082,50 +1082,9 @@ void document_header(int cgi_id, int use_stylesheet, char *cgi_title) {
 		printf("<script type=\"text/javascript\">\n");
 		printf("var refresh_rate=%d;\n", refresh_rate);
 		printf("var do_refresh=%s;\n",(refresh == TRUE) ? "true" : "false");
-		printf("var counter_seconds=refresh_rate;\n\n");
-
-		printf("function update_text(id,text) {\n");
-		printf("\tif (document.getElementById(id) != null )\n");
-		printf("\t\tdocument.getElementById(id).innerHTML = text;\n");
-		printf("}\n\n");
-
-		printf("function update_refresh_counter(reset) {\n");
-		printf("\tif (reset)\n");
-		printf("\t\tcounter_seconds=refresh_rate;\n");
-		printf("\tif (!do_refresh) {\n");
-		printf("\t\tupdate_text('refresh_text','- Update is PAUSED');\n");
-		printf("\t\tupdate_text('refresh_button','[continue]');\n");
-		printf("\t\treturn;\n");
-		printf("\t} else\n");
-		printf("\tupdate_text('refresh_button','[pause]');\n");
-		printf("\ts = (counter_seconds != 1) ? 's':'' ;\n");
-		printf("\tif (counter_seconds<=0) {\n");
-		printf("\t\tupdate_text('refresh_text','- Updating now');\n");
-		printf("\t\twindow.location.href=window.location.href;\n");
-		printf("\t\treturn false;\n");
-		printf("\t} else\n");
-		printf("\t\tupdate_text('refresh_text','- Update in '+counter_seconds+' second'+s);\n");
-		printf("\tcounter_seconds--;\n");
-		printf("}\n\n");
-
-		printf("function toggle_refresh() {\n");
-		printf("\tif (do_refresh) {\n");
-		printf("\t\tdo_refresh = false;\n");
-		printf("\t\tupdate_refresh_counter(true);\n");
-		printf("\t} else {\n");
-		printf("\t\tdo_refresh = true;\n");
-		printf("\t\tupdate_refresh_counter(true);\n");
-		printf("\t}\n");
-		printf("}\n\n");
-
-		printf("function counter_loop(){\n");
-		printf("\tupdate_refresh_counter(false)\n");
-		printf("\tsetTimeout(\"counter_loop()\",1000);\n");
-		printf("}\n\n");
-
-		printf("counter_loop();\n");
-
+		printf("var counter_seconds=refresh_rate;\n");
 		printf("</script>\n");
+		printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, PAGE_REFRESH_JS);
 	}
 
 	if (cgi_id == STATUS_CGI_ID || cgi_id == EXTINFO_CGI_ID) {
diff --git a/html/js/checkbox_functions.js b/html/js/checkbox_functions.js
index 0ce9866..c97f049 100644
--- a/html/js/checkbox_functions.js
+++ b/html/js/checkbox_functions.js
@@ -1,6 +1,6 @@
 // Written by Rune Darrud
 // Modified by Ricardo Bartels
-// For Icinga
+// Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
 
 function isValidForSubmit(form) {
 	var group = document.getElementById(form);
@@ -43,7 +43,7 @@ function enableDisableButton(form) {
 		document.forms[form].CommandButton.disabled=disabled;
 
 	// update refresh counter
-	update_refresh_counter(true);
+	reset_counter();
 }
 
 function showValue(form,arg,schedule_host_check,schedule_host_svc_check) {
diff --git a/html/js/page_refresh.js b/html/js/page_refresh.js
new file mode 100644
index 0000000..9a868b3
--- /dev/null
+++ b/html/js/page_refresh.js
@@ -0,0 +1,40 @@
+// Written by Jannis Moßhammer and Ricardo Bartels
+// Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
+
+/* set via document_header in *.cgi
+var refresh_rate=60;
+var do_refresh=true;
+*/
+
+function update_text(id,text) {
+	if (document.getElementById(id) != null )
+		document.getElementById(id).innerHTML = text;
+}
+
+function update_refresh_counter() {
+	if (counter_seconds<=0) {
+		update_text('refresh_text','- Updating now');
+		window.location.href=window.location.href;
+	} else if(do_refresh){ 
+		update_text('refresh_text','- Update in '+counter_seconds+' second'+((counter_seconds != 1) ? 's':''));
+		update_text('refresh_button','[pause]');
+		counter_seconds--;
+		setTimeout("update_refresh_counter()",1000);
+	} else {
+		update_text('refresh_text','- Update is PAUSED');
+		update_text('refresh_button','[continue]');
+	}
+}
+
+function reset_counter() {
+	counter_seconds=refresh_rate;
+}
+
+function toggle_refresh() {
+	do_refresh = (do_refresh) ? false : true;
+	reset_counter();
+	update_refresh_counter();
+}
+
+reset_counter();
+update_refresh_counter();
diff --git a/include/cgiutils.h b/include/cgiutils.h
index eee9626..8618a03 100644
--- a/include/cgiutils.h
+++ b/include/cgiutils.h
@@ -137,6 +137,7 @@ extern "C" {
 #define JQUERY_MAIN_JS		"jquery-1.6.2.min.js"
 #define JQUERY_DD_JS		"jquery.dd.js"
 #define SKINNYTIP_JS		"skinnytip.js"
+#define PAGE_REFRESH_JS		"page_refresh.js"
 
 /********************************* ICONS ************************************/
 





More information about the icinga-checkins mailing list