View Issue Details

IDProjectCategoryView StatusLast Update
841RackTablesJavaScriptpublic2013-06-08 19:41
Reporterblaza-pl Assigned Toadoom42  
PrioritylowSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version0.20.4 
Target Version0.20.5Fixed in Version0.20.5 
Summary841: Javascript to select parts or whole Location tree in Location filter
DescriptionI have created a patch to add some feature in Location filter. This allows user to de/select all locations or parts of location tree (location + location children)
TagsNo tags attached.

Activities

blaza-pl

blaza-pl

2013-05-07 14:11

reporter  

location-checkbox.patch (2,215 bytes)   
--- ../../racktables-prod/inc/interface.php	2013-05-07 09:30:53.233632046 +0200
+++ interface.php	2013-05-07 12:42:16.897757633 +0200
@@ -278,17 +278,41 @@
 		{
 			echo "<tr><td class=tagbox style='padding-left: " . ($level * 16) . "px;'><label>";
 			$checked = (in_array ($location['id'], $_SESSION['locationFilter'])) ? 'checked' : '';
-			echo "<label><input type=checkbox name='location_id[]' value='${location['id']}'${checked}>${location['name']}";
+			echo "<label><input type=checkbox name='location_id[]' class=${level} value='${location['id']}'${checked} onClick=checkAll(this)>${location['name']}";
 			echo "</label></td></tr>\n";
 			if ($location['kidc'])
 				$self ($location['kids'], $level + 1);
 		}
 	}
 
-	// TODO: add some javascript to toggle all children when a parent is toggled
+	addJS(<<<END
+		function checkAll(bx){
+			for (var tbls=document.getElementsByTagName("table"), i=tbls.length; i--; )
+				if (tbls[i].id=="locationFilter")
+				{	
+					var bxs=tbls[i].getElementsByTagName("input");
+					var in_tree = false;
+					for (var j=0; j<bxs.length; j++ )
+					{
+						if(in_tree == false && bxs[j].value== bx.value)
+							in_tree = true;
+						else if(parseInt(bxs[j].className) <= parseInt(bx.className))
+							in_tree = false;
+
+						
+						if (bxs[j].type=="checkbox" && in_tree == true)
+							bxs[j].checked = bx.checked;
+
+                            		}
+                            	}
+                }
+END
+	,TRUE);
+	
+	
 	startPortlet ('Location filter');
 	echo <<<END
-<table border=0 align=center cellspacing=0 class="tagtree">
+<table border=0 align=center cellspacing=0 class="tagtree" id="locationFilter">
     <form method=get>
     <input type=hidden name=page value=rackspace>
     <input type=hidden name=tab value=default>
@@ -299,6 +325,11 @@
 	if (count ($locationlist))
 	{
 		echo "<tr><td class=tagbox><hr></td></tr>\n";
+		
+		echo "<tr><td class=tagbox style='padding-left: 0px' ><label>";
+		echo "<label><input type=checkbox name='location'  onClick=checkAll(this)>";
+		echo "</label></td></tr>\n";
+		
 		renderLocationCheckbox (treeFromList ($locationlist));
 		echo "<tr><td class=tagbox><hr></td></tr>\n";
 		echo "<tr><td>";
location-checkbox.patch (2,215 bytes)   
adoom42

adoom42

2013-06-08 19:41

administrator   ~0001491

Thanks for the patch.

Issue History

Date Modified Username Field Change
2013-05-07 14:11 blaza-pl New Issue
2013-05-07 14:11 blaza-pl Status new => assigned
2013-05-07 14:11 blaza-pl Assigned To => andriyanov
2013-05-07 14:11 blaza-pl File Added: location-checkbox.patch
2013-06-03 17:26 adoom42 Assigned To andriyanov => adoom42
2013-06-08 19:41 adoom42 Note Added: 0001491
2013-06-08 19:41 adoom42 Status assigned => closed
2013-06-08 19:41 adoom42 Resolution open => fixed
2013-06-08 19:41 adoom42 Fixed in Version => 0.20.5
2013-06-08 19:41 adoom42 Target Version => 0.20.5