From 3a3bdb4de473f7966780c01f81996de2bf93170c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 9 Feb 2013 18:04:28 -0800 Subject: [PATCH] #268: Improve service function naming. --- guacamole/src/main/webapp/scripts/root-ui.js | 2 +- guacamole/src/main/webapp/scripts/service.js | 133 ++++++++++--------- 2 files changed, 74 insertions(+), 61 deletions(-) diff --git a/guacamole/src/main/webapp/scripts/root-ui.js b/guacamole/src/main/webapp/scripts/root-ui.js index 656e74d62..1b9ecae27 100644 --- a/guacamole/src/main/webapp/scripts/root-ui.js +++ b/guacamole/src/main/webapp/scripts/root-ui.js @@ -136,7 +136,7 @@ GuacamoleRootUI.reset = function() { // Read connections var connections; try { - connections = GuacamoleService.getConnections(parameters); + connections = GuacamoleService.Connections.list(parameters); } catch (e) { diff --git a/guacamole/src/main/webapp/scripts/service.js b/guacamole/src/main/webapp/scripts/service.js index 368ca6f8d..5c3d6e17a 100644 --- a/guacamole/src/main/webapp/scripts/service.js +++ b/guacamole/src/main/webapp/scripts/service.js @@ -44,75 +44,88 @@ GuacamoleService.Connection = function(protocol, id) { }; /** - * An arbitrary Guacamole user, consisting of a username. - * - * @constructor - * @param {String} username The username associate with this user. + * Collection of service functions which deal with connections. Each function + * makes an explicit HTTP query to the server, and parses the response. */ -GuacamoleService.User = function(username) { +GuacamoleService.Connections = { + + /** + * Returns an array of Connections for which the current user has access. + * + * @param {String} parameters Any parameters which should be passed to the + * server for the sake of authentication + * (optional). + * @return {GuacamoleService.Connection[]} An array of Connections for + * which the current user has + * access. + */ + "list" : function(parameters) { + + // Construct request URL + var list_url = "connections"; + if (parameters) list_url += "?" + parameters; + + // Get connection list + var xhr = new XMLHttpRequest(); + xhr.open("GET", list_url, false); + xhr.send(null); + + // If fail, throw error + if (xhr.status != 200) + throw new Error(xhr.statusText); + + // Otherwise, get list + var connections = new Array(); + + var connectionElements = xhr.responseXML.getElementsByTagName("connection"); + for (var i=0; i