diff --git a/source/Ox.UI/js/Core/Ox.DocPanel.js b/source/Ox.UI/js/Core/Ox.DocPanel.js index 7240cce4..53193e2f 100644 --- a/source/Ox.UI/js/Core/Ox.DocPanel.js +++ b/source/Ox.UI/js/Core/Ox.DocPanel.js @@ -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; }; diff --git a/source/Ox.UI/js/List/Ox.TreeList.js b/source/Ox.UI/js/List/Ox.TreeList.js index 05b867a1..1c9c0fba 100644 --- a/source/Ox.UI/js/List/Ox.TreeList.js +++ b/source/Ox.UI/js/List/Ox.TreeList.js @@ -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;