[Tree] Begin wiring in selection

This commit is contained in:
Victor Woeltjen 2016-03-11 17:09:17 -08:00
parent 03ab3bddc4
commit 82b6166408
3 changed files with 18 additions and 4 deletions
platform/commonUI/general
res/templates
src

@ -19,6 +19,6 @@
this source code distribution or the Licensing information page available
at runtime from the About dialog for additional information.
-->
<mct-tree mct-object="domainObject">
<mct-tree mct-object="domainObject" mct-model="ngModel.selectedObject">
</mct-tree>

@ -25,13 +25,17 @@ define([
'angular',
'../ui/TreeView'
], function (angular, TreeView) {
function MCTTree() {
function link(scope, element) {
var treeView = new TreeView();
function MCTTree($parse) {
function link(scope, element, attrs) {
var treeView = new TreeView(),
expr = $parse(attrs.mctModel),
unobserve = treeView.observe(expr.assign.bind(expr, scope));
element.append(angular.element(treeView.elements()));
scope.$parent.$watch(attrs.mctModel, treeView.value.bind(treeView));
scope.$watch('mctObject', treeView.model.bind(treeView));
scope.$on('$destroy', unobserve);
}
return {

@ -103,6 +103,16 @@ define([
});
};
TreeView.prototype.observe = function (callback) {
callback(this.selectedObject);
this.callbacks.push(callback);
return function () {
this.callbacks = this.callbacks.filter(function (c) {
return c !== callback;
});
}.bind(this);
};
/**
*
* @returns {HTMLElement[]}