make list preserve selection after reload
This commit is contained in:
parent
5790a5695e
commit
8dc0c02dfb
1 changed files with 32 additions and 23 deletions
|
@ -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,39 +2694,50 @@ 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 {
|
||||||
$.extend(self, {
|
callback();
|
||||||
$items: [],
|
}
|
||||||
$pages: [],
|
|
||||||
ids: {},
|
function callback(result) {
|
||||||
page: 0,
|
if (result) {
|
||||||
selected: []
|
$.extend(self, {
|
||||||
});
|
ids: {},
|
||||||
that.$content.empty();
|
selected: []
|
||||||
that.scrollTop(0);
|
});
|
||||||
loadPages(self.page);
|
$.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) {
|
that.sort = function(key, operator) {
|
||||||
|
|
Loading…
Reference in a new issue