expand TreeList selecting an item

This commit is contained in:
j 2011-12-29 17:54:29 +05:30
parent 1a7a5985d9
commit 7831dcd77d
2 changed files with 34 additions and 4 deletions

View file

@ -125,8 +125,7 @@ Ox.DocPanel = function(options, self) {
}); });
self.$list = Ox.TreeList({ self.$list = Ox.TreeList({
items: treeItems, items: treeItems,
//fixme causes strange layout width: self.options.size - Ox.UI.SCROLLBAR_SIZE
//width: self.options.size
}) })
.bindEvent({ .bindEvent({
select: selectItem select: selectItem
@ -185,7 +184,7 @@ Ox.DocPanel = function(options, self) {
@*/ @*/
that.selectItem = function(id) { that.selectItem = function(id) {
self.$list.triggerEvent('select', {'ids': [id]}); self.$list.triggerEvent('select', {'ids': [id]});
} };
return that; return that;
}; };

View file

@ -31,7 +31,10 @@ Ox.TreeList = function(options, self) {
selected: [], selected: [],
width: 256 width: 256
}) })
.options(options || {}); .options(options || {})
.bindEvent({
select: selectItem
});
if (self.options.data) { if (self.options.data) {
self.options.items = []; self.options.items = [];
@ -134,6 +137,23 @@ Ox.TreeList = function(options, self) {
return ret; return ret;
} }
function getParent(id, items) {
var ret;
Ox.forEach(items, function(item) {
if(item.items) {
if(Ox.getObjectById(item.items, id)) {
ret = item.id;
} else {
ret = getParent(id, item.items);
}
if(ret) {
return false;
}
}
});
return ret;
}
function parseData(key, value) { function parseData(key, value) {
//Ox.Log('List', 'parseData', key, value) //Ox.Log('List', 'parseData', key, value)
var ret = { var ret = {
@ -178,6 +198,17 @@ Ox.TreeList = function(options, self) {
return ret; return ret;
} }
function selectItem(data) {
var id = data.ids[0], parent = id, parents=[];
while(parent = getParent(parent, self.options.items)) {
parents.push(parent);
}
parents = parents.reverse();
toggleItems({
expanded: true,
ids: parents
});
}
function toggleItem(item, expanded) { function toggleItem(item, expanded) {
var $img, pos; var $img, pos;
item.expanded = expanded; item.expanded = expanded;