[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

View File

@ -19,6 +19,6 @@
this source code distribution or the Licensing information page available this source code distribution or the Licensing information page available
at runtime from the About dialog for additional information. 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> </mct-tree>

View File

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

View File

@ -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[]} * @returns {HTMLElement[]}