updates to url and filter

This commit is contained in:
rlx 2011-11-10 22:47:38 +00:00
parent 07c79ed7ac
commit d2a2ddb66e
4 changed files with 73 additions and 19 deletions

View file

@ -272,11 +272,11 @@ Ox.URL = function(options) {
function constructValue(str, key) { function constructValue(str, key) {
var findKey = Ox.getObjectById(self.options.findKeys, key), var findKey = Ox.getObjectById(self.options.findKeys, key),
list = findKey.list,
type = Ox.isArray(findKey.type) ? findKey.type[0] : findKey.type, type = Ox.isArray(findKey.type) ? findKey.type[0] : findKey.type,
value = str; value = str,
if (type == 'list') { values = findKey.values;
return list[value]; if (type == 'enum') {
return values[value];
} }
return value; return value;
} }
@ -617,21 +617,21 @@ Ox.URL = function(options) {
function parseValue(str, key) { function parseValue(str, key) {
var findKey = Ox.getObjectById(self.options.findKeys, key), var findKey = Ox.getObjectById(self.options.findKeys, key),
list = findKey.list,
type = Ox.isArray(findKey.type) ? findKey.type[0] : findKey.type, type = Ox.isArray(findKey.type) ? findKey.type[0] : findKey.type,
value = str; value = str,
values = findKey.values;
if (type == 'boolean') { if (type == 'boolean') {
value = ['', 'false'].indexOf(str) == -1; value = ['', 'false'].indexOf(str) == -1;
} else if (type == 'date') { } else if (type == 'date') {
value = Ox.formatDate(Ox.parseDate(str, true), '%F', true); value = Ox.formatDate(Ox.parseDate(str, true), '%F', true);
} else if (type == 'enum') {
value = Math.max(values.map(function(value) {
return value.toLowerCase();
}).indexOf(str.toLowerCase()), 0);
} else if (type == 'float') { } else if (type == 'float') {
value = parseFloat(str) || 0; value = parseFloat(str) || 0;
} else if (type == 'integer') { } else if (type == 'integer') {
value = Math.round(str) || 0; value = Math.round(str) || 0;
} else if (type == 'list') {
value = Math.max(list.map(function(value) {
return value.toLowerCase();
}).indexOf(str.toLowerCase()), 0);
} else if (type == 'time') { } else if (type == 'time') {
value = parseTime(value); value = parseTime(value);
} else if (type == 'year') { } else if (type == 'year') {

View file

@ -64,7 +64,7 @@ Ox.Filter = function(options, self) {
{id: '=,', title: 'is between'}, {id: '=,', title: 'is between'},
{id: '!=,', title: 'is not between'} {id: '!=,', title: 'is not between'}
], ],
list: [ enum: [
{id: '=', title: 'is'}, {id: '=', title: 'is'},
{id: '!=', title: 'is not'}, {id: '!=', title: 'is not'},
{id: '<', title: 'is less than'}, {id: '<', title: 'is less than'},
@ -74,6 +74,10 @@ Ox.Filter = function(options, self) {
{id: '=,', title: 'is between'}, {id: '=,', title: 'is between'},
{id: '!=,', title: 'is not between'} {id: '!=,', title: 'is not between'}
], ],
list: [
{id: '=', title: 'is'},
{id: '!=', title: 'is not'}
],
number: [ number: [
{id: '=', title: 'is'}, {id: '=', title: 'is'},
{id: '!=', title: 'is not'}, {id: '!=', title: 'is not'},
@ -97,11 +101,22 @@ Ox.Filter = function(options, self) {
text: [ text: [
{id: '=', title: 'contains'}, {id: '=', title: 'contains'},
{id: '!=', title: 'does not contain'} {id: '!=', title: 'does not contain'}
],
year: [
{id: '==', title: 'is'},
{id: '!==', title: 'is not'},
{id: '<', title: 'is before'},
{id: '!<', title: 'is not before'},
{id: '>', title: 'is after'},
{id: '!>', title: 'is not after'},
{id: '=,', title: 'is between'},
{id: '!=,', title: 'is not between'}
] ]
}; };
self.defaultValue = { self.defaultValue = {
boolean: 'true', boolean: 'true',
date: Ox.formatDate(new Date(), '%F'), date: Ox.formatDate(new Date(), '%F'),
enum: 0,
float: 0, float: 0,
hue: 0, hue: 0,
integer: 0, integer: 0,
@ -109,7 +124,7 @@ Ox.Filter = function(options, self) {
string: '', string: '',
text: '', text: '',
time: '00:00:00', time: '00:00:00',
year: new Date().getFullYear() year: new Date().getFullYear().toString()
}; };
self.operators = [ self.operators = [
{id: '&', title: 'all'}, {id: '&', title: 'all'},
@ -389,7 +404,7 @@ Ox.Filter = function(options, self) {
function getConditionType(type) { function getConditionType(type) {
type = Ox.isArray(type) ? type[0] : type; type = Ox.isArray(type) ? type[0] : type;
if (['float', 'hue', 'integer', 'time', 'year'].indexOf(type) > -1) { if (['float', 'hue', 'integer', 'time'].indexOf(type) > -1) {
type = 'number'; type = 'number';
} }
return type; return type;
@ -668,14 +683,22 @@ Ox.Filter = function(options, self) {
], ],
width: 288 width: 288
}); });
} else if (type == 'list') { } else if (type == 'enum') {
Ox.Log('FILTER', findKey, condition) Ox.Log('FILTER', findKey, condition)
$input = Ox.Select({ $input = Ox.Select({
items: findKey.list.map(function(v, i) { items: findKey.values.map(function(v, i) {
return {id: i, title: v, checked: i == value} return {id: i, title: v, checked: i == value}
}), }),
width: !isArray ? 288 : 128 width: !isArray ? 288 : 128
}); });
} else if (type == 'list') {
Ox.Log('FILTER', findKey)
$input = Ox.Input({
autocomplete: findKey.values,
autocompleteSelect: true,
value: value,
width: 288
});
} else if (findKey.format) { } else if (findKey.format) {
formatArgs = findKey.format.args formatArgs = findKey.format.args
formatType = findKey.format.type; formatType = findKey.format.type;
@ -694,7 +717,8 @@ Ox.Filter = function(options, self) {
'rgb(0, 255, 0)', 'rgb(0, 255, 255)', 'rgb(0, 255, 0)', 'rgb(0, 255, 255)',
'rgb(0, 0, 255)', 'rgb(255, 0, 255)', 'rgb(0, 0, 255)', 'rgb(255, 0, 255)',
'rgb(255, 0, 0)' 'rgb(255, 0, 0)'
] : ['rgb(0, 0, 0)', 'rgb(255, 255, 255)'] ] : ['rgb(0, 0, 0)', 'rgb(255, 255, 255)'],
value: value
}); });
} else if (formatType == 'date') { } else if (formatType == 'date') {
$input = Ox.DateInput(!isArray ? { $input = Ox.DateInput(!isArray ? {
@ -714,6 +738,23 @@ Ox.Filter = function(options, self) {
value: value, value: value,
width: {hours: 38, minutes: 37, seconds: 37} width: {hours: 38, minutes: 37, seconds: 37}
}); });
} else if (formatType == 'resolution') {
$input = Ox.InputGroup({
inputs: [
Ox.Input({
id: 'width',
type: 'int',
value: value
}),
Ox.Input({
id: 'height',
type: 'int',
value: value
})
],
separators: [{title: 'x', width: 16}],
width: !isArray ? 288 : 128
})
} else if ([ } else if ([
'currency', 'percent', 'unit', 'value' 'currency', 'percent', 'unit', 'value'
].indexOf(formatType) > -1) { ].indexOf(formatType) > -1) {

View file

@ -30,6 +30,7 @@ Ox.Range = function(options, self) {
self = self || {}; self = self || {};
var that = Ox.Element({}, self) var that = Ox.Element({}, self)
.defaults({ .defaults({
// fixme: needs a changeOnDrag option (default true)
arrows: false, arrows: false,
arrowStep: 1, arrowStep: 1,
arrowSymbols: ['left', 'right'], arrowSymbols: ['left', 'right'],
@ -240,7 +241,9 @@ Ox.Range = function(options, self) {
} }
function setValue(value, animate) { function setValue(value, animate) {
value = Ox.limit(value, self.options.min, self.options.max); // fixme: toPrecision helps with imprecise results of divisions,
// but won't work for very large values. And is 10 a good value?
value = Ox.limit(value.toPrecision(10), self.options.min, self.options.max);
if (value != self.options.value) { if (value != self.options.value) {
//time = getTime(self.options.value, value); //time = getTime(self.options.value, value);
self.options.value = value; self.options.value = value;
@ -259,6 +262,15 @@ Ox.Range = function(options, self) {
} }
} }
that.value = function() {
if (arguments.length == 0) {
return self.options.value;
} else {
self.options.type = arguments[0];
setThumb();
}
};
return that; return that;
}; };

View file

@ -548,7 +548,8 @@ Ox.formatValue = function(num, str, bin) {
/*@ /*@
Ox.formatUnit <f> Formats a number with a unit Ox.formatUnit <f> Formats a number with a unit
@*/ @*/
Ox.formatUnit = function(num, str, dec) { Ox.formatUnit = function(num, str, dec, factor) {
dec = Ox.isUndefined(dec) ? 3 : dec; dec = Ox.isUndefined(dec) ? 3 : dec;
return Ox.formatNumber(num, dec) + (str == '%' ? '' : ' ') + str; factor = Ox.isUndefined(factor) ? 1 : factor;
return Ox.formatNumber(num * factor, dec) + (str == '%' ? '' : ' ') + str;
}; };