From a6a64e4630ad267a10be55b18b7d993ea345d9b1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 9 Feb 2013 01:40:36 -0800 Subject: [PATCH] #268: Add user service JavaScript. --- guacamole/src/main/webapp/scripts/service.js | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/guacamole/src/main/webapp/scripts/service.js b/guacamole/src/main/webapp/scripts/service.js index 298184b15..368ca6f8d 100644 --- a/guacamole/src/main/webapp/scripts/service.js +++ b/guacamole/src/main/webapp/scripts/service.js @@ -43,6 +43,21 @@ GuacamoleService.Connection = function(protocol, id) { }; +/** + * An arbitrary Guacamole user, consisting of a username. + * + * @constructor + * @param {String} username The username associate with this user. + */ +GuacamoleService.User = function(username) { + + /** + * The username associated with this user. + */ + this.username = username; + +}; + GuacamoleService.getConnections = function(parameters) { // Construct request URL @@ -73,3 +88,31 @@ GuacamoleService.getConnections = function(parameters) { }; +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