mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Implement SHOW_ROOT_GROUP flag for GroupView. Use said flag for dropdown group selector.
This commit is contained in:
@@ -1217,7 +1217,7 @@ GuacAdmin.ConnectionGroupSelect = function(group) {
|
||||
var group_outside = GuacUI.createChildElement(container, "div", "overlay");
|
||||
var group_section = GuacUI.createChildElement(container, "div", "dropdown");
|
||||
|
||||
var view = new GuacUI.GroupView(group);
|
||||
var view = new GuacUI.GroupView(group, GuacUI.GroupView.SHOW_ROOT_GROUP);
|
||||
group_section.appendChild(view.getElement());
|
||||
|
||||
// Hide when clicked outside
|
||||
|
@@ -963,6 +963,11 @@ GuacUI.GroupView = function(root_group, flags) {
|
||||
*/
|
||||
var show_connections = flags & GuacUI.GroupView.SHOW_CONNECTIONS;
|
||||
|
||||
/**
|
||||
* Whether the root group should be included in the view.
|
||||
*/
|
||||
var show_root = flags & GuacUI.GroupView.SHOW_ROOT_GROUP;
|
||||
|
||||
/**
|
||||
* Set of all group checkboxes, indexed by ID. Only applicable when
|
||||
* multiselect is enabled.
|
||||
@@ -1125,33 +1130,47 @@ GuacUI.GroupView = function(root_group, flags) {
|
||||
pager.page_capacity = 20;
|
||||
|
||||
/**
|
||||
* Adds the given group to the given display parent object. This object
|
||||
* must have an addElement() function, which will be used for adding all
|
||||
* child elements representing child connections and groups.
|
||||
* Adds the contents of the given group via the given appendChild()
|
||||
* function, but not the given group itself.
|
||||
*
|
||||
* @param {GuacamoleService.ConnectionGroup} group The group to add.
|
||||
* @param {Function} appendChild A function which, given an element, will add that
|
||||
* element the the display as desired.
|
||||
* @param {GuacamoleService.ConnectionGroup} group The group whose contents
|
||||
* should be added.
|
||||
* @param {Function} appendChild A function which, given an element, will
|
||||
* add that element the the display as
|
||||
* desired.
|
||||
*/
|
||||
function addGroup(group, appendChild) {
|
||||
function addGroupContents(group, appendChild) {
|
||||
|
||||
var i;
|
||||
group_view.groups[group.id] = group;
|
||||
|
||||
// Add all contained connections
|
||||
if (show_connections) {
|
||||
for (i=0; i<group.connections.length; i++) {
|
||||
for (i=0; i<group.connections.length; i++)
|
||||
addConnection(group.connections[i], appendChild);
|
||||
}
|
||||
|
||||
// Add all contained groups
|
||||
for (i=0; i<group.groups.length; i++)
|
||||
addGroup(group.groups[i], appendChild);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given connection via the given appendChild() function.
|
||||
*
|
||||
* @param {GuacamoleService.Connection} connection The connection to add.
|
||||
* @param {Function} appendChild A function which, given an element, will
|
||||
* add that element the the display as
|
||||
* desired.
|
||||
*/
|
||||
function addConnection(connection, appendChild) {
|
||||
|
||||
// Add connection to set
|
||||
var connection = group.connections[i];
|
||||
group_view.connections[connection.id] = connection;
|
||||
|
||||
// Add connection to connection list or parent group
|
||||
var guacui_connection = new GuacUI.Connection(connection);
|
||||
GuacUI.addClass(guacui_connection.getElement(), "list-item");
|
||||
|
||||
(function(connection) {
|
||||
|
||||
// If multiselect, add checkbox for each connection
|
||||
if (multiselect) {
|
||||
|
||||
@@ -1190,25 +1209,27 @@ GuacUI.GroupView = function(root_group, flags) {
|
||||
group_view.onconnectionclick(connection);
|
||||
};
|
||||
|
||||
})(connection);
|
||||
|
||||
} // end for each connection
|
||||
}
|
||||
|
||||
// Add all contained groups
|
||||
for (i=0; i<group.groups.length; i++) {
|
||||
/**
|
||||
* Adds the given group via the given appendChild() function.
|
||||
*
|
||||
* @param {GuacamoleService.ConnectionGroup} group The group to add.
|
||||
* @param {Function} appendChild A function which, given an element, will
|
||||
* add that element the the display as
|
||||
* desired.
|
||||
*/
|
||||
function addGroup(group, appendChild) {
|
||||
|
||||
// Create display element for group
|
||||
var child_group = group.groups[i];
|
||||
var list_group = new GuacUI.ListGroup(child_group.name);
|
||||
// Add group to groups collection
|
||||
group_view.groups[group.id] = group;
|
||||
|
||||
// Recursively add all children to the new element
|
||||
addGroup(child_group, list_group.addElement);
|
||||
|
||||
// Add element to display
|
||||
// Create element for group
|
||||
var list_group = new GuacUI.ListGroup(group.name);
|
||||
GuacUI.addClass(list_group.getElement(), "list-item");
|
||||
|
||||
(function(child_group) {
|
||||
// Recursively add all children to the new element
|
||||
addGroupContents(group, list_group.addElement);
|
||||
|
||||
// If multiselect, add checkbox for each group
|
||||
if (multiselect) {
|
||||
@@ -1227,7 +1248,7 @@ GuacUI.GroupView = function(root_group, flags) {
|
||||
|
||||
// Fire event if handler defined
|
||||
if (group_view.ongroupchange)
|
||||
group_view.ongroupchange(child_group, this.checked);
|
||||
group_view.ongroupchange(group, this.checked);
|
||||
|
||||
}
|
||||
|
||||
@@ -1236,7 +1257,7 @@ GuacUI.GroupView = function(root_group, flags) {
|
||||
group_checkbox.addEventListener("change", fire_group_change, false);
|
||||
|
||||
// Add checbox to set of group checkboxes
|
||||
group_checkboxes[child_group.id] = group_checkbox;
|
||||
group_checkboxes[group.id] = group_checkbox;
|
||||
|
||||
}
|
||||
else
|
||||
@@ -1245,18 +1266,19 @@ GuacUI.GroupView = function(root_group, flags) {
|
||||
// Fire click events when group clicked
|
||||
list_group.onclick = function() {
|
||||
if (group_view.ongroupclick)
|
||||
group_view.ongroupclick(child_group);
|
||||
group_view.ongroupclick(group);
|
||||
};
|
||||
|
||||
})(child_group);
|
||||
|
||||
} // end for each gorup
|
||||
|
||||
}
|
||||
|
||||
// Add root group directly to pager
|
||||
// If requested, include the root group as an item
|
||||
if (show_root)
|
||||
addGroup(root_group, pager.addElement);
|
||||
|
||||
// Otherwise, only add contents of root group
|
||||
else
|
||||
addGroupContents(root_group, pager.addElement);
|
||||
|
||||
// Add buttons if more than one page
|
||||
if (pager.last_page !== 0) {
|
||||
var list_buttons = GuacUI.createChildElement(element, "div", "buttons");
|
||||
@@ -1278,6 +1300,11 @@ GuacUI.GroupView.MULTISELECT = 0x1;
|
||||
*/
|
||||
GuacUI.GroupView.SHOW_CONNECTIONS = 0x2;
|
||||
|
||||
/**
|
||||
* When set, also displays the root group. By default the root group is hidden.
|
||||
*/
|
||||
GuacUI.GroupView.SHOW_ROOT_GROUP = 0x4;
|
||||
|
||||
/**
|
||||
* Simple modal dialog providing a header, body, and footer. No other
|
||||
* functionality is provided other than a reasonable hierarchy of divs and
|
||||
|
Reference in New Issue
Block a user