Ox.ColumnList: implement query

This commit is contained in:
rolux 2012-12-18 15:05:47 +01:00
parent e5e93d8e12
commit 8c941edd03

View file

@ -14,11 +14,13 @@ Ox.ColumnList = function(options, self) {
custom: {},
items: [],
list: 'table',
query: {conditions: [], operator: '&'},
resize: null,
width: 768
})
.options(options || {})
.update({
query: updateQuery,
width: function() {
self.columnWidths = getColumnWidths();
self.$panel.size(0, self.columnWidths[0]);
@ -33,8 +35,20 @@ Ox.ColumnList = function(options, self) {
self.columnWidths = getColumnWidths();
self.numberOfColumns = self.options.columns.length;
self.flatItems = [];
self.ids = [{}, {}, {}];
self.options.items.forEach(function(item0) {
item0.items.forEach(function(item1) {
self.ids[1][item1.id] = [item0.id];
item1.items.forEach(function(item2) {
self.ids[2][item2.id] = [item0.id, item1.id];
self.flatItems.push(item2);
});
});
});
self.api = Ox.api(self.flatItems);
self.$lists = self.options.columns.map(function(column, i) {
//Ox.print('SELECTED::', self.options.selected[i]);
return Ox.CustomList({
item: self.options.columns[i].item,
itemHeight: self.options.columns[i].itemHeight,
@ -136,6 +150,40 @@ Ox.ColumnList = function(options, self) {
return Ox.splitInt(self.options.width, 3);
}
function updateQuery() {
if (self.options.query.conditions.length == 0) {
self.items = self.options.items;
} else {
self.api({
keys: ['id', '_ids'],
query: self.options.query
}, function(result) {
var ids = [[], [], []];
result.data.items.forEach(function(item) {
ids[0].push(self.ids[2][item.id][0]);
ids[1].push(self.ids[2][item.id][1]);
ids[2].push(item.id);
});
self.items = self.options.items.filter(function(item0) {
return Ox.contains(ids[0], item0.id);
});
self.items.forEach(function(item0) {
item0.items = item0.items.filter(function(item1) {
return Ox.contains(ids[1], item1.id);
});
item0.items.forEach(function(item1) {
item1.items = item1.items.filter(function(item2) {
return Ox.contains(ids[2], item2.id);
});
});
});
});
}
self.$lists.forEach(function($list, i) {
$list.options({items: i == 0 ? self.items : []});
});
}
return that;
};