Details
diff --git a/themes/src/main/resources/theme/base/admin/resources/js/app.js b/themes/src/main/resources/theme/base/admin/resources/js/app.js
index e892b45..f936fcd 100755
--- a/themes/src/main/resources/theme/base/admin/resources/js/app.js
+++ b/themes/src/main/resources/theme/base/admin/resources/js/app.js
@@ -2468,7 +2468,7 @@ module.controller('RoleSelectorModalCtrl', function($scope, realm, config, confi
})
});
-module.controller('ProviderConfigCtrl', function ($modal, $scope) {
+module.controller('ProviderConfigCtrl', function ($modal, $scope, ComponentUtils) {
$scope.fileNames = {};
@@ -2490,18 +2490,17 @@ module.controller('ProviderConfigCtrl', function ($modal, $scope) {
})
}
- $scope.newValues = [];
+ ComponentUtils.addLastEmptyValueToMultivaluedLists($scope.properties, $scope.config);
$scope.addValueToMultivalued = function(optionName) {
- var valueToPush = $scope.newValues[optionName];
+ var configProperty = $scope.config[optionName];
+ var lastIndex = configProperty.length - 1;
+ var lastValue = configProperty[lastIndex];
+ console.log("Option=" + optionName + ", lastIndex=" + lastIndex + ", lastValue=" + lastValue);
- console.log("New value to multivalued: optionName=" + optionName + ", valueToPush=" + valueToPush);
-
- if (!$scope.config[optionName]) {
- $scope.config[optionName] = [];
+ if (lastValue.length > 0) {
+ configProperty.push('');
}
- $scope.config[optionName].push(valueToPush);
- $scope.newValues[optionName] = "";
}
$scope.deleteValueFromMultivalued = function(optionName, index) {
diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js
index ba0917b..d0c2d0e 100644
--- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js
+++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js
@@ -2391,7 +2391,7 @@ module.controller('ClientRegPoliciesCtrl', function($scope, realm, clientRegistr
});
-module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientRegistrationPolicyProviders, instance, Dialog, Notifications, Components, $route, $location) {
+module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientRegistrationPolicyProviders, instance, Dialog, Notifications, Components, ComponentUtils, $route, $location) {
$scope.realm = realm;
$scope.instance = instance;
$scope.providerTypes = clientRegistrationPolicyProviders;
@@ -2408,7 +2408,11 @@ module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientReg
function toDefaultValue(configProperty) {
if (configProperty.type === 'MultivaluedString' || configProperty.type === 'MultivaluedList') {
- return [];
+ if (configProperty.defaultValue) {
+ return configProperty.defaultValue;
+ } else {
+ return [];
+ }
}
if (configProperty.defaultValue) {
@@ -2432,6 +2436,10 @@ module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientReg
}
}
+ if ($scope.providerType.properties) {
+ ComponentUtils.addLastEmptyValueToMultivaluedLists($scope.providerType.properties, $scope.instance.config);
+ }
+
var oldCopy = angular.copy($scope.instance);
$scope.changed = false;
diff --git a/themes/src/main/resources/theme/base/admin/resources/js/services.js b/themes/src/main/resources/theme/base/admin/resources/js/services.js
index 66ea756..a291732 100755
--- a/themes/src/main/resources/theme/base/admin/resources/js/services.js
+++ b/themes/src/main/resources/theme/base/admin/resources/js/services.js
@@ -191,6 +191,48 @@ module.factory('Notifications', function($rootScope, $timeout) {
return notifications;
});
+
+module.factory('ComponentUtils', function() {
+
+ var utils = {};
+
+ utils.addLastEmptyValueToMultivaluedLists = function(properties, config) {
+
+ for (var i=0 ; i<properties.length ; i++) {
+ var prop = properties[i];
+ if (prop.type === 'MultivaluedString') {
+ var configProperty = config[prop.name];
+
+ if (configProperty == null) {
+ configProperty = [];
+ config[prop.name] = configProperty;
+ }
+
+ if (configProperty.length == 0 || configProperty[configProperty.length - 1].length > 0) {
+ configProperty.push('');
+ }
+ }
+ }
+ }
+
+
+ utils.removeLastEmptyValue = function(componentConfig) {
+
+ for (var configPropertyName in componentConfig) {
+ var configVal = componentConfig[configPropertyName];
+ if (configVal && configVal.length > 0) {
+ var lastVal = configVal[configVal.length - 1];
+ if (lastVal === '') {
+ console.log('Remove empty value from config property: ' + configPropertyName);
+ configVal.splice(configVal.length - 1, 1);
+ }
+ }
+ }
+ }
+
+ return utils;
+});
+
module.factory('Realm', function($resource) {
return $resource(authUrl + '/admin/realms/:id', {
id : '@realm'
@@ -1648,13 +1690,32 @@ module.factory('DefaultGroups', function($resource) {
});
});
-module.factory('Components', function($resource) {
+module.factory('Components', function($resource, ComponentUtils) {
return $resource(authUrl + '/admin/realms/:realm/components/:componentId', {
realm : '@realm',
componentId : '@componentId'
}, {
update : {
- method : 'PUT'
+ method : 'PUT',
+ transformRequest: function(componentInstance) {
+
+ if (componentInstance.config) {
+ ComponentUtils.removeLastEmptyValue(componentInstance.config);
+ }
+
+ return angular.toJson(componentInstance);
+ }
+ },
+ save : {
+ method : 'POST',
+ transformRequest: function(componentInstance) {
+
+ if (componentInstance.config) {
+ ComponentUtils.removeLastEmptyValue(componentInstance.config);
+ }
+
+ return angular.toJson(componentInstance);
+ }
}
});
});
diff --git a/themes/src/main/resources/theme/base/admin/resources/templates/kc-component-config.html b/themes/src/main/resources/theme/base/admin/resources/templates/kc-component-config.html
index 63702f9..4062b1c 100755
--- a/themes/src/main/resources/theme/base/admin/resources/templates/kc-component-config.html
+++ b/themes/src/main/resources/theme/base/admin/resources/templates/kc-component-config.html
@@ -54,17 +54,15 @@
<div class="col-sm-6" data-ng-if="option.type == 'MultivaluedString'">
<div class="input-group" ng-repeat="(i, currentOption) in config[option.name] track by $index">
<input class="form-control" ng-model="config[option.name][i]">
- <div class="input-group-btn">
+ <div class="input-group-btn" data-ng-if="$index < config[option.name].length - 1">
<button class="btn btn-default" type="button" data-ng-click="deleteValueFromMultivalued(option.name, $index)"><span class="fa fa-minus"></span></button>
</div>
- </div>
- <div class="input-group">
- <input class="form-control" ng-model="newValues[option.name]">
- <div class="input-group-btn">
- <button class="btn btn-default" type="button" data-ng-click="newValues[option.name].length > 0 && addValueToMultivalued(option.name)"><span class="fa fa-plus"></span></button>
+ <div class="input-group-btn" data-ng-if="$index === config[option.name].length - 1">
+ <button class="btn btn-default" type="button" data-ng-click="addValueToMultivalued(option.name)"><span class="fa fa-plus"></span></button>
</div>
</div>
+
</div>
<kc-tooltip>{{:: option.helpText | translate}}</kc-tooltip>