diff --git a/platform/commonUI/general/res/templates/subtree.html b/platform/commonUI/general/res/templates/subtree.html index df16327e8c..abc7a0d34a 100644 --- a/platform/commonUI/general/res/templates/subtree.html +++ b/platform/commonUI/general/res/templates/subtree.html @@ -19,6 +19,6 @@ this source code distribution or the Licensing information page available at runtime from the About dialog for additional information. --> - + diff --git a/platform/commonUI/general/src/directives/MCTTree.js b/platform/commonUI/general/src/directives/MCTTree.js index fb0f63f956..29d2e00ba7 100644 --- a/platform/commonUI/general/src/directives/MCTTree.js +++ b/platform/commonUI/general/src/directives/MCTTree.js @@ -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 { diff --git a/platform/commonUI/general/src/ui/TreeView.js b/platform/commonUI/general/src/ui/TreeView.js index 6a4d7618f4..a0c635322e 100644 --- a/platform/commonUI/general/src/ui/TreeView.js +++ b/platform/commonUI/general/src/ui/TreeView.js @@ -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[]}