Store parent group in Connection and ConnectionGroup.

This commit is contained in:
Michael Jumper
2013-08-14 14:16:54 -07:00
parent 18ef0d2f77
commit 8f328d68f9

View File

@@ -51,6 +51,14 @@ GuacamoleService.ConnectionGroup = function(type, id, name) {
*/ */
this.name = name; this.name = name;
/**
* The parent connection group of this group. If this group is the root
* group, this will be null.
*
* @type GuacamoleService.ConnectionGroup
*/
this.parent = null;
/** /**
* All connection groups contained within this group. * All connection groups contained within this group.
* @type GuacamoleService.ConnectionGroup[] * @type GuacamoleService.ConnectionGroup[]
@@ -105,6 +113,12 @@ GuacamoleService.Connection = function(protocol, id, name) {
*/ */
var guac_connection = this; var guac_connection = this;
/**
* The parent connection group of this connection.
* @type GuacamoleService.ConnectionGroup
*/
this.parent = null;
/** /**
* The protocol associated with this connection. * The protocol associated with this connection.
*/ */
@@ -357,11 +371,13 @@ GuacamoleService.Connections = {
* Parse the contents of the given connection element within XML, * Parse the contents of the given connection element within XML,
* returning a corresponding GuacamoleService.Connection. * returning a corresponding GuacamoleService.Connection.
* *
* @param {Element} element * @param {GuacamoleService.ConnectionGroup} The connection group
* containing this connection.
* @param {Element} element The element being parsed.
* @return {GuacamoleService.Connection} The connection represented by * @return {GuacamoleService.Connection} The connection represented by
* the element just parsed. * the element just parsed.
*/ */
function parseConnection(element) { function parseConnection(parent, element) {
var i; var i;
@@ -371,6 +387,9 @@ GuacamoleService.Connections = {
element.getAttribute("name") element.getAttribute("name")
); );
// Set parent
connection.parent = parent;
// Add parameter values for each parmeter received // Add parameter values for each parmeter received
var paramElements = element.getElementsByTagName("param"); var paramElements = element.getElementsByTagName("param");
for (i=0; i<paramElements.length; i++) { for (i=0; i<paramElements.length; i++) {
@@ -416,12 +435,14 @@ GuacamoleService.Connections = {
* Recursively parse the contents of the given group element within XML, * Recursively parse the contents of the given group element within XML,
* returning a corresponding GuacamoleService.ConnectionGroup. * returning a corresponding GuacamoleService.ConnectionGroup.
* *
* @param {Element} element * @param {GuacamoleService.ConnectionGroup} The connection group
* containing this group.
* @param {Element} element The element being parsed.
* @return {GuacamoleService.ConnectionGroup} The connection group * @return {GuacamoleService.ConnectionGroup} The connection group
* represented by the element * represented by the element
* just parsed. * just parsed.
*/ */
function parseGroup(element) { function parseGroup(parent, element) {
var id = element.getAttribute("id"); var id = element.getAttribute("id");
var name = element.getAttribute("name"); var name = element.getAttribute("name");
@@ -437,6 +458,9 @@ GuacamoleService.Connections = {
// Create corresponding group // Create corresponding group
var group = new GuacamoleService.ConnectionGroup(type, id, name); var group = new GuacamoleService.ConnectionGroup(type, id, name);
// Set parent
group.parent = parent;
// For each child element // For each child element
var current = element.firstChild; var current = element.firstChild;
while (current !== null) { while (current !== null) {
@@ -450,7 +474,7 @@ GuacamoleService.Connections = {
for (i=0; i<children.length; i++) { for (i=0; i<children.length; i++) {
var child = children[i]; var child = children[i];
if (child.localName === "connection") if (child.localName === "connection")
group.connections.push(parseConnection(child)); group.connections.push(parseConnection(group, child));
} }
} }
@@ -460,7 +484,7 @@ GuacamoleService.Connections = {
for (i=0; i<children.length; i++) { for (i=0; i<children.length; i++) {
var child = children[i]; var child = children[i];
if (child.localName === "group") if (child.localName === "group")
group.groups.push(parseGroup(child)); group.groups.push(parseGroup(group, child));
} }
} }
@@ -490,7 +514,7 @@ GuacamoleService.Connections = {
// Handle response // Handle response
GuacamoleService.handleResponse(xhr); GuacamoleService.handleResponse(xhr);
return parseGroup(xhr.responseXML.documentElement); return parseGroup(null, xhr.responseXML.documentElement);
}, },