make list preserve selection after reload

This commit is contained in:
Rolux 2010-06-30 13:09:45 +02:00
parent 389f65a4d8
commit c615da32fb

View File

@ -2377,7 +2377,6 @@ requires
itemHeight: 16,
itemWidth: 16,
keys: [],
listLength: 0,
orientation: "vertical",
request: function() {}, // {sort:, range:, callback:}, without parameter returns {items, size etc.}
rowLength: 1,
@ -2542,7 +2541,6 @@ requires
offset = page * self.pageLength,
range = [offset, offset + (page < self.pages - 1 ?
self.pageLength : self.listLength % self.pageLength)];
Ox.print("keys", keys)
if (Ox.isUndefined(self.$pages[page])) {
self.requests.push(self.options.request({
callback: function(result) {
@ -2696,39 +2694,50 @@ requires
};
that.reload = function() {
$.each(self.requests, function(i, v) {
Ox.Request.cancel(v);
});
self.requests = [];
if (self.selected.length) {
$.extend(self, {
$items: [],
$pages: [],
page: 0,
requests: []
});
// fixme: optimize: send non-selected ids if more than half of the items are selected
Ox.print(self.selected.length, self.listLength);
if (self.selected.length && self.selected.length < self.listLength) {
Ox.print("sort", self.options.sort, "ids", $.map(self.selected, function(v, i) {
return self.ids[v];
}));
self.requests.push(self.options.request({
callback: function(result) {
self.selected = [];
$.each(result.data.positions, function(id, pos) {
Ox.print("id", id, "pos", pos)
self.selected.push(pos);
addToSelection(pos);
});
},
callback: callback,
ids: $.map(self.selected, function(v, i) {
return self.ids[v];
}),
sort: self.options.sort
}));
} else {
callback();
}
$.extend(self, {
$items: [],
$pages: [],
ids: {},
page: 0,
selected: []
});
that.$content.empty();
that.scrollTop(0);
loadPages(self.page);
function callback(result) {
if (result) {
$.extend(self, {
ids: {},
selected: []
});
$.each(result.data.positions, function(id, pos) {
Ox.print("id", id, "pos", pos)
self.selected.push(pos);
});
}
that.$content.empty();
that.scrollTop(0);
loadPages(self.page);
}
}
that.sort = function(key, operator) {