mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
[Tree] Change selection on click
This commit is contained in:
parent
217e697079
commit
a3a9393d1b
@ -29,7 +29,8 @@ define([
|
||||
function link(scope, element, attrs) {
|
||||
var treeView = new TreeView(),
|
||||
expr = $parse(attrs.mctModel),
|
||||
unobserve = treeView.observe(expr.assign.bind(expr, scope));
|
||||
assign = expr.assign.bind(expr, scope.$parent),
|
||||
unobserve = treeView.observe(assign);
|
||||
|
||||
element.append(angular.element(treeView.elements()));
|
||||
|
||||
|
@ -29,7 +29,7 @@ define([
|
||||
], function ($, nodeTemplate, ToggleView, TreeLabelView) {
|
||||
'use strict';
|
||||
|
||||
function TreeNodeView(subtreeFactory) {
|
||||
function TreeNodeView(subtreeFactory, selectFn) {
|
||||
this.li = $('<li>');
|
||||
|
||||
this.toggleView = new ToggleView(false);
|
||||
@ -49,6 +49,10 @@ define([
|
||||
|
||||
this.labelView = new TreeLabelView();
|
||||
|
||||
$(this.labelView.elements()).on('click', function () {
|
||||
selectFn(this.activeObject);
|
||||
}.bind(this));
|
||||
|
||||
this.li.append($(nodeTemplate));
|
||||
this.li.find('span').eq(0)
|
||||
.append($(this.toggleView.elements()))
|
||||
@ -80,7 +84,7 @@ define([
|
||||
function getId(domainObject) {
|
||||
return domainObject.getId();
|
||||
}
|
||||
|
||||
|
||||
return domainObject ?
|
||||
domainObject.getCapability('context').getPath().map(getId) :
|
||||
[];
|
||||
|
@ -27,21 +27,25 @@ define([
|
||||
], function ($, TreeNodeView) {
|
||||
'use strict';
|
||||
|
||||
function TreeView() {
|
||||
function TreeView(selectFn) {
|
||||
this.ul = $('<ul class="tree"></ul>');
|
||||
this.nodeViews = [];
|
||||
this.callbacks = [];
|
||||
this.selectFn = selectFn || this.value.bind(this);
|
||||
}
|
||||
|
||||
function newTreeView() {
|
||||
return new TreeView();
|
||||
TreeView.prototype.newTreeView = function () {
|
||||
return new TreeView(this.selectFn);
|
||||
}
|
||||
|
||||
TreeView.prototype.setSize = function (sz) {
|
||||
var nodeView;
|
||||
|
||||
while (this.nodeViews.length < sz) {
|
||||
nodeView = new TreeNodeView(newTreeView);
|
||||
nodeView = new TreeNodeView(
|
||||
this.newTreeView.bind(this),
|
||||
this.selectFn
|
||||
);
|
||||
this.nodeViews.push(nodeView);
|
||||
this.ul.append($(nodeView.elements()));
|
||||
}
|
||||
@ -104,7 +108,6 @@ define([
|
||||
};
|
||||
|
||||
TreeView.prototype.observe = function (callback) {
|
||||
callback(this.selectedObject);
|
||||
this.callbacks.push(callback);
|
||||
return function () {
|
||||
this.callbacks = this.callbacks.filter(function (c) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user