1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Adds ability for parent controller to call atCodeMirror's init() function.

This enables the parent controller to re-instantiate the CodeMirror instance
on the fly, when necessary. This was necessary on the NetworkUI to update the
CodeMirror instance on the Host Detail panel.
This commit is contained in:
Jared Tabor 2018-04-20 17:14:18 -07:00
parent 19ebaa6916
commit 0b4d88a57d
3 changed files with 16 additions and 7 deletions

View File

@ -1,6 +1,5 @@
const templateUrl = require('~components/code-mirror/code-mirror.partial.html');
const CodeMirrorEventListener = 'CodeMirror-init';
const CodeMirrorID = 'codemirror-extra-vars';
const CodeMirrorModalID = '#CodeMirror-modal';
const ParseVariable = 'parseType';
@ -43,10 +42,10 @@ function atCodeMirrorController (
vm.expanded = false;
vm.close = close;
vm.expand = expand;
if ($scope.init) {
$scope.init = init;
}
init($scope.variables);
$scope.$on(CodeMirrorEventListener, (e, vars) => {
init(vars);
});
}
atCodeMirrorController.$inject = [
@ -70,7 +69,8 @@ function atCodeMirrorTextarea () {
labelClass: '@',
tooltip: '@',
tooltipPlacement: '@',
variables: '@'
variables: '@',
init: '='
}
};
}

View File

@ -8,6 +8,12 @@
['$scope', 'HostsService',
function($scope, HostsService){
function codemirror () {
return {
init:{}
};
}
$scope.codeMirror = new codemirror();
$scope.formCancel = function(){
$scope.$parent.$broadcast('awxNet-closeDetailsPanel');
};
@ -38,6 +44,8 @@
} else {
$scope.item = data;
}
$scope.$broadcast('CodeMirror-init', $scope.item.variables);
if ($scope.codeMirror.init) {
$scope.codeMirror.init($scope.item.variables);
}
});
}];

View File

@ -34,7 +34,8 @@
<at-code-mirror
disabled="true"
variables="{{ item.variables }}"
tooltip-placement="left">
tooltip-placement="left"
init="codeMirror.init">
</at-code-mirror>
</div>
</form>