diff --git a/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js b/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js
index 0315485ee4..555b9579a4 100644
--- a/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js
+++ b/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js
@@ -1,58 +1,57 @@
const templateUrl = require('~components/code-mirror/code-mirror.partial.html');
const CodeMirrorModalID = '#CodeMirror-modal';
-const ParseVariable = 'parseType';
const ParseType = 'yaml';
function atCodeMirrorController (
$scope,
strings,
- ParseTypeChange,
- ParseVariableString
+ ParseTypeChange
) {
const vm = this;
- const variablesName = `${$scope.name}_variables`;
- function init (vars, name) {
- console.log('init', $scope, vars);
+ function init () {
if ($scope.disabled === 'true') {
$scope.disabled = true;
} else if ($scope.disabled === 'false') {
$scope.disabled = false;
}
- $scope.variablesName = variablesName;
- // $scope[variablesName] = ParseVariableString(_.cloneDeep(vars));
- $scope.variables = {
- value: ParseVariableString(_.cloneDeep(vars)),
- };
$scope.value = $scope.variables.value;
$scope.parseType = ParseType;
- const options = {
+
+ ParseTypeChange({
scope: $scope,
- variable: 'value', // variablesName,
- parse_variable: ParseVariable,
- field_id: name,
- readOnly: $scope.disabled,
- onChange: (value) => {
- console.log('change', value);
- },
- };
- ParseTypeChange(options);
+ variable: 'variables',
+ parse_variable: 'parseType',
+ field_id: `${$scope.name}_variables`,
+ readOnly: $scope.disabled
+ });
}
function expand () {
vm.expanded = true;
}
- function close () {
+ function close (varsFromModal) {
+ // TODO: make sure that the variables format matches
+ // parseType before re-initializing CodeMirror. Ex)
+ // user changes the format from yaml to json in the
+ // modal but CM in the form is set to YAML
+ $scope.variables = varsFromModal;
+ // New set of variables from the modal, reinit codemirror
+ ParseTypeChange({
+ scope: $scope,
+ variable: 'variables',
+ parse_variable: 'parseType',
+ field_id: `${$scope.name}_variables`,
+ readOnly: $scope.disabled
+ });
$(CodeMirrorModalID).off('hidden.bs.modal');
$(CodeMirrorModalID).modal('hide');
$('.popover').popover('hide');
vm.expanded = false;
}
- // vm.variablesName = variablesName;
vm.name = $scope.name;
- vm.modalName = `${vm.name}_modal`;
vm.strings = strings;
vm.expanded = false;
vm.close = close;
@@ -68,8 +67,7 @@ function atCodeMirrorController (
atCodeMirrorController.$inject = [
'$scope',
'CodeMirrorStrings',
- 'ParseTypeChange',
- 'ParseVariableString'
+ 'ParseTypeChange'
];
function atCodeMirrorTextarea () {
@@ -86,7 +84,7 @@ function atCodeMirrorTextarea () {
labelClass: '@',
tooltip: '@',
tooltipPlacement: '@',
- variables: '@',
+ variables: '=',
name: '@',
init: '='
}
diff --git a/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html b/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html
index 97572159f5..da1f492139 100644
--- a/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html
+++ b/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html
@@ -23,7 +23,7 @@
type="radio"
value="yaml"
ng-model="parseType"
- ng-change="parseTypeChange('parseType', vm.variables)"
+ ng-change="parseTypeChange('parseType', 'variables')"
class="ng-pristine ng-untouched ng-valid ng-not-empty">
{{ vm.strings.get('label.YAML')}}
@@ -32,7 +32,7 @@
type="radio"
value="json"
ng-model="parseType"
- ng-change="parseTypeChange('parseType', vm.variables)"
+ ng-change="parseTypeChange('parseType', 'variables')"
class="ng-pristine ng-untouched ng-valid ng-not-empty">
{{ vm.strings.get('label.JSON')}}
@@ -44,18 +44,18 @@