expand TreeList selecting an item
This commit is contained in:
parent
1a7a5985d9
commit
7831dcd77d
2 changed files with 34 additions and 4 deletions
|
@ -125,8 +125,7 @@ Ox.DocPanel = function(options, self) {
|
|||
});
|
||||
self.$list = Ox.TreeList({
|
||||
items: treeItems,
|
||||
//fixme causes strange layout
|
||||
//width: self.options.size
|
||||
width: self.options.size - Ox.UI.SCROLLBAR_SIZE
|
||||
})
|
||||
.bindEvent({
|
||||
select: selectItem
|
||||
|
@ -185,7 +184,7 @@ Ox.DocPanel = function(options, self) {
|
|||
@*/
|
||||
that.selectItem = function(id) {
|
||||
self.$list.triggerEvent('select', {'ids': [id]});
|
||||
}
|
||||
};
|
||||
return that;
|
||||
|
||||
};
|
||||
|
|
|
@ -31,7 +31,10 @@ Ox.TreeList = function(options, self) {
|
|||
selected: [],
|
||||
width: 256
|
||||
})
|
||||
.options(options || {});
|
||||
.options(options || {})
|
||||
.bindEvent({
|
||||
select: selectItem
|
||||
});
|
||||
|
||||
if (self.options.data) {
|
||||
self.options.items = [];
|
||||
|
@ -134,6 +137,23 @@ Ox.TreeList = function(options, self) {
|
|||
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) {
|
||||
//Ox.Log('List', 'parseData', key, value)
|
||||
var ret = {
|
||||
|
@ -178,6 +198,17 @@ Ox.TreeList = function(options, self) {
|
|||
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) {
|
||||
var $img, pos;
|
||||
item.expanded = expanded;
|
||||
|
|
Loading…
Reference in a new issue