From ac2f063c89c43aaa26a34cd6a60f13fda6a6a25f Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Wed, 15 Feb 2017 12:20:22 -0500 Subject: [PATCH 1/2] fixing codemirror instantiation on ctit auth-form --- .../configuration-auth.controller.js | 66 +++++++++++-------- .../configuration/configuration.controller.js | 8 ++- 2 files changed, 45 insertions(+), 29 deletions(-) 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 a674eb76aa..e4d471d9ba 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 @@ -60,9 +60,11 @@ export default [ } var activeForm = function() { + if(!$scope.$parent[formTracker.currentFormName()].$dirty) { authVm.activeAuthForm = authVm.dropdownValue; formTracker.setCurrentAuth(authVm.activeAuthForm); + startCodeMirrors(); } else { var msg = i18n._('You have unsaved changes. Would you like to proceed without saving?'); var title = i18n._('Warning: Unsaved Changes'); @@ -115,28 +117,36 @@ export default [ var authForms = [{ formDef: configurationAzureForm, - id: 'auth-azure-form' + id: 'auth-azure-form', + name: 'azure' }, { formDef: configurationGithubForm, - id: 'auth-github-form' + id: 'auth-github-form', + name: 'github' }, { formDef: configurationGithubOrgForm, - id: 'auth-github-org-form' + id: 'auth-github-org-form', + name: 'github_org' }, { formDef: configurationGithubTeamForm, - id: 'auth-github-team-form' + id: 'auth-github-team-form', + name: 'github_team' }, { formDef: configurationGoogleForm, - id: 'auth-google-form' + id: 'auth-google-form', + name: 'google_oauth' }, { formDef: configurationLdapForm, - id: 'auth-ldap-form' + id: 'auth-ldap-form', + name: 'ldap' }, { formDef: configurationRadiusForm, - id: 'auth-radius-form' + id: 'auth-radius-form', + name: 'radius' }, { formDef: configurationSamlForm, - id: 'auth-saml-form' + id: 'auth-saml-form', + name: 'saml' }, ]; var forms = _.pluck(authForms, 'formDef'); @@ -161,6 +171,27 @@ export default [ form.buttons.save.disabled = $rootScope.user_is_system_auditor; }); + function startCodeMirrors(){ + // Attach codemirror to fields that need it + let form = _.find(authForms, function(form){ + return form.name === $scope.authVm.activeAuthForm; + }); + _.each(form.formDef.fields, function(field) { + // Codemirror balks at empty values so give it one + if($scope.$parent[field.name] === null && field.codeMirror) { + $scope.$parent[field.name] = '{}'; + } + if(field.codeMirror) { + ParseTypeChange({ + scope: $scope.$parent, + variable: field.name, + parse_variable: 'parseType', + field_id: form.formDef.name + '_' + field.name + }); + } + }); + } + function addFieldInfo(form, key) { _.extend(form.fields[key], { awPopOver: ($scope.$parent.configDataResolve[key].defined_in_file) ? @@ -195,24 +226,7 @@ export default [ var dropdownRendered = false; $scope.$on('populated', function() { - // Attach codemirror to fields that need it - _.each(authForms, function(form) { - _.each(form.formDef.fields, function(field) { - // Codemirror balks at empty values so give it one - if($scope.$parent[field.name] === null && field.codeMirror) { - $scope.$parent[field.name] = '{}'; - } - if(field.codeMirror) { - ParseTypeChange({ - scope: $scope.$parent, - variable: field.name, - parse_variable: 'parseType', - field_id: form.formDef.name + '_' + field.name, - readonly: true, - }); - } - }); - }); + startCodeMirrors(); // Create Select2 fields var opts = []; diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index f9319300a9..78b9b228d3 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -7,7 +7,7 @@ export default [ '$scope', '$rootScope', '$state', '$stateParams', '$timeout', '$q', 'Alert', 'ClearScope', 'ConfigurationService', 'ConfigurationUtils', 'CreateDialog', 'CreateSelect2', 'i18n', 'ParseTypeChange', 'ProcessErrors', 'Store', - 'Wait', 'configDataResolve', + 'Wait', 'configDataResolve', 'ToJSON', //Form definitions 'configurationAzureForm', 'configurationGithubForm', @@ -25,7 +25,7 @@ export default [ function( $scope, $rootScope, $state, $stateParams, $timeout, $q, Alert, ClearScope, ConfigurationService, ConfigurationUtils, CreateDialog, CreateSelect2, i18n, ParseTypeChange, ProcessErrors, Store, - Wait, configDataResolve, + Wait, configDataResolve, ToJSON, //Form definitions configurationAzureForm, configurationGithubForm, @@ -363,7 +363,9 @@ export default [ if($scope[key] === '') { payload[key] = {}; } else { - payload[key] = JSON.parse($scope[key]); + // payload[key] = JSON.parse($scope[key]); + payload[key] = ToJSON($scope.parseType, + $scope[key]); } } else { From 106230803523c187cf0b60fc47dd6ad625e50c70 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Wed, 15 Feb 2017 23:51:23 -0500 Subject: [PATCH 2/2] fix for line escaping for codemirror on ctit --- .../src/configuration/auth-form/configuration-auth.controller.js | 1 + 1 file changed, 1 insertion(+) 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 e4d471d9ba..a98ef9dc74 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 @@ -188,6 +188,7 @@ export default [ parse_variable: 'parseType', field_id: form.formDef.name + '_' + field.name }); + $scope.parseTypeChange('parseType', field.name); } }); }