[icinga-checkins] icinga.org: icinga-core/dev/cgis: classic-ui: Added "Select All" checkbox to cmd.cgi host/service list #2697

git at icinga.org git at icinga.org
Mon Aug 20 17:04:14 CEST 2012


Module: icinga-core
Branch: dev/cgis
Commit: 2949ee4f2e4ecceb335b4269430298233aa58ec9
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=2949ee4f2e4ecceb335b4269430298233aa58ec9

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Mon Aug 20 16:57:53 2012 +0200

classic-ui: Added "Select All" checkbox to cmd.cgi host/service list #2697

refs: #2697

* Added "Select All" checkbox
* Added title to checkboxes (active / passive)

---

 Changelog                     |    6 ++++--
 cgi/cmd.c                     |   28 +++++++++++++++++++++-------
 html/js/checkbox_functions.js |   11 ++---------
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/Changelog b/Changelog
index 0fbf5f8..3c444ed 100644
--- a/Changelog
+++ b/Changelog
@@ -91,7 +91,7 @@ classic ui: Changed cgi GET params
 	** Added "start_time", "end_time" and "timeperiod" to notifications.cgi - #2341
 	** "send_notification" and "sticky_ack" on cmd.cgi require 0|1 vars, if not set, default is 1 #2926
 
-* classic ui: Added/Changed cgi.cfg options
+classic ui: Added/Changed cgi.cfg options
 	** authorized_for_comments_read_only - #2699
 	** authorized_for_downtimes_read_only - #2699
 	** authorized_contactgroup_for_comments_read_only - #2699
@@ -100,13 +100,15 @@ classic ui: Changed cgi GET params
 	** "result_limit" replaces "default_num_displayed_log_entries" - #2725
 	** default_expiring_disabled_notifications_duration=86400 #905
 
-*classic ui: change strings in json output: !!!IMPORTANT!!!
+classic ui: change strings in json output: !!!IMPORTANT!!!
 	** host -> host_name
 	** service -> service_description
 	** description -> service_description
 	** added host_display_name
 	** added service_display_name
 
+classic ui: added checkbox in cmd.cgi to deselect unintentional selected hosts/services #2697
+
 * idoutils: add disable_notif_expire_time to programstatus table #905
 
 
