From 389f65a4d81e6b547b3c21ad2ae6620db78d16f3 Mon Sep 17 00:00:00 2001 From: Rolux Date: Wed, 30 Jun 2010 12:39:49 +0200 Subject: [PATCH] make list preserve selection after reload --- build/css/ox.ui.css | 1 + build/js/ox.ui.js | 37 +++++++++++++++++++++++++++++-------- demos/test/list.js | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/build/css/ox.ui.css b/build/css/ox.ui.css index 1af5176..194bdcd 100644 --- a/build/css/ox.ui.css +++ b/build/css/ox.ui.css @@ -560,6 +560,7 @@ Lists } .OxTextList .OxBody .OxItem { height: 16px; + cursor: default; } .OxTextList .OxBody .OxItem .OxCell { float: left; diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index ea9bf58..5e73780 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -2391,6 +2391,7 @@ requires $.extend(self, { $items: [], $pages: [], + ids: {}, page: 0, pageLength: 100, requests: [], @@ -2399,6 +2400,7 @@ requires self.options.request({ callback: function(result) { + Ox.print("items", result.data.items); $.extend(self, { listHeight: result.data.items * self.options.itemHeight, listLength: result.data.items, @@ -2408,7 +2410,6 @@ requires pageHeight: self.options.orientation == "horizontal" ? 0 : self.pageLength * self.options.itemHeight / self.options.rowLength }); - Ox.print("listHeight", self.listHeight) that.$content.css({ height: self.listHeight + "px" }); @@ -2499,7 +2500,7 @@ requires function getNext() { var pos = -1; if (self.selected.length) { - var pos = Ox.max(self.selected) + 1; + pos = Ox.max(self.selected) + 1; if (pos == self.$items.length) { pos = -1; } @@ -2516,7 +2517,7 @@ requires function getPrevious() { var pos = -1; if (self.selected.length) { - var pos = Ox.min(self.selected) - 1; + pos = Ox.min(self.selected) - 1; } return pos; } @@ -2533,7 +2534,7 @@ requires function loadPage(page, callback) { Ox.print("loadPage", page) - if (page < 0 || page >= self.pages) { + if (page < 0 || page >= self.pages) { // fixme: callback doesn't get called return; } var keys = $.inArray("id", self.options.keys) > -1 ? self.options.keys : @@ -2562,13 +2563,14 @@ requires data: v, position: pos }); + self.ids[pos] = v.id; if (isSelected(pos)) { 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); - Ox.print(page, "self.$pages", self.$pages) + callback(); }, keys: keys, range: range, @@ -2698,10 +2700,29 @@ requires Ox.Request.cancel(v); }); 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, { $items: [], $pages: [], + ids: {}, page: 0, selected: [] }); @@ -2716,7 +2737,7 @@ requires key: key, operator: operator } - // trigger sort event + // fixme: trigger sort event here that.reload(); } } diff --git a/demos/test/list.js b/demos/test/list.js index 8a3af26..3d026d4 100644 --- a/demos/test/list.js +++ b/demos/test/list.js @@ -39,7 +39,7 @@ $(function() { id: "id", operator: "+", title: "ID", - visible: false, + visible: true, width: 80 }, {