mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
Add creation mode for ConnectionEditor and ConnectionGroupEditor.
This commit is contained in:
@@ -643,7 +643,12 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
// Create form base elements
|
// Create form base elements
|
||||||
var connection_header = GuacUI.createChildElement(dialog.getHeader(), "h2");
|
var connection_header = GuacUI.createChildElement(dialog.getHeader(), "h2");
|
||||||
var form_element = GuacUI.createChildElement(dialog.getBody(), "div", "form");
|
var form_element = GuacUI.createChildElement(dialog.getBody(), "div", "form");
|
||||||
connection_header.textContent = connection.name;
|
|
||||||
|
// Set header
|
||||||
|
if (connection)
|
||||||
|
connection_header.textContent = connection.name;
|
||||||
|
else
|
||||||
|
connection_header.textContent = "New Connection";
|
||||||
|
|
||||||
var sections = GuacUI.createChildElement(
|
var sections = GuacUI.createChildElement(
|
||||||
GuacUI.createChildElement(form_element, "div", "settings section"),
|
GuacUI.createChildElement(form_element, "div", "settings section"),
|
||||||
@@ -685,7 +690,7 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
history_header.textContent = "Usage History:";
|
history_header.textContent = "Usage History:";
|
||||||
|
|
||||||
// If history present, display as table
|
// If history present, display as table
|
||||||
if (connection.history.length > 0) {
|
if (connection && connection.history.length > 0) {
|
||||||
|
|
||||||
// History section
|
// History section
|
||||||
var history_section = GuacUI.createChildElement(sections, "dd");
|
var history_section = GuacUI.createChildElement(sections, "dd");
|
||||||
@@ -802,8 +807,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
var container =
|
var container =
|
||||||
GuacUI.createTabulatedContainer(field_table, parameter.title + ":");
|
GuacUI.createTabulatedContainer(field_table, parameter.title + ":");
|
||||||
|
|
||||||
// Set initial value
|
// Set initial value, if available
|
||||||
if (connection.parameters[name])
|
if (connection && connection.parameters[name])
|
||||||
field.setValue(connection.parameters[name]);
|
field.setValue(connection.parameters[name]);
|
||||||
|
|
||||||
// Add field
|
// Add field
|
||||||
@@ -815,8 +820,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set initially selected protocol
|
// Set initially selected protocol
|
||||||
protocol_field.value = connection.protocol;
|
if (connection) protocol_field.value = connection.protocol;
|
||||||
setFields(connection.protocol);
|
setFields(protocol_field.value);
|
||||||
|
|
||||||
protocol_field.onchange = protocol_field.onclick = function() {
|
protocol_field.onchange = protocol_field.onclick = function() {
|
||||||
setFields(this.value);
|
setFields(this.value);
|
||||||
@@ -834,8 +839,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
// Build connection
|
// Build connection
|
||||||
var updated_connection = new GuacamoleService.Connection(
|
var updated_connection = new GuacamoleService.Connection(
|
||||||
protocol_field.value,
|
protocol_field.value,
|
||||||
connection.id,
|
connection && connection.id,
|
||||||
connection.name
|
connection && connection.name /* FIXME: Actually allow rename */
|
||||||
);
|
);
|
||||||
|
|
||||||
// Populate parameters
|
// Populate parameters
|
||||||
@@ -845,8 +850,15 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
updated_connection.parameters[name] = field.getValue();
|
updated_connection.parameters[name] = field.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update connection
|
// Update connection if provided
|
||||||
GuacamoleService.Connections.update(updated_connection, parameters);
|
if (connection)
|
||||||
|
GuacamoleService.Connections.update(updated_connection, parameters);
|
||||||
|
|
||||||
|
// Otherwise, create
|
||||||
|
else
|
||||||
|
GuacamoleService.Connections.create(updated_connection, parameters);
|
||||||
|
|
||||||
|
// Hide dialog and reset UI
|
||||||
dialog.getElement().parentNode.removeChild(dialog.getElement());
|
dialog.getElement().parentNode.removeChild(dialog.getElement());
|
||||||
GuacAdmin.reset();
|
GuacAdmin.reset();
|
||||||
|
|
||||||
@@ -866,8 +878,8 @@ GuacAdmin.ConnectionEditor = function(connection, parameters) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Add delete button if permission available
|
// Add delete button if permission available
|
||||||
if (GuacAdmin.cached_permissions.administer ||
|
if (connection && (GuacAdmin.cached_permissions.administer ||
|
||||||
connection.id in GuacAdmin.cached_permissions.remove_connection) {
|
connection.id in GuacAdmin.cached_permissions.remove_connection)) {
|
||||||
|
|
||||||
// Create button
|
// Create button
|
||||||
var delete_button = GuacUI.createChildElement(dialog.getFooter(), "button", "danger");
|
var delete_button = GuacUI.createChildElement(dialog.getFooter(), "button", "danger");
|
||||||
@@ -925,7 +937,12 @@ GuacAdmin.ConnectionGroupEditor = function(group, parameters) {
|
|||||||
// Create form base elements
|
// Create form base elements
|
||||||
var group_header = GuacUI.createChildElement(dialog.getHeader(), "h2");
|
var group_header = GuacUI.createChildElement(dialog.getHeader(), "h2");
|
||||||
var form_element = GuacUI.createChildElement(dialog.getBody(), "div", "form");
|
var form_element = GuacUI.createChildElement(dialog.getBody(), "div", "form");
|
||||||
group_header.textContent = group.name;
|
|
||||||
|
// Set title
|
||||||
|
if (group)
|
||||||
|
group_header.textContent = group.name;
|
||||||
|
else
|
||||||
|
group_header.textContent = "New Group";
|
||||||
|
|
||||||
var sections = GuacUI.createChildElement(
|
var sections = GuacUI.createChildElement(
|
||||||
GuacUI.createChildElement(form_element, "div", "settings section"),
|
GuacUI.createChildElement(form_element, "div", "settings section"),
|
||||||
@@ -968,12 +985,18 @@ GuacAdmin.ConnectionGroupEditor = function(group, parameters) {
|
|||||||
// Build group
|
// Build group
|
||||||
var updated_group = new GuacamoleService.ConnectionGroup(
|
var updated_group = new GuacamoleService.ConnectionGroup(
|
||||||
type,
|
type,
|
||||||
group.id,
|
group && group.id,
|
||||||
group.name
|
group && group.name /* FIXME: Allow renaming */
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update group
|
// Update group if provided
|
||||||
GuacamoleService.ConnectionGroups.update(updated_group, parameters);
|
if (connection)
|
||||||
|
GuacamoleService.ConnectionGroups.update(updated_group, parameters);
|
||||||
|
|
||||||
|
// Otherwise, create
|
||||||
|
else
|
||||||
|
GuacamoleService.ConnectionGroups.create(updated_group, parameters);
|
||||||
|
|
||||||
dialog.getElement().parentNode.removeChild(dialog.getElement());
|
dialog.getElement().parentNode.removeChild(dialog.getElement());
|
||||||
GuacAdmin.reset();
|
GuacAdmin.reset();
|
||||||
|
|
||||||
@@ -993,8 +1016,8 @@ GuacAdmin.ConnectionGroupEditor = function(group, parameters) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Add delete button if permission available
|
// Add delete button if permission available
|
||||||
if (GuacAdmin.cached_permissions.administer ||
|
if (group && (GuacAdmin.cached_permissions.administer ||
|
||||||
group.id in GuacAdmin.cached_permissions.remove_connection_group) {
|
group.id in GuacAdmin.cached_permissions.remove_connection_group)) {
|
||||||
|
|
||||||
// Create button
|
// Create button
|
||||||
var delete_button = GuacUI.createChildElement(dialog.getFooter(), "button", "danger");
|
var delete_button = GuacUI.createChildElement(dialog.getFooter(), "button", "danger");
|
||||||
@@ -1074,19 +1097,9 @@ GuacAdmin.reset = function() {
|
|||||||
|
|
||||||
GuacAdmin.buttons.add_connection.onclick = function() {
|
GuacAdmin.buttons.add_connection.onclick = function() {
|
||||||
|
|
||||||
// Try to create connection
|
// Open connection creation dialog
|
||||||
try {
|
var connection_dialog = new GuacAdmin.ConnectionEditor(null, parameters);
|
||||||
var connection = new GuacamoleService.Connection(
|
document.body.appendChild(connection_dialog.getElement());
|
||||||
GuacAdmin.cached_protocols[0].name, null, GuacAdmin.fields.connection_name.value);
|
|
||||||
GuacamoleService.Connections.create(connection, parameters);
|
|
||||||
GuacAdmin.fields.connection_name.value = "";
|
|
||||||
GuacAdmin.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alert on failure
|
|
||||||
catch (e) {
|
|
||||||
alert(e.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user