make list preserve selection after reload

This commit is contained in:
Rolux 2010-06-30 13:09:45 +02:00
parent 5790a5695e
commit 8dc0c02dfb

View file

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