From 85a058d7acb86f2b3e9e19e3be55c829112940cb Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 22 Dec 2012 01:20:37 +0100 Subject: [PATCH] refactoring --- source/Ox.UI/js/List/ColumnList.js | 65 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/source/Ox.UI/js/List/ColumnList.js b/source/Ox.UI/js/List/ColumnList.js index 31e749fd..ad9fc306 100644 --- a/source/Ox.UI/js/List/ColumnList.js +++ b/source/Ox.UI/js/List/ColumnList.js @@ -52,7 +52,7 @@ Ox.ColumnList = function(options, self) { return Ox.CustomList({ item: self.options.columns[i].item, itemHeight: self.options.columns[i].itemHeight, - items: i == 0 ? self.options.items : [], + items: getItems(i), itemWidth: self.columnWidths[i], keys: self.options.columns[i].keys, // FIXME: undefined max will overwrite CustomList default @@ -89,35 +89,9 @@ Ox.ColumnList = function(options, self) { } }, select: function(data) { - var items = []; self.options.columns[i].selected = data.ids; if (i < self.numberOfColumns - 1) { - data.ids.forEach(function(id) { - var index; - if (i == 0) { - index = Ox.getIndexById(self.options.items, id); - items = items.concat( - self.options.items[index].items - ); - } else if (i == 1) { - index = []; - Ox.forEach(self.options.columns[0].selected, function(id_) { - index[0] = Ox.getIndexById( - self.options.items, id_ - ); - index[1] = Ox.getIndexById( - self.options.items[index[0]].items, id - ); - if (index[1] > -1) { - return false; - } - }); - items = items.concat( - self.options.items[index[0]].items[index[1]].items - ); - } - }); - self.$lists[i + 1].options({items: items}) + self.$lists[i + 1].options({items: getItems(i + 1)}); } if (i == 0 || data.ids.length) { that.triggerEvent('select', { @@ -151,6 +125,41 @@ Ox.ColumnList = function(options, self) { return Ox.splitInt(self.options.width, 3); } + function getItems(i) { + var items; + if (i == 0) { + items = self.options.items; + } else { + items = []; + self.options.columns[i - 1].selected.forEach(function(id) { + var index; + if (i == 1) { + index = Ox.getIndexById(self.options.items, id); + items = items.concat( + self.options.items[index].items + ); + } else if (i == 2) { + index = []; + Ox.forEach(self.options.columns[0].selected, function(id_) { + index[0] = Ox.getIndexById( + self.options.items, id_ + ); + index[1] = Ox.getIndexById( + self.options.items[index[0]].items, id + ); + if (index[1] > -1) { + return false; + } + }); + items = items.concat( + self.options.items[index[0]].items[index[1]].items + ); + } + }); + } + return items; + } + function updateQuery() { if (self.options.query.conditions.length == 0) { self.items = self.options.items;