make list preserve selection after reload

This commit is contained in:
Rolux 2010-06-30 12:39:49 +02:00
parent de422b8faa
commit 5790a5695e
3 changed files with 31 additions and 9 deletions

View file

@ -560,6 +560,7 @@ Lists
} }
.OxTextList .OxBody .OxItem { .OxTextList .OxBody .OxItem {
height: 16px; height: 16px;
cursor: default;
} }
.OxTextList .OxBody .OxItem .OxCell { .OxTextList .OxBody .OxItem .OxCell {
float: left; float: left;

View file

@ -2391,6 +2391,7 @@ requires
$.extend(self, { $.extend(self, {
$items: [], $items: [],
$pages: [], $pages: [],
ids: {},
page: 0, page: 0,
pageLength: 100, pageLength: 100,
requests: [], requests: [],
@ -2399,6 +2400,7 @@ requires
self.options.request({ self.options.request({
callback: function(result) { callback: function(result) {
Ox.print("items", result.data.items);
$.extend(self, { $.extend(self, {
listHeight: result.data.items * self.options.itemHeight, listHeight: result.data.items * self.options.itemHeight,
listLength: result.data.items, listLength: result.data.items,
@ -2408,7 +2410,6 @@ requires
pageHeight: self.options.orientation == "horizontal" ? 0 : pageHeight: self.options.orientation == "horizontal" ? 0 :
self.pageLength * self.options.itemHeight / self.options.rowLength self.pageLength * self.options.itemHeight / self.options.rowLength
}); });
Ox.print("listHeight", self.listHeight)
that.$content.css({ that.$content.css({
height: self.listHeight + "px" height: self.listHeight + "px"
}); });
@ -2499,7 +2500,7 @@ requires
function getNext() { function getNext() {
var pos = -1; var pos = -1;
if (self.selected.length) { if (self.selected.length) {
var pos = Ox.max(self.selected) + 1; pos = Ox.max(self.selected) + 1;
if (pos == self.$items.length) { if (pos == self.$items.length) {
pos = -1; pos = -1;
} }
@ -2516,7 +2517,7 @@ requires
function getPrevious() { function getPrevious() {
var pos = -1; var pos = -1;
if (self.selected.length) { if (self.selected.length) {
var pos = Ox.min(self.selected) - 1; pos = Ox.min(self.selected) - 1;
} }
return pos; return pos;
} }
@ -2533,7 +2534,7 @@ requires
function loadPage(page, callback) { function loadPage(page, callback) {
Ox.print("loadPage", page) Ox.print("loadPage", page)
if (page < 0 || page >= self.pages) { if (page < 0 || page >= self.pages) { // fixme: callback doesn't get called
return; return;
} }
var keys = $.inArray("id", self.options.keys) > -1 ? self.options.keys : var keys = $.inArray("id", self.options.keys) > -1 ? self.options.keys :
@ -2562,13 +2563,14 @@ requires
data: v, data: v,
position: pos position: pos
}); });
self.ids[pos] = v.id;
if (isSelected(pos)) { if (isSelected(pos)) {
self.$items[pos].addClass("OxSelected"); self.$items[pos].addClass("OxSelected");
} }
self.$items[pos].appendTo(self.$pages[page]) self.$items[pos].appendTo(self.$pages[page]);
}); });
self.$pages[page].appendTo(that.$content); self.$pages[page].appendTo(that.$content);
Ox.print(page, "self.$pages", self.$pages) callback();
}, },
keys: keys, keys: keys,
range: range, range: range,
@ -2698,10 +2700,29 @@ requires
Ox.Request.cancel(v); Ox.Request.cancel(v);
}); });
self.requests = []; self.requests = [];
//unloadPages(self.page); if (self.selected.length) {
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);
});
},
ids: $.map(self.selected, function(v, i) {
return self.ids[v];
}),
sort: self.options.sort
}));
}
$.extend(self, { $.extend(self, {
$items: [], $items: [],
$pages: [], $pages: [],
ids: {},
page: 0, page: 0,
selected: [] selected: []
}); });
@ -2716,7 +2737,7 @@ requires
key: key, key: key,
operator: operator operator: operator
} }
// trigger sort event // fixme: trigger sort event here
that.reload(); that.reload();
} }
} }

View file

@ -39,7 +39,7 @@ $(function() {
id: "id", id: "id",
operator: "+", operator: "+",
title: "ID", title: "ID",
visible: false, visible: true,
width: 80 width: 80
}, },
{ {