mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
#268: Improve service function naming.
This commit is contained in:
@@ -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) {
|
||||||
|
|
||||||
|
@@ -44,75 +44,88 @@ 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 = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<connectionElements.length; i++) {
|
||||||
|
connections.push(new GuacamoleService.Connection(
|
||||||
|
connectionElements[i].getAttribute("protocol"),
|
||||||
|
connectionElements[i].getAttribute("id")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return connections;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GuacamoleService.Users = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The username associated with this user.
|
* 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.
|
||||||
*/
|
*/
|
||||||
this.username = username;
|
"list" : function(parameters) {
|
||||||
|
|
||||||
};
|
// Construct request URL
|
||||||
|
var users_url = "users";
|
||||||
|
if (parameters) users_url += "?" + parameters;
|
||||||
|
|
||||||
GuacamoleService.getConnections = function(parameters) {
|
// Get user list
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("GET", users_url, false);
|
||||||
|
xhr.send(null);
|
||||||
|
|
||||||
// Construct request URL
|
// If fail, throw error
|
||||||
var connections_url = "connections";
|
if (xhr.status != 200)
|
||||||
if (parameters) connections_url += "?" + parameters;
|
throw new Error(xhr.statusText);
|
||||||
|
|
||||||
// Get connection list
|
// Otherwise, get list
|
||||||
var xhr = new XMLHttpRequest();
|
var users = new Array();
|
||||||
xhr.open("GET", connections_url, false);
|
|
||||||
xhr.send(null);
|
|
||||||
|
|
||||||
// If fail, throw error
|
var userElements = xhr.responseXML.getElementsByTagName("user");
|
||||||
if (xhr.status != 200)
|
for (var i=0; i<userElements.length; i++)
|
||||||
throw new Error(xhr.statusText);
|
users.push(userElements[i].getAttribute("name"));
|
||||||
|
|
||||||
// Otherwise, get list
|
return users;
|
||||||
var connections = new Array();
|
|
||||||
|
|
||||||
var connectionElements = xhr.responseXML.getElementsByTagName("connection");
|
|
||||||
for (var i=0; i<connectionElements.length; i++) {
|
|
||||||
connections.push(new GuacamoleService.Connection(
|
|
||||||
connectionElements[i].getAttribute("protocol"),
|
|
||||||
connectionElements[i].getAttribute("id")
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connections;
|
};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GuacamoleService.getUsers = function(parameters) {
|
|
||||||
|
|
||||||
// Construct request URL
|
|
||||||
var users_url = "users";
|
|
||||||
if (parameters) users_url += "?" + parameters;
|
|
||||||
|
|
||||||
// Get user list
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("GET", users_url, false);
|
|
||||||
xhr.send(null);
|
|
||||||
|
|
||||||
// If fail, throw error
|
|
||||||
if (xhr.status != 200)
|
|
||||||
throw new Error(xhr.statusText);
|
|
||||||
|
|
||||||
// Otherwise, get list
|
|
||||||
var users = new Array();
|
|
||||||
|
|
||||||
var userElements = xhr.responseXML.getElementsByTagName("user");
|
|
||||||
for (var i=0; i<userElements.length; i++) {
|
|
||||||
users.push(new GuacamoleService.User(
|
|
||||||
userElements[i].getAttribute("name")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return users;
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user