From 7c8bacc7e883ce8ce870299d813d805c76b14bd1 Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 11 May 2011 15:53:29 +0200 Subject: [PATCH] better sorting in DocPanel --- source/Ox.UI/js/Core/Ox.DocPanel.js | 17 +++++++++++++++++ source/Ox.UI/js/List/Ox.TreeList.js | 9 +++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/source/Ox.UI/js/Core/Ox.DocPanel.js b/source/Ox.UI/js/Core/Ox.DocPanel.js index ba5d4e52..b1ad9716 100644 --- a/source/Ox.UI/js/Core/Ox.DocPanel.js +++ b/source/Ox.UI/js/Core/Ox.DocPanel.js @@ -96,6 +96,13 @@ Ox.DocPanel = function(options, self) { title: docItem.name }); }); + treeItems.sort(sortByTitle); + treeItems.forEach(function(item) { + item.items.sort(sortByTitle); + item.items.forEach(function(subitem) { + subitem.items.sort(sortByTitle); + }) + }); self.$list = Ox.TreeList({ items: treeItems, width: self.options.width @@ -128,6 +135,16 @@ Ox.DocPanel = function(options, self) { } } + function sortByTitle(a, b) { + var ret = 0; + if (a.title < b.title) { + ret = -1; + } else if (a.title > b.title) { + ret = 1; + } + return ret; + } + return that; }; \ No newline at end of file diff --git a/source/Ox.UI/js/List/Ox.TreeList.js b/source/Ox.UI/js/List/Ox.TreeList.js index 71a0e1ba..257cc145 100644 --- a/source/Ox.UI/js/List/Ox.TreeList.js +++ b/source/Ox.UI/js/List/Ox.TreeList.js @@ -160,8 +160,7 @@ Ox.TreeList = function(options, self) { function toggleItem(item, expanded) { var $img, pos; item.expanded = expanded; - getItemById(item.id).expanded = expanded; - Ox.print('>>>>', getItemById(item.id)) + //getItemById(item.id).expanded = expanded; $.each(that.$element.find('.OxItem'), function(i, v) { var $item = $(v); if ($item.data('id') == item.id) { @@ -170,15 +169,13 @@ Ox.TreeList = function(options, self) { return false; } }); - ///* $img.attr({ src: Ox.UI.getImagePath( - 'symbol' + (item.expanded ? 'Down' : 'Right') + '.svg' + 'symbol' + (expanded ? 'Down' : 'Right') + '.svg' ) }); - //*/ that.$element.value(item.id, 'expanded', expanded); - item.expanded ? + expanded ? that.$element.addItems(pos + 1, parseItems(item.items, item.level + 1)) : that.$element.removeItems(pos + 1, parseItems(item.items, item.level + 1).length); }