fixing reset for CodeMirror instances

This commit is contained in:
jaredevantabor
2017-02-21 17:51:10 -08:00
parent 331be6c803
commit 63f27a120f
2 changed files with 38 additions and 19 deletions

View File

@@ -171,26 +171,37 @@ export default [
form.buttons.save.disabled = $rootScope.user_is_system_auditor; form.buttons.save.disabled = $rootScope.user_is_system_auditor;
}); });
function startCodeMirrors(){ function startCodeMirrors(key){
// Attach codemirror to fields that need it
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){ let form = _.find(authForms, function(form){
return form.name === $scope.authVm.activeAuthForm; return form.name === $scope.authVm.activeAuthForm;
}); });
_.each(form.formDef.fields, function(field) {
// Codemirror balks at empty values so give it one if(!key){
if($scope.$parent[field.name] === null && field.codeMirror) { // Attach codemirror to fields that need it
$scope.$parent[field.name] = '{}'; _.each(form.formDef.fields, function(field) {
} // Codemirror balks at empty values so give it one
if(field.codeMirror) { if($scope.$parent[field.name] === null && field.codeMirror) {
ParseTypeChange({ $scope.$parent[field.name] = '{}';
scope: $scope.$parent, }
variable: field.name, if(field.codeMirror) {
parse_variable: 'parseType', createIt(field.name)
field_id: form.formDef.name + '_' + field.name }
}); });
$scope.parseTypeChange('parseType', field.name); }
} else if(key){
}); createIt(key);
}
} }
function addFieldInfo(form, key) { function addFieldInfo(form, key) {
@@ -252,6 +263,10 @@ export default [
populateLDAPGroupType(flag); populateLDAPGroupType(flag);
}); });
$scope.$on('codeMirror_populated', function(e, key) {
startCodeMirrors(key);
});
$scope.$on('populated', function() { $scope.$on('populated', function() {
startCodeMirrors(); startCodeMirrors();
populateLDAPGroupType(); populateLDAPGroupType();

View File

@@ -300,12 +300,16 @@ export default [
// after resetting the value. Example: // after resetting the value. Example:
$scope.$broadcast(key+'_populated', null, false); $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'); $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); $scope[key] = ConfigurationUtils.arrayToList($scope[key], key);
} }
else if($scope[key + '_field'].hasOwnProperty('codeMirror')){
$scope[key] = '{}';
$scope.$broadcast('codeMirror_populated', key);
}
loginUpdate(); loginUpdate();
}) })
.catch(function(error) { .catch(function(error) {