From c615da32fb2862c4b6a4e7d02d379ac9a2be09db Mon Sep 17 00:00:00 2001 From: Rolux Date: Wed, 30 Jun 2010 13:09:45 +0200 Subject: [PATCH] make list preserve selection after reload --- build/js/ox.ui.js | 55 +++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 5e73780..d6d8234 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -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 })); - } - $.extend(self, { - $items: [], - $pages: [], - ids: {}, - page: 0, - selected: [] - }); - that.$content.empty(); - that.scrollTop(0); - loadPages(self.page); + } else { + callback(); + } + + 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) {