diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js index fda9e28a3..cee4d7315 100644 --- a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js +++ b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js @@ -281,26 +281,6 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i return 'PROTOCOL_' + translationStringService.canonicalize(protocolName) + '.NAME'; }; - /** - * Given the internal name of a protocol and the internal name of a - * parameter for that protocol, produces the translation string - * for the localized, human-readable name of that protocol parameter. - * - * @param {String} protocolName - * The name of the protocol. - * - * @param {String} parameterName - * The name of the protocol parameter. - * - * @returns {String} - * The translation string which produces the translated name of the - * protocol parameter specified. - */ - $scope.getProtocolParameterName = function getProtocolParameterName(protocolName, parameterName) { - return 'PROTOCOL_' + translationStringService.canonicalize(protocolName) - + '.FIELD_HEADER_' + translationStringService.canonicalize(parameterName); - }; - /** * Cancels all pending edits, returning to the management page. */ diff --git a/guacamole/src/main/webapp/app/manage/directives/connectionParameter.js b/guacamole/src/main/webapp/app/manage/directives/connectionParameter.js index 8ca090163..583872e54 100644 --- a/guacamole/src/main/webapp/app/manage/directives/connectionParameter.js +++ b/guacamole/src/main/webapp/app/manage/directives/connectionParameter.js @@ -33,36 +33,24 @@ angular.module('manage').directive('guacConnectionParameter', [function connecti scope: { /** - * The protocol this parameter is associated with. + * The field to display. * - * @type Protocol + * @type Field */ - protocol : '=', + field : '=', /** - * The unique name of this parameter within the protocol - * definition. - * + * The property which contains this fields current value. When this + * field changes, the property will be updated accordingly. + * * @type String */ - name : '=', - - /** - * The current map of parameter names to their corresponding string - * values. - * - * @type Object. - */ - parameters : '=' + model : '=' }, templateUrl: 'app/manage/templates/connectionParameter.html', controller: ['$scope', '$injector', function connectionParameterController($scope, $injector) { - // Required services - var $q = $injector.get('$q'); - var translationStringService = $injector.get('translationStringService'); - /** * The type to use for password input fields. By default, password * input fields have type 'password', and are thus masked. @@ -109,122 +97,82 @@ angular.module('manage').directive('guacConnectionParameter', [function connecti }; /** - * Deferred load of the parameter definition, pending availability - * of the protocol definition as a whole. + * Translates the given string field value into an appropriately- + * typed value as dictated by the attributes of the field, + * exposing that typed value within the scope as + * $scope.typedValue. * - * @type Deferred + * @param {String} modelValue + * The current string value of the field. */ - var parameterDefinitionAvailable = $q.defer(); + var setTypedValue = function setTypedValue(modelValue) { - /** - * Populates the parameter definition on the scope as - * $scope.parameter if both the parameter name and - * protocol definition are available. If either are unavailable, - * this function has no effect. - */ - var retrieveParameterDefinition = function retrieveParameterDefinition() { - - // Both name and protocol are needed to retrieve the parameter definition - if (!$scope.name || !$scope.protocol) + // Don't bother if the modelValue is not yet defined + if (!$scope.field) return; - // Once protocol definition is available, locate parameter definition by name - $scope.protocol.parameters.forEach(function findParameter(parameter) { - if (parameter.name === $scope.name) { - $scope.parameter = parameter; - parameterDefinitionAvailable.resolve(parameter); - } - }); + // Coerce numeric strings to numbers + if ($scope.field.type === 'NUMERIC') + $scope.typedValue = (modelValue ? Number($scope.field.value) : null); + + // Coerce boolean strings to boolean values + else if ($scope.field.type === 'BOOLEAN') + $scope.typedValue = (modelValue === $scope.field.value); + + // All other parameter types are represented internally as strings + else + $scope.typedValue = modelValue || ''; }; - // Load parameter definition once protocol definition is available. - $scope.$watch('name', retrieveParameterDefinition); - $scope.$watch('protocol', retrieveParameterDefinition); + /** + * Translates the given typed field value into a string as dictated + * by the attributes of the field, assigning that string value to + * the model. + * + * @param {String|Number|Boolean} typedValue + * The current value of the field, as an appropriate JavaScript + * type. + */ + var setModelValue = function setModelValue(typedValue) { + + // Don't bother if the model is not yet defined + if (!$scope.field) + return; + + // Convert numeric values back into strings + if ($scope.field.type === 'NUMERIC') { + if (!typedValue) + $scope.model = ''; + else + $scope.model = typedValue.toString(); + } + + // Convert boolean values back into strings based on protocol description + else if ($scope.field.type === 'BOOLEAN') + $scope.model = (typedValue ? $scope.field.value : ''); + + // All other parameter types are already strings + else + $scope.model = typedValue || ''; + + }; + + // Update string value and re-assign to model when field is changed + $scope.$watch('field', function setField(field) { + setTypedValue($scope.model); + setModelValue($scope.typedValue); + }); // Update typed value when parameter set is changed - $scope.$watch('parameters', function setParameters(parameters) { - - // Don't bother if no parameters were provided - if (!parameters) - return; - - // Wait for parameter definition - parameterDefinitionAvailable.promise.then(function setTypedValue() { - - // Pull parameter value - var value = parameters[$scope.name]; - - // Coerce numeric strings to numbers - if ($scope.parameter.type === 'NUMERIC') - $scope.typedValue = (value ? Number(value) : null); - - // Coerce boolean strings to boolean values - else if ($scope.parameter.type === 'BOOLEAN') - $scope.typedValue = (value === $scope.parameter.value); - - // All other parameter types are represented internally as strings - else - $scope.typedValue = value || ''; - - }); - + $scope.$watch('model', function setModel(model) { + setTypedValue(model); }); - + // Update string value in parameter set when typed value is changed $scope.$watch('typedValue', function typedValueChanged(typedValue) { - - // Don't bother if there's nothing to set - if (!$scope.parameters) - return; - - // Wait for parameter definition - parameterDefinitionAvailable.promise.then(function setValue() { - - // Convert numeric values back into strings - if ($scope.parameter.type === 'NUMERIC') { - if (!typedValue) - $scope.parameters[$scope.name] = ''; - else - $scope.parameters[$scope.name] = typedValue.toString(); - } - - // Convert boolean values back into strings based on protocol description - else if ($scope.parameter.type === 'BOOLEAN') - $scope.parameters[$scope.name] = (typedValue ? $scope.parameter.value : ''); - - // All other parameter types are already strings - else - $scope.parameters[$scope.name] = typedValue || ''; - - }); - - }); // end watch typedValue - - /** - * Given the internal name of a protocol, the internal name of a - * parameter for that protocol, and the internal name for a valid - * value of that parameter, produces the translation string for the - * localized, human-readable name of that parameter value. - * - * @param {String} protocolName - * The name of the protocol. - * - * @param {String} parameterName - * The name of the protocol parameter. - * - * @param {String} parameterValue - * The name of the parameter value. - * - * @returns {String} - * The translation string which produces the translated name of the - * parameter value specified. - */ - $scope.getProtocolParameterOption = function getProtocolParameterOption(protocolName, parameterName, parameterValue) { - return 'PROTOCOL_' + translationStringService.canonicalize(protocolName) - + '.FIELD_OPTION_' + translationStringService.canonicalize(parameterName) - + '_' + translationStringService.canonicalize(parameterValue || 'EMPTY'); - }; + setModelValue(typedValue); + }); }] // end controller }; diff --git a/guacamole/src/main/webapp/app/manage/templates/connectionParameter.html b/guacamole/src/main/webapp/app/manage/templates/connectionParameter.html index 7cbd07c10..b00ffac39 100644 --- a/guacamole/src/main/webapp/app/manage/templates/connectionParameter.html +++ b/guacamole/src/main/webapp/app/manage/templates/connectionParameter.html @@ -22,21 +22,21 @@ --> - - - - + + + + - -
+ +
- - + + - - + +
\ No newline at end of file diff --git a/guacamole/src/main/webapp/app/manage/templates/manageConnection.html b/guacamole/src/main/webapp/app/manage/templates/manageConnection.html index 6f0505959..7bf5946af 100644 --- a/guacamole/src/main/webapp/app/manage/templates/manageConnection.html +++ b/guacamole/src/main/webapp/app/manage/templates/manageConnection.html @@ -64,9 +64,9 @@ THE SOFTWARE. - {{getProtocolParameterName(connection.protocol, parameter.name) | translate}} + {{parameter.title | translate}} - + diff --git a/guacamole/src/main/webapp/app/rest/types/ProtocolParameter.js b/guacamole/src/main/webapp/app/rest/types/Field.js similarity index 88% rename from guacamole/src/main/webapp/app/rest/types/ProtocolParameter.js rename to guacamole/src/main/webapp/app/rest/types/Field.js index 34d87c81e..66ff9026a 100644 --- a/guacamole/src/main/webapp/app/rest/types/ProtocolParameter.js +++ b/guacamole/src/main/webapp/app/rest/types/Field.js @@ -21,20 +21,20 @@ */ /** - * Service which defines the ProtocolParameter class. + * Service which defines the Field class. */ -angular.module('rest').factory('ProtocolParameter', [function defineProtocolParameter() { +angular.module('rest').factory('Field', [function defineField() { /** * The object returned by REST API calls when representing the data * associated with a configuration parameter of a remote desktop protocol. * * @constructor - * @param {ProtocolParameter|Object} [template={}] + * @param {Field|Object} [template={}] * The object whose properties should be copied within the new - * ProtocolParameter. + * Field. */ - var ProtocolParameter = function ProtocolParameter(template) { + var Field = function Field(template) { // Use empty object by default template = template || {}; @@ -56,12 +56,12 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara /** * The type string defining which values this parameter may contain, * as well as what properties are applicable. Valid types are listed - * within ProtocolParameter.Type. + * within Field.Type. * * @type String - * @default ProtocolParameter.Type.TEXT + * @default Field.Type.TEXT */ - this.type = template.type || ProtocolParameter.Type.TEXT; + this.type = template.type || Field.Type.TEXT; /** * The value to set the parameter to, in the case of a BOOLEAN @@ -75,7 +75,7 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara * All possible legal values for this parameter. This property is only * applicable to ENUM type parameters. * - * @type ProtocolParameterOption[] + * @type FieldOption[] */ this.options = template.options; @@ -84,7 +84,7 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara /** * All valid protocol parameter types. */ - ProtocolParameter.Type = { + Field.Type = { /** * The type string associated with parameters that may contain a single @@ -147,6 +147,6 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara }; - return ProtocolParameter; + return Field; }]); \ No newline at end of file diff --git a/guacamole/src/main/webapp/app/rest/types/ProtocolParameterOption.js b/guacamole/src/main/webapp/app/rest/types/FieldOption.js similarity index 83% rename from guacamole/src/main/webapp/app/rest/types/ProtocolParameterOption.js rename to guacamole/src/main/webapp/app/rest/types/FieldOption.js index 09401be48..75ca5d544 100644 --- a/guacamole/src/main/webapp/app/rest/types/ProtocolParameterOption.js +++ b/guacamole/src/main/webapp/app/rest/types/FieldOption.js @@ -21,20 +21,20 @@ */ /** - * Service which defines the ProtocolParameterOption class. + * Service which defines the FieldOption class. */ -angular.module('rest').factory('ProtocolParameterOption', [function defineProtocolParameterOption() { +angular.module('rest').factory('FieldOption', [function defineFieldOption() { /** * The object returned by REST API calls when representing a single possible * legal value of a configuration parameter of a remote desktop protocol. * * @constructor - * @param {ProtocolParameterOption|Object} [template={}] + * @param {FieldOption|Object} [template={}] * The object whose properties should be copied within the new - * ProtocolParameterOption. + * FieldOption. */ - var ProtocolParameterOption = function ProtocolParameterOption(template) { + var FieldOption = function FieldOption(template) { // Use empty object by default template = template || {}; @@ -56,6 +56,6 @@ angular.module('rest').factory('ProtocolParameterOption', [function defineProtoc }; - return ProtocolParameterOption; + return FieldOption; }]); \ No newline at end of file diff --git a/guacamole/src/main/webapp/app/rest/types/Protocol.js b/guacamole/src/main/webapp/app/rest/types/Protocol.js index 02b6ead27..121673a55 100644 --- a/guacamole/src/main/webapp/app/rest/types/Protocol.js +++ b/guacamole/src/main/webapp/app/rest/types/Protocol.js @@ -57,7 +57,7 @@ angular.module('rest').factory('Protocol', [function defineProtocol() { * An array of all known parameters for this protocol, their types, * and other information. * - * @type ProtocolParameter[] + * @type Field[] * @default [] */ this.parameters = template.parameters || [];