diff --git a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js index d8ca6d97f9..5acfaec62e 100644 --- a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js +++ b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js @@ -313,6 +313,15 @@ export default [ populateTacacsProtocol(false); }); + $scope.$on('codeMirror_populated', function() { + let tab = $stateParams.currentTab; + if (tab === 'auth') { + startCodeMirrors(); + codeInputInitialized = true; + } + }); + + angular.extend(authVm, { activeForm: activeForm, activeAuthForm: activeAuthForm, diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index 66f08942a9..335e1286cb 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -87,8 +87,9 @@ export default [ // behind the comma. if(key === "AD_HOC_COMMANDS"){ $scope[key] = data[key].toString(); - } - else { + } else if (key === "AUTH_LDAP_USER_SEARCH" || key === "AUTH_LDAP_GROUP_SEARCH") { + $scope[key] = JSON.stringify(data[key]); + } else { $scope[key] = ConfigurationUtils.arrayToList(data[key], key); } @@ -324,11 +325,12 @@ export default [ else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){ $scope.$broadcast(key+'_reverted'); } - else if($scope[key + '_field'].type === "textarea" && _.isArray($scope.configDataResolve[key].default)){ - $scope[key] = ConfigurationUtils.arrayToList($scope[key], key); - } else if($scope[key + '_field'].hasOwnProperty('codeMirror')){ - $scope[key] = '{}'; + if (key === "AUTH_LDAP_USER_SEARCH" || key === "AUTH_LDAP_GROUP_SEARCH") { + $scope[key] = '[]'; + } else { + $scope[key] = '{}'; + } $scope.$broadcast('codeMirror_populated', key); } loginUpdate(); diff --git a/awx/ui/client/src/configuration/configurationUtils.service.js b/awx/ui/client/src/configuration/configurationUtils.service.js index 7620d6917d..e9d448aff5 100644 --- a/awx/ui/client/src/configuration/configurationUtils.service.js +++ b/awx/ui/client/src/configuration/configurationUtils.service.js @@ -9,16 +9,30 @@ export default ['$q', return { listToArray: function(input) { - if (input.indexOf('\n') !== -1) { + var payload; + + if (input.indexOf('[') !== -1) { + try { + payload = JSON.parse(input); + + if (!Array.isArray(payload)) { + payload = []; + } + } catch(err) { + payload = []; + } + } else if (input.indexOf('\n') !== -1) { //Parse multiline input - return input.replace(/^\s+|\s+$/g, "").split('\n'); + payload = input.replace(/^\s+|\s+$/g, "").split('\n'); } else { - if (input === '') { - return []; + if (input === '' || input === '{}') { + payload = []; } else { - return input.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/); + payload = input.replace(/^\s+|\s+$/g, "") + .split(/\s*,\s*/); } } + return payload; }, arrayToList: function(input) { diff --git a/awx/ui/client/src/shared/parse/parse-type-change.factory.js b/awx/ui/client/src/shared/parse/parse-type-change.factory.js index 678c91abe9..1556acad78 100644 --- a/awx/ui/client/src/shared/parse/parse-type-change.factory.js +++ b/awx/ui/client/src/shared/parse/parse-type-change.factory.js @@ -51,11 +51,16 @@ export default // converting yaml to json try { removeField(fld); + json_obj = jsyaml.load(scope[fld]); + if ($.isEmptyObject(json_obj)) { - scope[fld] = "{}"; - } - else { + if (Array.isArray(json_obj)) { + scope[fld] = "[]"; + } else { + scope[fld] = "{}"; + } + } else { scope[fld] = JSON.stringify(json_obj, null, " "); } createField(onReady, onChange, fld);