View Issue Details

IDProjectCategoryView StatusLast Update
879RackTablesdefaultpublic2013-06-09 00:35
Reporterblaza-pl Assigned Toadoom42  
PrioritylowSeveritytweakReproducibilityalways
Status closedResolutionfixed 
Product Version0.20.4 
Target Version0.20.5Fixed in Version0.20.5 
Summary879: Display location select box options as a tree
DescriptionI have created patch to display locations in the Manage location tab and Manage rows tab drop-down lists as a tree like structure.
TagsNo tags attached.

Activities

blaza-pl

blaza-pl

2013-06-03 13:34

reporter  

location.tree.jpg (57,833 bytes)   
location.tree.jpg (57,833 bytes)   
blaza-pl

blaza-pl

2013-06-03 13:36

reporter  

location-edit-tree_ajax-interface.php.patch (1,045 bytes)   
--- racktables-test/inc/ajax-interface.php	2013-04-14 22:27:19.000000000 +0200
+++ racktables-prod/inc/ajax-interface.php	2013-04-30 13:59:03.501947591 +0200
@@ -151,15 +151,15 @@
 		$current_location_id = $m[1];
 		$selected_id = $locationlist[$current_location_id]['parent_id'];
 		echo $selected_id;
-		$options[0] = '-- NONE --';
-		foreach ($locationlist as $location_id => $locationinfo)
-			if (! in_array ($current_location_id, $locationinfo['trace']) && $current_location_id != $location_id)
-				$options[$location_id] = $locationinfo['name'];
+		echo "<option value=0>-- NONE --</option>";
 	}
-	foreach ($options as $location_id => $value)
-		echo "<option value='$location_id'" .
-			($location_id == $selected_id ? ' selected' : '') .
-			'>' . htmlspecialchars ($value) . '</option>';
+	foreach ($locationtree as $location)
+	{
+		echo "<option value=${location['id']} style=\"font-weight: bold\"  >${location['name']}</option>";
+		printLocationChildren($location,0,$current_location_id);
+	}
+
+
 }
 
 function verifyCodeAJAX()
blaza-pl

blaza-pl

2013-06-03 13:36

reporter  

location-edit-tree_functions.php.patch (766 bytes)   
--- functions.php	2013-04-14 22:27:19.000000000 +0200
+++ /var/www/racktables-bg-dev/inc/functions.php	2013-04-30 10:31:39.241319845 +0200
@@ -6045,4 +6045,21 @@
 	return FALSE;
 }
 
+// print tree in select options for locations
+function printLocationChildren($locations,$lvl = 0, $sel = 0)
+{
+        $lvl++;
+        foreach ($locations['kids'] as $subLocation)
+        {
+                echo "<option value=${subLocation['id']}";
+                if ($subLocation['id'] == $sel)
+                        echo " selected ";
+                echo ">" . str_repeat("&raquo; ",$lvl) . "${subLocation['name']}</option>";
+
+                if($subLocation['kidc'] > 0)
+                        printLocationChildren($subLocation,$lvl,$sel);
+        }
+}
+
+
 ?>
blaza-pl

blaza-pl

2013-06-03 13:36

reporter  

location-edit-tree_interface.php.patch (2,913 bytes)   
--- /var/www/racktables-prod/inc/interface.php	2013-04-30 10:01:27.449185928 +0200
+++ /var/www/racktables-bg-dev/inc/interface.php	2013-04-30 10:19:03.961882935 +0200
@@ -449,6 +449,21 @@
 	}
 }
 
