Merge 1.0.0 changes back to master.

This commit is contained in:
Nick Couchman
2018-06-13 06:15:10 -04:00
18 changed files with 213 additions and 38 deletions

View File

@@ -24,44 +24,10 @@
angular.module('form').controller('selectFieldController', ['$scope', '$injector',
function selectFieldController($scope, $injector) {
// Required services
var translationStringService = $injector.get('translationStringService');
// Interpret undefined/null as empty string
$scope.$watch('model', function setModel(model) {
if (!model && model !== '')
$scope.model = '';
});
/**
* Produces the translation string for the given field option
* value. The translation string will be of the form:
*
* <code>NAMESPACE.FIELD_OPTION_NAME_VALUE<code>
*
* where <code>NAMESPACE</code> is the namespace provided to the
* directive, <code>NAME</code> is the field name transformed
* via translationStringService.canonicalize(), and
* <code>VALUE</code> is the option value transformed via
* translationStringService.canonicalize()
*
* @param {String} value
* The name of the option value.
*
* @returns {String}
* The translation string which produces the translated name of the
* value specified.
*/
$scope.getFieldOption = function getFieldOption(value) {
// If no field, or no value, then no corresponding translation string
if (!$scope.field || !$scope.field.name || !value)
return '';
return translationStringService.canonicalize($scope.namespace || 'MISSING_NAMESPACE')
+ '.FIELD_OPTION_' + translationStringService.canonicalize($scope.field.name)
+ '_' + translationStringService.canonicalize(value || 'EMPTY');
};
}]);

View File

@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Controller for text fields.
*/
angular.module('form').controller('textFieldController', ['$scope', '$injector',
function textFieldController($scope, $injector) {
/**
* The ID of the datalist element that should be associated with the text
* field, providing a set of known-good values. If no such values are
* defined, this will be null.
*
* @type String
*/
$scope.dataListId = null;
// Generate unique ID for datalist, if applicable
if ($scope.field.options && $scope.field.options.length)
$scope.dataListId = $scope.field.name + '-datalist';
}]);

View File

@@ -97,6 +97,37 @@ angular.module('form').directive('guacFormField', [function formField() {
};
/**
* Produces the translation string for the given field option
* value. The translation string will be of the form:
*
* <code>NAMESPACE.FIELD_OPTION_NAME_VALUE<code>
*
* where <code>NAMESPACE</code> is the namespace provided to the
* directive, <code>NAME</code> is the field name transformed
* via translationStringService.canonicalize(), and
* <code>VALUE</code> is the option value transformed via
* translationStringService.canonicalize()
*
* @param {String} value
* The name of the option value.
*
* @returns {String}
* The translation string which produces the translated name of the
* value specified.
*/
$scope.getFieldOption = function getFieldOption(value) {
// If no field, or no value, then no corresponding translation string
if (!$scope.field || !$scope.field.name || !value)
return '';
return translationStringService.canonicalize($scope.namespace || 'MISSING_NAMESPACE')
+ '.FIELD_OPTION_' + translationStringService.canonicalize($scope.field.name)
+ '_' + translationStringService.canonicalize(value || 'EMPTY');
};
/**
* Returns whether the current field should be displayed.
*

View File

@@ -44,6 +44,8 @@ angular.module('form').provider('formService', function formServiceProvider() {
* @type FieldType
*/
'TEXT' : {
module : 'form',
controller : 'textFieldController',
templateUrl : 'app/form/templates/textField.html'
},

View File

@@ -1 +1,7 @@
<input type="text" ng-model="model" autocorrect="off" autocapitalize="off"/>
<div class="text-field">
<input type="text" ng-model="model" autocorrect="off" autocapitalize="off" ng-attr-list="{{ dataListId }}"/>
<datalist ng-if="dataListId" id="{{ dataListId }}">
<option ng-repeat="option in field.options | orderBy: option"
value="{{ option }}">{{ getFieldOption(option) | translate }}</option>
</datalist>
</div>