mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	#268: Implement connection management.
This commit is contained in:
		| @@ -285,15 +285,96 @@ | ||||
|                  */ | ||||
|  | ||||
|                 var selected_connection = null; | ||||
|                 var connections = GuacamoleService.Connections.list(); | ||||
|  | ||||
|                 // Add connections to list | ||||
|                 connection_list.innerHTML = ""; | ||||
|                 for (name in permissions.read_connection) {(function(name){ | ||||
|                 for (i=0; i<connections.length; i++) {(function(connection){ | ||||
|  | ||||
|                     var item = new GuacAdmin.ListItem("connection", name); | ||||
|                     connection_list.appendChild(item.getElement()); | ||||
|                     var item = new GuacAdmin.ListItem("connection", connection.id); | ||||
|                     var item_element = item.getElement(); | ||||
|                     connection_list.appendChild(item_element); | ||||
|  | ||||
|                 })(name)}; | ||||
|                     item_element.onclick = function() { | ||||
|  | ||||
|                         // Ignore clicks if any item is selected | ||||
|                         if (selected_connection) return; | ||||
|                         else selected_connection = connection.id; | ||||
|  | ||||
|                         // Load buttons | ||||
|                         var buttons = [new GuacAdmin.Button("Save"), | ||||
|                                        new GuacAdmin.Button("Cancel")]; | ||||
|  | ||||
|                         var fields = []; | ||||
|  | ||||
|                         if (connection.id in permissions.remove_connection) | ||||
|                             buttons.push(new GuacAdmin.Button("Delete")); | ||||
|  | ||||
|                         // FIXME: Actually generate form from properties | ||||
|  | ||||
|                         // Connection property form. | ||||
|                         var connection_properties = new GuacAdmin.Form( | ||||
|  | ||||
|                             /* Fields */ | ||||
|                             [new GuacAdmin.Field.TEXT("Hostname:", [], | ||||
|                                  [connection.parameters.hostname || ""]), | ||||
|  | ||||
|                              new GuacAdmin.Field.TEXT("Port:", [], | ||||
|                                  [connection.parameters.port || ""])], | ||||
|                              | ||||
|                             /* Buttons */ | ||||
|                             buttons | ||||
|  | ||||
|                         ); | ||||
|  | ||||
|                         // Select | ||||
|                         GuacUI.addClass(connection_list, "disabled"); | ||||
|                         GuacUI.addClass(item_element, "selected"); | ||||
|  | ||||
|                         // Handle buttons | ||||
|                         connection_properties.onaction = function(title, fields) { | ||||
|                              | ||||
|                             try { | ||||
|  | ||||
|                                 if (title == "Save") { | ||||
|  | ||||
|                                     // Get fields (FIXME: Actually implement)  | ||||
|                                     var hostname = fields[0][0]; | ||||
|                                     var port = fields[1][0]; | ||||
|  | ||||
|                                     // Update fields | ||||
|                                     connection.parameters.hostname = hostname; | ||||
|                                     connection.parameters.port = port; | ||||
|  | ||||
|                                     // Save connection | ||||
|                                     GuacamoleService.Connections.update(connection); | ||||
|                                     reset_admin_ui(); | ||||
|  | ||||
|                                 } | ||||
|                                 else if (title == "Delete") { | ||||
|                                     GuacamoleService.Connections.remove(selected_connection); | ||||
|                                     reset_admin_ui(); | ||||
|                                 } | ||||
|  | ||||
|                                 // Deselect | ||||
|                                 GuacUI.removeClass(connection_list, "disabled"); | ||||
|                                 GuacUI.removeClass(item_element, "selected"); | ||||
|                                 item_element.removeChild(connection_properties.getElement()); | ||||
|                                 selected_connection = null; | ||||
|  | ||||
|                             } | ||||
|                             catch (e) { | ||||
|                                 alert(e.message); | ||||
|                             } | ||||
|                                  | ||||
|                         }; | ||||
|  | ||||
|                         item_element.appendChild(connection_properties.getElement()); | ||||
|  | ||||
|                     }; | ||||
|  | ||||
|  | ||||
|                 })(connections[i])}; | ||||
|  | ||||
|             } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user