+function locationSelectTree($selected = 0)
+{
+		echo "<option value=0>-- NONE --</option>";
+		foreach (treeFromList(listCells ('location')) as $location)
+		{
+			echo "<option value=${location['id']} style=\"font-weight: bold\" ";
+			if ($location['id'] == $selected )
+			    echo " selected ";
+			echo ">${location['name']}</option>";
+			printLocationChildren($location,0,$selected);
+		}
+		echo "</select>";
+}
+
+
 function renderRackspaceLocationEditor ()
 {
 	addJS
@@ -469,11 +484,9 @@
 		printOpFormIntro ('addLocation');
 		echo "<tr><td>";
 		printImageHREF ('create', 'Add new location', TRUE);
-		echo "</td><td><select name=parent_id tabindex=100>";
-		echo "<option value=0>-- NONE --</option>";
-		foreach (listCells ('location') as $location)
-			echo "<option value=${location['id']}>${location['name']}</option>";
-		echo "</select></td>";
+		echo "</td><td><select name=parent_id tabindex=100>";
+		locationSelectTree();
+		echo "</td>";
 		echo "<td><input type=text size=48 name=name tabindex=101></td><td>";
 		printImageHREF ('create', 'Add new location', TRUE, 102);
 		echo "</td></tr></form>\n";
@@ -496,16 +509,14 @@
 
 function renderRackspaceRowEditor ()
 {
-	function printNewItemTR ($locationlist)
+	function printNewItemTR ()
 	{
 		printOpFormIntro ('addRow');
 		echo "<tr><td>";
 		printImageHREF ('create', 'Add new row', TRUE);
 		echo "</td><td><select name=location_id tabindex=100>";
-		echo "<option value=0>-- NONE --</option>";
-		foreach ($locationlist as $location)
-			echo "<option value=${location['id']}>${location['name']}</option>";
-		echo "</select></td>";
+		locationSelectTree();
+		echo "</td>";
 		echo "<td><input type=text name=name tabindex=101></td><td>";
 		printImageHREF ('create', 'Add new row', TRUE, 102);
 		echo "</td></tr></form>";
@@ -516,7 +527,7 @@
 	echo "<table border=0 cellspacing=0 cellpadding=5 align=center class=widetable>\n";
 	echo "<tr><th>&nbsp;</th><th>Location</th><th>Name</th><th>&nbsp;</th></tr>\n";
 	if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
-		printNewItemTR($locationlist);
+		printNewItemTR();
 	foreach (getAllRows() as $row_id => $rowInfo)
 	{
 		echo "<tr><td>";
@@ -534,7 +545,8 @@
 		$selectlist['other'][0] = '-- NONE --';
 		foreach ($locationlist as $location_id => $locationdata)
 			$selectlist['other'][$location_id] = $locationdata['name'];
-		printNiftySelect ($selectlist, array ('name' => 'location_id'), $rowInfo['location_id']);
+		echo "<select name=location_id tabindex=100>";
+		locationSelectTree($rowInfo['location_id']);
 		echo "</td><td><input type=text name=name value='${rowInfo['name']}'></td><td>";
 		printImageHREF ('save', 'Save changes', TRUE);
 		echo "</form></td></tr>\n";
adoom42

adoom42

2013-06-09 00:35

administrator   ~0001493

Thanks for the submission. I committed a slightly modified version of your patch.

The original version included all locations in the 'parent' drop-down list. This allowed you to 1) set a location's parent to itself, and 2) set a location's parent to one of its children, both of which are invalid.

Issue History

Date Modified Username Field Change
2013-06-03 13:34 blaza-pl New Issue
2013-06-03 13:34 blaza-pl File Added: location.tree.jpg
2013-06-03 13:36 blaza-pl File Added: location-edit-tree_ajax-interface.php.patch
2013-06-03 13:36 blaza-pl File Added: location-edit-tree_functions.php.patch
2013-06-03 13:36 blaza-pl File Added: location-edit-tree_interface.php.patch
2013-06-03 17:35 adoom42 Assigned To => adoom42
2013-06-03 17:35 adoom42 Status new => assigned
2013-06-09 00:35 adoom42 Note Added: 0001493
2013-06-09 00:35 adoom42 Status assigned => closed
2013-06-09 00:35 adoom42 Resolution open => fixed
2013-06-09 00:35 adoom42 Fixed in Version => 0.20.5
2013-06-09 00:35 adoom42 Target Version => 0.20.5