add an optional function to textlist columns that maps values to sort values

This commit is contained in:
rolux 2011-05-22 15:14:42 +02:00
parent 5915acd72c
commit a3c18e57b0
6 changed files with 34 additions and 16 deletions

View file

@ -123,7 +123,7 @@ Ox.Form = function(options, self) {
} else { } else {
Ox.forEach(arguments[0], function(value, key) { Ox.forEach(arguments[0], function(value, key) {
var index = getItemIndexById(key); var index = getItemIndexById(key);
index > -1 && Ox.print(key, value) //index > -1 && Ox.print(key, value)
index > -1 && self.options.items[index].options({value: value}); index > -1 && self.options.items[index].options({value: value});
}); });
return that; return that;

View file

@ -45,14 +45,11 @@ Ox.List = function(options, self) {
that = new Ox.Container({}, self) that = new Ox.Container({}, self)
.defaults({ .defaults({
centered: false, centered: false,
construct: null, construct: null,
draggable: false, draggable: false,
format: [], format: [],
itemHeight: 16, itemHeight: 16,
items: null, items: null,
itemWidth: 16, itemWidth: 16,
keys: [], keys: [],
max: -1, max: -1,
@ -1217,16 +1214,18 @@ Ox.List = function(options, self) {
})); }));
} }
function updateSort() { function updateSort(map) {
var key = self.options.sort[0].key, var key = self.options.sort[0].key,
operator = self.options.sort[0].operator; operator = self.options.sort[0].operator;
if (self.listLength > 1) { if (self.listLength > 1) {
if (Ox.isArray(self.options.items)) { if (Ox.isArray(self.options.items)) {
self.options.items.sort(function(a, b) { self.options.items.sort(function(a, b) {
var ret = 0 var aValue = map ? map(a[key]) : a[key],
if (a[key] < b[key]) { bValue = map ? map(b[key]) : b[key],
ret = 0
if (aValue < bValue) {
return operator == '+' ? -1 : 1 return operator == '+' ? -1 : 1
} else if (a[key] > b[key]) { } else if (aValue > bValue) {
return operator == '+' ? 1 : -1; return operator == '+' ? 1 : -1;
} }
return ret; return ret;
@ -1468,12 +1467,13 @@ Ox.List = function(options, self) {
(key, operator) -> <f> returns List Element (key, operator) -> <f> returns List Element
key <s> key to sort list by key <s> key to sort list by
operator <s> +/- sort ascending or descending operator <s> +/- sort ascending or descending
map <f> function that maps values to sort values
@*/ @*/
that.sortList = function(key, operator) { that.sortList = function(key, operator, map) {
Ox.print('sortList', key, operator) Ox.print('sortList', key, operator)
if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) { if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) {
self.options.sort[0] = {key: key, operator: operator}; self.options.sort[0] = {key: key, operator: operator};
updateSort(); updateSort(map);
that.triggerEvent('sort', self.options.sort[0]); that.triggerEvent('sort', self.options.sort[0]);
} }
return that; return that;

View file

@ -6,7 +6,17 @@ Ox.TextList <f:Ox.Element> TextList Object
(options) -> <f> TextList Object (options) -> <f> TextList Object
(options, self) -> <f> TextList Object (options, self) -> <f> TextList Object
options <o> Options object options <o> Options object
columns <a|[]> columns <[o]|[]>
Fixme: There's probably more...
addable <b>
editable <b>
id <s>
removable <b>
operator <s> default sort operator
sort <f> function that maps values to sort values
title <s>
visible <b>
width <n>
columnsMovable <b|false> columnsMovable <b|false>
columnsRemovable <b|false> columnsRemovable <b|false>
columnsResizable <b|false> columnsResizable <b|false>
@ -48,8 +58,6 @@ Ox.TextList = function(options, self) {
.options(options || {}) .options(options || {})
.addClass('OxTextList'); .addClass('OxTextList');
Ox.print('Ox.TextList self.options', self.options)
self.options.columns.forEach(function(v) { // fixme: can this go into a generic ox.js function? self.options.columns.forEach(function(v) { // fixme: can this go into a generic ox.js function?
// fixme: and can't these just remain undefined? // fixme: and can't these just remain undefined?
if (Ox.isUndefined(v.align)) { if (Ox.isUndefined(v.align)) {
@ -713,7 +721,11 @@ Ox.TextList = function(options, self) {
toggleSelected(self.options.columns[self.selectedColumn].id); toggleSelected(self.options.columns[self.selectedColumn].id);
} }
} }
that.$body.sortList(self.options.sort[0].key, self.options.sort[0].operator); that.$body.sortList(
self.options.sort[0].key,
self.options.sort[0].operator,
self.options.columns[self.selectedColumn].sort
);
return that; return that;
}; };

View file

@ -55,6 +55,9 @@ Ox.ListMap = function(options, self) {
id: 'geoname', id: 'geoname',
removable: false, removable: false,
operator: '+', operator: '+',
sort: function(v) {
return v.split(', ').reverse().join(', ')
},
title: 'Geoname', title: 'Geoname',
visible: true, visible: true,
width: 192 width: 192

View file

@ -83,7 +83,7 @@ Ox.MapMarker = function(options) {
} }
function getMarkerImage(options, callback) { function getMarkerImage(options, callback) {
// unused // fixme: unused
options = Ox.extend({ options = Ox.extend({
background: [255, 0, 0], background: [255, 0, 0],
editing: false, editing: false,

View file

@ -27,9 +27,12 @@ Ox.MapMarkerImage = (function() {
options.type, options.mode, options.size, options.color.join(',') options.type, options.mode, options.size, options.color.join(',')
].join(';'); ].join(';');
Ox.print('HELLO??')
if (!cache[index]) { if (!cache[index]) {
var color = options.type == 'place' ? var color = options.type == 'place' ?
Ox.merge(Ox.clone(options.color), [0.5]) : [0, 0, 0, 0], Ox.merge(Ox.clone(options.color), [0.5]) :
options.type == 'result' ? [128, 128, 128, 0.5] : [0, 0, 0, 0],
border = options.mode == 'normal' ? [0, 0, 0] : border = options.mode == 'normal' ? [0, 0, 0] :
options.mode == 'selected' ? [255, 255, 255] : [128, 128, 255], options.mode == 'selected' ? [255, 255, 255] : [128, 128, 255],
c = Ox.canvas(options.size, options.size), c = Ox.canvas(options.size, options.size),