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

View File

@ -8,6 +8,12 @@
['$scope', 'HostsService', ['$scope', 'HostsService',
function($scope, HostsService){ function($scope, HostsService){
function codemirror () {
return {
init:{}
};
}
$scope.codeMirror = new codemirror();
$scope.formCancel = function(){ $scope.formCancel = function(){
$scope.$parent.$broadcast('awxNet-closeDetailsPanel'); $scope.$parent.$broadcast('awxNet-closeDetailsPanel');
}; };
@ -38,6 +44,8 @@
} else { } else {
$scope.item = data; $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 <at-code-mirror
disabled="true" disabled="true"
variables="{{ item.variables }}" variables="{{ item.variables }}"
tooltip-placement="left"> tooltip-placement="left"
init="codeMirror.init">
</at-code-mirror> </at-code-mirror>
</div> </div>
</form> </form>