Read protocols from service, not from hard-coded JS.

This commit is contained in:
Michael Jumper
2013-03-12 13:40:37 -07:00
parent 0ca02f937f
commit 9ad24744ec
2 changed files with 96 additions and 31 deletions

View File

@@ -807,10 +807,11 @@ GuacAdmin.addConnection = function(connection) {
var protocol = available_protocols[protocol_name]; var protocol = available_protocols[protocol_name];
// For each parameter // For each parameter
for (var name in protocol.parameters) { for (var i=0; i<protocol.parameters.length; i++) {
// Get parameter // Get parameter
var parameter = protocol.parameters[name]; var parameter = protocol.parameters[i];
var name = parameter.name;
// Create corresponding field // Create corresponding field
var field; var field;
@@ -889,8 +890,7 @@ GuacAdmin.addConnection = function(connection) {
); );
// Populate parameters // Populate parameters
var protocol = available_protocols[updated_connection.protocol]; for (var name in fields) {
for (var name in protocol.parameters) {
var field = fields[name]; var field = fields[name];
if (field) if (field)
updated_connection.parameters[name] = field.getValue(); updated_connection.parameters[name] = field.getValue();

View File

@@ -862,38 +862,103 @@ GuacamoleService.Protocols = {
*/ */
"list" : function(parameters) { "list" : function(parameters) {
var vnc = new GuacamoleService.Protocol( // Construct request URL
"vnc", "VNC", [ var list_url = "protocols";
if (parameters) list_url += "?" + parameters;
new GuacamoleService.Protocol.Parameter( // Get permission list
"hostname", "Hostname", var xhr = new XMLHttpRequest();
GuacamoleService.Protocol.Parameter.TEXT), xhr.open("GET", list_url, false);
xhr.send(null);
new GuacamoleService.Protocol.Parameter( // Handle response
"port", "Port", GuacamoleService.handleResponse(xhr);
GuacamoleService.Protocol.Parameter.NUMERIC),
// Array of all protocols
new GuacamoleService.Protocol.Parameter( var protocols = [];
"color-depth", "Color depth",
GuacamoleService.Protocol.Parameter.ENUM, // Parse all protocols
[ var protocolElements = xhr.responseXML.getElementsByTagName("protocol");
for (var i=0; i<protocolElements.length; i++) {
// Get protocol element
var protocolElement = protocolElements[i];
// Create corresponding protocol
var protocol = new GuacamoleService.Protocol(
protocolElement.getAttribute("name"),
protocolElement.getAttribute("title")
);
// Parse all parameters
var paramElements = protocolElement.getElementsByTagName("param");
for (var j=0; j<paramElements.length; j++) {
// Get parameter element
var paramElement = paramElements[j];
// Create corresponding parameter
var parameter = new GuacamoleService.Protocol.Parameter(
paramElement.getAttribute("name"),
paramElement.getAttribute("title")
);
// Parse type
switch (paramElement.getAttribute("type")) {
// Text parameter
case "text":
parameter.type = GuacamoleService.Protocol.Parameter.TEXT;
break;
// Password parameter
case "password":
parameter.type = GuacamoleService.Protocol.Parameter.PASSWORD;
break;
// Numeric parameter
case "numeric":
parameter.type = GuacamoleService.Protocol.Parameter.NUMERIC;
break;
// Boolean parameter
case "boolean":
parameter.type = GuacamoleService.Protocol.Parameter.BOOLEAN;
break;
// Enumerated parameter
case "enum":
parameter.type = GuacamoleService.Protocol.Parameter.ENUM;
break;
}
// Parse all options
var optionElements = paramElement.getElementsByTagName("option");
for (var k=0; k<optionElements.length; k++) {
// Get option element
var optionElement = optionElements[k];
parameter.options.push(
new GuacamoleService.Protocol.Parameter.Option( new GuacamoleService.Protocol.Parameter.Option(
"8", "256 colors"), optionElement.getAttribute("value"),
new GuacamoleService.Protocol.Parameter.Option( optionElement.textContent
"16", "High color (16-bit)"), ));
new GuacamoleService.Protocol.Parameter.Option(
"24", "True color (24-bit)")
]),
new GuacamoleService.Protocol.Parameter( } // end for each option
"read-only", "Read-only",
GuacamoleService.Protocol.Parameter.BOOLEAN)
]
);
// FIXME: STUB // Add parameter
return [vnc]; protocol.parameters.push(parameter);
} // end for each parameter
// Add protocol
protocols.push(protocol);
} // end for each protocol
return protocols;
} }