diff --git a/source/Ox.UI/js/List/Ox.List.js b/source/Ox.UI/js/List/Ox.List.js index 52df9392..ac74ec36 100644 --- a/source/Ox.UI/js/List/Ox.List.js +++ b/source/Ox.UI/js/List/Ox.List.js @@ -26,6 +26,7 @@ Ox.List List Element selected ids of the selected elements sort sort order sortable If true, items can be re-ordered + sums <[]|[]> sums to be included in totals type unique name of the key that acts as unique id self shared private variable @@ -68,12 +69,29 @@ Ox.List = function(options, self) { selected: [], sort: [], sortable: false, + sums: [], type: 'text', unique: '' }) .options(options || {}) .scroll(scroll); + self.options.sort = self.options.sort.map(function(sort) { + return Ox.isString(sort) ? { + key: sort.replace(/^[\+\-]/, ''), + operator: sort[0] == '-' ? '-' : '+' + } : sort; + }); + + if (Ox.isArray(self.options.items)) { + self.options.items = Ox.api(self.options.items, { + cache: true, + sort: self.options.sort, + sums: self.options.sums, + unique: self.options.unique + }); + } + that.$content.bindEvent({ mousedown: mousedown, singleclick: singleclick, @@ -103,7 +121,7 @@ Ox.List = function(options, self) { $items: [], $pages: [], format: {}, - isAsync: Ox.isFunction(self.options.items), + isAsync: true, itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later keyboardEvents: { key_control_c: copyItems, @@ -1384,15 +1402,20 @@ Ox.List = function(options, self) { //Ox.Log('List', 'list setOption', key, value); var previousSelected; if (key == 'items') { - // fixme: this could be used to change the list - // from sync to async or vice versa, which wouldn't work if (Ox.isArray(value)) { + self.options.items = Ox.api(self.options.items, { + cache: true, + sort: self.options.sort, + sums: self.options.sums, + unique: self.options.unique + }); + /* self.listLength = value.length; updateSelected(); updateSort(); - } else { - updateQuery(); + */ } + updateQuery(); } else if (key == 'selected') { previousSelected = self.selected; setSelected(value); diff --git a/source/Ox.UI/js/List/Ox.TextList.js b/source/Ox.UI/js/List/Ox.TextList.js index 87b9b082..70423312 100644 --- a/source/Ox.UI/js/List/Ox.TextList.js +++ b/source/Ox.UI/js/List/Ox.TextList.js @@ -37,8 +37,9 @@ Ox.TextList TextList Object pageLength Number of items per page scrollbarVisible If true, the scrollbar is always visible selected - sort + sort <[]|[]> sortable If true, elements can be re-ordered + sums <[]|[]> Sums to be included in totals self shared private variable @*/ @@ -68,7 +69,8 @@ Ox.TextList = function(options, self) { scrollbarVisible: false, selected: [], sort: [], - sortable: false + sortable: false, + sums: [] }) .options(options || {}) .addClass('OxTextList') @@ -86,6 +88,13 @@ Ox.TextList = function(options, self) { keys: find }); + self.options.sort = self.options.sort.map(function(sort) { + return Ox.isString(sort) ? { + key: sort.replace(/^[\+\-]/, ''), + operator: sort[0] == '-' ? '-' : '+' + } : sort; + }); + self.options.columns.forEach(function(column) { // fixme: can this go into a generic ox.js function? // fixme: and can't these just remain undefined? if (Ox.isUndefined(column.align)) { @@ -208,6 +217,7 @@ Ox.TextList = function(options, self) { selected: self.options.selected, sort: self.options.sort, sortable: self.options.sortable, + sums: self.options.sums, type: 'text', unique: self.unique }, Ox.clone(self)) // pass event handler diff --git a/source/Ox.UI/js/Map/Ox.Map.js b/source/Ox.UI/js/Map/Ox.Map.js index bba3deed..826499e0 100644 --- a/source/Ox.UI/js/Map/Ox.Map.js +++ b/source/Ox.UI/js/Map/Ox.Map.js @@ -207,7 +207,10 @@ Ox.Map = function(options, self) { place.id = Ox.encodeBase32(Ox.uid()); } }); - self.options.places = Ox.api(self.options.places, {geo: true}); + self.options.places = Ox.api(self.options.places, { + geo: true, + sort: '-area' + }); } self.mapHeight = getMapHeight(); diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index 74401ed3..cd88681c 100644 --- a/source/Ox/js/Array.js +++ b/source/Ox/js/Array.js @@ -173,6 +173,7 @@ Ox.api = function(items, options) { data.items = result.data.items.length; if (api.geo) { /* + fixme: slow, disabled data.area = Ox.joinAreas(result.data.items.map(function(item) { return { sw: {lat: item.south, lng: item.west},