diff --git a/cgi/cmd.c b/cgi/cmd.c
index 32f84b8..b4e4cf5 100644
--- a/cgi/cmd.c
+++ b/cgi/cmd.c
@@ -813,12 +813,24 @@ void print_object_list(int list_type) {
 	printf("<tr><td colspan=\"2\"> </td></tr>\n");
 	printf("<tr class=\"sectionHeader\"><td colspan=\"2\" >Affected Objects</td></tr>\n");
 
-	printf("<tr><td colspan=\"2\"><TABLE cellspacing='2' cellpadding='0' border='0' width='100%%'>\n");
+	printf("<tr><td colspan=\"2\">\n");
+
+	printf("<script language='javascript' type=\"text/javascript\">\nchecked=false;\n");
+	printf("function checkAllBoxes() {\n"
+		"	checked = (checked == false) ? true : false;\n"
+		"	for (var i=0; i < %d; i++) {\n"
+		"		var checkboxes = document.getElementById(\"cb_\" + i);\n"
+		"		if (checkboxes != null ) { checkboxes.checked = checked; }\n"
+		"	}\n"
+		"}\n", NUMBER_OF_STRUCTS);
+	printf("</script>\n");
+
+	printf("<TABLE cellspacing='2' cellpadding='0' border='0' width='100%%'>\n");
 
 	if (list_type == PRINT_SERVICE_LIST)
-		printf("<tr class=\"objectDescription\"><td width=\"46%%\">Host</td><td width=\"46%%\">Service</td><td width='16'></td></tr>\n");
+		printf("<tr class=\"objectDescription\"><td width=\"46%%\">Host</td><td width=\"46%%\">Service</td><td width='16'><input type='checkbox' onclick=\"checkAllBoxes();\" title=\"Check All\"></td></tr>\n");
 	else if (list_type == PRINT_HOST_LIST)
-		printf("<tr class=\"objectDescription\"><td colspan=\"2\" width=\"96%%\">Hosts</td><td width='16'></td></tr>\n");
+		printf("<tr class=\"objectDescription\"><td colspan=\"2\" width=\"96%%\">Hosts</td><td width='16'><input type='checkbox' onclick=\"checkAllBoxes();\" title=\"Check All\"></td></tr>\n");
 	else
 		printf("<tr><td colspan=\"3\"> </td></tr>\n");
 
@@ -831,6 +843,9 @@ void print_object_list(int list_type) {
 			if (commands[x].host_name == NULL)
 				continue;
 
+			if (list_type == PRINT_SERVICE_LIST && commands[x].description == NULL)
+				continue;
+
 			if (strlen(commands[x].host_name) != 0 && (
 				command_type == CMD_SCHEDULE_HOST_CHECK ||
 				command_type == CMD_DISABLE_HOST_CHECK ||
@@ -841,7 +856,6 @@ void print_object_list(int list_type) {
 						host_passive = TRUE;
 				}
 
-
 				if (list_type == PRINT_SERVICE_LIST && strlen(commands[x].description) != 0 ) {
 					if((temp_servicestatus = find_servicestatus(commands[x].host_name, commands[x].description)) != NULL) {
 						if (temp_servicestatus->checks_enabled == FALSE)
@@ -862,7 +876,7 @@ void print_object_list(int list_type) {
 			/* hostname and service description are present */
 			if (strlen(commands[x].host_name) != 0  && strlen(commands[x].description) != 0) {
 				printf(">%s</td><td>%s</td>", escape_string(commands[x].host_name), escape_string(commands[x].description));
-				printf("<td align='center'><input type='checkbox' name='hostservice' value='%s^%s' %s></td></tr>\n", escape_string(commands[x].host_name), escape_string(commands[x].description), (service_passive == FALSE) ? "checked" : "");
+				printf("<td align='center'><input type='checkbox' name='hostservice' id=\"cb_%d\" value='%s^%s' title=\"%s Service\" %s></td></tr>\n", x, escape_string(commands[x].host_name), escape_string(commands[x].description), (service_passive == FALSE) ? "Active" : "Passive", (service_passive == FALSE) ? "checked" : "");
 			} else {
 				/* if hostname is empty print inputbox instead */
 				if (!strcmp(commands[x].host_name, ""))
@@ -883,7 +897,7 @@ void print_object_list(int list_type) {
 				printf(" style=\"font-weight:bold;\">Host:</td><td><INPUT TYPE='TEXT' NAME='host' SIZE=30></td><td></td></tr>\n");
 			else {
 				printf(" style=\"font-weight:bold;\">Host:</td><td>%s</td>", escape_string(commands[x].host_name));
-				printf("<td align='center'><input type='checkbox' name='host' value='%s' %s></td></tr>\n", escape_string(commands[x].host_name), (host_passive == FALSE) ? "checked" : "");
+				printf("<td align='center'><input type='checkbox' name='host' id=\"cb_%d\" value='%s' title=\"%s Host\" %s></td></tr>\n", x, escape_string(commands[x].host_name), (host_passive == FALSE) ? "Active" : "Passive", (host_passive == FALSE) ? "checked" : "");
 			}
 		} else if (list_type == PRINT_COMMENT_LIST) {
 			printf(" style=\"font-weight:bold;\">Comment ID:</td><td><INPUT TYPE='HIDDEN' NAME='com_id' VALUE='%lu'>%lu</td></tr>\n", multi_ids[x], multi_ids[x]);
@@ -892,7 +906,7 @@ void print_object_list(int list_type) {
 		}
 	}
 
-	printf("</td><tr></table>\n");
+	printf("</td><tr></table>\n</td></tr>\n");
 
 	return;
 }
diff --git a/html/js/checkbox_functions.js b/html/js/checkbox_functions.js
index 34e8eec..e46c958 100644
--- a/html/js/checkbox_functions.js
+++ b/html/js/checkbox_functions.js
@@ -68,11 +68,7 @@ function showValue(form,arg,schedule_host_check,schedule_host_svc_check) {
 checked=false;
 function checkAll(form) {
 	var checkboxes = document.getElementById(form);
-	if (checked == false)
-		checked = true;
-	else
-		checked = false;
-
+	checked = (checked == false) ? true : false;
 	for (var i=0; i < checkboxes.elements.length; i++) {
 		if (checkboxes.elements[i].type == "checkbox" ) {
 			checkboxes.elements[i].checked = checked;
@@ -83,10 +79,7 @@ function checkAll(form) {
 function toggle_checkbox(id, form) {
 	var x = document.getElementById(id);
 
-	if ( x.checked == true )
-		x.checked=false;
-	else
-		x.checked=true;
+	x.checked = ( x.checked == true ) ? false : true;
 
 	isValidForSubmit(form);
 





More information about the icinga-checkins mailing list