#268: Improve service function naming.

This commit is contained in:
Michael Jumper
2013-02-09 18:04:28 -08:00
parent c77d1413cc
commit 3a3bdb4de4
2 changed files with 74 additions and 61 deletions

View File

@@ -136,7 +136,7 @@ GuacamoleRootUI.reset = function() {
// Read connections // Read connections
var connections; var connections;
try { try {
connections = GuacamoleService.getConnections(parameters); connections = GuacamoleService.Connections.list(parameters);
} }
catch (e) { catch (e) {

View File

@@ -44,29 +44,30 @@ GuacamoleService.Connection = function(protocol, id) {
}; };
/** /**
* An arbitrary Guacamole user, consisting of a username. * Collection of service functions which deal with connections. Each function
* * makes an explicit HTTP query to the server, and parses the response.
* @constructor
* @param {String} username The username associate with this user.
*/ */
GuacamoleService.User = function(username) { GuacamoleService.Connections = {
/** /**
* The username associated with this user. * 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.
*/ */
this.username = username; "list" : function(parameters) {
};
GuacamoleService.getConnections = function(parameters) {
// Construct request URL // Construct request URL
var connections_url = "connections"; var list_url = "connections";
if (parameters) connections_url += "?" + parameters; if (parameters) list_url += "?" + parameters;
// Get connection list // Get connection list
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("GET", connections_url, false); xhr.open("GET", list_url, false);
xhr.send(null); xhr.send(null);
// If fail, throw error // If fail, throw error
@@ -86,9 +87,22 @@ GuacamoleService.getConnections = function(parameters) {
return connections; return connections;
}
}; };
GuacamoleService.getUsers = function(parameters) { GuacamoleService.Users = {
/**
* Returns an array of usernames 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 {String[]} An array of usernames for which the current user has
* access.
*/
"list" : function(parameters) {
// Construct request URL // Construct request URL
var users_url = "users"; var users_url = "users";
@@ -107,12 +121,11 @@ GuacamoleService.getUsers = function(parameters) {
var users = new Array(); var users = new Array();
var userElements = xhr.responseXML.getElementsByTagName("user"); var userElements = xhr.responseXML.getElementsByTagName("user");
for (var i=0; i<userElements.length; i++) { for (var i=0; i<userElements.length; i++)
users.push(new GuacamoleService.User( users.push(userElements[i].getAttribute("name"));
userElements[i].getAttribute("name")
));
}
return users; return users;
} }
};