From 63f27a120fdd1d8d43715a7a42faa3ac3097b371 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 21 Feb 2017 17:51:10 -0800 Subject: [PATCH] fixing reset for CodeMirror instances --- .../configuration-auth.controller.js | 49 ++++++++++++------- .../configuration/configuration.controller.js | 8 ++- 2 files changed, 38 insertions(+), 19 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 fe85f071ea..325d77e611 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 @@ -171,26 +171,37 @@ export default [ form.buttons.save.disabled = $rootScope.user_is_system_auditor; }); - function startCodeMirrors(){ - // Attach codemirror to fields that need it + function startCodeMirrors(key){ + + function createIt(name){ + ParseTypeChange({ + scope: $scope.$parent, + variable: name, + parse_variable: 'parseType', + field_id: form.formDef.name + '_' + name + }); + $scope.parseTypeChange('parseType', name); + } + 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 - }); - $scope.parseTypeChange('parseType', field.name); - } - }); + + if(!key){ + // Attach codemirror to fields that need it + _.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) { + createIt(field.name) + } + }); + } + else if(key){ + createIt(key); + } } function addFieldInfo(form, key) { @@ -252,6 +263,10 @@ export default [ populateLDAPGroupType(flag); }); + $scope.$on('codeMirror_populated', function(e, key) { + startCodeMirrors(key); + }); + $scope.$on('populated', function() { startCodeMirrors(); populateLDAPGroupType(); diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index d02dd41eef..49a5f2ad99 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -300,12 +300,16 @@ export default [ // after resetting the value. Example: $scope.$broadcast(key+'_populated', null, false); } - if($scope[key + '_field'].reset === "CUSTOM_LOGO"){ + else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){ $scope.$broadcast(key+'_reverted'); } - if($scope[key + '_field'].type === "textarea" && _.isArray($scope.configDataResolve[key].default)){ + 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] = '{}'; + $scope.$broadcast('codeMirror_populated', key); + } loginUpdate(); }) .catch(function(error) {