[Tree] Begin handling selection state

This commit is contained in:
Victor Woeltjen
2016-03-11 17:00:55 -08:00
parent 4a8222a152
commit 03ab3bddc4
3 changed files with 50 additions and 4 deletions

View File

@ -76,6 +76,36 @@ define([
}
};
TreeNodeView.prototype.value = function (domainObject) {
var activeIdPath = getIdPath(this.activeObject),
selectedIdPath = getIdPath(domainObject);
if (this.onSelectionPath) {
this.li.find('.tree-item').eq(0).removeClass('selected');
if (this.subtreeView) {
this.subtreeView.value(undefined);
}
}
this.onSelectionPath =
!!domainObject &&
!!this.activeObject &&
(activeIdPath.length <= selectedIdPath.length) &&
activeIdPath.every(function (id, index) {
return selectedIdPath[index] === id;
});
if (this.onSelectionPath) {
if (activeIdPath.length === selectedIdPath.length) {
this.li.find('.tree-item').eq(0).addClass('selected');
} else {
// Expand to reveal the selection
this.toggleView.value(true);
this.subtreeView.value(domainObject);
}
}
};
/**
*
* @returns {HTMLElement[]}
@ -86,4 +116,4 @@ define([
return TreeNodeView;
});
});