better sorting of geonames
This commit is contained in:
parent
6ad45105af
commit
32b2da184a
4 changed files with 49 additions and 19 deletions
|
@ -155,6 +155,18 @@ Ox.load.Geo = function(options, callback) {
|
|||
return country;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.reverseGeoname <f> Reverses a geoname
|
||||
@*/
|
||||
Ox.reverseGeoname = function(geoname) {
|
||||
return geoname
|
||||
.replace('Bonaire, Saint Eustatius and Saba', 'Bonaire Saint Eustatius and Saba')
|
||||
.split(', ')
|
||||
.reverse()
|
||||
.join(', ')
|
||||
.replace('Bonaire Saint Eustatius and Saba', 'Bonaire, Saint Eustatius and Saba');
|
||||
};
|
||||
|
||||
callback(true);
|
||||
|
||||
});
|
||||
|
|
|
@ -1227,20 +1227,25 @@ Ox.List = function(options, self) {
|
|||
setSelected(newSelectedIds);
|
||||
}
|
||||
|
||||
function updateSort(map) {
|
||||
function updateSort() {
|
||||
Ox.print('start sort')
|
||||
var key = self.options.sort[0].key,
|
||||
operator = self.options.sort[0].operator;
|
||||
operator = self.options.sort[0].operator,
|
||||
map = self.options.sort[0].map,
|
||||
sort = {};
|
||||
self.options.items.forEach(function(item) {
|
||||
sort[item.id] = map ? map(item[key]) : item[key];
|
||||
});
|
||||
if (self.listLength > 1) {
|
||||
if (Ox.isArray(self.options.items)) {
|
||||
self.options.items.sort(function(a, b) {
|
||||
var aValue = map ? map(a[key]) : a[key],
|
||||
bValue = map ? map(b[key]) : b[key],
|
||||
var aValue = sort[a.id],
|
||||
bValue = sort[b.id],
|
||||
ret = 0
|
||||
if (aValue < bValue) {
|
||||
return operator == '+' ? -1 : 1
|
||||
ret = operator == '+' ? -1 : 1
|
||||
} else if (aValue > bValue) {
|
||||
return operator == '+' ? 1 : -1;
|
||||
ret = operator == '+' ? 1 : -1;
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
|
@ -1266,6 +1271,9 @@ Ox.List = function(options, self) {
|
|||
} else if (key == 'selected') {
|
||||
Ox.print('setOption selected', value)
|
||||
setSelected(value);
|
||||
} else if (key == 'sort') {
|
||||
Ox.print('---sort---')
|
||||
updateSort();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1490,11 +1498,13 @@ Ox.List = function(options, self) {
|
|||
operator <s> +/- sort ascending or descending
|
||||
map <f> function that maps values to sort values
|
||||
@*/
|
||||
// fixme: this (and others) should be deprecated,
|
||||
// one should set options instead
|
||||
that.sortList = function(key, operator, map) {
|
||||
Ox.print('sortList', key, operator)
|
||||
Ox.print('sortList', key, operator, map)
|
||||
if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) {
|
||||
self.options.sort[0] = {key: key, operator: operator};
|
||||
updateSort(map);
|
||||
self.options.sort[0] = {key: key, operator: operator, map: map};
|
||||
updateSort();
|
||||
that.triggerEvent('sort', self.options.sort[0]);
|
||||
}
|
||||
return that;
|
||||
|
|
|
@ -13,8 +13,8 @@ Ox.TextList <f:Ox.Element> TextList Object
|
|||
format <f>
|
||||
id <s>
|
||||
removable <b>
|
||||
map <f> function that maps values to sort values
|
||||
operator <s> default sort operator
|
||||
sort <f> function that maps values to sort values
|
||||
title <s>
|
||||
unique <b> If true, this column acts as unique id
|
||||
visible <b>
|
||||
|
@ -254,11 +254,15 @@ Ox.TextList = function(options, self) {
|
|||
Ox.print('clickColumn', id);
|
||||
var i = getColumnIndexById(id),
|
||||
isSelected = self.options.sort[0].key == self.options.columns[i].id;
|
||||
that.sortList(
|
||||
self.options.columns[i].id, isSelected ?
|
||||
(self.options.sort[0].operator == '+' ? '-' : '+') :
|
||||
self.options.columns[i].operator
|
||||
);
|
||||
that.$body.options({
|
||||
sort: [{
|
||||
key: self.options.columns[i].id,
|
||||
operator: isSelected ?
|
||||
(self.options.sort[0].operator == '+' ? '-' : '+') :
|
||||
self.options.columns[i].operator,
|
||||
map: self.options.columns[i].map
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function constructHead() {
|
||||
|
@ -729,7 +733,11 @@ Ox.TextList = function(options, self) {
|
|||
|
||||
that.sortList = function(key, operator) {
|
||||
var isSelected = key == self.options.sort[0].key;
|
||||
self.options.sort = [{key: key, operator: operator}];
|
||||
self.options.sort = [{
|
||||
key: key,
|
||||
operator: operator,
|
||||
map: self.options.columns[self.selectedColumn].sort
|
||||
}];
|
||||
if (self.options.columnsVisible) {
|
||||
if (isSelected) {
|
||||
updateOrder(self.options.columns[self.selectedColumn].id);
|
||||
|
@ -745,7 +753,7 @@ Ox.TextList = function(options, self) {
|
|||
that.$body.sortList(
|
||||
self.options.sort[0].key,
|
||||
self.options.sort[0].operator,
|
||||
self.options.columns[self.selectedColumn].sort
|
||||
self.options.sort[0].map
|
||||
);
|
||||
}, 10);
|
||||
return that;
|
||||
|
|
|
@ -102,10 +102,10 @@ Ox.ListMap = function(options, self) {
|
|||
editable: true,
|
||||
id: 'geoname',
|
||||
removable: false,
|
||||
operator: '+',
|
||||
sort: function(v) {
|
||||
map: function(v) {
|
||||
return v.split(', ').reverse().join(', ')
|
||||
},
|
||||
operator: '+',
|
||||
title: 'Geoname',
|
||||
visible: true,
|
||||
width: 192
|
||||
|
|
Loading…
Reference in a new issue