GUAC-1160: Move generalized parameter directive into own "form" module as "guacFormField".

This commit is contained in:
Michael Jumper
2015-04-15 14:04:15 -07:00
parent 6d0d7b127f
commit d29ab56d44
7 changed files with 94 additions and 46 deletions

View File

@@ -1,180 +0,0 @@
/*
* Copyright (C) 2014 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* A directive that allows editing of a connection parameter.
*/
angular.module('manage').directive('guacConnectionParameter', [function connectionParameter() {
return {
// Element only
restrict: 'E',
replace: true,
scope: {
/**
* The field to display.
*
* @type Field
*/
field : '=',
/**
* The property which contains this fields current value. When this
* field changes, the property will be updated accordingly.
*
* @type String
*/
model : '='
},
templateUrl: 'app/manage/templates/connectionParameter.html',
controller: ['$scope', '$injector', function connectionParameterController($scope, $injector) {
/**
* The type to use for password input fields. By default, password
* input fields have type 'password', and are thus masked.
*
* @type String
* @default 'password'
*/
$scope.passwordInputType = 'password';
/**
* Returns a string which describes the action the next call to
* togglePassword() will have.
*
* @return {String}
* A string which describes the action the next call to
* togglePassword() will have.
*/
$scope.getTogglePasswordHelpText = function getTogglePasswordHelpText() {
// If password is hidden, togglePassword() will show the password
if ($scope.passwordInputType === 'password')
return 'MANAGE.HELP_SHOW_PASSWORD';
// If password is shown, togglePassword() will hide the password
return 'MANAGE.HELP_HIDE_PASSWORD';
};
/**
* Toggles visibility of the parameter contents, if this parameter
* is a password parameter. Initially, password contents are
* masked (invisible).
*/
$scope.togglePassword = function togglePassword() {
// If password is hidden, show the password
if ($scope.passwordInputType === 'password')
$scope.passwordInputType = 'text';
// If password is shown, hide the password
else
$scope.passwordInputType = 'password';
};
/**
* 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
* <code>$scope.typedValue<code>.
*
* @param {String} modelValue
* The current string value of the field.
*/
var setTypedValue = function setTypedValue(modelValue) {
// Don't bother if the modelValue is not yet defined
if (!$scope.field)
return;
// 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 || '';
};
/**
* 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('model', function setModel(model) {
setTypedValue(model);
});
// Update string value in parameter set when typed value is changed
$scope.$watch('typedValue', function typedValueChanged(typedValue) {
setModelValue(typedValue);
});
}] // end controller
};
}]);

View File

@@ -24,6 +24,7 @@
* The module for the administration functionality.
*/
angular.module('manage', [
'form',
'groupList',
'list',
'locale',

View File

@@ -21,37 +21,8 @@
*/
/* Do not stretch connection parameters to fit available area */
.connection-parameter input[type=text],
.connection-parameter input[type=password],
.connection-parameter input[type=number] {
.connection-parameters input[type=text],
.connection-parameters input[type=password],
.connection-parameters input[type=number] {
width: auto;
}
/* Keep toggle-password icon on same line */
.connection-parameter .password-field {
white-space: nowrap;
}
/* Generic 1x1em icon/button */
.connection-parameter .password-field .icon.toggle-password {
display: inline-block;
opacity: 0.5;
cursor: default;
background-repeat: no-repeat;
background-size: 1em;
width: 1em;
height: 1em;
}
/* Icon for unmasking passwords */
.connection-parameter .password-field input[type=password] ~ .icon.toggle-password {
background-image: url('images/action-icons/guac-show-pass.png');
}
/* Icon for masking passwords */
.connection-parameter .password-field input[type=text] ~ .icon.toggle-password {
background-image: url('images/action-icons/guac-hide-pass.png');
}

View File

@@ -1,42 +0,0 @@
<div class="connection-parameter">
<!--
Copyright 2014 Glyptodon LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!-- Generic input types -->
<input ng-show="field.type === 'TEXT'" type="text" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
<input ng-show="field.type === 'NUMERIC'" type="number" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
<input ng-show="field.type === 'USERNAME'" type="text" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
<input ng-show="field.type === 'BOOLEAN'" type="checkbox" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
<!-- Password field -->
<div ng-show="field.type === 'PASSWORD'" class="password-field">
<input type="{{passwordInputType}}" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
<div class="icon toggle-password" ng-click="togglePassword()" title="{{getTogglePasswordHelpText() | translate}}"></div>
</div>
<!-- Multiline field -->
<textarea ng-show="field.type === 'MULTILINE'" ng-model="typedValue" autocorrect="off" autocapitalize="off"></textarea>
<!-- Enumerated field -->
<select ng-show="field.type === 'ENUM'" ng-model="typedValue" ng-options="option.value as option.title | translate for option in field.options | orderBy: value"></select>
</div>

View File

@@ -60,13 +60,13 @@ THE SOFTWARE.
<!-- Connection parameters -->
<h2 class="header">{{'MANAGE_CONNECTION.SECTION_HEADER_PARAMETERS' | translate}}</h2>
<div class="section" ng-class="{loading: !parameters}">
<table class="properties">
<table class="properties connection-parameters">
<!-- All the different possible editable field types -->
<tr ng-repeat="parameter in protocols[connection.protocol].parameters">
<th>{{parameter.title | translate}}</th>
<td>
<guac-connection-parameter field="parameter" model="parameters[parameter.name]"></guac-connection-parameter>
<guac-form-field field="parameter" model="parameters[parameter.name]"></guac-form-field>
</td>
</tr>
</table>