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 e892b4544b..f936fcdbe6 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 ba0917b57d..d0c2d0e8e1 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 c2e28f575d..5b4438245a 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 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' @@ -1657,13 +1699,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 63702f91df..4062b1cc33 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 @@
-
+
+ +
+ +
-
- -
- -
-
{{:: option.helpText | translate}}